feat: update asset browser
This commit is contained in:
@@ -1,37 +1,115 @@
|
||||
#ifndef EDITOR_ASSETBROWSER_H
|
||||
#define EDITOR_ASSETBROWSER_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <future>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include <glm/vec3.hpp>
|
||||
|
||||
#include <destrum/Graphics/GPUImage.h>
|
||||
|
||||
class GfxDevice;
|
||||
class ImguiPass;
|
||||
struct FSMount;
|
||||
|
||||
class AssetBrowser final {
|
||||
public:
|
||||
AssetBrowser(GfxDevice& gfxDevice, ImguiPass& imguiPass);
|
||||
~AssetBrowser();
|
||||
|
||||
AssetBrowser(const AssetBrowser&) = delete;
|
||||
AssetBrowser& operator=(const AssetBrowser&) = delete;
|
||||
|
||||
std::optional<std::string> Draw(bool* open = nullptr);
|
||||
|
||||
void ConfigureCooking(std::filesystem::path cooker, std::vector<std::string> schemes);
|
||||
|
||||
enum class Kind { Folder, Model, Scene, Prefab, Material, Image, Audio, Shader, Font, Text, Other };
|
||||
|
||||
private:
|
||||
struct Entry {
|
||||
std::string name;
|
||||
Kind kind{Kind::Other};
|
||||
bool directory{false};
|
||||
std::uintmax_t size{0};
|
||||
std::filesystem::path fullPath;
|
||||
std::filesystem::path previewPath;
|
||||
glm::vec3 tint{1.0f};
|
||||
};
|
||||
|
||||
struct Location {
|
||||
std::string scheme;
|
||||
std::filesystem::path folder;
|
||||
};
|
||||
|
||||
struct ThumbnailPixels {
|
||||
int width{0};
|
||||
int height{0};
|
||||
int sourceWidth{0};
|
||||
int sourceHeight{0};
|
||||
std::vector<unsigned char> rgba;
|
||||
};
|
||||
|
||||
struct Thumbnail {
|
||||
GPUImage image;
|
||||
std::filesystem::file_time_type writeTime;
|
||||
int sourceWidth{0};
|
||||
int sourceHeight{0};
|
||||
bool failed{false};
|
||||
};
|
||||
|
||||
void Refresh();
|
||||
void StartCook();
|
||||
void PollCook();
|
||||
void Navigate(const std::string& scheme, const std::filesystem::path& folder);
|
||||
void Navigate(std::string scheme, std::filesystem::path folder, bool record = true);
|
||||
void GoBack();
|
||||
void GoForward();
|
||||
void GoUp();
|
||||
[[nodiscard]] std::string VirtualPath(const std::string& name) const;
|
||||
void DrawEntry(const Entry& entry, std::optional<std::string>& opened, bool& navigated);
|
||||
|
||||
void DrawToolbar();
|
||||
void DrawBreadcrumbs(float width);
|
||||
void DrawFolderTree();
|
||||
void DrawFolderNode(const FSMount& mount, const std::filesystem::path& folder, const std::string& label);
|
||||
void DrawEntries(std::optional<std::string>& opened);
|
||||
void DrawGrid(const std::vector<const Entry*>& entries, std::optional<std::string>& opened);
|
||||
void DrawList(const std::vector<const Entry*>& entries, std::optional<std::string>& opened);
|
||||
void DrawStatusBar();
|
||||
void HandleEntryInput(const Entry& entry, std::optional<std::string>& opened, bool& navigated);
|
||||
void Open(const Entry& entry, std::optional<std::string>& opened, bool& navigated);
|
||||
void DrawFolderMenu();
|
||||
void DrawEntryIcon(const Entry& entry, float x, float y, float size);
|
||||
[[nodiscard]] const std::vector<std::string>& Subfolders(const FSMount& mount, const std::filesystem::path& folder);
|
||||
|
||||
[[nodiscard]] const Thumbnail* RequestThumbnail(const std::filesystem::path& path);
|
||||
[[nodiscard]] static ThumbnailPixels DecodeThumbnail(const std::filesystem::path& path);
|
||||
void PollThumbnails();
|
||||
void DestroyThumbnail(Thumbnail& thumbnail);
|
||||
|
||||
GfxDevice& m_GfxDevice;
|
||||
ImguiPass& m_ImguiPass;
|
||||
|
||||
std::string m_Scheme;
|
||||
std::filesystem::path m_Folder;
|
||||
std::vector<Entry> m_Entries;
|
||||
std::string m_Filter;
|
||||
std::string m_Selected;
|
||||
std::size_t m_VisibleCount{0};
|
||||
bool m_Dirty{true};
|
||||
bool m_RevealFolder{true};
|
||||
float m_TileSize{88.0f};
|
||||
|
||||
std::vector<Location> m_History;
|
||||
std::size_t m_HistoryIndex{0};
|
||||
std::unordered_map<std::string, std::vector<std::string>> m_Subfolders;
|
||||
|
||||
std::unordered_map<std::string, Thumbnail> m_Thumbnails;
|
||||
std::unordered_map<std::string, std::future<ThumbnailPixels>> m_PendingThumbnails;
|
||||
|
||||
std::filesystem::path m_Cooker;
|
||||
std::vector<std::string> m_CookSchemes;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include <editor/RectGizmo.h>
|
||||
#include <editor/ResourcesInspector.h>
|
||||
#include <editor/SceneInspector.h>
|
||||
#include <editor/SceneTree.h>
|
||||
#include <editor/ShaderHotReload.h>
|
||||
#include <editor/TransformGizmo.h>
|
||||
#include <editor/UndoStack.h>
|
||||
@@ -54,6 +55,7 @@ public:
|
||||
|
||||
private:
|
||||
struct Panels {
|
||||
bool sceneTree{true};
|
||||
bool inspector{true};
|
||||
bool assets{true};
|
||||
bool stats{true};
|
||||
@@ -118,6 +120,7 @@ private:
|
||||
EditorCamera m_Camera;
|
||||
PlayMode m_PlayMode;
|
||||
UndoStack m_UndoStack;
|
||||
SceneTree m_SceneTree;
|
||||
SceneInspector m_Inspector;
|
||||
AssetBrowser m_AssetBrowser;
|
||||
ResourcesInspector m_ResourcesInspector;
|
||||
@@ -137,6 +140,7 @@ private:
|
||||
bool m_ItemWasActive{false};
|
||||
bool m_EditPending{false};
|
||||
bool m_CameraHadInput{false};
|
||||
bool m_DockLayoutChecked{false};
|
||||
};
|
||||
|
||||
#endif // EDITOR_EDITOR_H
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
@@ -15,44 +14,17 @@ class Scene;
|
||||
|
||||
class SceneInspector final {
|
||||
public:
|
||||
void Draw(Scene& scene, ObjectId& selectedObjectId, const std::function<void()>& drawSceneSettings, bool* open);
|
||||
void Draw(Scene& scene, ObjectId selectedObjectId, const std::function<void()>& drawSceneSettings, bool* open);
|
||||
|
||||
private:
|
||||
struct PendingMove {
|
||||
ObjectId object{InvalidObjectId};
|
||||
ObjectId parent{InvalidObjectId};
|
||||
ObjectId anchor{InvalidObjectId};
|
||||
bool after{false};
|
||||
};
|
||||
|
||||
void DrawHierarchy(Scene& scene, ObjectId& selectedObjectId);
|
||||
void DrawNode(Scene& scene, GameObject& object, ObjectId& selectedObjectId, std::unordered_set<const GameObject*>& visited);
|
||||
void DrawRenameField(GameObject& object);
|
||||
void DrawNodeDragDrop(GameObject& object);
|
||||
void DrawObjectMenu(Scene& scene, GameObject* object, ObjectId& selectedObjectId);
|
||||
void HandleShortcuts(Scene& scene, ObjectId& selectedObjectId);
|
||||
void ApplyPendingActions(Scene& scene, ObjectId& selectedObjectId);
|
||||
|
||||
void DrawObject(GameObject& object);
|
||||
void DrawTransform(GameObject& object);
|
||||
void DrawComponents(GameObject& object);
|
||||
void DrawComponentMenu(GameObject& object, Component& component, std::size_t index, bool removable);
|
||||
void DrawAddComponent(GameObject& object);
|
||||
|
||||
void BeginRename(const GameObject& object);
|
||||
|
||||
std::string m_Filter;
|
||||
std::string m_ComponentFilter;
|
||||
|
||||
ObjectId m_RenamingId{InvalidObjectId};
|
||||
std::string m_RenameBuffer;
|
||||
bool m_FocusRename{false};
|
||||
|
||||
ObjectId m_OpenNextFrame{InvalidObjectId};
|
||||
PendingMove m_PendingMove;
|
||||
ObjectId m_PendingDelete{InvalidObjectId};
|
||||
ObjectId m_PendingDuplicate{InvalidObjectId};
|
||||
|
||||
std::string m_ClipboardType;
|
||||
nlohmann::json m_Clipboard;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
#ifndef EDITOR_SCENETREE_H
|
||||
#define EDITOR_SCENETREE_H
|
||||
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
#include <destrum/ObjectModel/ObjectId.h>
|
||||
|
||||
class GameObject;
|
||||
class Scene;
|
||||
|
||||
class SceneTree final {
|
||||
public:
|
||||
void Draw(Scene& scene, ObjectId& selectedObjectId, bool* open);
|
||||
|
||||
private:
|
||||
struct PendingMove {
|
||||
ObjectId object{InvalidObjectId};
|
||||
ObjectId parent{InvalidObjectId};
|
||||
ObjectId anchor{InvalidObjectId};
|
||||
bool after{false};
|
||||
};
|
||||
|
||||
void DrawHierarchy(Scene& scene, ObjectId& selectedObjectId);
|
||||
void DrawNode(Scene& scene, GameObject& object, ObjectId& selectedObjectId, std::unordered_set<const GameObject*>& visited);
|
||||
void DrawRenameField(GameObject& object);
|
||||
void DrawNodeDragDrop(GameObject& object);
|
||||
void DrawObjectMenu(Scene& scene, GameObject* object, ObjectId& selectedObjectId);
|
||||
void HandleShortcuts(Scene& scene, ObjectId& selectedObjectId);
|
||||
void ApplyPendingActions(Scene& scene, ObjectId& selectedObjectId);
|
||||
|
||||
void BeginRename(const GameObject& object);
|
||||
|
||||
std::string m_Filter;
|
||||
|
||||
ObjectId m_RenamingId{InvalidObjectId};
|
||||
std::string m_RenameBuffer;
|
||||
bool m_FocusRename{false};
|
||||
|
||||
ObjectId m_OpenNextFrame{InvalidObjectId};
|
||||
PendingMove m_PendingMove;
|
||||
ObjectId m_PendingDelete{InvalidObjectId};
|
||||
ObjectId m_PendingDuplicate{InvalidObjectId};
|
||||
};
|
||||
|
||||
#endif // EDITOR_SCENETREE_H
|
||||
Reference in New Issue
Block a user