18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 15:17:08 +01:00

Merge branch 'feat/eu07m-gref' into feat/eu07m-model-inspector

This commit is contained in:
maj00r
2026-11-30 22:27:03 +01:00
12 changed files with 34 additions and 34 deletions
+8 -8
View File
@@ -1,4 +1,4 @@
# The EU07M model format (`.r3a`)
# The EU07M model format (`.ng3d`)
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
@@ -196,7 +196,7 @@ of the game, the folders of a family are 7% to 38% of their size with their shar
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 seeds
`0xcbf29ce484222325` and `0x84222325cbf29ce4`. 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.r3p` in the folder of the models: a 32 B header (magic `EU7P`, `u16` major 1,
- **The store** of the family is `geometry.ng3p` in the folder of the models: a 32 B header (magic `EU7P`, `u16` major 1,
`u16` minor 0, `u32` block count, `u32` flags, `u64` offset 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 × 2` id, `u64` offset, `u32` size in the file,
`u32` size unpacked, `u32` flags (0x1 zstd), `u32` 0), sorted by the id.
@@ -260,7 +260,7 @@ component; `0xFFFFFFFF` = none.
## Conversion from E3D and T3D
`eu07 -eu07m convert <input.e3d|.t3d> <output.r3a> [dynamic]` loads the model with the existing loader (as `-e3d` does) and writes
`eu07 -eu07m convert <input.e3d|.t3d> <output.ng3d> [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 `.mmd` and the events work as
@@ -275,13 +275,13 @@ it as EU07M:
game makes of it, not from its `.t3d`.
- A replaceable skin `-k` drawn in the translucent pass (bit k−1 of the E3D flags) has the `translucent` flag in `MATL`.
The other commands: `eu07 -eu07m dump <file.r3a>` (the content as text, clips included) and `eu07 -eu07m validate <file.r3a>`
The other commands: `eu07 -eu07m dump <file.ng3d>` (the content as text, clips included) and `eu07 -eu07m validate <file.ng3d>`
(a check of the file with the hash of its content).
## In the game
With `modelformat r3a` in `eu07.ini`, a model with an `.r3a` file beside its `.e3d` / `.t3d` (or alone) is loaded from it
(`TModel3d::LoadFromEU07M`). The default `modelformat legacy` leaves `.r3a` files alone.
With `modelformat ng3d` in `eu07.ini`, a model with an `.ng3d` file beside its `.e3d` / `.t3d` (or alone) is loaded from it
(`TModel3d::LoadFromEU07M`). The default `modelformat legacy` leaves `.ng3d` 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
@@ -461,5 +461,5 @@ own. It applies to EU07M and E3D models alike.
## Backward compatibility
E3D and T3D are read as before. An `.r3a` file is loaded only when it exists, behind the switch `modelformat r3a` in
`eu07.ini`. The current release doesn't read `.r3a`.
E3D and T3D are read as before. An `.ng3d` file is loaded only when it exists, behind the switch `modelformat ng3d` in
`eu07.ini`. The current release doesn't read `.ng3d`.
+2 -2
View File
@@ -167,8 +167,8 @@ TModelsManager::find_on_disk( std::string const &Name ) {
std::vector<std::string> extensions { { ".e3d" }, { ".t3d" } };
if( Global.modelformat_eu07m ) {
// a model may come as an .r3a alone
extensions.emplace_back( ".r3a" );
// a model may come as an .ng3d alone
extensions.emplace_back( ".ng3d" );
}
for( auto const &extension : extensions ) {
+3 -3
View File
@@ -1831,7 +1831,7 @@ glm::vec3 TSubModel::offset(float const Geometrytestoffsetthreshold) const
namespace
{
// modelformat r3a: an .r3a older than the .e3d / .t3d it was made from isn't used, the model was changed after it was
// modelformat ng3d: an .ng3d older than the .e3d / .t3d it was made from isn't used, the model was changed after it was
// converted (the hash of the source in its header would need the source read whole to be compared)
bool eu07m_up_to_date(std::string const &Eu07m, std::initializer_list<std::string> const Sources)
{
@@ -1953,10 +1953,10 @@ bool TModel3d::LoadFromFile(std::string const &FileName, bool dynamic)
Init();
assign_lod_ranges(Root, name);
}
else if (auto const eu07mfile{Global.modelformat_eu07m ? FileCased(name + ".r3a") : std::string{}};
else if (auto const eu07mfile{Global.modelformat_eu07m ? FileCased(name + ".ng3d") : std::string{}};
(false == eu07mfile.empty()) && eu07m_up_to_date(eu07mfile, {binaryfile, textfile}) && LoadFromEU07M(eu07mfile, dynamic))
{
// modelformat r3a: the .r3a made from the model takes its place; one which doesn't load leaves the .e3d / .t3d to go on
// modelformat ng3d: the .ng3d made from the model takes its place; one which doesn't load leaves the .e3d / .t3d to go on
asBinary = "";
Init();
assign_lod_ranges(Root, name);
+4 -4
View File
@@ -320,7 +320,7 @@ bool load_source(std::string const &Input, bool const Dynamic, TModel3d &Source,
auto const start{std::chrono::steady_clock::now()};
if (extension_of(Input) == ".e3d")
Source.LoadFromBinFile(Input, Dynamic);
else if (extension_of(Input) == ".r3a")
else if (extension_of(Input) == ".ng3d")
Source.LoadFromEU07M(Input, Dynamic);
else
Source.LoadFromTextFile(Input, Dynamic);
@@ -481,7 +481,7 @@ void model_diff::geometry(TSubModel const &Left, TSubModel const &Right) {
int command_diff(int const Argc, char *Argv[]) {
if (Argc < 5) {
std::cerr << "usage: -eu07m diff <model.e3d|model.t3d> <model.r3a> [dynamic 0|1]\n";
std::cerr << "usage: -eu07m diff <model.e3d|model.t3d> <model.ng3d> [dynamic 0|1]\n";
return 2;
}
if (false == start_tools(Argc, Argv))
@@ -506,7 +506,7 @@ int command_diff(int const Argc, char *Argv[]) {
int command_convert(int const Argc, char *Argv[]) {
if (Argc < 5) {
std::cerr << "usage: -eu07m convert <model.e3d|model.t3d> <model.r3a> [dynamic 0|1] [convertmodels flags]\n";
std::cerr << "usage: -eu07m convert <model.e3d|model.t3d> <model.ng3d> [dynamic 0|1] [convertmodels flags]\n";
return 2;
}
std::string const input{Argv[3]};
@@ -548,7 +548,7 @@ int command_convert(int const Argc, char *Argv[]) {
int command_read(int const Argc, char *Argv[], bool const Dump) {
if (Argc < 4) {
std::cerr << std::format("usage: -eu07m {} <model.r3a>\n", Dump ? "dump" : "validate");
std::cerr << std::format("usage: -eu07m {} <model.ng3d>\n", Dump ? "dump" : "validate");
return 2;
}
auto const file{read_whole_file(Argv[3])};
+1 -1
View File
@@ -377,7 +377,7 @@ struct packed_rotation {
};
static_assert(sizeof(packed_rotation) == 8);
// the geometry of a primitive kept in the geometry store of the family of the model (geometry.r3p beside the file) instead of
// the geometry of a primitive kept in the geometry store of the family of the model (geometry.ng3p beside the file) instead of
// in the file: its vertices in every vertex stream of the file and its indices. the writer leaves its ranges out of the streams of the
// file, and the reader puts the block of the store back in their place, so the model in memory always has its whole streams
struct geometry_reference_record {
+1 -1
View File
@@ -73,7 +73,7 @@ bool write_file(std::filesystem::path const &Path, std::span<std::byte const> Da
bool is_model(std::filesystem::directory_entry const &Entry) {
auto extension{Entry.path().extension().string()};
std::ranges::transform(extension, extension.begin(), [](unsigned char const Letter) { return static_cast<char>(std::tolower(Letter)); });
return Entry.is_regular_file() && extension == ".r3a";
return Entry.is_regular_file() && extension == ".ng3d";
}
// the models of the folder read whole, with the store there is; false when one can't be read
+1 -1
View File
@@ -28,7 +28,7 @@ struct pack_result {
};
// the geometry of the primitives of at least MinBytes which occur more than once in the models of the folder moved to its store
// (geometry.r3p), made anew from all of them; the models are written again referring to it. every model is read back and
// (geometry.ng3p), made anew from all of them; the models are written again referring to it. every model is read back and
// compared with what it was before it's replaced. what was done goes to Log
pack_result pack_folder(std::filesystem::path const &Folder, std::size_t MinBytes, std::ostream &Log);
// the models of the folder written again with their whole geometry; the store is left for the user to delete
+2 -2
View File
@@ -10,7 +10,7 @@ http://mozilla.org/MPL/2.0/.
#pragma once
// the geometry shared by the models of a family (the variants of a vehicle): blocks of the geometry of primitives kept once in the
// store of the folder (geometry.r3p) and referred to by the models (GREF) instead of being repeated in each of them
// store of the folder (geometry.ng3p) and referred to by the models (GREF) instead of being repeated in each of them
#include "model/eu07m/eu07m_model.h"
@@ -26,7 +26,7 @@ namespace eu07m {
using block_id = std::array<std::uint64_t, 2>;
// the name of the store in the folder of the models
constexpr char const *store_file_name{"geometry.r3p"};
constexpr char const *store_file_name{"geometry.ng3p"};
// the streams a block carries, in this order after its header
namespace block_streams {
+5 -5
View File
@@ -177,9 +177,9 @@ TEST_CASE("gref: a folder packed and unpacked") {
auto const a{variant(40, 0.f, 1.f)};
auto const b{variant(40, 0.f, 2.f)};
auto const c{variant(40, 5.f, 3.f)};
save(folder / "a.r3a", eu07m::write(a));
save(folder / "b.r3a", eu07m::write(b));
save(folder / "c.r3a", eu07m::write(c));
save(folder / "a.ng3d", eu07m::write(a));
save(folder / "b.ng3d", eu07m::write(b));
save(folder / "c.ng3d", eu07m::write(c));
std::ostringstream log;
auto const packed{eu07m::pack_folder(folder, 4096, log)};
@@ -195,7 +195,7 @@ TEST_CASE("gref: a folder packed and unpacked") {
REQUIRE(store.open(folder / eu07m::store_file_name, error));
eu07m::read_options options;
options.blocks = memory_source(store);
for (auto const &[name, original] : {std::pair{"a.r3a", &a}, std::pair{"b.r3a", &b}, std::pair{"c.r3a", &c}}) {
for (auto const &[name, original] : {std::pair{"a.ng3d", &a}, std::pair{"b.ng3d", &b}, std::pair{"c.ng3d", &c}}) {
eu07m::model read;
REQUIRE(eu07m::read(load(folder / name), read, options).ok);
CHECK(same_streams(read, *original));
@@ -207,7 +207,7 @@ TEST_CASE("gref: a folder packed and unpacked") {
auto const unpacked{eu07m::unpack_folder(folder, log)};
REQUIRE(unpacked.ok);
eu07m::model whole;
REQUIRE(eu07m::read(load(folder / "b.r3a"), whole, {}).ok);
REQUIRE(eu07m::read(load(folder / "b.ng3d"), whole, {}).ok);
CHECK(whole.geometry_references.empty());
CHECK(same_streams(whole, b));
std::filesystem::remove_all(folder);
+3 -3
View File
@@ -216,7 +216,7 @@ TEST_CASE("skinning: the skinned tube is a valid EU07M file") {
CHECK(read.weights.size() == read.positions.size());
CHECK(read.primitives[0].skin == 0);
// kept in the scratch folder for a look in the game
auto const path{std::filesystem::path{EU07_UNIT_TESTS_SCRATCH} / "skinned_tube.r3a"};
auto const path{std::filesystem::path{EU07_UNIT_TESTS_SCRATCH} / "skinned_tube.ng3d"};
std::ofstream output{path, std::ios::binary};
output.write(reinterpret_cast<char const *>(file.data()), static_cast<std::streamsize>(file.size()));
CHECK(output.good());
@@ -243,7 +243,7 @@ TEST_CASE("skinning: the tube bent by a clip of its own") {
}
CHECK(eu07m::validate(model, 16).empty());
auto const file{eu07m::write(model, {true, 9})};
auto const path{std::filesystem::path{EU07_UNIT_TESTS_SCRATCH} / "clip_tube.r3a"};
auto const path{std::filesystem::path{EU07_UNIT_TESTS_SCRATCH} / "clip_tube.ng3d"};
std::ofstream output{path, std::ios::binary};
output.write(reinterpret_cast<char const *>(file.data()), static_cast<std::streamsize>(file.size()));
CHECK(output.good());
@@ -292,7 +292,7 @@ TEST_CASE("skinning: the tube moved by channels") {
model.add_component(eu07m::component::channel, eu07m::target_kind::model, 0, eu07m::payload_writer{}.put(phase).put(toclip).data());
CHECK(eu07m::validate(model, 16).empty());
auto const file{eu07m::write(model, {true, 9})};
auto const path{std::filesystem::path{EU07_UNIT_TESTS_SCRATCH} / "channel_tube.r3a"};
auto const path{std::filesystem::path{EU07_UNIT_TESTS_SCRATCH} / "channel_tube.ng3d"};
std::ofstream output{path, std::ios::binary};
output.write(reinterpret_cast<char const *>(file.data()), static_cast<std::streamsize>(file.size()));
CHECK(output.good());
+3 -3
View File
@@ -1001,10 +1001,10 @@ bool global_settings::ConfigParseSimulation(cParser& Parser, const std::string&
if (token == "modelformat")
{
// r3a: a model with an .r3a file beside its .e3d / .t3d is loaded from it; legacy: the .r3a files are left alone
// ng3d: a model with an .ng3d file beside its .e3d / .t3d is loaded from it; legacy: the .ng3d files are left alone
std::string value;
ParseOne(Parser, value, 1);
modelformat_eu07m = value == "r3a";
modelformat_eu07m = value == "ng3d";
return true;
}
@@ -2700,7 +2700,7 @@ global_settings::export_as_text( std::ostream &Output ) const {
export_as_text( Output, "hiddenevents", iHiddenEvents );
export_as_text( Output, "pause", ( iPause & 1 ) != 0 );
export_as_text(Output, "priorityLoadText3D", priorityLoadText3D);
export_as_text(Output, "modelformat", std::string{modelformat_eu07m ? "r3a" : "legacy"});
export_as_text(Output, "modelformat", std::string{modelformat_eu07m ? "ng3d" : "legacy"});
export_as_text( Output, "lang", asLang );
export_as_text( Output, "python.updatetime", PythonScreenUpdateRate );
Output
+1 -1
View File
@@ -121,7 +121,7 @@ struct global_settings {
int file_binary_terrain_skipped{0}; // number of terrain includes left out by the parser during the current scenery load
// logs
bool priorityLoadText3D{false}; // ladowanie T3D priorytetowo
bool modelformat_eu07m{false}; // modelformat r3a: models are loaded from their .r3a files where there are some
bool modelformat_eu07m{false}; // modelformat ng3d: models are loaded from their .ng3d files where there are some
int iWriteLogEnabled{ 3 }; // maska bitowa: 1-zapis do pliku, 2-okienko, 4-nazwy torów
bool MultipleLogs{ false };
bool crashdump_full{ false }; // crash dump with the whole memory of the process instead of the small one