2

I would like to allow the user to rotate the scene by touch but have the lighting remain fixed. This works quite well using the default camera and default lighting. However, the default light is "straight on", i.e. along the screen's -z axis. I would rather it be directed at an angle more like a stage light, say from the front upper right.

But when I create my own light it appears that it needs to be attached to an existing node, the rootNode for example. When this is done, the light then rotates around with the model as the user manipulates the scene.

Is there a simple way to keep the lighting fixed while rotating with the default camera or do I need to get seriously involved creating a custom camera?

1 Answer 1

2

The lighting is already "fixed": that is, each light source keeps its position and direction within the scene unless you do something to change it. But it sounds like instead, you want to have a light that is fixed relative to a camera.

To achieve this, don't attach the light to the scene's root node. Instead, attach it to the same node that the camera is attached to. Or if you want to adjust the light's position relative to the camera, you could construct a small node tree, with one leaf containing the camera and the other leaf containing a directional light.

You'll almost always want to create your own camera or cameras in SceneKit. The default user-manipulable camera is useful for quickly getting up and running, and debugging, but not something that you want to expose to end users.

2
  • 1
    Thanks for the response. I made a camera and childed a couple lights to it. For some reason these stay fixed while the nodes with geometry respond to my rotation gestures. It's somewhat of a black box to me but it does exactly what I want.
    – bpedit
    Feb 5, 2016 at 0:14
  • Hi - I'm trying to achieve exactly the same as @bpedit b nut can't seem to get it to work even though I think I'm following the answer. Would anyone be able to put up some quick code so I can see where I'm going wrong?!!! Thanks in advance!
    – Sniffer
    Mar 17, 2019 at 18:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.