|
@@ -60,10 +60,12 @@
|
|
|
|
|
|
var sceneHUD, cameraOrtho, hudMaterial;
|
|
|
|
|
|
- var morphs = [];
|
|
|
+ var morph, morphs = [];
|
|
|
|
|
|
var light;
|
|
|
|
|
|
+ var delta, newTime, oldTime;
|
|
|
+
|
|
|
init();
|
|
|
animate();
|
|
|
|
|
@@ -246,7 +248,11 @@
|
|
|
|
|
|
if ( fudgeColor ) THREE.ColorUtils.adjustHSV( material.color, 0, 0.5 - Math.random(), 0.5 - Math.random() );
|
|
|
|
|
|
- var meshAnim = new THREE.Mesh( geometry, material );
|
|
|
+ var meshAnim = new THREE.MorphAnimMesh( geometry, material );
|
|
|
+
|
|
|
+ meshAnim.speed = speed;
|
|
|
+ meshAnim.duration = duration;
|
|
|
+ meshAnim.time = 600 * Math.random();
|
|
|
|
|
|
meshAnim.position.set( x, y, z );
|
|
|
meshAnim.rotation.y = Math.PI/2;
|
|
@@ -256,9 +262,7 @@
|
|
|
|
|
|
scene.add( meshAnim );
|
|
|
|
|
|
- morphs.push( { mesh: meshAnim, lastKeyframe: 0, currentKeyframe: 0,
|
|
|
- offset: Math.random() * 6, speed: speed, duration: duration,
|
|
|
- oldTime: new Date().getTime() } );
|
|
|
+ morphs.push( meshAnim );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -343,69 +347,45 @@
|
|
|
addMorph( geometry, 0.45, 500, 500 - Math.random() * 500, FLOOR + 300, 700 );
|
|
|
|
|
|
} } );
|
|
|
-
|
|
|
*/
|
|
|
|
|
|
}
|
|
|
|
|
|
+ //
|
|
|
|
|
|
- var t = 0, newTime, delta;
|
|
|
-
|
|
|
-
|
|
|
- function updateMorph( morph ) {
|
|
|
+ function animate() {
|
|
|
|
|
|
- // Alternate morph targets
|
|
|
+ requestAnimationFrame( animate );
|
|
|
|
|
|
- var interpolation = morph.duration / ( morph.mesh.geometry.morphTargets.length - 1 );
|
|
|
+ render();
|
|
|
+ stats.update();
|
|
|
|
|
|
- var time = ( new Date().getTime() + morph.offset * 100 ) % morph.duration;
|
|
|
- var keyframe = Math.floor( time / interpolation ) + 1;
|
|
|
+ }
|
|
|
|
|
|
- var mesh = morph.mesh;
|
|
|
+ function render() {
|
|
|
|
|
|
- if ( keyframe != morph.currentKeyframe ) {
|
|
|
+ if ( oldTime === undefined ) oldTime = new Date().getTime();
|
|
|
|
|
|
- mesh.morphTargetInfluences[ morph.lastKeyframe ] = 0;
|
|
|
- mesh.morphTargetInfluences[ morph.currentKeyframe ] = 1;
|
|
|
- mesh.morphTargetInfluences[ keyframe ] = 0;
|
|
|
+ newTime = new Date().getTime();
|
|
|
+ delta = newTime - oldTime;
|
|
|
+ oldTime = newTime;
|
|
|
|
|
|
- morph.lastKeyframe = morph.currentKeyframe;
|
|
|
- morph.currentKeyframe = keyframe;
|
|
|
+ for ( var i = 0; i < morphs.length; i ++ ) {
|
|
|
|
|
|
- }
|
|
|
+ morph = morphs[ i ];
|
|
|
|
|
|
- mesh.morphTargetInfluences[ keyframe ] = ( time % interpolation ) / interpolation;
|
|
|
- mesh.morphTargetInfluences[ morph.lastKeyframe ] = 1 - mesh.morphTargetInfluences[ keyframe ];
|
|
|
+ morph.updateAnimation( delta );
|
|
|
|
|
|
- var newTime = new Date().getTime();
|
|
|
- delta = newTime - morph.oldTime;
|
|
|
- morph.oldTime = newTime;
|
|
|
+ morph.position.x += morph.speed * delta;
|
|
|
|
|
|
- mesh.position.x += morph.speed * delta;
|
|
|
+ if ( morph.position.x > 2000 ) {
|
|
|
|
|
|
- if ( mesh.position.x > 2000 ) {
|
|
|
+ morph.position.x = -1000 - Math.random() * 500;
|
|
|
|
|
|
- mesh.position.x = -1000 - Math.random() * 500;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
- }
|
|
|
-
|
|
|
- //
|
|
|
-
|
|
|
- function animate() {
|
|
|
-
|
|
|
- requestAnimationFrame( animate );
|
|
|
-
|
|
|
- render();
|
|
|
- stats.update();
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- function render() {
|
|
|
-
|
|
|
- for ( var i = 0; i < morphs.length; i++ ) updateMorph( morphs[ i ] );
|
|
|
-
|
|
|
controls.update();
|
|
|
|
|
|
renderer.clear();
|