For a project we’re developing at the moment, involving the BABYLON.GLTF2Export functionality, we’re wondering if it is available out-of-the-box (can’t find a lot of this exporter in docs or the web):
to export only specific meshes in the scene;
to overwrite/rewrite the exported file, in order to keep the same name while avoiding the population of the “downloads” folder with successive annoying (suffixed with a number) files
I’m a bit confused on what “same name” means here. Do you mean changing the file name? That’s possible too. Or do you mean changing something inside the generated file? Since the GLTF format is a defined standard glTF™ 2.0 Specification (khronos.org) that’s also possible too.
First, thank you for your immediate response. I’ll take a closer look to the docs.
About the same name, I’d like to overwrite the same file (same name) again and again, that is, calling BABYLON.GLTF2Export.GLBAsync(scene, assetName) white the same assetName, but not having then a series of files: assetName(1).glb, assetName(2).glb, …
Is there any way to “overwrite flag” that let me do that or I need to delete first the previous assetName.glb file?
Another question I’d like to ask you, related with this same subject, once it’s clear that working with local folders is avoided in order to not mess with security issues: How can I manage to upload the gltf/glb data (file I mean) to a public web server location? Is it in fact even possible?
Yes, it is possible to export only specific meshes in the scene and overwrite/rewrite the exported file using the BABYLON.GLTF2Export functionality. Here’s how to do it:
Exporting only specific meshes
To export only specific meshes in the scene, you can create a filter function that checks if the mesh should be exported. The filter function takes a mesh as an argument and returns a boolean value indicating whether to include the mesh in the export. You can then pass this filter function to the GLTF2Export options object. For example:
JavaScript
function shouldExportMesh(mesh) {
// Check if the mesh should be exported
return mesh.name === "myMeshName";
}
BABYLON.GLTF2Export.GLTFAsync(scene, "myScene.gltf", {
onlyExportMeshes: shouldExportMesh
}).then((gltf) => {
gltf.downloadFiles();
});
This code will only export the mesh named “myMeshName” to the “myScene.gltf” file.
Overwriting/rewriting the exported file
To overwrite/rewrite the exported file, you can use the existingFile option in the GLTF2Export options object. This option takes a boolean value indicating whether to overwrite an existing file. For example: