Skip to content

Commit 607cb74

Browse files
authored
Merge pull request mrdoob#16760 from Mugen87/dev33
JSM: Added module and TS files for MMD helper classes.
2 parents 778e227 + 601470c commit 607cb74

File tree

8 files changed

+2715
-35
lines changed

8 files changed

+2715
-35
lines changed

docs/manual/en/introduction/Import-via-modules.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ <h2>Importable Examples</h2>
8080
<ul>
8181
<li>AnimationClipCreator</li>
8282
<li>CCDIKSolver</li>
83+
<li>MMDAnimationHelper</li>
84+
<li>MMDPhysics</li>
8385
<li>TimelinerController</li>
8486
</ul>
8587
</li>

examples/js/animation/MMDAnimationHelper.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ THREE.MMDAnimationHelper = ( function () {
1919
* @param {Object} params - (optional)
2020
* @param {boolean} params.sync - Whether animation durations of added objects are synched. Default is true.
2121
* @param {Number} params.afterglow - Default is 0.0.
22-
* @param {boolean} params resetPhysicsOnLoop - Default is true.
22+
* @param {boolean} params.resetPhysicsOnLoop - Default is true.
2323
*/
2424
function MMDAnimationHelper( params ) {
2525

@@ -53,7 +53,7 @@ THREE.MMDAnimationHelper = ( function () {
5353
cameraAnimation: true
5454
};
5555

56-
this.onBeforePhysics = function ( mesh ) {};
56+
this.onBeforePhysics = function ( /* mesh */ ) {};
5757

5858
// experimental
5959
this.sharedPhysics = false;
@@ -239,7 +239,7 @@ THREE.MMDAnimationHelper = ( function () {
239239
* Enabes/Disables an animation feature.
240240
*
241241
* @param {string} key
242-
* @param {boolean} enebled
242+
* @param {boolean} enabled
243243
* @return {THREE.MMDAnimationHelper}
244244
*/
245245
enable: function ( key, enabled ) {
@@ -488,7 +488,7 @@ THREE.MMDAnimationHelper = ( function () {
488488

489489
var masterPhysics = this._getMasterPhysics();
490490

491-
if ( masterPhysics !== null ) world = masterPhysics.world;
491+
if ( masterPhysics !== null ) world = masterPhysics.world; // eslint-disable-line no-undef
492492

493493
}
494494

@@ -945,7 +945,7 @@ THREE.MMDAnimationHelper = ( function () {
945945
}
946946

947947
if ( this.currentTime < this.delayTime ) return false;
948-
948+
949949
// 'duration' can be bigger than 'audioDuration + delayTime' because of sync configuration
950950
if ( ( this.currentTime - this.delayTime ) > this.audioDuration ) return false;
951951

examples/js/animation/MMDPhysics.js

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
* - Physics in Worker
1212
*/
1313

14+
/* global Ammo */
15+
1416
THREE.MMDPhysics = ( function () {
1517

1618
/**
@@ -137,7 +139,7 @@ THREE.MMDPhysics = ( function () {
137139
*/
138140
reset: function () {
139141

140-
for ( var i = 0, il = this.bodies.length; i < il; i++ ) {
142+
for ( var i = 0, il = this.bodies.length; i < il; i ++ ) {
141143

142144
this.bodies[ i ].reset();
143145

@@ -155,7 +157,7 @@ THREE.MMDPhysics = ( function () {
155157
*/
156158
warmup: function ( cycles ) {
157159

158-
for ( var i = 0; i < cycles; i++ ) {
160+
for ( var i = 0; i < cycles; i ++ ) {
159161

160162
this.update( 1 / 60 );
161163

@@ -258,7 +260,7 @@ THREE.MMDPhysics = ( function () {
258260

259261
_initRigidBodies: function ( rigidBodies ) {
260262

261-
for ( var i = 0, il = rigidBodies.length; i < il; i++ ) {
263+
for ( var i = 0, il = rigidBodies.length; i < il; i ++ ) {
262264

263265
this.bodies.push( new RigidBody(
264266
this.mesh, this.world, rigidBodies[ i ], this.manager ) );
@@ -269,7 +271,7 @@ THREE.MMDPhysics = ( function () {
269271

270272
_initConstraints: function ( constraints ) {
271273

272-
for ( var i = 0, il = constraints.length; i < il; i++ ) {
274+
for ( var i = 0, il = constraints.length; i < il; i ++ ) {
273275

274276
var params = constraints[ i ];
275277
var bodyA = this.bodies[ params.rigidBodyIndex1 ];
@@ -307,7 +309,7 @@ THREE.MMDPhysics = ( function () {
307309

308310
_updateRigidBodies: function () {
309311

310-
for ( var i = 0, il = this.bodies.length; i < il; i++ ) {
312+
for ( var i = 0, il = this.bodies.length; i < il; i ++ ) {
311313

312314
this.bodies[ i ].updateFromBone();
313315

@@ -317,7 +319,7 @@ THREE.MMDPhysics = ( function () {
317319

318320
_updateBones: function () {
319321

320-
for ( var i = 0, il = this.bodies.length; i < il; i++ ) {
322+
for ( var i = 0, il = this.bodies.length; i < il; i ++ ) {
321323

322324
this.bodies[ i ].updateBone();
323325

@@ -476,32 +478,32 @@ THREE.MMDPhysics = ( function () {
476478

477479
},
478480

479-
getOrigin: function( t ) {
481+
getOrigin: function ( t ) {
480482

481483
return t.getOrigin();
482484

483485
},
484486

485-
setOrigin: function( t, v ) {
487+
setOrigin: function ( t, v ) {
486488

487489
t.getOrigin().setValue( v.x(), v.y(), v.z() );
488490

489491
},
490492

491-
copyOrigin: function( t1, t2 ) {
493+
copyOrigin: function ( t1, t2 ) {
492494

493495
var o = t2.getOrigin();
494496
this.setOrigin( t1, o );
495497

496498
},
497499

498-
setBasis: function( t, q ) {
500+
setBasis: function ( t, q ) {
499501

500502
t.setRotation( q );
501503

502504
},
503505

504-
setBasisFromMatrix3: function( t, m ) {
506+
setBasisFromMatrix3: function ( t, m ) {
505507

506508
var q = this.matrix3ToQuaternion( m );
507509
this.setBasis( t, q );
@@ -626,40 +628,40 @@ THREE.MMDPhysics = ( function () {
626628

627629
},
628630

629-
addVector3: function( v1, v2 ) {
631+
addVector3: function ( v1, v2 ) {
630632

631633
var v = this.allocVector3();
632634
v.setValue( v1.x() + v2.x(), v1.y() + v2.y(), v1.z() + v2.z() );
633635
return v;
634636

635637
},
636638

637-
dotVectors3: function( v1, v2 ) {
639+
dotVectors3: function ( v1, v2 ) {
638640

639641
return v1.x() * v2.x() + v1.y() * v2.y() + v1.z() * v2.z();
640642

641643
},
642644

643-
rowOfMatrix3: function( m, i ) {
645+
rowOfMatrix3: function ( m, i ) {
644646

645647
var v = this.allocVector3();
646648
v.setValue( m[ i * 3 + 0 ], m[ i * 3 + 1 ], m[ i * 3 + 2 ] );
647649
return v;
648650

649651
},
650652

651-
columnOfMatrix3: function( m, i ) {
653+
columnOfMatrix3: function ( m, i ) {
652654

653655
var v = this.allocVector3();
654656
v.setValue( m[ i + 0 ], m[ i + 3 ], m[ i + 6 ] );
655657
return v;
656658

657659
},
658660

659-
negativeVector3: function( v ) {
661+
negativeVector3: function ( v ) {
660662

661663
var v2 = this.allocVector3();
662-
v2.setValue( -v.x(), -v.y(), -v.z() );
664+
v2.setValue( - v.x(), - v.y(), - v.z() );
663665
return v2;
664666

665667
},
@@ -685,7 +687,7 @@ THREE.MMDPhysics = ( function () {
685687

686688
},
687689

688-
transposeMatrix3: function( m ) {
690+
transposeMatrix3: function ( m ) {
689691

690692
var m2 = [];
691693
m2[ 0 ] = m[ 0 ];
@@ -736,28 +738,28 @@ THREE.MMDPhysics = ( function () {
736738

737739
},
738740

739-
matrix3ToQuaternion: function( m ) {
741+
matrix3ToQuaternion: function ( m ) {
740742

741743
var t = m[ 0 ] + m[ 4 ] + m[ 8 ];
742744
var s, x, y, z, w;
743745

744-
if( t > 0 ) {
746+
if ( t > 0 ) {
745747

746748
s = Math.sqrt( t + 1.0 ) * 2;
747749
w = 0.25 * s;
748750
x = ( m[ 7 ] - m[ 5 ] ) / s;
749751
y = ( m[ 2 ] - m[ 6 ] ) / s;
750752
z = ( m[ 3 ] - m[ 1 ] ) / s;
751753

752-
} else if( ( m[ 0 ] > m[ 4 ] ) && ( m[ 0 ] > m[ 8 ] ) ) {
754+
} else if ( ( m[ 0 ] > m[ 4 ] ) && ( m[ 0 ] > m[ 8 ] ) ) {
753755

754756
s = Math.sqrt( 1.0 + m[ 0 ] - m[ 4 ] - m[ 8 ] ) * 2;
755757
w = ( m[ 7 ] - m[ 5 ] ) / s;
756758
x = 0.25 * s;
757759
y = ( m[ 1 ] + m[ 3 ] ) / s;
758760
z = ( m[ 2 ] + m[ 6 ] ) / s;
759761

760-
} else if( m[ 4 ] > m[ 8 ] ) {
762+
} else if ( m[ 4 ] > m[ 8 ] ) {
761763

762764
s = Math.sqrt( 1.0 + m[ 4 ] - m[ 0 ] - m[ 8 ] ) * 2;
763765
w = ( m[ 2 ] - m[ 6 ] ) / s;
@@ -794,7 +796,7 @@ THREE.MMDPhysics = ( function () {
794796
*/
795797
function RigidBody( mesh, world, params, manager ) {
796798

797-
this.mesh = mesh;
799+
this.mesh = mesh;
798800
this.world = world;
799801
this.params = params;
800802
this.manager = manager;
@@ -882,7 +884,7 @@ THREE.MMDPhysics = ( function () {
882884

883885
function generateShape( p ) {
884886

885-
switch( p.shapeType ) {
887+
switch ( p.shapeType ) {
886888

887889
case 0:
888890
return new Ammo.btSphereShape( p.width );
@@ -912,7 +914,7 @@ THREE.MMDPhysics = ( function () {
912914
var localInertia = manager.allocVector3();
913915
localInertia.setValue( 0, 0, 0 );
914916

915-
if( weight !== 0 ) {
917+
if ( weight !== 0 ) {
916918

917919
shape.calculateLocalInertia( weight, localInertia );
918920

@@ -1103,7 +1105,7 @@ THREE.MMDPhysics = ( function () {
11031105
*/
11041106
function Constraint( mesh, world, bodyA, bodyB, params, manager ) {
11051107

1106-
this.mesh = mesh;
1108+
this.mesh = mesh;
11071109
this.world = world;
11081110
this.bodyA = bodyA;
11091111
this.bodyB = bodyB;
@@ -1171,9 +1173,9 @@ THREE.MMDPhysics = ( function () {
11711173
constraint.setAngularLowerLimit( all );
11721174
constraint.setAngularUpperLimit( aul );
11731175

1174-
for ( var i = 0; i < 3; i++ ) {
1176+
for ( var i = 0; i < 3; i ++ ) {
11751177

1176-
if( params.springPosition[ i ] !== 0 ) {
1178+
if ( params.springPosition[ i ] !== 0 ) {
11771179

11781180
constraint.enableSpring( i, true );
11791181
constraint.setStiffness( i, params.springPosition[ i ] );
@@ -1182,9 +1184,9 @@ THREE.MMDPhysics = ( function () {
11821184

11831185
}
11841186

1185-
for ( var i = 0; i < 3; i++ ) {
1187+
for ( var i = 0; i < 3; i ++ ) {
11861188

1187-
if( params.springRotation[ i ] !== 0 ) {
1189+
if ( params.springRotation[ i ] !== 0 ) {
11881190

11891191
constraint.enableSpring( i + 3, true );
11901192
constraint.setStiffness( i + 3, params.springRotation[ i ] );
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import {
2+
AnimationClip,
3+
Audio,
4+
Camera,
5+
Mesh,
6+
Object3D,
7+
SkinnedMesh
8+
} from '../../../src/Three';
9+
10+
export interface MMDAnimationHelperParameter {
11+
sync?: boolean;
12+
afterglow?: number;
13+
resetPhysicsOnLoop?: boolean;
14+
}
15+
16+
export interface MMDAnimationHelperAddParameter {
17+
animation?: AnimationClip | AnimationClip[];
18+
physics?: boolean;
19+
warmup?: number;
20+
unitStep?: number;
21+
maxStepNum?: number;
22+
gravity?: number;
23+
delayTime?: number;
24+
}
25+
26+
export interface MMDAnimationHelperPoseParameter {
27+
resetPose?: boolean;
28+
ik?: boolean;
29+
grant?: boolean;
30+
}
31+
32+
export class MMDAnimationHelper {
33+
constructor(params?: MMDAnimationHelperParameter);
34+
meshes: Mesh[];
35+
camera: Camera | null;
36+
cameraTarget: Object3D;
37+
audio: Audio;
38+
audioManager: AudioManager;
39+
configuration: {
40+
sync: boolean;
41+
afterglow: number;
42+
resetPhysicsOnLoop: boolean;
43+
};
44+
enabled: {
45+
animation: boolean;
46+
ik: boolean;
47+
grant: boolean;
48+
physics: boolean;
49+
cameraAnimation: boolean;
50+
};
51+
onBeforePhysics: (mesh: SkinnedMesh) => void;
52+
sharedPhysics: boolean;
53+
masterPhysics: null;
54+
55+
add(object: SkinnedMesh | Camera | Audio, params?: MMDAnimationHelperAddParameter): this;
56+
remove(object: SkinnedMesh | Camera | Audio): this;
57+
update(delta: number): this;
58+
pose(mesh: SkinnedMesh, vpd: object, params?: MMDAnimationHelperPoseParameter): this;
59+
enable(key: string, enabled: boolean): this;
60+
createGrantSolver(mesh: SkinnedMesh): GrantSolver;
61+
}
62+
63+
export interface AudioManagerParameter {
64+
delayTime?: number;
65+
}
66+
67+
export class AudioManager {
68+
constructor(audio: Audio, params?: AudioManagerParameter);
69+
audio: Audio;
70+
elapsedTime: number;
71+
currentTime: number;
72+
delayTime: number;
73+
audioDuration: number;
74+
duration: number;
75+
76+
control(delta: number): this;
77+
}
78+
79+
export class GrantSolver {
80+
constructor(mesh: SkinnedMesh, grants: object[]);
81+
mesh: SkinnedMesh;
82+
grants: object[];
83+
84+
update(): this;
85+
}

0 commit comments

Comments
 (0)