MMDPhysics

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

A Physics handler for MMD resources.

MMDPhysics calculates Physics for model loaded by MMDLoader with ammo.js (Bullet-based JavaScript Physics engine).

代码示例

const physics;
// Load MMD resources and instantiate MMDPhysics
new MMDLoader().load(
  'models/mmd/miku.pmd',
  function ( mesh ) {
    physics = new MMDPhysics( mesh )
    scene.add( mesh );
  }
);
function render() {
  const delta = clock.getDelta();
  animate( delta );  // update bones
  if ( physics !== undefined ) physics.update( delta );
  renderer.render( scene, camera );
}

例子

webgl_loader_mmd
webgl_loader_mmd_audio

Constructor

MMDPhysics( mesh : SkinnedMesh, rigidBodyParams : Array, constraintParams : Array, params : Object )

meshSkinnedMesh for which MMDPhysics calculates Physics.
rigidBodyParams — An array of Object specifying Rigid Body parameters.
constraintParams — (optional) An array of Object specifying Constraint parameters.
params — (optional)

Creates a new MMDPhysics.

Properties

.mesh : Array

SkinnedMesh passed to the constructor.

Methods

.createHelper () : MMDPhysicsHelper

Return MMDPhysicsHelper. You can visualize Rigid bodies by adding the helper to scene.

.reset () : CCDIKSolver

Resets Rigid bodies transorm to current bone's.

.setGravity ( gravity : Vector3 ) : CCDIKSolver

gravity — Direction and volume of gravity.

Set gravity.

.update ( delta : Number ) : CCDIKSolver

delta — Time in second.

Advance Physics calculation and updates bones.

.warmup ( cycles : Integer ) : CCDIKSolver

delta — Time in second.

Warm up Rigid bodies. Calculates cycles steps.

Source

examples/jsm/animation/MMDPhysics.js