【问题标题】:Is there a good way to implement RealityKit into a Swift playground?有没有一种将 RealityKit 实现到 Swift 游乐场的好方法?
【发布时间】:2020-06-02 23:49:36
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

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

    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
    

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


    关于 iPad 版 Swift Playgrounds read here


    【讨论】:

    • 您可以使用任何您想要的实体更改保龄球场景。不一定来自 .reality 文件。
    • 完全同意。然而,Apple 工程师在 Xcode 控制台中留下了一个提示——我们必须使用名称为 main.reality 文件。 .reality 文件在 Playground 中运行得更快。
    • 看到了提示,根据我的经验,它与您在代码中创建的实体完美配合
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-15
    • 2019-10-20
    • 2017-08-27
    • 1970-01-01
    • 2023-02-05
    • 2012-01-11
    • 2011-10-23
    相关资源
    最近更新 更多