Formalize scene viewport resource path resolution
This commit is contained in:
@@ -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) {
|
||||
|
||||
61
editor/src/Viewport/SceneViewportResourcePaths.h
Normal file
61
editor/src/Viewport/SceneViewportResourcePaths.h
Normal 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
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user