My visionOS app has over 150 3D models that work flawlessly via firebase URL. I also have some RealityKitContent scenes (stored locally) that are getting pretty large so I'm looking to move those into firebase as well and call on them as needed. I can't find any documentation that has worked for this and can't find anyone that's talked about it. Does anyone know if this possible?
I tried exporting the Reality Composer Pro scenes as USDZ's and then importing them in but kept getting material errors. Maybe there's a way to call on each 3D model separately and have RealityKit build them into the scene? I'm not really sure. Any help would be much appreciated !
It is possible to load RealityKitContent scenes from a remote server. Here's an approach that I've had success with.
- Zip (the directory that contains your .realitycomposerpro file)
- Deploy this zip to your web server
- At runtime download the zip and load the desired usda into an entity
Limitation - Your project can use built in components, but not custom ones.
Here's a snippet to point you in the right direction:
struct ImmersiveView: View {
func downloadBundle() async throws -> URL? {
// Change to your domain
if let modelUrl = URL(string: "http://<your url>/DownloadableStuff.zip") {
if let (tempFileUrl, _) = try? await URLSession.shared.download(from: modelUrl) {
let destinationUrl = FileManager.default.temporaryDirectory.appending(component: "\(UUID().uuidString).zip")
if FileManager().fileExists(atPath: destinationUrl.path) {
print("File already exists [\(destinationUrl.path)]")
try FileManager().removeItem(at: destinationUrl)
}
try FileManager.default.moveItem(at: tempFileUrl, to: destinationUrl)
let unzipDirectory = //use your favorite zip library to unzip the file
return unzipDirectory
}
}
return nil
}
var body: some View {
RealityView { content in
do {
guard let bundleRoot = try await downloadBundle() else {return}
// DownloadableStuff is the name of the zip file
// I threw this together quickly, ideally this wouldn't be hardcoded here and in download bundle
let usdaURL = "DownloadableStuff/Sources/RealityKitContent/RealityKitContent.rkassets/Immersive.usda"
let url = bundleRoot.appending(path: usdaURL)
let entity = try await Entity(contentsOf: url)
content.add(entity)
}
catch {
// show an error
print(error)
}
}
}
}