[英]How to update RealityKit world position SIMD3 constantly?
我正在嘗試使用 RealityKit 在世界 position 上放置一個 object,設置一個計時器,該計時器將清除所有錨點並每 5 秒放置一個新的 object。
問題是無論我如何移動我的相機,object 仍然每 5 秒放置在同一個位置。
如何不斷更新世界 position 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()
}
}
使用 ModelEntity() 的 removeFromParent() function & 使用 AnchorEntity() 的 addChild() function 並確保導入 RealityKit。
參考: 參考樣本
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.