18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-03 00:45:29 +01:00
Commit Graph

18 Commits

Author SHA1 Message Date
maj00r ecfb99db1a Merge branch 'feat/eu07m-gref' of https://github.com/MaSzyna-EU07/maszyna into feat/eu07m-model-inspector
# Conflicts:
#	model/AnimModel.h
2026-11-29 21:34:23 +01:00
maj00r b03fff75df Merge the review fixes of the PRs below from feat/eu07m-channels into feat/eu07m-gref 2026-11-29 18:23:01 +01:00
maj00r 6efc1eb718 Merge the review fixes of the PRs below from feat/eu07m-clip-event into feat/eu07m-channels
RaPrepare() applies the clips, then the channels, then the animation events, so an event on a node takes over from both.
The spec has the fixes of #538, #540 and #542 in English.
2026-11-29 18:23:01 +01:00
maj00r c171e2e7d5 Merge the review fixes of the PRs below from feat/eu07m-skinning into feat/eu07m-clips 2026-11-29 18:22:13 +01:00
maj00r ce40e11b94 fix(model): EU07M review of #543: channel names keep their case, the joint moves from its rest value
- The channel event reads the name of the channel as written (getTokens lowercased it), and set_channel() finds it
  regardless of case: a channel named doorLeft couldn't be set from a scenery.
- JOIN.rest is read: the node is modelled at the rest value of its joint, which moves it by the value less rest (the
  limits stay values of the joint). A part modelled half open no longer jumps when its channel is set. Files without it
  (rest 0) move as before.
- The spec says so, and that no vehicle sets channels yet.

Test: a slider modelled half out.
2026-11-29 18:20:09 +01:00
maj00r 474c9ab5ae fix(model): EU07M review of #540: stopped clips held per instance, events over clips, the rest of a matrix node from its matrix
- stop_clips() holds each clip at the moment it was stopped instead of dropping it: the pose lives in the submodels the
  instances of a model share, so an instance whose clips were cleared snapped back to rest as soon as another instance of
  the model played one (two doors of one model).
- RaPrepare() applies the clips before the animation events of the scenery, so an event moving a node (rotate,
  translate...) takes it over from a clip, one ended or stopped included; before, a finished clip overrode the events
  on its nodes on every draw.
- A node with a matrix (XFRM) has its TRS fields only as an approximation: the parts the tracks of a clip don't move are
  taken from the decomposed matrix, so the node no longer jumps or skews when a clip starts moving another part of it.
- The spec says so.
2026-11-29 18:17:49 +01:00
maj00r 115c13b274 fix(model): EU07M review of #539: a model made anew keeps its transforms, normals of scaled joints, the rest pose far from the origin
- A node of a model made anew (legacy_flags 0) with a transform gets 0x8000, as a converted one has it: the walk and
  posed_transform() left such nodes out, so a skin was drawn off its place in the bind pose (the tube: the upper half 2 m
  off) and jumped when an animation set 0x4000 on the joint.
- Normals are skinned by the cofactors of the blended rotation (the direction of its inverse transpose), with the sign of
  its determinant, not by the rotation: a joint scaled unevenly tilted the normals of its part.
- rest_pose() takes the translation within the tolerance times the distance from the origin of the mesh and the joints
  (palette_scale()): the float chain rounds in proportion to it, and a model a few kilometres out counted as posed in the
  bind pose, with a geometry copy and a skinning pass of its own.

Tests: the rest pose far from the origin, the normals of a stretched and of a mirroring joint.
2026-11-29 18:16:19 +01:00
maj00r 107cc3c927 feat(editor): the EU07M window edits in 3D, holds vehicle parts and adds lights
The window of an EU07M model gets tabs: the tree of the nodes beside
the properties of the node picked, the parts of the vehicle, the clips
and channels, and the components of the model. The texts are Polish in
lang/editor_pl.po.

- With nothing selected, it shows the model of the vehicle driven (its
  body or its cab).
