首页 > 解决方案 > 如何通过触摸移动场景中的 SCNNode?场景套件

问题描述

我有一个从搅拌机制作并导入的平面 3d 模型。构建我的场景let scene = SCNScene(named: "MainGame.scnassets/plane.scn")用于启动场景。我希望能够在场景中点击并移动我的飞机。我是 3d swift 新手。

标签: swiftscenekit

解决方案


NVM 我明白了

override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) { for touch in touches { touchLocation = CGPointToSCNVector3(view: sceneView, depth: 0, point:touch.location(in: sceneView) ) plane?.position.x = Float(touchLocation.x) plane?.position.y = Float(touchLocation.y) } }

func CGPointToSCNVector3(view: SCNView, depth: Float, point: CGPoint) -> SCNVector3 { let projectedOrigin = view.projectPoint(SCNVector3Make(0, 0, depth)) let locationWithz = SCNVector3Make(Float(point.x), Float(point.y), projectedOrigin.z) return view.unprojectPoint(locationWithz) }


推荐阅读