Spatial Scene API 应该如何使用?

Asked on 06/18/2025

1 search

To use the Spatial Scene API in RealityKit, you need to follow a series of steps to generate and present a spatial scene from a 2D image or a spatial photo. Here's a brief overview of the process:

  1. Create a Spatial 3D Image: Start by creating a spatial 3D image from a URL. This is the first step before you can initialize the image presentation component.

  2. Generate the Spatial Scene: Use the Spatial 3D Images Generate method to generate the spatial scene. This process takes a few seconds and is necessary before the image presentation component can present the scene.

  3. Set the Viewing Mode: After generating the spatial scene, update the image presentation component's available viewing modes to include Spatial 3D and Spatial 3D immersive modes. You can then set one of these modes as the desired viewing mode to opt into either a windowed or immersive presentation of the spatial scene.

  4. Present the Scene: You can choose to generate the spatial scene in advance or wait until a user action, such as pressing a button, to generate and present the scene. This approach is similar to how the Photos app operates on VisionOS.

For more detailed information and code examples, you can refer to the session What’s new in RealityKit (16:35) from WWDC 2025.