MMDAnimationHelper

优质
小牛编辑
140浏览
2023-12-01

A animation helper for MMD resources.

MMDAnimationHelper handles animation of MMD assets loaded by MMDLoader with MMD special features as IK, Grant, and Physics. It uses CCDIKSolver and MMDPhysics inside.

代码示例

// Instantiate a helper
const helper = new MMDAnimationHelper();
// Load MMD resources and add to helper
new MMDLoader().loadWithAnimation(
  'models/mmd/miku.pmd',
  'models/mmd/dance.vmd',
  function ( mmd ) {
    helper.add( mmd.mesh, {
      animation: mmd.animation,
      physics: true
    } );
    scene.add( mmd.mesh );
    new THREE.AudioLoader().load(
      'audios/mmd/song.mp3',
      function ( buffer ) {
        const listener = new THREE.AudioListener();
        const audio = new THREE.Audio( listener ).setBuffer( buffer );
        listener.position.z = 1;
        scene.add( audio );
        scene.add( listener );
      }
    );
  }
);
function render() {
  helper.update( clock.getDelta() );
  renderer.render( scene, camera );
}

例子

webgl_loader_mmd
webgl_loader_mmd_pose
webgl_loader_mmd_audio

Constructor

MMDAnimationHelper( params : Object )

params — (optional)

  • sync - Whether animation durations of added objects are synched. Default is true.
  • afterglow - Default is 0.0.
  • resetPhysicsOnLoop - Default is true.
  • pmxAnimation - If it is set to true, the helper follows the complex and costly PMX animation system. Try this option only if your PMX model animation doesn't work well. Default is false.

Creates a new MMDAnimationHelper.

Properties

.audio : Audio

An Audio added to helper.

.camera : Camera

An Camera added to helper.

.meshes : Array

An array of SkinnedMesh added to helper.

.objects : WeakMap

A WeakMap which holds animation stuffs used in helper for objects added to helper. For example, you can access AnimationMixer for an added SkinnedMesh with "helper.objects.get( mesh ).mixer"

.onBeforePhysics : Function

An optional callback that is executed immediately before the physicis calculation for an SkinnedMesh. This function is called with the SkinnedMesh.

Methods

.add ( object : Object3D, params : Object ) : MMDAnimationHelper

objectSkinnedMesh, Camera, or Audio
params — (optional)

Add an SkinnedMesh, Camera, or Audio to helper and setup animation. The anmation durations of added objects are synched. If camera/audio has already been added, it'll be replaced with a new one.

.enable ( key : String, enabled : Boolean ) : MMDAnimationHelper

key — Allowed strings are 'animation', 'ik', 'grant', 'physics', and 'cameraAnimation'.
enabled — true is enable, false is disable

Enable/Disable an animation feature

.pose ( mesh : SkinnedMesh, vpd : Object, params : Object ) : MMDAnimationHelper

meshSkinnedMesh which changes the posing. It doesn't need to be added to helper.
vpd — VPD content obtained by MMDLoader.loadVPD
params — (optional)

Changes the posing of SkinnedMesh as VPD content specifies.

.remove ( object : Object3D ) : MMDAnimationHelper

objectSkinnedMesh, Camera, or Audio

Remove an SkinnedMesh, Camera, or Audio from helper.

.update ( delta : Nummber ) : MMDAnimationHelper

delta — number in second

Advance mixer time and update the animations of objects added to helper

Source

examples/jsm/animation/MMDAnimationHelper.js