# Texture

Artifact: [androidx.xr.scenecore:scenecore](https://developer.android.com/jetpack/androidx/releases/xr-scenecore) [View Source](https://cs.android.com/search?q=file:androidx/xr/scenecore/Texture.kt+class:androidx.xr.scenecore.Texture) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

*** ** * ** ***


```
open class Texture : AutoCloseable
```

<br />

*** ** * ** ***

Represents a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture` in SceneCore.

A texture is an image that can be applied to a 3D model to give it color, detail, and realism. It can also be used as an alpha mask for a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/SurfaceEntity`.

It's important to close a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture` when it's no longer needed to free up resources. This can be done by calling the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture#close()` method or letting it get garbage collected.

## Summary

| ### Public companion functions |
|---|---|
| `suspend https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture#create(androidx.xr.runtime.Session,java.nio.file.Path)(session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session, path: https://developer.android.com/reference/java/nio/file/Path.html)` Public factory for a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture`, asynchronously loading a preprocessed texture from a `https://developer.android.com/reference/java/nio/file/Path.html` relative to the application's `assets/` folder. |

| ### Public functions |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture#close()()` Closes the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture`. |

## Public companion functions

### create

```
@MainThread
suspend fun create(session: Session, path: Path): Texture
```

Public factory for a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture`, asynchronously loading a preprocessed texture from a `https://developer.android.com/reference/java/nio/file/Path.html` relative to the application's `assets/` folder.

Currently, only URLs and relative paths from the `assets/` directory are supported.

| Parameters |
|---|---|
| `session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` | The `https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` to use for loading the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture`. |
| `path: https://developer.android.com/reference/java/nio/file/Path.html` | The `https://developer.android.com/reference/java/nio/file/Path.html` of the `.png` texture file to be loaded, relative to the application's `assets/` folder. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture` | a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture` upon completion. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if `https://developer.android.com/reference/java/nio/file/Path.html#isAbsolute()` is true, as this method requires a relative path. |
| `https://developer.android.com/reference/java/io/IOException.html` | if no file exists at the specified path, or if the file cannot be read or decoded. |

## Public functions

### close

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

```
@MainThread
open fun close(): Unit
```

Closes the given `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture`.

The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture` can be explicitly closed at anytime or garbage collected. In both cases, its resources are freed and an exception will be thrown if the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Texture` is used after being closed.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if the resource has already been closed. |