Skip to content

Commit

Permalink
Merge pull request #665 from ousttrue/fix/skip_empty_submesh
Browse files Browse the repository at this point in the history
skip empty submesh
  • Loading branch information
hiroj authored Jan 14, 2021
2 parents 3415fe7 + cc459c0 commit 17e5e31
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions Assets/UniGLTF/Runtime/UniGLTF/IO/MeshExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,36 @@ static glTFMesh ExportPrimitives(glTF gltf, int bufferIndex,
}

var gltfMesh = new glTFMesh(mesh.name);
var indices = new List<uint>();
for (int j = 0; j < mesh.subMeshCount; ++j)
{
var indices = TriangleUtil.FlipTriangle(mesh.GetIndices(j)).Select(y => (uint)y).ToArray();
var indicesAccessorIndex = gltf.ExtendBufferAndGetAccessorIndex(bufferIndex, indices, glBufferTarget.ELEMENT_ARRAY_BUFFER);
indices.Clear();

var triangles = mesh.GetIndices(j);
if (triangles.Length == 0)
{
// https://github.com/vrm-c/UniVRM/issues/664
continue;
}

for (int i = 0; i < triangles.Length; i += 3)
{
var i0 = triangles[i];
var i1 = triangles[i + 1];
var i2 = triangles[i + 2];

// flip triangle
indices.Add((uint)i2);
indices.Add((uint)i1);
indices.Add((uint)i0);
}

var indicesAccessorIndex = gltf.ExtendBufferAndGetAccessorIndex(bufferIndex, indices.ToArray(), glBufferTarget.ELEMENT_ARRAY_BUFFER);
if (indicesAccessorIndex < 0)
{
// https://github.com/vrm-c/UniVRM/issues/664
throw new Exception();
}

if (j >= materials.Length)
{
Expand Down

0 comments on commit 17e5e31

Please sign in to comment.