diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.cpp b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.cpp index 40eed76a114..60b2ff000c6 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.cpp +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.cpp @@ -34,4 +34,7 @@ namespace sofa::gui::component::performer template class SOFA_GUI_COMPONENT_API ConstraintAttachBodyPerformer; helper::Creator > ConstraintAttachBodyPerformerVec3dClass("ConstraintAttachBody",true); -} // namespace sofa::gui::component::performer \ No newline at end of file +template class SOFA_GUI_COMPONENT_API ConstraintAttachBodyPerformer; +helper::Creator > ConstraintAttachBodyPerformerRigidClass("ConstraintAttachBody",true); + +} // namespace sofa::gui::component::performer diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.h b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.h index 8ade312f8cc..5d4b7a35cf8 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.h +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.h @@ -53,6 +53,7 @@ class ConstraintAttachBodyPerformer: public BaseAttachBodyPerformer #if !defined(SOFA_COMPONENT_COLLISION_CONSTRAINTATTACHBODYPERFORMER_CPP) extern template class SOFA_GUI_COMPONENT_API ConstraintAttachBodyPerformer; +extern template class SOFA_GUI_COMPONENT_API ConstraintAttachBodyPerformer; #endif } // namespace sofa::gui::component::performer diff --git a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.inl b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.inl index 02ac9f2e1c9..a64f733f7d2 100644 --- a/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.inl +++ b/Sofa/GUI/Component/src/sofa/gui/component/performer/ConstraintAttachBodyPerformer.inl @@ -25,6 +25,7 @@ #include #include #include +#include namespace sofa::gui::component::performer { @@ -52,12 +53,13 @@ bool ConstraintAttachBodyPerformer::startPartial(const BodyPicked& pi const std::string name = "contactMouse"; mstateCollision = this->m_mapper->createMapping(name.c_str()); this->m_mapper->resize(1); - - const typename DataTypes::Coord pointPicked=picked.point; + const int idx=picked.indexCollisionElement; + typename DataTypes::CPos pointPicked = picked.point; typename DataTypes::Real r=0.0; - - index = this->m_mapper->addPointB(pointPicked, idx, r); + typename DataTypes::Coord dofPicked; + DataTypes::setCPos(dofPicked, pointPicked); + index = this->m_mapper->addPointB(dofPicked, idx, r); this->m_mapper->update(); if (mstateCollision->getContext() != picked.body->getContext()) @@ -89,22 +91,38 @@ bool ConstraintAttachBodyPerformer::startPartial(const BodyPicked& pi m_mstate1 = dynamic_cast(this->m_interactor->getMouseContainer()); m_mstate2 = mstateCollision; - type::Vec3d point1; - type::Vec3d point2; - using sofa::component::constraint::lagrangian::model::BilateralLagrangianConstraint; + this->m_interactionObject = sofa::core::objectmodel::New >(m_mstate1, m_mstate2); + auto* bconstraint = dynamic_cast< BilateralLagrangianConstraint< DataTypes >* >(this->m_interactionObject.get()); - this->m_interactionObject = sofa::core::objectmodel::New >(m_mstate1, m_mstate2); - auto* bconstraint = dynamic_cast< BilateralLagrangianConstraint< sofa::defaulttype::Vec3Types >* >(this->m_interactionObject.get()); + if constexpr (sofa::type::isRigidType()) + { + // BilateralLagrangianConstraint::d_keepOrientDiff is protected + auto* keepOrientDiffBaseData = bconstraint->findData("keepOrientationDifference"); + assert(keepOrientDiffBaseData); + auto* keepOrientDiffData = dynamic_cast*>(keepOrientDiffBaseData); + assert(keepOrientDiffData); + + // setting "keepOrientDiffData" to True + // would avoid having the beam forced to be oriented with the world frame. + // But it is unstable in v24.12 so for now, we set to false. + keepOrientDiffData->setValue(false); + + bconstraint->init(); + } bconstraint->setName("Constraint-Mouse-Contact"); - type::Vec3d normal = point1-point2; - - bconstraint->addContact(normal, point1, point2, normal.norm(), 0, index, point2, point1); + static const typename DataTypes::Coord point1 {}; + static const typename DataTypes::Coord point2 {}; + static const typename DataTypes::Deriv normal {}; + bconstraint->addContact(normal, point1, point2, 0.0, 0, index, point2, point1); + + bconstraint->bwdInit(); + const core::objectmodel::TagSet &tags=mstateCollision->getTags(); for (auto tag : tags) bconstraint->addTag(tag);