One Logo Pool Ball
RealityFoundation · IOS API REFERENCE

EnvironmentResource

class · iOS 13.0+ · SDK 27.1

@MainActor @preconcurrency class EnvironmentResource

An environmental resource that contains background and lighting information for a scene. RealityKit supports image-based lighting that enables realistic reflections on your scene's 3D content. You can define the look of your scene's background by supplying an environment resource image that determines the general color of the room, and the location of any spotlights or shadowed areas within the reflection. RealityKit applies the image's characteristics to your scene's reflective content. ![Two screenshots depicting the process of applying an environment resource image to a reflective surface in a RealityKit scene. The first screenshot defines the scene's background, which shows a wide angle view of a room with overhead lights. The second screenshot shows a sphere with the image of the room displayed in a reflection.](EnvironmentResource) RealityKit checks a bundle for an environment resource by the filename you supply to one of the load functions. ### Create a skybox folder To add an environment resource to your Xcode project, make a folder with a name that ends in `.skybox` and place a single image inside. Ensure that the image is an environment map of equirectangular projection, also known as a *latitude-longitude projection*. Drag the folder into the Project navigator. In the options pane, choose to create a folder reference (not a group), and add the folder to your app's targets. At build time, Xcode compiles the image for use as an environment resource and inserts the result into the app bundle. RealityKit supports the same input formats as Image I/O, such as `.png` and `.jpg` However, to achieve rich, vibrant lighting, use a `.exr` or `.hdr` format, which support a wide dynamic range.

Members (12)

init · iOS 27.0+

init

TypeScript
static initEquirectangularOptions(cgImage: _CoreGraphics_CGImage, options: EnvironmentResource_CreateOptions): Promise<EnvironmentResource>
Swift declaration
@MainActor convenience init(equirectangular cgImage: CGImage, options: EnvironmentResource.CreateOptions) throws

Synchronously creates an environment resource from an equirectangular image. Loading an ``EnvironmentResource`` with this method blocks the main actor because it’s synchronous, so only call it from a command-line application. The method can stall a regular app, which makes it visibly hitch, and the system terminates an app if its UI becomes unresponsive. - Parameters: - cgImage: The source equirectangular (latitude, longitude) image. To preserve all details use an image where the width is half the height. - parameter options: A configuration for generating the environment resource.

init · iOS 27.0+

init

TypeScript
static initEquirectangularOptions57422(cgImage: _CoreGraphics_CGImage, options: EnvironmentResource_CreateOptions): Promise<EnvironmentResource>
Swift declaration
@MainActor convenience init(equirectangular cgImage: CGImage, options: EnvironmentResource.CreateOptions) async throws

Asynchronously generates an environment resource from an equirectangular image. - Parameters: - cgImage: The source equirectangular (latitude, longitude) image. To preserve all details use an image where the width is half the height. - parameter options: A configuration for generating the environment resource.

init · iOS 18.0+ · Deprecated in iOS 100000.0

init

TypeScript
static initEquirectangularWithName(cgImage: _CoreGraphics_CGImage, resourceName?: (string) | null): Promise<EnvironmentResource>
Swift declaration
@MainActor @preconcurrency convenience init(equirectangular cgImage: CGImage, withName resourceName: String? = nil) throws

Synchronously creates an environment resource from an equirectangular image. Loading an ``EnvironmentResource`` with this method blocks the main actor because it’s synchronous, so only call it from a command-line application. The method can stall a regular app, which makes it visibly hitch, and the system terminates an app if its UI becomes unresponsive. - Parameters: - cgImage: The source equirectangular (latitude, longitude) image. To preserve all details use an image where the width is half the height. - resourceName: A unique name the method assigns to the resource it loads, for use in network synchronization.

init · iOS 18.0+ · Deprecated in iOS 100000.0

init

TypeScript
static initEquirectangularWithName66002(cgImage: _CoreGraphics_CGImage, resourceName?: (string) | null): Promise<EnvironmentResource>
Swift declaration
@MainActor @preconcurrency convenience init(equirectangular cgImage: CGImage, withName resourceName: String? = nil) async throws

Asynchronously generates an environment resource from an equirectangular image. - Parameters: - cgImage: The source equirectangular (latitude, longitude) image. To preserve all details use an image where the width is half the height. - resourceName: A unique name the method assigns to the resource it loads, for use in network synchronization.

init · iOS 18.0+

init

TypeScript
static initCubeOptions(cubeTexture: TextureResource, options: EnvironmentResource_CreateOptions): Promise<EnvironmentResource>
Swift declaration
@MainActor @preconcurrency convenience init(cube cubeTexture: TextureResource, options: EnvironmentResource.CreateOptions) throws

Synchronously generates an environment resource from a cube texture resource. Loading an ``EnvironmentResource`` with this method blocks the main actor because it’s synchronous, so only call it from a command-line application. The method can stall a regular app, which makes it visibly hitch, and the system terminates an app if its UI becomes unresponsive. RealityKit generates an environment resource from a skybox cube texture of the environment. The created environment shares the input skybox. See ``init(cube:options:)-4xqiz`` for more details. ```swift // Use compression and high quality options to export optimized resources. let cube = try await TextureResource( cubeFromEquirectangular: image, quality: .high, options: TextureResource.CreateOptions(semantic: .hdrColor) ) let options = EnvironmentResource.CreateOptions( samplingQuality: .high, specularCubeDimension: cube.width/2, compression: .astc(blockSize: .block4x4, quality: .high) ) // Create an environment resource from the cube texture. let environment = try await EnvironmentResource( cube: cube, options: EnvironmentResource.CreateOptions( samplingQuality: .high, specularCubeDimension: cube.width/2, compression: .astc(blockSize: .block4x4, quality: .high) ) ) await MainActor.run { // Assign the environment to an image-based light component. let lightEntity = Entity() lightEntity.components.set(ImageBasedLightComponent( source: .single(environment) )) ... } ``` - parameter cubeTexture: A skybox cube texture of type `.cubeType` and `.color` or `.hdrColor` semantics. - parameter options: A configuration for generating the environment resource. - Note: If you request `.astc` compression and `cubeTexture` isn't already compressed, RealityKit compresses it.

init · iOS 18.0+

init

TypeScript
static initCubeOptions12915(cubeTexture: TextureResource, options: EnvironmentResource_CreateOptions): Promise<EnvironmentResource>
Swift declaration
@MainActor @preconcurrency convenience init(cube cubeTexture: TextureResource, options: EnvironmentResource.CreateOptions) async throws

Asynchronously creates an environment resource from a cube texture. RealityKit generates an environment resource from a skybox cube texture of the environment. The created environment shares the input skybox. - Note: ``CreateOptions/SamplingQuality-swift.enum/high`` and ``CreateOptions/SamplingQuality-swift.enum/veryHigh``, along with ``TextureResource/Compression/astc(blockSize:quality:)`` compression options, are only available in macOS. Use these options to write optimized scenes for all target platforms when exporting from macOS with ``Entity/write(to:)``. Compression options also significantly reduce an environmental resource's memory and disk usage. ```swift // Use compression and high quality options to export optimized resources. let cube = try TextureResource( cubeFromEquirectangular: image, quality: .high, options: TextureResource.CreateOptions(semantic: .color) ) let options = EnvironmentResource.CreateOptions( samplingQuality: .high, specularCubeDimension: cube.width/2, compression: .astc(blockSize: .block4x4, quality: .high) ) let environment = try EnvironmentResource( cube: cube, options: EnvironmentResource.CreateOptions( samplingQuality: .high, specularCubeDimension: cube.width/2, compression: .astc(blockSize: .block4x4, quality: .high) ) ) let lightEntity = Entity() lightEntity.components.set(ImageBasedLightComponent( source: .single(environment) )) ... ``` - parameter cubeTexture: A skybox cube texture of type `.cubeType` with `.color` or `.hdrColor` semantics. - parameter options: A configuration for generating the environment resource. - Note: If you request `.astc` compression and `cubeTexture` isn't already compressed, RealityKit compresses it.

static · iOS 13.0+ · Deprecated in iOS 100000.0

load

TypeScript
static load(name: string, bundle?: (_Foundation_Bundle) | null): Promise<EnvironmentResource>
Swift declaration
@MainActor @preconcurrency static func load(named name: String, in bundle: Bundle? = nil) throws -> EnvironmentResource

Synchronously loads an environment resource from a bundle. Loading an ``EnvironmentResource`` with this method blocks the main actor because it’s synchronous, so only call it from a command-line application. The method can stall a regular app, which makes it visibly hitch, and the system terminates an app if its UI becomes unresponsive. If your image file is at the path `Foo.skybox/Bar.exr` in your Xcode project, use `Bar` for the name parameter. To add an environment resource to your Xcode project, see ``EnvironmentResource``. - Important: This function blocks the calling thread while RealityKit loads the requested resource. - Parameters: - name: The image name without the file extension. - bundle: The bundle to search for the resource. Use `nil` to indicate the app’s bundle. - Returns: The environment resource that loads from the specified bundle.

init · iOS 27.0+

init

TypeScript
static initNamedInSkyboxMode(name: string, bundle: (_Foundation_Bundle) | null, skyboxMode: EnvironmentResource_SkyboxMode): Promise<EnvironmentResource>
Swift declaration
@MainActor @preconcurrency convenience init(named name: String, in bundle: Bundle? = nil, skyboxMode: EnvironmentResource.SkyboxMode) async throws

Asynchronously loads an environment resource from a bundle. - parameter skyboxMode: Skybox's preservation in the environment resource.

init · iOS 18.0+ · Deprecated in iOS 100000.0

init

TypeScript
static initNamedIn(name: string, bundle?: (_Foundation_Bundle) | null): Promise<EnvironmentResource>
Swift declaration
@MainActor @preconcurrency convenience init(named name: String, in bundle: Bundle? = nil) async throws

Asynchronously loads an environment resource from a bundle.

init · iOS 27.0+

init

TypeScript
static initSkyboxSpecularDiffuse(skyboxTexture: (TextureResource) | null, specularTexture: TextureResource, diffuseTexture: TextureResource): Promise<EnvironmentResource>
Swift declaration
@MainActor convenience init(skybox skyboxTexture: TextureResource?, specular specularTexture: TextureResource, diffuse diffuseTexture: TextureResource) throws

Creates an EnvironmentResource a skybox, specular and diffuse texture resources. - parameters: - skyboxTexture: a skybox texture to preserve. If nil, derives a low-resolution proxy from other inputs for lower memory usage. - specularTexture: an image based light specular texture. - diffuseTexture: an image based light diffuse texture. - Note: `SkyboxGenerator` and `ImageBasedLightTextureGenerator` can generate required textures into a `LowLevelTexture`, itself wrapped as a `TextureResource`. - Note: The skybox is not needed for image based lighting with `VirtualEnvironmentProbeComponent` and `ImageBasedLightComponent`.

get · iOS 18.0+

skybox

TypeScript
get skybox(): Promise<TextureResource>
Swift declaration
@MainActor @preconcurrency var skybox: TextureResource { get }

The cube color texture that contains environment surrounding details, or a low-resolution proxy of the original skybox if the `EnvironmentResource` was created with `CreateOptions(skyboxMode: .discard)`. The skybox contains the environment's detailed surroundings as a cube texture, which you can use to render the background of a scene. The skybox texture determines the environment's lighting. You can assign the skybox texture to a ``ShaderGraphMaterial`` cube texture parameter. ```swift // Load an environment resource. let env = try await EnvironmentResource( named: environmentResourceName, in: Bundle.main) // Assign its skybox to a material's cube map texture parameter. var skyboxCubeMaterial = try await ShaderGraphMaterial(named: materialUSDPath, from: sceneResourceName, in: contentBundle) try await skyboxCubeMaterial.setParameter(name: cubeTextureParameterName, value: .textureResource(env.skybox)) skyboxCubeMaterial.faceCulling = .front // Apply to a background sky dome sphere. let skyDome = await ModelEntity(mesh: .generateSphere(radius: 1E3), materials: [skyboxCubeMaterial]) await MainActor.run { sceneRootEntity.addChild(skyDome) // Also use the environment resource for lighting. let probe = VirtualEnvironmentProbeComponent.Probe(environment: env) sceneRootEntity.components.set(VirtualEnvironmentProbeComponent(source: .single(probe))) } ```

static · iOS 13.0+ · Deprecated in iOS 18.0

loadAsync

TypeScript
static loadAsync(name: string, bundle?: (_Foundation_Bundle) | null): Promise<LoadRequest<EnvironmentResource>>
Swift declaration
@MainActor @preconcurrency static func loadAsync(named name: String, in bundle: Bundle? = nil) -> LoadRequest<EnvironmentResource>

Asynchronously loads an environment resource from a bundle. If your image file is at the path `Foo.skybox/Bar.exr` in your Xcode project, use `Bar` for the name parameter. You need to call this function with the `async` keyword from an asynchronous context, such as from within a <doc://com.apple.documentation/documentation/swift/task> closure. To add an environment resource to your Xcode project, see ``EnvironmentResource``. - Parameters: - name: The image name without the file extension. - bundle: The bundle to search for the resource. Use `nil` to indicate the app’s bundle. - Returns: The environment resource that loads from the specified bundle.

Skipped declarations

No declarations were skipped in this snapshot.

All RealityFoundation types →