Getting vertices associated with specific bone.
by Lukas Joergensen · in Torque 3D Professional · 11/26/2012 (6:46 pm) · 0 replies
Been trying to crack this nut for a while now!
I try to get all vertices associated to a specific bone, however so far, when I try to get the vertices belonging to the head, it gives me the thumb.. Anyone know a good way to do this?
So far this is what I have come up with by looking at the updateskin branch of the TSSkinMesh class:
(Parts of the code might be missing)
Basically, I try to use the batchoperation on the skin mesh to find all the vertices associated to a node by saying; "Oh this batch operation is using the correct nodes transform, what vertex is it affecting then?" but there must be a simpler way (or one that works atleast thumb =/= head)
I believe that there must be somewhere, where the vertexgroups are stored but I have failed to locate that treasure pile of data it is :)
I try to get all vertices associated to a specific bone, however so far, when I try to get the vertices belonging to the head, it gives me the thumb.. Anyone know a good way to do this?
So far this is what I have come up with by looking at the updateskin branch of the TSSkinMesh class:
ShapeBase* SS = dynamic_cast<ShapeBase*>(SB);
const TSShapeInstance* model;
TSShape* shape;
if(SS)
model = SS->getShapeInstance();
else{
model = (dynamic_cast<TSStatic*>(SB))->getShapeInstance();
}
shape = model->getShape();
const TSShape::Detail& det = shape->details[model->getCurrentDetail()];
S32 od = det.objectDetailNum;
S32 start = shape->subShapeFirstObject[det.subShapeNum];
S32 end = start + shape->subShapeNumObjects[det.subShapeNum];
S32 nodeStart = shape->subShapeFirstNode[det.subShapeNum];
S32 nodeEnd = nodeStart + shape->subShapeNumNodes[det.subShapeNum];
S32 node = shape->findNode("Bip01_Head");
if(node < 0)
return;
Vector<S32> vertIDX;
TSSkinMesh* sMesh = dynamic_cast<TSSkinMesh*>(mesh);
if(sMesh->batchData.transformKeys.size() == 0)
continue;
S32 * curVtx = sMesh->vertexIndex.begin();
S32 * curBone = sMesh->boneIndex.begin();
F32 * curWeight = sMesh->weight.begin();
const S32 * endVtx = sMesh->vertexIndex.end();
// Temp vector to build batch operations
Vector<TSSkinMesh::BatchData::BatchedVertex> batchOperations;
// Build the batch operations
while( curVtx != endVtx )
{
const S32 vidx = *curVtx;
++curVtx;
const S32 midx = *curBone;
++curBone;
const F32 w = *curWeight;
++curWeight;
if( !batchOperations.empty() &&
batchOperations.last().vertexIndex == vidx )
{
vertIDX.push_back(vidx);
const int opIdx = batchOperations.last().transformCount++;
batchOperations.last().transform[opIdx].transformIndex = midx;
batchOperations.last().transform[opIdx].weight = w;
}
else
{
batchOperations.increment();
batchOperations.last().vertexIndex = vidx;
batchOperations.last().transformCount = 1;
batchOperations.last().transform[0].transformIndex = midx;
batchOperations.last().transform[0].weight = w;
}
//Con::printf( "[%d] transform idx %d, weight %1.5f", vidx, midx, w );
}
U32 IDX = gRandGen.randI() % vertIDX.size();
U32 VIDX = vertIDX[IDX];
//TSMesh::TSMeshVertexArray vertexList = shape->meshes[meshIndex]->mVertexData;
S32 numVerts;
numVerts = mesh->mVertexData.size();
if (sMesh)
numVerts = sMesh[meshIndex].mVertexData.size();
if(!numVerts)
continue;
vertexCount = numVerts;
if(co >= numVerts)
{
co -= numVerts;
continue;
}
const Point3F *vertPos;
const Point3F *vertNorm;
vertPos = new const Point3F(sMesh->mVertexData[vertIDX[IDX]].vert());
vertNorm = new const Point3F(sMesh->mVertexData[vertIDX[IDX]].normal());(Parts of the code might be missing)
Basically, I try to use the batchoperation on the skin mesh to find all the vertices associated to a node by saying; "Oh this batch operation is using the correct nodes transform, what vertex is it affecting then?" but there must be a simpler way (or one that works atleast thumb =/= head)
I believe that there must be somewhere, where the vertexgroups are stored but I have failed to locate that treasure pile of data it is :)
About the author
IPS Bundle available at: https://www.winterleafentertainment.com/Products/IPS.aspx