Skip to content

Commit c5e35b6

Browse files
[Mapping] SkinningMapping: compute weights from position (#6080)
1 parent 698ec11 commit c5e35b6

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SkinningMapping.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class SkinningMapping : public LinearMapping<TIn, TOut>
8585
// data for dual quat blending
8686
Data< type::vector<unsigned int> > d_nbRef; ///< Number of primitives influencing each point.
8787
Data< type::vector<sofa::type::SVector<unsigned int> > > d_index; ///< parent indices for each child.
88+
Data< bool > d_computeWeightsFromPosition;
8889
Data< type::vector<sofa::type::SVector<InReal> > > d_weight; ///< influence weights of the Dofs.
8990
void updateWeights();
9091

Sofa/Component/Mapping/Linear/src/sofa/component/mapping/linear/SkinningMapping.inl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ SkinningMapping<TIn, TOut>::SkinningMapping ()
4242
, d_index (initData (&d_index, "indices", "parent indices for each child." ) )
4343
, d_weight (initData (&d_weight, "weight", "influence weights of the Dofs." ) )
4444
, d_showFromIndex (initData (&d_showFromIndex, ( unsigned int ) 0, "showFromIndex", "Displayed From Index." ) )
45+
, d_computeWeightsFromPosition (initData (&d_computeWeightsFromPosition, false, "computeWeightsFromPosition", "By default, the weights are computed w.r.t the rest positions of the input model. Set to true to compute them from the position instead." ) )
4546
, d_showWeights (initData (&d_showWeights, false, "showWeights", "Show influence." ) )
4647
{
4748
type::vector<unsigned int> defaultNbRef;
@@ -86,7 +87,7 @@ void SkinningMapping<TIn, TOut>::reinit()
8687

8788
sofa::helper::ReadAccessor<Data<OutVecCoord> > out (*this->toModel->read(core::vec_id::read_access::position));
8889
sofa::helper::ReadAccessor<Data<OutVecCoord> > xto (this->d_initPos);
89-
sofa::helper::ReadAccessor<Data<InVecCoord> > xfrom = *this->fromModel->read(core::vec_id::read_access::restPosition);
90+
sofa::helper::ReadAccessor<Data<InVecCoord> > xfrom = *this->fromModel->read(d_computeWeightsFromPosition.getValue()? core::vec_id::read_access::position : core::vec_id::read_access::restPosition);
9091
sofa::helper::WriteAccessor<Data<type::vector<sofa::type::SVector<InReal> > > > m_weights (d_weight );
9192
const sofa::helper::ReadAccessor<Data<type::vector<sofa::type::SVector<unsigned int> > > > index ( this->d_index );
9293

@@ -133,7 +134,8 @@ void SkinningMapping<TIn, TOut>::updateWeights ()
133134
msg_info() << "UPDATE WEIGHTS";
134135

135136
sofa::helper::ReadAccessor<Data<OutVecCoord> > xto (this->d_initPos);
136-
sofa::helper::ReadAccessor<Data<InVecCoord> > xfrom = *this->fromModel->read(core::vec_id::read_access::restPosition);
137+
sofa::helper::ReadAccessor<Data<InVecCoord> > xfrom = *this->fromModel->read(d_computeWeightsFromPosition.getValue()? core::vec_id::read_access::position : core::vec_id::read_access::restPosition);
138+
137139
sofa::helper::WriteAccessor<Data<type::vector<sofa::type::SVector<InReal> > > > m_weights (d_weight );
138140
sofa::helper::WriteAccessor<Data<type::vector<sofa::type::SVector<unsigned int> > > > index (d_index );
139141

0 commit comments

Comments
 (0)