Skip to content

⬅️ Back to Table of Contents

📄 MorphAnimMesh.js

📊 Analysis Summary

Metric Count
🔧 Functions 5
🧱 Classes 1
📦 Imports 3

📚 Table of Contents

🛠️ File Location:

📂 examples/jsm/misc/MorphAnimMesh.js

📦 Imports

Name Source
AnimationClip three
AnimationMixer three
Mesh three

Functions

MorphAnimMesh.setDirectionForward(): void

JSDoc:

/**
     * Sets the animation playback direction to "forward".
     */

Returns: void

Code
setDirectionForward() {

        this.mixer.timeScale = 1.0;

    }

MorphAnimMesh.setDirectionBackward(): void

JSDoc:

/**
     * Sets the animation playback direction to "backward".
     */

Returns: void

Code
setDirectionBackward() {

        this.mixer.timeScale = - 1.0;

    }

MorphAnimMesh.playAnimation(label: string, fps: number): void

JSDoc:

/**
     * Plays the defined animation clip. The implementation assumes the animation
     * clips are stored in {@link Object3D#animations} or the geometry.
     *
     * @param {string} label - The name of the animation clip.
     * @param {number} fps - The FPS of the animation clip.
     */

Parameters:

  • label string
  • fps number

Returns: void

Calls:

  • this.activeAction.stop
  • AnimationClip.findByName
  • this.mixer.clipAction
  • action.play
Code
playAnimation( label, fps ) {

        if ( this.activeAction ) {

            this.activeAction.stop();
            this.activeAction = null;

        }

        const clip = AnimationClip.findByName( this, label );

        if ( clip ) {

            const action = this.mixer.clipAction( clip );
            action.timeScale = ( clip.tracks.length * fps ) / clip.duration;
            this.activeAction = action.play();

        } else {

            throw new Error( 'THREE.MorphAnimMesh: animations[' + label + '] undefined in .playAnimation()' );

        }

    }

MorphAnimMesh.updateAnimation(delta: number): void

JSDoc:

/**
     * Updates the animations of the mesh. Must be called inside the animation loop.
     *
     * @param {number} delta - The delta time in seconds.
     */

Parameters:

  • delta number

Returns: void

Calls:

  • this.mixer.update
Code
updateAnimation( delta ) {

        this.mixer.update( delta );

    }

MorphAnimMesh.copy(source: any, recursive: any): this

Parameters:

  • source any
  • recursive any

Returns: this

Calls:

  • super.copy
Code
copy( source, recursive ) {

        super.copy( source, recursive );

        this.mixer = new AnimationMixer( this );

        return this;

    }

Classes

MorphAnimMesh

Class Code
class MorphAnimMesh extends Mesh {

    /**
     * Constructs a new morph anim mesh.
     *
     * @param {BufferGeometry} [geometry] - The mesh geometry.
     * @param {Material|Array<Material>} [material] - The mesh material.
     */
    constructor( geometry, material ) {

        super( geometry, material );

        this.type = 'MorphAnimMesh';

        /**
         * The internal animation mixer.
         *
         * @type {AnimationMixer}
         */
        this.mixer = new AnimationMixer( this );

        /**
         * The current active animation action.
         *
         * @type {?AnimationAction}
         * @default null
         */
        this.activeAction = null;

    }

    /**
     * Sets the animation playback direction to "forward".
     */
    setDirectionForward() {

        this.mixer.timeScale = 1.0;

    }

    /**
     * Sets the animation playback direction to "backward".
     */
    setDirectionBackward() {

        this.mixer.timeScale = - 1.0;

    }

    /**
     * Plays the defined animation clip. The implementation assumes the animation
     * clips are stored in {@link Object3D#animations} or the geometry.
     *
     * @param {string} label - The name of the animation clip.
     * @param {number} fps - The FPS of the animation clip.
     */
    playAnimation( label, fps ) {

        if ( this.activeAction ) {

            this.activeAction.stop();
            this.activeAction = null;

        }

        const clip = AnimationClip.findByName( this, label );

        if ( clip ) {

            const action = this.mixer.clipAction( clip );
            action.timeScale = ( clip.tracks.length * fps ) / clip.duration;
            this.activeAction = action.play();

        } else {

            throw new Error( 'THREE.MorphAnimMesh: animations[' + label + '] undefined in .playAnimation()' );

        }

    }

    /**
     * Updates the animations of the mesh. Must be called inside the animation loop.
     *
     * @param {number} delta - The delta time in seconds.
     */
    updateAnimation( delta ) {

        this.mixer.update( delta );

    }

    copy( source, recursive ) {

        super.copy( source, recursive );

        this.mixer = new AnimationMixer( this );

        return this;

    }

}

Methods

setDirectionForward(): void
Code
setDirectionForward() {

        this.mixer.timeScale = 1.0;

    }
setDirectionBackward(): void
Code
setDirectionBackward() {

        this.mixer.timeScale = - 1.0;

    }
playAnimation(label: string, fps: number): void
Code
playAnimation( label, fps ) {

        if ( this.activeAction ) {

            this.activeAction.stop();
            this.activeAction = null;

        }

        const clip = AnimationClip.findByName( this, label );

        if ( clip ) {

            const action = this.mixer.clipAction( clip );
            action.timeScale = ( clip.tracks.length * fps ) / clip.duration;
            this.activeAction = action.play();

        } else {

            throw new Error( 'THREE.MorphAnimMesh: animations[' + label + '] undefined in .playAnimation()' );

        }

    }
updateAnimation(delta: number): void
Code
updateAnimation( delta ) {

        this.mixer.update( delta );

    }
copy(source: any, recursive: any): this
Code
copy( source, recursive ) {

        super.copy( source, recursive );

        this.mixer = new AnimationMixer( this );

        return this;

    }