TimerNode.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.TimerNode = function ( scale, scope ) {
  5. THREE.FloatNode.call( this );
  6. this.scale = scale !== undefined ? scale : 1;
  7. this.scope = scope || THREE.TimerNode.GLOBAL;
  8. this.timeScale = 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.isUnique = function ( builder ) {
  17. // share TimerNode "uniform" input if is used on more time with others TimerNode
  18. return this.timeScale && ( this.scope === THREE.TimerNode.GLOBAL || this.scope === THREE.TimerNode.DELTA );
  19. };
  20. THREE.TimerNode.prototype.updateFrame = function ( frame ) {
  21. var scale = this.timeScale ? this.scale : 1;
  22. switch( this.scope ) {
  23. case THREE.TimerNode.LOCAL:
  24. this.number += frame.delta * scale;
  25. break;
  26. case THREE.TimerNode.DELTA:
  27. this.number = frame.delta * scale;
  28. break;
  29. default:
  30. this.number = frame.time * scale;
  31. }
  32. };
  33. THREE.TimerNode.prototype.toJSON = function ( meta ) {
  34. var data = this.getJSONNode( meta );
  35. if ( ! data ) {
  36. data = this.createJSONNode( meta );
  37. data.scope = this.scope;
  38. data.scale = this.scale;
  39. data.timeScale = this.timeScale;
  40. }
  41. return data;
  42. };