GltfModelEntity


public final class GltfModelEntity implements ScenePose, Entity


GltfModelEntity is a concrete implementation of Entity that hosts a glTF model.

Note: The size property of this Entity is always reported as {0, 0, 0}, regardless of the actual size of the model.

Summary

Nested types

public static class GltfModelEntity.AnimationState

Specifies the current animation state of the GltfModelEntity.

Public methods

static final @NonNull GltfModelEntity

Public factory function for a GltfModelEntity.

final int

The current animation state of the GltfModelEntity.

final void

Sets a material override for a mesh in the glTF model.

final void
@MainThread
startAnimation(boolean loop)

Starts animating the glTF with the first animation found in the model.

final void
@MainThread
startAnimation(boolean loop, @NonNull String animationName)

Starts the animation with the given name.

final void

Stops the currently active animation.

Inherited methods

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
setAlpha(@FloatRange(from = 0.0, to = 1.0) float alpha)

Sets the alpha transparency of the Entity and its children.

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
abstract @NonNull Pose

The current Pose relative to the activity space root.

abstract @NonNull HitTestResult
hitTest(@NonNull Vector3 origin, @NonNull Vector3 direction)

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

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

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

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

Public methods

create

Added in 1.0.0-alpha05
@MainThread
public static final @NonNull GltfModelEntity create(@NonNull Session session, @NonNull GltfModel model, @NonNull Pose pose)

Public factory function for a GltfModelEntity.

This method must be called from the main thread. https://developer.android.com/guide/components/processes-and-threads

Parameters
@NonNull Session session

Session to create the GltfModel in.

@NonNull GltfModel model

The GltfModel this Entity is referencing.

@NonNull Pose pose

The initial Pose of the Entity.

getAnimationState

Added in 1.0.0-alpha05
public final int getAnimationState()

The current animation state of the GltfModelEntity.

Returns
int

The current animation state.

setMaterialOverride

Added in 1.0.0-alpha05
@MainThread
public final void setMaterialOverride(@NonNull Material material, @NonNull String meshName)

Sets a material override for a mesh in the glTF model.

This method must be called from the main thread. https://developer.android.com/guide/components/processes-and-threads

If the material is not created or the mesh name is not found in the glTF model, this method will throw an IllegalStateException.

Parameters
@NonNull Material material

The material to use for the mesh.

@NonNull String meshName

The name of the mesh to use the material for.

startAnimation

Added in 1.0.0-alpha05
@MainThread
public final void startAnimation(boolean loop)

Starts animating the glTF with the first animation found in the model.

This method must be called from the main thread. https://developer.android.com/guide/components/processes-and-threads

Parameters
boolean loop

Whether the animation should loop over or stop after animating once. Defaults to true.

Throws
kotlin.IllegalArgumentException

if the underlying model doesn't contain any animations.

startAnimation

Added in 1.0.0-alpha05
@MainThread
public final void startAnimation(boolean loop, @NonNull String animationName)

Starts the animation with the given name. Only one animation can be playing at a time.

This method must be called from the main thread. https://developer.android.com/guide/components/processes-and-threads

Parameters
boolean loop

Whether the animation should loop over or stop after animating once.

@NonNull String animationName

The name of the animation to start.

Throws
kotlin.IllegalArgumentException

if the underlying model doesn't contain an animation with the given name.

stopAnimation

Added in 1.0.0-alpha05
@MainThread
public final void stopAnimation()

Stops the currently active animation.

This method must be called from the main thread. https://developer.android.com/guide/components/processes-and-threads