shouldExportNode issue with TransformNode

Hi Everyone

While exporting GLB from Babylon with specific type of Imported Scene, I am unable to export selective meshes which are child of TransformNode.

In the Above Scene, After loading the GLB into Scene, there are two meshes, Cube and Cylinder, where cylinder is child to a Node. While exporting Cube, It works fine. But export for Cylinder downloads a file, which I am unable to open in lot of tools, including Microsoft 3D viewer, Babylon Sandbox, and more.

When loading the exported GLB into Blender, I found that Mesh is there. But the exported file doesn’t load up in Babylon. I guess this has to do something being child of a Node.

Seems a bug, Until fixed, If we can find a workaround, would be great.

Thanks

ping @carolhmj and @bghgary

The thing is you are exporting an empty gltf here cause you prevent to export parent of the node you want.

This is still a valid gltf as you can see in the validator but I do not think there is a lot we can do ?

If you include the node of the parent node of the cylinder, then it will work.

https://playground.babylonjs.com/#2347FQ#2

Like @sebavan says, if you don’t export the parent, it won’t even traverse that branch to reach the cylinder.

@sebavan I agree that GLB is valid. It is not empty, If you see this in blender, it shows the Cylinder properly. Even If you look at file size, It consist of mesh data. I am proposing a solution further down. A GLB without empty node, loads on Babylonjs Sandbox, but this one gives error despite being valid.

@bghgary The solution that you provided seems to work fine. I also figured out since I posted the question. The challenge is, my GLB file has meshes in a deep nested hierarchy, To separate a mesh which is deep nested seems a big problem.

Proposed behavior :
We add a flag to export option, to include all parent nodes. It is better to keep the flag, as maintaining hierarchy for meshes is also important for lot of projects. How I implemented workaround is :

// Using the collectParent Method to get the list of all 
const collectParent = (mesh, array) => {
    if (mesh.parent != null) {
        if (!mesh.parent._isMesh) {
        }
        array.push(mesh.parent.uniqueId);
        collectParent(mesh.parent, array);
    }
}

// element below is mesh that I am trying to export.
const meshCollection = [element.uniqueId]
if (element.parent != null) {
    collectParent(element, meshCollection );
}

and then inside shouldExportNode, I am then checking if node.uniqueId exists in meshCollection array created above.

I’m okay with this proposal and would be okay to merge if you contribute a fix, but I don’t think this situation is very common. The shouldExportNode can be used to do whatever is necessary. I don’t consider your solution to be a workaround. It seems to be a valid solution to the problem.

1 Like