# 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)

*** ** * ** ***


```
public final class MeshEntity extends Entity
```

<br />

|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) ||||
| ↳ | [androidx.xr.scenecore.BaseScenePose](https://developer.android.com/reference/androidx/xr/scenecore/BaseScenePose) |||
|   | ↳ | [androidx.xr.scenecore.Entity](https://developer.android.com/reference/androidx/xr/scenecore/Entity) ||
|   |   | ↳ | [androidx.xr.scenecore.MeshEntity](https://developer.android.com/reference/androidx/xr/scenecore/MeshEntity) |

*** ** * ** ***

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

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

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/MeshEntity` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/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)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/CustomMesh mesh, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Material> materials, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 0, to = 255) int boneCount, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Pose pose, https://developer.android.com/reference/androidx/xr/scenecore/Entity parent )` Creates a new `https://developer.android.com/reference/androidx/xr/scenecore/MeshEntity`. |
| `final int` | `https://developer.android.com/reference/androidx/xr/scenecore/MeshEntity#getBoneCount()()` The number of bones used to animate the mesh. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Material>` | `https://developer.android.com/reference/androidx/xr/scenecore/MeshEntity#getMaterials()()` The list of materials used to render this entity's custom mesh. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/CustomMesh` | `https://developer.android.com/reference/androidx/xr/scenecore/MeshEntity#getMesh()()` The `https://developer.android.com/reference/androidx/xr/scenecore/CustomMesh` resource rendered by this entity. |
| `final void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/xr/scenecore/MeshEntity#setBoneTransforms(kotlin.collections.List)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4> transforms)` Sets the transforms for the bones in the skinned mesh. |
| `final void` | `@https://developer.android.com/reference/androidx/annotation/MainThread https://developer.android.com/reference/androidx/xr/scenecore/MeshEntity#setMaterial(androidx.xr.scenecore.Material,kotlin.Int)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Material material, int subsetIndex)` Sets a material for a mesh subset. |

### Inherited methods

From [androidx.xr.scenecore.BaseScenePose](https://developer.android.com/reference/androidx/xr/scenecore/BaseScenePose) `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Pose` `https://developer.android.com/reference/androidx/xr/scenecore/BaseScenePose#getPoseInActivitySpace()()`

The current `https://developer.android.com/reference/androidx/xr/runtime/math/Pose` relative to the activity space root.
`https://developer.android.com/reference/androidx/xr/scenecore/HitTestResult` `https://developer.android.com/reference/androidx/xr/scenecore/BaseScenePose#hitTest(androidx.xr.runtime.math.Vector3,androidx.xr.runtime.math.Vector3)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Vector3 origin, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Vector3 direction)`

Perform a hit test from the specified origin in the specified direction into the Scene.
`https://developer.android.com/reference/androidx/xr/scenecore/HitTestResult` `https://developer.android.com/reference/androidx/xr/scenecore/BaseScenePose#hitTest(androidx.xr.runtime.math.Vector3,androidx.xr.runtime.math.Vector3,kotlin.Int)(
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Vector3 origin,
@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Vector3 direction,
int hitTestFilter
)`

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

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

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

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

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/androidx/xr/scenecore/Entity) `final void` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#addChild(androidx.xr.scenecore.Entity)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity child)`

Sets an Entity to be a child of this Entity in the scene graph.
`final boolean` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#addComponent(androidx.xr.scenecore.Component)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Component component)`

Adds a Component to this Entity.
`final @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0) float` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#getAlpha(androidx.xr.scenecore.Space)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Space relativeTo)`

Returns the alpha transparency set for this Entity, relative to given Space.
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Entity>` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#getChildren()()`

Provides the list of all children of this entity.
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Component>` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#getComponents()()`

Retrieves all components attached to this Entity.
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull T>` `<T extends https://developer.android.com/reference/androidx/xr/scenecore/Component> https://developer.android.com/reference/androidx/xr/scenecore/Entity#getComponentsOfType(java.lang.Class)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Class.html<@https://developer.android.com/reference/androidx/annotation/NonNull T> type)`

Retrieves all Components of the given type `https://developer.android.com/reference/androidx/xr/scenecore/Entity#getComponentsOfType(java.lang.Class)` and its subtypes attached to this Entity.
`final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/CharSequence.html` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#getContentDescription()()`

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

The parent of this Entity, from which this Entity will inherit most of its properties.
`@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Pose` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#getPose(androidx.xr.scenecore.Space)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Space relativeTo)`

Returns the `https://developer.android.com/reference/androidx/xr/runtime/math/Pose` for this Entity, relative to the provided `https://developer.android.com/reference/androidx/xr/scenecore/Space`.
`@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0) float` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#getScale(androidx.xr.scenecore.Space)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Space relativeTo)`

Returns the scale of this entity, relative to given space.
`final boolean` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#isEnabled(kotlin.Boolean)(boolean includeParents)`

Returns the enabled status of this Entity.
`final void` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#removeAllComponents()()`

Remove all components from this Entity.
`final void` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#removeComponent(androidx.xr.scenecore.Component)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Component component)`

Removes the given Component from this Entity.
`final void` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#setAlpha(kotlin.Float)(@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, to = 1.0) float alpha)`

Sets the alpha transparency of the Entity relative to the parent Space.
`final void` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#setContentDescription(kotlin.CharSequence)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/CharSequence.html value)`

Alternate text for this Entity to be consumed by Accessibility systems.
`final void` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#setEnabled(kotlin.Boolean)(boolean enabled)`

Sets the local enabled state of this Entity.
`void` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#setParent(androidx.xr.scenecore.Entity)(https://developer.android.com/reference/androidx/xr/scenecore/Entity value)`

The parent of this Entity, from which this Entity will inherit most of its properties.
`void` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#setPose(androidx.xr.runtime.math.Pose,androidx.xr.scenecore.Space)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Pose pose, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Space relativeTo)`

Sets the `https://developer.android.com/reference/androidx/xr/runtime/math/Pose` for this Entity.
`void` `https://developer.android.com/reference/androidx/xr/scenecore/Entity#setScale(kotlin.Float,androidx.xr.scenecore.Space)(@https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0) float scale, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Space relativeTo)`

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

## Public methods

### create

```
@MainThread
public static final @NonNull MeshEntity create(
    @NonNull Session session,
    @NonNull CustomMesh mesh,
    @NonNull List<@NonNull Material> materials,
    @IntRange(from = 0, to = 255) int boneCount,
    @NonNull Pose pose,
    Entity parent
)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/Session session` | The session to use for creating the MeshEntity. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/CustomMesh mesh` | The `https://developer.android.com/reference/androidx/xr/scenecore/CustomMesh` to render. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Material> materials` | The list of `https://developer.android.com/reference/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. |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 0, to = 255) int boneCount` | 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/androidx/xr/scenecore/MeshEntity#setBoneTransforms(kotlin.collections.List)`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Pose pose` | The initial pose of the entity relative to its parent. Defaults to `Pose.Identity`. |
| `https://developer.android.com/reference/androidx/xr/scenecore/Entity parent` | 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/androidx/xr/scenecore/ActivitySpace` or any other `https://developer.android.com/reference/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/androidx/xr/scenecore/Entity` pre-configuration before making it visible. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/MeshEntity` | A new `https://developer.android.com/reference/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. |

### getBoneCount

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

```
public final int getBoneCount()
```

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/androidx/xr/scenecore/MeshEntity#setBoneTransforms(kotlin.collections.List)`.

### getMaterials

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

```
public final @NonNull List<@NonNull Material> getMaterials()
```

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

### getMesh

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

```
public final @NonNull CustomMesh getMesh()
```

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

### setBoneTransforms

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

```
@MainThread
public final void setBoneTransforms(@NonNull List<@NonNull Matrix4> transforms)
```

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/androidx/xr/runtime/math/Matrix4` object. This can only be used if `https://developer.android.com/reference/androidx/xr/scenecore/MeshEntity#boneCount()` is greater than zero.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/runtime/math/Matrix4> transforms` | A list of `https://developer.android.com/reference/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/androidx/xr/scenecore/MeshEntity#boneCount()`, in which case only the provided bones are updated. Any extra transforms beyond `https://developer.android.com/reference/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/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
public final void setMaterial(@NonNull Material material, int subsetIndex)
```

Sets a material for a mesh subset.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/xr/scenecore/Material material` | The new `https://developer.android.com/reference/androidx/xr/scenecore/Material` to apply to the mesh subset. |
| `int subsetIndex` | 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. |