Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GUI.Component] ConstraintAttachBodyPerformer: Add RigidType support #4801

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ namespace sofa::gui::component::performer
template class SOFA_GUI_COMPONENT_API ConstraintAttachBodyPerformer<defaulttype::Vec3Types>;
helper::Creator<InteractionPerformer::InteractionPerformerFactory, ConstraintAttachBodyPerformer<defaulttype::Vec3Types> > ConstraintAttachBodyPerformerVec3dClass("ConstraintAttachBody",true);

} // namespace sofa::gui::component::performer
template class SOFA_GUI_COMPONENT_API ConstraintAttachBodyPerformer<defaulttype::RigidTypes>;
helper::Creator<InteractionPerformer::InteractionPerformerFactory, ConstraintAttachBodyPerformer<defaulttype::RigidTypes> > ConstraintAttachBodyPerformerRigidClass("ConstraintAttachBody",true);

} // namespace sofa::gui::component::performer
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class ConstraintAttachBodyPerformer: public BaseAttachBodyPerformer<DataTypes>

#if !defined(SOFA_COMPONENT_COLLISION_CONSTRAINTATTACHBODYPERFORMER_CPP)
extern template class SOFA_GUI_COMPONENT_API ConstraintAttachBodyPerformer<defaulttype::Vec3Types>;
extern template class SOFA_GUI_COMPONENT_API ConstraintAttachBodyPerformer<defaulttype::RigidTypes>;
#endif

} // namespace sofa::gui::component::performer
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <sofa/core/visual/VisualParams.h>
#include <sofa/core/BaseMapping.h>
#include <sofa/simulation/Node.h>
#include <sofa/type/isRigidType.h>

namespace sofa::gui::component::performer
{
Expand Down Expand Up @@ -52,12 +53,13 @@ bool ConstraintAttachBodyPerformer<DataTypes>::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())
Expand Down Expand Up @@ -89,22 +91,38 @@ bool ConstraintAttachBodyPerformer<DataTypes>::startPartial(const BodyPicked& pi
m_mstate1 = dynamic_cast<MouseContainer*>(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<BilateralLagrangianConstraint<DataTypes> >(m_mstate1, m_mstate2);
auto* bconstraint = dynamic_cast< BilateralLagrangianConstraint< DataTypes >* >(this->m_interactionObject.get());

bakpaul marked this conversation as resolved.
Show resolved Hide resolved
this->m_interactionObject = sofa::core::objectmodel::New<BilateralLagrangianConstraint<sofa::defaulttype::Vec3Types> >(m_mstate1, m_mstate2);
auto* bconstraint = dynamic_cast< BilateralLagrangianConstraint< sofa::defaulttype::Vec3Types >* >(this->m_interactionObject.get());
if constexpr (sofa::type::isRigidType<DataTypes>())
{
// BilateralLagrangianConstraint::d_keepOrientDiff is protected
auto* keepOrientDiffBaseData = bconstraint->findData("keepOrientationDifference");
assert(keepOrientDiffBaseData);
auto* keepOrientDiffData = dynamic_cast<Data<bool>*>(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);
Expand Down
Loading