Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLTFLoader outputs an empty Group when multiple scenes refer to the same root node #27993

Open
wlinna opened this issue Mar 25, 2024 · 1 comment

Comments

@wlinna
Copy link
Contributor

wlinna commented Mar 25, 2024

Description

GLTFLoader outputs an empty Group when multiple scenes refer to the same root node. I created a simple cube in Blender, exported to glTF. This works fine. But when I duplicate the scenes array in glTF file and try to view it in ThreeJS, glTF loader returns an empty group.

So this works:

	"scene":0,
	"scenes":[
		{
			"name":"Scene",
			"nodes":[0]
		}
	],

... while this doesn't:

	"scene":0,
	"scenes":[
		{
			"name":"Scene",
			"nodes":[0]
		},
		{
			"name":"Scene2",
			"nodes":[0]
		}
	],

glTF specification allows referring to the same root nodes from multiple scenes, so I consider this a bug.

While I have no reason to duplicate scenes, we do sometimes load such models from external sources, and have no practical way to preprocess the files to remove

Reproduction steps

  1. Download the attached GLB file
  2. Add it to threejs editor, gltfviewer or any three.js scene
  3. Admire the empty scene

duplicatescene.zip

Code

 const loader = new GLTFLoader();
 loader.parse(e.target.result, '', gltf => {
            console.log(gltf)
            if (gltf.scene.isGroup && gltf.scene.children.length === 0) {
            		console.error('gltf.scene is a group with no children!')
            }
  });

Live example

https://jsfiddle.net/jteq8mov/2/

Screenshots

No response

Version

r156 and r162 at least

Device

No response

Browser

No response

OS

No response

@donmccurdy
Copy link
Collaborator

Agreed, while glTF models with multiple scenes are fairly rare, I would consider this a bug as well. Note that we'll need to either parse the node subtree a second time, or use SkeletonUtils.clone to make a copy. Calling node.clone() alone will break connections to the bones of skinned meshes.

@donmccurdy donmccurdy added the Bug label Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants