#swift #asynchronous #arkit #realitykit #reality-composer
#swift #асинхронный #arkit #realitykit #реальность-композитор
Вопрос:
Вот документация Apple:
1.Загрузка файлов Reality Composer вручную без сгенерированного кода
и я использовал код «Загрузить сцену синхронно с URL»:
func loadRealityComposerSceneAsync (filename: String,
fileExtension: String,
sceneName: String,
completion: @escaping (Swift.Result<(Entity amp; 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: amp;streams)
}
В viewDidLoad :
loadRealityComposerSceneAsync(filename: "TestScene", fileExtension: "reality", sceneName: "space") { result in
switch result {
case .success(let anchor):
print("space is (anchor)n")
// anchor -> (Entity amp; 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.
Спасибо!!!