<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 26.0.0 -",
    "visionOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "RealityKit",
  "identifier" : "/documentation/RealityKit/TextureResource/cube(slices:named:options:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "RealityKit"
    ],
    "preciseIdentifier" : "s:17RealityFoundation15TextureResourceC4cube6slices5named7optionsACSaySo10CGImageRefaG_SSSgAC13CreateOptionsVtYaKFZ::OverloadGroup"
  },
  "title" : "cube(slices:named:options:)"
}
-->

# cube(slices:named:options:)

Asynchronously creates a cube texture resource from face images.

```
@MainActor @preconcurrency static func cube(slices: [CGImage], named resourceName: String? = nil, options: TextureResource.CreateOptions) async throws -> TextureResource
```

## Parameters

`slices`

The source images for each cube face in [`+X`, `-X`, `+Y`, `-Y`, `+Z`, `-Z`] order.
All images need to be square, and of equal size.

`resourceName`

A unique name for syncing the texture resource across the network.
The name is empty if you don’t include one.

`options`

A configuration for generating the texture.

## Discussion

Provide the cube faces in the following order: [`+X`, `-X`, `+Y`, `-Y`, `+Z`, `-Z`].

|![An illustration of the +X cube face orientation.](textureresource-cube-x-orientation)|![An illustration of the -X cube face orientation.](textureresource-cube-negx-orientation)|![An illustration of the +Y cube face orientation.](textureresource-cube-y-orientation)|![An illustration of the -Y cube face orientation.](textureresource-cube-negy-orientation)|![An illustration of the +Z cube face orientation.](textureresource-cube-z-orientation)|![An illustration of the -Z cube face orientation.](textureresource-cube-negz-orientation)|
|---------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|

Use the resulting texture to create an [`EnvironmentResource`](/documentation/RealityKit/EnvironmentResource),
or assign it to a material in Reality Composer Pro that requires
a cube texture type.

```swift
// Create a cube texture from image slices.
let cube = try await TextureResource.cube(
    slices: [posXImage, negXImage, posYImage, negYImage, posZImage, negZImage],
    options: TextureResource.CreateOptions(semantic: .hdrColor)
)

// Create an environment resource from the cube texture.
let environment = try await EnvironmentResource(
    cube: cube,
    options: EnvironmentResource.CreateOptions()
)

await MainActor.run {
    // Assign the environment to an image-based light component.
    let lightEntity = Entity()
    lightEntity.components.set(ImageBasedLightComponent(
        source: .single(environment)))
    ...
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)