# GltfModelNode

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/GltfModelNode.kt+class:androidx.xr.scenecore.GltfModelNode) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

*** ** * ** ***


```
class GltfModelNode
```

<br />

*** ** * ** ***

`https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelNode` represents a node in a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelEntity`.

Nodes are the fundamental structural elements of a glTF scene. A `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelNode` defines a spatial transformation and can be associated with other components such as a mesh. This class allows you to manipulate these spatial properties and, if a mesh is attached, override its rendering materials.

The lifecycle of a glTF node is tied to the glTF model itself. Trying to use the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelNode` after the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelEntity` is disposed will throw an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html`.

## Summary

| ### Public functions |
|---|---|
| `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/GltfModelNode#clearMaterialOverride(kotlin.Int)(primitiveIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Clears a previously set material override for a specific primitive of the mesh associated with this node. |
| `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/GltfModelNode#setMaterialOverride(androidx.xr.scenecore.Material,kotlin.Int)(material: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Material, primitiveIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets a material override for a primitive of the mesh associated with this node. |

| ### Public properties |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelNode#index()` The index of this node in the flattened list of nodes of the glTF model. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelNode#localPose()` The `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` of this node relative to its direct parent as defined in the source glTF asset. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelNode#localScale()` The scale of this node relative to its direct parent as defined in the source glTF asset. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelNode#modelPose()` The `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` of this node relative to the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelEntity` root. |
| `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelNode#modelScale()` The scale of this node relative to the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelEntity` root. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelNode#name()` The name of the node as defined in the glTF file. |

## Public functions

### clearMaterialOverride

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

```
@MainThread
fun clearMaterialOverride(primitiveIndex: Int = 0): Unit
```

Clears a previously set material override for a specific primitive of the mesh associated with this node.

If no override was previously set for that primitive, this call has no effect.

| Parameters |
|---|---|
| `primitiveIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | The zero-based index for the primitive of the associated mesh. The valid range is from `0` to `(primitiveCount - 1)`, where `primitiveCount` is the total number of primitives defined for the mesh in the source glTF asset. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if this node is not associated with a mesh. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-index-out-of-bounds-exception/index.html` | if the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelNode#clearMaterialOverride(kotlin.Int)` is out of bounds for the associated mesh. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelNode#setMaterialOverride(androidx.xr.scenecore.Material,kotlin.Int)` |   |

### setMaterialOverride

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

```
@MainThread
fun setMaterialOverride(material: Material, primitiveIndex: Int = 0): Unit
```

Sets a material override for a primitive of the mesh associated with this node.

In a glTF model, a node may be associated with a mesh. A mesh consists of one or more geometric surfaces called primitives (such as a collection of triangles) that are rendered using a single material. This method applies a material override to a specific primitive within this node's associated mesh.

| Parameters |
|---|---|
| `material: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Material` | The new `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Material` to apply to the primitive. |
| `primitiveIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | The zero-based index for the primitive of the associated mesh. The valid range is from `0` to `(primitiveCount - 1)`, where `primitiveCount` is the total number of primitives defined for the mesh in the source glTF asset. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if the provided `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Material` is invalid. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if this node is not associated with a mesh. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-index-out-of-bounds-exception/index.html` | if the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelNode#setMaterialOverride(androidx.xr.scenecore.Material,kotlin.Int)` is out of bounds for the associated mesh. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelNode#clearMaterialOverride(kotlin.Int)` |   |

## Public properties

### index

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

```
val index: Int
```

The index of this node in the flattened list of nodes of the glTF model.

### localPose

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

```
var localPose: Pose
```

The `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` of this node relative to its direct parent as defined in the source glTF asset.

Even though the API exposes nodes as a flattened list, their local transforms still respect the structure of the original glTF asset. If this node has no parent in the source asset, this pose is relative to the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelEntity` root.

### localScale

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

```
var localScale: Vector3
```

The scale of this node relative to its direct parent as defined in the source glTF asset.

### modelPose

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

```
var modelPose: Pose
```

The `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` of this node relative to the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelEntity` root.

Unlike `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelNode#localPose()`, which is strictly relative to the node's parent in the glTF file, the model pose represents the node's final, accumulated transformation within the model.

### modelScale

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

```
var modelScale: Vector3
```

The scale of this node relative to the `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/GltfModelEntity` root.

### name

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

```
val name: String?
```

The name of the node as defined in the glTF file. Returns `null` if the node has no name.