NodeFrame.js 888 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { NodeUpdateType } from './constants.js';
  2. class NodeFrame {
  3. constructor() {
  4. this.time = 0;
  5. this.deltaTime = 0;
  6. this.frameId = 0;
  7. this.startTime = null;
  8. this.updateMap = new WeakMap();
  9. this.renderer = null;
  10. this.material = null;
  11. this.camera = null;
  12. this.object = null;
  13. }
  14. updateNode( node ) {
  15. if ( node.updateType === NodeUpdateType.Frame ) {
  16. if ( this.updateMap.get( node ) !== this.frameId ) {
  17. this.updateMap.set( node, this.frameId );
  18. node.update( this );
  19. }
  20. } else if ( node.updateType === NodeUpdateType.Object ) {
  21. node.update( this );
  22. }
  23. }
  24. update() {
  25. this.frameId ++;
  26. if ( this.lastTime === undefined ) this.lastTime = performance.now();
  27. this.deltaTime = ( performance.now() - this.lastTime ) / 1000;
  28. this.lastTime = performance.now();
  29. this.time += this.deltaTime;
  30. }
  31. }
  32. export default NodeFrame;