Update on this Matty ...
I've followed the steps you described but am not seeing any results. Interestingly, DBP/GDK appears to drop bones from a model when they're not important. So in the case of a leg, even though the .X model contains the whole bone structure (as verified by other modelling programs), it appears DBP keeps the root, hip, knee, ankle etc. bones, and discards the rest. So my models don't have the same bone structure. Very interesting. However, they still share the same names, so I believe this should be possible.
With the body component I want to synchronise with the Dynamix controlled rag doll, I do the following:
1. objPart->position.bCustomBoneMatrix = true;
2. Extract the no of bones in the body part I want to synchronise
int intPartBones = objPart->ppMeshList[0]->dwBoneCount;
3. I then loop through these bones, finding the name of each one with:
char* strPartBoneName = objPart->ppMeshList[0]->pFrameRef[pb]->szName;
4. I do the same with the main dynamix controlled character, and then do a strcmp() to ensure they're the same bone.
5. I then copy the matrix data from the dynamix controlled character to the body part I want to synchronise:
D3DXMATRIX* matPart = objMaster->ppMeshList[0]->pFrameMatrices[pb];
To get a pointer to the matrix, and then a load of these manually to copy it across ...
dest->_11 = source->_11;
dest->_12 = source->_12;
dest->_13 = source->_13;
dest->_14 = source->_14;
etc.
Code here ...
void RagDoll::PosePartToBase(int dbObj){
sObject* objMaster = dbGetObject(dbObjBase);
sObject* objPart = dbGetObject(dbObj);
objPart->position.bCustomBoneMatrix = true;
int intMasterBones = objMaster->ppMeshList[0]->dwBoneCount;
int intPartBones = objPart->ppMeshList[0]->dwBoneCount;
// Cycle through each bone, find the corresponding bone in the main model (by name) and copy its matrix
for (int pb=0; pb < intPartBones; pb++){
char* strPartBoneName = objPart->ppMeshList[0]->pFrameRef[pb]->szName;
for (int mb = 0; mb < intMasterBones; mb++){
char* strMasterBoneName = objMaster->ppMeshList[0]->pFrameRef[mb]->szName;
if (strcmp(strPartBoneName,strMasterBoneName) == 0){
D3DXMATRIX* matMaster = objMaster->ppMeshList[0]->pFrameMatrices[mb];
D3DXMATRIX* matPart = objMaster->ppMeshList[0]->pFrameMatrices[pb];
CopyMatrix(matMaster,matPart);
break;
}
}
}
}
void RagDoll::CopyMatrix(D3DXMATRIX* source, D3DXMATRIX* dest){
dest->_11 = source->_11;
dest->_12 = source->_12;
dest->_13 = source->_13;
dest->_14 = source->_14;
dest->_21 = source->_21;
dest->_22 = source->_22;
dest->_23 = source->_23;
dest->_24 = source->_24;
dest->_31 = source->_31;
dest->_32 = source->_32;
dest->_33 = source->_33;
dest->_34 = source->_34;
dest->_41 = source->_41;
dest->_42 = source->_42;
dest->_43 = source->_43;
dest->_44 = source->_44;
}
I can confirm the strcmp works and the CopyMatrix function is run for each limb, every loop. So it's being copied, but my body part models still stay unrotated/positioned and at the origin.
Any ideas what I may be missing or doing wrong?