GltfModelEntity


public final class GltfModelEntity extends BaseEntity


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

This class is deprecated. Use GltfAnimation.AnimationState instead.

Public methods

static final @NonNull GltfModelEntity

Public factory function for a GltfModelEntity.

final @NonNull GltfModelEntity.AnimationState

This method is deprecated. Entity-level animation state is deprecated.

final @NonNull List<@NonNull GltfAnimation>

A list of all GltfAnimations defined in the GltfModelEntity.

final @NonNull List<@NonNull GltfModelNode>

A list of all GltfModelNodes defined in the GltfModelEntity.

final void
@MainThread
startAnimation(boolean loop)

This method is deprecated. Use GltfAnimation.start() on the specific animation instead.

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

This method is deprecated. Use GltfAnimation.start() on the specific animation instead.

final void

This method is deprecated. Use GltfAnimation.stop() on individual animations instead.

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.

void

Disposes of any system resources held by this Entity, and transitively calls dispose() on all its children.

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 sub-types 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

Added in 1.0.0-alpha13
@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-alpha13
Deprecated in 1.0.0-alpha13
public final @NonNull GltfModelEntity.AnimationState getAnimationState()

The current animation state of the GltfModelEntity.

Returns
@NonNull GltfModelEntity.AnimationState

The current animation state.

getAnimations

Added in 1.0.0-alpha13
@RequiresApi(value = 26)
@MainThread
public final @NonNull List<@NonNull GltfAnimationgetAnimations()

A list of all GltfAnimations defined in the GltfModelEntity. The list is lazily initialized on the first access.

The returned list corresponds to the array of animations defined in the source glTF file. The order of elements in this list is guaranteed to match the order of animations in the glTF file's animations array.

getNodes

Added in 1.0.0-alpha13
@MainThread
public final @NonNull List<@NonNull GltfModelNodegetNodes()

A list of all GltfModelNodes defined in the GltfModelEntity. The list is lazily initialized on the first access.

The returned list corresponds to the flattened array of nodes defined in the source glTF file. The order of elements in this list is guaranteed to match the order of nodes in the glTF file's nodes array.

startAnimation

Added in 1.0.0-alpha13
Deprecated in 1.0.0-alpha13
@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
IllegalArgumentException

if the underlying model doesn't contain any animations.

startAnimation

Added in 1.0.0-alpha13
Deprecated in 1.0.0-alpha13
@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

If this GltfModelEntity currently has an animation that is playing or paused, that animation will be stopped.

Parameters
boolean loop

If true, the animation plays in a loop indefinitely until stopAnimation is called. If false, the animation plays once and then stops.

@NonNull String animationName

The name of the animation to start.

Throws
IllegalArgumentException

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

stopAnimation

Added in 1.0.0-alpha13
Deprecated in 1.0.0-alpha13
@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