Skip to content

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.

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",
}
}

Type: boolean

Description: Specifies whether the model casts shadows.

Default: false

Example:

{
gltfModel: {
castShadow: true,
}
}

Type: boolean

Description: Specifies whether the model receives shadows.

Default: false

Example:

{
gltfModel: {
receiveShadow: true,
}
}

Type: boolean

Description: Specifies whether to enable animation.

Example:

{
gltfModel: {
animationEnabled: true,
}
}

Type: string[]

Description: Specifies the list of available animation clip names. Used as read-only information.

Example:

{
gltfModel: {
animationClips: ["Walk", "Run", "Jump"],
}
}

Type: string

Description: Specifies the currently active animation clip name.

Example:

{
gltfModel: {
animationActiveClip: "Walk",
}
}

Type: number

Description: Specifies the animation playback speed. 1.0 is normal speed.

Default: 1.0

Example:

{
gltfModel: {
animationSpeed: 1.5, // 1.5x speed
}
}

Type: boolean

Description: Specifies whether to loop the animation playback.

Default: true

Example:

{
gltfModel: {
animationLoop: true,
}
}

Type: number

Description: Specifies the crossfade duration in seconds when switching animations.

Default: 0.3

Example:

{
gltfModel: {
animationCrossfadeDuration: 0.5, // 0.5 seconds
}
}

Type: boolean

Description: Specifies whether to automatically play the animation after the model is loaded.

Default: false

Example:

{
gltfModel: {
animationAutoPlay: true,
}
}

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"]

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 }

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
// }

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 name
  • to: The target animation clip name
  • duration: 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 }
]);

Description: Stops the currently playing animation.

Example:

modelDesc.ref.stopAnimation();

Description: Pauses the currently playing animation.

Example:

modelDesc.ref.pauseAnimation();

Description: Resumes a paused animation.

Example:

modelDesc.ref.resumeAnimation();

Description: Sets the animation playback speed.

Parameters:

  • speed: Animation speed (1.0 is normal speed)

Example:

modelDesc.ref.setAnimationSpeed(2.0); // 2x speed

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 name
  • weight: Weight (0.0-1.0)

Example:

modelDesc.ref.setAnimationWeight("Walk", 0.5);

Description: Fired when the model loading is complete.

Example:

modelDesc.ref.on("load", () => {
console.log("Model loaded!");
});

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);
});
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 GLTFModelDesc
const modelDesc = view.addMesh<GLTFModelDesc>({
gltfModel: {
url: "https://example.com/models/character.glb",
castShadow: true,
receiveShadow: true,
},
position: { x: 0, y: 0, z: 0 },
});
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 loads
animatedModel.ref.on("animationReady", () => {
setTimeout(() => {
animatedModel.ref.crossFadeAnimation("Idle", "Walk", 0.5);
}, 2000);
});
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 },
]);
});
// Change the URL to reload the model
modelDesc.update({
gltfModel: {
url: "https://example.com/models/new-model.glb",
},
});
// Change the animation speed
modelDesc.update({
gltfModel: {
animationSpeed: 2.0,
},
});