Closed tomspilman closed 4 years ago
@vpenades - I hack things by doing this:
... but likely that is a bad solution.
The issue is each call i make to add a mesh to a node looks like this:
node.WithMesh(root.CreateMesh(mesh));
... each of these calls can end up creating duplicate materials in the ModelRoot
as it never checks if the material already exists.
The Schema2 namespace creation methods are quite explicit and low level, and it is expected that you build some minimum infrastructure over them.
That's why there's also a root.CreateMeshes(...);
CreateMeshes is able to find all the shared materials in the input meshes and coalesce them.
Anyway, I would suggest you to use Toolkit's SceneBuilder to create your meshes; it is easier to follow than the glTF DOM, and has additional optimizations when converted to schema2 glTF DOM.
That's why there's also a root.CreateMeshes(...); CreateMeshes is able to find all the shared materials in the input meshes and coalesce them.
I see... so my mistake is not building all the meshes in one call... then after that doing the node association.
Anyway, I would suggest you to use Toolkit's SceneBuilder to create your meshes;
I didn't realize i wasn't using the recommended path. There seems to be several ways to do things and not every clear guidance as to which way is best.
Thanks for clearing this up!
On creating the meshes we're careful to share
MaterialBuilder
s when creating meshes. We basically have one material per-texture. Later when we export we find duplicate materials with the same name...Is there a way to keep it from doing this?