@@ -26,7 +26,7 @@ void edit_material(NotClosed<Window> target, SceneResources const& resources, Li
26
26
make_id_slot (lit.emissive , " Emissive" , name.c_str (), {true });
27
27
}
28
28
29
- void edit_material (SceneResourcesMut resources, UnlitMaterial& unlit) {
29
+ void edit_material (SceneResources const & resources, UnlitMaterial& unlit) {
30
30
auto name = FixedString<128 >{};
31
31
if (unlit.texture ) { name = FixedString<128 >{" {} ({})" , resources.textures [*unlit.texture ].name (), *unlit.texture }; }
32
32
make_id_slot (unlit.texture , " Texture" , name.c_str (), {true });
@@ -57,12 +57,13 @@ void ResourceInspector::view(StaticMesh const& mesh, Id<StaticMesh> id) const {
57
57
}
58
58
59
59
void ResourceInspector::edit (Material& out_material, Id<Material> id) const {
60
- auto const name = FixedString<128 >{" {} ({})" , out_material.name , id};
60
+ auto const name = FixedString<128 >{" {} ({})" , out_material.name () , id};
61
61
auto tn = TreeNode{name.c_str ()};
62
62
drag_payload (id, name.c_str ());
63
63
if (tn) {
64
- if (auto * lit = dynamic_cast <LitMaterial*>(&out_material)) { return edit_material (m_target, m_resources, *lit); }
65
- if (auto * unlit = dynamic_cast <UnlitMaterial*>(&out_material)) { return edit_material (m_resources, *unlit); }
64
+ auto & mat = out_material.base ();
65
+ if (auto * lit = dynamic_cast <LitMaterial*>(&mat)) { return edit_material (m_target, m_resources, *lit); }
66
+ if (auto * unlit = dynamic_cast <UnlitMaterial*>(&mat)) { return edit_material (m_resources, *unlit); }
66
67
}
67
68
}
68
69
@@ -78,7 +79,7 @@ void ResourceInspector::edit(Mesh& out_mesh, Id<Mesh> id) const {
78
79
make_id_slot (primitive.static_mesh , " Static Mesh" , name.c_str ());
79
80
80
81
name = {};
81
- if (primitive.material ) { name = FixedString<128 >{" {} ({})" , m_resources.materials [*primitive.material ]-> name , *primitive.material }; }
82
+ if (primitive.material ) { name = FixedString<128 >{" {} ({})" , m_resources.materials [*primitive.material ]. name () , *primitive.material }; }
82
83
make_id_slot (primitive.material , " Material" , name.c_str (), {true });
83
84
84
85
if (small_button_red (" x###remove_primitive" )) { to_erase = index; }
@@ -95,46 +96,54 @@ void ResourceInspector::edit(Mesh& out_mesh, Id<Mesh> id) const {
95
96
}
96
97
}
97
98
98
- void SceneInspector::resources (std::string& out_name_buf ) const {
99
+ void SceneInspector::resources (Data& out_data ) const {
99
100
auto const ri = ResourceInspector{m_target, m_scene};
100
101
static constexpr auto flags_v = ImGuiTreeNodeFlags_Framed;
101
102
bool add_material{}, add_mesh{};
102
103
if (auto tn = TreeNode (" Textures" , flags_v)) {
103
- for (auto [texture, id] : enumerate(m_resources.textures )) { ri.view (texture, id); }
104
+ for (auto [texture, id] : enumerate(m_resources.textures . view () )) { ri.view (texture, id); }
104
105
}
105
106
if (auto tn = TreeNode (" Static Meshes" , flags_v)) {
106
- for (auto [static_mesh, id] : enumerate(m_resources.static_meshes )) { ri.view (static_mesh, id); }
107
+ for (auto [static_mesh, id] : enumerate(m_resources.static_meshes . view () )) { ri.view (static_mesh, id); }
107
108
}
108
109
if (auto tn = TreeNode (" Materials" , flags_v)) {
109
- for (auto [material, id] : enumerate(m_resources.materials )) { ri.edit (* material, id); }
110
+ for (auto [material, id] : enumerate(m_resources.materials . view ())) { ri.edit (material, id); }
110
111
if (ImGui::Button (" Add..." )) { add_material = true ; }
111
112
}
112
113
if (auto tn = TreeNode{" Meshes" , flags_v}) {
113
- for (auto [mesh, id] : enumerate(m_resources.meshes )) { ri.edit (mesh, id); }
114
+ for (auto [mesh, id] : enumerate(m_resources.meshes . view () )) { ri.edit (mesh, id); }
114
115
if (ImGui::Button (" Add..." )) { add_mesh = true ; }
115
116
}
116
117
117
118
if (add_material) { Popup::open (" Add Material" ); }
119
+ if (out_data.input_buffer .empty ()) { out_data.input_buffer .resize (128 , ' \0 ' ); }
120
+
121
+ if (auto popup = Popup{" Add Mesh" }) {
122
+ ImGui::InputText (" Name" , out_data.input_buffer .data (), out_data.input_buffer .size ());
123
+ if (ImGui::Button (" Add" ) && *out_data.input_buffer .c_str ()) {
124
+ m_scene.add (Mesh{.name = out_data.input_buffer .c_str ()});
125
+ Popup::close_current ();
126
+ }
127
+ }
128
+
118
129
if (add_mesh) { Popup::open (" Add Mesh" ); }
119
- if (out_name_buf.empty ()) { out_name_buf.resize (128 , ' \0 ' ); }
120
- auto open_popup = [&out_name_buf](char const * id, auto func) {
121
- if (auto popup = Popup{id}) {
122
- ImGui::InputText (" Name" , out_name_buf.data (), out_name_buf.size ());
123
- if (ImGui::Button (id)) {
124
- auto str = out_name_buf.c_str ();
125
- if (!*str) { return ; }
126
- func (str);
127
- Popup::close_current ();
130
+ if (auto popup = Popup{" Add Material" }) {
131
+ ImGui::InputText (" Name" , out_data.input_buffer .data (), out_data.input_buffer .size ());
132
+ static constexpr char const * mat_types_v[] = {" Lit" , " Unlit" };
133
+ static constexpr auto mat_types_size_v{static_cast <int >(std::size (mat_types_v))};
134
+ char const * mat_type = out_data.material_type >= 0 && out_data.material_type < mat_types_size_v ? mat_types_v[out_data.material_type ] : " Invalid" ;
135
+ ImGui::SliderInt (" Type" , &out_data.material_type , 0 , mat_types_size_v - 1 , mat_type);
136
+ if (ImGui::Button (" Add" ) && *out_data.input_buffer .c_str ()) {
137
+ auto mat = std::unique_ptr<MaterialBase>{};
138
+ switch (out_data.material_type ) {
139
+ case 0 : mat = std::make_unique<LitMaterial>(); break ;
140
+ case 1 : mat = std::make_unique<UnlitMaterial>(); break ;
128
141
}
142
+ mat->name = out_data.input_buffer .c_str ();
143
+ m_scene.add (Material{std::move (mat)});
144
+ Popup::close_current ();
129
145
}
130
- };
131
- auto push_material = [this ](std::string name) {
132
- auto mat = std::make_unique<LitMaterial>();
133
- mat->name = std::move (name);
134
- m_scene.add (std::move (mat));
135
- };
136
- open_popup (" Add Material" , [&push_material](char const * name) { push_material (name); });
137
- open_popup (" Add Mesh" , [this ](char const * name) { m_scene.add (Mesh{.name = name}); });
146
+ }
138
147
}
139
148
140
149
void SceneInspector::camera () const {
@@ -218,7 +227,7 @@ void SceneInspector::mesh(Node& out_node) const {
218
227
auto * mesh_id = out_node.find <Id<Mesh>>();
219
228
if (auto tn = TreeNode{" Mesh" , ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_Framed}) {
220
229
auto name = FixedString<128 >{};
221
- if (mesh_id) { name = FixedString<128 >{" {} ({})" , m_scene .find (*mesh_id)->name , *mesh_id}; }
230
+ if (mesh_id) { name = FixedString<128 >{" {} ({})" , m_resources. meshes .find (*mesh_id)->name , *mesh_id}; }
222
231
make_id_slot<Mesh>(out_node, " Mesh" , name.c_str ());
223
232
}
224
233
}
0 commit comments