feat: add TRS serialization and display property support to MultiSelectionProp

This commit is contained in:
AndreaRigoni
2026-04-10 21:44:18 +00:00
parent e320c932d2
commit bf4006ff91
4 changed files with 56 additions and 9 deletions

View File

@@ -569,6 +569,18 @@ void Prop3D::SetOpacity(double alpha)
pd->ApplyAppearance(pd->m_Prop);
}
void Prop3D::GetColor(double &r, double &g, double &b) const
{
r = pd->m_Color[0];
g = pd->m_Color[1];
b = pd->m_Color[2];
}
double Prop3D::GetOpacity() const
{
return pd->m_Opacity;
}

View File

@@ -86,8 +86,10 @@ public:
void DisonnectViewer(Viewer *viewer);
void SetColor(double r, double g, double b);
void GetColor(double &r, double &g, double &b) const;
void SetOpacity(double alpha);
double GetOpacity() const;
void SetSelectable(bool selectable = true);
bool IsSelectable() const;

View File

@@ -1,3 +1,4 @@
#include "uLibVtkInterface.h"
#include "vtkMultiSelectionProp.h"
#include <vtkActor.h>
#include <vtkPolyDataMapper.h>
@@ -13,17 +14,19 @@ namespace uLib {
namespace Vtk {
MultiSelectionProp::MultiSelectionProp() : Prop3D() {
this->SetInstanceName("Selection Group");
((::uLib::Object*)this)->SetInstanceName("Selection Group");
m_PrevMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
m_GroupHighlightActor = vtkSmartPointer<vtkActor>::New();
vtkNew<vtkPolyDataMapper> mapper;
m_GroupHighlightActor->SetMapper(mapper);
m_GroupHighlightActor->GetProperty()->SetRepresentationToWireframe();
m_GroupHighlightActor->GetProperty()->SetColor(0.0, 1.0, 0.0); // Green for group
m_GroupHighlightActor->GetProperty()->SetLineWidth(2.0);
m_GroupHighlightActor->GetProperty()->SetLighting(0);
m_GroupHighlightActor->PickableOff();
// Set default display color in Prop3D state
((Prop3D*)this)->SetColor(0.0, 1.0, 0.0);
}
MultiSelectionProp::~MultiSelectionProp() {
@@ -32,7 +35,7 @@ MultiSelectionProp::~MultiSelectionProp() {
MultiSelectionProp* MultiSelectionProp::Clone() const {
auto* copy = new MultiSelectionProp();
copy->SetMembers(this->m_Members);
copy->SetInstanceName(this->GetInstanceName());
((::uLib::Object*)copy)->SetInstanceName(((::uLib::Object*)this)->GetInstanceName());
return copy;
}
@@ -88,13 +91,22 @@ void MultiSelectionProp::Update() {
mapper->SetInputConnection(cube->GetOutputPort());
}
// The highlight actor itself should have identity user matrix initially,
// as it's defined in world space bounds.
m_GroupHighlightActor->SetUserMatrix(nullptr);
m_PrevMatrix->Identity();
// Apply TRS from m_SelectionTransform
vtkNew<vtkMatrix4x4> trsMatrix;
Matrix4fToVtk(m_SelectionTransform.GetWorldMatrix(), trsMatrix);
m_GroupHighlightActor->SetUserMatrix(trsMatrix);
// Apply Display Properties (Color, Opacity)
double r, g, b;
((Prop3D*)this)->GetColor(r, g, b);
m_GroupHighlightActor->GetProperty()->SetColor(r, g, b);
m_GroupHighlightActor->GetProperty()->SetOpacity(((Prop3D*)this)->GetOpacity());
// Update Prev Matrix for delta calculations
m_PrevMatrix->DeepCopy(trsMatrix);
// Ensure it's in the renderers
vtkRendererCollection* rens = this->GetRenderers();
vtkRendererCollection* rens = ((Prop3D*)this)->GetRenderers();
rens->InitTraversal();
for (int i = 0; i < rens->GetNumberOfItems(); ++i) {
vtkRenderer* ren = rens->GetNextItem();
@@ -126,7 +138,6 @@ void MultiSelectionProp::SyncFromVtk() {
vtkMatrix4x4::Multiply4x4(delta, memberWorldMatrix, nextWorldMatrix);
// Set the new world matrix.
// We need to calculate the new local matrix if there's a parent.
if (tr->GetParent()) {
Matrix4f invParentWorld = tr->GetParent()->GetWorldMatrix().inverse();
Matrix4f nextLocalMatrix = invParentWorld * VtkToMatrix4f(nextWorldMatrix);
@@ -140,6 +151,7 @@ void MultiSelectionProp::SyncFromVtk() {
}
m_PrevMatrix->DeepCopy(currentMatrix);
m_SelectionTransform.FromMatrix(VtkToMatrix4f(currentMatrix));
}
vtkProp* MultiSelectionProp::GetProp() {
@@ -150,5 +162,14 @@ vtkProp3D* MultiSelectionProp::GetProxyProp() {
return m_GroupHighlightActor;
}
void MultiSelectionProp::serialize(Archive::property_register_archive &ar, const unsigned int version) {
ar & boost::serialization::make_nvp("Transform", m_SelectionTransform);
}
void MultiSelectionProp::serialize_display(uLib::Archive::display_properties_archive &ar, const unsigned int version) {
// Call base class to register standard display properties (Color, Opacity)
((Prop3D*)this)->serialize_display(ar, version);
}
} // namespace Vtk
} // namespace uLib

View File

@@ -2,6 +2,7 @@
#define ULIB_VTK_MULTISELECTIONPROP_H
#include "uLibVtkInterface.h"
#include "Math/Transform.h"
#include <vector>
#include <vtkSmartPointer.h>
#include <vtkMatrix4x4.h>
@@ -37,10 +38,21 @@ public:
virtual vtkProp* GetProp() override;
virtual vtkProp3D* GetProxyProp() override;
// Serialization for Properties Panel (TRS)
void serialize(Archive::property_register_archive &ar, const unsigned int version);
// Serialization for Display Properties Panel (Color, Opacity)
void serialize_display(uLib::Archive::display_properties_archive &ar, const unsigned int version = 0) override;
virtual uLib::Object* GetContent() const override { return const_cast<MultiSelectionProp*>(this); }
private:
std::vector<Prop3D*> m_Members;
uLib::TRS m_SelectionTransform;
vtkSmartPointer<vtkMatrix4x4> m_PrevMatrix;
vtkSmartPointer<vtkActor> m_GroupHighlightActor;
};
} // namespace Vtk