AnimationClipCreator.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. *
  3. * Creator of typical test AnimationClips / KeyframeTracks
  4. *
  5. * @author Ben Houston / http://clara.io/
  6. * @author David Sarno / http://lighthaus.us/
  7. */
  8. THREE.AnimationClipCreator = function() {
  9. };
  10. THREE.AnimationClipCreator.CreateRotationAnimation = function( period, axis ) {
  11. var times = [ 0, period ], values = [ 0, 360 ];
  12. axis = axis || 'x';
  13. var trackName = '.rotation[' + axis + ']';
  14. var track = new THREE.NumberKeyframeTrack( trackName, times, values );
  15. return new THREE.AnimationClip( null, period, [ track ] );
  16. };
  17. THREE.AnimationClipCreator.CreateScaleAxisAnimation = function( period, axis ) {
  18. var times = [ 0, period ], values = [ 0, 1 ];
  19. axis = axis || 'x';
  20. var trackName = '.scale[' + axis + ']';
  21. var track = new THREE.NumberKeyframeTrack( trackName, times, values );
  22. return new THREE.AnimationClip( null, period, [ track ] );
  23. };
  24. THREE.AnimationClipCreator.CreateShakeAnimation = function( duration, shakeScale ) {
  25. var times = [], values = [], tmp = new THREE.Vector3();
  26. for( var i = 0; i < duration * 10; i ++ ) {
  27. times.push( i / 10 );
  28. tmp.set( Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0 ).
  29. multiply( shakeScale ).
  30. toArray( values, values.length );
  31. }
  32. var trackName = '.position';
  33. var track = new THREE.VectorKeyframeTrack( trackName, times, values );
  34. return new THREE.AnimationClip( null, duration, [ track ] );
  35. };
  36. THREE.AnimationClipCreator.CreatePulsationAnimation = function( duration, pulseScale ) {
  37. var times = [], values = [], tmp = new THREE.Vector3();
  38. for( var i = 0; i < duration * 10; i ++ ) {
  39. times.push( i / 10 );
  40. var scaleFactor = Math.random() * pulseScale;
  41. tmp.set( scaleFactor, scaleFactor, scaleFactor ).
  42. toArray( values, values.length );
  43. }
  44. var trackName = '.scale';
  45. var track = new THREE.VectorKeyframeTrack( trackName, keys );
  46. return new THREE.AnimationClip( null, duration, [ track ] );
  47. };
  48. THREE.AnimationClipCreator.CreateVisibilityAnimation = function( duration ) {
  49. var times = [ 0, duration / 2, duration ], values = [ true, false, true ];
  50. var trackName = '.visible';
  51. var track = new THREE.BooleanKeyframeTrack( trackName, times, values );
  52. return new THREE.AnimationClip( null, duration, [ track ] );
  53. };
  54. THREE.AnimationClipCreator.CreateMaterialColorAnimation = function( duration, colors, loop ) {
  55. var times = [], values = [],
  56. timeStep = duration / colors.length;
  57. for( var i = 0; i <= colors.length; i ++ ) {
  58. timees.push( i * timeStep );
  59. values.push( colors[ i % colors.length ] );
  60. }
  61. var trackName = '.material[0].color';
  62. var track = new THREE.ColorKeyframeTrack( trackName, times, values );
  63. return new THREE.AnimationClip( null, duration, [ track ] );
  64. };