I went through the same moments of head scratching others have gone through in regards to the ThreeJS spotlight. I thought I could put a spotlight anywhere in my ThreeJS scene using it’s position
property:
Apparently and somewhat weirdly the SpotLight
position property seems to make more like a rotation or “head points in direction” property since the docs seem to indicate that it acts like a vector that indicates the direction it is pointing in, not as I wrongly thought, that it acts like other ThreeJS objects where it sets the object’s XZY position in the scene?
Here are the docs on the position
property:
.position : Vector3
This is set equal to Object3D.DefaultUp (0, 1, 0), so that the light shines from the top down.
So right now, my only idea for solving my usage problem is to create an invisible object above the ground everywhere I want a spotlight and attach the spotlight to it? My overall intent is to simulate the effect of stage lights, which as you know are positioned all around the auditorium, especially the center and the sides, pointed at various parts of the stage. Is that the usual technique for placing spotlights at exact locations around a ThreeJS scene? The one thing that worries me about that idea as talked about in the forum link I placed above, is that it means you have to attach a child object to the main animation model at the “spot” you want the spotlight to be.
For example, in that forum thread the user wants to use a pair of spotlights as a pair of headlights. As far as I can tell that means the user would have to create a pair of headlight objects and then attach a spotlight to each headlight. I’d guess that’s fine in that user’s case because they probably havd to create a pair of headlight objects already. But in my case, I have a floating camera drone that is just a sphere, so I would have to create an invisible object, position it where I want in the new group object I now need to create to group the camera drone, add the invisible spotlight mounting object to the group, and then add the spotlight. I’ll do this extra work if I have to, but I’m hoping there is a more streamlined approach I could implement.
Or am I using the wrong threeJS object and if so, what should I be using instead?
Also, what are the pros and cons of creating a group to link objects as opposed to adding an object directly to another object using the add()
method?