18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 22:07:55 +01:00
Commit Graph

4 Commits

Author SHA1 Message Date
maj00r fa98bdb8b0 Merge #535's review fixes into feat/e4d-load
Resolved: start_tools() parses the convertmodels flags with from_chars and both commands stop on bad flags; a vehicle's
.t3d is refused before it. The reader keeps the streams of this branch and the known sections of #535: an unknown
section the model needs is refused as unknown before its codec is looked at, and an unknown optional one in the codec of
the streams is passed over even by the tools, which can't keep it unpacked (forward compatibility of the codec flag). An
exception in a stream worker (no memory for a declared size) becomes the error of the file instead of std::terminate;
NOSONAR on the S2259 false positive there and on the seeded engines of the tests.
2026-11-29 17:53:28 +01:00
maj00r 0d095e225c fix(model): E4D review of #535: no guessed pass in the file, the header and the tree checked, unknown sections passed over
- The pass bits (0x30) BinInit guesses from a material when the E3D has none are marked (TSubModel::m_passguessed) and the
  converter leaves them out of legacy_flags and the primitive flags: it loads through the null renderer, whose materials
  all guess opaque, so the game makes the guess again with the real material.
- A vehicle's model isn't converted from its .t3d (dynamic 1): the game prepares it only after the vehicle marked its
  animated parts, so the .e3d the game makes of it is converted instead.
- read_header refuses a file_size smaller than the header, which made the hash check read outside the span.
- Sections seen twice are found with a set, not O(n^2); all the sections together may claim at most 2 GiB; a section the
  reader doesn't know and the model can do without is passed over before it is unpacked when keep_unknown is off.
- validate() checks that the parent of each node is the innermost node whose subtree holds it, so the tree of the ranges
  is the tree of the parents.
- Light_OnNN / Light_OffNN found by the game's GetFromName, so of two submodels of a name the same one counts; a
  replaceable skin drawn translucent gets material_flags::translucent; the convertmodels flags parsed without stoi.
- S3519: the matrix made with glm::make_mat4 instead of a memcpy into its first column; NOSONAR on the seeded engines of
  the tests (S2245).
- The spec: u16 indices up to 65 536 vertices, and the two rules above.

Tests: a file_size below the header, a node in the subtree of another than its parent, an unknown section passed over.
2026-11-29 17:25:23 +01:00
maj00r d8e6c6e36e feat(model): the game loads .e4d models, behind modelformat e4d in eu07.ini
Stage 2 of the E4D model format. With modelformat e4d a model with an .e4d file beside its .e3d / .t3d is loaded from it;
legacy, the default, leaves the .e4d files alone and the game loads models exactly as before. The key is written to the
log at the start.

- TModel3d::LoadFromE4D (model/e4d/e4d_load.cpp) builds the same tree of submodels LoadFromBinFile builds from E3D,
  and both go on through the same finish_binary() (the end of the E3D loading, moved out of deserialize unchanged).
  .mmd, events, GetFromName and the editor work as before. A file that can't be read or isn't valid is logged and the
  .e3d / .t3d is loaded instead. TModelsManager finds a model which comes as an .e4d alone.
- Format additions found by comparing loads (the format isn't released, so still version 1.0):
  - the LMAT component: the material of a node without geometry (light points, rotators), whose light threshold,
    colours and material the lights use;
  - node_flags::no_transform: an E3D submodel without a matrix, told apart from one with the identity matrix;
  - section_flags::meshopt: the vertex and index streams in the codecs of meshoptimizer (vertex codec version 1,
    index sequence codec), lossless, several times faster to unpack than zstd on this data. zstd packs the other
    sections; zstd over the coded streams is an option for archives (write_options::compress_streams).
- meshoptimizer v1.3 (MIT) as a submodule in ref/meshoptimizer; only its vertex and index codecs are built, into
  eu07_core.
- Loading speed: the big streams unpack on threads of their own, and a model of 100 000 vertices or more fills the
  vertices and indices of its submodels on up to 8 threads (std::jthread); the vertices are written once, without the
  zeroes of resize(). QTangent decoding takes the two matrix columns it needs without a square root.
- eu07 -e4d diff <e3d|t3d> <e4d> [dynamic] compares the two loads submodel by submodel and times them.

Checked:
- 250 random models of the installed game: all convert, and loaded from E4D they give the same tree, names, flags,
  materials and indices as from E3D; positions and UVs bit for bit, transforms within 6.5e-5, normals within 0.03 deg
  (4 vertices with a broken normal in the E3D get a proper one).
- Size 39% of the E3D (263 MB against 682 MB). Load outside the game, with the files in the system's cache: 516 ms
  against 561 ms, 0.75 of the time for the models of 5 MB and more, 1.21 for the smaller ones.
- In the game on Vulkan (self-test, the same 250 models): 3.05 s against 3.15 s to load them, the same frame time and
  device memory, the picture within 1/255 of the legacy one.
- Unit tests 1189/1189, among them the codecs with and without zstd, a codec on a wrong section and a cut stream. Not
  built with GCC here.

No asset change is needed: the game data has no .e4d files, and the release doesn't read them.
2026-11-28 20:55:57 +01:00
maj00r d6bace0fda feat(model): the E4D model format: spec, reader, writer and conversion from E3D/T3D
A fully binary successor of E3D, laid out for the GL 4.6 and Vulkan 1.4 renderers. Stage 1 of the plan: the format
and its tools. The game doesn't load .e4d yet; that is stage 2, behind a switch in eu07.ini.

- docs/e4d-format.md: the spec (in Polish, like world-format-eu07.md).
- model/e4d/e4d_format.h: the records and FourCCs, with static_asserts on sizes and offsets.
  - A table of sections with required/optional flags and zstd per section; tables carry count and stride, so a later
    version appends fields and an older reader takes the part it knows.
  - Nodes in depth-first order with TRS (XFRM for sheared matrices), meshes, 48-byte primitives.
  - Split vertex streams: VPOS f32x3, VATT QTangent snorm16x4 + UV f32x2 (28 B a vertex instead of 48 B), VSKN/VSKW
    skin weights, VUSR user data, VBND for primitives merged from several nodes (rigid joints, light slots).
  - Indices u16 or u32 per primitive, local to its base vertex.
  - Typed components on the model, nodes, meshes and vertex groups (PROP, SOCK, JOIN, SPRG, CHAN, VARI, CHNL, LSLT,
    LGHT, EMIT, MREF, COLL, LANM, LTXT, STAR), skins, vertex groups, a name index and bounds.
- model/e4d/e4d_io: write and read; the file is untrusted, so every offset, size, index, parent and reference is
  checked (validate) before anything is used, and a broken file is refused with a reason.
- model/e4d/e4d_build: QTangent packing, TRS from matrices, the name index and the bounds.
- model/e4d/e4d_convert: a model loaded from E3D or T3D into E4D, and the command line:
  eu07 -e4d convert <in.e3d|in.t3d> <out.e4d> [dynamic], eu07 -e4d dump <file>, eu07 -e4d validate <file>.
- zstd moves to eu07_core, which the unit tests link.
- tests/unit/test_e4d.cpp: round trip, section alignment, records of a later version, broken files, random mutations,
  QTangent, TRS, name lookup, bounds, merged primitives.

Checked: 250 random .e3d of the installed game convert (E4D 21% of their size with zstd, 60% without), and the
vehicle families en57_v2, t448p_v2 and vectron_v1 (701 files). Unit tests 1188/1188. Not built with GCC here.
2026-11-28 19:45:55 +01:00