@@ -36,8 +36,12 @@ namespace Tetragrama::Components
3636
3737 void HierarchyViewUIComponent::Update (ZEngine::Core::TimeStep dt)
3838 {
39+ if (!ParentLayer)
40+ {
41+ return ;
42+ }
3943
40- if (ParentLayer && ParentLayer ->ParentWindow )
44+ if (ParentLayer->ParentWindow )
4145 {
4246 auto window = ParentLayer->ParentWindow ;
4347 if (IDevice::As<Keyboard>()->IsKeyPressed (ZENGINE_KEY_T, window))
@@ -55,6 +59,84 @@ namespace Tetragrama::Components
5559 m_gizmo_operation = ImGuizmo::OPERATION::SCALE;
5660 }
5761 }
62+
63+ if (ParentLayer->ParentContext )
64+ {
65+ auto ctx = reinterpret_cast <EditorContext*>(ParentLayer->ParentContext );
66+ auto current_scene = ctx->CurrentScenePtr ;
67+
68+ Managers::AssetManager::AssetHandle handle = {};
69+ if (ctx->PendingOnLoadHierarchies ->Pop (handle))
70+ {
71+ Importers::AssetNodeHierarchy* mesh_node_hierarchy = Managers::AssetManager::GetAsset<Importers::AssetNodeHierarchy>(handle);
72+ if (!mesh_node_hierarchy)
73+ {
74+ return ;
75+ }
76+
77+ struct StackEntry
78+ {
79+ int Parent = -1 ;
80+ int Depth = -1 ;
81+ int node_id = -1 ;
82+ };
83+
84+ for (int i = 0 ; i < mesh_node_hierarchy->Hierarchies .size (); ++i)
85+ {
86+ if (mesh_node_hierarchy->Hierarchies [i].Parent == -1 )
87+ {
88+ std::stack<StackEntry> stack;
89+ stack.push ({0 , 1 , i});
90+
91+ while (!stack.empty ())
92+ {
93+ auto entry = stack.top ();
94+ stack.pop ();
95+
96+ if (entry.node_id == -1 )
97+ {
98+ continue ;
99+ }
100+
101+ auto node_ref = Importers::AssetNodeRef{.AssetNodeHandle = handle, .NodeHierarchyIndex = entry.node_id };
102+ if (mesh_node_hierarchy->NodeNames .contains (entry.node_id ))
103+ {
104+ auto name_idx = mesh_node_hierarchy->NodeNames [entry.node_id ];
105+ node_ref.Name = mesh_node_hierarchy->Names [name_idx].c_str ();
106+ }
107+
108+ int scene_node_id = current_scene->CreateSceneNode (entry.Parent , entry.Depth , node_ref);
109+
110+ const auto & node = mesh_node_hierarchy->Hierarchies [entry.node_id ];
111+ bool has_children = (node.FirstChild != -1 );
112+
113+ if (has_children)
114+ {
115+ // Push TreePop manually
116+ stack.push ({-1 }); // Marker for TreePop
117+
118+ // Push children in reverse order
119+ auto scratch = ZGetScratch (&ParentLayer->LocalArena );
120+ ZEngine::Core::Containers::Array<int > children;
121+ children.init (scratch.Arena , 5 );
122+
123+ for (int child = node.FirstChild ; child != -1 ; child = mesh_node_hierarchy->Hierarchies [child].RightSibling )
124+ {
125+ children.push (child);
126+ }
127+
128+ for (int i = static_cast <int >(children.size ()) - 1 ; i >= 0 ; --i)
129+ {
130+ stack.push ({scene_node_id, (entry.Depth + 1 ), children[i]});
131+ }
132+
133+ ZReleaseScratch (scratch);
134+ }
135+ }
136+ }
137+ }
138+ }
139+ }
58140 }
59141
60142 void HierarchyViewUIComponent::Render (ZEngine::Rendering::Renderers::GraphicRenderer* const renderer, ZEngine::Hardwares::CommandBuffer* const command_buffer)
0 commit comments