Models from Blender: glTF

Since 2.4.0 the game loads glTF 2.0 models (.glb, or .gltf with its .bin and images), the format Blender and most 3D tools export. A dinosaur, a weapon or a map object made in Blender goes into a mod as it is: no converter, no .3dn or .ani files. Skeletons (armatures), shape keys and object animation all work; the game bakes them into its own vertex animation when it loads the model.

How it works

The game asks for its files by name. When a file is not there and a glTF file of the right name is, the game makes it from the glTF, in memory:

The game asks for Made from raptor.glb
raptor.3dn the model: every mesh in the scene, at rest, as one model
raptor_walk.ani the animation named walk (Blender: the action walk), sampled at 30 frames a second
raptor.tga the base colour texture of the first textured material (or the material's colour)

So a character file names a glTF model like any other: the model is <name>.3dn and each animation <name>_<animation> (the animation's name in lower case, other characters as _). Sounds are .wav files as before.

carnivores_character

[general]
model = raptor.3dn

[animations]
count = 3
animation_id 0
    file = raptor_walk
animation_id 1
    file = raptor_run
animation_id 2
    file = raptor_die
    sound_index = 0

[sounds]
count = 1
sound_id 0
    file = raptor_die

A content pack then uses it as any new species (Content packs):

{"id": "blender_raptor", "copy": "velociraptor", "name": "Blender Raptor", "file": "raptor", "price": 120}

The animations' order is the AI's: each species' AI plays fixed animation slots (walk, run, idle, eat, die ...), so a .cat lists them in the order of the species it copies; The game's files lists the slots of every species. Start from that species' .cat and rename its files.

In Blender

Size and direction. 1 Blender metre = 1 metre in the game (128 game units). Model the creature at its real size, standing on the ground (feet at height 0), facing Blender's front view (-Y; in glTF +Z). The species' own scale still applies on top (scale in a content pack). A weapon is seen from the eye: the origin is the eye, it points forward along Blender's +Y (glTF -Z, the way a glTF camera looks), +X to the right.

Animations. One action per animation slot, named as the .cat names them (walk, run, die ...). An action plays from its first key to its last; for a looping animation make the last frame equal to the first. Each action is sampled at 30 frames a second (the game blends between frames). Armature animation, shape keys and moving objects can be mixed.

Texture. One texture per model: the base colour image of the material (Principled BSDF, Base Color). Textures are resized to powers of two (64 ... 2048) if they are not. Pixels whose alpha is below 0.6 are cut out (leaves, fur).

Special faces, by the material's name:

Material name contains Effect
[kill] a shot into these faces kills at once (the game's T-Rex eyes)
[nohit] shots and traces pass through (leaves, thin parts)
(Backface Culling off / glTF doubleSided) drawn from both sides

Export (File → Export → glTF 2.0):

A complete example is Swiftclaw: a dinosaur made in Blender, with its .blend source.

Limits

What Limit
Triangles per model 21845 (more: the model is refused and the log says so; use Decimate)
Size about +-32 m from the origin (the animation format's range)
Texture one per model, PNG; at most 2048 x 2048
Animation names the .cat's file names are at most 31 characters: <model>_<animation>
Model name at most 27 characters

Animations are stored per point and frame (vertices that differ only at UV seams are one point): a model of 2000 points with 2-second animations takes about 0.7 MB of memory per animation. The game's own creatures have 300-2000 points; the Swiftclaw example has 1960.

When something is wrong, the game's log says so with the file's name (glTF: error: raptor.glb: ...); start the game from a terminal or look at its log. A model that converts prints a line like glTF: raptor.glb: 374 points, 748 faces, 12 animations (walk, run, ...), texture 256x256.

Tools

tools/gltf/carnivores_to_blender.py (Blender) turns a creature of the game into a .glb: its model, texture and every animation as shape-key actions, a starting point for your own:

blender -b --factory-startup -P tools/gltf/carnivores_to_blender.py -- <the game's data folder> velo2 velo2.glb

In the game's older creatures (Velociraptor, T-Rex, Allosaurus, Stegosaurus ...) the rest model is half the size of their animations; the game always shows the animations. A creature exported with carnivores_to_blender.py keeps that: in Blender its rest pose is half as tall as its actions. A model of your own simply has one size.

tools/gltf/inspect_glb.py (Python 3) lists what a .glb holds: meshes, skins, shape keys, animations, images.

Sharing a .blend? Blender also saves its window state into the file, and with it the file browser's last folder: your home folder, with your user name. tools/gltf/clean_blend.py writes a .blend again without it (everything of the scene stays: objects, armatures, actions, materials, packed textures):

blender -b --factory-startup -P tools/gltf/clean_blend.py -- my_dino.blend

The .glb the game loads holds no such paths.