@idetik/core 0.5.0 → 0.6.0

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
@@ -434,6 +434,7 @@ declare abstract class Layer {
434
434
  get state(): LayerState;
435
435
  addStateChangeCallback(callback: StateChangeCallback): void;
436
436
  removeStateChangeCallback(callback: StateChangeCallback): void;
437
+ hasMultipleLODs(): boolean;
437
438
  protected setState(newState: LayerState): void;
438
439
  protected addObject(object: RenderableObject): void;
439
440
  protected removeObject(object: RenderableObject): void;
@@ -685,13 +686,13 @@ declare class WebGLRenderer extends Renderer {
685
686
  textures: number;
686
687
  totalBytes: number;
687
688
  };
689
+ private initStencil;
688
690
  private renderLayer;
689
691
  protected renderObject(layer: Layer, objectIndex: number, camera: Camera): void;
690
692
  private drawGeometry;
691
693
  private glGetPrimitive;
692
694
  protected resize(width: number, height: number): void;
693
695
  protected clear(): void;
694
- private get gl();
695
696
  }
696
697
 
697
698
  type PerspectiveCameraOptions = {
@@ -821,6 +822,7 @@ declare class ChunkedImageLayer extends Layer implements ChannelsEnabled {
821
822
  onDetached(_context: IdetikContext): void;
822
823
  update(context?: RenderContext): void;
823
824
  private updateChunks;
825
+ hasMultipleLODs(): boolean;
824
826
  get lastPresentationTimeCoord(): number | undefined;
825
827
  private isPresentationStale;
826
828
  private resliceIfZChanged;
package/dist/index.js CHANGED
@@ -1799,25 +1799,31 @@ class pQ {
1799
1799
  this.currentCullingMode_ = A;
1800
1800
  }
1801
1801
  }
1802
+ setStencilTest(A) {
1803
+ A ? this.enable(this.gl_.STENCIL_TEST) : this.disable(this.gl_.STENCIL_TEST);
1804
+ }
1802
1805
  }
1803
1806
  const mQ = DQ(AA(), [1, -1, 1]);
