在 RealityKit 中更改 AnchorEntity 的旋转

Change a rotation of AnchorEntity in RealityKit

我在放置对象 3 秒后将 3d 对象放置到 ARViewController,然后我想将对象旋转 90 度:

arView.scene.addAnchor(anchorEntity)

DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {

    print("after 3 sec ! ")
            
    let radians = 90.0 * Float.pi / 180.0
    
    anchorEntity.orientation = simd_quatf(angle: radians, 
                                           axis: SIMD3(x: 0, y: 1, z: 0))
}

效果很好,但问题是我想要平滑旋转,你看短视频,突然旋转,看起来很奇怪。

我该怎么做?

https://youtu.be/Ixk2elm-bfU

尝试move(...)实例方法:

import UIKit
import RealityKit
import SceneKit

class ViewController: UIViewController {
    
    @IBOutlet var arView: ARView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let box = try! Experience.loadBox()
        let entity = box.steelBox!
        
        DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {

            let currentMatrix = entity.transform.matrix

            // Nothing prevents you from using even SceneKit's matrix methods
            let rotation = simd_float4x4(SCNMatrix4MakeRotation(.pi/2, 0,1,0))

            let transform = simd_mul(currentMatrix, rotation)               
            entity.move(to: transform, relativeTo: nil, duration: 3.0)
        }
        arView.scene.anchors.append(box)
    }
}