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)

Hi there, @bghgary:

Related to this same subject, I need to exclude from my exportation all the disabled nodes (and children) in the scene (user enables ones and disables others).

The work shouldExportNode mechanism works flawless when I specify the nodes (i.e. _axesRoot and _floor in the following code snippet):

...
var options = {
  shouldExportNode: function (node) {
     return (node != _axesRoot && node != _floor);
  }
};
...

But when I try to use isEnabled flag instead, in order to have it done in an automated way, I get and exception, raised by the node.isEnabled() call:

...
var options = {
  shouldExportNode: function (node) {
     return (node.isEnabled());
  }
};
...

Any advice on this?

Thanks for your time.

Hmm, that doesn’t seem right. What is the exception? Do you have a repro I can try?

Hi, @bghgary, and thank you for your immediate response.

My scene is not a very simple one, and the models have NDA related to them. So a PG should need serious work to be generated. Anyway, I thought the node.isEnabled was going to work. It should, isn’t It?

Maybe, having nodes with the same name, but of course in different models of the scene, is being a problem for the exporter?

Thanks a lot for your time.

Hi there, @bghgary:

I’ve realized that the problem doesn’t have to do with the disabled nodes. The GLB is indeed exported without them, and I’m able to visualize it with BJS Sandbox (by the way with a lot of severity 3 errors).

The case is that I’m using Google’s model-viewer to show that exported GLB in AR, and is that web component which is raising the exception: “TypeError: can’t access property “name”, s is undefined”, related with this line of code:

// reserve node's name before its dependencies, so the root has the intended name.
const nodeName = nodeDef.name ? parser.createUniqueName( nodeDef.name ) : '';

It’s strange, but model-viewer shows flawless my original 3d models (coming from 3d authorship), but can’t show the modified-and-exported ones (coming from BJS code).

Maybe the animation-groups, that are still in the scene, referring to not exported nodes (as they’re disabled) have something to do with it? How can I filter the animation-groups in shouldExportNode, in order to not being exported?

Thanks for your time.

It looks like there are two threads with the same issue. Let’s use the other thread.