Here is where the loader copies translation, rotation, and scale to the mesh's joints.
Code: Select all
scene::CM2Mesh::SJoint* Joint;
for(u32 i=0;i<M2MBones.size();i++)
{
if(M2MBones[i].parentBone == -1)
{
ParentJoint=(scene::CM2Mesh::SJoint*)0;
}
else
{
ParentJoint=AnimatedMesh->getAllJoints()[M2MBones[i].parentBone];
}
Joint=AnimatedMesh->addJoint(ParentJoint);
if(M2MBones[i].translation.timestamps.size()>0)
{
for(u32 j=0;j<M2MBones[i].translation.timestamps.size();j++)
{
scene::CM2Mesh::SPositionKey* pos=AnimatedMesh->addPositionKey(Joint);
pos->frame=M2MBones[i].translation.timestamps[j];
pos->position=fixCoordSystem(core::vector3df(M2MBones[i].translation.values[j*3],M2MBones[i].translation.values[j*3+1],M2MBones[i].translation.values[j*3+2]));
}
}
if(M2MBones[i].rotation.timestamps.size()>0)
{
for(u32 j=0;j<M2MBones[i].rotation.timestamps.size();j++)
{
scene::CM2Mesh::SRotationKey* rot=AnimatedMesh->addRotationKey(Joint);
rot->frame=M2MBones[i].rotation.timestamps[j];
core::quaternion tempQ=core::quaternion(M2MBones[i].rotation.values[j*4+0],M2MBones[i].rotation.values[j*4+1],M2MBones[i].rotation.values[j*4+2],M2MBones[i].rotation.values[j*4+3]);
tempQ = fixQuaternion(tempQ);
tempQ.normalize();
rot->rotation=tempQ;
}
}
if(M2MBones[i].scaling.timestamps.size()>0)
{
for(u32 j=0;j<M2MBones[i].scaling.timestamps.size();j++)
{
scene::CM2Mesh::SScaleKey* scale=AnimatedMesh->addScaleKey(Joint);
scale->frame=M2MBones[i].scaling.timestamps[j];
scale->scale=core::vector3df(M2MBones[i].scaling.values[j*3],M2MBones[i].scaling.values[j*3+1],M2MBones[i].scaling.values[j*3+2]);
}
}
Joint->Animatedposition=M2MBones[i].PivotPoint;
Joint->Animatedscale=core::vector3df(1.0f,1.0f,1.0f);
Joint->Animatedrotation=core::quaternion(0.0f,0.0f,0.0f,1.0f);
core::matrix4 positionMatrix;
positionMatrix.setTranslation( Joint->Animatedposition );
core::matrix4 rotationMatrix = Joint->Animatedrotation.getMatrix();
core::matrix4 scaleMatrix;
scaleMatrix.setScale( Joint->Animatedscale );
Joint->GlobalMatrix = positionMatrix * rotationMatrix * scaleMatrix;
}