Adding gltf in scene ,where are they?

hello ,

i m trying to understand how a scene is structured and where are object . i ve seen, when i add an object which has directly created with Three , that scene.children.length increase. So i ve understood that if i want to deal with an object i can use scene.children[ i ] .

now if i add object which is imported with gltf , everything work very well , i can see objet in web page , but i can’t found it in the scene , cause after i have added my object , the scene.children.length don’t increase . So i dont know where object imported with gltf are . question where are there ?
thank

If scene.children.length does not increase, it means you didn’t really add the object to the scene :

scene.add( myObjectFromGLTF );

When your GLTF is loaded, you’re supposed to add it to the scene like this :

const loader = new GLTFLoader();

loader.load( url, function ( gltf ) {

		scene.add( gltf.scene );

	},

	function ( xhr ) {

		console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );

	},

	function ( error ) {

		console.log( 'An error happened' );

	}
);

hello,

here my code ,

this code work fine cause i can see house in my web page . but scene.children.length dont increase after i have added house object .

I think you are logging scene.length before the model is actually added to the scene.

thank you very much , you are right .

ive wrote the code which display scene.children.length just after the loader and it dont increase because object wasnt yet load .

if now i try to display scene.children.length at the end , once everything have been loaded like this

it work fine .

thank you very much for your help .

1 Like