TimerNode.js 942 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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.prototype = Object.create( THREE.FloatNode.prototype );
  12. THREE.TimerNode.prototype.constructor = THREE.TimerNode;
  13. THREE.TimerNode.prototype.nodeType = "Timer";
  14. THREE.TimerNode.prototype.updateFrame = function ( frame ) {
  15. switch( this.scope ) {
  16. case THREE.TimerNode.LOCAL:
  17. this.number += frame.delta * this.scale;
  18. break;
  19. default:
  20. this.number = frame.time * this.scale;
  21. }
  22. };
  23. THREE.TimerNode.prototype.toJSON = function ( meta ) {
  24. var data = this.getJSONNode( meta );
  25. if ( ! data ) {
  26. data = this.createJSONNode( meta );
  27. data.scope = this.scope;
  28. data.scale = this.scale;
  29. }
  30. return data;
  31. };