VectorKeyframeTrack.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. *
  3. * A Track that interpolates Vectors
  4. *
  5. * @author Ben Houston / http://clara.io/
  6. * @author David Sarno / http://lighthaus.us/
  7. */
  8. THREE.VectorKeyframeTrack = function ( name, keys ) {
  9. THREE.KeyframeTrack.call( this, name, keys );
  10. // local cache of value type to avoid allocations during runtime.
  11. this.result = this.keys[0].value.clone();
  12. };
  13. THREE.VectorKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  14. THREE.VectorKeyframeTrack.prototype.constructor = THREE.VectorKeyframeTrack;
  15. THREE.VectorKeyframeTrack.prototype.setResult = function( value ) {
  16. this.result.copy( value );
  17. };
  18. // memoization of the lerp function for speed.
  19. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  20. THREE.VectorKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  21. return value0.lerp( value1, alpha );
  22. };
  23. THREE.VectorKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  24. return value0.equals( value1 );
  25. };
  26. THREE.VectorKeyframeTrack.prototype.clone = function() {
  27. var clonedKeys = [];
  28. for( var i = 0; i < this.keys.length; i ++ ) {
  29. var key = this.keys[i];
  30. clonedKeys.push( {
  31. time: key.time,
  32. value: key.value.clone()
  33. } );
  34. }
  35. return new THREE.VectorKeyframeTrack( this.name );
  36. };
  37. THREE.VectorKeyframeTrack.parse = function( name, jsonKeys ) {
  38. var elementCount = jsonKeys[0].value.length;
  39. var valueType = THREE[ 'Vector' + elementCount ];
  40. var keys = [];
  41. for( var i = 0; i < jsonKeys.length; i ++ ) {
  42. var jsonKey = jsonKeys[i];
  43. var key = {
  44. value: new valueType().fromArray( jsonKey.value ),
  45. time: jsonKey.time
  46. };
  47. keys.push( key );
  48. }
  49. return new THREE.VectorKeyframeTrack( name, keys );
  50. };
粤ICP备19079148号