NodeFrame.js 922 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. const updateType = node.getUpdateType();
  16. if ( updateType === NodeUpdateType.FRAME ) {
  17. if ( this.updateMap.get( node ) !== this.frameId ) {
  18. this.updateMap.set( node, this.frameId );
  19. node.update( this );
  20. }
  21. } else if ( updateType === NodeUpdateType.OBJECT ) {
  22. node.update( this );
  23. }
  24. }
  25. update() {
  26. this.frameId ++;
  27. if ( this.lastTime === undefined ) this.lastTime = performance.now();
  28. this.deltaTime = ( performance.now() - this.lastTime ) / 1000;
  29. this.lastTime = performance.now();
  30. this.time += this.deltaTime;
  31. }
  32. }
  33. export default NodeFrame;