THREE.Object3D.add: object not an instance of THREE.Object3D
For those arriving here and looking for an alternate reason for getting this error, I got it because I loaded a GLTF object, but did not add it to the scene as a THREE.Object3D object.
A pared-down example of what I did wrong:
let example = new THREE.Object3D();
loader.load(objects.exampleGLTF, function (object){
example = object;
scene.add(example);
});
I was puzzled for a while, as I did various debugging to see that, indeed, it was loading, and waiting 5 seconds didn't make the problem go away.
The key was to add ".scene", as seen below.
let example = new THREE.Object3D();
loader.load(objects.exampleGLTF, function (object){
example = object.scene;
scene.add(example);
});
Ok here is the issue , the add call is invoked in wrong time , because i havent written this code from scratch and dont have time for very deep debugging , but i will give you a hint of what is wrong , and im sure you will find it easy to find the bug later , cause i think some of your objects are still loading while you are trying to add them to scene.
Procedure :
i changed
loader.onLoadComplete=function(){
scene.add(FloorDiskFire);
//scene.add(FloorDiskEarth);
//scene.add(FloorDiskWater);
//scene.add(FloorDiskAir);
scene.add(firePillar);
scene.add(earthPillar);
scene.add(waterPillar);
scene.add(airPillar);
}
grouped the action in one new function called addObjects();
:
function addObjects(){
scene.add(FloorDiskFire);
//scene.add(FloorDiskEarth);
//scene.add(FloorDiskWater);
//scene.add(FloorDiskAir);
scene.add(firePillar);
scene.add(earthPillar);
scene.add(waterPillar);
scene.add(airPillar);
};
then in your init()
function i invoked the addObjects();
, but it still give the same error !! so i tried invoking it after sometime - in line 309 > index.html :
setTimeout(function(){addObjects();},1000);
please note that i have tried 100ms , and it didnt work , then 1 second works well , this is not a solution , it is just and indication that if you delay the function call everything will work fine , it is your job now to determine when to call it (i.e find the proper event to invoke the function ) as it appears that loader.onLoadComplete
is not doing the job.
you can find the modified file here.