1804
1807
  class uQ extends OB {
1805
- gl_ = null;
1808
+ gl_;
1806
1809
  programs_;
1807
1810
  bindings_;
1808
1811
  textures_;
1809
1812
  state_;
1810
1813
  renderedObjectsPerFrame_ = 0;
1811
1814
  constructor(A) {
1812
- if (super(A), this.gl_ = this.canvas.getContext("webgl2", {
1815
+ super(A);
1816
+ const I = this.canvas.getContext("webgl2", {
1813
1817
  depth: !0,
1814
- antialias: !0
1815
- }), !this.gl_)
1818
+ antialias: !0,
1819
+ stencil: !0
1820
+ });
1821
+ if (!I)
1816
1822
  throw new Error("Failed to initialize WebGL2 context");
1817
- U.info(
1823
+ this.gl_ = I, U.info(
1818
1824
  "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);
1825
+ `WebGL version ${I.getParameter(I.VERSION)}`
1826
+ ), this.programs_ = new EQ(I), this.bindings_ = new lQ(I), this.textures_ = new fQ(I), this.state_ = new pQ(I), this.initStencil(), this.resize(this.canvas.width, this.canvas.height);
1821
1827
  }
1822
1828
  render(A) {
1823
1829
  const I = A.getBoxRelativeTo(this.canvas), B = new z(
@@ -1849,9 +1855,14 @@ class uQ extends OB {
1849
1855
  get textureInfo() {
1850
1856
  return this.textures_.textureInfo;
1851
1857
  }
1858
+ initStencil() {
1859
+ this.gl_.clearStencil(0), this.gl_.stencilMask(255), this.gl_.stencilFunc(this.gl_.EQUAL, 0, 255), this.gl_.stencilOp(this.gl_.KEEP, this.gl_.KEEP, this.gl_.INCR);
1860
+ }
1852
1861
  renderLayer(A, I, B) {
1853
- this.state_.setBlendingMode(A.transparent ? A.blendMode : "none"), A.objects.forEach((Q, C) => {
1854
- B.intersectsWithBox3(Q.boundingBox) && (this.renderObject(A, C, I), this.renderedObjectsPerFrame_ += 1);
1862
+ this.state_.setBlendingMode(A.transparent ? A.blendMode : "none");
1863
+ const Q = A.objects.length > 0 && A.hasMultipleLODs();
1864
+ this.state_.setStencilTest(Q), Q && this.gl_.clear(this.gl_.STENCIL_BUFFER_BIT), A.objects.forEach((C, E) => {
1865
+ B.intersectsWithBox3(C.boundingBox) && (this.renderObject(A, E, I), this.renderedObjectsPerFrame_ += 1);
1855
1866
  });
1856
1867
  }
1857
1868
  renderObject(A, I, B) {
@@ -1902,16 +1913,16 @@ class uQ extends OB {
1902
1913
  y in a && Q.setUniform(y, a[y]);
1903
1914
  }
1904
1915
  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);
1916
+ h.length ? this.gl_.drawElements(D, h.length, this.gl_.UNSIGNED_INT, 0) : this.gl_.drawArrays(D, 0, A.vertexCount);
1906
1917
  }
1907
1918
  glGetPrimitive(A) {
1908
1919
  switch (A) {
1909
1920
  case "points":
1910
- return this.gl.POINTS;
1921
+ return this.gl_.POINTS;
1911
1922
  case "triangles":
1912
- return this.gl.TRIANGLES;
1923
+ return this.gl_.TRIANGLES;
1913
1924
  case "lines":
1914
- return this.gl.LINES;
1925
+ return this.gl_.LINES;
1915
1926
  default: {
1916
1927
  const I = A;
1917
1928
  throw new Error(`Unknown Primitive type: ${I}`);
@@ -1926,10 +1937,7 @@ class uQ extends OB {
1926
1937
  this.state_.setViewport(B);
1927
1938
  }
1928
1939
  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_;
1940
+ 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
1941
  }
1934
1942
  }
1935
1943
  const TQ = 8;
@@ -2051,9 +2059,12 @@ class bQ {
2051
2059
  const I = this.store_.getTimeIndex(A), B = this.store_.getChunksAtTime(I), Q = B.filter(
2052
2060
  (i) => i.lod === this.currentLOD_ && this.chunkViewStates_.get(i)?.visible === !0 && i.state === "loaded"
2053
2061
  ), C = this.store_.getLowestResLOD();
2054
- return this.currentLOD_ === C ? Q : [...B.filter(
2062
+ if (this.currentLOD_ === C)
2063
+ return Q;
2064
+ const E = B.filter(
2055
2065
  (i) => i.lod === C && this.chunkViewStates_.get(i)?.visible === !0 && i.state === "loaded"
2056
- ), ...Q];
2066
+ );
2067
+ return [...Q, ...E];
2057
2068
  }
2058
2069
  updateChunkStates(A, I) {
2059
2070
  const B = I.camera;
@@ -3354,6 +3365,9 @@ class GA {
3354
3365
  throw new Error(`Callback to remove could not be found: ${A}`);
3355
3366
  this.callbacks_.splice(I, 1);
3356
3367
  }
3368
+ hasMultipleLODs() {
3369
+ return !1;
3370
+ }
3357
3371
  setState(A) {
3358
3372
  const I = this.state_;
3359
3373
  this.state_ = A, this.callbacks_.forEach((B) => B(A, I));
@@ -3975,6 +3989,9 @@ class NB extends GA {
3975
3989
  this.visibleChunks_.set(Q, C), this.addObject(C);
3976
3990
  }
3977
3991
  }
3992
+ hasMultipleLODs() {
3993
+ return this.chunkStoreView_ ? this.chunkStoreView_.lodCount > 1 : !1;
3994
+ }
3978
3995
  get lastPresentationTimeCoord() {
3979
3996
  return this.lastPresentationTimeCoord_;
3980
3997
  }