swift - 如何通过触摸移动场景中的 SCNNode?场景套件
问题描述
我有一个从搅拌机制作并导入的平面 3d 模型。构建我的场景let scene = SCNScene(named: "MainGame.scnassets/plane.scn")
用于启动场景。我希望能够在场景中点击并移动我的飞机。我是 3d swift 新手。
解决方案
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) }
推荐阅读
- android - 为什么 TextView 变量需要在循环内
- c# - 如何根据对象的使用有条件地保持对象属性“必需”?
- node.js - Node.js 发布请求返回 404
- isabelle - 有没有学术论文的伊莎贝尔来源的例子?
- java - 在我的程序“AWT-EventQueue-0”java.lang.NullPointerException 中按下按钮时出现此错误
- php - Laravel sortByDesc 和 Paginate 关系
- java - 如何根据显着光值使振动不同?
- rest - GraphQL 如何比 REST 更高效?
- r - 根据 R 中的条件添加元素 rep 的列和 nb
- facebook-graph-api - 视频尚未准备好通过 Facebook Marketing API 在广告中使用