gpt4 book ai didi

swift - 在 ARSCNView 中显示 "ARAnchor"

转载 作者:搜寻专家 更新时间:2023-11-01 05:49:26 26 4
gpt4 key购买 nike

在 ARKit 中,我们可以通过 .showFeaturePoints 类型属性可视化在 ARSession 中检测到的 Feature Points' Cloud:

self.sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints]

此外,我们还可以显示坐标轴可视化,指示 AR 世界坐标系的位置和方向:

static let showWorldOrigin: SCNDebugOptions

但是可以在 ARSCNView 中显示 ARAnchors 吗?

如果,我们该怎么做?

最佳答案

只是为了跟进@sj-r 和@Rickster 的评论。

@Rickster 谈到的关于 coordinateOrigin.scn 的示例代码可以在这里找到:Creating Face Based Experiences

这是我之前用来可视化 Axis 的一个小片段:

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 提供的答案的扩展有用。

关于swift - 在 ARSCNView 中显示 "ARAnchor",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52189189/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com