【问题标题】:Anchoring Multiple Scenes in RealityKit在 RealityKit 中锚定多个场景
【发布时间】:2020-05-12 10:04:23
【问题描述】:

在将多个场景(来自现实作曲家)加载到 arView 时,场景并未锚定在同一空间中。

在本例中,scene1 在应用启动时加载。按下按钮后,scene2 被添加到场景中。在这两个场景中,模型都放置在原点并预计与场景2 重叠被添加到视图中。但是scene1和scene2在加入arView时的位置是不同的。

import UIKit  
import RealityKit  

class ViewController: UIViewController {  

    @IBOutlet var arView: ARView!  
    @IBOutlet weak var button: UIButton!  

    var scene1: Experience.Scene1!  
    var scene2: Experience.Scene2!  

    override func viewDidLoad() {  
        super.viewDidLoad()  

        // Load the "Box" scene from the "Experience" Reality File  
        scene1 = try! Experience.loadScene1()  
        scene2 = try! Experience.loadScene2()  

        // Add the box anchor to the scene  
        arView.scene.addAnchor(scene1)  
    }  

    @IBAction func buttonPressed(_ sender: Any) {  
        arView.scene.addAnchor(scene2)  
    }  

}

注意:同时添加两个场景时不会出现此问题。

如何确保两个场景都锚定在同一个 ARAnchor 上?

【问题讨论】:

  • 如果你改用arView.scene.anchors.append(scene2) 会发生什么?

标签: swift augmented-reality arkit realitykit reality-composer


【解决方案1】:

使用以下方法:

let scene01 = try! Cube.loadCube()
let scene02 = try! Ball.loadSphere()

let cubeEntity: Entity = scene01.steelCube!.children[0]
let ballEntity: Entity = scene02.glassBall!.children[0]

// var cubeComponent: ModelComponent = cubeEntity.components[ModelComponent].self!
// var ballComponent: ModelComponent = ballEntity.components[ModelComponent].self!

let anchor = AnchorEntity()
anchor.addChild(cubeEntity)
anchor.addChild(ballEntity)

// scene01.steelCube!.components.set(cubeComponent)
// scene02.glassBall!.components.set(ballComponent)
arView.scene.anchors.append(anchor)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-18
    • 2021-04-17
    • 2021-01-25
    • 1970-01-01
    • 1970-01-01
    • 2020-01-17
    • 1970-01-01
    • 2023-04-02
    相关资源
    最近更新 更多