Motivation: I'm teaching a college course on interactive animation next semester (hopefully using Ogre), my student's will have little programming knowledge, so I need to be able to black box things like pose loading for them. Also, I think a generalized pose loader could be useful for everyone.
My two options:
1) Load all poses ahead of time for each submesh
2) Load Poses just in time
The problem with option 1:
I need the list of poses to load. It seems that when I try to get the list using
Code: Select all
Mesh::PoseIterator poseIter = mesh->getPoseIterator(); //or getPoseList()
Code: Select all
mesh = MeshManager::getSingleton().load(headFile, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
The problem with option 2:
If I don't call
Code: Select all
Ogre::VertexAnimationTrack *vt = poseAnim->createVertexTrack(curSubMesh, VAT_POSE);
vpKeyFrame = vt->createVertexPoseKeyFrame(0);
Here is the code I've been trying for just in time loading:
Code: Select all
/** Goes through all the submeshes and all the poses finding and updating poses with this name
*If they aren't yet loaded, also loads all poses as the list is traversed*/
void MeshPoseManager::updatePose(std::string poseName, float weight){
//get the pose list
Mesh::PoseIterator poseIter = mesh->getPoseIterator();
int curPoseIndex = 0;
//loop through each submesh
int numSubMeshes = mesh->getNumSubMeshes();
//skip submesh 0 since it is the shared geometry, and we have no poses on that
for(int curSubMesh = 1; curSubMesh <= numSubMeshes; curSubMesh++){
//if we haven't called updatePose before, create a pose reference for each submesh
if(!posesInitialized){
Ogre::VertexAnimationTrack *vt = poseAnim->createVertexTrack(curSubMesh, VAT_POSE);
vpKeyFrame = vt->createVertexPoseKeyFrame(0);
}
//while the poses apply to the current submesh, check to see if the current pose matches the name, then get the next pose
while(poseIter.peekNext()->getTarget() == curSubMesh-1){
//if we haven't called updatePose before, create a pose reference for each pose
if(!posesInitialized){
vpKeyFrame->addPoseReference(curPoseIndex, 0.0f);
}
//get next pose and check if it's the one we want to update
if(!poseIter.getNext()->getName().compare(poseName)){
//We found our pose, update it
Ogre::VertexAnimationTrack *vt = poseAnim->getVertexTrack(curSubMesh);
Ogre::VertexPoseKeyFrame *keyFrame = vt->getVertexPoseKeyFrame(0);
keyFrame->updatePoseReference(curPoseIndex, weight);
}
curPoseIndex++;
//go to the next pose
}
//go to the next submesh
}
//enable poses animation state if it is not yet
if(!posesInitialized){
manualAnimState = head->getAnimationState("posesAnimState");
manualAnimState->setTimePosition(0);
manualAnimState->setEnabled(true);
}
posesInitialized = true; //we have initialized our poses
}
1) When does the pose list get populated? What is it waiting for? Is the
Code: Select all
mesh = MeshManager::getSingleton().load(headFile, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
2) I would prefer to load poses just in time. Is it possible to load poses after the mesh has finished loading and is attached to its scene node? Or has the hardware buffering been completed and can't be altered?
My guesses are just shots in the dark, if someone could illuminate the situation or give me another avenue for making a generic pose loader I would very much appreciate it.