Is there any way to remove bone assignments? I'm working on a system to allow parts of a skeletal animated mesh to be controlled by softbody physics (FEM) and I need to be able to clear the bone assignments on the FEM target vertices so that the skeletal animation doesn't put the vertices in a different reference frame to the FEM.
I can't assign all the vertex bone weights to 0 as that causes NaN's for the weights passed to the hardware buffer by _rationaliseBoneAssignments (called by _compileBoneAssignments).
Here's what I have:
Code: Select all
const set<size_t>& vertexGroup = ...; // set of vertex indices to clear bone assignments
// loop through all bone assignments and zero the weight
for ( auto &it: mEntity->getMesh()->getBoneAssignmentIterator() ) {
size_t vertexIndex = it.first;
// only clear bone assignments for vertices that are in the vertexGroup
if ( vertexGroup.count(vertexIndex) {
Ogre::VertexBoneAssignment& assignment = it.second;
// hack to avoid NaN when all weights are 0
assignment.weight = 0.00000001f;
}
}
// (re)-compile the bone assignments
mEntity->getMesh()->_compileBoneAssignments();
Code: Select all
// remove all bone assignments for given vertex
mEntity->getMesh()->clearBoneAssignments(ogreVertexIndex); Code: Select all
// remove bone assignment for given vertex and bone
mEntity->getMesh()->removeBoneAssignment(ogreVertexIndex, boneIndex); 