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

Public companion functions

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

Public factory function for a GltfModelEntity.

Public functions

Int

Returns the current animation state of this glTF entity.

Unit

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

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

Starts the animation with the given name.

Unit

Stops the animation of the glTF entity.

Inherited functions

From androidx.xr.scenecore.ActivityPose
abstract Pose

Returns the activity space pose for this ActivityPose.

abstract ListenableFuture<HitTestResult>
hitTestAsync(origin: Vector3, direction: Vector3)

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

abstract ListenableFuture<HitTestResult>
hitTestAsync(
    origin: Vector3,
    direction: Vector3,
    @ActivityPose.HitTestFilterValue hitTestFilter: Int
)

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

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

Returns a pose relative to this ActivityPose transformed into a pose relative to the destination.

From androidx.xr.scenecore.BaseEntity
open Unit
addChild(child: Entity)

Sets an Entity to be represented in this coordinate space.

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: Int)

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 Entity?

Returns the parent of this Entity.

open Pose
getPose(relativeTo: Int)

Returns the pose for this entity, relative to the provided space.

open Float
getScale(relativeTo: Int)

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

open Boolean
isHidden(includeParents: Boolean)

Returns the hidden 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, relativeTo: Int)

Sets the alpha transparency of the Entity relative to given space.

open Unit

Sets alternate text for this entity to be consumed by Accessibility systems.

open Unit
setHidden(hidden: Boolean)

Sets the local hidden state of this Entity.

open Unit
setParent(parent: Entity?)

Sets this Entity to be represented in the parent's coordinate space.

open Unit
setPose(pose: Pose, relativeTo: Int)

Sets the pose for this Entity.

open Unit
setScale(scale: Float, relativeTo: Int)

Sets the scale of this entity relative to given space.

From androidx.xr.scenecore.Entity
open Float

Returns the alpha transparency set for this Entity.

open Pose

Returns the pose for this entity, relative to its parent.

open Float

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

open Unit
setAlpha(alpha: 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: Float)

Sets the scale of this entity relative to its parent.

Public companion functions

create

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

Returns
GltfModelEntity

a GltfModelEntity instance

Public functions

getAnimationState

Added in 1.0.0-alpha04
fun getAnimationState(): Int

Returns the current animation state of this glTF entity.

setMaterialOverride

Added in 1.0.0-alpha04
@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-alpha04
@MainThread
fun startAnimation(loop: Boolean, animationName: String? = null): Unit

Starts the animation with the given name.

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.

animationName: String? = null

The name of the animation to start. If null, the first animation found in the glTF will be played.

stopAnimation

Added in 1.0.0-alpha04
@MainThread
fun stopAnimation(): Unit

Stops the animation of the glTF entity.

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