2
0

TimerNode.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.TimerNode = function ( scope, scale ) {
  5. THREE.FloatNode.call( this );
  6. this.scope = scope || THREE.TimerNode.GLOBAL;
  7. this.scale = scale !== undefined ? scale : 1;
  8. };
  9. THREE.TimerNode.GLOBAL = 'global';
  10. THREE.TimerNode.LOCAL = 'local';
  11. THREE.TimerNode.DELTA = 'delta';
  12. THREE.TimerNode.prototype = Object.create( THREE.FloatNode.prototype );
  13. THREE.TimerNode.prototype.constructor = THREE.TimerNode;
  14. THREE.TimerNode.prototype.nodeType = "Timer";
  15. THREE.TimerNode.prototype.updateFrame = function ( frame ) {
  16. switch( this.scope ) {
  17. case THREE.TimerNode.LOCAL:
  18. this.number += frame.delta * this.scale;
  19. break;
  20. case THREE.TimerNode.DELTA:
  21. this.number = frame.delta * this.scale;
  22. break;
  23. default:
  24. this.number = frame.time * this.scale;
  25. }
  26. };
  27. THREE.TimerNode.prototype.toJSON = function ( meta ) {
  28. var data = this.getJSONNode( meta );
  29. if ( ! data ) {
  30. data = this.createJSONNode( meta );
  31. data.scope = this.scope;
  32. data.scale = this.scale;
  33. }
  34. return data;
  35. };