Contents

init(cube:options:)

Asynchronously creates an environment resource from a cube texture.

Declaration

@MainActor @preconcurrency convenience init(cube cubeTexture: TextureResource, options: EnvironmentResource.CreateOptions) async throws

Parameters

  • cubeTexture:

    A skybox cube texture of type .cubeType with .color or .hdrColor semantics.

  • options:

    A configuration for generating the environment resource.

Discussion

RealityKit generates an environment resource from a skybox cube texture of the environment. The created environment shares the input skybox.

// 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)
))
...