I wanted to update this post with resources I found.
It appears the automation for persistent anchors and world data maps has been configured as WorldAnchors. Currently, it looks like this is only supported in visionOS.
https://developer.apple.com/documentation/visionos/tracking-points-in-world-space
It appears that by simply adding a WorldAnchor that visionOS automatically tracks the world map, unloading and loading based on your location automatically in the background. This is amazing.
Though, I'm not sure why this wouldn't be supported on iOs and iPadOS as well. Perhaps in the future it will be implemented as a core ARKit feature as well.
To the best of my limited knowledge, it appears we will have to continue to use the previous methods for persistent data, which can be found here:
https://developer.apple.com/documentation/arkit/arkit_in_ios/data_management/saving_and_loading_world_data
However, I still have to try and implement this with RealityView. As it is my understanding that only RealityView supports Reality Composer Pro packages.
The goal here is to simply place a Reality Composer Pro package with AR Persistence...
Post
Replies
Boosts
Views
Activity
I was struggling to get QuickLook functioning in my app. It would display with the text "No File to View." The OP helped me fix my issues. My issues were in the coordinator setup. So, here's a functioning (as of 12/'24) QuickLook wrapped in SwiftUI using URL pass through from button if anyone needs it.
import QuickLook
import ARKit
// 1. Create a SwiftUI view that will present the QLPreviewController.
struct QuickLookView: View {
var fileURL: URL // Accept the URL as a parameter from button
var body: some View {
QuickLookPreview(fileURL: fileURL) // Pass the fileURL to the QuickLookPreview
.edgesIgnoringSafeArea(.all)
}
}
// 2. Create a UIViewControllerRepresentable that wraps the UIKit QLPreviewController.
struct QuickLookPreview: UIViewControllerRepresentable {
var fileURL: URL // Accept the fileURL parameter
func makeUIViewController(context: Context) -> QLPreviewController {
let previewController = QLPreviewController()
previewController.dataSource = context.coordinator
return previewController
}
func updateUIViewController(_ uiViewController: QLPreviewController, context: Context) {
// No updates required
}
// 3. Create a Coordinator to handle the QLPreviewControllerDataSource methods.
class Coordinator: NSObject, QLPreviewControllerDataSource {
var fileURL: URL // Store the fileURL in the Coordinator
init(fileURL: URL) {
self.fileURL = fileURL
}
func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
return 1
}
func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
return fileURL as QLPreviewItem // Return the fileURL as the preview item
}
}
// Create a Coordinator instance
func makeCoordinator() -> Coordinator {
return Coordinator(fileURL: fileURL) // Pass the fileURL to the Coordinator
}
}
And the then button
NavigationLink(destination: QuickLookView(fileURL: Bundle.main.url(forResource: "modelName", withExtension: "usdz")!)) {
Text("Quick Look")
.font(.system(size: 22))
.fontWeight(.bold)
.padding(.horizontal, 40)
.padding(.vertical, 20)
.background(Color.purple)
.foregroundColor(.white)
.cornerRadius(6)
}
Well, I figured it out from the Happy Beam demo code here: Happy Beam Docs
Problem: the Bundle var wasn’t found in scope.
Solution:
Make sure that your Reality Composer Pro Package has been as a Framework in he General Project Settings
Import (your package name)
In the Sources directory that Reality Composer Pro created, there is a Swift file that contains var you’re looking for usually (your project name + Bundle; i.e. “projectnameBundle”)
Load by creating an entity; scene = Entity(named: “Scene”, in: projectnameBundle)
Add the entity to your RealityView; content.add(scene)
Note: those will place the scene at your cameras location. So, be sure to move the camera away from the starting point to verify, but it’d be best to add a horizontal anchor and add the entity to the anchor, then the anchor to the RealityView to be less confusing Visually.
import RealityKit
import projectName
struct ContentView : View {
var body: some View {
RealityView { content in
// Create horizontal plane anchor
let anchor = AnchorEntity(.plane(.horizontal, classification: .any, minimumBounds: SIMD2<Float>(0.2, 0.2)))
// Load Scene from Reality Composer Pro Package
do {
let scene = try await Entity(named: "Scene", in: projectnameBundle)
// Add model to anchor
anchor.addChild(scene)
// Add anchor to RealityView
content.add(anchor)
} catch is CancellationError {
// The entity initializer can throw this error if an enclosing
// RealityView disappears before the model loads. Exit gracefully.
return
} catch let error {
// Other errors indicate unrecoverable problems.
print("Failed to load scene: \(error)")
}
// View Settings
content.camera = .spatialTracking
}
.edgesIgnoringSafeArea(.all)
}
}