refactor: prevent update loops in vtkCylinder by tracking connection and blocking signals during sync
This commit is contained in:
@@ -40,7 +40,7 @@ namespace Vtk {
|
||||
vtkCylinder::vtkCylinder(vtkCylinder::Content *content)
|
||||
: m_Content(content), m_Actor(nullptr), m_VtkAsm(nullptr) {
|
||||
this->InstallPipe();
|
||||
Object::connect(m_Content, &uLib::Object::Updated, this, &vtkCylinder::Update);
|
||||
m_UpdateSignal = Object::connect(m_Content, &uLib::Object::Updated, this, &vtkCylinder::Update);
|
||||
}
|
||||
|
||||
vtkCylinder::~vtkCylinder() {
|
||||
@@ -80,23 +80,31 @@ void vtkCylinder::Update() {
|
||||
root->Modified();
|
||||
}
|
||||
|
||||
// Use base class sync, which handles appearance and children
|
||||
// Delegate rest of update (appearance, render, etc)
|
||||
ConnectionBlock blocker(m_UpdateSignal);
|
||||
this->Puppet::Update();
|
||||
}
|
||||
|
||||
void vtkCylinder::SyncFromVtk() {
|
||||
if (!m_Content) return;
|
||||
|
||||
vtkProp3D* assembly = this->GetProxyProp();
|
||||
if (!assembly) return;
|
||||
vtkProp3D* root = this->GetProxyProp();
|
||||
if (!root) return;
|
||||
|
||||
// VTK -> Model: Update TRS properties from VTK matrix via world transform
|
||||
m_Content->SetWorldMatrix(VtkToMatrix4f(assembly->GetUserMatrix()));
|
||||
// VTK -> Model: Extract new world TRS from proxy
|
||||
vtkMatrix4x4* rootMat = root->GetUserMatrix();
|
||||
if (rootMat) {
|
||||
std::cout << "[vtkCylinder::SyncFromVtk] Read Proxy UserMatrix:" << std::endl;
|
||||
rootMat->Print(std::cout);
|
||||
}
|
||||
|
||||
// Resync TRS property members (pos/rot/scale) from the newly set local matrix
|
||||
m_Content->FromMatrix(m_Content->GetMatrix());
|
||||
Matrix4f vtkWorld = VtkToMatrix4f(rootMat);
|
||||
|
||||
// Since we modified the model, notify observers, but block the loop back to VTK
|
||||
// Directly sync model from the world matrix
|
||||
m_Content->FromMatrix(vtkWorld);
|
||||
|
||||
std::cout << "[vtkCylinder::SyncFromVtk] New Model WorldMatrix:" << std::endl << m_Content->GetWorldMatrix() << std::endl;
|
||||
|
||||
m_Content->Updated();
|
||||
}
|
||||
|
||||
|
||||
@@ -63,6 +63,7 @@ protected:
|
||||
vtkActor *m_Actor;
|
||||
::vtkAssembly *m_VtkAsm;
|
||||
Content *m_Content;
|
||||
uLib::Connection m_UpdateSignal;
|
||||
};
|
||||
|
||||
} // namespace Vtk
|
||||
|
||||
Reference in New Issue
Block a user