GLTFModelDesc
The GLTFModelDesc class is a mesh descriptor for loading and displaying GLTF/GLB format 3D models. It provides features such as animation playback, shadow settings, and dynamic updates.
In addition to the properties below, all common properties from the base class (position, rotation, scale, matrix, matrixWorld, pickable, visible) are available. See MeshDesc for details.
Properties
Section titled “Properties”Type: string
Description: Specifies the URL of the GLTF/GLB file to load. This is a required parameter.
Example:
{ gltfModel: { url: "https://example.com/models/character.glb", }}castShadow
Section titled “castShadow”Type: boolean
Description: Specifies whether the model casts shadows.
Default: false
Example:
{ gltfModel: { castShadow: true, }}receiveShadow
Section titled “receiveShadow”Type: boolean
Description: Specifies whether the model receives shadows.
Default: false
Example:
{ gltfModel: { receiveShadow: true, }}animationEnabled
Section titled “animationEnabled”Type: boolean
Description: Specifies whether to enable animation.
Example:
{ gltfModel: { animationEnabled: true, }}animationClips
Section titled “animationClips”Type: string[]
Description: Specifies the list of available animation clip names. Used as read-only information.
Example:
{ gltfModel: { animationClips: ["Walk", "Run", "Jump"], }}animationActiveClip
Section titled “animationActiveClip”Type: string
Description: Specifies the currently active animation clip name.
Example:
{ gltfModel: { animationActiveClip: "Walk", }}animationSpeed
Section titled “animationSpeed”Type: number
Description: Specifies the animation playback speed. 1.0 is normal speed.
Default: 1.0
Example:
{ gltfModel: { animationSpeed: 1.5, // 1.5x speed }}animationLoop
Section titled “animationLoop”Type: boolean
Description: Specifies whether to loop the animation playback.
Default: true
Example:
{ gltfModel: { animationLoop: true, }}animationCrossfadeDuration
Section titled “animationCrossfadeDuration”Type: number
Description: Specifies the crossfade duration in seconds when switching animations.
Default: 0.3
Example:
{ gltfModel: { animationCrossfadeDuration: 0.5, // 0.5 seconds }}animationAutoPlay
Section titled “animationAutoPlay”Type: boolean
Description: Specifies whether to automatically play the animation after the model is loaded.
Default: false
Example:
{ gltfModel: { animationAutoPlay: true, }}Methods
Section titled “Methods”getAnimationAvailable()
Section titled “getAnimationAvailable()”Description: Gets an array of available animation clip names.
Returns:
An array of available animation clip names
Example:
const clips = modelDesc.ref.getAnimationAvailable();console.log(clips); // ["Walk", "Run", "Jump"]getAnimationDetails(name?: string)
Section titled “getAnimationDetails(name?: string)”Description: Gets detailed information about animations. If a name is specified, returns details for that specific animation; otherwise, returns details for all animations.
Parameters:
name: A specific animation name
Returns:
Animation detail information
Example:
const details = modelDesc.ref.getAnimationDetails("Walk");console.log(details);// { name: "Walk", duration: 2.5, tracks: 45, isLooping: true, timeScale: 1.0 }getAnimationCurrentState()
Section titled “getAnimationCurrentState()”Description: Gets the current animation playback state.
Returns:
The current animation playback state
Example:
const state = modelDesc.ref.getAnimationCurrentState();console.log(state);// {// isPlaying: true,// currentAnimation: "Walk",// isBlendMode: false,// blendAnimations: [],// playbackTime: 1.23,// progress: 0.492// }playAnimation(name: string)
Section titled “playAnimation(name: string)”Description: Plays the specified animation. Returns true if successful.
Parameters:
name: The animation clip name to play
Returns:
true if successful
Example:
modelDesc.ref.playAnimation("Run");crossFadeAnimation(from: string, to: string, duration: number)
Section titled “crossFadeAnimation(from: string, to: string, duration: number)”Description: Performs a crossfade between two animations.
Parameters:
from: The source animation clip nameto: The target animation clip nameduration: The crossfade duration (seconds)
Returns:
true if successful
Example:
modelDesc.ref.crossFadeAnimation("Walk", "Run", 0.5);blendAnimations(animations: { name: string, weight: number }[])
Section titled “blendAnimations(animations: { name: string, weight: number }[])”Description: Blends and plays multiple animations simultaneously.
Parameters:
animations: An array of animation names and weights
Example:
modelDesc.ref.blendAnimations([ { name: "Walk", weight: 0.7 }, { name: "Run", weight: 0.3 }]);stopAnimation()
Section titled “stopAnimation()”Description: Stops the currently playing animation.
Example:
modelDesc.ref.stopAnimation();pauseAnimation()
Section titled “pauseAnimation()”Description: Pauses the currently playing animation.
Example:
modelDesc.ref.pauseAnimation();resumeAnimation()
Section titled “resumeAnimation()”Description: Resumes a paused animation.
Example:
modelDesc.ref.resumeAnimation();setAnimationSpeed(speed: number)
Section titled “setAnimationSpeed(speed: number)”Description: Sets the animation playback speed.
Parameters:
speed: Animation speed (1.0 is normal speed)
Example:
modelDesc.ref.setAnimationSpeed(2.0); // 2x speedsetAnimationLoop(loop: boolean)
Section titled “setAnimationLoop(loop: boolean)”Description: Changes the animation loop setting.
Parameters:
loop: Enable/disable loop playback
Example:
modelDesc.ref.setAnimationLoop(false);setAnimationWeight(name: string, weight: number)
Section titled “setAnimationWeight(name: string, weight: number)”Description: Sets the weight of a specific animation.
Parameters:
name: The animation clip nameweight: Weight (0.0-1.0)
Example:
modelDesc.ref.setAnimationWeight("Walk", 0.5);Events
Section titled “Events”Description: Fired when the model loading is complete.
Example:
modelDesc.ref.on("load", () => { console.log("Model loaded!");});animationReady
Section titled “animationReady”Description: Fired when animation initialization is complete.
Example:
modelDesc.ref.on("animationReady", () => { console.log("Animations ready!"); const clips = modelDesc.ref.getAnimationAvailable(); console.log("Available clips:", clips);});Usage Examples
Section titled “Usage Examples”Basic Usage
Section titled “Basic Usage”import ThreeView from "@navaramap/three";import { GLTFModelDesc } from "@navaramap/three_default_descs";
const view = new ThreeView();view.registerMesh("gltfModel", GLTFModelDesc);await view.init();
// Add a GLTFModelDescconst modelDesc = view.addMesh<GLTFModelDesc>({ gltfModel: { url: "https://example.com/models/character.glb", castShadow: true, receiveShadow: true, }, position: { x: 0, y: 0, z: 0 },});Animated Model
Section titled “Animated Model”const animatedModel = view.addMesh<GLTFModelDesc>({ gltfModel: { url: "https://example.com/models/animated.glb", castShadow: true, receiveShadow: true, animationEnabled: true, animationActiveClip: "Idle", animationSpeed: 1.0, animationLoop: true, animationAutoPlay: true, },});
// Switch animation after model loadsanimatedModel.ref.on("animationReady", () => { setTimeout(() => { animatedModel.ref.crossFadeAnimation("Idle", "Walk", 0.5); }, 2000);});Blending Multiple Animations
Section titled “Blending Multiple Animations”const blendedModel = view.addMesh<GLTFModelDesc>({ gltfModel: { url: "https://example.com/models/character.glb", animationEnabled: true, },});
blendedModel.ref.on("animationReady", () => { // Blend walk and run blendedModel.ref.blendAnimations([ { name: "Walk", weight: 0.6 }, { name: "Run", weight: 0.4 }, ]);});Dynamic Model Update
Section titled “Dynamic Model Update”// Change the URL to reload the modelmodelDesc.update({ gltfModel: { url: "https://example.com/models/new-model.glb", },});
// Change the animation speedmodelDesc.update({ gltfModel: { animationSpeed: 2.0, },});