是否有将 RealityKit 实现到 Swift 游乐场的好方法?

Sam*_*ard 3 augmented-reality swift arkit realitykit reality-composer

我希望能够将在 Reality Composer 中创建的文件添加到 Swift Playground 中以进行测试。我也认为用作剧本的补充会很有趣。如何将 rcproject 添加到 Playground 中,例如 Apple 提供的场景“Box”的 Experience.rcproject?

ARG*_*Geo 5

您只能.reality使用以下代码在 Playground 中读取 RC文件格式:

import Cocoa
import RealityKit
import PlaygroundSupport

let arView = ARView(frame: CGRect(x: 0, y: 0, width: 800, height: 200))
arView.environment.background = .color(.black)

let fileURL = Bundle.main.url(forResource: "main", withExtension: "reality")
let bowlingScene = try! Entity.load(contentsOf: fileURL!)

let anchor = AnchorEntity()
anchor.addChild(bowlingScene)
anchor.scale = [4,4,4]
anchor.position.y = -0.5

arView.scene.anchors.append(anchor)

PlaygroundPage.current.liveView = arView
Run Code Online (Sandbox Code Playgroud)

因此,提供一个.playground带有main.reality场景的文件,使其嵌套。

在此处输入图片说明

  • 看到了提示,根据我的经验,它与您在代码中创建的实体完美配合 (2认同)