@ExperimentalCustomMeshApi
class MeshEntity : BaseEntity


A renderable entity in the scene graph that renders a CustomMesh.

A MeshEntity renders a CustomMesh using a list of Materials. The number of materials must match the number of subsets in the CustomMesh.

Summary

Public companion functions

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

Creates a new MeshEntity.

Public functions

Unit

Sets the transforms for the bones in the skinned mesh.

Unit
@MainThread
setMaterial(material: Material, subsetIndex: Int)

Sets a material for a mesh subset.

Public properties

Int

The number of bones used to animate the mesh.

List<Material>

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

CustomMesh

The CustomMesh resource rendered by this entity.

Inherited functions

From androidx.xr.scenecore.BaseEntity
open Unit
addChild(child: Entity)

Sets an Entity to be a child of this Entity in the scene graph.

open Boolean
addComponent(component: Component)

Adds a Component to this Entity.

open Float
getAlpha(relativeTo: Space)

Returns the alpha transparency set for this Entity, relative to given Space.

open List<Component>

Retrieves all components attached to this Entity.

open List<T>

Retrieves all Components of the given type T and its subtypes attached to this Entity.

open Pose
getPose(relativeTo: Space)

Returns the Pose for this Entity, relative to the provided Space.

open Float
getScale(relativeTo: Space)

Returns the scale of this entity, relative to given space.

open Boolean
isEnabled(includeParents: Boolean)

Returns the enabled status of this Entity.

open Unit

Remove all components from this Entity.

open Unit

Removes the given Component from this Entity.

open Unit
setAlpha(alpha: Float)

Sets the alpha transparency of the Entity relative to the parent Space.

open Unit
setEnabled(enabled: Boolean)

Sets the local enabled state of this Entity.

open Unit
setPose(pose: Pose, relativeTo: Space)

Sets the Pose for this Entity.

open Unit
setScale(scale: Float, relativeTo: Space)

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

From androidx.xr.scenecore.Entity
open @FloatRange(from = 0.0, to = 1.0) Float

Returns the alpha transparency set for this Entity.

open Pose

Returns the Pose for this Entity, relative to its parent.

open @FloatRange(from = 0.0) Float

Returns the local scale of this Entity, not inclusive of the parent's scale.

open Unit
setPose(pose: Pose)

Sets the Pose for this Entity, relative to its parent.

open Unit
setScale(scale: @FloatRange(from = 0.0) Float)

Sets the scale of this Entity relative to its parent.

From androidx.xr.scenecore.ScenePose
open suspend HitTestResult?
hitTest(origin: Vector3, direction: Vector3)

Perform a hit test from the specified origin in the specified direction into the Scene.

open suspend HitTestResult?
hitTest(origin: Vector3, direction: Vector3, hitTestFilter: Int)

Creates a hit test from the specified origin in the specified direction into the scene.

open Vector3
transformDirectionTo(direction: Vector3, destination: ScenePose)

Transforms a direction from this ScenePose's local space to the destination ScenePose's local space.

open Pose
transformPoseTo(pose: Pose, destination: ScenePose)

Returns a Pose relative to this ScenePose, transformed into a Pose relative to the destination.

open Vector3
transformPositionTo(position: Vector3, destination: ScenePose)

Transforms a position from this ScenePose's local space to the destination ScenePose's local space.

open Vector3
transformVectorTo(vector: Vector3, destination: ScenePose)

Transforms a vector from this ScenePose's local space to the destination ScenePose's local space.

Inherited properties

From androidx.xr.scenecore.BaseEntity
open List<Entity>

Provides the list of all children of this entity.

open CharSequence

Alternate text for this Entity to be consumed by Accessibility systems.

open Entity?

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

From androidx.xr.scenecore.ScenePose
open Pose

The current Pose relative to the activity space root.

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? = session.scene.activitySpace
): MeshEntity

Creates a new MeshEntity.

Parameters
session: Session

The session to use for creating the MeshEntity.

mesh: CustomMesh

The CustomMesh to render.

materials: List<Material>

The list of Materials 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: @IntRange(from = 0, to = 255) Int = 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 setBoneTransforms.

pose: Pose = Pose.Identity

The initial pose of the entity relative to its parent. Defaults to Pose.Identity.

parent: Entity? = session.scene.activitySpace

Parent entity. If null, the entity is created but not attached to the scene graph and will not be visible until a parent is set. The default value is Scene's ActivitySpace.

Returns
MeshEntity

A new MeshEntity.

Throws
IllegalArgumentException

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-alpha15
@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 Matrix4 object. This can only be used if boneCount is greater than zero.

Parameters
transforms: List<Matrix4>

A list of 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 boneCount, in which case only the provided bones are updated. Any extra transforms beyond boneCount will be ignored.

Throws
IllegalStateException

if boneCount is zero.

setMaterial

Added in 1.0.0-alpha15
@MainThread
fun setMaterial(material: Material, subsetIndex: Int = 0): Unit

Sets a material for a mesh subset.

Parameters
material: Material

The new Material to apply to the mesh subset.

subsetIndex: Int = 0

The zero-based index for the mesh subset. Default is the first subset of the mesh.

Throws
IllegalArgumentException

if subsetIndex is out of bounds for the number of subsets.

Public properties

boneCount

Added in 1.0.0-alpha15
val boneCountInt

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 setBoneTransforms.

materials

Added in 1.0.0-alpha15
val materialsList<Material>

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

mesh

Added in 1.0.0-alpha15
val meshCustomMesh

The CustomMesh resource rendered by this entity.