代码之家  ›  专栏  ›  技术社区  ›  Andy Jazz

在ARSCNView中显示“ARAnchor”

  •  1
  • Andy Jazz  · 技术社区  · 6 年前

    在阿基特我们可以想象 Feature Points' Cloud 在纵火中通过 .showFeaturePoints 类型属性:

    self.sceneView.debugOptions = [ARSCNDebugOptions.showFeaturePoints]
    

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

    static let showWorldOrigin: SCNDebugOptions
    

    ARAnchors

    如果

    2 回复  |  直到 6 年前
        1
  •  5
  •   BlackMirrorz    6 年前

    只是为了跟进@sj-r和@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提供的答案提供有用的扩展。

        2
  •  4
  •   sj-r    6 年前

    ARAnchor 仅表示“位置和方向”。你能看到的东西 SCNNode

    可以为通过中的方法添加的每个锚点附加一个节点 ARSCNViewDelegate

    func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
        //create a node so you can visualize the location.
        let sphereNode = SCNNode(geometry: SCNSphere(radius: 0.5))
        sphereNode.geometry?.firstMaterial?.diffuse.contents = UIColor.blue
        return sphereNode
    }
    

    在添加锚定后(或系统添加锚定时,例如在启用了“平面检测”或“图像/对象检测”时),将调用该命令

    sceneView.session.add(anchor:)