0

I have a sceneView where I loaded a 3d model. The model is showing fine and I can controlling it touching the screen.

What I need is to get the values of X, Y, Z rotation while the 3d model is rotating.

How could I get this values in real-time?

I have trying using camera rotation with a gesture recognizer but they are not updating.

override func viewDidLoad() {
        super.viewDidLoad()

        sceneView.scene = SCNScene(named: "PKB2");

        sceneView.autoenablesDefaultLighting = true
        sceneView.allowsCameraControl = true

        // add a tap gesture recognizer
        let tapGesture = UITapGestureRecognizer(target: self, action:
            #selector(handleTap(_:)))
        sceneView.addGestureRecognizer(tapGesture)

    }


    func handleTap(_ gestureRecognize: UIGestureRecognizer) {
        // retrieve the SCNView

        let cameraNode = SCNNode()
        cameraNode.camera = SCNCamera()

        print(cameraNode.rotation)

    }
SNos
  • 3,430
  • 5
  • 42
  • 92

1 Answers1

2

In your handleTap(_:)you are creating a new camera. The position and rotation of this camera (or the rotation of the node containing the camera) has nothing to do with the rotation of the camera used to render the scene. When you are setting allowsCameraControl to true on your view SceneKit is creating a new camera that the user can control with touch events.

You can get the node containing the camera that is currently used to render the view with the pointOfView property of the SCNSceneRenderer protocol that SCNView conforms to.

func handleTap(_ gestureRecognize: UIGestureRecognizer) {
    let cameraNode: SCNNode? = sceneView.pointOfView
    print(cameraNode?.rotation ?? "There is no camera set to the view")
} 
jlsiewert
  • 3,494
  • 18
  • 41
  • Thank you.. got it. Is there a way to disable only the position of the camera when moving the object with two fingers? I only want rotation e zoom enabled – SNos Jun 16 '17 at 13:05
  • 1
    Not while using `allowsCameraControl`. The SceneKit team sees this property only as a debugging tool. iOS 11 adds a lot of useful features to control the camera but for now you have to manually respond to the events and change the nodes position. Check [this](https://stackoverflow.com/questions/25654772/rotate-scncamera-node-looking-at-an-object-around-an-imaginary-sphere#25674762) post as a starting point – jlsiewert Jun 16 '17 at 13:10