【发布时间】:2017-09-24 12:26:31
【问题描述】:
下面的代码将 SCNPlane 放置在所触摸的点上,但平面的方向(旋转)到应用启动时手机所在的位置。理想情况下,我希望将节点定向到物理墙或相机的当前方向。 ARKit 是如何做到的?
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let touch = touches.first else {return}
let result = sceneView.hitTest(touch.location(in: sceneView), types: [ARHitTestResult.ResultType.featurePoint])
guard let hitResult = result.last else {return}
let hitTransform = SCNMatrix4.init(hitResult.worldTransform)
let hitVector = SCNVector3Make(hitTransform.m41, hitTransform.m42, hitTransform.m43)
createPlane(position: hitVector)
}
func createPlane(position: SCNVector3) {
let background = SCNNode()
background.geometry = SCNPlane.init(width: 0.12, height: 0.10) // better set its size
background.geometry?.firstMaterial?.diffuse.contents = "odinBW2.jpeg"
background.position = position
sceneView.scene.rootNode.addChildNode(background)
}
【问题讨论】:
-
你找到解决办法了吗??
-
最后,我决定让用户在开始 arkit 视图之前准备好将手机朝向正确方向的说明。