TimerNode.js 710 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import FloatNode from '../inputs/FloatNode.js';
  2. import { NodeUpdateType } from '../core/constants.js';
  3. class TimerNode extends FloatNode {
  4. static LOCAL = 'local';
  5. static GLOBAL = 'global';
  6. static DELTA = 'delta';
  7. constructor( scope = TimerNode.LOCAL ) {
  8. super();
  9. this.scope = scope;
  10. this.scale = 1;
  11. this.updateType = NodeUpdateType.Frame;
  12. }
  13. update( frame ) {
  14. const scope = this.scope;
  15. const scale = this.scale;
  16. if ( scope === TimerNode.LOCAL ) {
  17. this.value += frame.deltaTime * scale;
  18. } else if ( scope === TimerNode.DELTA ) {
  19. this.value = frame.deltaTime * scale;
  20. } else {
  21. // global
  22. this.value = frame.time * scale;
  23. }
  24. }
  25. }
  26. export default TimerNode;