2
0

AnimationClipCreator.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. console.warn( "THREE.AnimationClipCreator: As part of the transition to ES6 Modules, the files in 'examples/js' were deprecated in May 2020 (r117) and will be deleted in December 2020 (r124). You can find more information about developing using ES6 Modules in https://threejs.org/docs/#manual/en/introduction/Installation." );
  2. THREE.AnimationClipCreator = function () {};
  3. THREE.AnimationClipCreator.CreateRotationAnimation = function ( period, axis ) {
  4. var times = [ 0, period ], values = [ 0, 360 ];
  5. axis = axis || 'x';
  6. var trackName = '.rotation[' + axis + ']';
  7. var track = new THREE.NumberKeyframeTrack( trackName, times, values );
  8. return new THREE.AnimationClip( null, period, [ track ] );
  9. };
  10. THREE.AnimationClipCreator.CreateScaleAxisAnimation = function ( period, axis ) {
  11. var times = [ 0, period ], values = [ 0, 1 ];
  12. axis = axis || 'x';
  13. var trackName = '.scale[' + axis + ']';
  14. var track = new THREE.NumberKeyframeTrack( trackName, times, values );
  15. return new THREE.AnimationClip( null, period, [ track ] );
  16. };
  17. THREE.AnimationClipCreator.CreateShakeAnimation = function ( duration, shakeScale ) {
  18. var times = [], values = [], tmp = new THREE.Vector3();
  19. for ( var i = 0; i < duration * 10; i ++ ) {
  20. times.push( i / 10 );
  21. tmp.set( Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0, Math.random() * 2.0 - 1.0 ).
  22. multiply( shakeScale ).
  23. toArray( values, values.length );
  24. }
  25. var trackName = '.position';
  26. var track = new THREE.VectorKeyframeTrack( trackName, times, values );
  27. return new THREE.AnimationClip( null, duration, [ track ] );
  28. };
  29. THREE.AnimationClipCreator.CreatePulsationAnimation = function ( duration, pulseScale ) {
  30. var times = [], values = [], tmp = new THREE.Vector3();
  31. for ( var i = 0; i < duration * 10; i ++ ) {
  32. times.push( i / 10 );
  33. var scaleFactor = Math.random() * pulseScale;
  34. tmp.set( scaleFactor, scaleFactor, scaleFactor ).
  35. toArray( values, values.length );
  36. }
  37. var trackName = '.scale';
  38. var track = new THREE.VectorKeyframeTrack( trackName, times, values );
  39. return new THREE.AnimationClip( null, duration, [ track ] );
  40. };
  41. THREE.AnimationClipCreator.CreateVisibilityAnimation = function ( duration ) {
  42. var times = [ 0, duration / 2, duration ], values = [ true, false, true ];
  43. var trackName = '.visible';
  44. var track = new THREE.BooleanKeyframeTrack( trackName, times, values );
  45. return new THREE.AnimationClip( null, duration, [ track ] );
  46. };
  47. THREE.AnimationClipCreator.CreateMaterialColorAnimation = function ( duration, colors ) {
  48. var times = [], values = [],
  49. timeStep = duration / colors.length;
  50. for ( var i = 0; i <= colors.length; i ++ ) {
  51. times.push( i * timeStep );
  52. values.push( colors[ i % colors.length ] );
  53. }
  54. var trackName = '.material[0].color';
  55. var track = new THREE.ColorKeyframeTrack( trackName, times, values );
  56. return new THREE.AnimationClip( null, duration, [ track ] );
  57. };