Skip to content

Commit 91cf90e

Browse files
committed
SpringFF should be directly in the scene, and just link to them to handle topological changes... not sure why
1 parent a786c67 commit 91cf90e

File tree

2 files changed

+31
-10
lines changed

2 files changed

+31
-10
lines changed

src/InfinyToolkit/InteractionTools/GrasperJawModel.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typedef sofa::core::behavior::MechanicalState< sofa::defaulttype::Vec3Types > me
4242
GrasperJawModel::GrasperJawModel()
4343
: BaseJawModel()
4444
, d_stiffness(initData(&d_stiffness, SReal(100.0), "stiffness", "jaw speed factor."))
45+
, l_springFF(initLink("springFF", "link to the spring forcefield used to mimic grasping interaction."))
4546
{
4647
}
4748

@@ -87,7 +88,9 @@ void GrasperJawModel::performAction()
8788
void GrasperJawModel::stopAction()
8889
{
8990
// clean springs
90-
m_forcefield->clear();
91+
if (l_springFF.get())
92+
l_springFF.get()->clear();
93+
9194
m_rawIds.clear();
9295
//activateImpl();
9396
}
@@ -115,20 +118,39 @@ void GrasperJawModel::stopSecondaryAction()
115118

116119
int GrasperJawModel::createStiffSpringFF()
117120
{
118-
std::cout << this->getName() << " + createStiffSpringFF()" << std::endl;
121+
if (m_jaw == nullptr)
122+
{
123+
msg_error() << " Error createStiffSpringFF, no jaw model";
124+
return 0;
125+
}
126+
127+
if (m_target == nullptr)
128+
{
129+
msg_error() << " Error createStiffSpringFF, no valid m_target";
130+
return 0;
131+
}
132+
133+
SpringFF* stiffspringforcefield = l_springFF.get();
134+
if (stiffspringforcefield == nullptr)
135+
{
136+
msg_error() << " Error createStiffSpringFF, no valid spring force field";
137+
return 0;
138+
}
119139

120-
m_forcefield = sofa::core::objectmodel::New<SpringFF>(dynamic_cast<mechaState*>(m_jaw), dynamic_cast<mechaState*>(m_target));
121-
SpringFF* stiffspringforcefield = static_cast<SpringFF*>(m_forcefield.get());
122-
stiffspringforcefield->setName(this->getName() + "_SpringFF");
123-
m_target->getContext()->addObject(stiffspringforcefield);
124140

125141
return 1;
126142
}
127143

128144

129145
void GrasperJawModel::addJawSprings()
130146
{
131-
SpringFF* stiffspringforcefield = static_cast<SpringFF*>(m_forcefield.get());
147+
SpringFF* stiffspringforcefield = l_springFF.get();
148+
if (stiffspringforcefield == nullptr)
149+
{
150+
msg_error() << " Error addJawSprings, no valid spring force field";
151+
return;
152+
}
153+
132154
SReal stiffness = d_stiffness.getValue();
133155

134156
for (GrabContactInfo* cInfo : m_contactInfos)

src/InfinyToolkit/InteractionTools/GrasperJawModel.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,15 @@ class SOFA_INFINYTOOLKIT_API GrasperJawModel : public BaseJawModel
5454
void performSecondaryAction() override;
5555
/// Main API public method to stop the action of the Jaw
5656
void stopSecondaryAction() override;
57-
57+
5858
Data<SReal> d_stiffness;
59+
SingleLink<GrasperJawModel, SpringFF, BaseLink::FLAG_STOREPATH | BaseLink::FLAG_STRONGLINK> l_springFF;
5960

6061
protected:
6162
bool initImpl() override;
6263
int createStiffSpringFF();
6364
void addJawSprings();
6465

65-
private:
66-
SpringFF::SPtr m_forcefield = nullptr;
6766
};
6867

6968
} // namespace sofa::infinytoolkit

0 commit comments

Comments
 (0)