|
1 | 1 | #pragma once |
2 | 2 | #include <facade/engine/editor/common.hpp> |
3 | | -#include <facade/scene/material.hpp> |
4 | | -#include <facade/scene/node.hpp> |
5 | | -#include <facade/util/nvec3.hpp> |
6 | | -#include <facade/util/rgb.hpp> |
7 | | -#include <limits> |
| 3 | +#include <facade/scene/scene.hpp> |
8 | 4 |
|
9 | | -namespace facade { |
10 | | -struct Camera; |
11 | | -struct Mesh; |
12 | | -struct Lights; |
13 | | -struct SceneResources; |
14 | | -class Scene; |
15 | | - |
16 | | -namespace editor { |
| 5 | +namespace facade::editor { |
| 6 | +/// |
| 7 | +/// \brief Base class for Inspectors. |
17 | 8 | /// |
18 | | -/// \brief Stateless ImGui helper to inspect / reflect various properties |
| 9 | +/// Inspectors are stateless ImGui helpers to view / edit various components, with drag-and-drop support. |
19 | 10 | /// |
20 | 11 | class Inspector { |
21 | | - public: |
22 | | - static constexpr auto min_v{-std::numeric_limits<float>::max()}; |
23 | | - static constexpr auto max_v{std::numeric_limits<float>::max()}; |
24 | | - |
| 12 | + protected: |
25 | 13 | /// |
26 | | - /// \brief Construct an Inspector instance |
| 14 | + /// \brief Construct an Inspector instance. |
27 | 15 | /// |
28 | 16 | /// Inspectors don't do anything on construction, constructors exist to enforce invariants instance-wide. |
29 | | - /// For all Inspectors, an existing Window target is required, Inspector instances will not create any |
| 17 | + /// For all Inspectors, an existing Window target is required, Inspector instances will not create any. |
30 | 18 | /// |
31 | | - Inspector(NotClosed<Window>) {} |
32 | | - |
33 | | - bool inspect(char const* label, glm::vec2& out_vec2, float speed = 1.0f, float lo = min_v, float hi = max_v) const; |
34 | | - bool inspect(char const* label, glm::vec3& out_vec3, float speed = 1.0f, float lo = min_v, float hi = max_v) const; |
35 | | - bool inspect(char const* label, glm::vec4& out_vec4, float speed = 1.0f, float lo = min_v, float hi = max_v) const; |
36 | | - bool inspect(char const* label, nvec3& out_vec3, float speed = 0.01f) const; |
37 | | - bool inspect(char const* label, glm::quat& out_quat) const; |
38 | | - bool inspect_rgb(char const* label, glm::vec3& out_rgb) const; |
39 | | - bool inspect(char const* label, Rgb& out_rgb) const; |
40 | | - bool inspect(Transform& out_transform, Bool& out_unified_scaling) const; |
41 | | - bool inspect(std::span<Transform> out_instances, Bool unfied_scaling) const; |
42 | | - bool inspect(Lights& out_lights) const; |
| 19 | + Inspector(NotClosed<Window> target, Scene& out_scene) : m_target(target), m_scene(out_scene), m_resources(out_scene.resources()) {} |
43 | 20 |
|
44 | | - private: |
45 | | - bool do_inspect(Transform& out_transform, Bool& out_unified_scaling, Bool scaling_toggle) const; |
| 21 | + NotClosed<Window> m_target; |
| 22 | + Scene& m_scene; |
| 23 | + SceneResourcesMut m_resources; |
46 | 24 | }; |
47 | 25 |
|
48 | | -class SceneInspector : public Inspector { |
| 26 | +/// |
| 27 | +/// \brief Inspector for resources in a Scene. |
| 28 | +/// |
| 29 | +/// Provides drag source (and target) for each resource viewed (and edited). |
| 30 | +/// |
| 31 | +class ResourceInspector : public Inspector { |
49 | 32 | public: |
50 | | - using Inspector::inspect; |
51 | | - |
52 | | - SceneInspector(NotClosed<Window> target, Scene& scene); |
| 33 | + ResourceInspector(NotClosed<Window> target, Scene& out_scene) : Inspector(target, out_scene) {} |
53 | 34 |
|
54 | | - bool inspect(NotClosed<TreeNode>, UnlitMaterial& out_material) const; |
55 | | - bool inspect(NotClosed<TreeNode> node, LitMaterial& out_material) const; |
56 | | - bool inspect(Id<Material> material_id) const; |
57 | | - bool inspect(Id<Mesh> mesh_id) const; |
58 | | - bool inspect(Id<Camera> camera_id) const; |
59 | | - |
60 | | - bool inspect(Id<Node> node_id, Bool& out_unified_scaling) const; |
| 35 | + /// |
| 36 | + /// \brief Inspect a Texture (read-only). |
| 37 | + /// \param texture Texture to inspect |
| 38 | + /// \param id Id of the Texture being inspected (used to create unique labels and drag payloads) |
| 39 | + /// |
| 40 | + void view(Texture const& texture, Id<Texture> id) const; |
| 41 | + /// |
| 42 | + /// \brief Inspect a StaticMesh (read-only). |
| 43 | + /// \param mesh the StaticMesh to inspect |
| 44 | + /// \param id Id of the StaticMesh being inspected (used to create unique labels and drag payloads) |
| 45 | + /// |
| 46 | + void view(StaticMesh const& mesh, Id<StaticMesh> id) const; |
61 | 47 |
|
62 | | - private: |
63 | | - Scene& m_scene; |
64 | | - NotClosed<Window> m_target; |
| 48 | + /// |
| 49 | + /// \brief Inspect a Material. |
| 50 | + /// \param out_material Material to inspect |
| 51 | + /// \param id Id of the Material being inspected (used to create unique labels and drag payloads) |
| 52 | + /// |
| 53 | + void edit(Material& out_material, Id<Material> id) const; |
| 54 | + /// |
| 55 | + /// \brief Inspect a Mesh. |
| 56 | + /// \param out_mesh Mesh to inspect |
| 57 | + /// \param id Id of the Mesh being inspected (used to create unique labels and drag payloads) |
| 58 | + /// |
| 59 | + void edit(Mesh& out_mesh, Id<Mesh> id) const; |
65 | 60 | }; |
66 | 61 |
|
67 | | -class ResourceInspector { |
| 62 | +/// |
| 63 | +/// \brief Inspector for Scene and its Nodes. |
| 64 | +/// |
| 65 | +/// Provides drag-and-drop support where applicable. |
| 66 | +/// Uses a framed TreeNode for each top level component. |
| 67 | +/// |
| 68 | +class SceneInspector : public Inspector { |
68 | 69 | public: |
69 | | - ResourceInspector(NotClosed<Window>, SceneResources const& resources); |
70 | | - |
71 | | - void display() const; |
72 | | - void display(Camera const& camera, std::size_t index, std::string_view prefix = {}) const; |
73 | | - void display(Texture const& texture, std::size_t index, std::string_view prefix = {}) const; |
74 | | - void display(Material const& material, std::size_t const index, std::string_view prefix = {}) const; |
75 | | - void display(Mesh const& mesh, std::size_t const index, std::string_view prefix = {}) const; |
76 | | - |
77 | | - private: |
78 | | - void display(LitMaterial const& lit) const; |
79 | | - void display(UnlitMaterial const& unlit) const; |
| 70 | + SceneInspector(NotClosed<Window> target, Scene& out_scene) : Inspector(target, out_scene) {} |
80 | 71 |
|
81 | | - SceneResources const& m_resources; |
| 72 | + /// |
| 73 | + /// \brief View/edit all resources. |
| 74 | + /// \param out_name_buf Persistent buffer for popups |
| 75 | + /// |
| 76 | + /// Uses ResourceInspector. |
| 77 | + /// |
| 78 | + void resources(std::string& out_name_buf) const; |
| 79 | + /// |
| 80 | + /// \brief Inspect the Scene's camera. |
| 81 | + /// |
| 82 | + void camera() const; |
| 83 | + /// |
| 84 | + /// \brief Inspect the Scene's lights. |
| 85 | + /// |
| 86 | + void lights() const; |
| 87 | + /// |
| 88 | + /// \brief Inspect a Node's Transform. |
| 89 | + /// \param out_node Node whose Transform to inspect |
| 90 | + /// \param out_unified_scaling Whether to use a single locked control for scale |
| 91 | + /// |
| 92 | + void transform(Node& out_node, Bool& out_unified_scaling) const; |
| 93 | + /// |
| 94 | + /// \brief Inspect a Node's instances. |
| 95 | + /// \param out_node Node whose instances to inspect |
| 96 | + /// \param unified_scaling Whether to use a single locked control for scale |
| 97 | + /// |
| 98 | + void instances(Node& out_node, Bool unified_scaling) const; |
| 99 | + /// |
| 100 | + /// \brief Inspect a Node's Id<Mesh>. |
| 101 | + /// \param out_node Node whose attachment to inspect |
| 102 | + /// |
| 103 | + void mesh(Node& out_node) const; |
| 104 | + /// |
| 105 | + /// \brief Inspect a Node and its attachments. |
| 106 | + /// \param node_id Id of Node to inspect |
| 107 | + /// |
| 108 | + /// Inspects Transform, instances, and Id<Mesh>. |
| 109 | + /// |
| 110 | + void node(Id<Node> node_id, Bool& out_unified_scaling) const; |
82 | 111 | }; |
83 | | -} // namespace editor |
84 | | -} // namespace facade |
| 112 | +} // namespace facade::editor |
0 commit comments