BABYLON.GLTF2Export related aspects

Hi there, good people of the forum:

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):

  1. to export only specific meshes in the scene;
  2. 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

Thanks for your time.

Hello!

  1. Yep, there are ways of excluding certain elements from export, see: glTF Exporter | Babylon.js Documentation
  2. 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.

Hi there, @carolhmj:

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?

Best regards.

Ooooh, I see! This behavior is controlled by the browser/file system, so nothing we can do there unfortunately :frowning:

1 Like

Hi there, @carolhmj:

Yes, certainly I see that is a security aspect not allowing to overwrite nothing in download folder.

In that case, we’ll need to live with the “name of file plus a random number suffix” approach.

Thanks for your time.

Hi there, @carolhmj:

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?

Thanks for your time.

You mean, if it’s possible to upload GLTF/GLB to a file server? That’s possible yes, we use Github a lot for it here: Using External Assets In the Playground | Babylon.js Documentation (babylonjs.com)

1 Like

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:

JavaScript
BABYLON.GLTF2Export.GLTFAsync(scene, "myScene.gltf", {
  existingFile: true
}).then((gltf) => {
  gltf.downloadFiles();
});

This code will overwrite the “myScene.gltf” file if it already exists.

This looks like a none accurate GPT answer…

There should not be extension in the file prefix and option names are not correct.

function shouldExportMesh(mesh) {
  // Check if the mesh should be exported
  return mesh.name === "myMeshName";
}

BABYLON.GLTF2Export.GLTFAsync(scene, "myScene", {
  shouldExportNode: shouldExportMesh
}).then((gltf) => {
  gltf.downloadFiles();
});

The second point is a complete hallucination.

@johnsmiht4 please, do not do this without extra checks.