1

3D 对象在 ARSCNView 中完美放置,但问题是当对象放置在 AR 中并且将相机向右、向左、顶部和底部移动得太快时,3D 对象开始在 planeNode 的任何地方悬停和跳舞

我该如何解决这个问题,尝试了很多方法来找到解决方案仍然没有得到任何结果

func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
    // Cast ARAnchor as ARPlaneAnchor
    guard let planeAnchor = anchor as? ARPlaneAnchor else { return }

    let planeGeometry = ARSCNPlaneGeometry(device: MTLCreateSystemDefaultDevice()!)!
    planeGeometry.update(from: planeAnchor.geometry)

    // Add material to geometry
    let material = SCNMaterial()
    material.diffuse.contents = UIColor.blue.withAlphaComponent(0.8)
    planeGeometry.materials = [material]

    // Create a SCNNode from geometry
    let planeNode = SCNNode(geometry: planeGeometry)
    self.privateNode = planeNode
    self.anchors.append(planeNode)
    DispatchQueue.main.async {
        self.lbl_middle_heading.text = Constants.kSharedAppDelegate?.languageBundle.localizedString(forKey: "Please tap anywhere on screen.", value: "", table: nil)
        self.showFeaturePoints(isShowDeugOptions: false)
    }
    // Add the newly created plane node as a child of the node created for the ARAnchor
    node.addChildNode(planeNode)
}

func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
    // Cast ARAnchor as ARPlaneAnchor, get the child node of the anchor, and cast that node's geometry as an ARSCNPlaneGeometry
    guard
        let planeAnchor = anchor as? ARPlaneAnchor,
        let planeNode = node.childNodes.first,
        let planeGeometry = planeNode.geometry as? ARSCNPlaneGeometry
        else { return }

    planeGeometry.update(from: planeAnchor.geometry)
}
4

1 回答 1

0

该模型在 AR 应用程序中“跳舞”或沿着某个轴漂移,主要原因有以下三个:

  • 如果您导入了动画模型
  • 如果模型没有被 ARAnchor 绑定
  • 如果您的场景跟踪不佳

彻底跟踪周围环境并确保它有相应的照明并且具有非常详细的纹理,以便获得足够数量的特征点进行跟踪。

于 2020-06-18T11:28:32.343 回答