TimerNode.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.TimerNode = function ( scale, scope, useTimeScale ) {
  5. THREE.FloatNode.call( this );
  6. this.scale = scale !== undefined ? scale : 1;
  7. this.scope = scope || THREE.TimerNode.GLOBAL;
  8. this.useTimeScale = useTimeScale !== undefined ? useTimeScale : this.scale !== 1;
  9. };
  10. THREE.TimerNode.GLOBAL = 'global';
  11. THREE.TimerNode.LOCAL = 'local';
  12. THREE.TimerNode.DELTA = 'delta';
  13. THREE.TimerNode.prototype = Object.create( THREE.FloatNode.prototype );
  14. THREE.TimerNode.prototype.constructor = THREE.TimerNode;
  15. THREE.TimerNode.prototype.nodeType = "Timer";
  16. THREE.TimerNode.prototype.isReadonly = function ( builder ) {
  17. return false;
  18. };
  19. THREE.TimerNode.prototype.isUnique = function ( builder ) {
  20. // share TimerNode "uniform" input if is used on more time with others TimerNode
  21. return this.timeScale && ( this.scope === THREE.TimerNode.GLOBAL || this.scope === THREE.TimerNode.DELTA );
  22. };
  23. THREE.TimerNode.prototype.updateFrame = function ( frame ) {
  24. var scale = this.timeScale ? this.scale : 1;
  25. switch( this.scope ) {
  26. case THREE.TimerNode.LOCAL:
  27. this.value += frame.delta * scale;
  28. break;
  29. case THREE.TimerNode.DELTA:
  30. this.value = frame.delta * scale;
  31. break;
  32. default:
  33. this.value = frame.time * scale;
  34. }
  35. };
  36. THREE.TimerNode.prototype.copy = function ( source ) {
  37. THREE.GLNode.prototype.copy.call( this, source );
  38. this.scope = source.scope;
  39. this.scale = source.scale;
  40. this.useTimeScale = source.useTimeScale;
  41. };
  42. THREE.TimerNode.prototype.toJSON = function ( meta ) {
  43. var data = this.getJSONNode( meta );
  44. if ( ! data ) {
  45. data = this.createJSONNode( meta );
  46. data.scope = this.scope;
  47. data.scale = this.scale;
  48. data.useTimeScale = this.useTimeScale;
  49. }
  50. return data;
  51. };