transform properties
This commit is contained in:
@@ -41,6 +41,7 @@
|
||||
#include <vtkVersion.h>
|
||||
#include "vtkViewport.h"
|
||||
#include "uLibVtkInterface.h"
|
||||
#include "Math/Transform.h"
|
||||
#include <vtkActor.h>
|
||||
#include <vtkPolyDataMapper.h>
|
||||
#include <vtkProperty.h>
|
||||
@@ -484,7 +485,7 @@ void Puppet::SetSelected(bool selected)
|
||||
if (!pd->m_Selectable) return;
|
||||
if (pd->m_Selected == selected) return;
|
||||
pd->m_Selected = selected;
|
||||
pd->UpdateHighlight();
|
||||
pd->UpdateHighlight();0
|
||||
}
|
||||
|
||||
bool Puppet::IsSelected() const
|
||||
@@ -498,8 +499,25 @@ void Puppet::Update()
|
||||
if (root) {
|
||||
pd->ApplyAppearance(root);
|
||||
|
||||
// Apply transformation if it's a Prop3D
|
||||
if (auto* p3d = vtkProp3D::SafeDownCast(root)) {
|
||||
// Handle transformation synchronization from content
|
||||
if (auto* content = dynamic_cast<uLib::AffineTransform*>(GetContent())) {
|
||||
pd->m_Position = content->GetPosition().cast<double>();
|
||||
pd->m_Orientation = content->GetOrientation().cast<double>();
|
||||
pd->m_Scale = content->GetScale().cast<double>();
|
||||
|
||||
if (auto* p3d = vtkProp3D::SafeDownCast(root)) {
|
||||
vtkNew<vtkMatrix4x4> vmat;
|
||||
const Matrix4f& emat = content->GetMatrix();
|
||||
for(int i=0; i<4; ++i) for(int j=0; j<4; ++j) vmat->SetElement(i, j, emat(i,j));
|
||||
p3d->SetUserMatrix(vmat);
|
||||
|
||||
// Clear base transform to avoid double-application
|
||||
p3d->SetPosition(0,0,0);
|
||||
p3d->SetOrientation(0,0,0);
|
||||
p3d->SetScale(1,1,1);
|
||||
}
|
||||
}
|
||||
else if (auto* p3d = vtkProp3D::SafeDownCast(root)) {
|
||||
p3d->SetPosition(pd->m_Position.data());
|
||||
p3d->SetOrientation(pd->m_Orientation.data());
|
||||
p3d->SetScale(pd->m_Scale.data());
|
||||
@@ -539,23 +557,42 @@ void Puppet::Update()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Puppet::SyncFromVtk()
|
||||
{
|
||||
vtkProp* root = this->GetProp();
|
||||
if (auto* p3d = vtkProp3D::SafeDownCast(root)) {
|
||||
double pos[3], ori[3], scale[3];
|
||||
p3d->GetPosition(pos);
|
||||
p3d->GetOrientation(ori);
|
||||
p3d->GetScale(scale);
|
||||
|
||||
// Update properties
|
||||
for (int i=0; i<3; ++i) {
|
||||
pd->m_Position(i) = pos[i];
|
||||
pd->m_Orientation(i) = ori[i];
|
||||
pd->m_Scale(i) = scale[i];
|
||||
// Handle content synchronization if it's an AffineTransform
|
||||
if (auto* content = dynamic_cast<uLib::AffineTransform*>(GetContent())) {
|
||||
vtkMatrix4x4* vmat = p3d->GetUserMatrix();
|
||||
if (vmat) {
|
||||
Matrix4f emat;
|
||||
for (int i=0; i<4; ++i)
|
||||
for (int j=0; j<4; ++j)
|
||||
emat(i, j) = vmat->GetElement(i, j);
|
||||
content->SetMatrix(emat);
|
||||
|
||||
// Re-sync internal puppet properties from the now-updated content
|
||||
pd->m_Position = content->GetPosition().cast<double>();
|
||||
pd->m_Orientation = content->GetOrientation().cast<double>();
|
||||
pd->m_Scale = content->GetScale().cast<double>();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Update internal puppet properties directly from base components
|
||||
// only if no content exists (old behavior)
|
||||
double pos[3], ori[3], scale[3];
|
||||
p3d->GetPosition(pos);
|
||||
p3d->GetOrientation(ori);
|
||||
p3d->GetScale(scale);
|
||||
for (int i=0; i<3; ++i) {
|
||||
pd->m_Position(i) = pos[i];
|
||||
pd->m_Orientation(i) = ori[i];
|
||||
pd->m_Scale(i) = scale[i];
|
||||
}
|
||||
}
|
||||
|
||||
// Get the properties from the object
|
||||
// Notify puppet properties updated
|
||||
if (auto* propPos = this->GetProperty("Position")) propPos->Updated();
|
||||
if (auto* propOri = this->GetProperty("Orientation")) propOri->Updated();
|
||||
if (auto* propScale = this->GetProperty("Scale")) propScale->Updated();
|
||||
|
||||
Reference in New Issue
Block a user