so with { binary: true } I am getting json instead of array buffer if passing object with visible = false. no matter if the result is empty, I should get array buffer. the issue of course disappears with { binary: true, onlyVisible: false }
That happens because of this line:
Meaning an empty scene graph (or a scene graph with no visible 3d objects) results in undefined/empty output buffers and thus the code flow never reaches the check for the binary flag.
AFAICS, this approach was implemented right from the beginning of glb support so maybe there was a special reasons for doing so, see 0fd4cf3571eb361934194c87df307410924c7648.
I guess @donmccurdy just forgot or neglected to implement this in else clause.
Hm, yeah a binary file with no binary buffers was a case I forgot here... the "if" block could be changed to...
if ( outputJSON.buffers && outputJSON.buffers.length > 0 || options.binary ) {
... but then I expect some of the GLB-related code would need to be fixed to work without any buffers.
I've fiddle around with the code and managed to get it work. However, even if it's now possible to export an empty scene graph, it seems the resulting glTF asset is not valid according to glTF 2.0 validation report. Importing scene.zip in https://gltf-viewer.donmccurdy.com/ reports the following error:
EMPTY_ENTITY Entity cannot be empty. /scenes/0/nodes
Maybe it's better to prevent GLTFExporter from exporting such setups?
EMPTY_ENTITY Entity cannot be empty. /scenes/0/nodes
We can fix that, it just means that we need to replace {asset: {...}, nodes: []} with {asset: {...}} in the output JSON — empty arrays aren't allowed.
But is exporting without any visible nodes basically the same as this?
exporter.parse( null, function ( result ) {
// ...
} );
I'm not sure we should go to the trouble of constructing an empty .glb file here, even though we could. Surely this is user error, and an exception should be thrown?
There _is_ a valid case where you might export a scene that just doesn't contain any meshes. Maybe it's only Light, Object3D, Camera, and Group objects. In that case the nodes list will have things in it, but the buffers will still be empty. I'm OK with fixing that case.
this is user error, and an exception should be thrown
well it is already thrown, when the user takes the result and tries to do ArrayBuffer things with it. maybe you could just return null instead of json as rn?
There _is_ a valid case where you might export a scene that just doesn't contain any meshes. Maybe it's only Light, Object3D, Camera, and Group objects. In that case the nodes list will have things in it, but the buffers will still be empty. I'm OK with fixing that case.
Or just materials for some sort of library?
Or just materials for some sort of library?
That would be fine, but GLTFExporter currently requires Object3D subclasses as input.
@donmccurdy and what happens if the mesh has no geometry 🤔 ah https://jsfiddle.net/v5dzf1np/ json again 😔
PRs are welcome for these edge cases if you feel they should be supported.
Most helpful comment
We can fix that, it just means that we need to replace
{asset: {...}, nodes: []}with{asset: {...}}in the output JSON — empty arrays aren't allowed.But is exporting without any visible nodes basically the same as this?
I'm not sure we should go to the trouble of constructing an empty
.glbfile here, even though we could. Surely this is user error, and an exception should be thrown?There _is_ a valid case where you might export a scene that just doesn't contain any meshes. Maybe it's only Light, Object3D, Camera, and Group objects. In that case the nodes list will have things in it, but the buffers will still be empty. I'm OK with fixing that case.