【问题标题】:How to update RealityKit world position SIMD3 constantly?如何不断更新 RealityKit 世界位置 SIMD3?
【发布时间】:2022-11-23 14:54:03
【问题描述】:

我正在尝试使用 RealityKit 将一个对象放置在世界位置,设置一个计时器,该计时器将清除所有锚点并每 5 秒放置一个新对象。

问题是无论我如何移动我的相机,物体仍然每 5 秒放置在同一个位置。

如何不断更新世界位置 SIMD3?

这是我的代码。

  @objc func updateTimer(){
        
        if secondsPassed < 1 {
            
            let anchor = AnchorEntity(world: SIMD3(x: 0, y: -0.25, z: -0.4))
        
            let box = ModelEntity(mesh: .generateBox(size: 0.04), materials: [SimpleMaterial(color: .red, isMetallic: false)])

            anchor.addChild(box)

            arView.scene.addAnchor(anchor)
            
            secondsPassed += 1
            
            
        } else if secondsPassed < 5 {
            
            secondsPassed += 1
            
            
        } else {
            
            secondsPassed = 0
            
            arView.scene.anchors.removeAll()
            
        }
    }

【问题讨论】:

    标签: ios swift augmented-reality arkit realitykit


    【解决方案1】:

    使用 ModelEntity() 的 removeFromParent() 函数和使用 AnchorEntity() 的 addChild() 函数,并确保导入 RealityKit。

    参考: Reference to the sample

    【讨论】:

      猜你喜欢
      • 2019-10-25
      • 1970-01-01
      • 2019-02-16
      • 1970-01-01
      • 2017-05-09
      • 2018-01-29
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      相关资源
      最近更新 更多