0

I'm developing an app showing a 3D human body - in the SceneKit editor, I've set up the camera pointing to the model.

As I did set sceneView.allowsCameraControl = true, the user can move around the object, zoom in and zoom out with simple gestures.

In order to move vertically, I've implemented an UISlider - I don't want the user to pan vertically with two finger gestures.

In the slider action, I do the following:

@IBAction func sliderDidMove(_ sender: UISlider) {
    cameraNode = sceneView.scene?.rootNode.childNode(withName: "camera", recursively: true)
    let vert = 1.5*(0.5 - sender.value)
    cameraNode?.position.y = posY + vert
}

This works fine when I change the slider position just after loading my ViewController. But as soon as I rotate or zoom the model by gestures, the slider no longer shows effect - thus I can no longer change the position of my camera node programmatically.

Has anyone an idea how I can fix this?

pacification
  • 5,838
  • 4
  • 29
  • 51
Ulrich Vormbrock
  • 369
  • 2
  • 13
  • Unless I'm mistaken (it's been a while since I've placed with SK) you can't do both... once AllowsCamera is actually used the Scene ignores other inputs. You may have to take over all control - don't be worried about that, its not difficult. – Maury Markowitz Sep 07 '18 at 14:46
  • You may also want to try using sceneView.pointOfView in case it turns up a different result from the node named "camera". It's been a while since I used SceneKit with a SCNView, but I remember some confusion with that. – Dennis L Sep 09 '18 at 05:41
  • Thank you so much, Dennis - I tried it out and it works! And so simple! @IBAction func sliderDidMove(_ sender: UISlider) { let vert = 1.1*(0.5 - sender.value) sceneView.pointOfView?.position.y = posY + vert } – Ulrich Vormbrock Sep 10 '18 at 10:44

0 Answers0