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.
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
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
Is it possible to export the mesh sphere with the attached label as one?
Please see example playground
Thanks,
Michael
The GUI label wonât be exported to GLB as thatâs not supported by the format
Do I have to create 3D Text and render it first?
Can you add a 3D Text to the playground example on the sphere and export them together?
thanks,
Michael