# Conflicts: # model/AnimModel.h
33 KiB
The EU07M model format (.eu07m)
The successor of E3D: a fully binary model format. A file is read with almost no processing, straight into the buffers of OpenGL
4.6 and Vulkan 1.4. It carries TRS nodes, skinning, typed components and metadata of nodes and vertex groups, and it extends without
raising its version. The records, their sizes and offsets are in model/eu07m/eu07m_format.h, where static_asserts keep the code
and this description from drifting apart.
State: version 1.0. The format, its reader, writer and the conversion from E3D/T3D (stage 1); the loading in the game behind a
switch (stage 2); the compact streams in the Vulkan renderer (stage 3); the instancing of models with lights (stage 5); skinning
(stage 4); animation clips and channels (stage 8); the geometry shared by the variants of a family (GREF). See "In the game"
and "Geometry shared by a family".
Principles
- Little-endian. The records lie in the file as they lie in memory, and go to the GPU that way.
- A table of sections (TOC). Every section is found through the table, not by walking chunk after chunk. A reader may take only the sections it needs.
- Tables with a
stride. A section of records starts withcountandstride. A new version adds fields at the end of a record: an old reader takes the prefix it knows, a new one gives the missing fields their defaults. - Required and optional sections. A reader skips an optional section it doesn't know, and the tools carry it over unchanged. An unknown required section makes the file refused, with a readable message.
- Version. The major version changes only with an incompatible change; a reader refuses a file of a higher major version. The minor version marks new fields and sections, which an older reader skips.
- A file is untrusted data. The reader checks every offset, size, index, parent, joint and reference before anything is used
(
eu07m::validate). - Meaning in the data, not in the names. Roles, the ends of a vehicle, variants and light slots are fields of components. The
names stay, so the
.mmdfiles and the events of today work unchanged.
Header (64 B)
| Offset | Type | Field |
|---|---|---|
| 0 | char × 4 | magic EU7M, the name of the format in four bytes |
| 4 | u16 × 2 | major version (1), minor version (0) |
| 8 | u32 | flags: bit 0 = the index order was optimised |
| 12 | u32 | section count |
| 16 | u64 | offset of the table of sections |
| 24 | u64 | file size |
| 32 | u64 | FNV-1a 64 of the bytes from offset 64 to the end of the file |
| 40 | u64 | hash of the source file (the exporter and the converter know when to build again) |
| 48 | 16 B | reserved, zeroes |
Entry of the table of sections (32 B)
| Type | Field |
|---|---|
| u32 | FourCC |
| u32 | flags: bit 0 = required, bit 1 = zstd, bit 2 = meshoptimizer codec (vertex and index streams only) |
| u64 | offset in the file |
| u64 | size in the file |
| u64 | size unpacked |
Sections are aligned to 16 B, the vertex and index streams to 64 B. A section may be compressed with zstd. Each section appears at most once.
The vertex streams (VPOS, VATT, VSKN, VSKW, VUSR, VBND) may be stored in the vertex codec of meshoptimizer (version 1),
the index streams (IDX2, IDX4) in its index sequence codec (ref/meshoptimizer, MIT licence). The codec is lossless to the
byte and unpacks several times faster than zstd on this data. When a section has both flags, zstd packs the output of the codec;
the reader first unpacks zstd (at most to the bound of the codec size), then decodes. The unpacked size in the table entry is
always the size of the raw stream. The codec flag on any other section refuses the file.
Sections
[T] marks a table: u32 count, u32 stride, then count records of stride bytes. [S] marks a raw stream without a header:
the element count is the section size divided by the element size.
| FourCC | Required | Form | Content |
|---|---|---|---|
STRS |
yes | — | u32 count, u32 blob_size, count + 1 offsets u32, a UTF-8 blob. String i is the bytes [offset[i], offset[i+1]). |
NIDX |
no | [T] 16 B | the name index: u64 FNV-1a 64 of the name in ASCII lowercase, u32 node, u32 0; sorted by the hash, then by the node |
NODE |
yes | [T] 80 B | the nodes |
XFRM |
no | [T] 80 B | u32 node, 12 B of zeroes, a 4×4 f32 matrix by columns: the transform of a node which TRS can't describe (shear) |
MESH |
yes | [T] 16 B | u32 first primitive, u32 count, i32 skin (−1), u32 flags (0x1: the mesh uses VUSR) |
PRIM |
yes | [T] 48 B | the primitives (draw records) |
VPOS |
yes | [S] 12 B | position f32 × 3 |
VATT |
yes | [S] 16 B | QTangent snorm16 × 4, UV0 f32 × 2 |
VSKN |
no | [S] 8 B | joints u8 × 4, weights unorm8 × 4 (summing to 255) |
VSKW |
no | [S] 16 B | joints u16 × 4, weights unorm16 × 4 (summing to 65535); in place of VSKN when a skin has more than 256 joints |
VUSR |
no | [S] 16 B | user data f32 × 4 (the userdata of today) |
VBND |
yes, when present | [S] 4 B | the binding of a vertex of a merged primitive: u8 joint of the skin of the primitive, u8 light slot, u8 role in the slot (0 none, 1 lit, 2 dark), u8 0. The writer marks it required, as merged primitives are drawn wrong without it |
IDX2 |
no | [S] 2 B | u16 indices, local to the base_vertex of the primitive |
IDX4 |
no | [S] 4 B | u32 indices, as above |
MATL |
yes | [T] 80 B | the material slots |
SKIN |
no | [T] 16 B | u32 first joint in SKJT, u32 count, i32 root node, u32 0 |
SKJT |
no | [T] 64 B | u32 node, 12 B of zeroes, the 3×4 inverse bind matrix f32 (four columns of three) |
VGRP |
no | [T] 32 B | the vertex groups |
VGIT |
no | [S] 4 B | the items of the groups: vertices, or pairs (first, count) |
VGWT |
no | [S] 1 B | the unorm8 weights of the items of the groups which have them |
CMPT |
no | [T] 20 B | the components |
CDAT |
no | — | the data of the components |
BNDS |
no | [T] 40 B | bounds: f32 × 3 min, f32 × 3 max, a sphere f32 × 4; one record for each node (the geometry of the node in its space), the last one for the whole model |
EDIT |
no | [T] 16 B | u32 path of the source file (string), u32 tool (string), 8 B of zeroes |
ACLP |
no | [T] 32 B | an animation clip: u32 name, u32 flags (0x1 looped, 0x2 plays on its own from the start of the scenario), u32 first track in ATRK, u32 count, f32 duration in seconds, 12 B of zeroes |
ATRK |
no | [T] 24 B | a track of a clip: u32 node, u8 part (0 translation, 1 rotation, 2 scale), u8 interpolation (0 step, 1 linear, 2 cubic), u16 0, u32 key count, u32 first time in ATIM, u32 first value in AVEC or AROT, u32 0 |
ATIM |
no | [S] 4 B | the times of the keys, f32 seconds, from 0, not decreasing within a track |
AVEC |
no | [S] 12 B | the values of translations and scales, f32 × 3; with cubic interpolation three for each key: in-tangent, value, out-tangent (as in glTF) |
GREF |
yes, when present | [T] 32 B | a primitive whose geometry is in the store of the family: u32 primitive, u32 0, u64 × 2 hash of the block, u32 vertex count, u32 index count. See "Geometry shared by a family" |
AROT |
no | [S] 8 B | rotations, "smallest three": the three smaller components of the quaternion snorm16 × 3 (multiplied by √2), u16 index of the largest (0 x … 3 w), which is positive and rebuilt from the others |
All the vertex streams (VPOS, VATT, VSKN/VSKW, VUSR, VBND) have the same element count: one for each vertex of the file.
The skin stream so covers the vertices of rigid meshes too (with zeroes; zstd eats them). Only the ranges of skinned meshes go to
the GPU.
Node (80 B)
| Offset | Type | Field |
|---|---|---|
| 0 | u32 | name (string) |
| 4 | i32 | parent, −1 for the root |
| 8 | u32 | end of the subtree: the index past the last node of the subtree |
| 12 | u32 | flags: bit 0 animated, bit 1 hidden, bit 2 transform in XFRM, bit 3 no transform of its own (an E3D submodel without a matrix; the TRS is the identity) |
| 16 | f32 × 3 | translation |
| 28 | f32 × 4 | rotation, quaternion x y z w |
| 44 | f32 × 3 | scale |
| 56 | i32 | mesh, −1 without one |
| 60 | u32 × 2 | the components of the node: first, count |
| 68 | f32 × 2 | squared distance from the camera: from, to (0 = no limit) |
| 76 | u32 | the iFlags of the E3D submodel the node was made from; 0 in a model made anew |
The nodes lie in depth-first order: a parent before its children, and a subtree takes the continuous range [node, end of the subtree). The children of one parent are in drawing order. The world matrices are so worked out by one loop from the start of the
table. The transform of a node is T · R · S, unless it has the XFRM flag.
Primitive (48 B)
| Offset | Type | Field |
|---|---|---|
| 0 | u32 | first index in IDX2/IDX4; without indices: the first vertex counted from base_vertex |
| 4 | u32 | index count; without indices: the count of vertices drawn |
| 8 | u32 | base_vertex in the streams |
| 12 | u32 | vertex count of the primitive |
| 16 | u32 | material (MATL slot) |
| 20 | u32 | node |
| 24 | i32 | skin, −1 for a rigid one |
| 28 | u32 | flags: bits 0-3 topology (GL values: 0 points, 1 lines, 2 loop, 3 strip, 4 triangles, 5 strip, 6 fan); 0x10 indexed; 0x20 indices in IDX4; 0x40 opaque pass; 0x80 translucent pass; 0x100 no shadow; 0x200 rigid joints from VBND; 0x400 light slots from VBND; bits 16-23 LOD |
| 32 | f32 × 4 | sphere in the space of the node |
Merged primitives
Today every moving part and every lamp (Light_On## / Light_Off##) is a submodel of its own, so a draw call of its own in every
pass. A scenery model with a light or an animation isn't instanced either. EU07M allows the parts of several nodes with the same
material to be put in one primitive:
- Rigid joints (0x200). Each vertex names in
VBNDa joint of the skin of the primitive (skin≥ 0), with weight 1. The vertices lie in the bind pose, as with skinning, and the matrix isworld(joint) · inverse bind(joint). The vertex shader takes it from the pose buffer of the instance itself, without a compute pass. The primitive needs noVSKN. A skin has at most 256 joints; the tool splits a larger group into several primitives. - Light slots (0x400). A vertex names a slot (
u8, theslotfield of anLSLTcomponent) and a role: lit (glowing and visible while the slot is lit) or dark (visible while the slot is dark). The state of the slot lies in the state buffer of the instance, so a model with lights can be instanced. A slot the model hasn't the shader doesn't light. - The nodes stay. Merging moves only the geometry; the nodes and their names stay in
NODE, soGetFromName, the.mmdand the events keep working. Hiding a node (visible) is a zero matrix of its joint in the pose buffer. - The sphere of the primitive covers the bind pose. For a primitive with moving joints the runtime takes the bounds of the instance.
The tool merges (optimize), not the converter: it merges nodes which aren't animated and have no components, and keeps as joints
the nodes something refers to by name. Translucent parts, parts with replaceable skins other than the rest and parts with another
visibility range aren't merged.
Vertex
- Position
f32 × 3relative to the origin of the model. - QTangent: the quaternion of the rotation of the frame (T, B, N), where B = N × T. The quaternion has w ≥ 1/32767. When the
bitangent is flipped (mirrored UV,
tangent.w < 0inbasic_vertex), the whole quaternion is negated, so w < 0. Decoding: N = third column, T = first, B = N × T · sign(w). - UV0
f32 × 2; half floats lose precision on textures repeated hundreds of times.
Size: 28 B (rigid), 32 B (in a merged primitive, with VBND), 36 B (skinned), against the 48 B of basic_vertex. The shadow pass
reads only VPOS (and VBND in merged primitives).
Material (80 B)
| Offset | Type | Field |
|---|---|---|
| 0 | u32 | name of the .mat or of the texture (string); none = colours only |
| 4 | i32 | replaceable skin −1..−4, 0 = fixed |
| 8 | u32 | flags |
| 12 | f32 | selfillum threshold (fLight of E3D) |
| 16 | f32 × 4 × 4 | ambient, diffuse, specular, emission |
Vertex group (32 B)
u32 name, u32 mesh, u32 first item in VGIT, u32 item count, u32 flags (0x1 the items are pairs (first, count), 0x2
weights in VGWT), u32 × 2 the components of the group (first, count), u32 0. The vertex indices are those of the streams of
the file (absolute).
Geometry shared by a family
The variants of a vehicle repeat the same parts byte for byte (the includes of their .t3d). Measured on the converted models
of the game, the folders of a family are 7% to 38% of their size with their shared parts kept once (EU07M, blocks of at least
4 KiB): cd/181_v2 60.8 MB → 4.0 MB, pkp/11xa_v2/main 69.3 MB → 5.8 MB, pkp/elf_v1 109.6 MB → 39.0 MB, pkp/en57_v1
104.1 MB → 39.3 MB. PR #521 showed the problem first, on E3D.
- Block. The geometry of one primitive: a 16 B header (
u32the vertex streams it has, as bits 0x1VPOS, 0x2VATT, 0x4VSKN, 0x8VSKW, 0x10VUSR, 0x20VBND;u32vertex count;u32index count;u32index size 0, 2 or 4), then its vertices in each of those streams in that order, then its indices. Its id is 128 bits: two FNV-1a 64 of its bytes, with the seeds0xcbf29ce484222325and0x84222325cbf29ce4. A primitive can be kept in the store only when its vertex and index ranges are its own. - The store of the family is
geometry.eu07mpackin the folder of the models: a 32 B header (magicEU7P,u16major 1,u16minor 0,u32block count,u32flags,u64offset of the index, 8 B of zeroes), the blocks one after another, each packed with zstd when it saves an eighth, and the index: entries of 40 B (u64 × 2id,u64offset,u32size in the file,u32size unpacked,u32flags (0x1 zstd),u320), sorted by the id. - In a model file,
GREFnames the primitives kept in the store. The writer leaves their vertex and index ranges out of the streams of the file; the reader takes their blocks from the store, checks the id and the counts of each, and puts them back in their places, so the model in memory always has its whole streams and nothing past the reader knows the difference. A model with references and no store, or a block which isn't the one referred to, is refused with the reason in the log.GREFis a required section, so a reader which doesn't know it refuses the file rather than reading short streams. - The game opens the store of a folder once and keeps it, reading the blocks from it as the models ask for them.
- The tools.
eu07 -eu07m pack <folder> [minimum bytes]moves every block of at least the minimum (4096 by default) which occurs more than once in the models of the folder into its store, made anew from all of them, and writes the models again referring to it; each model is read back and compared with what it was before it's replaced.eu07 -eu07m unpack <folder>writes the models whole again (the store is left to be deleted).dumpandvalidateread the store of the folder. - The renderer still makes the geometry of each model on its own; a part shared by the variants takes one range of the buffers for each model that uses it. Sharing that range is the next step.
Components
A record in CMPT (20 B):
| Offset | Type | Field |
|---|---|---|
| 0 | u32 | type (FourCC) |
| 4 | u16 | version of the data |
| 6 | u8 | kind of the target: 0 model, 1 node, 2 mesh, 3 vertex group |
| 7 | u8 | flags |
| 8 | u32 | index of the target |
| 12 | u32 | offset of the data in CDAT (aligned to 4) |
| 16 | u32 | size of the data |
The components of one node lie next to each other, and the node names its range; so does a vertex group. The game skips an unknown
type, and the tools carry it over unchanged. A new version of a type adds fields at the very end of the data, past the lists, so an
older reader reads its part from the start and skips the rest. References within the data are indices: a string, a node or a
component; 0xFFFFFFFF = none.
| Type | Data (version 1) |
|---|---|
PROP |
u32 count, then records of 24 B: u32 key (string), u8 type (0 bool, 1 int, 2 float, 3-5 vec2-4, 6 string, 7 node, 8 component), 3 B of zeroes, 16 B of value |
SOCK |
a socket, 36 B: u32 role (string), u8 end (0 none, 1 front, 2 rear), u8 0, u16 index, position f32 × 3, rotation f32 × 4 (in the space of the node) |
JOIN |
a joint, 36 B: u8 kind (0 fixed, 1 hinge, 2 ball, 3 slider, 4 screw), u8 limited, u16 0, u32 role, axis f32 × 3, min, max, rest, pitch of a screw (m for each turn) |
SPRG |
a spring, 52 B: u8 mode (0 follow, 1 stretch, 2 aim, 3 pendulum), u8 side play, u16 0, anchor A (node, socket), anchor B (node, socket), axis f32 × 3, free length, travel min, max, pendulum length, pendulum damping |
CHAN |
a chain (hose, cable, bellows), 32 B: u8 kind (0 brake hose, 1 main reservoir hose, 2 cable, 3 bellows, 4 other), u8 0, u16 joint count, i32 skin, minimum bend radius, stiffness, head mass, length of the rigid head, the sockets of the ends A and B; then the joint nodes u32 × n and the segment lengths f32 × (n − 1) |
VARI |
a variant group: u32 name, u16 state count, u16 default state; states of 12 B (u32 name, u32 first, u32 node count), then the node list u32 |
CHNL |
a control channel: u32 name, f32 min, max, initial value, u16 binding count, u16 0; bindings of 16 B: u8 kind (0 joint, 1 clip, 2 variants, 3 light slot), 3 B of zeroes, u32 target (a JOIN component; for a clip its index in ACLP; a VARI or an LSLT component), f32 scale, f32 offset (value of the target = channel · scale + offset) |
LSLT |
a light slot: u16 slot, u16 0, f32 initial state (coded as in the lights event), colour f32 × 3 (negative: the colour of the sources), u16 counts of the lit nodes, the dark nodes, the LGHT sources, u16 0; then those three lists u32 |
LGHT |
a light source, 52 B: u8 kind (0 point, 1 spot), u8 flags (0x1 shadeself, 0x2 no shadows, 0x4 soft falloff, 0x8 light only, 0x10 halo), u16 0, colour f32 × 4, intensity, radius, halo from, to, i32 falloff kind, falloff radius, cos of the cone, cos of the hotspot |
EMIT |
an emitter, 16 B: u8 kind (0 smoke, 1 steam, 2 sparks), 3 B of zeroes, direction f32 × 3 |
MREF |
a model attached to the node, 12 B: path (string), socket (component), skin (string) |
COLL |
a solid, 48 B: u8 shape (0 box, 1 sphere, 2 capsule), 3 B of zeroes, u32 role, centre f32 × 3, rotation f32 × 4, half extents f32 × 3 |
LANM |
an E3D animation (TAnimType): u32 |
LTXT |
an E3D text display (TP_TEXT); the children of the node are the characters, named by their character. No data. |
STAR |
E3D stars (TP_STARS): u32 count, then RGB colours u32 (as in E3D), one for each vertex of the mesh of the node |
LMAT |
the material of a node without geometry (a light point, a rotator), which E3D keeps in every submodel: u32 MATL slot. The light takes its threshold (fLight), colours and material from it |
Conversion from E3D and T3D
eu07 -eu07m convert <input.e3d|.t3d> <output.eu07m> [dynamic] loads the model with the existing loader (as -e3d does) and writes
it as EU07M:
- A submodel becomes a node. The order of the children and the names stay, so
GetFromName, the.mmdand the events work as before. - The matrix of a submodel is decomposed into TRS. When TRS doesn't give it back (shear), the whole matrix goes to
XFRM. - The
iFlags, the visibility range and the colours stay in the node and in the material slot. TP_FREESPOTLIGHT→LGHT;Light_On##/Light_Off##→LSLT;smokesource_*→EMIT; ananim:animation →LANM;TP_TEXT→LTXT;TP_STARS→STAR.- The indices are written as
u16when a primitive has at most 65 536 vertices (indices 0–65 535). - The pass bits (0x30) guessed from a material when an E3D is loaded go neither into
legacy_flagsnor into the flags of the primitive: the game guesses them again, with the real material. A vehicle's model is converted from the.e3dthe game makes of it, not from its.t3d. - A replaceable skin
-kdrawn in the translucent pass (bit k−1 of the E3D flags) has thetranslucentflag inMATL.
The other commands: eu07 -eu07m dump <file.eu07m> (the content as text, clips included) and eu07 -eu07m validate <file.eu07m>
(a check of the file with the hash of its content).
In the game
With modelformat eu07m in eu07.ini, a model with an .eu07m file beside its .e3d / .t3d (or alone) is loaded from it
(TModel3d::LoadFromEU07M). The default modelformat legacy leaves .eu07m files alone.
- The Vulkan renderer keeps the streams of an EU07M model as they lie in the file: positions (12 B), attributes from
VATT(16 B), user data and indices, each in a buffer of its own in the bank (vertex_kind::scene_compact). The shaders read the position and the UV as before, and work out the normal and the tangent from the quaternion (compact_frame()inshaders/vk14/common.glsl, theCOMPACT_VERTEXvariant of a program). Ray tracing builds the BLAS from the positions with a stride of 12 B and reads the normals and UVs from the attributes (RT_FLAG_COMPACT). - The OpenGL 4.6 renderer gets the same models as
gfx::basic_vertex(48 B), as E3D models. - The code of the game which reads the vertices of a model (pantograph, bounds, picking, the editor) gets them as
gfx::basic_vertex, made from the streams the first time they are read. - The stars (
STAR) keep their colour in the normal, so they go asgfx::basic_vertexin Vulkan too. - A node with
range_max_sq0 has no distance limit; before, such a node (of a model made anew, not converted from E3D) wasn't drawn at all.
In the editor
Selecting a scenery model loaded from an .eu07m file opens the "EU07M model" window (application/editoruimodel.cpp). With
nothing selected, the window shows the model of the vehicle driven (its body or its cab), so a vehicle can be driven, the editor
opened with F11, a light changed and looked at from the cab again after F11:
- the file, and the tree of the nodes with their transforms and the components aimed at each of them, then the components of the model;
- the fields of the common components to edit:
SOCK,JOIN,CHNLwith its bindings,LGHT,LSLT,EMIT,COLL,MREF; the others are shown by their size. Strings are edited by their text. ALGHTchanged shows at once on the model the game has (on every instance of it), before the file is saved; - the "Model" tab holds the tree of the nodes beside the properties of the node picked (a click picks, a double click flies the camera to the node); the other tabs hold the parts of the vehicle, the clips and the channels, and the components of the model;
- in the 3d view the node picked is framed and shows its axes and a gizmo, which moves or turns it; the light sources are marked with their colour (a spot with its axis, the -z of its node), and a click on a mark picks its node. A press on the gizmo or on a mark doesn't pick a scenery node;
- the settings of a node: its position, its rotation (in degrees) and its scale, unless a matrix of
XFRMplaces it, and the distances it is drawn from and up to. "Add a light source here" puts in a new node,light_<n>, as the last child of the node, with aLGHTpoint or spot light; the references to the nodes after it move on (eu07m::insert_node). A change of a node or of a light, and a light added, show on the model the game has at once (on every instance of it), when that model is the one of the file; the spot's cones are edited as half angles in degrees; - for the vehicle driven, "Parts of the vehicle" holds its pantographs up or down, and its lamps, coupler hooks and hoses
(
headlamp11,coupler1,cpneumatic1and the like) in the_off,_onor_xonstate of their submodels, whatever the vehicle does with them, until they're set back to Automatic. A held pantograph moves at its own pace, in the editor too, up to the wire above it when there is one (1.6 m over its rest without one). A node that is in one of those parts shows its switch in the tree; - the clips, with their flags to edit and a time to hold the instance at (the time stands still in the editor), and the channels of the model, set on the instance with a slider, which tries them without changing the file;
- "Save the model" checks the model and writes the file again (the store of the family is kept); the game uses the change once it loads the model again. "Read it again" drops the changes.
The geometry, the mapping and the materials aren't edited there; that is the work of the exporter.
Animation clips
A clip (ACLP) is a set of tracks (ATRK), each of which sets one part of the TRS of a node: translation, rotation or scale. The
parts of a node without a track stay as in its TRS.
- Interpolation. Step holds the value of a key till the next one. Linear is the lerp of vectors and the slerp of rotations (the shorter way). Cubic is the Hermite spline of glTF, with tangents in units per second; vectors only, the validator refuses a cubic rotation. Before the first and past the last key a track holds its value.
- Time. A clip goes by the simulation time from when it started, at its pace. A looped clip starts over past its duration, another stops at its end. A clip with flag 0x2 starts on its own the first time the instance is drawn.
- In the game.
TAnimModel::play_clip(name, pace)starts a clip (the self-test commandclip <node> <name> [pace]), the name regardless of case, andstop_clips()stops them all: each is held at the moment it was stopped and goes on setting its nodes, as apart from what an instance sets as it's drawn the nodes are kept by the submodels all the instances share. Each time the instance is drawn,RaPrepare()samples the clips and sets the transforms of the nodes (TSubModel::SetClipTransform(), the animationat_Clip) before the animations of the events: an animation event of the scenery moving a node (rotate,translate...) takes it over from a clip, one which ended or was stopped included. The nodes the clips move are flagged animated at load, so a model with clips isn't instanced. A clip moving the joints of a skin bends the skinned parts (see "Skinning"). - The TRS fields of a node with a matrix (
XFRM) are only an approximation of it: the parts the tracks of a clip don't move are taken from the decomposed matrix, so the node doesn't jump when a clip starts moving another part of it. - Scenery event.
event <name> animation <delay> <model> clip <clip> <pace> endeventstarts the clip from its beginning at the pace (a clip playing starts over), and a pace of 0 stops the clips of the model; the nodes stay where the clips left them. The name of the clip is matched regardless of case, as the names of submodels are. An event without a pace (clip <clip> endevent) plays the clip at its own pace and givesBad event: ... gives no pace for clipin the log. A clip the model hasn't givesBad event: ... can't find clipin the log. This is a new form of theanimationevent, which the current release doesn't read; the forms before it (rotate,translate,digital,.vmd) read as they did.
The current release doesn't read the clip sections, and a file without them loads as before.
Channels
A channel (CHNL) is a named value of the model, kept within its range, which moves what it's bound to. Whatever sets it (an event,
the code of a vehicle, later Lua or a gauge in the cab) doesn't matter.
- Bindings the game follows. A joint (
JOINof a node): the value of the target turns a hinge (radians) or a screw, or moves a slider (metres) along the axis of the joint, from the transform of the node, within the limits of the joint when it has them; a fixed or a ball joint leaves the node at rest. The node is modelled at therestvalue of the joint: the joint moves it by the value lessrest(the limits are values of the joint, asrestis). A clip (its index inACLP): the value of the target is the share of the duration of the clip, 0 to 1, so the channel scrubs the clip without playing it. Bindings to variants and light slots are read but not followed yet. - In the game.
TAnimModel::set_channel(name, value)sets a channel (the self-test commandchannel <node> <name> <value>), the name regardless of case. Only scenery events and the self-test set channels so far; a vehicle (TDynamicObject: its cab controls, its state) has no hook to them yet. Each time the instance is drawn,RaPrepare()sets the nodes from the channels, after the clips, so a channel overrides a clip on the same node; an animation event of the scenery on the node takes over from both. A channel not set yet has its initial value. The nodes of the joints are flagged animated at load. - Scenery event.
event <name> animation <delay> <model> channel <channel> <value> endeventsets the channel. A channel the model hasn't givesBad event: ... can't find channelin the log. A new form of theanimationevent, which the current release doesn't read.
Skinning
A primitive with a skin (skin ≥ 0, weights in VSKN or VSKW) is drawn by the joints of its skin, in both renderers.
- Space. The vertices lie in the bind pose, in the space of the model, and the transform of the node of the mesh is left out,
as in glTF. The matrix of a joint is
world(joint) · inverse bind(joint), world being the transform of the node of the joint from the root of the model, with the animations of the instance. The inverse bind inSKJTso undoes the world of the joint in the bind pose. - Poses. The joints are ordinary nodes of the model, so they are posed as before:
animationevents, the animations of the.mmdand the code of the vehicles (GetFromName,SetRotate,SetTranslate), clips and channels. No API of its own is needed. - Palette. The pass of the renderer which first draws a skinned submodel of an instance in a frame works out the palette of the
joints on the CPU (
gfx::skin_cache,rendering/common/skincache.cpp, the maths inmodel/skinning.cpp). - Vertices. When the palette changed since the last frame, the vertices are moved before the passes of the next frame, as
nothing the passes draw changes while they draw (
gfx::walk_sync). The positions go by the blended matrix, the normals and the tangents by its rotation.- The Vulkan renderer does it in a compute shader (
shaders/vk14/skin.comp,rendering/vulkan14/vulkan14skinning.cpp): the bind pose with the weights goes to the GPU once for each skinned part, the palette in the ring of the frame, and the kernel writes the vertices straight into the buffer of the bank, over the geometry of the instance. When the bank makes its buffers anew (geometry of an instance made or let go), all the instances skinned on the GPU are moved again. - The OpenGL 4.6 renderer, and Vulkan with
gfx.skinning.gpu 0(default 1) or without the kernel, moves the vertices on the CPU and replaces the geometry of the instance. Both give the same picture.
- The Vulkan renderer does it in a compute shader (
- The vertices so follow the joints a frame late, and in its first frame an instance is in the bind pose.
- While the joints are in the bind pose, the geometry of the model is drawn, shared by all its instances. An instance not drawn for 600 frames lets go of its geometry.
- Limits of this version: the bounds of a submodel come from the bind pose; motion vectors and ray tracing don't see the moves of the joints.
Instancing of models with lights
With gfx.instancedlights 1 in eu07.ini, models with lights (lights, Light_On## / Light_Off##), such as signal heads, are
drawn instanced in both renderers, with the GPU culling and without it. The default 0 draws them as before, each instance on its
own. It applies to EU07M and E3D models alike.
- The light state of an instance is a word in the element
[0][3]of its instance matrix: bits 0–7 show the lit parts of the slots, bits 8–15 the dark ones, in the mantissa of a float of exponent 128 (0x40000000). Without that marker the shader draws everything. - A part of a light (
model_ubs.light_part: 0 none, 1 + slot lit, 9 + slot dark) the instance doesn't show gets a zero matrix in the shader (instance_hides_part()incommon.glsl). - An instance shows the whole lit part or the whole dark one. Blinking and switching (
ls_On/ls_Off/ls_Blink) change over at half the fade (opacity 0.5), not with the cross-fade of the draws instance by instance. Steady states look the same as without the instancing.ls_Darkandls_Homechange without the fade (fVisible) too. - An instance with light colours of its own (
lightcolorsof its node) is drawn on its own: the colours go onto the shared submodels as the instance is prepared, which the instances of a bucket don't each get. - Measured (Vulkan, 200 heads
s4ipcpb_dd): withgfx.gpucull 0the frame 9.2 ms → 1.5–2.5 ms and 2400 → 16 draw calls, withgfx.gpucull 19.1 ms → 3.0 ms and 2410 → 26 draw calls.
Backward compatibility
E3D and T3D are read as before. An .eu07m file is loaded only when it exists, behind the switch modelformat eu07m in
eu07.ini. The current release doesn't read .eu07m.