fix display of cylinder

This commit is contained in:
AndreaRigoni
2026-03-27 15:23:59 +00:00
parent e40cc77a5f
commit fa7c0f670e
3 changed files with 33 additions and 21 deletions

View File

@@ -55,17 +55,12 @@ void vtkCylinder::contentUpdate() {
vtkProp3D* root = vtkProp3D::SafeDownCast(this->GetProp());
if (!root) return;
// 1. Placement (Position/Rotation/Model-level Scale) goes to the root prop
vtkMatrix4x4* vmat = root->GetUserMatrix();
if (!vmat) {
vtkNew<vtkMatrix4x4> mat;
root->SetUserMatrix(mat);
vmat = mat;
}
Matrix4f transform = m_Content->GetMatrix();
Matrix4fToVtk(transform, vmat);
// 1. Placement handled by base Puppet class via Sync / Update logic
// Update internal pd->m_Transform from content
Puppet::Update();
// 2. Shape-local properties (Radius, Height, Axis alignment) go to the internal actor
// These are relative to the root assembly
vtkTransform* alignment = vtkTransform::SafeDownCast(m_Actor->GetUserTransform());
if (alignment) {
alignment->Identity();
@@ -83,23 +78,29 @@ void vtkCylinder::contentUpdate() {
}
root->Modified();
Puppet::Update();
}
void vtkCylinder::Update() {
this->contentUpdate();
}
void vtkCylinder::SyncFromVtk() {
if (!m_Content) return;
vtkProp3D* root = vtkProp3D::SafeDownCast(this->GetProp());
if (!root) return;
vtkProp3D* assembly = vtkProp3D::SafeDownCast(this->GetProp());
if (!assembly) return;
vtkMatrix4x4* vmat = root->GetUserMatrix();
if (!vmat) return;
double pos[3], ori[3], scale[3];
assembly->GetPosition(pos);
assembly->GetOrientation(ori);
assembly->GetScale(scale);
// Pull the placement matrix directly from VTK
Matrix4f transform = VtkToMatrix4f(vmat);
m_Content->SetMatrix(transform);
m_Content->SetPosition(Vector3f(pos[0], pos[1], pos[2]));
// Convert VTK degrees to model radians
m_Content->SetOrientation(Vector3f(ori[0], ori[1], ori[2]) * CLHEP::degree);
m_Content->SetScale(Vector3f(scale[0], scale[1], scale[2]));
m_Content->Updated();
m_Content->Updated(); // Notify change
}
void vtkCylinder::InstallPipe() {

View File

@@ -52,7 +52,10 @@ public:
virtual void contentUpdate();
/** Synchronizes the uLib model matrix with the VTK actor (e.g., after UI manipulation) */
virtual void Update();
virtual void Update() override;
/** Synchronizes the uLib model matrix with the VTK actor specifically for gizmo interactions */
virtual void SyncFromVtk() override;
virtual uLib::Object* GetContent() const override { return (uLib::Object*)m_Content; }

View File

@@ -121,6 +121,7 @@ public:
TRS m_Transform;
void ApplyAppearance(vtkProp *p) {
if (!p) return;
p->SetVisibility(m_Visibility);
p->SetPickable(m_Selectable);
p->SetDragable(m_Dragable);
@@ -143,6 +144,13 @@ public:
if (m_Opacity != -1.0) {
actor->GetProperty()->SetOpacity(m_Opacity);
}
} else if (vtkAssembly *asm_p = vtkAssembly::SafeDownCast(p)) {
// Recursively apply to parts of the assembly
vtkProp3DCollection *parts = asm_p->GetParts();
parts->InitTraversal();
for (int i = 0; i < parts->GetNumberOfItems(); ++i) {
this->ApplyAppearance(parts->GetNextProp3D());
}
}
}