GltfModelEntity


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

Specifies the current animation state of the GltfModelEntity.

Public companion functions

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

Public factory function for a GltfModelEntity.

Public functions

Unit

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

Unit

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

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

Starts the animation with the given name.

Unit

Stops the currently active animation.

Public properties

Int

The current animation state of the GltfModelEntity.

Inherited functions

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

Sets the alpha transparency of the Entity and its children.

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
abstract suspend HitTestResult
hitTest(origin: Vector3, direction: Vector3)

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

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

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

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

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

Inherited properties

From androidx.xr.scenecore.ScenePose
abstract Pose

The current Pose relative to the activity space root.

Public companion functions

create

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

setMaterialOverride

Added in 1.0.0-alpha05
@MainThread
fun setMaterialOverride(material: Material, meshName: String): Unit

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
material: Material

The material to use for the mesh.

meshName: String

The name of the mesh to use the material for.

startAnimation

Added in 1.0.0-alpha05
@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
kotlin.IllegalArgumentException

if the underlying model doesn't contain any animations.

startAnimation

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

Parameters
loop: Boolean

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

animationName: String

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
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-alpha05
val animationStateInt

The current animation state of the GltfModelEntity.

Returns
Int

The current animation state.