@@ -163,7 +163,7 @@ bool Inspector::do_inspect(Transform& out_transform, Bool& out_unified_scaling,
163163 return ret.value ;
164164}
165165
166- SceneInspector::SceneInspector (NotClosed<Window> target, Scene& scene) : Inspector(target), m_scene(scene) {}
166+ SceneInspector::SceneInspector (NotClosed<Window> target, Scene& scene) : Inspector(target), m_scene(scene), m_target(target) {}
167167
168168bool SceneInspector::inspect (NotClosed<TreeNode>, UnlitMaterial& out_material) const {
169169 auto ret = Modified{};
@@ -177,15 +177,14 @@ bool SceneInspector::inspect(NotClosed<TreeNode>, LitMaterial& out_material) con
177177 ret (ImGui::SliderFloat (" Roughness" , &out_material.roughness , 0 .0f , 1 .0f ));
178178 ret (inspect_rgb (" Albedo" , out_material.albedo ));
179179 if (out_material.base_colour || out_material.roughness_metallic ) {
180- if (auto tn = TreeNode{" Textures" }) {
181- if (out_material.base_colour ) {
182- auto const * tex = m_scene.find (*out_material.base_colour );
183- TreeNode::leaf (FixedString{" Albedo: {} ({})" , tex->name , *out_material.base_colour }.c_str ());
184- }
185- if (out_material.roughness_metallic ) {
186- auto const * tex = m_scene.find (*out_material.roughness_metallic );
187- TreeNode::leaf (FixedString{" Roughness-Metallic: {} ({})" , tex->name , *out_material.roughness_metallic }.c_str ());
188- }
180+ auto const ri = ResourceInspector{m_target, m_scene.resources ()};
181+ if (out_material.base_colour ) {
182+ auto const * tex = m_scene.find (*out_material.base_colour );
183+ ri.display (*tex, *out_material.base_colour , " Base Colour: " );
184+ }
185+ if (out_material.roughness_metallic ) {
186+ auto const * tex = m_scene.find (*out_material.roughness_metallic );
187+ ri.display (*tex, *out_material.roughness_metallic , " Roughness Metallic: " );
189188 }
190189 }
191190 return ret.value ;
@@ -228,4 +227,92 @@ bool SceneInspector::inspect(Id<Node> node_id, Bool& out_unified_scaling) const
228227 if (auto const * mesh_id = node->find <Id<Mesh>>()) { ret (inspect (*mesh_id)); }
229228 return ret.value ;
230229}
230+
231+ namespace {
232+ template <typename Named>
233+ void display_resource (Named const & named, std::size_t const index, std::string_view prefix = {}) {
234+ editor::TreeNode::leaf (FixedString<128 >{" {}{} ({})" , prefix, named.name (), index}.c_str ());
235+ }
236+ } // namespace
237+
238+ ResourceInspector::ResourceInspector (NotClosed<Window>, Scene::Resources const & resources) : m_resources(resources) {}
239+
240+ void ResourceInspector::display () const {
241+ static constexpr auto flags_v = ImGuiTreeNodeFlags_Framed;
242+ if (auto tn = editor::TreeNode (" Cameras" , flags_v)) {
243+ for (auto const [camera, index] : enumerate(m_resources.cameras )) { display (camera, index); }
244+ }
245+ if (auto tn = editor::TreeNode (" Samplers" , flags_v)) {
246+ for (auto const [sampler, index] : enumerate(m_resources.samplers )) { display_resource (sampler, index); }
247+ }
248+ if (auto tn = editor::TreeNode (" Textures" , flags_v)) {
249+ for (auto const [texture, index] : enumerate(m_resources.textures )) { display (texture, index); }
250+ }
251+ if (auto tn = editor::TreeNode (" Materials" , flags_v)) {
252+ for (auto const [material, index] : enumerate(m_resources.materials )) { display (*material, index); }
253+ }
254+ if (auto tn = editor::TreeNode (" Static Meshes" , flags_v)) {
255+ for (auto const [mesh, index] : enumerate(m_resources.static_meshes )) { display_resource (mesh, index); }
256+ }
257+ if (auto tn = editor::TreeNode (" Meshes" , flags_v)) {
258+ for (auto const [mesh, index] : enumerate(m_resources.meshes )) { display (mesh, index); }
259+ }
260+ }
261+
262+ void ResourceInspector::display (Camera const & camera, std::size_t index, std::string_view prefix) const {
263+ if (auto tn = editor::TreeNode{FixedString<128 >{" {}{} ({})" , prefix, camera.name , index}.c_str ()}) {
264+ auto const visitor = Visitor{
265+ [](Camera::Orthographic const & o) {
266+ ImGui::Text (" %s" , FixedString{" Near Plane: {}" , o.view_plane .near }.c_str ());
267+ ImGui::Text (" %s" , FixedString{" Far Plane: {}" , o.view_plane .near }.c_str ());
268+ },
269+ [](Camera::Perspective const & p) {
270+ ImGui::Text (" %s" , FixedString{" FoV: {}" , p.field_of_view }.c_str ());
271+ ImGui::Text (" %s" , FixedString{" Near Plane: {}" , p.view_plane .near }.c_str ());
272+ ImGui::Text (" %s" , FixedString{" Far Plane: {}" , p.view_plane .near }.c_str ());
273+ },
274+ };
275+ std::visit (visitor, camera.type );
276+ }
277+ }
278+
279+ void ResourceInspector::display (Texture const & texture, std::size_t index, std::string_view prefix) const {
280+ if (auto tn = editor::TreeNode{FixedString<128 >{" {}{} ({})" , prefix, texture.name (), index}.c_str ()}) {
281+ auto const view = texture.view ();
282+ editor::TreeNode::leaf (FixedString{" Extent: {}x{}" , view.extent .width , view.extent .height }.c_str ());
283+ editor::TreeNode::leaf (FixedString{" Mip levels: {}" , texture.mip_levels ()}.c_str ());
284+ auto const cs = texture.colour_space () == ColourSpace::eLinear ? " linear" : " sRGB" ;
285+ editor::TreeNode::leaf (FixedString{" Colour Space: {}" , cs}.c_str ());
286+ }
287+ }
288+
289+ void ResourceInspector::display (Material const & material, std::size_t const index, std::string_view prefix) const {
290+ if (auto tn = editor::TreeNode{FixedString<128 >{" {}{} ({})" , prefix, material.name , index}.c_str ()}) {
291+ if (auto const * lit = dynamic_cast <LitMaterial const *>(&material)) { return display (*lit); }
292+ if (auto const * unlit = dynamic_cast <UnlitMaterial const *>(&material)) { return display (*unlit); }
293+ }
294+ }
295+
296+ void ResourceInspector::display (Mesh const & mesh, std::size_t const index, std::string_view prefix) const {
297+ if (auto tn = editor::TreeNode{FixedString<128 >{" {}{} ({})" , prefix, mesh.name , index}.c_str ()}) {
298+ for (auto const primitive : mesh.primitives ) {
299+ display_resource (m_resources.static_meshes [primitive.static_mesh ], primitive.static_mesh , " Static Mesh: " );
300+ if (primitive.material ) { display (*m_resources.materials [*primitive.material ], *primitive.material , " Material: " ); }
301+ }
302+ }
303+ }
304+
305+ void ResourceInspector::display (LitMaterial const & lit) const {
306+ ImGui::Text (" Albedo: " );
307+ ImGui::SameLine ();
308+ ImGui::ColorButton (" Albedo" , {lit.albedo .x , lit.albedo .y , lit.albedo .z , 1 .0f });
309+ ImGui::Text (" %s" , FixedString{" Metallic: {:.2f}" , lit.metallic }.c_str ());
310+ ImGui::Text (" %s" , FixedString{" Roughness: {:.2f}" , lit.roughness }.c_str ());
311+ if (lit.base_colour ) { display (m_resources.textures [*lit.base_colour ], *lit.base_colour , " Base Colour: " ); }
312+ if (lit.roughness_metallic ) { display (m_resources.textures [*lit.roughness_metallic ], *lit.roughness_metallic , " Roughness Metallic: " ); }
313+ }
314+
315+ void ResourceInspector::display (UnlitMaterial const & unlit) const {
316+ if (unlit.texture ) { display (m_resources.textures [*unlit.texture ], *unlit.texture , " Texture: " ); }
317+ }
231318} // namespace facade::editor
0 commit comments