Formalize scene viewport resource path resolution

This commit is contained in:
2026-04-04 16:40:52 +08:00
parent ee8b5e8c44
commit 65d55c8536
3 changed files with 68 additions and 59 deletions

View File

@@ -1,7 +1,7 @@
#include "Passes/SceneViewportEditorOverlayPass.h"
#include "Platform/Win32Utf8.h"
#include "Viewport/SceneViewportMath.h"
#include "Viewport/SceneViewportResourcePaths.h"
#include <XCEngine/RHI/RHIBuffer.h>
#include <XCEngine/RHI/RHICommandList.h>
@@ -202,25 +202,17 @@ size_t ToSpriteTextureIndex(SceneViewportOverlaySpriteTextureKind textureKind) {
}
}
const char* GetSpriteTextureBaseName(SceneViewportOverlaySpriteTextureKind textureKind) {
std::filesystem::path ResolveOverlaySpriteTexturePath(SceneViewportOverlaySpriteTextureKind textureKind) {
switch (textureKind) {
case SceneViewportOverlaySpriteTextureKind::Camera:
return "camera_gizmo";
return std::filesystem::path(GetSceneViewportCameraGizmoIconPath().CStr());
case SceneViewportOverlaySpriteTextureKind::Light:
return "main_light_gizmo";
return std::filesystem::path(GetSceneViewportMainLightGizmoIconPath().CStr());
default:
return "";
break;
}
}
std::filesystem::path ResolveOverlaySpriteTexturePath(SceneViewportOverlaySpriteTextureKind textureKind) {
const std::filesystem::path exeDir(
Platform::Utf8ToWide(Platform::GetExecutableDirectoryUtf8()));
std::filesystem::path iconPath =
exeDir / L".." / L".." / L"resources" / L"Icons" /
std::filesystem::path(Platform::Utf8ToWide(GetSpriteTextureBaseName(textureKind)));
iconPath += L".png";
return iconPath.lexically_normal();
return std::filesystem::path();
}
bool ReadFileBytes(const std::filesystem::path& filePath, std::vector<stbi_uc>& outBytes) {

View File

@@ -0,0 +1,61 @@
#pragma once
#include <XCEngine/Core/Containers/String.h>
#include <filesystem>
namespace XCEngine {
namespace Editor {
namespace Detail {
inline Containers::String NormalizeSceneViewportResourcePath(const std::filesystem::path& path) {
return Containers::String(path.lexically_normal().generic_string().c_str());
}
inline std::filesystem::path GetSceneViewportResourceRepoRootPath() {
#ifdef XCENGINE_EDITOR_REPO_ROOT
return std::filesystem::path(XCENGINE_EDITOR_REPO_ROOT);
#else
return std::filesystem::path(__FILE__).parent_path().parent_path().parent_path();
#endif
}
inline Containers::String BuildSceneViewportEditorResourcePath(const std::filesystem::path& relativePath) {
return NormalizeSceneViewportResourcePath(
GetSceneViewportResourceRepoRootPath() /
"editor" /
"resources" /
relativePath);
}
} // namespace Detail
inline Containers::String GetSceneViewportInfiniteGridShaderPath() {
return Detail::BuildSceneViewportEditorResourcePath(
std::filesystem::path("shaders") /
"scene-viewport" /
"infinite-grid" /
"infinite-grid.shader");
}
inline Containers::String GetSceneViewportObjectIdOutlineShaderPath() {
return Detail::BuildSceneViewportEditorResourcePath(
std::filesystem::path("shaders") /
"scene-viewport" /
"object-id-outline" /
"object-id-outline.shader");
}
inline Containers::String GetSceneViewportCameraGizmoIconPath() {
return Detail::BuildSceneViewportEditorResourcePath(
std::filesystem::path("Icons") / "camera_gizmo.png");
}
inline Containers::String GetSceneViewportMainLightGizmoIconPath() {
return Detail::BuildSceneViewportEditorResourcePath(
std::filesystem::path("Icons") / "main_light_gizmo.png");
}
} // namespace Editor
} // namespace XCEngine

View File

@@ -1,47 +1,3 @@
#pragma once
#include <XCEngine/Core/Containers/String.h>
#include <filesystem>
namespace XCEngine {
namespace Editor {
namespace Detail {
inline Containers::String NormalizeSceneViewportShaderPath(const std::filesystem::path& path) {
return Containers::String(path.lexically_normal().generic_string().c_str());
}
inline std::filesystem::path GetSceneViewportShaderRepoRootPath() {
#ifdef XCENGINE_EDITOR_REPO_ROOT
return std::filesystem::path(XCENGINE_EDITOR_REPO_ROOT);
#else
return std::filesystem::path(__FILE__).parent_path().parent_path().parent_path();
#endif
}
inline Containers::String BuildSceneViewportShaderPath(const std::filesystem::path& relativePath) {
return NormalizeSceneViewportShaderPath(
GetSceneViewportShaderRepoRootPath() /
"editor" /
"resources" /
"shaders" /
"scene-viewport" /
relativePath);
}
} // namespace Detail
inline Containers::String GetSceneViewportInfiniteGridShaderPath() {
return Detail::BuildSceneViewportShaderPath(
std::filesystem::path("infinite-grid") / "infinite-grid.shader");
}
inline Containers::String GetSceneViewportObjectIdOutlineShaderPath() {
return Detail::BuildSceneViewportShaderPath(
std::filesystem::path("object-id-outline") / "object-id-outline.shader");
}
} // namespace Editor
} // namespace XCEngine
#include "SceneViewportResourcePaths.h"