'Json Parse Error line 22: Json Deserialization; unknown member 'EnableGuidedFilterOcclusion' - skipping
I want to load url of 3d model from internet, without saving it in local DB.So, after running my project it shows this error message -
Json Parse Error line 22: Json Deserialization; unknown member 'EnableGuidedFilterOcclusion' - skipping.Warning: in AppendProperty at line 859 of sdf/path.cpp -- Can only append a property 'preliminary:anchoring:type' to a prim path (/) Warning: in AppendProperty at line 859 of sdf/path.cpp -- Can only append a property 'triggers' to a prim path (/)
Please help me to solve this problem. Thanks in advance. Here is my code :
struct Augmen: UIViewRepresentable {
@Binding var location: Location
func makeUIView(context: Context) -> ARView {
let arView = ARView()
let url = URL(string: location.modelUrl)
let documents = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let destination = documents.appendingPathComponent(url!.lastPathComponent)
let session = URLSession(configuration: .default,
delegate: nil,
delegateQueue: nil)
var request = URLRequest(url: url!)
request.httpMethod = "GET"
let downloadTask = session.downloadTask(with: request, completionHandler: { (location: URL?,
response: URLResponse?,
error: Error?) -> Void in
let fileManager = FileManager.default
if fileManager.fileExists(atPath: destination.path) {
try! fileManager.removeItem(atPath: destination.path)
}
do {
try fileManager.moveItem(atPath: location?.path ?? "",
toPath: destination.path)
} catch {
print("error\(error.localizedDescription)")
}
DispatchQueue.main.async {
do {
let model = try Entity.load(contentsOf: destination)
let anchor = AnchorEntity()
anchor.addChild(model)
arView.scene.addAnchor(anchor)
// if #available(iOS 15.0, *) {
// model.playAnimation(model.availableAnimations.first!.repeat() )
// }
} catch {
print("Fail loading entity.")
}
}
})
downloadTask.resume()
return arView
}
func updateUIView(_ uiView: ARView, context: Context) {}
}
Solution 1:[1]
import SwiftUI
import ARKit
import RealityKit
class USDZSampleViewModel: ObservableObject{
let url = URL(string: "https://developer.apple.com/augmented-reality/quick-look/models/drummertoy/toy_drummer.usdz")
//The completion handler returns when it has the anchor
func downloadUSDZ(completion:@escaping (AnchorEntity?) -> Void){
guard let url = url else {
print("invalid url")
completion(nil)
return
}
if url.absoluteString.suffix(5) != ".usdz"{
print("not USDZ")
completion(nil)
return
}
//Mostly your code biggest difference is the completion handler
let documents = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first!
let destination = documents.appendingPathComponent(url.lastPathComponent)
let session = URLSession(configuration: .default,
delegate: nil,
delegateQueue: nil)
var request = URLRequest(url: url)
request.httpMethod = "GET"
let downloadTask = session.downloadTask(with: request, completionHandler: { (location: URL?, response: URLResponse?, error: Error?) -> Void in
let fileManager = FileManager.default
if fileManager.fileExists(atPath: destination.path) {
try! fileManager.removeItem(atPath: destination.path)
}
do {
try fileManager.moveItem(atPath: location?.path ?? "",
toPath: destination.path)
} catch {
print("error\(error)")
completion(nil)
}
DispatchQueue.main.async {
do {
let model = try Entity.load(contentsOf: destination)
let anchor = AnchorEntity()
anchor.addChild(model)
completion(anchor)
}
catch {
print("Fail load entity: \(error)")
completion(nil)
}
}
})
downloadTask.resume()
}
}
struct USDZSampleView: View {
@StateObject var vm: USDZSampleViewModel = .init()
@State var status: Steps = .waiting
@State var anchor: AnchorEntity? = nil
var body: some View {
switch status {
case .waiting:
Button("get USDZ", action: {
status = .fetching
//This operation is async so we have to wait until the Anchor is ready
vm.downloadUSDZ(completion: { anchor in
self.anchor = anchor
//When ready you can create the ARView
status = .showAR
})
})
case .fetching:
//Something to show while the download is happening
ProgressView()
case .showAR:
if let anchor = anchor {
Augmen(anchor: anchor)
}else{
Text("the anchor wasn't ready - ERROR")
}
}
}
enum Steps{
case waiting
case fetching
case showAR
}
}
struct Augmen: UIViewRepresentable {
var anchor: AnchorEntity
func makeUIView(context: Context) -> ARView {
let arView = ARView()
arView.scene.addAnchor(anchor)
return arView
}
func updateUIView(_ uiView: ARView, context: Context) {}
}
struct USDZSampleView_Previews: PreviewProvider {
static var previews: some View {
USDZSampleView()
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
