Swift 3 - SceneKit 获取3d模型比例值
Swift 3 - SceneKit Get 3d model scale value
我正在尝试获取加载到 sceneView
中的 3d 对象的值,同时使用两根手指对其进行缩放。我可以正确获取 rotation
、position
和 orientation
,但是 scale
始终保持在 1
。
我怎样才能得到这个值?
var update = Timer()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
sceneView.scene = SCNScene(named: "PKB2");
sceneView.debugOptions.insert(SCNDebugOptions.showWireframe)
sceneView.autoenablesDefaultLighting = true
sceneView.allowsCameraControl = true
update = Timer.scheduledTimer(timeInterval: 0.01, target: self, selector: #selector(self.updateFunc), userInfo: nil, repeats: true)
}
func updateFunc() {
var eulerAngles_x = Double((sceneView.pointOfView?.eulerAngles.x)!) * (180.0 / Double.pi)
if( eulerAngles_x < 0 ) {eulerAngles_x += 360.0}
var eulerAngles_y = Double((sceneView.pointOfView?.eulerAngles.y)!) * (180.0 / Double.pi)
if( eulerAngles_y < 0 ) {eulerAngles_y += 360.0}
var eulerAngles_z = Double((sceneView.pointOfView?.eulerAngles.z)!) * (180.0 / Double.pi)
if( eulerAngles_z < 0 ) {eulerAngles_z += 360.0}
x_lbl.text = String(format:"%.2f", eulerAngles_x)
y_lbl.text = String(format:"%.2f", eulerAngles_y)
z_lbl.text = String(format:"%.2f", eulerAngles_z)
w_lbl.text = String(format:"%.2f", (sceneView.pointOfView?.scale.z)!)
print(sceneView.pointOfView?.scale) // not changing while scaling the object
}
使用 sceneView.allowsCameraControl = true
时,您是在操纵相机,而不是物体。你的 3D 物体没有移动,相机在它周围移动。
因此检查相机的比例是错误的,因为比例没有改变,只是放大了。
尝试检查 sceneView.pointOfView?.camera.xFov
和 sceneView.pointOfView?.camera.yFov
。
另外值得注意的是 allowsCameraControl
状态的文档:
Note that the primary purpose of this property is to aid in debugging
your application. You may want to implement you own camera controller
suitable for your application.
我正在尝试获取加载到 sceneView
中的 3d 对象的值,同时使用两根手指对其进行缩放。我可以正确获取 rotation
、position
和 orientation
,但是 scale
始终保持在 1
。
我怎样才能得到这个值?
var update = Timer()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
sceneView.scene = SCNScene(named: "PKB2");
sceneView.debugOptions.insert(SCNDebugOptions.showWireframe)
sceneView.autoenablesDefaultLighting = true
sceneView.allowsCameraControl = true
update = Timer.scheduledTimer(timeInterval: 0.01, target: self, selector: #selector(self.updateFunc), userInfo: nil, repeats: true)
}
func updateFunc() {
var eulerAngles_x = Double((sceneView.pointOfView?.eulerAngles.x)!) * (180.0 / Double.pi)
if( eulerAngles_x < 0 ) {eulerAngles_x += 360.0}
var eulerAngles_y = Double((sceneView.pointOfView?.eulerAngles.y)!) * (180.0 / Double.pi)
if( eulerAngles_y < 0 ) {eulerAngles_y += 360.0}
var eulerAngles_z = Double((sceneView.pointOfView?.eulerAngles.z)!) * (180.0 / Double.pi)
if( eulerAngles_z < 0 ) {eulerAngles_z += 360.0}
x_lbl.text = String(format:"%.2f", eulerAngles_x)
y_lbl.text = String(format:"%.2f", eulerAngles_y)
z_lbl.text = String(format:"%.2f", eulerAngles_z)
w_lbl.text = String(format:"%.2f", (sceneView.pointOfView?.scale.z)!)
print(sceneView.pointOfView?.scale) // not changing while scaling the object
}
使用 sceneView.allowsCameraControl = true
时,您是在操纵相机,而不是物体。你的 3D 物体没有移动,相机在它周围移动。
因此检查相机的比例是错误的,因为比例没有改变,只是放大了。
尝试检查 sceneView.pointOfView?.camera.xFov
和 sceneView.pointOfView?.camera.yFov
。
另外值得注意的是 allowsCameraControl
状态的文档:
Note that the primary purpose of this property is to aid in debugging your application. You may want to implement you own camera controller suitable for your application.