refactor: Enhance VTK puppet lifecycle management by explicitly handling puppet removal and synchronizing puppets across all viewports, and remove default scene objects from startup.

This commit is contained in:
AndreaRigoni
2026-03-22 13:20:44 +00:00
parent 324aaa91b7
commit d87f3a984e
3 changed files with 47 additions and 17 deletions

View File

@@ -86,7 +86,7 @@ void ContextPanel::setContext(uLib::ObjectsContext* context) {
delete m_vtkContext;
}
m_vtkContext = new uLib::Vtk::vtkObjectsContext(context);
m_vtkView->AddPuppet(*m_vtkContext);
// m_vtkView->AddPuppet(*m_vtkContext); // redundant: child puppets are added individually
// Render viewport and add child puppets when context is updated
if (context) {
@@ -98,6 +98,13 @@ void ContextPanel::setContext(uLib::ObjectsContext* context) {
}
});
uLib::Object::connect(m_vtkContext, &uLib::Vtk::vtkObjectsContext::PuppetRemoved, [this](uLib::Vtk::Puppet* p) {
if (this->m_vtkView && p) {
this->m_vtkView->RemovePuppet(*p);
this->m_vtkView->Render();
}
});
// Add any puppets that were created during m_vtkContext's construction
for (auto* obj : context->GetObjects()) {
if (auto* p = m_vtkContext->GetPuppet(obj)) {