since I had some troubles exporting an animated Mesh with Blender I made a tutorial for it. Maybe someone can get use out of it
Introduction
In this tutorial we will use Blender to create a simple Minecraft like character, rig and animate it and export it to the Ogre data type.
Prerequisites
For this tutorial you need Blender in at least version 2.68 and the Blender2Ogre exporter in at least
version 0.5.9. (Can be found here http://code.google.com/p/blender2ogre/). I assume that you have a little
Blender knowledge. To see the animation in action we will use Ogre3d in version 1.8 and to make things simpler we will use the wiki framework with the code of the intermediate tutorial 1 (can be found here http://www.ogre3d.org/tikiwiki/tiki-ind ... =Tutorials)
Getting Started
To install the Blender2Ogre exporter, simply copy the python file to path_to_blender/2.68/scripts/addons. Now we need to activate the exporter in Blender by going to the user preferences tab. Go to File->User Preferences, there open the addons tab and activate in the list "Import-Export Ogre Exporter". Save the config and the Exporter is good to go.
Now we start to create our character.
Modeling a basic character
In the outliner expand the cube entry and give the next cube entry (the one with a triangle beside it) a name. Sonething like Larry. Larry is a good name. This will be the name with which you will load the mesh with Ogre.
Press numpad 1 to set the view to front view
- Go to edit mod (press tab)
Select the cube and press
s, z, 3 enter (scale the cube 3 units along the z axis)
s, x, 1.5 enter (scale the cube 1.5 units along the x axis)
Create a new cube, this will be an arm (press shift-a)
Select the cube and press
s, x, 0.5 enter
s, z, 1.7 enter
Move it to the height of the shoulder
Press shift-d while the arm is selected and move it to other side (it's easier when you press x, so you can only translate it along the x-axis)
Create a new cube this will be a leg (again press shift-a)
Select the cube and press
s, x, 0.6 enter
s, z, 2 enter
Move the mesh to the leg position
Again press shift-d, then the x button to move it to the other leg position
Create a new cube, this will be the head
The cube already has the correct size, so just move it to the head position
Your character should look like this
Before we rig the character we should rotate it so it will look down the x-axis. This is only important because then we don't need to do adjustments in the wiki framework code.
Select the mesh press r, z, 90 enter.
Now we need to apply the rotation.
Select the mesh and press strg-a -> rotation
This step is crucial because else the mesh and its animation will look differently in Ogre3D. So before you export your mesh always check that the rotation values in the transform window (press n) are set to 0.
In the next step we will rig the character.
Rigging the character
- Be sure that you are in the object mode.
Press shift-a go to armature and press on "single bone". Select the bone and go in the properties window (that is the one under the outliner) to the object data tab (that is the one with the cube on it). Now click on "X-Ray" in the Display section. This option will render the bone even if it is inside the mesh.
Place the bone in the mesh like it would be the spine of the character. Go again to the edit mode. Scale the bone up a bit so we can see and select it easier.
Press shift-a and we have another bone created. Place it in the head.
Press again shift-a and place the bone in one of the arms. Make sure that the bone cone is pointed downwards. * Keep the bone selected and press shift-d to duplicate and press x to restrain th translation to the x-axis. Move the bone in the other arm.
Repeat theses steps for the legs and we have rigged the character.
- Select one of the arm bones and then shift select the spine bone.
Press strg-p and choose "keep offset".
Do the same for the other arm bone. This will move both arms when the spine bone is moved or rotated.
Go to object mode and select the mesh and then shift select the armature. Press strg-p and choose "with automatic weights". Now the armature is the parent of the mesh, so when you translate the armature the mesh will move aswell. You can try it in the pose mode which you can find in the drop down menu where you can also change from object mode to edit mode.
Move or rotate all bones and you will see that for some reason the spine didn't get any weights so it won't move (if it does skip the next steps). To change this we need to go to the weight paint editor.
- First go back to object mode, select the mesh and now you can change to the weight paint mode.
First select the spine bone, by selecting it in the vertex group (the triangle) tab in the object properties window. * On the left side window choose the blend type "add".
In order to only paint the vertices which are related to the spine mesh we activate the option "Face selection masking for painting".
Now select the spine mesh and by left clicking paint the mesh completely red. Do the same for the backside.
In this section we will create two animations. One "Idle" and one "Walk" animation. First we setup our windows. We need the timeline window which is activated by default. The others are the dope sheet editor and the nla editor. At first we only need the timeline and the dope sheet. Split the timeline window horizontally and open in one of the new windows the dope sheet editor. Inside of the dope sheet open in the drop down menu the "Action Editor" and create a new action by pressing on the plus button. We start with the idle animation and that is how we call this action "Idle". Later we will use this name to play the animation with Ogre.
- In the timeline window activate the "automatic keyframe insertion for objects and bones" (the red dot). For the idle animation we will create a simple head shake.
Our animation will only last 48 frames so we don't need the default 250 frames. Change that in the timeline window.
Go to frame 12 and rotate the head to one side.
Go to frame 24 press alt-r to reset the rotation and the head should look straight ahead again.
In the dope sheet window select only these keyframes press shift-d to duplicate and move them to frame 0.
Go to frame 36 and rotate to the other side.
Go to frame 48 and press alt-r again.
To use this animation in Ogre we need to create a nla-strip. To do this we change the timeline window to the nla editor window. Expand armature and click on the snowflake to create a nla-strip. This is usually used to blend between animations but the Blender2Ogre exporter uses the nla-strip to get the names of the animations. If we wouldn't create a nla-strip the animation would be called "my_animation" and we couldn't create more than one animation.
Change the nla-strip window back to the timeline window and click on the red button to automatically create keyframes. Now we start to create the walking animation.
- First create a new action in the dope sheet editor and call that action "Walk".
This animation will also last for 48 frames.
Start at frame 12 and rotate the arms and the legs in a appropiate position.
Go to frame 24 and reset all the rotation by pressing alt-r for each bone.
Like we did it with the head select only the last keyframes and press shift-d. Move the duplicated keyframes to frame 0.
Go to frame 36 and rotate the arms and legs the other way around.
Go to frame 48 and reset all rotations.
Now we need to create a nla-strip. Do it the same way as you did with the idle animation.
Export
Export the animation with the following options: If you get the error that the mesh and the armature have an offset, select the mesh and press strg-a and click on location. This will set the location of the mesh to zero. Sometimes you have to do the same for the rotation and for scaling.
To use this animation with the intermediate tutorial 1 simply copy the .mesh and .skeleton files to path_to_project/dist/media/models.
In the TutorialApplication.cpp just load instead of the robot.mesh, the mesh you just copied in the working directory. And you should scale the mesh. Here is the code which belongs in the createScene() method.
Code: Select all
// Create the entity
mEntity = mSceneMgr->createEntity("Larry", "Larry.mesh"); // change the second string to the name you gave your mesh
mEntity->setCastShadows(true);
// Create the scene node
mNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("LarryNode", Ogre::Vector3(0.0f, 0.0f, 25.0f));
mNode->attachObject(mEntity);
mNode->setScale(10.0f,10.0f,10.0f); // scale the mesh
Code: Select all
if (nextLocation()) {
// Set walking
if("Idle" == mAnimationState->getAnimationName()) { //this will reset the idle animation state
mAnimationState->setWeight(0); //by setting its weight to 0
}
mAnimationState = mEntity->getAnimationState("Walk");
mAnimationState->setWeight(1);
mAnimationState->setLoop(true);
mAnimationState->setEnabled(true);
}//if
Code: Select all
if (!nextLocation()){
changedState = true;
if("Walk" == mAnimationState->getAnimationName()) {
mAnimationState->setWeight(0);
}
// Set Idle animation
mAnimationState = mEntity->getAnimationState("Idle");
mAnimationState->setWeight(1);
mAnimationState->setLoop(true);
mAnimationState->setEnabled(true);
}
http://youtu.be/0TQYGIuRz0U
If there is anything wrong with these steps or maybe there is an easier way to do things, let me know