Contents
We use Blender for modelling our models. It is a great tool for indie game developers.
Making an animation itself was not a problem. There are plenty of tutorials about it on the internet. The real problem was to export the animation from Blender and import it into the game so that everything runs correct.
Here I’m gonna show how I manged to do it after several days of troubleshooting.
I going to to animate a catapult model in Blender
I’m going to make an animation of the catapult. Add a bone armature by choosing Add -> Armature -> Single bone
I choose a left-side view. Choose the bone and click on object -> X-ray in order to see the bone through the mesh (look at the menu to the right).
Scale the bone by pressing “S” (although it is not necessary, it will be just easier to choose the bones if they are bigger).
Assign the bone to the object by choosing the object first and (while holding a Shift) a bone and clicking Ctrl + P -> With automatic weights. In my case it was not only one object I wanted the bone to be assigned to. I did join them before I assigned the bone.
Check that the bone is correctly assigned to the object by choosing the bone in “Pose mode” and dragging it. If everything is right the object should go along with the bone.
Check weights of the object that you assigned the bone to. Choose the object in “Object mode” and then choose “Weight paint”.
An object that is totally assigned to the bone correctly should be all RED.
Use the brush to make it red (left side menu).
After I have checked that the bone is connected to the mesh I choose a left-side view and make a new window for the “Dope sheet” by pulling a right up corner of the 3D window down and choosing a “Dope sheet” view. This view will allow us to make key frames of our animation.
Click a “Key frames” button down the window in order to automatically insert key frames.
To insert the first frame click “I” and choose what type of animation you are going to use. I’m going to just rotate the arm of the catapult, so I choose “Rotation”.
Move “the green line” position in the “Pose view” to a place where you want the next key frame. I need the arm to move fast up, so I choose to move 25 frames ahead. Then choose your bone in a 3D view and rotate (“R”) it up.
I want the arm to move slowly back, so I choose frame 100 as my next keyframe place and rotate the arm back to start position.
The best animation file extension is said to be b3d (Blitz3d). In Blender version 2.6 and higher it is available as a plugin that can be enabled by File -> User Preferences -> Addons -> Import-Export B3D (check the box). It is a Gandalfs exporter.
The main thing to remember here is that you need your animation to be exported as data strips. For that you use an NLA editor. Pull a new window and choose “NLA editor“.
Within an NLA editor you export your animation data by clicking a snow sign (on the left orange strip).
Then you will be able to see your animation in NLA editor.
Play your animation and make sure everything is correct. Then export your animation as a B3D file.
Watch a video tutorial about how to make an animation with Blender and export it as a B3D file.
People use different graphics engines in their games. We use Irrlicht in “Burnt Islands“.
In order to import an animated mesh into the game with Irrlicht see tutorial 4 “Movement”. Here is how we use it:
ISceneNode * IrrlichtCreate::loadMesh(ISceneManager * mgr, const vector3df & position, const vector3df & scale, const std::string & filename) { scene::IAnimatedMesh* mesh = mgr->getMesh(filename.c_str()); auto *node = new CAnimatedMeshSceneNode(mesh, 0, mgr, -1 ) ; node->setPosition(position); node->setScale(scale); return node; }
As we imported the b3d mesh exported from Blender into the game we got a fail result:
After several days of trying and failing I found out that an initial Blender exporter does something with both materials and vertexes and exports everything fail.
A solution to a fail exported B3D file form Blender was a program fragMOTION.
Import your B3D file into fragMOTION.
Check the animation. If something looks weird like mine was, you need to fix it. In my case there were some weights that were not totally 1.0 for the bone.
Export it again as a B3D file from fragMOTION.
I needed to uncheck a “Hierachical mesh” checkbox.
The result is a correct animated mesh in your game!
Senior Software Engineer developing all kinds of stuff.