chore: checkpoint current workspace changes
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <XCEngine/Resources/Material/MaterialLoader.h>
|
||||
#include <XCEngine/Core/Asset/ArtifactContainer.h>
|
||||
#include <XCEngine/Core/Asset/ArtifactFormats.h>
|
||||
#include <XCEngine/Resources/BuiltinResources.h>
|
||||
#include <XCEngine/Core/Asset/ResourceManager.h>
|
||||
@@ -19,6 +20,32 @@ namespace Resources {
|
||||
|
||||
namespace {
|
||||
|
||||
Containers::String GetPathExtensionString(const Containers::String& path) {
|
||||
const std::filesystem::path fsPath(path.CStr());
|
||||
const std::string extension = fsPath.has_extension()
|
||||
? fsPath.extension().string()
|
||||
: std::string();
|
||||
if (!extension.empty() && extension[0] == '.') {
|
||||
return Containers::String(extension.substr(1).c_str());
|
||||
}
|
||||
|
||||
return Containers::String(extension.c_str());
|
||||
}
|
||||
|
||||
Containers::String GetMaterialPathExtension(const Containers::String& path) {
|
||||
Containers::String containerPath;
|
||||
Containers::String entryName;
|
||||
if (TryParseArtifactContainerEntryPath(path, containerPath, entryName)) {
|
||||
const Containers::String entryExtension = GetPathExtensionString(entryName);
|
||||
if (!entryExtension.Empty()) {
|
||||
return entryExtension;
|
||||
}
|
||||
return GetPathExtensionString(containerPath);
|
||||
}
|
||||
|
||||
return GetPathExtensionString(path);
|
||||
}
|
||||
|
||||
std::string ToStdString(const Containers::Array<Core::uint8>& data) {
|
||||
return std::string(reinterpret_cast<const char*>(data.Data()), data.Size());
|
||||
}
|
||||
@@ -27,6 +54,17 @@ Containers::Array<Core::uint8> ReadMaterialArtifactFileData(const Containers::St
|
||||
Containers::Array<Core::uint8> data;
|
||||
|
||||
auto tryRead = [&data](const std::filesystem::path& filePath, bool& opened) {
|
||||
opened = false;
|
||||
Containers::String containerError;
|
||||
if (ReadArtifactContainerPayloadByPath(
|
||||
Containers::String(filePath.generic_string().c_str()),
|
||||
ResourceType::Material,
|
||||
data,
|
||||
&containerError)) {
|
||||
opened = true;
|
||||
return;
|
||||
}
|
||||
|
||||
std::ifstream file(filePath, std::ios::binary | std::ios::ate);
|
||||
if (!file.is_open()) {
|
||||
opened = false;
|
||||
@@ -143,12 +181,27 @@ Containers::String ResolveArtifactDependencyPath(const Containers::String& depen
|
||||
}
|
||||
|
||||
std::filesystem::path dependencyFsPath(dependencyPath.CStr());
|
||||
Containers::String containerPathText;
|
||||
Containers::String entryName;
|
||||
const bool isContainerEntryPath =
|
||||
TryParseArtifactContainerEntryPath(dependencyPath, containerPathText, entryName);
|
||||
if (isContainerEntryPath) {
|
||||
dependencyFsPath = std::filesystem::path(containerPathText.CStr());
|
||||
}
|
||||
|
||||
auto rebuildResolvedPath = [&entryName, isContainerEntryPath](const std::filesystem::path& resolvedPath) {
|
||||
const Containers::String normalizedPath = NormalizePathString(resolvedPath);
|
||||
return isContainerEntryPath
|
||||
? BuildArtifactContainerEntryPath(normalizedPath, entryName)
|
||||
: normalizedPath;
|
||||
};
|
||||
|
||||
if (dependencyFsPath.is_absolute() && std::filesystem::exists(dependencyFsPath)) {
|
||||
return NormalizePathString(dependencyFsPath);
|
||||
return rebuildResolvedPath(dependencyFsPath);
|
||||
}
|
||||
|
||||
if (std::filesystem::exists(dependencyFsPath)) {
|
||||
return NormalizePathString(dependencyFsPath);
|
||||
return rebuildResolvedPath(dependencyFsPath);
|
||||
}
|
||||
|
||||
const Containers::String& resourceRoot = ResourceManager::Get().GetResourceRoot();
|
||||
@@ -156,7 +209,7 @@ Containers::String ResolveArtifactDependencyPath(const Containers::String& depen
|
||||
const std::filesystem::path projectRelativeCandidate =
|
||||
std::filesystem::path(resourceRoot.CStr()) / dependencyFsPath;
|
||||
if (std::filesystem::exists(projectRelativeCandidate)) {
|
||||
return NormalizePathString(projectRelativeCandidate);
|
||||
return rebuildResolvedPath(projectRelativeCandidate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +221,7 @@ Containers::String ResolveArtifactDependencyPath(const Containers::String& depen
|
||||
const std::filesystem::path ownerRelativeCandidate =
|
||||
ownerArtifactFsPath.parent_path() / dependencyFsPath;
|
||||
if (std::filesystem::exists(ownerRelativeCandidate)) {
|
||||
return NormalizePathString(ownerRelativeCandidate);
|
||||
return rebuildResolvedPath(ownerRelativeCandidate);
|
||||
}
|
||||
|
||||
std::filesystem::path current = ownerArtifactFsPath.parent_path();
|
||||
@@ -178,7 +231,7 @@ Containers::String ResolveArtifactDependencyPath(const Containers::String& depen
|
||||
if (!projectRoot.empty()) {
|
||||
const std::filesystem::path projectRelativeCandidate = projectRoot / dependencyFsPath;
|
||||
if (std::filesystem::exists(projectRelativeCandidate)) {
|
||||
return NormalizePathString(projectRelativeCandidate);
|
||||
return rebuildResolvedPath(projectRelativeCandidate);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1800,7 +1853,7 @@ bool MaterialLoader::CanLoad(const Containers::String& path) const {
|
||||
return true;
|
||||
}
|
||||
|
||||
Containers::String ext = GetExtension(path).ToLower();
|
||||
const Containers::String ext = GetMaterialPathExtension(path).ToLower();
|
||||
return ext == "mat" || ext == "material" || ext == "json" || ext == "xcmat";
|
||||
}
|
||||
|
||||
@@ -1811,7 +1864,7 @@ LoadResult MaterialLoader::Load(const Containers::String& path, const ImportSett
|
||||
return CreateBuiltinMaterialResource(path);
|
||||
}
|
||||
|
||||
const Containers::String ext = GetExtension(path).ToLower();
|
||||
const Containers::String ext = GetMaterialPathExtension(path).ToLower();
|
||||
if (ext == "xcmat") {
|
||||
return LoadMaterialArtifact(path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user