Remy Konings
Remy Konings

Reputation: 51

How do I get the parent modelEntity of my custom reality composer scene?

I'm trying to make an iOS AR app and I'm customising the standard AR app template with my custom model. I'm in need of finding the modelEntity of my custom usd scene.

When I start an AR app in Xcode and use the standard custom box scene, the modelEntity is "simpBld_root". All works find there and I can manipulate the model. Though when using a imported custom model, I'm not sure how the get the modelEntity of the whole scene. Looking at the console I thought it would have been "USD scene", but that doesn't seem to work.

Looking for some advice on how to handle custom usd scenes.

My current code looks like this:

import SwiftUI
import RealityKit

struct ContentView : View {
    var body: some View {
        ARViewContainer().edgesIgnoringSafeArea(.all)
    }
}

struct ARViewContainer: UIViewRepresentable {
    
    func makeUIView(context: Context) -> ARView {
        
        let arView = ARView(frame: .zero)
        typealias GstReady = Entity & HasCollision
        
        // Load the "Box" scene from the "Experience" Reality File
        let boxAnchor = try! Experience2.loadBox()
        
        // Add the box anchor to the scene
        arView.scene.anchors.append(boxAnchor)
        
        print(boxAnchor)
                
        if let entity = boxAnchor.findEntity(named: "simpBld_root") as? GstReady {
            entity.generateCollisionShapes(recursive: false)
            arView.installGestures([.rotation, .scale, .translation], for: entity)
        }
        
        return arView
        
    }
    
    func updateUIView(_ uiView: ARView, context: Context) {}
    
}

#if DEBUG
struct ContentView_Previews : PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
#endif

Console of the standard box scene: Standard Box scene

Console of my custom usd scene Custom usd scene

Upvotes: 2

Views: 279

Answers (0)

Related Questions