SCNLookAtConstraint导致缩放超过3D模型

时间:2017-03-15 20:26:09

标签: swift3 scenekit

UPDATE: 

经过进一步测试和评估后,似乎SCNLookAtConstraint导致了问题。基本上因为它移除了2个手指Pan手势,它会导致一些奇怪的行为与捏和滚动手势。有谁知道如何解决这个问题?

override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) { 
  let quaternion = sceneView.pointOfView?.orientation
  let position = sceneView?.pointOfView?.position
  print("Orientation: ((quaternion?.x),(quaternion?.y),(quaternion?.z),(quaternion?.w)) Position: ((position?.x),(position?.y),(position?.z)") 
}

但是现在只需按下2个手指变焦即可打印出相同的值。

func setupScene() {
    let scene = SCNScene()
    self.sceneView.scene = scene

    let camera = SCNCamera()
    let cameraNode = SCNNode()
    cameraNode.camera = camera
    cameraNode.position = SCNVector3(x: -1.0, y: 0.0, z: -1.0)
    cameraNode.boundingBox.max = SCNVector3(x: 2, y: 2, z: 2)
    cameraNode.boundingBox.min = SCNVector3(x: 0.1, y: 0.1, z: 0.1)

    let centerNode = SCNNode()
    centerNode.position = SCNVector3(x: 0.0, y: 0.0, z: 0.0)

    let light = SCNLight()
    let lightNode = SCNNode()
    light.type = .ambient
    light.color = UIColor.white
    lightNode.light = light

    scene.rootNode.addChildNode(cameraNode)
    scene.rootNode.addChildNode(centerNode)
    scene.rootNode.addChildNode(lightNode)

    cameraNode.constraints = [SCNLookAtConstraint(target: centerNode)]
    sceneView.pointOfView = cameraNode

}

0 个答案:

没有答案