Export to glb and exclude array of Meshes

Hi everyone,

Im trying to
Export scene to glb and exclude array of Meshes (not just one mesh)

I tried to create Node and setParent of array of meshes to new Node but it still does not switch the array of meshes from node0 to the new node.

Any help will be much appreciated

Thansk,
MIchael

Hello and welcome to the Babylon community!

The GLTF/GLB export functions GLTF2Export | Babylon.js Documentation (babylonjs.com) accept a options parameter, one of which is a function that filters which nodes should and shouldn’t be exported: IExportOptions | Babylon.js Documentation (babylonjs.com)

let options = {
    
    
    
    shouldExportNode: function (node) {
    
 



        return node == "node0";
       
    }

}

I have setparent to the array of meshes to node0 but return node == “node0”; doesnt seem to work
Thanks for your help!

You should check the type of the argument, it’s a Node, not a string.

I set the parent node named ‘meshGroup’ to array of meshes succesfully
const parentnode = new BABYLON.TransformNode(‘meshGroup’, scene);
workermeshes[i].setParent(parentnode);

and then checked for node ===parentnode as seen below:

let options = {

        shouldExportNode: function (node, parentnode ) {
            
               
            return  node ===parentnode ;
            }
        

   
    }

still doesnt work what am I missing? thanks

shouldExportNode doesn’t receive a parentNode parameter…

if you can share a playground ( Babylon.js Playground (babylonjs.com)) showing how you’re setting up these meshes and exporting them, it will be easier to help.

I created a sandbox environment to demonstrate how Im trying to export all meshes of the first object (the boombox)

var createScene = function () {
var scene = new BABYLON.Scene(engine);
var helper = scene.createDefaultVRExperience();

var baseUrl = "https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Models/master/2.0/";

Promise.all([
    BABYLON.SceneLoader.ImportMeshAsync(null, baseUrl + "BoomBox/glTF/", "BoomBox.gltf", scene).then(function (result) {
        result.meshes[0].position.x = 0.01;
    }),
    BABYLON.SceneLoader.ImportMeshAsync(null, baseUrl + "Avocado/glTF/", "Avocado.gltf", scene).then(function (result) {
        result.meshes[0].position.x = -0.01;
        result.meshes[0].position.y = -0.01;
        result.meshes[0].scaling.scaleInPlace(0.25);
    })
]).then(() => {
    scene.createDefaultCameraOrLight(true, true, true);
    scene.activeCamera.alpha += Math.PI;
});

//i WANT TO EXPORT ALL MESHES OF THE FIRST OBJECT ONLY

let options = {
shouldExportNode: function (node) {
return node === result.meshes;
},
};

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

return scene;

}

Please use the Playground, I linked it above. We won’t be able to help otherwise.

Here it is Thanks

You are doing node === result.meshes

At this point result is not available, it only exists within the scope of the callback function so it is undefined resulting in the error.

also you are comparing a node and an array which is not possible you need to check if the not is part of the array.

I would like the not to be an array of meshes (maybe with the same parent node or a tag) thanks

see this example: Exclude meshes from export | Babylon.js Playground (babylonjs.com)

Thank you for the example

How can I sort the meshes by wether emissive color is applied (true or false)

and export as two separate glbs?

You can do an if condition.

Is it possible to create two different glb exports? can you please show me thanks

Run the function twice :slight_smile:

1 Like