Skip to content

Commit

Permalink
MMDLoader enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
takahirox committed Nov 27, 2015
1 parent bca0bc9 commit 9e9db10
Show file tree
Hide file tree
Showing 39 changed files with 8,172 additions and 619 deletions.
2 changes: 2 additions & 0 deletions examples/index.html
Expand Up @@ -270,6 +270,8 @@ <h1><a href="http://threejs.org">three.js</a> / examples</h1>
"webgl_loader_md2",
"webgl_loader_md2_control",
"webgl_loader_mmd",
"webgl_loader_mmd_pose",
"webgl_loader_mmd_audio",
"webgl_loader_msgpack",
"webgl_loader_obj",
"webgl_loader_obj_mtl",
Expand Down
24 changes: 19 additions & 5 deletions examples/js/animation/MMDPhysics.js
Expand Up @@ -16,11 +16,20 @@
* - if possible, make this class being non-MMD specific.
*/

THREE.MMDPhysics = function ( mesh ) {
THREE.MMDPhysics = function ( mesh, params ) {

this.mesh = mesh;
this.helper = new THREE.MMDPhysics.PhysicsHelper();

/*
* Note: Default 1 / 65 unit step is a workaround that
* some bones go wrong at near 60fps if it's 1 / 60.
* Be careful that small unitStep could cause heavy
* physics calculation.
*/
this.unitStep = ( params && params.unitStep ) ? params.unitStep : 1 / 65;
this.maxStepNum = ( params && params.maxStepNum ) ? params.maxStepNum : 3;

this.world = null;
this.bodies = [];
this.constraints = [];
Expand Down Expand Up @@ -86,13 +95,13 @@ THREE.MMDPhysics.prototype = {

update: function ( delta ) {

var unitStep = 1 / 60;
var unitStep = this.unitStep;
var stepTime = delta;
var maxStepNum = ( ( delta / unitStep ) | 0 ) + 1;

if ( maxStepNum > 3 ) {
if ( maxStepNum > this.maxStepNum ) {

maxStepNum = 3;
maxStepNum = this.maxStepNum;

}

Expand Down Expand Up @@ -790,16 +799,21 @@ THREE.MMDPhysics.RigidBody.prototype = {

var thQ = helper.allocThreeQuaternion();
var thQ2 = helper.allocThreeQuaternion();
var thQ3 = helper.allocThreeQuaternion();

thQ.set( q.x(), q.y(), q.z(), q.w() );
thQ2.setFromRotationMatrix( this.bone.matrixWorld );
thQ2.conjugate()
thQ2.multiply( thQ );

this.bone.quaternion.multiply( thQ2 );
//this.bone.quaternion.multiply( thQ2 );

thQ3.setFromRotationMatrix( this.bone.matrix );
this.bone.quaternion.copy( thQ2.multiply( thQ3 ) );

helper.freeThreeQuaternion( thQ );
helper.freeThreeQuaternion( thQ2 );
helper.freeThreeQuaternion( thQ3 );

helper.freeQuaternion( q );
helper.freeTransform( tr );
Expand Down

0 comments on commit 9e9db10

Please sign in to comment.