skip not used materials
This commit is contained in:
@@ -20,7 +20,15 @@ Mesh::Mesh(const MeshBuilderData& data) {
|
||||
"Materials count must be greater than 0");
|
||||
|
||||
for (u32 i = 0; i < data.materials.size(); i++) {
|
||||
materials.push_back(new MeshMaterial(data, i));
|
||||
auto* material = new MeshMaterial(data, i);
|
||||
|
||||
if (material->frames.size() == 0) {
|
||||
TYRA_WARN("Found empty material: ", material->name, ". Skipping...");
|
||||
delete material;
|
||||
continue;
|
||||
}
|
||||
|
||||
materials.push_back(material);
|
||||
}
|
||||
|
||||
isMother = true;
|
||||
|
||||
@@ -45,14 +45,22 @@ MeshMaterial::MeshMaterial(const MeshBuilderData& data,
|
||||
u32 lastVertexCount = 0;
|
||||
|
||||
for (u32 i = 0; i < material->frames.size(); i++) {
|
||||
frames.push_back(new MeshMaterialFrame(data, i, materialIndex));
|
||||
if (material->frames[i]->count > 0) {
|
||||
frames.push_back(new MeshMaterialFrame(data, i, materialIndex));
|
||||
|
||||
if (i > 0) {
|
||||
TYRA_ASSERT(frames[i]->count == lastVertexCount,
|
||||
"Vertex count must be the same for all frames");
|
||||
if (i > 0) {
|
||||
TYRA_ASSERT(frames[i]->count == lastVertexCount,
|
||||
"Vertex count must be the same for all frames");
|
||||
}
|
||||
|
||||
lastVertexCount = frames[i]->count;
|
||||
} else { // We will not use it, lets clean it up
|
||||
auto* frame = material->frames[i];
|
||||
if (frame->vertices != nullptr) delete[] frame->vertices;
|
||||
if (frame->normals != nullptr) delete[] frame->normals;
|
||||
if (frame->textureCoords != nullptr) delete[] frame->textureCoords;
|
||||
if (frame->colors != nullptr) delete[] frame->colors;
|
||||
}
|
||||
|
||||
lastVertexCount = frames[i]->count;
|
||||
}
|
||||
|
||||
isMother = true;
|
||||
|
||||
@@ -21,17 +21,20 @@ namespace Tyra {
|
||||
MeshMaterialFrame::MeshMaterialFrame(const MeshBuilderData& data,
|
||||
const u32& frameIndex,
|
||||
const u32& materialIndex) {
|
||||
auto* material = data.materials[materialIndex];
|
||||
|
||||
TYRA_ASSERT(materialIndex < data.materials.size(), "Provided index \"",
|
||||
materialIndex, "\" is out of range");
|
||||
|
||||
TYRA_ASSERT(frameIndex < data.materials[materialIndex]->frames.size(),
|
||||
"Provided index \"", frameIndex, "\" is out of range");
|
||||
TYRA_ASSERT(frameIndex < material->frames.size(), "Provided index \"",
|
||||
frameIndex, "\" is out of range");
|
||||
|
||||
id = rand() % 1000000;
|
||||
|
||||
auto* frame = data.materials[materialIndex]->frames[frameIndex];
|
||||
auto* frame = material->frames[frameIndex];
|
||||
|
||||
TYRA_ASSERT(frame->count > 0, "Vertex count must be greater than 0");
|
||||
TYRA_ASSERT(frame->count > 0, "Vertex count must be greater than 0",
|
||||
"Material name: ", material->name);
|
||||
TYRA_ASSERT(frame->vertices != nullptr, "Vertex array can't be null");
|
||||
TYRA_ASSERT(!data.normalsEnabled || frame->normals != nullptr,
|
||||
"Normal array can't be null");
|
||||
|
||||
Reference in New Issue
Block a user