Wondering if someone can help me determine why my GLTF files have a large number of vertices.
I have been using Aspose 3D for .NET to convert from a number of different file formats out to GLB. For this example, we are converting from OBJ → GLB.
We have also been testing the obj2gltf library.
When comparing the output of both libraries with the same input OBJ, the file size of the GLB when using the obj2gltf library is much smaller, when using gltf.report we can see why, everything is the same bar the number of vertices:
NAME | MODE | PRIMITIVES | GL_PRIMITIVES | VERTICES | INDICES | ATTRIBUTES | INSTANCES | SIZE |
---|---|---|---|---|---|---|---|---|
obj2gltf | TRIANGLES | 5 | 233,055 | 199,386 | u32 | POSITION:f32, TEXCOORD_0:f32 | 1 | 6.78 MB |
Aspose | TRIANGLES | 5 | 233,055 | 605,479 | u32 | POSITION:f32, TEXCOORD_0:f32 | 1 | 14.91 MB |
The MB difference of the Meshes above is the same difference of the overall GLB size, so we can confidently assume that the actual mesh is the culprit - not textures for example.
605479 / 199386 = 3~ , so potentially the vertices are duplicated?
FYI I’m running the below so duplicate control points shouldn’t be the case:
if (node.Entities[i] is Mesh mesh)
{
node.Entities[i] = mesh.Optimize(true);
}
After the OBJ has been processed and exported to GLB, I run it through the following to get some stats:
if (entity is Aspose.ThreeD.Entities.Geometry geom)
{
if (geom.GetElement(VertexElementType.Normal) is VertexElement norm)
{
NumberNormal += (norm.Indices.Count);
}
if (geom.GetElement(VertexElementType.UV) is VertexElement uv)
{
NumberUV += uv.Indices.Count;
}
if (geom.GetElement(VertexElementType.Material) is VertexElement mat)
{
NumberMaterial += mat.Indices.Count;
}
NumberVertices += geom.ControlPoints.Count;
}
The Aspose GLB export returns:
Normal.Indicies.Count: 0
UV.Indicies.Count: 0
Materials.Indicies.Count: 3
Number of Control points: 605479
obj2gltf stats:
Normal.Indicies.Count: 0
UV.Indicies.Count: 0
Materials.Indicies.Count: 3
Number of Control points: 199386
The original OBJ stats:
Normal.Indicies.Count: 0
UV.Indicies.Count: 699165
Materials.Indicies.Count: 233055
Number of Control points: 115771
If I then run mesh.Optimise(true)
on the GLB which has been exported, I get the below:
Normal.Indicies.Count: 0
UV.Indicies.Count: 699165
Materials.Indicies.Count: 3
Number of Control points: 150283
So it seems like the Aspose may be duplicating control points when exporting to GLB, which would require a second pass of the file after exporting, which may still not work as we would have to save the scene back to another GLTF which could cause the same issues - or am I missing something?
Or can the vertices be shared between different vertex types instead of duplicating?
Any help is appreciated - the smaller we can get our GLB files the better, as they can get extremely large and they are to be streamed in the browser.
I will send the following via large file transfer to the support email:
- GLB produced by Aspose from input OBJ
- GLB produced by obj2gltf from input OBJ
- The raw OBJ
Side note - is there a built in method within Aspose which is similar to this weld method, which can merge and index vertices to share data more efficiently?
Thanks for your help,
Tom