RealityKit – Load another Scene from the same Reality Composer project

眉间皱痕 提交于 2020-08-03 08:14:26

问题


I create an Augmented Reality Project using Xcode's template.

Xcode creates a file called Experience.rcproject.

This project contains a scene called Box and a cube called Steel Cube.

I add 3 more scenes to Experience.rcproject, called alpha, bravo and delta.

I run the project.

Xcode runs these two lines

// Load the "Box" scene from the "Experience" Reality File
let boxAnchor = try! Experience.loadBoxX(namedFile: "Ground")

// Add the box anchor to the scene
arView.scene.anchors.append(boxAnchor)

These lines load the Box scene from the Experience file.

Once this scene is loaded how do I switch to another scene alpha, bravo or delta without having to load the whole thing?


回答1:


The simplest approach in RealityKit to switch two or more scenes coming from Reality Composer is to use removeAll() instance method, allowing you to delete all the anchors from array.

You can switch two scenes using asyncAfter(deadline:execute:) method:

let boxAnchor = try! Experience.loadBox()
arView.scene.anchors.append(boxAnchor)

    
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
    
    self.arView.scene.anchors.removeAll()

    let sphereAnchor = try! Experience.loadSphere()
    self.arView.scene.anchors.append(sphereAnchor)
}

Or you can switch two different RC scenes using a regular UIButton:

@IBAction func loadNewSceneAndDeletePrevious(_ sender: UIButton) {

    self.arView.scene.anchors.removeAll()

    let sphereAnchor = try! Experience.loadSphere()
    self.arView.scene.anchors.append(sphereAnchor)
}


来源:https://stackoverflow.com/questions/62533302/realitykit-load-another-scene-from-the-same-reality-composer-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!