在arkit中,我们可以通过Feature Points' Cloud
类型属性可视化在会话中检测到的.showFeaturePoints
:
self.sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints]
此外,我们可以显示坐标轴可视化,指示AR世界坐标系的位置和方向:
static let showWorldOrigin: SCNDebugOptions
但是在arscnview中是否可以显示
ARAnchors
?如果是的话,我们怎么做呢?
最佳答案
只是为了跟进@sj-r和@rickster的评论。
@rickster谈到的关于coordinateOrigin.scn
的示例代码可以在这里找到:Creating Face Based Experiences
这是我以前使用的一个小片段,用来想象轴心:
class BMOriginVisualizer: SCNNode {
//----------------------
//MARK: - Initialization
//---------------------
/// Creates An AxisNode To Vizualize ARAnchors
///
/// - Parameter scale: CGFloat
init(scale: CGFloat = 1) {
super.init()
//1. Create The X Axis
let xNode = SCNNode()
let xNodeGeometry = SCNBox(width: 1, height: 0.01, length: 0.01, chamferRadius: 0)
xNode.geometry = xNodeGeometry
xNodeGeometry.firstMaterial?.diffuse.contents = UIColor.red
xNode.position = SCNVector3(0.5, 0, 0)
self.addChildNode(xNode)
//2. Create The Y Axis
let yNode = SCNNode()
let yNodeGeometry = SCNBox(width: 0.01, height: 1, length: 0.01, chamferRadius: 0)
yNode.geometry = yNodeGeometry
yNode.position = SCNVector3(0, 0.5, 0)
yNodeGeometry.firstMaterial?.diffuse.contents = UIColor.green
self.addChildNode(yNode)
//3. Create The Z Axis
let zNode = SCNNode()
let zNodeGeometry = SCNBox(width: 0.01, height: 0.01, length: 1, chamferRadius: 0)
zNode.geometry = zNodeGeometry
zNodeGeometry.firstMaterial?.diffuse.contents = UIColor.blue
zNode.position = SCNVector3(0, 0, 0.5)
self.addChildNode(zNode)
//4. Scale Our Axis
self.scale = SCNVector3(scale, scale, scale)
}
required init?(coder aDecoder: NSCoder) { fatalError("Vizualizer Coder Not Implemented") }
}
可以这样初始化:
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
let anchorVizualizer = BMOriginVisualizer(scale: 0.5)
node.addChildNode(anchorVizualizer)
}
希望这将为@sj-r提供的答案提供有用的扩展。