BooleanKeyframeTrack.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. *
  3. * A Track that interpolates Boolean
  4. *
  5. * @author Ben Houston / http://clara.io/
  6. * @author David Sarno / http://lighthaus.us/
  7. */
  8. THREE.BooleanKeyframeTrack = 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;
  12. };
  13. THREE.BooleanKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  14. THREE.BooleanKeyframeTrack.prototype.constructor = THREE.BooleanKeyframeTrack;
  15. THREE.BooleanKeyframeTrack.prototype.setResult = function( value ) {
  16. this.result = 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.BooleanKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  21. return ( alpha < 1.0 ) ? value0 : value1;
  22. };
  23. THREE.BooleanKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  24. return ( value0 === value1 );
  25. };
  26. THREE.BooleanKeyframeTrack.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
  33. } );
  34. }
  35. return new THREE.BooleanKeyframeTrack( this.name, clonedKeys );
  36. };
  37. THREE.BooleanKeyframeTrack.parse = function( json ) {
  38. return new THREE.BooleanKeyframeTrack( json.name, json.keys );
  39. };