移动相机时 3D 对象悬停



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)
}

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

  • 如果导入了动画模型
  • 如果模型没有被 ARAnchor 绑定
  • 如果场景跟踪很差

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

相关内容

  • 没有找到相关文章

最新更新