GltfModelEntity


class GltfModelEntity : 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 companion functions

GltfModelEntity
@MainThread
create(session: Session, model: GltfModel, pose: Pose)

Public factory function for a GltfModelEntity.

Public functions

Unit

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

Unit
@MainThread
startAnimation(loop: Boolean, animationName: String)

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

Unit

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

Public properties

GltfModelEntity.AnimationState

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

List<GltfAnimation>

A list of all GltfAnimations defined in the GltfModelEntity.

List<GltfModelNode>

A list of all GltfModelNodes defined in the GltfModelEntity.

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 Unit

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

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

Added in 1.0.0-alpha13
@MainThread
fun create(session: Session, model: GltfModel, pose: Pose = Pose.Identity): GltfModelEntity

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
session: Session

Session to create the GltfModel in.

model: GltfModel

The GltfModel this Entity is referencing.

pose: Pose = Pose.Identity

The initial Pose of the Entity.

Public functions

startAnimation

Added in 1.0.0-alpha13
Deprecated in 1.0.0-alpha13
@MainThread
fun startAnimation(loop: Boolean = true): Unit

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
loop: Boolean = true

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
fun startAnimation(loop: Boolean, animationName: String): Unit

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
loop: Boolean

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

animationName: String

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
fun stopAnimation(): Unit

Stops the currently active animation.

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

Public properties

animationState

Added in 1.0.0-alpha13
Deprecated in 1.0.0-alpha13
val animationStateGltfModelEntity.AnimationState

The current animation state of the GltfModelEntity.

Returns
GltfModelEntity.AnimationState

The current animation state.

animations

Added in 1.0.0-alpha13
val animationsList<GltfAnimation>

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.

nodes

Added in 1.0.0-alpha13
val nodesList<GltfModelNode>

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.