@idetik/core 0.4.3 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -475,6 +475,7 @@ declare class OrthographicCamera extends Camera {
475
475
  }
476
476
 
477
477
  interface CameraControls {
478
+ onUpdate(dt: number): void;
478
479
  onEvent(event: EventContext): void;
479
480
  }
480
481
  declare class PanZoomControls implements CameraControls {
@@ -483,6 +484,7 @@ declare class PanZoomControls implements CameraControls {
483
484
  private dragStart_;
484
485
  constructor(camera: OrthographicCamera);
485
486
  onEvent(event: EventContext): void;
487
+ onUpdate(_delta: number): void;
486
488
  private onWheel;
487
489
  private onPointerDown;
488
490
  private onPointerMove;
@@ -564,7 +566,7 @@ declare class ChunkManager {
564
566
  }
565
567
 
566
568
  type Overlay = {
567
- update(idetik: Idetik, timestamp?: DOMHighResTimeStamp): void;
569
+ update(idetik: Idetik): void;
568
570
  };
569
571
  type IdetikParams = {
570
572
  canvas: HTMLCanvasElement;
@@ -576,7 +578,6 @@ type IdetikContext = {
576
578
  chunkManager: ChunkManager;
577
579
  };
578
580
  declare class Idetik {
579
- private lastAnimationId_?;
580
581
  private readonly chunkManager_;
581
582
  private readonly context_;
582
583
  private readonly renderer_;
@@ -585,6 +586,8 @@ declare class Idetik {
585
586
  readonly overlays: Overlay[];
586
587
  private readonly stats_?;
587
588
  private readonly sizeObserver_;
589
+ private lastAnimationId_?;
590
+ private lastTimestamp_;
588
591
  /**
589
592
  * Creates a new Idetik visualization runtime instance.
590
593
  *
@@ -688,7 +691,6 @@ declare class WebGLRenderer extends Renderer {
688
691
  private glGetPrimitive;
689
692
  protected resize(width: number, height: number): void;
690
693
  protected clear(): void;
691
- private get gl();
692
694
  }
693
695
 
694
696
  type PerspectiveCameraOptions = {
package/dist/index.js CHANGED
@@ -1802,22 +1802,24 @@ class pQ {
1802
1802
  }
1803
1803
  const mQ = DQ(AA(), [1, -1, 1]);
1804
1804
  class uQ extends OB {
1805
- gl_ = null;
1805
+ gl_;
1806
1806
  programs_;
1807
1807
  bindings_;
1808
1808
  textures_;
1809
1809
  state_;
1810
1810
  renderedObjectsPerFrame_ = 0;
1811
1811
  constructor(A) {
1812
- if (super(A), this.gl_ = this.canvas.getContext("webgl2", {
1812
+ super(A);
1813
+ const I = this.canvas.getContext("webgl2", {
1813
1814
  depth: !0,
1814
1815
  antialias: !0
1815
- }), !this.gl_)
1816
+ });
1817
+ if (!I)
1816
1818
  throw new Error("Failed to initialize WebGL2 context");
1817
- U.info(
1819
+ this.gl_ = I, U.info(
1818
1820
  "WebGLRenderer",
1819
- `WebGL version ${this.gl.getParameter(this.gl.VERSION)}`
1820
- ), this.programs_ = new EQ(this.gl), this.bindings_ = new lQ(this.gl), this.textures_ = new fQ(this.gl), this.state_ = new pQ(this.gl), this.resize(this.canvas.width, this.canvas.height);
1821
+ `WebGL version ${I.getParameter(I.VERSION)}`
1822
+ ), this.programs_ = new EQ(I), this.bindings_ = new lQ(I), this.textures_ = new fQ(I), this.state_ = new pQ(I), this.resize(this.canvas.width, this.canvas.height);
1821
1823
  }
1822
1824
  render(A) {
1823
1825
  const I = A.getBoxRelativeTo(this.canvas), B = new z(
@@ -1902,16 +1904,16 @@ class uQ extends OB {
1902
1904
  y in a && Q.setUniform(y, a[y]);
1903
1905
  }
1904
1906
  const D = this.glGetPrimitive(A.primitive), h = A.indexData;
1905
- h.length ? this.gl.drawElements(D, h.length, this.gl.UNSIGNED_INT, 0) : this.gl.drawArrays(D, 0, A.vertexCount);
1907
+ h.length ? this.gl_.drawElements(D, h.length, this.gl_.UNSIGNED_INT, 0) : this.gl_.drawArrays(D, 0, A.vertexCount);
1906
1908
  }
1907
1909
  glGetPrimitive(A) {
1908
1910
  switch (A) {
1909
1911
  case "points":
1910
- return this.gl.POINTS;
1912
+ return this.gl_.POINTS;
1911
1913
  case "triangles":
1912
- return this.gl.TRIANGLES;
1914
+ return this.gl_.TRIANGLES;
1913
1915
  case "lines":
1914
- return this.gl.LINES;
1916
+ return this.gl_.LINES;
1915
1917
  default: {
1916
1918
  const I = A;
1917
1919
  throw new Error(`Unknown Primitive type: ${I}`);
@@ -1926,10 +1928,7 @@ class uQ extends OB {
1926
1928
  this.state_.setViewport(B);
1927
1929
  }
1928
1930
  clear() {
1929
- this.gl.clearColor(...this.backgroundColor.rgba), this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT), this.state_.setDepthTesting(!0), this.gl.depthFunc(this.gl.LEQUAL);
1930
- }
1931
- get gl() {
1932
- return this.gl_;
1931
+ this.gl_.clearColor(...this.backgroundColor.rgba), this.gl_.clear(this.gl_.COLOR_BUFFER_BIT | this.gl_.DEPTH_BUFFER_BIT), this.state_.setDepthTesting(!0), this.gl_.depthFunc(this.gl_.LEQUAL);
1933
1932
  }
1934
1933
  }
1935
1934
  const TQ = 8;
@@ -2770,7 +2769,6 @@ class IC {
2770
2769
  }
2771
2770
  }
2772
2771
  class Do {
2773
- lastAnimationId_;
2774
2772
  chunkManager_;
2775
2773
  context_;
2776
2774
  renderer_;
@@ -2779,6 +2777,9 @@ class Do {
2779
2777
  overlays;
2780
2778
  stats_;
2781
2779
  sizeObserver_;
2780
+ lastAnimationId_;
2781
+ // this value will be set after start
2782
+ lastTimestamp_ = 0;
2782
2783
  /**
2783
2784
  * Creates a new Idetik visualization runtime instance.
2784
2785
  *
@@ -2868,20 +2869,24 @@ class Do {
2868
2869
  if (U.info("Idetik", "Idetik runtime starting"), this.lastAnimationId_ === void 0) {
2869
2870
  for (const A of this.viewports_)
2870
2871
  A.events.connect();
2871
- this.sizeObserver_.connect(), this.animate();
2872
+ this.sizeObserver_.connect(), this.lastAnimationId_ = requestAnimationFrame((A) => {
2873
+ this.lastTimestamp_ = A, this.animate(A);
2874
+ });
2872
2875
  } else
2873
2876
  U.warn("Idetik", "Idetik runtime already started");
2874
2877
  return this;
2875
2878
  }
2876
2879
  animate(A) {
2877
2880
  this.stats_ && this.stats_.begin();
2878
- for (const I of this.viewports_)
2879
- this.renderer_.render(I);
2881
+ const I = Math.min(A - this.lastTimestamp_, 100) / 1e3;
2882
+ this.lastTimestamp_ = A;
2883
+ for (const B of this.viewports_)
2884
+ B.cameraControls?.onUpdate(I), this.renderer_.render(B);
2880
2885
  this.chunkManager_.update();
2881
- for (const I of this.overlays)
2882
- I.update(this, A);
2886
+ for (const B of this.overlays)
2887
+ B.update(this);
2883
2888
  this.stats_ && this.stats_.end(), this.lastAnimationId_ = requestAnimationFrame(
2884
- (I) => this.animate(I)
2889
+ (B) => this.animate(B)
2885
2890
  );
2886
2891
  }
2887
2892
  stop() {
@@ -3272,6 +3277,8 @@ class yo {
3272
3277
  break;
3273
3278
  }
3274
3279
  }
3280
+ onUpdate(A) {
3281
+ }
3275
3282
  onWheel(A) {
3276
3283
  if (!A.worldPos || !A.clipPos) return;
3277
3284
  const I = A.event;