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)
|
vtkCylinder::vtkCylinder(vtkCylinder::Content *content)
|
||||||
: m_Content(content), m_Actor(nullptr), m_VtkAsm(nullptr) {
|
: m_Content(content), m_Actor(nullptr), m_VtkAsm(nullptr) {
|
||||||
this->InstallPipe();
|
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() {
|
vtkCylinder::~vtkCylinder() {
|
||||||
@@ -80,23 +80,31 @@ void vtkCylinder::Update() {
|
|||||||
root->Modified();
|
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();
|
this->Puppet::Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void vtkCylinder::SyncFromVtk() {
|
void vtkCylinder::SyncFromVtk() {
|
||||||
if (!m_Content) return;
|
if (!m_Content) return;
|
||||||
|
|
||||||
vtkProp3D* assembly = this->GetProxyProp();
|
vtkProp3D* root = this->GetProxyProp();
|
||||||
if (!assembly) return;
|
if (!root) return;
|
||||||
|
|
||||||
// VTK -> Model: Update TRS properties from VTK matrix via world transform
|
// VTK -> Model: Extract new world TRS from proxy
|
||||||
m_Content->SetWorldMatrix(VtkToMatrix4f(assembly->GetUserMatrix()));
|
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
|
Matrix4f vtkWorld = VtkToMatrix4f(rootMat);
|
||||||
m_Content->FromMatrix(m_Content->GetMatrix());
|
|
||||||
|
|
||||||
// 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();
|
m_Content->Updated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ protected:
|
|||||||
vtkActor *m_Actor;
|
vtkActor *m_Actor;
|
||||||
::vtkAssembly *m_VtkAsm;
|
::vtkAssembly *m_VtkAsm;
|
||||||
Content *m_Content;
|
Content *m_Content;
|
||||||
|
uLib::Connection m_UpdateSignal;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Vtk
|
} // namespace Vtk
|
||||||
|
|||||||
Reference in New Issue
Block a user