From 65d55c85368a7aaa4f0612f9691d804dcddfcad8 Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Sat, 4 Apr 2026 16:40:52 +0800 Subject: [PATCH] Formalize scene viewport resource path resolution --- .../Passes/SceneViewportEditorOverlayPass.cpp | 20 ++---- .../src/Viewport/SceneViewportResourcePaths.h | 61 +++++++++++++++++++ .../src/Viewport/SceneViewportShaderPaths.h | 46 +------------- 3 files changed, 68 insertions(+), 59 deletions(-) create mode 100644 editor/src/Viewport/SceneViewportResourcePaths.h diff --git a/editor/src/Viewport/Passes/SceneViewportEditorOverlayPass.cpp b/editor/src/Viewport/Passes/SceneViewportEditorOverlayPass.cpp index a6fd2465..52024adf 100644 --- a/editor/src/Viewport/Passes/SceneViewportEditorOverlayPass.cpp +++ b/editor/src/Viewport/Passes/SceneViewportEditorOverlayPass.cpp @@ -1,7 +1,7 @@ #include "Passes/SceneViewportEditorOverlayPass.h" -#include "Platform/Win32Utf8.h" #include "Viewport/SceneViewportMath.h" +#include "Viewport/SceneViewportResourcePaths.h" #include #include @@ -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& outBytes) { diff --git a/editor/src/Viewport/SceneViewportResourcePaths.h b/editor/src/Viewport/SceneViewportResourcePaths.h new file mode 100644 index 00000000..8d2e561a --- /dev/null +++ b/editor/src/Viewport/SceneViewportResourcePaths.h @@ -0,0 +1,61 @@ +#pragma once + +#include + +#include + +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 diff --git a/editor/src/Viewport/SceneViewportShaderPaths.h b/editor/src/Viewport/SceneViewportShaderPaths.h index 6022c59e..fbd2412d 100644 --- a/editor/src/Viewport/SceneViewportShaderPaths.h +++ b/editor/src/Viewport/SceneViewportShaderPaths.h @@ -1,47 +1,3 @@ #pragma once -#include - -#include - -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"