Skip to content

Commit ca5848a

Browse files
refresh hierarchy after spawning model
1 parent da5d4a5 commit ca5848a

3 files changed

Lines changed: 19 additions & 0 deletions

File tree

ICEBERG/include/Viewport.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ class Viewport : public Controller {
1313

1414
void setSelectedEntity(ICE::Entity e);
1515

16+
// True once after a model has been dropped into the viewport (the flag is cleared by the read),
17+
// signalling that the scene gained entities and the hierarchy needs rebuilding.
18+
bool entitySpawned();
19+
1620
private:
1721
std::shared_ptr<ICE::ICEEngine> m_engine;
1822
bool m_done = false;
@@ -23,6 +27,7 @@ class Viewport : public Controller {
2327
const double scroll_speed = 0.5;
2428
ImGuizmo::OPERATION m_guizmo_mode = ImGuizmo::TRANSLATE;
2529
ICE::Entity m_selected_entity = 0;
30+
bool m_entity_spawned = false;
2631
std::function<void()> m_entity_transformed_callback = [] {
2732
};
2833
std::function<void(ICE::Entity e)> m_entity_picked_callback = [](ICE::Entity) {

ICEBERG/src/Editor.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ bool Editor::update() {
5959
}
6060
m_audio_mixer.render();
6161
m_viewport->update();
62+
// A model dropped into the viewport spawns entities behind the Hierarchy's back: rebuild its
63+
// cached tree before it renders, so the new nodes show up on the same frame.
64+
if (m_viewport->entitySpawned()) {
65+
m_hierarchy->rebuildTree();
66+
}
6267
m_hierarchy->update();
6368
m_inspector->update();
6469
m_assets->update();

ICEBERG/src/Viewport.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ Viewport::Viewport(const std::shared_ptr<ICE::ICEEngine> &engine, const std::fun
100100
if (uid == NO_ASSET_ID)
101101
return;
102102
ICE::Entity e = m_engine->getProject()->getCurrentScene()->spawnTree(uid, m_engine->getAssetBank());
103+
// The spawn adds a whole node tree to the scene; the Hierarchy caches its view and has no
104+
// other way to learn about it.
105+
m_entity_spawned = true;
103106
m_entity_picked_callback(e);
104107
});
105108
}
@@ -161,3 +164,9 @@ bool Viewport::update() {
161164
void Viewport::setSelectedEntity(ICE::Entity e) {
162165
m_selected_entity = e;
163166
}
167+
168+
bool Viewport::entitySpawned() {
169+
bool spawned = m_entity_spawned;
170+
m_entity_spawned = false;
171+
return spawned;
172+
}

0 commit comments

Comments
 (0)