mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 14:16:48 +01:00
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.
This commit is contained in:
+3
-3
@@ -166,9 +166,9 @@ std::string
|
||||
TModelsManager::find_on_disk( std::string const &Name ) {
|
||||
|
||||
std::vector<std::string> extensions { { ".e3d" }, { ".t3d" } };
|
||||
if( Global.modelformat_e4d ) {
|
||||
// a model may come as an .e4d alone
|
||||
extensions.emplace_back( ".e4d" );
|
||||
if( Global.modelformat_eu07m ) {
|
||||
// a model may come as an .eu07m alone
|
||||
extensions.emplace_back( ".eu07m" );
|
||||
}
|
||||
for( auto const &extension : extensions ) {
|
||||
|
||||
|
||||
+4
-4
@@ -1875,9 +1875,9 @@ bool TModel3d::LoadFromFile(std::string const &FileName, bool dynamic)
|
||||
Init();
|
||||
assign_lod_ranges(Root, name);
|
||||
}
|
||||
else if (auto const e4dfile{Global.modelformat_e4d ? FileCased(name + ".e4d") : std::string{}}; (false == e4dfile.empty()) && LoadFromE4D(e4dfile, dynamic))
|
||||
else if (auto const eu07mfile{Global.modelformat_eu07m ? FileCased(name + ".eu07m") : std::string{}}; (false == eu07mfile.empty()) && LoadFromEU07M(eu07mfile, dynamic))
|
||||
{
|
||||
// modelformat e4d: the .e4d made from the model takes its place; one which doesn't load leaves the .e3d / .t3d to go on
|
||||
// modelformat eu07m: the .eu07m 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);
|
||||
@@ -2651,7 +2651,7 @@ void TModel3d::deserialize(std::istream &s, size_t size, bool dynamic)
|
||||
finish_binary(dynamic, hastangents);
|
||||
}
|
||||
|
||||
// the submodels read from a file (E3D or E4D) tied together, their materials looked up and their geometry handed to the renderer
|
||||
// the submodels read from a file (E3D or EU07M) tied together, their materials looked up and their geometry handed to the renderer
|
||||
void TModel3d::finish_binary(bool const dynamic, bool const hastangents)
|
||||
{
|
||||
for (size_t i = 0; (int)i < iSubModelsCount; ++i)
|
||||
@@ -2681,7 +2681,7 @@ void TModel3d::finish_binary(bool const dynamic, bool const hastangents)
|
||||
}
|
||||
if (false == Root[i].CompactPositions.empty())
|
||||
{
|
||||
// a submodel of an E4D model: its compact streams as they are, the renderer keeps them or makes basic_vertex of them
|
||||
// a submodel of an EU07M model: its compact streams as they are, the renderer keeps them or makes basic_vertex of them
|
||||
Root[i].m_geometry.handle = GfxRenderer->Insert_Compact(Root[i].Indices, Root[i].CompactPositions, Root[i].CompactAttributes, Root[i].Userdata, m_geometrybank, type);
|
||||
continue;
|
||||
}
|
||||
|
||||
+3
-3
@@ -159,7 +159,7 @@ public: // chwilowo
|
||||
gfx::vertex_array Vertices;
|
||||
gfx::userdata_array Userdata;
|
||||
gfx::index_array Indices;
|
||||
// the compact streams of a submodel loaded from E4D, in place of Vertices till they go to the renderer (Insert_Compact())
|
||||
// the compact streams of a submodel loaded from EU07M, in place of Vertices till they go to the renderer (Insert_Compact())
|
||||
gfx::position_array CompactPositions;
|
||||
gfx::compact_array CompactAttributes;
|
||||
float m_boundingradius { 0 };
|
||||
@@ -341,9 +341,9 @@ public:
|
||||
void AddTo(TSubModel *tmp, TSubModel *SubModel);
|
||||
void LoadFromTextFile(std::string const &FileName, bool dynamic);
|
||||
void LoadFromBinFile(std::string const &FileName, bool dynamic);
|
||||
// the model from an E4D file (model/e4d/e4d_load.cpp), as LoadFromBinFile builds it from E3D. returns false, with the reason
|
||||
// the model from an EU07M file (model/eu07m/eu07m_load.cpp), as LoadFromBinFile builds it from E3D. returns false, with the reason
|
||||
// in the log and nothing loaded, when the file can't be read or isn't valid
|
||||
bool LoadFromE4D(std::string const &FileName, bool dynamic);
|
||||
bool LoadFromEU07M(std::string const &FileName, bool dynamic);
|
||||
bool LoadFromFile(std::string const &FileName, bool dynamic);
|
||||
TSubModel *AppendChildFromGeometry(const std::string &name, const std::string &parent, const gfx::vertex_array &vertices, const gfx::index_array &indices);
|
||||
void SaveToBinFile(std::string const &FileName);
|
||||
|
||||
@@ -9,14 +9,14 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "model/e4d/e4d_build.h"
|
||||
#include "model/eu07m/eu07m_build.h"
|
||||
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
#include <limits>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace e4d {
|
||||
namespace eu07m {
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -271,4 +271,4 @@ void compute_bounds(model &Model) {
|
||||
Model.bounds.push_back(to_bounds(whole, whole.empty() ? 0.f : glm::length(whole.max - whole.centre())));
|
||||
}
|
||||
|
||||
} // namespace e4d
|
||||
} // namespace eu07m
|
||||
@@ -9,14 +9,14 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#pragma once
|
||||
|
||||
// the helpers which make and read the data of an E4D model: the tangent frames, the transforms of the nodes, the index of
|
||||
// the helpers which make and read the data of an EU07M model: the tangent frames, the transforms of the nodes, the index of
|
||||
// the names and the bounds
|
||||
|
||||
#include "model/e4d/e4d_model.h"
|
||||
#include "model/eu07m/eu07m_model.h"
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
namespace e4d {
|
||||
namespace eu07m {
|
||||
|
||||
struct tangent_frame {
|
||||
glm::vec3 normal{0.f, 0.f, 1.f};
|
||||
@@ -47,4 +47,4 @@ std::vector<std::uint32_t> find_nodes(model const &Model, std::string_view Name)
|
||||
// the bounds of every node (its own geometry, in its space) and of the whole model, and the spheres of the primitives
|
||||
void compute_bounds(model &Model);
|
||||
|
||||
} // namespace e4d
|
||||
} // namespace eu07m
|
||||
@@ -9,11 +9,11 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "model/e4d/e4d_convert.h"
|
||||
#include "model/eu07m/eu07m_convert.h"
|
||||
|
||||
#include "model/e4d/e4d_build.h"
|
||||
#include "model/e4d/e4d_dump.h"
|
||||
#include "model/e4d/e4d_io.h"
|
||||
#include "model/eu07m/eu07m_build.h"
|
||||
#include "model/eu07m/eu07m_dump.h"
|
||||
#include "model/eu07m/eu07m_io.h"
|
||||
#include "model/Model3d.h"
|
||||
#include "rendering/renderer.h"
|
||||
#include "utilities/Globals.h"
|
||||
@@ -27,11 +27,11 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include <iostream>
|
||||
#include <tuple>
|
||||
|
||||
namespace e4d {
|
||||
namespace eu07m {
|
||||
|
||||
namespace {
|
||||
|
||||
// the E3D kinds of geometry are the primitive types of OpenGL, which the topologies of E4D take over
|
||||
// the E3D kinds of geometry are the primitive types of OpenGL, which the topologies of EU07M take over
|
||||
constexpr int gl_primitive_last{6};
|
||||
|
||||
std::uint32_t pack_colour(glm::vec3 const &Colour) {
|
||||
@@ -290,8 +290,8 @@ 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) == ".e4d")
|
||||
Source.LoadFromE4D(Input, Dynamic);
|
||||
else if (extension_of(Input) == ".eu07m")
|
||||
Source.LoadFromEU07M(Input, Dynamic);
|
||||
else
|
||||
Source.LoadFromTextFile(Input, Dynamic);
|
||||
if (Milliseconds != nullptr)
|
||||
@@ -443,7 +443,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: -e4d diff <model.e3d|model.t3d> <model.e4d> [dynamic 0|1]\n";
|
||||
std::cerr << "usage: -eu07m diff <model.e3d|model.t3d> <model.eu07m> [dynamic 0|1]\n";
|
||||
return 2;
|
||||
}
|
||||
start_tools(Argc, Argv);
|
||||
@@ -461,13 +461,13 @@ int command_diff(int const Argc, char *Argv[]) {
|
||||
std::cout << std::format("{}: {} submodels, {} vertices, {} differences; transforms within {:.2g}, normals within {:.3f} deg ({} past 0.5 deg), tangents within {:.3f} deg\n", Argv[4],
|
||||
diff.submodels, diff.vertices, diff.differences.size(), diff.matrix, diff.normal, diff.bent, diff.tangent);
|
||||
// with the files in the system's cache or not, as they came: a run right after another one of the same files finds them there
|
||||
std::cout << std::format("load: source {:.2f} ms, e4d {:.2f} ms\n", sourcetime, convertedtime);
|
||||
std::cout << std::format("load: source {:.2f} ms, eu07m {:.2f} ms\n", sourcetime, convertedtime);
|
||||
return diff.differences.empty() ? 0 : 1;
|
||||
}
|
||||
|
||||
int command_convert(int const Argc, char *Argv[]) {
|
||||
if (Argc < 5) {
|
||||
std::cerr << "usage: -e4d convert <model.e3d|model.t3d> <model.e4d> [dynamic 0|1] [convertmodels flags]\n";
|
||||
std::cerr << "usage: -eu07m convert <model.e3d|model.t3d> <model.eu07m> [dynamic 0|1] [convertmodels flags]\n";
|
||||
return 2;
|
||||
}
|
||||
std::string const input{Argv[3]};
|
||||
@@ -483,7 +483,7 @@ int command_convert(int const Argc, char *Argv[]) {
|
||||
std::cerr << std::format("{}: {}\n", input, fault);
|
||||
auto const file{read_whole_file(input)};
|
||||
converted.source_hash = hash_bytes(std::as_bytes(std::span{file.data.get(), file.size}));
|
||||
converted.edit.push_back({converted.intern(input), converted.intern("eu07 -e4d convert"), {}});
|
||||
converted.edit.push_back({converted.intern(input), converted.intern("eu07 -eu07m convert"), {}});
|
||||
if (auto const problems{validate(converted)}; false == problems.empty()) {
|
||||
for (auto const &problem : problems)
|
||||
std::cerr << std::format("the converted model is invalid: {}\n", problem);
|
||||
@@ -502,7 +502,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: -e4d {} <model.e4d>\n", Dump ? "dump" : "validate");
|
||||
std::cerr << std::format("usage: -eu07m {} <model.eu07m>\n", Dump ? "dump" : "validate");
|
||||
return 2;
|
||||
}
|
||||
auto const file{read_whole_file(Argv[3])};
|
||||
@@ -539,8 +539,8 @@ int run_command_line(int const Argc, char *Argv[]) {
|
||||
return command_read(Argc, Argv, false);
|
||||
if (command == "diff")
|
||||
return command_diff(Argc, Argv);
|
||||
std::cerr << "usage: -e4d convert|dump|validate|diff ...\n";
|
||||
std::cerr << "usage: -eu07m convert|dump|validate|diff ...\n";
|
||||
return 2;
|
||||
}
|
||||
|
||||
} // namespace e4d
|
||||
} // namespace eu07m
|
||||
@@ -9,23 +9,23 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#pragma once
|
||||
|
||||
// the conversion of a model loaded from E3D or T3D into E4D, and the -e4d commands of the program
|
||||
// the conversion of a model loaded from E3D or T3D into EU07M, and the -eu07m commands of the program
|
||||
|
||||
#include "model/e4d/e4d_model.h"
|
||||
#include "model/eu07m/eu07m_model.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class TModel3d;
|
||||
|
||||
namespace e4d {
|
||||
namespace eu07m {
|
||||
|
||||
// the E4D form of the loaded model, its geometry taken from the renderer's banks (as SaveToBinFile does). the name index
|
||||
// the EU07M form of the loaded model, its geometry taken from the renderer's banks (as SaveToBinFile does). the name index
|
||||
// and the bounds are filled in; the source hash is left to the caller. the faults of the source found on the way, which
|
||||
// leave the result invalid, are added to Faults, each naming its submodel
|
||||
model convert(TModel3d &Source, std::vector<std::string> &Faults);
|
||||
|
||||
// the -e4d commands: convert, dump, validate. returns the exit code of the program
|
||||
// the -eu07m commands: convert, dump, validate. returns the exit code of the program
|
||||
int run_command_line(int Argc, char *Argv[]);
|
||||
|
||||
} // namespace e4d
|
||||
} // namespace eu07m
|
||||
@@ -9,11 +9,11 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "model/e4d/e4d_dump.h"
|
||||
#include "model/eu07m/eu07m_dump.h"
|
||||
|
||||
#include <format>
|
||||
|
||||
namespace e4d {
|
||||
namespace eu07m {
|
||||
|
||||
std::string fourcc_name(std::uint32_t const Id) {
|
||||
std::string text(4, ' ');
|
||||
@@ -113,4 +113,4 @@ std::string dump(model const &Model) {
|
||||
return output;
|
||||
}
|
||||
|
||||
} // namespace e4d
|
||||
} // namespace eu07m
|
||||
@@ -9,16 +9,16 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#pragma once
|
||||
|
||||
// the content of an E4D model as text, for people and for comparing two files
|
||||
// the content of an EU07M model as text, for people and for comparing two files
|
||||
|
||||
#include "model/e4d/e4d_model.h"
|
||||
#include "model/eu07m/eu07m_model.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace e4d {
|
||||
namespace eu07m {
|
||||
|
||||
std::string dump(model const &Model);
|
||||
|
||||
std::string fourcc_name(std::uint32_t Id);
|
||||
|
||||
} // namespace e4d
|
||||
} // namespace eu07m
|
||||
@@ -9,7 +9,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#pragma once
|
||||
|
||||
// the records of the E4D model format, as they lie in the file. docs/e4d-format.md describes them; the sizes and offsets
|
||||
// the records of the EU07M model format, as they lie in the file. docs/eu07m-format.md describes them; the sizes and offsets
|
||||
// below are the format, and the static_asserts keep the two the same
|
||||
|
||||
#include <array>
|
||||
@@ -18,9 +18,9 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include <cstdint>
|
||||
#include <string_view>
|
||||
|
||||
namespace e4d {
|
||||
namespace eu07m {
|
||||
|
||||
static_assert(std::endian::native == std::endian::little, "the E4D records are read and uploaded to the gpu as they lie in the file, little-endian");
|
||||
static_assert(std::endian::native == std::endian::little, "the EU07M records are read and uploaded to the gpu as they lie in the file, little-endian");
|
||||
|
||||
constexpr std::uint32_t fourcc(std::string_view const Code) {
|
||||
return static_cast<std::uint32_t>(static_cast<unsigned char>(Code[0])) | (static_cast<std::uint32_t>(static_cast<unsigned char>(Code[1])) << 8) |
|
||||
@@ -82,7 +82,7 @@ constexpr std::uint32_t legacy_material{fourcc("LMAT")};
|
||||
} // namespace component
|
||||
|
||||
struct file_header {
|
||||
std::array<char, 4> magic{'E', '4', 'D', '\0'};
|
||||
std::array<char, 4> magic{'E', 'U', '7', 'M'}; // the name of the format, EU07M, in four bytes
|
||||
std::uint16_t major{version_major};
|
||||
std::uint16_t minor{version_minor};
|
||||
std::uint32_t flags{0};
|
||||
@@ -575,4 +575,4 @@ static_assert(sizeof(legacy_material) == 4);
|
||||
|
||||
} // namespace payload
|
||||
|
||||
} // namespace e4d
|
||||
} // namespace eu07m
|
||||
@@ -9,8 +9,8 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "model/e4d/e4d_io.h"
|
||||
#include "model/e4d/e4d_dump.h"
|
||||
#include "model/eu07m/eu07m_io.h"
|
||||
#include "model/eu07m/eu07m_dump.h"
|
||||
|
||||
#include "meshoptimizer.h"
|
||||
#include "zstd.h"
|
||||
@@ -22,7 +22,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include <type_traits>
|
||||
#include <span>
|
||||
|
||||
namespace e4d {
|
||||
namespace eu07m {
|
||||
|
||||
std::uint32_t model::intern(std::string_view const Text) {
|
||||
if (m_stringids.size() != strings.size()) {
|
||||
@@ -370,7 +370,7 @@ bool file_reader::read_header(file_header &Header) {
|
||||
return fail("the file is shorter than the header");
|
||||
std::memcpy(&Header, m_file.data(), sizeof(file_header));
|
||||
if (Header.magic != file_header{}.magic)
|
||||
return fail("the file isn't an E4D model");
|
||||
return fail("the file isn't an EU07M model");
|
||||
if (Header.major != version_major)
|
||||
return fail(std::format("the model has version {}.{}, this program reads version {}", Header.major, Header.minor, version_major));
|
||||
if (Header.file_size > m_file.size())
|
||||
@@ -1126,4 +1126,4 @@ std::vector<std::string> validate(model const &Model, std::size_t const Limit) {
|
||||
return validator{Model, Limit}.run();
|
||||
}
|
||||
|
||||
} // namespace e4d
|
||||
} // namespace eu07m
|
||||
@@ -9,14 +9,14 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#pragma once
|
||||
|
||||
// writing, reading and checking of E4D files
|
||||
// writing, reading and checking of EU07M files
|
||||
|
||||
#include "model/e4d/e4d_model.h"
|
||||
#include "model/eu07m/eu07m_model.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace e4d {
|
||||
namespace eu07m {
|
||||
|
||||
struct write_options {
|
||||
bool compress{true}; // zstd for the sections where it saves at least an eighth
|
||||
@@ -46,4 +46,4 @@ read_result read(std::span<std::byte const> File, model &Model, read_options con
|
||||
// the faults of the model, each a line of text; empty when it can be used. stops after Limit faults
|
||||
std::vector<std::string> validate(model const &Model, std::size_t Limit = 16);
|
||||
|
||||
} // namespace e4d
|
||||
} // namespace eu07m
|
||||
@@ -11,8 +11,8 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#include "model/Model3d.h"
|
||||
|
||||
#include "model/e4d/e4d_build.h"
|
||||
#include "model/e4d/e4d_io.h"
|
||||
#include "model/eu07m/eu07m_build.h"
|
||||
#include "model/eu07m/eu07m_io.h"
|
||||
#include "rendering/renderer.h"
|
||||
#include "utilities/Logs.h"
|
||||
#include "utilities/wholefile.h"
|
||||
@@ -27,49 +27,49 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include <span>
|
||||
#include <thread>
|
||||
|
||||
// the loading of an E4D model into the tree of submodels the rest of the game works with: each node becomes a submodel, with
|
||||
// the loading of an EU07M model into the tree of submodels the rest of the game works with: each node becomes a submodel, with
|
||||
// what E3D keeps in the submodel taken from the node, its material, its primitive and its components. the result is what
|
||||
// TModel3d::LoadFromBinFile() makes of the E3D the model was converted from
|
||||
|
||||
namespace {
|
||||
|
||||
// the vertex streams of the file are the compact layout of the renderer, byte for byte
|
||||
static_assert(sizeof(e4d::position) == sizeof(glm::vec3));
|
||||
static_assert(sizeof(e4d::attributes) == sizeof(gfx::compact_attributes));
|
||||
static_assert(offsetof(e4d::attributes, qtangent) == offsetof(gfx::compact_attributes, qtangent));
|
||||
static_assert(offsetof(e4d::attributes, uv) == offsetof(gfx::compact_attributes, texture));
|
||||
static_assert(sizeof(eu07m::position) == sizeof(glm::vec3));
|
||||
static_assert(sizeof(eu07m::attributes) == sizeof(gfx::compact_attributes));
|
||||
static_assert(offsetof(eu07m::attributes, qtangent) == offsetof(gfx::compact_attributes, qtangent));
|
||||
static_assert(offsetof(eu07m::attributes, uv) == offsetof(gfx::compact_attributes, texture));
|
||||
|
||||
// what E3D keeps in the submodel and E4D in the components of the node
|
||||
// what E3D keeps in the submodel and EU07M in the components of the node
|
||||
struct legacy_parts {
|
||||
std::optional<e4d::payload::light> light;
|
||||
std::uint32_t material{e4d::no_index}; // of a node without geometry
|
||||
std::optional<eu07m::payload::light> light;
|
||||
std::uint32_t material{eu07m::no_index}; // of a node without geometry
|
||||
TAnimType animation{TAnimType::at_None};
|
||||
bool text{false};
|
||||
std::span<std::byte const> stars; // the packed colours, one for each vertex of the mesh
|
||||
};
|
||||
|
||||
legacy_parts parts_of(e4d::model const &Model, e4d::node_record const &Node) {
|
||||
legacy_parts parts_of(eu07m::model const &Model, eu07m::node_record const &Node) {
|
||||
legacy_parts parts;
|
||||
for (auto idx = Node.component_first; idx < Node.component_first + Node.component_count; ++idx) {
|
||||
auto const type{Model.components[idx].type};
|
||||
auto const data{Model.component_payload(idx)};
|
||||
e4d::payload_reader reader{data};
|
||||
if (type == e4d::component::light) {
|
||||
if (e4d::payload::light light; reader.get(light))
|
||||
eu07m::payload_reader reader{data};
|
||||
if (type == eu07m::component::light) {
|
||||
if (eu07m::payload::light light; reader.get(light))
|
||||
parts.light = light;
|
||||
}
|
||||
else if (type == e4d::component::legacy_animation) {
|
||||
if (e4d::payload::legacy_animation animation; reader.get(animation))
|
||||
else if (type == eu07m::component::legacy_animation) {
|
||||
if (eu07m::payload::legacy_animation animation; reader.get(animation))
|
||||
parts.animation = static_cast<TAnimType>(animation.type);
|
||||
}
|
||||
else if (type == e4d::component::legacy_text)
|
||||
else if (type == eu07m::component::legacy_text)
|
||||
parts.text = true;
|
||||
else if (type == e4d::component::legacy_material) {
|
||||
if (e4d::payload::legacy_material material; reader.get(material))
|
||||
else if (type == eu07m::component::legacy_material) {
|
||||
if (eu07m::payload::legacy_material material; reader.get(material))
|
||||
parts.material = material.material;
|
||||
}
|
||||
else if (type == e4d::component::legacy_stars && data.size() >= sizeof(e4d::payload::legacy_stars))
|
||||
parts.stars = data.subspan(sizeof(e4d::payload::legacy_stars));
|
||||
else if (type == eu07m::component::legacy_stars && data.size() >= sizeof(eu07m::payload::legacy_stars))
|
||||
parts.stars = data.subspan(sizeof(eu07m::payload::legacy_stars));
|
||||
}
|
||||
return parts;
|
||||
}
|
||||
@@ -87,7 +87,7 @@ glm::vec4 to_vec4(std::array<float, 4> const &Value) {
|
||||
|
||||
// the vertices and the indices of a submodel, filled once the submodels are set up
|
||||
struct geometry_job {
|
||||
e4d::primitive_record const *primitive{nullptr};
|
||||
eu07m::primitive_record const *primitive{nullptr};
|
||||
std::span<std::byte const> stars;
|
||||
TSubModel *submodel{nullptr};
|
||||
};
|
||||
@@ -99,8 +99,8 @@ constexpr unsigned parallel_thread_limit{8};
|
||||
// fills the submodels from the nodes of the model
|
||||
class submodel_builder {
|
||||
public:
|
||||
submodel_builder(e4d::model const &Model, std::vector<std::string> &Textures, std::vector<std::string> &Names, std::vector<float4x4> &Matrices)
|
||||
: m_model(Model), m_textures(Textures), m_names(Names), m_matrices(Matrices), m_transforms(e4d::local_transforms(Model)) {
|
||||
submodel_builder(eu07m::model const &Model, std::vector<std::string> &Textures, std::vector<std::string> &Names, std::vector<float4x4> &Matrices)
|
||||
: m_model(Model), m_textures(Textures), m_names(Names), m_matrices(Matrices), m_transforms(eu07m::local_transforms(Model)) {
|
||||
// texture 0 is "none" in the submodels
|
||||
m_textures.emplace_back();
|
||||
}
|
||||
@@ -112,13 +112,13 @@ class submodel_builder {
|
||||
void links(std::uint32_t Index, TSubModel &Submodel) const;
|
||||
void transform(std::uint32_t Index, TSubModel &Submodel);
|
||||
void material(std::uint32_t Material, TSubModel &Submodel);
|
||||
static void light(e4d::payload::light const &Light, TSubModel &Submodel);
|
||||
void geometry(e4d::primitive_record const &Primitive, legacy_parts const &Parts, TSubModel &Submodel);
|
||||
static void light(eu07m::payload::light const &Light, TSubModel &Submodel);
|
||||
void geometry(eu07m::primitive_record const &Primitive, legacy_parts const &Parts, TSubModel &Submodel);
|
||||
void fill(geometry_job const &Job) const;
|
||||
void indices(e4d::primitive_record const &Primitive, TSubModel &Submodel) const;
|
||||
void indices(eu07m::primitive_record const &Primitive, TSubModel &Submodel) const;
|
||||
int texture(std::string_view Name);
|
||||
|
||||
e4d::model const &m_model;
|
||||
eu07m::model const &m_model;
|
||||
std::vector<std::string> &m_textures;
|
||||
std::vector<std::string> &m_names;
|
||||
std::vector<float4x4> &m_matrices;
|
||||
@@ -135,7 +135,7 @@ class submodel_builder {
|
||||
void submodel_builder::build(std::uint32_t const Index, TSubModel &Submodel) {
|
||||
auto const &node{m_model.nodes[Index]};
|
||||
links(Index, Submodel);
|
||||
if (node.name != e4d::no_index) {
|
||||
if (node.name != eu07m::no_index) {
|
||||
Submodel.iName = static_cast<int>(m_names.size());
|
||||
m_names.emplace_back(m_model.string(node.name));
|
||||
}
|
||||
@@ -172,7 +172,7 @@ void submodel_builder::links(std::uint32_t const Index, TSubModel &Submodel) con
|
||||
}
|
||||
|
||||
void submodel_builder::transform(std::uint32_t const Index, TSubModel &Submodel) {
|
||||
if ((m_model.nodes[Index].flags & e4d::node_flags::no_transform) != 0) {
|
||||
if ((m_model.nodes[Index].flags & eu07m::node_flags::no_transform) != 0) {
|
||||
Submodel.iMatrix = -1;
|
||||
return;
|
||||
}
|
||||
@@ -193,7 +193,7 @@ void submodel_builder::material(std::uint32_t const Material, TSubModel &Submode
|
||||
auto const &material{m_model.materials[Material]};
|
||||
if (material.replaceable != 0)
|
||||
Submodel.iTexture = material.replaceable;
|
||||
else if (material.name != e4d::no_index)
|
||||
else if (material.name != eu07m::no_index)
|
||||
Submodel.iTexture = texture(m_model.string(material.name));
|
||||
Submodel.fLight = material.selfillum;
|
||||
Submodel.f4Ambient = to_vec4(material.ambient);
|
||||
@@ -202,8 +202,8 @@ void submodel_builder::material(std::uint32_t const Material, TSubModel &Submode
|
||||
Submodel.f4Emision = to_vec4(material.emission);
|
||||
}
|
||||
|
||||
void submodel_builder::light(e4d::payload::light const &Light, TSubModel &Submodel) {
|
||||
namespace light_flags = e4d::payload::light_flags;
|
||||
void submodel_builder::light(eu07m::payload::light const &Light, TSubModel &Submodel) {
|
||||
namespace light_flags = eu07m::payload::light_flags;
|
||||
Submodel.f4Diffuse = to_vec4(Light.color);
|
||||
Submodel.fHotspotPower = Light.hotspot_power;
|
||||
Submodel.fLightRadius = Light.radius;
|
||||
@@ -221,10 +221,10 @@ void submodel_builder::light(e4d::payload::light const &Light, TSubModel &Submod
|
||||
}
|
||||
|
||||
// what the submodel knows of its geometry; the vertices and the indices come later, in fill_geometry()
|
||||
void submodel_builder::geometry(e4d::primitive_record const &Primitive, legacy_parts const &Parts, TSubModel &Submodel) {
|
||||
Submodel.eType = Parts.stars.empty() ? static_cast<int>(Primitive.flags & e4d::primitive_flags::topology_mask) : TP_STARS;
|
||||
void submodel_builder::geometry(eu07m::primitive_record const &Primitive, legacy_parts const &Parts, TSubModel &Submodel) {
|
||||
Submodel.eType = Parts.stars.empty() ? static_cast<int>(Primitive.flags & eu07m::primitive_flags::topology_mask) : TP_STARS;
|
||||
material(Primitive.material, Submodel);
|
||||
auto const indexed{(Primitive.flags & e4d::primitive_flags::indexed) != 0};
|
||||
auto const indexed{(Primitive.flags & eu07m::primitive_flags::indexed) != 0};
|
||||
Submodel.m_geometry.vertex_count = static_cast<int>(Primitive.vertex_count);
|
||||
Submodel.m_geometry.vertex_offset = m_vertexoffset;
|
||||
Submodel.m_geometry.index_count = indexed ? static_cast<int>(Primitive.index_count) : 0;
|
||||
@@ -264,7 +264,7 @@ void submodel_builder::fill(geometry_job const &Job) const {
|
||||
auto const source{std::size_t{primitive.base_vertex} + idx};
|
||||
auto const &position{m_model.positions[source]};
|
||||
auto const &attribute{m_model.vertex_attributes[source]};
|
||||
auto const frame{e4d::decode_qtangent(attribute.qtangent)};
|
||||
auto const frame{eu07m::decode_qtangent(attribute.qtangent)};
|
||||
gfx::basic_vertex vertex;
|
||||
vertex.position = {position[0], position[1], position[2]};
|
||||
vertex.normal = unpack_colour(Job.stars, idx);
|
||||
@@ -274,10 +274,10 @@ void submodel_builder::fill(geometry_job const &Job) const {
|
||||
}
|
||||
}
|
||||
|
||||
void submodel_builder::indices(e4d::primitive_record const &Primitive, TSubModel &Submodel) const {
|
||||
if ((Primitive.flags & e4d::primitive_flags::indexed) == 0)
|
||||
void submodel_builder::indices(eu07m::primitive_record const &Primitive, TSubModel &Submodel) const {
|
||||
if ((Primitive.flags & eu07m::primitive_flags::indexed) == 0)
|
||||
return;
|
||||
if ((Primitive.flags & e4d::primitive_flags::index32) != 0) {
|
||||
if ((Primitive.flags & eu07m::primitive_flags::index32) != 0) {
|
||||
auto const source{std::span{m_model.indices32}.subspan(Primitive.first_index, Primitive.index_count)};
|
||||
Submodel.Indices.assign(source.begin(), source.end());
|
||||
}
|
||||
@@ -316,17 +316,17 @@ void submodel_builder::fill_geometry() {
|
||||
|
||||
} // namespace
|
||||
|
||||
bool TModel3d::LoadFromE4D(std::string const &FileName, bool const dynamic) {
|
||||
WriteLog("Loading E4D model data from \"" + FileName + "\"...", logtype::model);
|
||||
bool TModel3d::LoadFromEU07M(std::string const &FileName, bool const dynamic) {
|
||||
WriteLog("Loading EU07M model data from \"" + FileName + "\"...", logtype::model);
|
||||
auto const file{read_whole_file(FileName)};
|
||||
if (file.data == nullptr) {
|
||||
ErrorLog("Bad model: can't read \"" + FileName + "\"", logtype::model);
|
||||
return false;
|
||||
}
|
||||
e4d::model model;
|
||||
eu07m::model model;
|
||||
// the game has no use for the sections it doesn't know
|
||||
if (auto const result{e4d::read(std::as_bytes(std::span{file.data.get(), file.size}), model, {false, false})}; false == result.ok) {
|
||||
ErrorLog("Bad model: \"" + FileName + "\" isn't a valid E4D file: " + result.error, logtype::model);
|
||||
if (auto const result{eu07m::read(std::as_bytes(std::span{file.data.get(), file.size}), model, {false, false})}; false == result.ok) {
|
||||
ErrorLog("Bad model: \"" + FileName + "\" isn't a valid EU07M file: " + result.error, logtype::model);
|
||||
return false;
|
||||
}
|
||||
if (model.nodes.empty()) {
|
||||
@@ -351,6 +351,6 @@ bool TModel3d::LoadFromE4D(std::string const &FileName, bool const dynamic) {
|
||||
m_indexcount += builder.index_count;
|
||||
// the tangents come with the vertices
|
||||
finish_binary(dynamic, true);
|
||||
WriteLog("Finished loading E4D model data from \"" + FileName + "\"", logtype::model);
|
||||
WriteLog("Finished loading EU07M model data from \"" + FileName + "\"", logtype::model);
|
||||
return true;
|
||||
}
|
||||
@@ -9,9 +9,9 @@ http://mozilla.org/MPL/2.0/.
|
||||
|
||||
#pragma once
|
||||
|
||||
// an E4D model in memory: the tables of the file, as the writer takes them and the reader gives them back
|
||||
// an EU07M model in memory: the tables of the file, as the writer takes them and the reader gives them back
|
||||
|
||||
#include "model/e4d/e4d_format.h"
|
||||
#include "model/eu07m/eu07m_format.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
@@ -22,7 +22,7 @@ http://mozilla.org/MPL/2.0/.
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace e4d {
|
||||
namespace eu07m {
|
||||
|
||||
// a section the reader didn't know, kept so the tools write it back unchanged
|
||||
struct unknown_section {
|
||||
@@ -139,4 +139,4 @@ std::uint64_t hash_bytes(std::span<std::byte const> Data, std::uint64_t Seed = 0
|
||||
// FNV-1a 64 of the name in ASCII lowercase, the key of the name index
|
||||
std::uint64_t hash_name(std::string_view Name);
|
||||
|
||||
} // namespace e4d
|
||||
} // namespace eu07m
|
||||
Reference in New Issue
Block a user