【问题标题】:RealityKit – AnchorEntity moves only to OriginRealityKit – AnchorEntity 仅移动到 Origin
【发布时间】:2022-02-13 03:21:06
【问题描述】:

问题在于它会上升到原点......而不仅仅是旋转自身。

视频是youtu.be/hFafOjKN3rg

anchorEntity.anchoring = AnchoringComponent(anchor)
anchorEntity.addChild(modelEntityClone)
anchorEntity.addChild(downEntity)
anchorEntity.addChild(sideEntity)
anchorEntity.addChild(rightEntity)
anchorEntity.name = name
        
arView.scene.addAnchor(anchorEntity)
arView.scene.addAnchor(planeEntity)

DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
    print("after 3 sec")
            
    let radians = 90.0 * Float.pi / 180.0
            
    let currentMatrix = anchorEntity.transform.matrix
    let rotation = simd_float4x4(SCNMatrix4MakeRotation(90.0 * .pi/180, 0,1,0))
    let transform = simd_mul(currentMatrix, rotation)                
    anchorEntity.move(to: transform, relativeTo: nil, duration: 3.0)
}

【问题讨论】:

    标签: swift realitykit


    【解决方案1】:

    应用锚点相对于模型实体的旋转:

    let model = ModelEntity(mesh: .generateBox(size: 0.2))
    let anchor = AnchorEntity(world: [0, 0.5, 0])
    anchor.addChild(model)
    
    let currentMatrix = anchor.transform.matrix
    let rotation = simd_float4x4(SCNMatrix4MakeRotation(.pi/2, 0, 1, 0))
    let transform = simd_mul(currentMatrix, rotation)
    anchor.move(to: transform, relativeTo: model, duration: 3.0)
    

    This post 也很有用。

    【讨论】:

    • 谢谢它有效!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-08-22
    • 1970-01-01
    • 1970-01-01
    • 2023-01-03
    • 2019-11-21
    • 2019-06-01
    • 2020-06-09
    相关资源
    最近更新 更多