- In the 3D view the node picked is framed and shows its axes and a
  gizmo to move or turn it. The light sources are marked in their colour,
  a spot with its axis, and a click on a mark picks its node. A press on
  the gizmo or a mark doesn't pick a scenery node, and the editor's own
  gizmo gives way. A double click in the tree flies the camera there.
- The settings of a node: its position, rotation (degrees) and scale,
  and the distances it is drawn from and up to.
- "Add a light source here" puts in a node light_<n> with a point or
  spot LGHT as the last child of the node. eu07m::insert_node moves
  every reference to the nodes after it, and eu07m::add_component
  appends a component; both have unit tests.
- Changes show at once on the model the game has, through new TModel3d
  methods for the editor (ApplyEU07MLight, AddEditorLight,
  SetEditorTransform, SetEditorRange). The spot's cones are edited as
  half angles in degrees.
- Parts of the vehicle: the editor holds the lamps, coupler hooks and
  hoses in their _off/_on/_xon state, and the pantographs up or down,
  whatever the vehicle does. A held pantograph moves at its own pace,
  in the editor too, up to the wire above it. Only the look changes:
  the electrics of the vehicle don't.
- Neither the empty-scenery line nor the no-tracks hint shows in a
  scenery of models alone.
- New editor self-test command: modelnode <name>.
2026-11-29 18:11:38 +01:00
maj00r 8b75db6b70 Merge the review fixes of #535 and #536 from feat/eu07m-channels into feat/eu07m-gref 2026-11-29 17:55:01 +01:00
maj00r c6ece72d6a Merge the review fixes of #535 and #536 from feat/eu07m-clip-event into feat/eu07m-channels 2026-11-29 17:54:59 +01:00
maj00r 628f7eb707 Merge the review fixes of #535 and #536 from feat/eu07m-skinning into feat/eu07m-clips 2026-11-29 17:54:44 +01:00
maj00r 0efab6a080 Merge the review fixes of #535 and #536 from feat/eu07m-instancing into feat/eu07m-skinning 2026-11-29 17:54:34 +01:00
maj00r 20f2156ce2 Merge #535 and #536's review fixes into feat/e4d-compact
Resolved for the rename to EU07M: the stale-file check is eu07m_up_to_date() before LoadFromEU07M, the loader catches
what reading throws, and the new tests name eu07m::.
2026-11-29 17:54:01 +01:00
maj00r d930b6519d feat(model): the geometry shared by the variants of a family kept once, in a store of the folder
The variants of a vehicle repeat the same parts byte for byte, and each EU07M file carried them all again. PR #521 showed the
problem on E3D; EU07M solves it in the format.

- Block: the geometry of one primitive, its vertices in every vertex stream of the file and its indices, with a 16-byte header;
  its id is 128 bits, two FNV-1a 64 of its bytes. Only a primitive whose vertex and index ranges are its own can be shared.
- Store: geometry.eu07mpack in the folder of the models, the blocks each once (zstd when it saves an eighth) and an index
  sorted by their id (model/eu07m/eu07m_store.{h,cpp}).
- GREF, a new required section: the primitives kept in the store. The writer leaves their ranges out of the streams of the
  file; the reader takes their blocks from the store (read_options::blocks), checks the id and the counts of each and puts
  them back in place, so the model in memory has its whole streams and nothing past the reader knows the difference. A
  model with references and no store, or with a block which isn't the one referred to, is refused with the reason. The
  validator checks the references (primitive, counts, ranges of its own).
