【发布时间】:2018-03-26 11:41:34
【问题描述】:
我有一个简单的 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 hitTrasform = SCNMatrix4(hitResult.worldTransform)
let hitVector = SCNVector3Make(hitTrasform.m41, hitTrasform.m42, hitTrasform.m43)
createBox(position: hitVector)
}
我添加了一个立方体
func createBox(position: SCNVector3) {
let box = SCNBox(width: 0.1, height: 0.1, length: 0.1, chamferRadius: 1)
box.firstMaterial?.diffuse.contents = UIColor.black
let sides = [
UIColor.red, // Front
UIColor.black, // Right
UIColor.black, // Back
UIColor.black, // Left
UIColor.black, // Top
UIColor.black // Bottom
]
let materials = sides.map { (side) -> SCNMaterial in
let material = SCNMaterial()
material.diffuse.contents = side
material.locksAmbientWithDiffuse = true
return material
}
box.materials = materials
let boxNode = SCNNode(geometry: box)
boxNode.position = position
sceneView.scene.rootNode.addChildNode(boxNode)
}
当我第一次添加它时,我看到了正面和右侧。如果我绕过另一侧的立方体并添加另一个立方体,我会看到立方体的背面。那么,无论用户如何走动,我能否做到让用户只看到正面。
谢谢。
【问题讨论】:
标签: swift scenekit arkit scnnode