TimerNode.js 967 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import UniformNode from '../core/UniformNode.js';
  2. import { NodeUpdateType } from '../core/constants.js';
  3. class TimerNode extends UniformNode {
  4. static LOCAL = 'local';
  5. static GLOBAL = 'global';
  6. static DELTA = 'delta';
  7. constructor( scope = TimerNode.LOCAL, scale = 1, value = 0 ) {
  8. super( value );
  9. this.scope = scope;
  10. this.scale = scale;
  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. serialize( data ) {
  26. super.serialize( data );
  27. data.scope = this.scope;
  28. data.scale = this.scale;
  29. }
  30. deserialize( data ) {
  31. super.deserialize( data );
  32. this.scope = data.scope;
  33. this.scale = data.scale;
  34. }
  35. }
  36. export default TimerNode;