Skip to content

Commit 03dfbf0

Browse files
authored
Feature/asset browser (#245)
# 機能追加 - アセットブラウザの実装を行いました。 - ファイルドロップでアセットの追加を行えるよう追加しました。その際に、最適化を行えるフラグを追加しました。 # 修正 - Assetフォルダのフォルダ名変更に伴う修正を行いました。 # 変更 - EditorHierarchyDandDをEditorDandDManagerに命名変更しました。 - ファイルのドロップ時にWMを受け取るよう変更しました。 - Transform2D/3Dをcopyableに変更しました。 # 削除 - 各種AssetLibraryからdebug_gui関数を削除しました。
1 parent 1ea01e1 commit 03dfbf0

88 files changed

Lines changed: 3459 additions & 1986 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Engine/Application/WinApp.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ void WinApp::Initialize() {
203203
);
204204

205205
// Texture
206-
TextureLibrary::RegisterLoadQue("./SyzygyEngine/EditorResources/Texture/EngineIcon_DirectionalLight.png");
206+
TextureLibrary::RegisterLoadQue("[[editor]]/EngineIcon_DirectionalLight.png");
207207
#endif // _DEBUG
208208

209209
// 待機
@@ -362,6 +362,7 @@ void WinApp::ShowAppWindow() {
362362
if (!ProjectSettings::GetApplicationSettingsImm().hideWindowForce) {
363363
ShowWindow(GetInstance().hWnd, SW_SHOW);
364364
szgInformation("Show application window.");
365+
DragAcceptFiles(GetInstance().hWnd, TRUE); // Drag&Dropを受け付ける
365366
}
366367

367368
#ifdef DEBUG_FEATURES_ENABLE
@@ -388,6 +389,21 @@ void WinApp::ProcessMessage() {
388389
return;
389390
}
390391
switch (instance.msg.message) {
392+
#ifdef DEBUG_FEATURES_ENABLE
393+
case WM_DROPFILES: // ファイルがドロップされた
394+
szgInformation("Dropped File.");
395+
{
396+
wchar_t filePathW[MAX_PATH]{};
397+
HDROP hDrop = reinterpret_cast<HDROP>(instance.msg.wParam);
398+
UINT fileCount = DragQueryFileW(hDrop, 0xFFFFFFFF, nullptr, 0);
399+
for (UINT i = 0; i < fileCount; ++i) {
400+
DragQueryFileW(hDrop, i, filePathW, MAX_PATH);
401+
EditorMain::HandleDropFile(filePathW);
402+
}
403+
DragFinish(hDrop);
404+
}
405+
break;
406+
#endif // DEBUG_FEATURES_ENABLE
391407
case WM_QUIT: // windowの×ボタンが押されたら通知
392408
instance.isEndApp = true;
393409
break;

Engine/Assets/Animation/NodeAnimation/NodeAnimationLibrary.cpp

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,6 @@ using namespace szg;
1111
#include "Engine/Application/Logger.h"
1212
#include "Engine/Assets/BackgroundLoader/BackgroundLoader.h"
1313

14-
#ifdef DEBUG_FEATURES_ENABLE
15-
#include <ranges>
16-
#include <imgui.h>
17-
#endif // _DEBUG
18-
19-
std::mutex nodeAnimationMutex;
20-
2114
void NodeAnimationLibrary::RegisterLoadQue(const std::filesystem::path& filePath) {
2215
// ロード済みの場合は何もしない
2316
if (IsRegistered(filePath.filename().string())) {
@@ -27,8 +20,17 @@ void NodeAnimationLibrary::RegisterLoadQue(const std::filesystem::path& filePath
2720
BackgroundLoader::RegisterLoadQue(eps::CreateUnique<NodeAnimationAssetBuilder>(filePath));
2821
}
2922

23+
void szg::NodeAnimationLibrary::Unload(const std::string& name) {
24+
std::lock_guard<std::mutex> lock{ mutex };
25+
auto& instance = GetInstance();
26+
if (IsRegisteredNonlocking(name)) {
27+
szgInformation("Unload NodeAnimation Name-\'{:}\'.", name);
28+
instance.instanceList.erase(name);
29+
}
30+
}
31+
3032
std::shared_ptr<const NodeAnimationAsset> NodeAnimationLibrary::GetAnimation(const std::string& name) {
31-
std::lock_guard<std::mutex> lock{ nodeAnimationMutex };
33+
std::lock_guard<std::mutex> lock{ mutex };
3234
if (IsRegisteredNonlocking(name)) {
3335
return GetInstance().instanceList.at(name);
3436
}
@@ -39,40 +41,16 @@ std::shared_ptr<const NodeAnimationAsset> NodeAnimationLibrary::GetAnimation(con
3941
}
4042

4143
bool NodeAnimationLibrary::IsRegistered(const std::string& name) {
42-
std::lock_guard<std::mutex> lock{ nodeAnimationMutex };
44+
std::lock_guard<std::mutex> lock{ mutex };
4345
return IsRegisteredNonlocking(name);
4446
}
4547

4648
void NodeAnimationLibrary::Transfer(const std::string& name, std::shared_ptr<NodeAnimationAsset> data) {
47-
std::lock_guard<std::mutex> lock{ nodeAnimationMutex };
49+
std::lock_guard<std::mutex> lock{ mutex };
4850
szgInformation("Transfer new NodeAnimation. Name-\'{:}\', Address-\'{:016}\'", name, (void*)data.get());
4951
GetInstance().instanceList.emplace(name, data);
5052
}
5153

52-
#ifdef DEBUG_FEATURES_ENABLE
53-
bool NodeAnimationLibrary::AnimationListGui(std::string& current) {
54-
bool changed = false;
55-
56-
std::lock_guard<std::mutex> lock{ nodeAnimationMutex };
57-
if (ImGui::BeginCombo("AnimationList", current.c_str())) {
58-
auto&& list = GetInstance().instanceList;
59-
for (const auto& name : list | std::views::keys) {
60-
bool is_selected = (current == name);
61-
if (ImGui::Selectable(name.c_str(), is_selected)) {
62-
current = name;
63-
changed = true;
64-
}
65-
if (is_selected) {
66-
ImGui::SetItemDefaultFocus();
67-
}
68-
}
69-
ImGui::EndCombo();
70-
71-
}
72-
return changed;
73-
}
74-
#endif // _DEBUG
75-
7654
bool NodeAnimationLibrary::IsRegisteredNonlocking(const std::string& name) {
7755
return GetInstance().instanceList.contains(name);
7856
}

Engine/Assets/Animation/NodeAnimation/NodeAnimationLibrary.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <filesystem>
66
#include <memory>
7+
#include <mutex>
78
#include <string>
89
#include <unordered_map>
910

@@ -24,6 +25,8 @@ class NodeAnimationLibrary final : SingletonInterface<NodeAnimationLibrary> {
2425
/// <param name="filePath">ファイルパス</param>
2526
static void RegisterLoadQue(const std::filesystem::path& filePath);
2627

28+
static void Unload(const std::string& name);
29+
2730
/// <summary>
2831
/// Animationの取得
2932
/// </summary>
@@ -45,15 +48,6 @@ class NodeAnimationLibrary final : SingletonInterface<NodeAnimationLibrary> {
4548
/// <param name="data">ロード済みデータ</param>
4649
static void Transfer(const std::string& name, std::shared_ptr<NodeAnimationAsset> data);
4750

48-
#ifdef DEBUG_FEATURES_ENABLE
49-
/// <summary>
50-
/// Animation一覧をComboBoxで表示するImGui(Debugビルドのみ)
51-
/// </summary>
52-
/// <param name="current">現在選択中のAnimation名</param>
53-
/// <returns>currentが変更されたかどうか</returns>
54-
static bool AnimationListGui(std::string& current);
55-
#endif // _DEBUG
56-
5751
private:
5852
/// <summary>
5953
/// Animationが登録されているか取得(mutexなし)
@@ -64,6 +58,8 @@ class NodeAnimationLibrary final : SingletonInterface<NodeAnimationLibrary> {
6458

6559
private:
6660
std::unordered_map<std::string, std::shared_ptr<NodeAnimationAsset>> instanceList;
61+
62+
static inline std::mutex mutex{};
6763
};
6864

6965

Engine/Assets/Animation/NodeAnimation/NodeAnimationPlayer.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -95,25 +95,6 @@ void NodeAnimationPlayer::animation_speed(r32 speed) noexcept {
9595
animationSpeed = speed;
9696
}
9797

98-
#ifdef DEBUG_FEATURES_ENABLE
99-
#include <imgui.h>
100-
void NodeAnimationPlayer::debug_gui() {
101-
if (NodeAnimationLibrary::AnimationListGui(animationName)) {
102-
reset_animation(animationName);
103-
}
104-
105-
if (ImGui::TreeNodeEx(animationName.c_str(), ImGuiTreeNodeFlags_DefaultOpen)) {
106-
ImGui::Checkbox("Active", &isActive);
107-
ImGui::Checkbox("Loop", &isLoop);
108-
if (nodeAnimation) {
109-
ImGui::SliderFloat("Timer", reinterpret_cast<float*>(&timer), 0, nodeAnimation->duration(), "%.3fs");
110-
}
111-
ImGui::DragFloat("AnimationSpeed", &animationSpeed, 0.1f);
112-
ImGui::TreePop();
113-
}
114-
}
115-
#endif // _DEBUG
116-
11798
template<typename T, T LerpFunction(const T&, const T&, r32)>
11899
T CalculateValue(const NodeAnimationAsset::AnimationCurve<T>& animationCurve, r32 time) {
119100
const std::map<r32, T>& keyframes = animationCurve.keyframes;

Engine/Assets/Animation/NodeAnimation/NodeAnimationPlayer.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ class NodeAnimationPlayer {
4848

4949
void animation_speed(r32 speed = 1.0f) noexcept;
5050

51-
#ifdef DEBUG_FEATURES_ENABLE
52-
public:
53-
void debug_gui();
54-
#endif // _DEBUG
55-
5651
private:
5752
bool isLoop{ false };
5853
bool isActive{ true };

Engine/Assets/Animation/Skeleton/SkeletonLibrary.cpp

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
using namespace szg;
44

5-
#include <mutex>
6-
75
#include "./SkeletonAsset.h"
86
#include "./SkeletonAssetBuilder.h"
97
#include "Engine/Application/Logger.h"
@@ -15,8 +13,6 @@ using namespace szg;
1513
#include <imgui.h>
1614
#endif // _DEBUG
1715

18-
std::mutex skeletonMutex;
19-
2016
void SkeletonLibrary::RegisterLoadQue(const std::filesystem::path& filePath) {
2117
// ロード済みの場合は何もしない
2218
if (IsRegistered(filePath.filename().string())) {
@@ -26,8 +22,17 @@ void SkeletonLibrary::RegisterLoadQue(const std::filesystem::path& filePath) {
2622
BackgroundLoader::RegisterLoadQue(eps::CreateUnique<SkeletonAssetBuilder>(filePath));
2723
}
2824

25+
void szg::SkeletonLibrary::Unload(const std::string& name) {
26+
std::lock_guard<std::mutex> lock{ mutex };
27+
auto& instance = GetInstance();
28+
if (IsRegisteredNonlocking(name)) {
29+
szgInformation("Unload skeleton Name-\'{:}\'.", name);
30+
instance.instanceList.erase(name);
31+
}
32+
}
33+
2934
std::shared_ptr<const SkeletonAsset> SkeletonLibrary::GetSkeleton(const std::string& name) {
30-
std::lock_guard<std::mutex> lock{ skeletonMutex };
35+
std::lock_guard<std::mutex> lock{ mutex };
3136
if (IsRegisteredNonlocking(name)) {
3237
return GetInstance().instanceList.at(name);
3338
}
@@ -38,39 +43,17 @@ std::shared_ptr<const SkeletonAsset> SkeletonLibrary::GetSkeleton(const std::str
3843
}
3944

4045
bool SkeletonLibrary::IsRegistered(const std::string& name) {
41-
std::lock_guard<std::mutex> lock{ skeletonMutex };
46+
std::lock_guard<std::mutex> lock{ mutex };
4247
return IsRegisteredNonlocking(name);
4348

4449
}
4550

4651
void SkeletonLibrary::Transfer(const std::string& name, std::shared_ptr<SkeletonAsset>& data) {
47-
std::lock_guard<std::mutex> lock{ skeletonMutex };
52+
std::lock_guard<std::mutex> lock{ mutex };
4853
szgInformation("Transfer new Skeleton. Name-\'{:}\', Address-\'{:016}\'", name, (void*)data.get());
4954
GetInstance().instanceList.emplace(name, data);
5055
}
5156

52-
//bool SkeletonLibrary::SkeletonListGui(std::string& current) {
53-
// bool changed = false;
54-
//
55-
// std::lock_guard<std::mutex> lock{ skeletonMutex };
56-
// if (ImGui::BeginCombo("SkeletonList", current.c_str())) {
57-
// auto&& list = GetInstance().instanceList;
58-
// for (auto itr = list.begin(); itr != list.end(); ++itr) {
59-
// bool is_selected = (current == itr->first);
60-
// if (ImGui::Selectable(itr->first.c_str(), is_selected)) {
61-
// current = itr->first;
62-
// changed = true;
63-
// }
64-
// if (is_selected) {
65-
// ImGui::SetItemDefaultFocus();
66-
// }
67-
// }
68-
// ImGui::EndCombo();
69-
//
70-
// }
71-
// return changed;
72-
//}
73-
7457
bool SkeletonLibrary::IsRegisteredNonlocking(const std::string& name) {
7558
return GetInstance().instanceList.contains(name);
7659
}

Engine/Assets/Animation/Skeleton/SkeletonLibrary.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <filesystem>
66
#include <memory>
7+
#include <mutex>
78
#include <string>
89
#include <unordered_map>
910

@@ -24,6 +25,8 @@ class SkeletonLibrary final : SingletonInterface<SkeletonLibrary> {
2425
/// <param name="filePath">ファイルパス</param>
2526
static void RegisterLoadQue(const std::filesystem::path& filePath);
2627

28+
static void Unload(const std::string& name);
29+
2730
/// <summary>
2831
/// Skeletonの取得
2932
/// </summary>
@@ -45,15 +48,6 @@ class SkeletonLibrary final : SingletonInterface<SkeletonLibrary> {
4548
/// <param name="data">ロード済みデータ</param>
4649
static void Transfer(const std::string& name, std::shared_ptr<SkeletonAsset>& data);
4750

48-
#ifdef DEBUG_FEATURES_ENABLE
49-
/// <summary>
50-
/// Skeleton一覧をComboBoxで表示するImGui(Debugビルドのみ)
51-
/// </summary>
52-
/// <param name="current">現在選択中のSkeleton名</param>
53-
/// <returns>currentが変更されたかどうか</returns>
54-
//static bool SkeletonListGui(std::string& current);
55-
#endif // _DEBUG
56-
5751
private:
5852
/// <summary>
5953
/// Skeletonが登録されているか取得(mutexなし)
@@ -64,6 +58,8 @@ class SkeletonLibrary final : SingletonInterface<SkeletonLibrary> {
6458

6559
private:
6660
std::unordered_map<std::string, std::shared_ptr<SkeletonAsset>> instanceList;
61+
62+
static inline std::mutex mutex{};
6763
};
6864

6965
}; // szg

Engine/Assets/AssetRootPath.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#pragma once
2+
3+
#include <array>
4+
5+
namespace szg {
6+
7+
enum class AssetRootType {
8+
Unselect,
9+
Engine,
10+
Game,
11+
Editor,
12+
13+
Max,
14+
};
15+
16+
static constexpr i32 ASSET_ROOT_TYPE_MAX = static_cast<i32>(AssetRootType::Max);
17+
18+
static constexpr std::array<string_literal, ASSET_ROOT_TYPE_MAX> ROOT_TAG{
19+
"[[unselect]]",
20+
"[[szg]]",
21+
"[[game]]",
22+
"[[editor]]",
23+
};
24+
25+
static constexpr std::array<wstring_literal, ASSET_ROOT_TYPE_MAX> ROOT_TAG_W{
26+
L"[[unselect]]",
27+
L"[[szg]]",
28+
L"[[game]]",
29+
L"[[editor]]",
30+
};
31+
32+
static constexpr std::array<string_literal, ASSET_ROOT_TYPE_MAX> ROOT_PATH{
33+
"",
34+
".\\SyzygyEngine\\EngineResources",
35+
".\\Game\\Assets",
36+
".\\SyzygyEngine\\EditorResources",
37+
};
38+
39+
} // namespace szg

Engine/Assets/AssetTypeEnum.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#pragma once
2+
3+
#include <array>
4+
5+
namespace szg {
6+
7+
enum class AssetType {
8+
Unknown,
9+
Texture,
10+
Mesh,
11+
Skeleton,
12+
Animation,
13+
Font,
14+
Json,
15+
Audio,
16+
Shader,
17+
18+
Max,
19+
};
20+
21+
constexpr i32 ASSET_TYPE_MAX = static_cast<i32>(AssetType::Max);
22+
23+
constexpr std::array<string_literal, ASSET_TYPE_MAX> ASSET_TYPE_NAME = {
24+
"Unknown",
25+
"Texture",
26+
"Mesh",
27+
"Skeleton",
28+
"Animation",
29+
"Font",
30+
"Json",
31+
"Audio",
32+
"Shader",
33+
};
34+
35+
}

0 commit comments

Comments
 (0)