How to exclude multiple meshes from export?

In the babylonjs documentation, I found an example that exclude one mesh in the export. What would be the best way to select multiple meshes to be excluded in the options array?

// Initializer code...
let skybox = scene.createDefaultSkybox(hdrTexture, true, 100, 0.3);
// scene setup code...

let options = {
  shouldExportNode: function (node) {
    return node !== skybox;
  },
};

BABYLON.GLTF2Export.GLBAsync(scene, "fileName", options).then((glb) => {
  glb.downloadFiles();
});

One way that’s pretty straightforward IMO is to create an array of excluded nodes and then just use indexOf() to test if the node should be exported like below. :slight_smile:

let excludedNodes = [];
let options = {
    shouldExportNode: function (node) {
        return excludedNodes.indexOf(node) === -1;
    }
};

Perfect! And one more thing. Is there a way to exclude the parents without excluding the children?. If I unparent the child positions change

I’m not sure about that part, but if you use child.setParent(null) then the child will retain its position…

Just one more question. When I export the scene excluding all meshes, there is a validation problem in my scenario and I see that still there are some cameras in it

{
“uri”: “fileName.glb”,
“mimeType”: “model/gltf-binary”,
“validatorVersion”: “2.0.0-dev.3.5”,
“validatedAt”: “2022-03-22T03:26:31.129Z”,
“issues”: {
“numErrors”: 2,
“numWarnings”: 0,
“numInfos”: 2,
“numHints”: 0,
“messages”: [
{
“code”: “TYPE_MISMATCH”,
“message”: “Type mismatch. Property value null is not a ‘number’.”,
“severity”: 0,
“pointer”: “/cameras/1/perspective/yfov”
},
{
“code”: “UNDEFINED_PROPERTY”,
“message”: “Property ‘yfov’ must be defined.”,
“severity”: 0,
“pointer”: “/cameras/1/perspective”
},
{
“code”: “UNUSED_OBJECT”,
“message”: “This object may be unused.”,
“severity”: 2,
“pointer”: “/cameras/0”
},
{
“code”: “UNUSED_OBJECT”,
“message”: “This object may be unused.”,
“severity”: 2,
“pointer”: “/cameras/1”
}
],
“truncated”: false
}
}

Hmm I’ve never tried exporting to gltf with everything excluded, IDK what’s up with the exported camera and errors, but @bghgary is the gltf guru to ask I think. :slight_smile:

1 Like

Pardon, my crudeness, but is the scene going to be used for anything post export? If not, maybe just dispose of anything you do not want on the file.

In this case I excluded everything from export but I cant dispose it because I need to post process it. I also excluded camera and light nodes.Is there any other thing to exclude beside nodes?

Show me how to repro (e.g., create a playground) and I can help you.

Here it is : Babylon.js Playground

In the sandbox of the exported file, 2 errors are being displayed.

1 Like

There are multiple issues with this:

  1. Camera export only partially respects the shouldExportNode option.
  2. Camera export was using incorrect values to construct the fov value.
  3. There is no way to specify what you want to export from the inspector glTF export.

This PR addresses all of them:
glTF exporter updates by bghgary · Pull Request #12253 · BabylonJS/Babylon.js (github.com)