# MeshEntity

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

*** ** * ** ***


```
class MeshEntity : Entity
```

<br />

|---|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) ||||
| ↳ | [androidx.xr.scenecore.BaseScenePose](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/BaseScenePose) |||
|   | ↳ | [androidx.xr.scenecore.Entity](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity) ||
|   |   | ↳ | [androidx.xr.scenecore.MeshEntity](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MeshEntity) |

*** ** * ** ***

A renderable entity in the scene graph that renders a `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/CustomMesh`.

A `MeshEntity` renders a `CustomMesh` using a list of `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Material`. The number of materials must match the number of subsets in the `CustomMesh`.

## Summary

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MeshEntity` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MeshEntity#create(androidx.xr.runtime.Session,androidx.xr.scenecore.CustomMesh,kotlin.collections.List,kotlin.Int,androidx.xr.runtime.math.Pose,androidx.xr.scenecore.Entity)( session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session, mesh: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/CustomMesh, materials: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Material>, boneCount: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, pose: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose, parent: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity? )` Creates a new `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MeshEntity`. |

| ### 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/MeshEntity#setBoneTransforms(kotlin.collections.List)(transforms: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4>)` Sets the transforms for the bones in the skinned mesh. |
| `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/MeshEntity#setMaterial(androidx.xr.scenecore.Material,kotlin.Int)(material: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Material, subsetIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets a material for a mesh subset. |

| ### Public properties |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MeshEntity#boneCount()` The number of bones used to animate the mesh. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Material>` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MeshEntity#materials()` The list of materials used to render this entity's custom mesh. |
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/CustomMesh` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MeshEntity#mesh()` The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/CustomMesh` resource rendered by this entity. |

### Inherited functions

From [androidx.xr.scenecore.BaseScenePose](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/BaseScenePose) `open suspend https://developer.android.com/reference/kotlin/androidx/xr/scenecore/HitTestResult?` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/BaseScenePose#hitTest(androidx.xr.runtime.math.Vector3,androidx.xr.runtime.math.Vector3)(origin: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3, direction: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3)`

Perform a hit test from the specified origin in the specified direction into the Scene.
`open suspend https://developer.android.com/reference/kotlin/androidx/xr/scenecore/HitTestResult?` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/BaseScenePose#hitTest(androidx.xr.runtime.math.Vector3,androidx.xr.runtime.math.Vector3,kotlin.Int)(origin: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3, direction: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3, hitTestFilter: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`

Creates a hit test from the specified origin in the specified direction into the scene.
`open https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/BaseScenePose#transformDirectionTo(androidx.xr.runtime.math.Vector3,androidx.xr.scenecore.ScenePose)(direction: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3, destination: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ScenePose)`

Transforms a direction from this ScenePose's local space to the destination ScenePose's local space.
`open https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/BaseScenePose#transformPoseTo(androidx.xr.runtime.math.Pose,androidx.xr.scenecore.ScenePose)(pose: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose, destination: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ScenePose)`

Returns a `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` relative to this ScenePose, transformed into a Pose relative to the destination.
`open https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/BaseScenePose#transformPositionTo(androidx.xr.runtime.math.Vector3,androidx.xr.scenecore.ScenePose)(position: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3, destination: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ScenePose)`

Transforms a position from this ScenePose's local space to the destination ScenePose's local space.
`open https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/BaseScenePose#transformVectorTo(androidx.xr.runtime.math.Vector3,androidx.xr.scenecore.ScenePose)(vector: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Vector3, destination: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ScenePose)`