- The game opens the store of a folder once and keeps it (eu07m::family_store()); dump and validate read it too.
- Tools: "-eu07m pack <folder> [minimum bytes]" moves every block of at least 4 KiB (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 read back and compared with what it was before it's replaced; "-eu07m unpack <folder>" writes them whole again.

Measured on copies of the converted models of the game: cd/181_v2 60.8 MB -> 4.0 MB (7%), pkp/11xa_v2/main 69.3 MB ->
5.8 MB (8%), pkp/elf_v1 109.6 MB -> 39.0 MB (36%), pkp/en57_v1 104.1 MB -> 39.3 MB (38%), 2-4 s a folder. All 223 packed
files pass -eu07m validate with their store. Four ELF parts drawn in the game (Vulkan) from the packed and from the whole
files, with the auto exposure off and the same seed: no pixel differs by more than 1. Unit tests 1208/1208, 4 new ones for a
round trip through a store, a model without its store, a wrong block, a primitive sharing its vertices and a folder packed,
packed again and unpacked.

The renderer still makes the geometry of each model on its own; sharing one range of the buffers between the models of a
family is the next step. No asset change: the game data has no .eu07m files, and the release doesn't read them.
2026-11-29 04:03:49 +01:00
maj00r 55c7050c49 feat(model): the channels of EU07M models move joints and scrub clips
A channel (CHNL component) is a named value of a model, kept within its range, which moves what it's bound to. The game now
follows its bindings to joints and to clips.

- A joint binding (a JOIN component of a node): the value of the target (channel * scale + offset) turns a hinge (radians)
  or a screw (turning and moving by its pitch), 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
  (animation::joint_transform()).
- A clip binding: 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.
- Format, before the release: the target of a clip binding is the index of the clip in ACLP (clips aren't components); the
  validator checks the target by the kind of the binding (a joint has to be a JOIN component).
- TAnimModel::set_channel(name, value); a channel not set has its initial value. RaPrepare() sets the nodes from the
  channels after the clips playing, so a channel overrides a clip on the same node. The nodes of the joints are flagged
  animated at load, which keeps the model out of the instancing.
- New form of the animation event: "animation <delay> <model> channel <name> <value>"; a channel the model hasn't gets
  "Bad event: ... can't find channel ..." in the log. The current release doesn't read the new form.
- The editor self-test gets "channel <node> <name> <value>".

Checked in the game (Vulkan, a skinned tube with a hinge on its tip and a clip on its base): "bend 1" from the self-test
and "bend -1" from an event turn the tip both ways, "phase 0.5" from an event turns the whole tube through the clip, an
unknown channel logs the error. Unit tests 1204/1204, 4 new ones for the hinge, slider, screw and limits, the range of a
channel and the targets of the bindings in the file. Not built with GCC here.
2026-11-29 01:47:21 +01:00
maj00r c8068d8f3d feat(model): animation clips of EU07M models, played on scenery instances
Stage 8 of the EU07M model format. A model can carry animation clips; each track of a clip sets the translation, the
rotation or the scale of a node at a time of the clip, and the parts of a node without a track keep its TRS.

- Format, five optional sections: ACLP (clips: name, duration, flags 0x1 loop and 0x2 autoplay, range of tracks), ATRK
  (tracks: node, part, interpolation step / linear / cubic, ranges of keys), ATIM (key times), AVEC (vectors; with cubic
  the in-tangent, value and out-tangent of glTF) and AROT (rotations in 8 bytes, "smallest three": the three smaller
  components as snorm16 scaled by sqrt(2) and the index of the largest; eu07m::encode_rotation / decode_rotation).
  The validator refuses a node out of range, keys out of their arrays, times which aren't numbers from 0 up, a cubic
  rotation and tracks out of the range of the clip. -eu07m dump lists the clips and their tracks. The current release
  doesn't read these sections; a file without them loads as before.
- Sampling (model/clip.cpp): step, lerp / slerp the shorter way, the Hermite spline of glTF with tangents per second;
  the first and the last key held outside of them; a looped clip goes around its duration, another stops at its end.
- In the game: the clips play by the simulation time, from TAnimModel::play_clip(name, speed) or, flagged autoplay, from
  the first time the instance is drawn. RaPrepare() samples them for the instance drawn and sets the transforms of the
  nodes (TSubModel::SetClipTransform(), the new animation type at_Clip, gated by the instance like the others), so a clip
  moving the joints of a skin bends the skinned parts. The nodes a clip moves are flagged animated at load, which keeps
  the model out of the instancing. stop_clips() stops them.
- The editor self-test gets "clip <node> <name> [speed]".

Not yet: a scenery event starting a clip, and the CHNL channels bound to the time of a clip.

Checked: a skinned tube with an autoplay clip (the tip to 60 degrees and back in 2 s, looped) beside a still one, six
screenshots in Vulkan and in GL 4.6 go from straight to fully bent while the other stays (time let run in the editor for
the test only). Unit tests 1200/1200, 6 new ones for the packing, the interpolations, the time and the file. Not built
with GCC here.
2026-11-29 00:49:44 +01:00
maj00r d324c53233 feat(model): skinned parts of EU07M models move with their joints, skinned on the CPU
Stage 4 of the EU07M model format. A primitive with a skin (SKIN, SKJT, weights in VSKN or VSKW) was drawn in its bind
pose. Now it follows the joints of its skin, in both renderers.

- The joints are nodes of the model, so they're posed as before: animation events, the .mmd, SetRotate / SetTranslate
  from the vehicle code. The matrix of a joint is world(joint) * inverse bind(joint), world being the transform of the
  joint from the root of the model with the animations of the instance drawn (TSubModel::posed_transform()); the
  vertices lie in the bind pose in the space of the model, the transform of the node of the mesh left out, as in glTF.
- The loader keeps the bind pose and the weights of a skinned primitive (skinning::skinned_geometry on the submodel) and
  the skins of the model (TModel3d::skins()).
- The first pass of a frame to draw a skinned submodel of an instance works out the palette and, when it changed, moves
  the vertices on the CPU: positions by the blended matrix, normals and tangents by its rotation (model/skinning.cpp,
  gfx::skin_cache in rendering/common/skincache.cpp). The geometry of the instance is made or replaced before the passes
  of the next frame (flush() in the frame setup of both renderers), as nothing the passes draw may change while they draw
  (gfx::walk_sync): the vertices follow the joints a frame late. In the bind pose the shared geometry of the model is
  drawn; an instance not drawn for 600 frames lets go of its own.
- Fix: a node with range_max_sq 0, which the spec gives as no limit, was never drawn (a model made anew rather than
  converted from E3D); it keeps the default range of a submodel now.
- The editor self-test gets "animate <node> <submodel> <x> <y> <z>", which turns a submodel of an instance as an
  animation event does, since the editor doesn't run the events.

Not in this commit: the skinning in a compute shader, bounds of the posed submodel, motion vectors and ray tracing of the
moved vertices.

Checked: a tube of two joints in two instances, one turned by 60 degrees at its middle, bends smoothly while the other
stays straight, in Vulkan and GL 4.6, with gfx.gpucull 0 and 1 (time let run in the editor for the test only). Unit
tests 1194/1194, 5 new ones for the weights, the bind pose, the blending and the file. Not built with GCC here.
2026-11-28 23:52:35 +01:00
maj00r 92cc2dcc28 refactor(model): the new model format is EU07M (.eu07m), not E4D
E4D read as the next version of E3D, which the format isn't meant to be tied to; EU07M goes with the world format .eu07.
The format isn't released, so nothing reads the old name.

- The extension .eu07m, the magic EU7M (the four bytes of the header), model/eu07m/ with eu07m_*.{h,cpp},
  namespace eu07m, docs/eu07m-format.md, tests/unit/test_eu07m.cpp.
- The command line -eu07m convert|dump|validate|diff, TModel3d::LoadFromEU07M, and the key modelformat eu07m|legacy
  of eu07.ini (Global.modelformat_eu07m).
- Nothing else changes: the sections, the records and the components are the same, so a converted file needs only its
  magic and its extension changed.

Unit tests 1189/1189.
2026-11-28 22:02:05 +01:00