three.min.js:2 THREE.Object3D.add: object not an instance of THREE.Object3D

Viewed 1092

i got error three.min.js:2 THREE.Object3D.add: object not an instance of THREE.Object3D when try to run the 3D object.

  const loader = new THREE.OBJLoader();

  loader.load("./model/Room.obj", function (object) {
    scene.add(object.scene);
    console.log(object);
    renderer.render(scene, camera);
  });
1 Answers

Instead of doing:

scene.add(object.scene);

just do this when using OBJLoader:

scene.add(object);

OBJLoader always returns an instance of THREE.Group which has no scene property.

Also notice that the various loaders in three.js return their results in slightly different ways. Meaning the code in the onLoad() callback is specific for the respective loader.

Related