RealityKit - сохраненные объекты и асинхронная загрузка сцены из URL-адреса

Вот документация Apple:

1. Загрузка файлов, созданных вручную без Reality Composer

и я использовал загрузку сцены асинхронно из URL-кода:

 func loadRealityComposerSceneAsync (filename: String,
                                     fileExtension: String,
                                     sceneName: String,
                                     completion: @escaping (Swift.Result<(Entity & HasAnchoring)?, Swift.Error>) -> Void) {
     
     guard let realityFileSceneURL = createRealityURL(filename: filename, fileExtension: fileExtension, sceneName: sceneName) else {
         print("Error: Unable to find specified file in application bundle")
         return
     }
     
     let loadRequest = Entity.loadAnchorAsync(contentsOf: realityFileSceneURL)
     
     let cancellable = loadRequest.sink(receiveCompletion: { (loadCompletion) in
         if case let .failure(error) = loadCompletion {
             completion(.failure(error))
         }
     }, receiveValue: { (entity) in
         //  entity -> AnchorEntity
         completion(.success(entity))
     })
     cancellable.store(in: &streams)
 }

В viewDidLoad:

  loadRealityComposerSceneAsync(filename: "TestScene", fileExtension: "reality", sceneName: "space") { result in
            switch result {
            case .success(let anchor):
                print("space is \(anchor)\n")
                // anchor -> (Entity & HasAnchoring)?
                // How to show the TestScene file on the self.arView.scene

                break
             
            case .failure(let error):
                print(error.localizedDescription)
                break
            }
        }

пространство для печати:

Optional(▿ '' : AnchorEntity, children: 1
  ⟐ SynchronizationComponent
  ⟐ Transform
  ⟐ AnchoringComponent
  ▿ '' : Entity, children: 3
    ⟐ SynchronizationComponent
    ⟐ Transform
    ▿ 'boxs' : Entity, children: 1
      ⟐ SynchronizationComponent
      ⟐ Transform
      ▿ 'simpBld_root' : ModelEntity
        ⟐ ModelComponent
        ⟐ SynchronizationComponent
        ⟐ Transform
        ⟐ CollisionComponent
    ▿ '8C519DF7-2575-4AEE-A729-57F7CE0EFB41' : Entity, children: 1
      ⟐ SynchronizationComponent
      ⟐ Transform
      ▿ 'simpBld_root' : ModelEntity
        ⟐ ModelComponent
        ⟐ SynchronizationComponent
        ⟐ Transform
    ▿ 'star' : Entity, children: 1
      ⟐ SynchronizationComponent
      ⟐ Transform
      ▿ 'simpBld_root' : ModelEntity
        ⟐ ModelComponent
        ⟐ SynchronizationComponent
        ⟐ Transform
)

Итак, мой вопрос: как показать мой файл TestScene.reality на self.arView.scene. Спасибо!!!


person Hincat    schedule 20.08.2020    source источник