How do I load USDZ file into RealityKit scene?

Asked on 01/25/2025

1 search

To load a USDZ file into a RealityKit scene, you can use the RealityKit API, which supports loading USD files. Here's a general approach:

  1. Import the USDZ file: You can import your USDZ file into your RealityKit project. This can be done by dragging and dropping the USDZ file into your Xcode project.

  2. Load the USDZ file in RealityKit: Use the Entity.loadModel(named:) method to load the USDZ file into your RealityKit scene. This method asynchronously loads the model and returns an Entity that you can add to your scene.

  3. Add the model to your scene: Once the model is loaded, you can add it to your RealityKit scene by attaching it to an AnchorEntity or directly to the scene's root entity.

Here's a simple code example:

import RealityKit

// Load the USDZ model
let modelEntity = try! Entity.loadModel(named: "YourModelName")

// Create an anchor entity
let anchorEntity = AnchorEntity()

// Add the model entity to the anchor
anchorEntity.addChild(modelEntity)

// Add the anchor to the scene
arView.scene.addAnchor(anchorEntity)

For more detailed information, you might want to check out the session titled "What’s new in USD and MaterialX" from WWDC 2024, which discusses the support for USD in RealityKit. You can find more about this in the What’s new in USD and MaterialX (02:31) session.