@ExperimentalCustomMeshApi
public final class MeshEntity extends 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 methods

static final @NonNull MeshEntity
@MainThread
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 MeshEntity.

final int

The number of bones used to animate the mesh.

final @NonNull List<@NonNull Material>

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

final @NonNull CustomMesh

The CustomMesh resource rendered by this entity.

final void

Sets the transforms for the bones in the skinned mesh.

final void
@MainThread
setMaterial(@NonNull Material material, int subsetIndex)

Sets a material for a mesh subset.

Inherited fields

From androidx.xr.scenecore.ScenePose
@NonNull Pose

The current Pose relative to the activity space root.

Inherited methods

From androidx.xr.scenecore.BaseEntity
void

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

boolean

Adds a Component to this Entity.

float
getAlpha(@NonNull Space relativeTo)

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

@NonNull List<@NonNull Entity>

Provides the list of all children of this entity.

@NonNull List<@NonNull Component>

Retrieves all components attached to this Entity.

@NonNull List<@NonNull T>

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

@NonNull CharSequence

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

Entity

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

@NonNull Pose
getPose(@NonNull Space relativeTo)

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

float
getScale(@NonNull Space relativeTo)

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

boolean
isEnabled(boolean includeParents)

Returns the enabled status of this Entity.

void

Remove all components from this Entity.

void

Removes the given Component from this Entity.

void
setAlpha(float alpha)

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

void

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

void
setEnabled(boolean enabled)

Sets the local enabled state of this Entity.

void

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

void
setPose(@NonNull Pose pose, @NonNull Space relativeTo)

Sets the Pose for this Entity.

void
setScale(float scale, @NonNull Space relativeTo)

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

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

Returns the alpha transparency set for this Entity.

@NonNull Pose

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

@FloatRange(from = 0.0) float

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

void

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

void
setScale(@FloatRange(from = 0.0) float scale)

Sets the scale of this Entity relative to its parent.

From androidx.xr.scenecore.ScenePose
HitTestResult
hitTest(@NonNull Vector3 origin, @NonNull Vector3 direction)

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

HitTestResult
hitTest(
    @NonNull Vector3 origin,
    @NonNull Vector3 direction,
    int hitTestFilter
)

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

@NonNull Vector3
transformDirectionTo(
    @NonNull Vector3 direction,
    @NonNull ScenePose destination
)

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

@NonNull Pose
transformPoseTo(@NonNull Pose pose, @NonNull ScenePose destination)

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

@NonNull Vector3
transformPositionTo(
    @NonNull Vector3 position,
    @NonNull ScenePose destination
)

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

@NonNull Vector3

Transforms a vector from this ScenePose's local space to the destination ScenePose's local 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 MeshEntity.

Parameters
@NonNull Session session

The session to use for creating the MeshEntity.

@NonNull CustomMesh mesh

The CustomMesh to render.

@NonNull List<@NonNull Material> materials

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.

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

@NonNull Pose pose

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

Entity parent

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
@NonNull 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.

getBoneCount

Added in 1.0.0-alpha15
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 setBoneTransforms.

getMaterials

Added in 1.0.0-alpha15
public final @NonNull List<@NonNull MaterialgetMaterials()

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

getMesh

Added in 1.0.0-alpha15
public final @NonNull CustomMesh getMesh()

The CustomMesh resource rendered by this entity.

setBoneTransforms

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

Parameters
@NonNull List<@NonNull Matrix4> transforms

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
public final void setMaterial(@NonNull Material material, int subsetIndex)

Sets a material for a mesh subset.

Parameters
@NonNull Material material

The new 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
IllegalArgumentException

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