Transforms a vector from this ScenePose's local space to the destination ScenePose's local space.
From [androidx.xr.scenecore.Entity](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#addChild(androidx.xr.scenecore.Entity)(child: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity)`

Sets an Entity to be a child of this Entity in the scene graph.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#addComponent(androidx.xr.scenecore.Component)(component: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component)`

Adds a Component to this Entity.
`@https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#getAlpha(androidx.xr.scenecore.Space)(relativeTo: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Space)`

Returns the alpha transparency set for this Entity, relative to given Space.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component>` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#getComponents()()`

Retrieves all components attached to this Entity.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<T>` `<T : https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component> https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#getComponentsOfType(java.lang.Class)(type: https://developer.android.com/reference/java/lang/Class.html<T>)`

Retrieves all Components of the given type `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#getComponentsOfType(java.lang.Class)` and its subtypes attached to this Entity.
`open https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#getPose(androidx.xr.scenecore.Space)(relativeTo: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Space)`

Returns the `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` for this Entity, relative to the provided `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Space`.
`open @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#getScale(androidx.xr.scenecore.Space)(relativeTo: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Space)`

Returns the scale of this entity, relative to given space.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#isEnabled(kotlin.Boolean)(includeParents: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`

Returns the enabled status of this Entity.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#removeAllComponents()()`

Remove all components from this Entity.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#removeComponent(androidx.xr.scenecore.Component)(component: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Component)`

Removes the given Component from this Entity.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#setAlpha(kotlin.Float)(alpha: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)`

Sets the alpha transparency of the Entity relative to the parent Space.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#setEnabled(kotlin.Boolean)(enabled: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`

Sets the local enabled state of this Entity.
`open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#setPose(androidx.xr.runtime.math.Pose,androidx.xr.scenecore.Space)(pose: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose, relativeTo: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Space)`

Sets the `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` for this Entity.
`open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#setScale(kotlin.Float,androidx.xr.scenecore.Space)(scale: @https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, relativeTo: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Space)`

Sets the scale of this Entity relative to the given Space.

### Inherited properties

From [androidx.xr.scenecore.BaseScenePose](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/BaseScenePose) `open https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/BaseScenePose#poseInActivitySpace()`

The current `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose` relative to the activity space root.
From [androidx.xr.scenecore.Entity](https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity>` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#children()`

Provides the list of all children of this entity.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#contentDescription()`

Alternate text for this Entity to be consumed by Accessibility systems.
`open https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity?` `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity#parent()`

The parent of this Entity, from which this Entity will inherit most of its properties.

## Public companion functions

### create

```
@MainThread
fun create(
    session: Session,
    mesh: CustomMesh,
    materials: List<Material>,
    boneCount: @IntRange(from = 0, to = 255) Int = 0,
    pose: Pose = Pose.Identity,
    parent: Entity? = null
): MeshEntity
```

Creates a new `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MeshEntity`.

| Parameters |
|---|---|
| `session: https://developer.android.com/reference/kotlin/androidx/xr/runtime/Session` | The session to use for creating the MeshEntity. |
| `mesh: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/CustomMesh` | The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/CustomMesh` to render. |
| `materials: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Material>` | The list of `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Material` to use for each subset of the mesh. The list must contain one material per mesh subset. Materials in the list must not be null. |
| `boneCount: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0, to = 255) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | The number of bones used to animate the mesh. Must be between 0 and 255, inclusive. If 0, skinning is disabled. If non-zero, bone transforms can be set with `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MeshEntity#setBoneTransforms(kotlin.collections.List)`. |
| `pose: https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Pose = Pose.Identity` | The initial pose of the entity relative to its parent. Defaults to `Pose.Identity`. |
| `parent: https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity? = null` | Parent entity. Defaults to `null`. If `null`, the entity is created but not attached to the scene graph, meaning it will be invisible. If a parent entity (e.g., `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/ActivitySpace` or any other `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` already present in the scene) is assigned later, the entity will become visible (provided it is enabled). This allows for `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/Entity` pre-configuration before making it visible. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MeshEntity` | A new `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MeshEntity`. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if `boneCount` is not between 0 and 255, if the number of materials does not match the number of mesh subsets, or if any material in the list is null. |

## Public functions

### setBoneTransforms

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

```
@MainThread
fun setBoneTransforms(transforms: List<Matrix4>): Unit
```

Sets the transforms for the bones in the skinned mesh.

This function is used to animate meshes with skeletal animations (skinning). Each bone's transform is represented by a `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4` object. This can only be used if `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MeshEntity#boneCount()` is greater than zero.

| Parameters |
|---|---|
| `transforms: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4>` | A list of `https://developer.android.com/reference/kotlin/androidx/xr/runtime/math/Matrix4` objects representing the new bone transforms. The order in the list corresponds to the bone indices. The number of transforms can be less than `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MeshEntity#boneCount()`, in which case only the provided bones are updated. Any extra transforms beyond `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MeshEntity#boneCount()` will be ignored. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MeshEntity#boneCount()` is zero. |

### setMaterial

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

```
@MainThread
fun setMaterial(material: Material, subsetIndex: Int = 0): Unit
```

Sets a material for a mesh subset.

| 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 mesh subset. |
| `subsetIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 0` | The zero-based index for the mesh subset. Default is the first subset of the mesh. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if `subsetIndex` is out of bounds for the number of subsets. |

## Public properties

### boneCount

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

```
val boneCount: @IntRange(from = 0, to = 255) Int
```

The number of bones used to animate the mesh. Must be between 0 and 255, inclusive. If 0, skinning is disabled. If non-zero, bone transforms can be set with `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/MeshEntity#setBoneTransforms(kotlin.collections.List)`.

### materials

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

```
val materials: List<Material>
```

The list of materials used to render this entity's custom mesh.

### mesh

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

```
val mesh: CustomMesh
```

The `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/CustomMesh` resource rendered by this entity.