I am trying to display a reality
file created using Reality Composer
. The below code works for usdz
but not for reality
. Here is my code
struct ARViewContainer: UIViewRepresentable {
var modelConfirmedForPlacement: AnchorEntity?
func makeUIView(context: Context) -> ARView {
let arView = ARView(frame: .zero,
cameraMode: .ar,automaticallyConfigureSession: true)
let config = ARFaceTrackingConfiguration()
arView.session.run(config)
return arView
}
func updateUIView(_ uiView: ARView, context: Context) {
if let modelEntity = modelConfirmedForPlacement {
// Add the box anchor to the scene
uiView.scene.anchors.append(modelEntity)
}
}
}
//ViewModel
final class ContentViewModel: ObservableObject {
@Published var modelConfirmedForPlacement: AnchorEntity?
private var cancellable: AnyCancellable? = nil
func updateModelEntity(path: String){
let url = URL(fileURLWithPath: path)
self.cancellable = AnchorEntity.loadAnchorAsync(contentsOf: url)
.sink(receiveCompletion: { loadCompletion in
if case let .failure(error) = loadCompletion {
print("Unable to load a model due to error \(error)")
}
self.cancellable?.cancel()
}, receiveValue: { modelEntity in
debugPrint("hereeeeeeeee")
self.modelConfirmedForPlacement = modelEntity
})
}
func loadFileSync(url: URL, completion: @escaping (String?, Error?) -> Void)
{
//load from network and save locally }
The file does gets saved locally correctly but for reality files it is not displaying Here are the Xcode logs
File already exists [/var/mobile/Containers/Data/Application/880ED2EE-CCE7-4EE5-B854-0D1398650705/Documents/Experience.reality]
2021-07-25 16:29:09.060267+0530 RealityKitLoadModelFromNetwork[1352:474463] Metal GPU Frame Capture Enabled
2021-07-25 16:29:09.060478+0530 RealityKitLoadModelFromNetwork[1352:474463] Metal API Validation Enabled