Loading...
 
Blender Dynamic Tutorial        

Blender Dynamic Tutorial

Here we show how to make a dynamic object (one that can move) in Blender, and export it into Grit.

We assume

We will continue using the mywork directory and blend file from the previous tutorial.

Creating the class


Move the cursor underground, somewhere out of the way, and click 'New Class'. We will make a cube that can be pushed around the map. We'll start with an empty collision mesh, and add the cube shape to it later.

Image

Image

Now, finish off the graphical elements of the cube as described in the previous tutorial. Ensure it is smooth shaded, has appropriate sharp edges and edge split modifier, and give it a material called 'Plain' and add that material to mywork/init.lua

material "Plain" { }


Collision Mesh (Hull)


A triangle mesh is not appropriate for a dynamic object like a cube. This is because firstly, it takes more CPU, secondly, it is hollow, and thirdly, it has annoying artifacts in the physical simulation (unwanted behaviours).

The correct way to define a dynamic collision mesh is using a set of convex shapes at particular positions and orientations relative to the centre of gravity. Here, we want a single cube shape centered on the centre of gravity.

The centre of gravity is the 'empty' — the set of axes to the left of the graphical representation. Note that this corresponds to the origin in the graphical representation — it is fortunate that our graphical cube has 0,0,0 right in its center.

Click the centre of gravity, and uncheck 'static'. We can leave the mass at 100kg. Move the cursor on top of the centre of gravity. Then click 'New Primitive'. This will create a new object at the cursor that is a child of the centre of gravity.

Image

By default, this object is a hull (an arbitrary convex shape). This is acceptable to define the shape of a cube, but Grit supports a special 'box' primitive shape that is more efficient than a cube-shaped hull.

Collision Mesh (Cube)


In order to create special kinds of primitives, we have to link in some meshes from common/lib.blend. Click on the 'link' icon from the file menu, and find common/lib.blend. Click into this blend file and go into meshes, select all the physics meshes (press a twice) and import them.

Image

Image

Image

Now, change the mesh of the hull to be the GritPhysicsBox mesh. This will cause it to be exported using the box primitive instead of as a hull.

Image

The mesh cannot be editted, since it is from another file. To alter the position / rotation / scale of the box with respect to the origin, the usual blender object tools can be used. In object mode, press s 2 <enter> to scale it up by a factor of 2 to match the graphical cube.

Setting Materials On An Imported Mesh


Since the box mesh is from another file, one has to assign its materials as object overrides. In the material tab of the properties panel, change 'Data' to 'Object' and then assign the material /common/pmat/Metal.

Image

Instantiating a stack of cubes


Scroll up to the Ground instance on the map (the top one) and place the cursor somewhere on it.

Image

Instantiate the 'MyCube' class you just created at the cursor

Image

Image

Move it into position so it does not intersect the ground too much, and then duplicate it linked (alt+d), pressing z to constrain the duplicate above the original, and place it above the first in a stack. Rotate it about z (r z) a little to make it more interesting. Repeat this to form a stack of 3 cube instances.

Image

Exporting To Grit


Click 'Export Whole Scene' and load the mywork/init.lua in Grit once more. This time, there should be a stack of large cubes in the middle of the ground, which can be knocked over.

Image

Image

Further Steps


By adding more primitives to a collision mesh, one can make arbitrarily complex collision meshes without using triangle mesh geometry. Each primitive can have a different material. See how a combination of cylinders and spheres in particular places are used to define this bowling pin:

Image