Removing models from scene

@phil_crowther

I got to work by sticking them in an array, then when they need to be removed I loop through the array and remove all of them at once.

I was hesitant going this because I couldn’t grab any if the objects to get their transforms….but now I learned how to do that. Little bit of a learning curve learning this when you try to do something that works in other platforms but not in this.

That’s good to know.

I was pleasantly surprised when I realized that you could store 3D object addresses in an array and then create subroutines that would work on a single object within that array. It really helped with creating generalized subroutines.

So now it sounds like I can make those objects disappear one by one.

On that airplane diorama that I added to the showcase, I have been trying to determine the best way to switch between the exterior and interior models. I initially used the visible=false mentioned above. Efforts to pre-define the models as 3D objects generated errors. However, once loaded, I found that I could use the remove command. Apparently, a GLTF file is not treated as an object, but a group - since it can include \multiple objects, animations, lights, etc. And you can use the remove command on a group. So much to learn!

@phil_crowther

Yeah if I was in unity I would just use another camera and toggle them. Not sure if you can do that in three.js……I imagine you could. But not sure if disabling one would automatically move you to another one….or be able to set up Boolean as toggles for multiple cams.

Yes, you can easily move the camera around in three.js. That is another feature I used in my demo.

The camera is attached to an object (camobj) which acts like a selfie stick. In the program, pressing the “view” button moves camobj from (1) a central object to, (2) the aircraft object to (3) the cockpit object. This move is accomplished by removing the camobj from the old object and adding it to the new object.

In the external views, using camobj allows the camera to orbit the object to which camoobj is attached. You simply move the camera a specified z-distance from camobj and set the y-rotation to 180 degrees so it will always look back at the origin. Then you orbit the camera by changing the rotation of camobj. In the cockpit view, the camera y-rotation is set to “0” so that it always looks away from the origin and the z-distance is reduced to almost zero. As before, you look around by rotating camobj.

You can also easily move sounds and lights around since they are also treated as objects. Or you can have multiple sounds and lights and switch between them. I believe that you can have multiple cameras, including cameras working in tandem. I believe that is how they generate the skybox reflections on my models. But that is not a topic I have explored in depth - at least not yet.

1 Like