Skip to content

Commit e8eac13

Browse files
committed
#4109 Refactor LLGLTFLoader::populateModelFromMesh() #2
1 parent 3eab945 commit e8eac13

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

indra/newview/gltf/llgltfloader.cpp

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -434,25 +434,36 @@ bool LLGLTFLoader::populateModelFromMesh(LLModel* pModel, const LL::GLTF::Mesh&
434434
indices.push_back(prim.mIndexArray[i]);
435435
}
436436

437+
// Check for empty vertex array before processing
438+
if (vertices.empty())
439+
{
440+
LL_WARNS("GLTF_IMPORT") << "Empty vertex array for primitive" << LL_ENDL;
441+
continue; // Skip this primitive
442+
}
443+
437444
std::vector<LLVolumeFace::VertexData> faceVertices;
438-
glm::vec3 min = glm::vec3(0);
439-
glm::vec3 max = glm::vec3(0);
445+
glm::vec3 min = glm::vec3(FLT_MAX);
446+
glm::vec3 max = glm::vec3(-FLT_MAX);
440447

441448
for (U32 i = 0; i < vertices.size(); i++)
442449
{
443450
LLVolumeFace::VertexData vert;
444-
if (i == 0 || vertices[i].position.x > max.x)
445-
max.x = vertices[i].position.x;
446-
if (i == 0 || vertices[i].position.y > max.y)
447-
max.y = vertices[i].position.y;
448-
if (i == 0 || vertices[i].position.z > max.z)
449-
max.z = vertices[i].position.z;
450-
if (i == 0 || vertices[i].position.x < min.x)
451-
min.x = vertices[i].position.x;
452-
if (i == 0 || vertices[i].position.y < min.y)
453-
min.y = vertices[i].position.y;
454-
if (i == 0 || vertices[i].position.z < min.z)
455-
min.z = vertices[i].position.z;
451+
452+
// Update min/max bounds
453+
if (i == 0)
454+
{
455+
min = max = vertices[i].position;
456+
}
457+
else
458+
{
459+
min.x = std::min(min.x, vertices[i].position.x);
460+
min.y = std::min(min.y, vertices[i].position.y);
461+
min.z = std::min(min.z, vertices[i].position.z);
462+
max.x = std::max(max.x, vertices[i].position.x);
463+
max.y = std::max(max.y, vertices[i].position.y);
464+
max.z = std::max(max.z, vertices[i].position.z);
465+
}
466+
456467
LLVector4a position = LLVector4a(vertices[i].position.x, vertices[i].position.y, vertices[i].position.z);
457468
LLVector4a normal = LLVector4a(vertices[i].normal.x, vertices[i].normal.y, vertices[i].normal.z);
458469
vert.setPosition(position);
@@ -499,22 +510,22 @@ bool LLGLTFLoader::populateModelFromMesh(LLModel* pModel, const LL::GLTF::Mesh&
499510
std::vector<LLModel::JointWeight> wght;
500511
F32 total = 0.f;
501512

502-
for (U32 i = 0; i < llmin((U32)4, (U32)weight_list.size()); ++i)
513+
for (U32 j = 0; j < llmin((U32)4, (U32)weight_list.size()); ++j)
503514
{
504515
// take up to 4 most significant weights
505516
// Ported from the DAE loader - however, GLTF right now only supports up to four weights per vertex.
506-
wght.push_back(weight_list[i]);
507-
total += weight_list[i].mWeight;
517+
wght.push_back(weight_list[j]);
518+
total += weight_list[j].mWeight;
508519
}
509520

510521
if (total != 0.f)
511522
{
512523
F32 scale = 1.f / total;
513524
if (scale != 1.f)
514525
{ // normalize weights
515-
for (U32 i = 0; i < wght.size(); ++i)
526+
for (U32 j = 0; j < wght.size(); ++j)
516527
{
517-
wght[i].mWeight *= scale;
528+
wght[j].mWeight *= scale;
518529
}
519530
}
520531
}

0 commit comments

Comments
 (0)