Posts

Post not yet marked as solved
0 Replies
549 Views
Hi I am trying to display a USDZ model in my app using code similar to that described here: https://developer.apple.com/documentation/arkit/previewing_a_model_with_ar_quick_look however, after updating to iOS 15 and Xcode 13 the option to toggle between the base model view and the AR view is no longer there, the share button is also missing. I am using view inside a navigation view in SwiftUI with code as follows. import SwiftUI struct ModelView: View {   var body: some View {     ARQuickLookView()   } } struct ModelView_Previews: PreviewProvider {   static var previews: some View {     ModelView()   } } import SwiftUI import QuickLook import ARKit struct ARQuickLookView: UIViewControllerRepresentable {   var allowScaling: Bool = true       func makeCoordinator() -> ARQuickLookView.Coordinator {     Coordinator(self)   }       func makeUIViewController(context: Context) -> QLPreviewController {     let controller = QLPreviewController()     controller.dataSource = context.coordinator     return controller   }       func updateUIViewController(_ controller: QLPreviewController,                 context: Context) {     // nothing to do here   }       class Coordinator: NSObject, QLPreviewControllerDataSource {     let parent: ARQuickLookView           init(_ parent: ARQuickLookView) {       self.parent = parent       super.init()     }           func numberOfPreviewItems(in controller: QLPreviewController) -> Int {       return 1     }           func previewController(      _ controller: QLPreviewController,      previewItemAt index: Int) -> QLPreviewItem {       let url = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("model.usdz")       return url as QLPreviewItem     }         } } struct ARQuickLookView_Previews: PreviewProvider {   static var previews: some View {     ARQuickLookView()   } } Any info on why I don't have these options and how I could get them back would be appreciated. Thanks Louis
Posted Last updated
.
Post marked as solved
1 Replies
449 Views
I am very new to USD, I have written a simple Python script to generate a basic USD file containing a blue Sphere, this part works fine, however, I then want to create a USDZ package using this file so have used the UsdUtils CreateNewUSDZPackage function which results in a pink and purple mess instead of the blue from the original file. I would like to know why this is occurring and how to prevent it. The simple script is as follows: from pxr import Usd, UsdGeom, UsdUtils stage = Usd.Stage.CreateNew('HelloWorld.usd') xform = stage.DefinePrim('/hello', 'Xform') sphere = stage.DefinePrim('/hello/world', 'Sphere') extentAttr = sphere.GetAttribute('extent') radiusAttr = sphere.GetAttribute('radius') radiusAttr.Set(2) extentAttr.Set(extentAttr.Get() * 2) sphereSchema = UsdGeom.Sphere(sphere) color = sphereSchema.GetDisplayColorAttr() color.Set([(0, 0, 1)]) stage.GetRootLayer().Save() UsdUtils.CreateNewUsdzPackage('HelloWorld.usd', 'HelloWorldZ.usdz') The produced files look like this: Thank you
Posted Last updated
.
Post marked as solved
3 Replies
566 Views
Hi Apple developers, I am new to IOS development and have recently added to my app the ability to download a file from a web API I created to be used in the app. The strange thing is this works fine in the simulator but when I plug in my IOS device I get these two errors: nw_endpoint_handler_set_adaptive_read_handler [C2 192.168.1.67:5000 ready channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, dns)] unregister notification for read_timeout failed and nw_endpoint_handler_set_adaptive_write_handler [C2 192.168.1.67:5000 ready channel-flow (satisfied (Path is satisfied), viable, interface: en0, ipv4, dns)] unregister notification for write_timeout failed Other endpoints from the web API that do not involve file downloads still work on the device. The file type is a usdz model Here is the code used to download and store the file: class ModelFetcher: NSObject{   var modelUrl: URL?       func generateModel() {     guard let url = URL(string: "http://192.168.1.67:5000/model.usdz") else {return}     let urlSession = URLSession(configuration: .default, delegate: self, delegateQueue: OperationQueue())     var request = URLRequest(url: url)     request.httpMethod = "POST"     let downloadTask = urlSession.downloadTask(with: request)     downloadTask.resume()   } } extension ModelFetcher: URLSessionDownloadDelegate {   func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {     print("File Downloaded Location- ", location)           let docsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]     let destinationPath = docsPath.appendingPathComponent("model.usdz")           try? FileManager.default.removeItem(at: destinationPath)           do {       try FileManager.default.copyItem(at: location, to: destinationPath)       self.modelUrl = destinationPath       print("File moved to: \(modelUrl!)")     } catch let error {       print("Copy Error: \(error.localizedDescription)")     }   } } Perhaps I have missed some configuration setting needed to allow file downloads on a device? Because, again, it works on the simulator but not on my own device, and, again, the other plain JSON endpoints still work on the device. Any help would be much appreciated. Thanks Louis
Posted Last updated
.
Post marked as solved
2 Replies
531 Views
Hi all, this is my first time trying to add an AR preview into an app (also my first time using the file system). I have been trying to implement a solution similar to that explained here https://developer.apple.com/forums/thread/126377 however one key difference is that my usdz model is not in my main bundle as it is generated and downloaded from an external source at run time. I was wondering if it is possible to display a file stored in the apps documents or cache directory and how it is done. The file is downloaded and stored in the caches directory as follows: class ModelFetcher: NSObject{   var modelUrl: URL?       func generateModel() {     guard let url = URL(string: "http://127.0.0.1:5000/model.usdz") else {return}     let urlSession = URLSession(configuration: .default, delegate: self, delegateQueue: OperationQueue())     var request = URLRequest(url: url)     request.httpMethod = "POST"     let downloadTask = urlSession.downloadTask(with: request)     downloadTask.resume()   } } extension ModelFetcher: URLSessionDownloadDelegate {   func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {     print("File Downloaded Location- ", location)           guard let url = downloadTask.originalRequest?.url else {       return     }     let docsPath = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0]     let destinationPath = docsPath.appendingPathComponent(url.lastPathComponent)           try? FileManager.default.removeItem(at: destinationPath)           do {       try FileManager.default.copyItem(at: location, to: destinationPath)       self.modelUrl = destinationPath       print("File moved to: \(modelUrl?.absoluteURL)")     } catch let error {       print("Copy Error: \(error.localizedDescription)")     }   } } and then the quick look preview looks like this: import SwiftUI import QuickLook import ARKit struct ARQuickLookView: UIViewControllerRepresentable {   var allowScaling: Bool = true       func makeCoordinator() -> ARQuickLookView.Coordinator {     Coordinator(self)   }       func makeUIViewController(context: Context) -> QLPreviewController {     let controller = QLPreviewController()     controller.dataSource = context.coordinator     return controller   }       func updateUIViewController(_ controller: QLPreviewController,                 context: Context) {     // nothing to do here   }       class Coordinator: NSObject, QLPreviewControllerDataSource {     let parent: ARQuickLookView     let destinationPath = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0].appendingPathComponent("model.usdz")     private lazy var fileURL: URL = destinationPath           init(_ parent: ARQuickLookView) {       self.parent = parent       super.init()     }           func numberOfPreviewItems(in controller: QLPreviewController) -> Int {       return 1     }     func previewController(       _ controller: QLPreviewController,       previewItemAt index: Int     ) -> QLPreviewItem {       let fileURL = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask)[0].appendingPathComponent("model.usdz")       print(fileURL)       let item = ARQuickLookPreviewItem(fileAt: fileURL)       print(item)       item.allowsContentScaling = parent.allowScaling       return item     }   } } struct ARQuickLookView_Previews: PreviewProvider {   static var previews: some View {     ARQuickLookView()   } } However, I get an error reading "Unhandled item type 13: contentType is: (null) #PreviewItem" I know the file is actually located at this location as I have opened it in Finder. Any help would be much appreciated. Thanks in advance, Louis
Posted Last updated
.