Sherin Shaju
Sherin Shaju

Reputation: 266

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

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);
  });

Upvotes: 2

Views: 2311

Answers (1)

Mugen87
Mugen87

Reputation: 31086

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.

Upvotes: 3

Related Questions