Merlin wrote:How does that whole animation stuff work?
I am planning on making some mods which add different categories of animal mobs (like farm animals), and so far I've been understanding a lot by examining PilzAdams Simple Mobs and the answer to my last question from 4aiman (thanks again mate!), but set_animation and the animation table are still a big riddle to me.
Any in depth explanation of that stuff would be greatly appreciated (and I guess not only by me).
I analysed
@PilzAdam's Simple Mobs and can answer your question for the sheep. Perhaps this is what you're looking for (but there are probably other ways to do animation in Minetest).
@PilzAdam used a DirectX .x file to specify the sheep's shape, appearance and animation using an
armature or
kinematic chain model. The position and orientation of the sheep is given by six coordinates (x, y, z, pitch, yaw, roll). Parts of the sheep like the head and legs are attached to the main body. Each part has its own 6 position/rotation coordinates that are relative to the position of the main body. Armature parts are sometimes called "bones" because the whole model is like a skeleton with many moving parts attached to each other. But bones don't have to move on a single fixed joint, they can move in any way permitted by the 6 coordinates. They can even change in size during animation.
There is no calculation of physics within the individual parts of the sheep. The whole thing has velocity and acceleration, and it collides with something (ground, wall, etc.) and stops moving in that direction when it collides; but there is no separate collision of individual parts of the sheep. When the sheep stops, the legs and head stop with it.
In
mobs_sheep.x, the main body of the sheep is
Armature_Root, the legs are
Armature_Bone_001, Armature_Bone_002, Armature_Bone_003 and
Armature_RR_leg, and the head is
Armature_Head. The first thing we see is a bunch of matrices giving the relative size and orientation (rotation) of each of the bones in the start position.
Next is the skin. This is a mesh (a table of polygons, in this case "quads" which are four-sided polygons) starting with the line that says
"Mesh { //Cube_000 Mesh". First there are 500 sets of 3D coordinates, which are the vertices (corners) of the polygons. Then we have 125 polygons, each given as something like "4;24;25;26;27;," which means a quad that uses vertices 24 through 27 as its four corners. Then we have "mesh normals", which are vectors telling what direction each vertex should be considered to be pointing, these are used in calculating lighting and reflection of light off of the surface. Then we have a
MeshMaterialList which isn't really being used, because this object uses a texture (PNG file) instead. Then we have the
MeshTextureCoords table, which tells where each vertex gets its colour given as a 2-dimensional coordinate within the PNG file (which goes from 0.00 to 1.00 in both directions X and Y)
When the parts of an armature move, different parts of the skin will follow different bones as they move. Some parts of the skin can be told to follow multiple bones with fractional amounts, called "skin weights". These are given in the
SkinWeights tables in
mobs_sheep.x, with entries for each vertex (500 vertices total, with a table for each of the 6 parts of the sheep). All the skin weights are 1.00, that means that each piece of the sheep moves by itself and there is no partial movement of the skin near the joints.
Finally we have the animation. Each of the 6 pieces has a set of animation frames, called
AnimationKey, that is given in three parts: position, rotation, and scale. Each
AnimationKey has 165 frames.
The
AnimationKey tables are fairly boring, almost every line of data is identical. But go down to
"Animation { {Armature_RR_leg} AnimationKey {" and skip down to the "Rotation" section and eventually you'll see this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
80;4; -0.000000, 1.000000, 0.000000,-0.000000;;,
81;4; -0.023017, 0.996971,-0.000000,-0.000000;;,
82;4; -0.087830, 0.988440,-0.000000,-0.000000;;,
83;4; -0.171026, 0.977486,-0.000000,-0.000000;;,
84;4; -0.235816, 0.968955,-0.000000,-0.000000;;,
85;4; -0.258819, 0.965926,-0.000000,-0.000000;;,
[more lines here]
99;4; 0.023017, 0.996971, 0.000000,-0.000000;;,
100;4; -0.000000, 1.000000, 0.000000,-0.000000;;,
Frames 80 through 100 tell that this piece (one of the legs) should rotate. It doesn't rotate much: the furthest it gets is about 0.25 in either direction, with 0.96 on the other coordinate, these are the sine and cosine of 15 degrees. So they set up the legs to move 15 degrees forwards and back when the sheep walks.
That's all we find in
mobs_sheep.x, but there is one more important part in how the animation is specified.
In
init.lua, or in
sheep.lua if your mod has the animals in separate init files, the sheep's animations are specified like this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
animation = {
speed_normal = 15,
stand_start = 0,
stand_end = 80,
walk_start = 81,
walk_end = 100,
},
This means that when the sheep is walking, Minetest should use animation frames 81 through 100 to specify how each of the armature parts are moved.
Notice that when the sheep is standing, it uses animation frames 0 through 80. These frames don't move the legs at all, but the head moves a little during frames 1-58 (look for
"1;4; 0.000000, 0.000000, 0.706989, 0.707223;;,"). Also, frames 101 through 164 aren't being used at all.
We don't know what tools
@PilzAdam used to create this, but Blender exports to DirectX and appears to be able to create this type of model. Here is a link to the Armatures section of the Blender online documentation:
Armatures. There are a lot of very complex things you can do in Blender models, but Minetest will only support the ones that are directly provided by Irrlicht.
There is a page on the Minetest wiki about this:
Using BlenderAs I mentioned at the start, there are other ways to get models into MineTest. For example,
my portalgun mod originally by
@UjEdwin uses "Alias Wavefront OBJ files" that were made in SketchUp.
This page describes the texture and mesh file formats supported by Irrlicht.