update VEC3 structure

This commit is contained in:
MihailRis 2024-10-24 20:15:59 +03:00
parent 39d9f269fa
commit 30725c80c7
4 changed files with 25 additions and 25 deletions

View File

@ -57,10 +57,10 @@ struct Header {
sizeof(Header) == 12;
struct Body {
uint16 model_count
uint16 material_count
Model models[];
uint16 model_count
Material materials[];
Model models[];
};
sizeof(Body) == 4; // + dynamic models array + dynamic materials array

Binary file not shown.

View File

@ -181,8 +181,7 @@ assetload::postfunc assetload::sound(
if (!fs::exists(variantFile)) {
break;
}
baseSound->variants.emplace_back(audio::load_sound(variantFile, keepPCM)
);
baseSound->variants.emplace_back(audio::load_sound(variantFile, keepPCM));
}
auto sound = baseSound.release();
@ -191,8 +190,13 @@ assetload::postfunc assetload::sound(
};
}
assetload::postfunc assetload::
model(AssetsLoader* loader, const ResPaths* paths, const std::string& file, const std::string& name, const std::shared_ptr<AssetCfg>&) {
assetload::postfunc assetload::model(
AssetsLoader* loader,
const ResPaths* paths,
const std::string& file,
const std::string& name,
const std::shared_ptr<AssetCfg>&
) {
auto path = paths->find(file + ".obj");
auto text = files::read_string(path);
try {

View File

@ -107,7 +107,9 @@ static model::Mesh build_mesh(
return model::Mesh {texture, std::move(vertices)};
}
static model::Mesh load_mesh(ByteReader& reader) {
static model::Mesh load_mesh(
ByteReader& reader, const std::vector<Material>& materials
) {
int triangleCount = reader.getInt32();
int materialId = reader.getInt16();
int flags = reader.getInt16();
@ -145,12 +147,13 @@ static model::Mesh load_mesh(ByteReader& reader) {
return build_mesh(
attributes,
indices,
// encode material index to UTF-8 because materials are not loaded yet
util::wstr2str_utf8(std::wstring({static_cast<wchar_t>(materialId)}))
materials.at(materialId).name
);
}
static Model load_model(ByteReader& reader) {
static Model load_model(
ByteReader& reader, const std::vector<Material>& materials
) {
int nameLength = reader.getInt16();
assert(nameLength >= 0);
float x = reader.getFloat32();
@ -161,7 +164,7 @@ static Model load_model(ByteReader& reader) {
std::vector<model::Mesh> meshes;
for (int i = 0; i < meshCount; i++) {
meshes.push_back(load_mesh(reader));
meshes.push_back(load_mesh(reader, materials));
}
util::Buffer<char> chars(nameLength);
reader.get(chars.data(), nameLength);
@ -194,27 +197,20 @@ File vec3::load(
assert(reserved == 0);
// Body
int modelCount = reader.getInt16();
int materialCount = reader.getInt16();
assert(modelCount >= 0);
int modelCount = reader.getInt16();
assert(materialCount >= 0);
assert(modelCount >= 0);
std::unordered_map<std::string, Model> models;
for (int i = 0; i < modelCount; i++) {
Model model = load_model(reader);
models[model.name] = std::move(model);
}
std::vector<Material> materials;
for (int i = 0; i < materialCount; i++) {
materials.push_back(load_material(reader));
}
// Resolve textures
for (auto& [_, model] : models) {
for (auto& mesh : model.model.meshes) {
int materialId = util::str2wstr_utf8(mesh.texture).at(0);
mesh.texture = materials.at(materialId).name;
}
std::unordered_map<std::string, Model> models;
for (int i = 0; i < modelCount; i++) {
Model model = load_model(reader, materials);
models[model.name] = std::move(model);
}
return File {std::move(models), std::move(materials)};
}