Mesh Primitives and LOD

Hi there,

I’ve been exporting objects from Blender using Khronos’ gLTF add-on, and have run into bit of an issue; mesh objects with higher levels of geometry have been split into several primitives, and are parented to a Transform Node with the same name. This is causing issues when trying to setup LOD, as the primitives are seen as 4 unique meshes instead of one:

Is there an easy solution for this, like grouping them? I’ve only seen LOD methods under “mesh”. Thanks for your time!

I had/have this same exact issue with the Babylon Toolkit Unity Exporter.

I end up creating an extension to gltf called CVTOOLS_babylon_mesh that does not break the meshes down into separate primitive meshes but instead serializes a bit of extra metadata need to implement sub meshes and multi materials.

This allowed not only a single mesh for simplicity sake, but now can easily handle LOD … Since your using you originally authored meshes

That’s how I am dealing with GLTF Primitives … or better said… No GLTF Primitives but native Babylon meshes inside GLTF

1 Like

Also GLTF Skinning … Totally sucks balls.

I am currently working on another extension to implement native Babylon Skeletons in GLTF as well

3 Likes

Pinging @bghgary for the gltf issue

1 Like

Good to know I’m not the only one experiencing this. I might write a function that parents the transform node to simple BabylonJS mesh object, like a cube for example, and see if the children (primitives) inherit the LOD attributes. The only downside is that this feels like a sloppy approach. Transform Nodes should just have a LOD method for the sake of simplicity.

Gary is off for the week but we could chat next week to see if we can offer an option to automatically merge primitives into one single mesh.

That’d be great, thanks!

This is unfortunately not an easy fix as there are many edge cases that are supported by glTF. I’ve attempted to fix this twice and scrapped them both. Would it be workable if you merge the meshes yourself after loading the glTF?

How do I merge these grids myself? I have the same problem

Trying to merge them back together after the gltf Exporter separates them out to primitives is really tough… I tried… but I use the gltf as a the complete scene file.

EDIT
Merging back together will only really work if each gltf is one model only

My best solution involves an extension to handle keeping mesh hierarchy and serializing a bit of extra metadata to setup the proper sub meshes and multi materials… Works beautifully using the Babylon Scene Manager to parse the gltf… which is automatic

I also support left handed gltf as well… I hate right handed coordinates

1 Like

@bghgary Merging the primitives post gLTF load has been my solution too. @ranwei-001 I use a forEach loop for identifying the Transform Nodes which contain all the primitives as children, then I have a function to merge them.

1 Like

How should be gotten specifically, I know nothing about this respect, can tell in detail

https://www.babylonjs-playground.com/#4AJ16M#180
this my PG

@ranwei-001 I modified the ‘ImportMeshAsync’ promise in your PG example to push the meshes into an array (the index starts at 1 instead of 0 so the ‘root’ is ignored), then used the new array with Babylon’s MergeMesh method. Hope this helps!

for (let index = 0; index < JsonObject.length; index++) {
    BABYLON.SceneLoader.ImportMeshAsync(
        null,
        JsonObject[index].url,
        JsonObject[index].filename, 
        scene)
    .then(
        function (result){
            var jsonMeshArray = [];
             for (i = 1; i <= result.meshes.length; i++) {
                 jsonMeshArray.push(result.meshes[i]);
             }
             var newMesh = BABYLON.Mesh.MergeMeshes(jsonMeshArray, true, true, undefined, false, true);
             alert('meshes merged');
    });
}

I‘ ’m trying



https://www.babylonjs-playground.com/#4AJ16M#182

  • I did an interview in the scene, and there still seems to be a problem
  • Some models are missing, some are missing materials

Try setting the index in the for loop to ‘index <= JsonObject.length’. I think I deleted the ‘=’ by accident. Should merge the last meshes.