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

Examples: Convert animation to ES6. (#21596)

* Examples: Convert animation to ES6.

* Examples: Clean up.
上级 ceee7dd2
( function () {
var AnimationClipCreator = function () {};
class AnimationClipCreator {
AnimationClipCreator.CreateRotationAnimation = function ( period, axis ) {
static CreateRotationAnimation( period, axis = 'x' ) {
var times = [ 0, period ],
values = [ 0, 360 ];
axis = axis || 'x';
var trackName = '.rotation[' + axis + ']';
var track = new THREE.NumberKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, period, [ track ] );
const times = [ 0, period ],
values = [ 0, 360 ];
const trackName = '.rotation[' + axis + ']';
const track = new THREE.NumberKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, period, [ track ] );
};
}
static CreateScaleAxisAnimation( period, axis = 'x' ) {
const times = [ 0, period ],
values = [ 0, 1 ];
const trackName = '.scale[' + axis + ']';
const track = new THREE.NumberKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, period, [ track ] );
AnimationClipCreator.CreateScaleAxisAnimation = function ( period, axis ) {
}
var times = [ 0, period ],
values = [ 0, 1 ];
axis = axis || 'x';
var trackName = '.scale[' + axis + ']';
var track = new THREE.NumberKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, period, [ track ] );
static CreateShakeAnimation( duration, shakeScale ) {
};
const times = [],
values = [],
tmp = new THREE.Vector3();
AnimationClipCreator.CreateShakeAnimation = function ( duration, shakeScale ) {
for ( let i = 0; i < duration * 10; i ++ ) {
var times = [],
values = [],
tmp = new THREE.Vector3();
times.push( i / 10 );
tmp.set( Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0 ).multiply( shakeScale ).toArray( values, values.length );
for ( var i = 0; i < duration * 10; i ++ ) {
}
times.push( i / 10 );
tmp.set( Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0 ).multiply( shakeScale ).toArray( values, values.length );
const trackName = '.position';
const track = new THREE.VectorKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, duration, [ track ] );
}
var trackName = '.position';
var track = new THREE.VectorKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, duration, [ track ] );
static CreatePulsationAnimation( duration, pulseScale ) {
};
const times = [],
values = [],
tmp = new THREE.Vector3();
AnimationClipCreator.CreatePulsationAnimation = function ( duration, pulseScale ) {
for ( let i = 0; i < duration * 10; i ++ ) {
var times = [],
values = [],
tmp = new THREE.Vector3();
times.push( i / 10 );
const scaleFactor = Math.random() * pulseScale;
tmp.set( scaleFactor, scaleFactor, scaleFactor ).toArray( values, values.length );
for ( var i = 0; i < duration * 10; i ++ ) {
}
times.push( i / 10 );
var scaleFactor = Math.random() * pulseScale;
tmp.set( scaleFactor, scaleFactor, scaleFactor ).toArray( values, values.length );
const trackName = '.scale';
const track = new THREE.VectorKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, duration, [ track ] );
}
var trackName = '.scale';
var track = new THREE.VectorKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, duration, [ track ] );
static CreateVisibilityAnimation( duration ) {
};
const times = [ 0, duration / 2, duration ],
values = [ true, false, true ];
const trackName = '.visible';
const track = new THREE.BooleanKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, duration, [ track ] );
AnimationClipCreator.CreateVisibilityAnimation = function ( duration ) {
}
var times = [ 0, duration / 2, duration ],
values = [ true, false, true ];
var trackName = '.visible';
var track = new THREE.BooleanKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, duration, [ track ] );
static CreateMaterialColorAnimation( duration, colors ) {
};
const times = [],
values = [],
timeStep = duration / colors.length;
AnimationClipCreator.CreateMaterialColorAnimation = function ( duration, colors ) {
for ( let i = 0; i <= colors.length; i ++ ) {
var times = [],
values = [],
timeStep = duration / colors.length;
times.push( i * timeStep );
values.push( colors[ i % colors.length ] );
for ( var i = 0; i <= colors.length; i ++ ) {
}
times.push( i * timeStep );
values.push( colors[ i % colors.length ] );
const trackName = '.material[0].color';
const track = new THREE.ColorKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, duration, [ track ] );
}
var trackName = '.material[0].color';
var track = new THREE.ColorKeyframeTrack( trackName, times, values );
return new THREE.AnimationClip( null, duration, [ track ] );
};
}
THREE.AnimationClipCreator = AnimationClipCreator;
......
( function () {
const _q = new THREE.Quaternion();
const _targetPos = new THREE.Vector3();
const _targetVec = new THREE.Vector3();
const _effectorPos = new THREE.Vector3();
const _effectorVec = new THREE.Vector3();
const _linkPos = new THREE.Vector3();
const _invLinkQ = new THREE.Quaternion();
const _linkScale = new THREE.Vector3();
const _axis = new THREE.Vector3();
const _vector = new THREE.Vector3();
const _matrix = new THREE.Matrix4();
/**
* CCD Algorithm
* - https://sites.google.com/site/auraliusproject/ccd-algorithm
......@@ -20,223 +41,243 @@
* } ];
*/
var CCDIKSolver = function () {
class CCDIKSolver {
/**
* @param {THREE.SkinnedMesh} mesh
* @param {Array<Object>} iks
*/
function CCDIKSolver( mesh, iks ) {
constructor( mesh, iks = [] ) {
this.mesh = mesh;
this.iks = iks || [];
this.iks = iks;
this._valid();
}
/**
* Update all IK bones.
*
* @return {CCDIKSolver}
*/
CCDIKSolver.prototype = {
constructor: CCDIKSolver,
/**
* Update all IK bones.
*
* @return {CCDIKSolver}
*/
update: function () {
update() {
var iks = this.iks;
const iks = this.iks;
for ( var i = 0, il = iks.length; i < il; i ++ ) {
for ( let i = 0, il = iks.length; i < il; i ++ ) {
this.updateOne( iks[ i ] );
this.updateOne( iks[ i ] );
}
}
return this;
return this;
}
/**
* Update one IK bone
*
* @param {Object} ik parameter
* @return {CCDIKSolver}
*/
},
/**
* Update one IK bone
*
* @param {Object} ik parameter
* @return {CCDIKSolver}
*/
updateOne: function () {
updateOne( ik ) {
var q = new THREE.Quaternion();
var targetPos = new THREE.Vector3();
var targetVec = new THREE.Vector3();
var effectorPos = new THREE.Vector3();
var effectorVec = new THREE.Vector3();
var linkPos = new THREE.Vector3();
var invLinkQ = new THREE.Quaternion();
var linkScale = new THREE.Vector3();
var axis = new THREE.Vector3();
var vector = new THREE.Vector3();
return function update( ik ) {
const bones = this.mesh.skeleton.bones; // for reference overhead reduction in loop
var bones = this.mesh.skeleton.bones; // for reference overhead reduction in loop
const math = Math;
const effector = bones[ ik.effector ];
const target = bones[ ik.target ]; // don't use getWorldPosition() here for the performance
// because it calls updateMatrixWorld( true ) inside.
var math = Math;
var effector = bones[ ik.effector ];
var target = bones[ ik.target ]; // don't use getWorldPosition() here for the performance
// because it calls updateMatrixWorld( true ) inside.
_targetPos.setFromMatrixPosition( target.matrixWorld );
targetPos.setFromMatrixPosition( target.matrixWorld );
var links = ik.links;
var iteration = ik.iteration !== undefined ? ik.iteration : 1;
const links = ik.links;
const iteration = ik.iteration !== undefined ? ik.iteration : 1;
for ( var i = 0; i < iteration; i ++ ) {
for ( let i = 0; i < iteration; i ++ ) {
var rotated = false;
let rotated = false;
for ( var j = 0, jl = links.length; j < jl; j ++ ) {
for ( let j = 0, jl = links.length; j < jl; j ++ ) {
var link = bones[ links[ j ].index ]; // skip this link and following links.
// this skip is used for MMD performance optimization.
const link = bones[ links[ j ].index ]; // skip this link and following links.
// this skip is used for MMD performance optimization.
if ( links[ j ].enabled === false ) break;
var limitation = links[ j ].limitation;
var rotationMin = links[ j ].rotationMin;
var rotationMax = links[ j ].rotationMax; // don't use getWorldPosition/Quaternion() here for the performance
// because they call updateMatrixWorld( true ) inside.
if ( links[ j ].enabled === false ) break;
const limitation = links[ j ].limitation;
const rotationMin = links[ j ].rotationMin;
const rotationMax = links[ j ].rotationMax; // don't use getWorldPosition/Quaternion() here for the performance
// because they call updateMatrixWorld( true ) inside.
link.matrixWorld.decompose( linkPos, invLinkQ, linkScale );
invLinkQ.invert();
effectorPos.setFromMatrixPosition( effector.matrixWorld ); // work in link world
link.matrixWorld.decompose( _linkPos, _invLinkQ, _linkScale );
effectorVec.subVectors( effectorPos, linkPos );
effectorVec.applyQuaternion( invLinkQ );
effectorVec.normalize();
targetVec.subVectors( targetPos, linkPos );
targetVec.applyQuaternion( invLinkQ );
targetVec.normalize();
var angle = targetVec.dot( effectorVec );
_invLinkQ.invert();
if ( angle > 1.0 ) {
_effectorPos.setFromMatrixPosition( effector.matrixWorld ); // work in link world
angle = 1.0;
} else if ( angle < - 1.0 ) {
_effectorVec.subVectors( _effectorPos, _linkPos );
angle = - 1.0;
_effectorVec.applyQuaternion( _invLinkQ );
}
_effectorVec.normalize();
angle = math.acos( angle ); // skip if changing angle is too small to prevent vibration of bone
// Refer to http://www20.atpages.jp/katwat/three.js_r58/examples/mytest37/mmd.three.js
_targetVec.subVectors( _targetPos, _linkPos );
if ( angle < 1e-5 ) continue;
_targetVec.applyQuaternion( _invLinkQ );
if ( ik.minAngle !== undefined && angle < ik.minAngle ) {
_targetVec.normalize();
angle = ik.minAngle;
let angle = _targetVec.dot( _effectorVec );
}
if ( angle > 1.0 ) {
if ( ik.maxAngle !== undefined && angle > ik.maxAngle ) {
angle = 1.0;
angle = ik.maxAngle;
} else if ( angle < - 1.0 ) {
}
angle = - 1.0;
axis.crossVectors( effectorVec, targetVec );
axis.normalize();
q.setFromAxisAngle( axis, angle );
link.quaternion.multiply( q ); // TODO: re-consider the limitation specification
}
if ( limitation !== undefined ) {
angle = math.acos( angle ); // skip if changing angle is too small to prevent vibration of bone
// Refer to http://www20.atpages.jp/katwat/three.js_r58/examples/mytest37/mmd.three.js
var c = link.quaternion.w;
if ( c > 1.0 ) c = 1.0;
var c2 = math.sqrt( 1 - c * c );
link.quaternion.set( limitation.x * c2, limitation.y * c2, limitation.z * c2, c );
if ( angle < 1e-5 ) continue;
}
if ( ik.minAngle !== undefined && angle < ik.minAngle ) {
if ( rotationMin !== undefined ) {
angle = ik.minAngle;
link.rotation.setFromVector3( link.rotation.toVector3( vector ).max( rotationMin ) );
}
}
if ( ik.maxAngle !== undefined && angle > ik.maxAngle ) {
if ( rotationMax !== undefined ) {
angle = ik.maxAngle;
link.rotation.setFromVector3( link.rotation.toVector3( vector ).min( rotationMax ) );
}
}
_axis.crossVectors( _effectorVec, _targetVec );
link.updateMatrixWorld( true );
rotated = true;
_axis.normalize();
}
_q.setFromAxisAngle( _axis, angle );
if ( ! rotated ) break;
link.quaternion.multiply( _q ); // TODO: re-consider the limitation specification
if ( limitation !== undefined ) {
let c = link.quaternion.w;
if ( c > 1.0 ) c = 1.0;
const c2 = math.sqrt( 1 - c * c );
link.quaternion.set( limitation.x * c2, limitation.y * c2, limitation.z * c2, c );
}
return this;
if ( rotationMin !== undefined ) {
link.rotation.setFromVector3( link.rotation.toVector3( _vector ).max( rotationMin ) );
};
}
if ( rotationMax !== undefined ) {
}(),
link.rotation.setFromVector3( link.rotation.toVector3( _vector ).min( rotationMax ) );
/**
* Creates Helper
*
* @return {CCDIKHelper}
*/
createHelper: function () {
}
return new CCDIKHelper( this.mesh, this.mesh.geometry.userData.MMD.iks );
link.updateMatrixWorld( true );
rotated = true;
},
// private methods
_valid: function () {
}
var iks = this.iks;
var bones = this.mesh.skeleton.bones;
if ( ! rotated ) break;
for ( var i = 0, il = iks.length; i < il; i ++ ) {
}
var ik = iks[ i ];
var effector = bones[ ik.effector ];
var links = ik.links;
var link0, link1;
link0 = effector;
return this;
for ( var j = 0, jl = links.length; j < jl; j ++ ) {
}
/**
* Creates Helper
*
* @return {CCDIKHelper}
*/
link1 = bones[ links[ j ].index ];
if ( link0.parent !== link1 ) {
createHelper() {
console.warn( 'THREE.CCDIKSolver: bone ' + link0.name + ' is not the child of bone ' + link1.name );
return new CCDIKHelper( this.mesh, this.mesh.geometry.userData.MMD.iks );
}
} // private methods
link0 = link1;
_valid() {
const iks = this.iks;
const bones = this.mesh.skeleton.bones;
for ( let i = 0, il = iks.length; i < il; i ++ ) {
const ik = iks[ i ];
const effector = bones[ ik.effector ];
const links = ik.links;
let link0, link1;
link0 = effector;
for ( let j = 0, jl = links.length; j < jl; j ++ ) {
link1 = bones[ links[ j ].index ];
if ( link0.parent !== link1 ) {
console.warn( 'THREE.CCDIKSolver: bone ' + link0.name + ' is not the child of bone ' + link1.name );
}
link0 = link1;
}
}
};
/**
* Visualize IK bones
*
* @param {SkinnedMesh} mesh
* @param {Array<Object>} iks
*/
function CCDIKHelper( mesh, iks ) {
}
}
function getPosition( bone, matrixWorldInv ) {
return _vector.setFromMatrixPosition( bone.matrixWorld ).applyMatrix4( matrixWorldInv );
THREE.Object3D.call( this );
}
function setPositionOfBoneToAttributeArray( array, index, bone, matrixWorldInv ) {
const v = getPosition( bone, matrixWorldInv );
array[ index * 3 + 0 ] = v.x;
array[ index * 3 + 1 ] = v.y;
array[ index * 3 + 2 ] = v.z;
}
/**
* Visualize IK bones
*
* @param {SkinnedMesh} mesh
* @param {Array<Object>} iks
*/
class CCDIKHelper extends THREE.Object3D {
constructor( mesh, iks = [] ) {
super();
this.root = mesh;
this.iks = iks || [];
this.iks = iks;
this.matrix.copy( mesh.matrixWorld );
this.matrixAutoUpdate = false;
this.sphereGeometry = new THREE.SphereGeometry( 0.25, 16, 8 );
......@@ -268,148 +309,124 @@
this._init();
}
/**
* Updates IK bones visualization.
*/
CCDIKHelper.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
constructor: CCDIKHelper,
/**
* Updates IK bones visualization.
*/
updateMatrixWorld: function () {
var matrix = new THREE.Matrix4();
var vector = new THREE.Vector3();
updateMatrixWorld( force ) {
function getPosition( bone, matrixWorldInv ) {
const mesh = this.root;
return vector.setFromMatrixPosition( bone.matrixWorld ).applyMatrix4( matrixWorldInv );
if ( this.visible ) {
}
let offset = 0;
const iks = this.iks;
const bones = mesh.skeleton.bones;
function setPositionOfBoneToAttributeArray( array, index, bone, matrixWorldInv ) {
_matrix.copy( mesh.matrixWorld ).invert();
var v = getPosition( bone, matrixWorldInv );
array[ index * 3 + 0 ] = v.x;
array[ index * 3 + 1 ] = v.y;
array[ index * 3 + 2 ] = v.z;
for ( let i = 0, il = iks.length; i < il; i ++ ) {
}
const ik = iks[ i ];
const targetBone = bones[ ik.target ];
const effectorBone = bones[ ik.effector ];
const targetMesh = this.children[ offset ++ ];
const effectorMesh = this.children[ offset ++ ];
targetMesh.position.copy( getPosition( targetBone, _matrix ) );
effectorMesh.position.copy( getPosition( effectorBone, _matrix ) );
return function updateMatrixWorld( force ) {
for ( let j = 0, jl = ik.links.length; j < jl; j ++ ) {
var mesh = this.root;
const link = ik.links[ j ];
const linkBone = bones[ link.index ];
const linkMesh = this.children[ offset ++ ];
linkMesh.position.copy( getPosition( linkBone, _matrix ) );
if ( this.visible ) {
}
var offset = 0;
var iks = this.iks;
var bones = mesh.skeleton.bones;
matrix.copy( mesh.matrixWorld ).invert();
const line = this.children[ offset ++ ];
const array = line.geometry.attributes.position.array;
setPositionOfBoneToAttributeArray( array, 0, targetBone, _matrix );
setPositionOfBoneToAttributeArray( array, 1, effectorBone, _matrix );
for ( var i = 0, il = iks.length; i < il; i ++ ) {
for ( let j = 0, jl = ik.links.length; j < jl; j ++ ) {
var ik = iks[ i ];
var targetBone = bones[ ik.target ];
var effectorBone = bones[ ik.effector ];
var targetMesh = this.children[ offset ++ ];
var effectorMesh = this.children[ offset ++ ];
targetMesh.position.copy( getPosition( targetBone, matrix ) );
effectorMesh.position.copy( getPosition( effectorBone, matrix ) );
const link = ik.links[ j ];
const linkBone = bones[ link.index ];
setPositionOfBoneToAttributeArray( array, j + 2, linkBone, _matrix );
for ( var j = 0, jl = ik.links.length; j < jl; j ++ ) {
}
var link = ik.links[ j ];
var linkBone = bones[ link.index ];
var linkMesh = this.children[ offset ++ ];
linkMesh.position.copy( getPosition( linkBone, matrix ) );
line.geometry.attributes.position.needsUpdate = true;
}
}
var line = this.children[ offset ++ ];
var array = line.geometry.attributes.position.array;
setPositionOfBoneToAttributeArray( array, 0, targetBone, matrix );
setPositionOfBoneToAttributeArray( array, 1, effectorBone, matrix );
}
for ( var j = 0, jl = ik.links.length; j < jl; j ++ ) {
this.matrix.copy( mesh.matrixWorld );
super.updateMatrixWorld( force );
var link = ik.links[ j ];
var linkBone = bones[ link.index ];
setPositionOfBoneToAttributeArray( array, j + 2, linkBone, matrix );
} // private method
}
line.geometry.attributes.position.needsUpdate = true;
_init() {
}
const scope = this;
const iks = this.iks;
}
function createLineGeometry( ik ) {
this.matrix.copy( mesh.matrixWorld );
THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
const geometry = new THREE.BufferGeometry();
const vertices = new Float32Array( ( 2 + ik.links.length ) * 3 );
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
return geometry;
};
}
}(),
// private method
_init: function () {
function createTargetMesh() {
var scope = this;
var iks = this.iks;
return new THREE.Mesh( scope.sphereGeometry, scope.targetSphereMaterial );
function createLineGeometry( ik ) {
}
var geometry = new THREE.BufferGeometry();
var vertices = new Float32Array( ( 2 + ik.links.length ) * 3 );
geometry.setAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
return geometry;
function createEffectorMesh() {
}
return new THREE.Mesh( scope.sphereGeometry, scope.effectorSphereMaterial );
function createTargetMesh() {
}
return new THREE.Mesh( scope.sphereGeometry, scope.targetSphereMaterial );
function createLinkMesh() {
}
return new THREE.Mesh( scope.sphereGeometry, scope.linkSphereMaterial );
function createEffectorMesh() {
}
return new THREE.Mesh( scope.sphereGeometry, scope.effectorSphereMaterial );
function createLine( ik ) {
}
return new THREE.Line( createLineGeometry( ik ), scope.lineMaterial );
function createLinkMesh() {
}
return new THREE.Mesh( scope.sphereGeometry, scope.linkSphereMaterial );
for ( let i = 0, il = iks.length; i < il; i ++ ) {
}
const ik = iks[ i ];
this.add( createTargetMesh() );
this.add( createEffectorMesh() );
function createLine( ik ) {
for ( let j = 0, jl = ik.links.length; j < jl; j ++ ) {
return new THREE.Line( createLineGeometry( ik ), scope.lineMaterial );
this.add( createLinkMesh() );
}
for ( var i = 0, il = iks.length; i < il; i ++ ) {
var ik = iks[ i ];
this.add( createTargetMesh() );
this.add( createEffectorMesh() );
for ( var j = 0, jl = ik.links.length; j < jl; j ++ ) {
this.add( createLinkMesh() );
}
this.add( createLine( ik ) );
}
this.add( createLine( ik ) );
}
} );
return CCDIKSolver;
}();
}
}
THREE.CCDIKSolver = CCDIKSolver;
......
此差异已折叠。
......@@ -7,111 +7,108 @@ import {
VectorKeyframeTrack
} from '../../../build/three.module.js';
var AnimationClipCreator = function () {};
class AnimationClipCreator {
AnimationClipCreator.CreateRotationAnimation = function ( period, axis ) {
static CreateRotationAnimation( period, axis = 'x' ) {
var times = [ 0, period ], values = [ 0, 360 ];
const times = [ 0, period ], values = [ 0, 360 ];
axis = axis || 'x';
var trackName = '.rotation[' + axis + ']';
const trackName = '.rotation[' + axis + ']';
var track = new NumberKeyframeTrack( trackName, times, values );
const track = new NumberKeyframeTrack( trackName, times, values );
return new AnimationClip( null, period, [ track ] );
return new AnimationClip( null, period, [ track ] );
};
AnimationClipCreator.CreateScaleAxisAnimation = function ( period, axis ) {
}
var times = [ 0, period ], values = [ 0, 1 ];
static CreateScaleAxisAnimation( period, axis = 'x' ) {
axis = axis || 'x';
var trackName = '.scale[' + axis + ']';
const times = [ 0, period ], values = [ 0, 1 ];
var track = new NumberKeyframeTrack( trackName, times, values );
const trackName = '.scale[' + axis + ']';
return new AnimationClip( null, period, [ track ] );
const track = new NumberKeyframeTrack( trackName, times, values );
};
return new AnimationClip( null, period, [ track ] );
AnimationClipCreator.CreateShakeAnimation = function ( duration, shakeScale ) {
}
var times = [], values = [], tmp = new Vector3();
static CreateShakeAnimation( duration, shakeScale ) {
for ( var i = 0; i < duration * 10; i ++ ) {
const times = [], values = [], tmp = new Vector3();
times.push( i / 10 );
for ( let i = 0; i < duration * 10; i ++ ) {
tmp.set( Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0 ).
multiply( shakeScale ).
toArray( values, values.length );
times.push( i / 10 );
}
tmp.set( Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0 ).
multiply( shakeScale ).
toArray( values, values.length );
var trackName = '.position';
}
var track = new VectorKeyframeTrack( trackName, times, values );
const trackName = '.position';
return new AnimationClip( null, duration, [ track ] );
const track = new VectorKeyframeTrack( trackName, times, values );
};
return new AnimationClip( null, duration, [ track ] );
}
AnimationClipCreator.CreatePulsationAnimation = function ( duration, pulseScale ) {
static CreatePulsationAnimation( duration, pulseScale ) {
var times = [], values = [], tmp = new Vector3();
const times = [], values = [], tmp = new Vector3();
for ( var i = 0; i < duration * 10; i ++ ) {
for ( let i = 0; i < duration * 10; i ++ ) {
times.push( i / 10 );
times.push( i / 10 );
var scaleFactor = Math.random() * pulseScale;
tmp.set( scaleFactor, scaleFactor, scaleFactor ).
toArray( values, values.length );
const scaleFactor = Math.random() * pulseScale;
tmp.set( scaleFactor, scaleFactor, scaleFactor ).
toArray( values, values.length );
}
}
var trackName = '.scale';
const trackName = '.scale';
var track = new VectorKeyframeTrack( trackName, times, values );
const track = new VectorKeyframeTrack( trackName, times, values );
return new AnimationClip( null, duration, [ track ] );
return new AnimationClip( null, duration, [ track ] );
};
}
static CreateVisibilityAnimation( duration ) {
AnimationClipCreator.CreateVisibilityAnimation = function ( duration ) {
const times = [ 0, duration / 2, duration ], values = [ true, false, true ];
var times = [ 0, duration / 2, duration ], values = [ true, false, true ];
const trackName = '.visible';
var trackName = '.visible';
const track = new BooleanKeyframeTrack( trackName, times, values );
var track = new BooleanKeyframeTrack( trackName, times, values );
return new AnimationClip( null, duration, [ track ] );
return new AnimationClip( null, duration, [ track ] );
}
};
static CreateMaterialColorAnimation( duration, colors ) {
const times = [], values = [],
timeStep = duration / colors.length;
AnimationClipCreator.CreateMaterialColorAnimation = function ( duration, colors ) {
for ( let i = 0; i <= colors.length; i ++ ) {
var times = [], values = [],
timeStep = duration / colors.length;
times.push( i * timeStep );
values.push( colors[ i % colors.length ] );
for ( var i = 0; i <= colors.length; i ++ ) {
}
times.push( i * timeStep );
values.push( colors[ i % colors.length ] );
const trackName = '.material[0].color';
}
const track = new ColorKeyframeTrack( trackName, times, values );
var trackName = '.material[0].color';
return new AnimationClip( null, duration, [ track ] );
var track = new ColorKeyframeTrack( trackName, times, values );
return new AnimationClip( null, duration, [ track ] );
}
};
}
export { AnimationClipCreator };
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册