未验证 提交 607cb747 编写于 作者: M Michael Herzog 提交者: GitHub

Merge pull request #16760 from Mugen87/dev33

JSM: Added module and TS files for MMD helper classes.
......@@ -80,6 +80,8 @@
<ul>
<li>AnimationClipCreator</li>
<li>CCDIKSolver</li>
<li>MMDAnimationHelper</li>
<li>MMDPhysics</li>
<li>TimelinerController</li>
</ul>
</li>
......
......@@ -19,7 +19,7 @@ THREE.MMDAnimationHelper = ( function () {
* @param {Object} params - (optional)
* @param {boolean} params.sync - Whether animation durations of added objects are synched. Default is true.
* @param {Number} params.afterglow - Default is 0.0.
* @param {boolean} params resetPhysicsOnLoop - Default is true.
* @param {boolean} params.resetPhysicsOnLoop - Default is true.
*/
function MMDAnimationHelper( params ) {
......@@ -53,7 +53,7 @@ THREE.MMDAnimationHelper = ( function () {
cameraAnimation: true
};
this.onBeforePhysics = function ( mesh ) {};
this.onBeforePhysics = function ( /* mesh */ ) {};
// experimental
this.sharedPhysics = false;
......@@ -239,7 +239,7 @@ THREE.MMDAnimationHelper = ( function () {
* Enabes/Disables an animation feature.
*
* @param {string} key
* @param {boolean} enebled
* @param {boolean} enabled
* @return {THREE.MMDAnimationHelper}
*/
enable: function ( key, enabled ) {
......@@ -488,7 +488,7 @@ THREE.MMDAnimationHelper = ( function () {
var masterPhysics = this._getMasterPhysics();
if ( masterPhysics !== null ) world = masterPhysics.world;
if ( masterPhysics !== null ) world = masterPhysics.world; // eslint-disable-line no-undef
}
......@@ -945,7 +945,7 @@ THREE.MMDAnimationHelper = ( function () {
}
if ( this.currentTime < this.delayTime ) return false;
// 'duration' can be bigger than 'audioDuration + delayTime' because of sync configuration
if ( ( this.currentTime - this.delayTime ) > this.audioDuration ) return false;
......
......@@ -11,6 +11,8 @@
* - Physics in Worker
*/
/* global Ammo */
THREE.MMDPhysics = ( function () {
/**
......@@ -137,7 +139,7 @@ THREE.MMDPhysics = ( function () {
*/
reset: function () {
for ( var i = 0, il = this.bodies.length; i < il; i++ ) {
for ( var i = 0, il = this.bodies.length; i < il; i ++ ) {
this.bodies[ i ].reset();
......@@ -155,7 +157,7 @@ THREE.MMDPhysics = ( function () {
*/
warmup: function ( cycles ) {
for ( var i = 0; i < cycles; i++ ) {
for ( var i = 0; i < cycles; i ++ ) {
this.update( 1 / 60 );
......@@ -258,7 +260,7 @@ THREE.MMDPhysics = ( function () {
_initRigidBodies: function ( rigidBodies ) {
for ( var i = 0, il = rigidBodies.length; i < il; i++ ) {
for ( var i = 0, il = rigidBodies.length; i < il; i ++ ) {
this.bodies.push( new RigidBody(
this.mesh, this.world, rigidBodies[ i ], this.manager ) );
......@@ -269,7 +271,7 @@ THREE.MMDPhysics = ( function () {
_initConstraints: function ( constraints ) {
for ( var i = 0, il = constraints.length; i < il; i++ ) {
for ( var i = 0, il = constraints.length; i < il; i ++ ) {
var params = constraints[ i ];
var bodyA = this.bodies[ params.rigidBodyIndex1 ];
......@@ -307,7 +309,7 @@ THREE.MMDPhysics = ( function () {
_updateRigidBodies: function () {
for ( var i = 0, il = this.bodies.length; i < il; i++ ) {
for ( var i = 0, il = this.bodies.length; i < il; i ++ ) {
this.bodies[ i ].updateFromBone();
......@@ -317,7 +319,7 @@ THREE.MMDPhysics = ( function () {
_updateBones: function () {
for ( var i = 0, il = this.bodies.length; i < il; i++ ) {
for ( var i = 0, il = this.bodies.length; i < il; i ++ ) {
this.bodies[ i ].updateBone();
......@@ -476,32 +478,32 @@ THREE.MMDPhysics = ( function () {
},
getOrigin: function( t ) {
getOrigin: function ( t ) {
return t.getOrigin();
},
setOrigin: function( t, v ) {
setOrigin: function ( t, v ) {
t.getOrigin().setValue( v.x(), v.y(), v.z() );
},
copyOrigin: function( t1, t2 ) {
copyOrigin: function ( t1, t2 ) {
var o = t2.getOrigin();
this.setOrigin( t1, o );
},
setBasis: function( t, q ) {
setBasis: function ( t, q ) {
t.setRotation( q );
},
setBasisFromMatrix3: function( t, m ) {
setBasisFromMatrix3: function ( t, m ) {
var q = this.matrix3ToQuaternion( m );
this.setBasis( t, q );
......@@ -626,7 +628,7 @@ THREE.MMDPhysics = ( function () {
},
addVector3: function( v1, v2 ) {
addVector3: function ( v1, v2 ) {
var v = this.allocVector3();
v.setValue( v1.x() + v2.x(), v1.y() + v2.y(), v1.z() + v2.z() );
......@@ -634,13 +636,13 @@ THREE.MMDPhysics = ( function () {
},
dotVectors3: function( v1, v2 ) {
dotVectors3: function ( v1, v2 ) {
return v1.x() * v2.x() + v1.y() * v2.y() + v1.z() * v2.z();
},
rowOfMatrix3: function( m, i ) {
rowOfMatrix3: function ( m, i ) {
var v = this.allocVector3();
v.setValue( m[ i * 3 + 0 ], m[ i * 3 + 1 ], m[ i * 3 + 2 ] );
......@@ -648,7 +650,7 @@ THREE.MMDPhysics = ( function () {
},
columnOfMatrix3: function( m, i ) {
columnOfMatrix3: function ( m, i ) {
var v = this.allocVector3();
v.setValue( m[ i + 0 ], m[ i + 3 ], m[ i + 6 ] );
......@@ -656,10 +658,10 @@ THREE.MMDPhysics = ( function () {
},
negativeVector3: function( v ) {
negativeVector3: function ( v ) {
var v2 = this.allocVector3();
v2.setValue( -v.x(), -v.y(), -v.z() );
v2.setValue( - v.x(), - v.y(), - v.z() );
return v2;
},
......@@ -685,7 +687,7 @@ THREE.MMDPhysics = ( function () {
},
transposeMatrix3: function( m ) {
transposeMatrix3: function ( m ) {
var m2 = [];
m2[ 0 ] = m[ 0 ];
......@@ -736,12 +738,12 @@ THREE.MMDPhysics = ( function () {
},
matrix3ToQuaternion: function( m ) {
matrix3ToQuaternion: function ( m ) {
var t = m[ 0 ] + m[ 4 ] + m[ 8 ];
var s, x, y, z, w;
if( t > 0 ) {
if ( t > 0 ) {
s = Math.sqrt( t + 1.0 ) * 2;
w = 0.25 * s;
......@@ -749,7 +751,7 @@ THREE.MMDPhysics = ( function () {
y = ( m[ 2 ] - m[ 6 ] ) / s;
z = ( m[ 3 ] - m[ 1 ] ) / s;
} else if( ( m[ 0 ] > m[ 4 ] ) && ( m[ 0 ] > m[ 8 ] ) ) {
} else if ( ( m[ 0 ] > m[ 4 ] ) && ( m[ 0 ] > m[ 8 ] ) ) {
s = Math.sqrt( 1.0 + m[ 0 ] - m[ 4 ] - m[ 8 ] ) * 2;
w = ( m[ 7 ] - m[ 5 ] ) / s;
......@@ -757,7 +759,7 @@ THREE.MMDPhysics = ( function () {
y = ( m[ 1 ] + m[ 3 ] ) / s;
z = ( m[ 2 ] + m[ 6 ] ) / s;
} else if( m[ 4 ] > m[ 8 ] ) {
} else if ( m[ 4 ] > m[ 8 ] ) {
s = Math.sqrt( 1.0 + m[ 4 ] - m[ 0 ] - m[ 8 ] ) * 2;
w = ( m[ 2 ] - m[ 6 ] ) / s;
......@@ -794,7 +796,7 @@ THREE.MMDPhysics = ( function () {
*/
function RigidBody( mesh, world, params, manager ) {
this.mesh = mesh;
this.mesh = mesh;
this.world = world;
this.params = params;
this.manager = manager;
......@@ -882,7 +884,7 @@ THREE.MMDPhysics = ( function () {
function generateShape( p ) {
switch( p.shapeType ) {
switch ( p.shapeType ) {
case 0:
return new Ammo.btSphereShape( p.width );
......@@ -912,7 +914,7 @@ THREE.MMDPhysics = ( function () {
var localInertia = manager.allocVector3();
localInertia.setValue( 0, 0, 0 );
if( weight !== 0 ) {
if ( weight !== 0 ) {
shape.calculateLocalInertia( weight, localInertia );
......@@ -1103,7 +1105,7 @@ THREE.MMDPhysics = ( function () {
*/
function Constraint( mesh, world, bodyA, bodyB, params, manager ) {
this.mesh = mesh;
this.mesh = mesh;
this.world = world;
this.bodyA = bodyA;
this.bodyB = bodyB;
......@@ -1171,9 +1173,9 @@ THREE.MMDPhysics = ( function () {
constraint.setAngularLowerLimit( all );
constraint.setAngularUpperLimit( aul );
for ( var i = 0; i < 3; i++ ) {
for ( var i = 0; i < 3; i ++ ) {
if( params.springPosition[ i ] !== 0 ) {
if ( params.springPosition[ i ] !== 0 ) {
constraint.enableSpring( i, true );
constraint.setStiffness( i, params.springPosition[ i ] );
......@@ -1182,9 +1184,9 @@ THREE.MMDPhysics = ( function () {
}
for ( var i = 0; i < 3; i++ ) {
for ( var i = 0; i < 3; i ++ ) {
if( params.springRotation[ i ] !== 0 ) {
if ( params.springRotation[ i ] !== 0 ) {
constraint.enableSpring( i + 3, true );
constraint.setStiffness( i + 3, params.springRotation[ i ] );
......
import {
AnimationClip,
Audio,
Camera,
Mesh,
Object3D,
SkinnedMesh
} from '../../../src/Three';
export interface MMDAnimationHelperParameter {
sync?: boolean;
afterglow?: number;
resetPhysicsOnLoop?: boolean;
}
export interface MMDAnimationHelperAddParameter {
animation?: AnimationClip | AnimationClip[];
physics?: boolean;
warmup?: number;
unitStep?: number;
maxStepNum?: number;
gravity?: number;
delayTime?: number;
}
export interface MMDAnimationHelperPoseParameter {
resetPose?: boolean;
ik?: boolean;
grant?: boolean;
}
export class MMDAnimationHelper {
constructor(params?: MMDAnimationHelperParameter);
meshes: Mesh[];
camera: Camera | null;
cameraTarget: Object3D;
audio: Audio;
audioManager: AudioManager;
configuration: {
sync: boolean;
afterglow: number;
resetPhysicsOnLoop: boolean;
};
enabled: {
animation: boolean;
ik: boolean;
grant: boolean;
physics: boolean;
cameraAnimation: boolean;
};
onBeforePhysics: (mesh: SkinnedMesh) => void;
sharedPhysics: boolean;
masterPhysics: null;
add(object: SkinnedMesh | Camera | Audio, params?: MMDAnimationHelperAddParameter): this;
remove(object: SkinnedMesh | Camera | Audio): this;
update(delta: number): this;
pose(mesh: SkinnedMesh, vpd: object, params?: MMDAnimationHelperPoseParameter): this;
enable(key: string, enabled: boolean): this;
createGrantSolver(mesh: SkinnedMesh): GrantSolver;
}
export interface AudioManagerParameter {
delayTime?: number;
}
export class AudioManager {
constructor(audio: Audio, params?: AudioManagerParameter);
audio: Audio;
elapsedTime: number;
currentTime: number;
delayTime: number;
audioDuration: number;
duration: number;
control(delta: number): this;
}
export class GrantSolver {
constructor(mesh: SkinnedMesh, grants: object[]);
mesh: SkinnedMesh;
grants: object[];
update(): this;
}
此差异已折叠。
import {
Bone,
Euler,
Matrix4,
Object3D,
Quaternion,
SkinnedMesh,
Vector3
} from '../../../src/Three';
export interface MMDPhysicsParameter {
unitStep?: number;
maxStepNum?: number;
gravity?: Vector3;
}
export class MMDPhysics {
constructor(mesh: SkinnedMesh, rigidBodyParams: object[], constraintParams?: object[], params?: MMDPhysicsParameter);
manager: ResourceManager;
mesh: SkinnedMesh;
unitStep: number;
maxStepNum: number;
gravity: Vector3;
world: null;
bodies: RigidBody[];
constraints: Constraint[];
update(delta: number): this;
reset(): this;
warmup(cycles: number): this;
setGravity(gravity: Vector3): this;
createHelper(): MMDPhysicsHelper;
}
export class ResourceManager{
constructor();
threeVector3s: Vector3[];
threeMatrix4s: Matrix4[];
threeQuaternions: Quaternion[];
threeEulers: Euler[];
transforms: object[];
quaternions: object[];
vector3s: object[];
allocThreeVector3(): void;
freeThreeVector3(v: Vector3): void;
allocThreeMatrix4(): void;
freeThreeMatrix4(m: Matrix4): void;
allocThreeQuaternion(): void;
freeThreeQuaternion(q: Quaternion): void;
allocThreeEuler(): void;
freeThreeEuler(e: Euler): void;
allocTransform(): void;
freeTransform(t: object): void;
allocQuaternion(): void;
freeQuaternion(q: object): void;
allocVector3(): void;
freeVector3(v: object): void;
setIdentity(): void;
getBasis(t: object): object;
getBasisAsMatrix3(t: object): object;
getOrigin(t: object): object;
setOrigin(t: object, v: object): void;
copyOrigin(t1: object, t2: object): void;
setBasis(t: object, q: object): void;
setBasisFromMatrix3(t: object, m: object): void;
setOriginFromArray3(t: object, a: number[]): void;
setOriginFromThreeVector3(t: object, v: Vector3): void;
setBasisFromArray3(t: object, a: number[]): void;
setBasisFromThreeQuaternion(t: object, a: Quaternion): void;
multiplyTransforms(t1: object, t2: object): object;
inverseTransform(t: object): object;
multiplyMatrices3(m1: object, m2: object): object;
addVector3(v1: object, v2: object): object;
dotVectors3(v1: object, v2: object): number;
rowOfMatrix3(m: object, i: number): object;
columnOfMatrix3(m: object, i: number): object;
negativeVector3(v: object): object;
multiplyMatrix3ByVector3(m: object, v: object): object;
transposeMatrix3(m: object): object;
quaternionToMatrix3(q: object): object;
matrix3ToQuaternion(m: object): object;
}
export class RigidBody{
constructor(mesh: SkinnedMesh, world: object, params: object, manager: ResourceManager);
mesh: SkinnedMesh;
world: object;
params: object;
manager: ResourceManager;
body: object;
bone: Bone;
boneOffsetForm: object;
boneOffsetFormInverse: object;
reset(): this;
updateFromBone(): this;
updateBone(): this;
}
export class Constraint{
constructor(mesh: SkinnedMesh, world: object, bodyA: RigidBody, bodyB: RigidBody, params: object, manager: ResourceManager);
}
export class MMDPhysicsHelper extends Object3D {
constructor();
}
此差异已折叠。
......@@ -12,6 +12,8 @@ var dstFolder = __dirname + '/../examples/jsm/';
var files = [
{ path: 'animation/AnimationClipCreator.js', dependencies: [], ignoreList: [] },
{ path: 'animation/CCDIKSolver.js', dependencies: [], ignoreList: [ 'SkinnedMesh' ] },
{ path: 'animation/MMDAnimationHelper.js', dependencies: [ { name: 'CCDIKSolver', path: 'animation/CCDIKSolver.js' }, { name: 'MMDPhysics', path: 'animation/MMDPhysics.js' } ], ignoreList: [ 'AnimationClip', 'Audio', 'Camera', 'SkinnedMesh' ] },
{ path: 'animation/MMDPhysics.js', dependencies: [], ignoreList: [ 'SkinnedMesh' ] },
{ path: 'animation/TimelinerController.js', dependencies: [], ignoreList: [] },
{ path: 'cameras/CinematicCamera.js', dependencies: [ { name: 'BokehShader', path: 'shaders/BokehShader2.js' }, { name: 'BokehDepthShader', path: 'shaders/BokehShader2.js' } ], ignoreList: [] },
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册