RealityKit – 从同一个 Reality Composer 项目加载另一个场景 [英] RealityKit – Load another Scene from the same Reality Composer project

查看:53
本文介绍了RealityKit – 从同一个 Reality Composer 项目加载另一个场景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Xcode 的模板创建了一个增强现实项目.

Xcode 创建一个名为 Experience.rcproject 的文件.

该项目包含一个名为 Box 的场景和一个名为 Steel Cube 的立方体.

我向 Experience.rcproject 添加了另外 3 个场景,分别称为 alphabravodelta.

我负责项目.

Xcode 运行这两行

//加载盒子"《体验》中的场景现实档案让 boxAnchor = 尝试!Experience.loadBoxX(命名文件:地面")//将框锚添加到场景中arView.scene.anchors.append(boxAnchor)

这些行从 Experience 文件加载 Box 场景.

一旦加载了这个场景,我如何切换到另一个场景 alphabravodelta 而不必加载整个场景?

解决方案

在 RealityKit 中切换来自 Reality Composer 的两个或多个场景的最简单方法是使用 removeAll() 实例方法,允许您删除数组中的所有锚点.

可以使用asyncAfter(deadline:execute:)方法切换两个场景:

让 boxAnchor = 试试!经验.loadBox()arView.scene.anchors.append(boxAnchor)DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {self.arView.scene.anchors.removeAll()让 sphereAnchor = 尝试!Experience.loadSphere()self.arView.scene.anchors.append(sphereAnchor)}

或者你可以使用一个普通的UIButton来切换两个不同的RC场景:

@IBAction func loadNewSceneAndDeletePrevious(_ sender: UIButton) {self.arView.scene.anchors.removeAll()让 sphereAnchor = 尝试!Experience.loadSphere()self.arView.scene.anchors.append(sphereAnchor)}

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?

解决方案

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)
}

这篇关于RealityKit – 从同一个 Reality Composer 项目加载另一个场景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