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; sizeof(Header) == 12;
struct Body { struct Body {
uint16 model_count
uint16 material_count uint16 material_count
Model models[]; uint16 model_count
Material materials[]; Material materials[];
Model models[];
}; };
sizeof(Body) == 4; // + dynamic models array + dynamic materials array 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)) { if (!fs::exists(variantFile)) {
break; break;
} }
baseSound->variants.emplace_back(audio::load_sound(variantFile, keepPCM) baseSound->variants.emplace_back(audio::load_sound(variantFile, keepPCM));
);
} }
auto sound = baseSound.release(); auto sound = baseSound.release();
@ -191,8 +190,13 @@ assetload::postfunc assetload::sound(
}; };
} }
assetload::postfunc assetload:: assetload::postfunc assetload::model(
model(AssetsLoader* loader, const ResPaths* paths, const std::string& file, const std::string& name, const std::shared_ptr<AssetCfg>&) { 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 path = paths->find(file + ".obj");
auto text = files::read_string(path); auto text = files::read_string(path);
try { try {

View File

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