@xeokit/xeokit-sdk 2.4.0-alpha-89 → 2.4.0-alpha-90

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.
Files changed (30) hide show
  1. package/dist/xeokit-sdk.cjs.js +169 -92
  2. package/dist/xeokit-sdk.es.js +169 -92
  3. package/dist/xeokit-sdk.es5.js +58 -58
  4. package/dist/xeokit-sdk.min.cjs.js +3 -3
  5. package/dist/xeokit-sdk.min.es.js +3 -3
  6. package/dist/xeokit-sdk.min.es5.js +3 -3
  7. package/package.json +1 -1
  8. package/src/viewer/scene/mesh/pick/PickMeshRenderer.js +3 -0
  9. package/src/viewer/scene/mesh/pick/PickMeshShaderSource.js +11 -3
  10. package/src/viewer/scene/mesh/pick/PickTriangleRenderer.js +4 -0
  11. package/src/viewer/scene/mesh/pick/PickTriangleShaderSource.js +11 -4
  12. package/src/viewer/scene/model/dtx/triangles/renderers/TrianglesDataTexturePickDepthRenderer.js +13 -2
  13. package/src/viewer/scene/model/dtx/triangles/renderers/TrianglesDataTexturePickMeshRenderer.js +13 -2
  14. package/src/viewer/scene/model/dtx/triangles/renderers/TrianglesDataTexturePickNormalsFlatRenderer.js +14 -2
  15. package/src/viewer/scene/model/dtx/triangles/renderers/TrianglesDataTexturePickNormalsRenderer.js +13 -2
  16. package/src/viewer/scene/model/vbo/VBOSceneModelRenderers.js +17 -39
  17. package/src/viewer/scene/model/vbo/pointsBatching/renderers/PointsBatchingPickDepthRenderer.js +3 -1
  18. package/src/viewer/scene/model/vbo/pointsBatching/renderers/PointsBatchingPickMeshRenderer.js +3 -1
  19. package/src/viewer/scene/model/vbo/pointsInstancing/renderers/PointsInstancingPickDepthRenderer.js +4 -1
  20. package/src/viewer/scene/model/vbo/pointsInstancing/renderers/PointsInstancingPickMeshRenderer.js +3 -0
  21. package/src/viewer/scene/model/vbo/trianglesBatching/renderers/TrianglesBatchingPickDepthRenderer.js +4 -1
  22. package/src/viewer/scene/model/vbo/trianglesBatching/renderers/TrianglesBatchingPickMeshRenderer.js +3 -1
  23. package/src/viewer/scene/model/vbo/trianglesBatching/renderers/TrianglesBatchingPickNormalsFlatRenderer.js +3 -1
  24. package/src/viewer/scene/model/vbo/trianglesBatching/renderers/TrianglesBatchingPickNormalsRenderer.js +3 -1
  25. package/src/viewer/scene/model/vbo/trianglesInstancing/renderers/TrianglesInstancingPickDepthRenderer.js +3 -1
  26. package/src/viewer/scene/model/vbo/trianglesInstancing/renderers/TrianglesInstancingPickMeshRenderer.js +3 -1
  27. package/src/viewer/scene/model/vbo/trianglesInstancing/renderers/TrianglesInstancingPickNormalsFlatRenderer.js +3 -1
  28. package/src/viewer/scene/model/vbo/trianglesInstancing/renderers/TrianglesInstancingPickNormalsRenderer.js +3 -1
  29. package/src/viewer/scene/webgl/RenderBuffer.js +1 -1
  30. package/src/viewer/scene/webgl/Renderer.js +31 -29
@@ -24000,6 +24000,16 @@ function buildVertex$3(mesh) {
24000
24000
  src.push(" mat[2][2] =1.0;");
24001
24001
  src.push("}");
24002
24002
  }
24003
+
24004
+ src.push("uniform vec2 pickClipPos;");
24005
+
24006
+ src.push("vec4 remapClipPos(vec4 clipPos) {");
24007
+ src.push(" clipPos.xy /= clipPos.w;");
24008
+ src.push(" clipPos.xy -= pickClipPos;");
24009
+ src.push(" clipPos.xy *= clipPos.w;");
24010
+ src.push(" return clipPos;");
24011
+ src.push("}");
24012
+
24003
24013
  src.push("void main(void) {");
24004
24014
  src.push("vec4 localPosition = vec4(position, 1.0); ");
24005
24015
  if (quantizedGeometry) {
@@ -24026,7 +24036,7 @@ function buildVertex$3(mesh) {
24026
24036
  src.push("vFragDepth = 1.0 + clipPos.w;");
24027
24037
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
24028
24038
  }
24029
- src.push("gl_Position = clipPos;");
24039
+ src.push("gl_Position = remapClipPos(clipPos);");
24030
24040
  src.push("}");
24031
24041
  return src;
24032
24042
  }
@@ -24229,6 +24239,8 @@ PickMeshRenderer.prototype.drawMesh = function (frameCtx, mesh) {
24229
24239
  const r = pickID & 0xFF;
24230
24240
  gl.uniform4f(this._uPickColor, r / 255, g / 255, b / 255, a / 255);
24231
24241
 
24242
+ gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos);
24243
+
24232
24244
  if (geometryState.indicesBuf) {
24233
24245
  gl.drawElements(geometryState.primitive, geometryState.indicesBuf.numItems, geometryState.indicesBuf.itemType, 0);
24234
24246
  frameCtx.drawElements++;
@@ -24262,6 +24274,7 @@ PickMeshRenderer.prototype._allocate = function (mesh) {
24262
24274
  this._aPosition = program.getAttribute("position");
24263
24275
  this._uClippable = program.getLocation("clippable");
24264
24276
  this._uPickColor = program.getLocation("pickColor");
24277
+ this._uPickClipPos = program.getLocation("pickClipPos");
24265
24278
  this._uOffset = program.getLocation("offset");
24266
24279
  if (scene.logarithmicDepthBufferEnabled ) {
24267
24280
  this._uLogDepthBufFC = program.getLocation("logDepthBufFC");
@@ -24299,8 +24312,6 @@ function buildVertex$2(mesh) {
24299
24312
  const scene = mesh.scene;
24300
24313
  const clipping = scene._sectionPlanesState.sectionPlanes.length > 0;
24301
24314
  const quantizedGeometry = !!mesh._geometry._state.compressGeometry;
24302
- mesh._state.billboard;
24303
- mesh._state.stationary;
24304
24315
  const src = [];
24305
24316
  src.push('#version 300 es');
24306
24317
  src.push("// Surface picking vertex shader");
@@ -24322,6 +24333,16 @@ function buildVertex$2(mesh) {
24322
24333
  src.push("}");
24323
24334
  src.push("out float isPerspective;");
24324
24335
  }
24336
+
24337
+ src.push("uniform vec2 pickClipPos;");
24338
+
24339
+ src.push("vec4 remapClipPos(vec4 clipPos) {");
24340
+ src.push(" clipPos.xy /= clipPos.w;");
24341
+ src.push(" clipPos.xy -= pickClipPos;");
24342
+ src.push(" clipPos.xy *= clipPos.w;");
24343
+ src.push(" return clipPos;");
24344
+ src.push("}");
24345
+
24325
24346
  src.push("out vec4 vColor;");
24326
24347
  if (quantizedGeometry) {
24327
24348
  src.push("uniform mat4 positionsDecodeMatrix;");
@@ -24343,7 +24364,7 @@ function buildVertex$2(mesh) {
24343
24364
  src.push("vFragDepth = 1.0 + clipPos.w;");
24344
24365
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
24345
24366
  }
24346
- src.push("gl_Position = clipPos;");
24367
+ src.push("gl_Position = remapClipPos(clipPos);");
24347
24368
  src.push("}");
24348
24369
  return src;
24349
24370
  }
@@ -24536,6 +24557,9 @@ PickTriangleRenderer.prototype.drawMesh = function (frameCtx, mesh) {
24536
24557
  } else {
24537
24558
  this._aPosition.bindArrayBuffer(positionsBuf);
24538
24559
  }
24560
+
24561
+ gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos);
24562
+
24539
24563
  pickColorsBuf.bind();
24540
24564
  gl.enableVertexAttribArray(this._aColor.location);
24541
24565
  gl.vertexAttribPointer(this._aColor.location, pickColorsBuf.itemSize, pickColorsBuf.itemType, true, 0, 0); // Normalize
@@ -24567,6 +24591,7 @@ PickTriangleRenderer.prototype._allocate = function (mesh) {
24567
24591
  }
24568
24592
  this._aPosition = program.getAttribute("position");
24569
24593
  this._aColor = program.getAttribute("color");
24594
+ this._uPickClipPos = program.getLocation("pickClipPos");
24570
24595
  this._uClippable = program.getLocation("clippable");
24571
24596
  this._uOffset = program.getLocation("offset");
24572
24597
  if (scene.logarithmicDepthBufferEnabled ) {
@@ -34357,7 +34382,7 @@ class RenderBuffer {
34357
34382
 
34358
34383
  read(pickX, pickY, glFormat = null, glType = null, arrayType = Uint8Array, arrayMultiplier = 4) {
34359
34384
  const x = pickX;
34360
- const y = (this.buffer.height || this.gl.drawingBufferHeight) - pickY;
34385
+ const y = this.buffer.height ? (this.buffer.height - pickY - 1) : (this.gl.drawingBufferHeight - pickY);
34361
34386
  const pix = new arrayType(arrayMultiplier);
34362
34387
  const gl = this.gl;
34363
34388
  gl.readPixels(x, y, 1, 1, glFormat || gl.RGBA, glType || gl.UNSIGNED_BYTE, pix, 0);
@@ -37545,7 +37570,6 @@ const edgesDefaultColor = new Float32Array([0, 0, 0, 1]);
37545
37570
 
37546
37571
  const tempVec4 = math.vec4();
37547
37572
  const tempVec3a$w = math.vec3();
37548
- math.vec3();
37549
37573
  const tempVec3c$n = math.vec3();
37550
37574
  const tempMat4a$f = math.mat4();
37551
37575
 
@@ -37618,6 +37642,18 @@ class VBOSceneModelRenderer {
37618
37642
  return src;
37619
37643
  }
37620
37644
 
37645
+ _addRemapClipPosLines(src) {
37646
+ src.push("uniform vec2 pickClipPos;");
37647
+
37648
+ src.push("vec4 remapClipPos(vec4 clipPos) {");
37649
+ src.push(" clipPos.xy /= clipPos.w;");
37650
+ src.push(" clipPos.xy -= pickClipPos;");
37651
+ src.push(" clipPos.xy *= clipPos.w;");
37652
+ src.push(" return clipPos;");
37653
+ src.push("}");
37654
+ return src;
37655
+ }
37656
+
37621
37657
  getValid() {
37622
37658
  return this._hash === this._getHash();
37623
37659
  }
@@ -37751,6 +37787,7 @@ class VBOSceneModelRenderer {
37751
37787
  this._aPickColor = program.getAttribute("pickColor");
37752
37788
  this._uPickZNear = program.getLocation("pickZNear");
37753
37789
  this._uPickZFar = program.getLocation("pickZFar");
37790
+ this._uPickClipPos = program.getLocation("pickClipPos");
37754
37791
 
37755
37792
  this._uColorMap = "uColorMap";
37756
37793
  this._uMetallicRoughMap = "uMetallicRoughMap";
@@ -37791,7 +37828,6 @@ class VBOSceneModelRenderer {
37791
37828
  const program = this._program;
37792
37829
  const lightsState = scene._lightsState;
37793
37830
  const lights = lightsState.lights;
37794
- const project = scene.camera.project;
37795
37831
 
37796
37832
  program.bind();
37797
37833
 
@@ -37818,43 +37854,6 @@ class VBOSceneModelRenderer {
37818
37854
  gl.uniform3fv(this._uLightDir[i], light.dir);
37819
37855
  }
37820
37856
  }
37821
-
37822
- if (this._withSAO) {
37823
- const sao = scene.sao;
37824
- const saoEnabled = sao.possible;
37825
- if (saoEnabled) {
37826
- const viewportWidth = gl.drawingBufferWidth;
37827
- const viewportHeight = gl.drawingBufferHeight;
37828
- tempVec4[0] = viewportWidth;
37829
- tempVec4[1] = viewportHeight;
37830
- tempVec4[2] = sao.blendCutoff;
37831
- tempVec4[3] = sao.blendFactor;
37832
- gl.uniform4fv(this._uSAOParams, tempVec4);
37833
- this._program.bindTexture(this._uOcclusionTexture, frameCtx.occlusionTexture, 0);
37834
- }
37835
- }
37836
-
37837
- if (scene.logarithmicDepthBufferEnabled) {
37838
- const logDepthBufFC = 2.0 / (Math.log(project.far + 1.0) / Math.LN2);
37839
- gl.uniform1f(this._uLogDepthBufFC, logDepthBufFC);
37840
- }
37841
-
37842
- if (this._uGammaFactor) {
37843
- gl.uniform1f(this._uGammaFactor, scene.gammaFactor);
37844
- }
37845
-
37846
- if (this._uPickInvisible) {
37847
- gl.uniform1i(this._uPickInvisible, frameCtx.pickInvisible);
37848
- }
37849
-
37850
-
37851
- if (this._uShadowViewMatrix) {
37852
- gl.uniformMatrix4fv(this._uShadowViewMatrix, false, frameCtx.shadowViewMatrix);
37853
- }
37854
-
37855
- if (this._uShadowProjMatrix) {
37856
- gl.uniformMatrix4fv(this._uShadowProjMatrix, false, frameCtx.shadowProjMatrix);
37857
- }
37858
37857
  }
37859
37858
 
37860
37859
  _makeVAO(state) {
@@ -38051,6 +38050,10 @@ class VBOSceneModelRenderer {
38051
38050
  gl.uniform1f(this._uPickZFar, frameCtx.pickZFar);
38052
38051
  }
38053
38052
 
38053
+ if (this._uPickClipPos) {
38054
+ gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos);
38055
+ }
38056
+
38054
38057
  if (this._uPositionsDecodeMatrix) {
38055
38058
  gl.uniformMatrix4fv(this._uPositionsDecodeMatrix, false, state.positionsDecodeMatrix);
38056
38059
  }
@@ -39230,6 +39233,8 @@ class TrianglesBatchingPickMeshRenderer extends VBOSceneModelTriangleBatchingRen
39230
39233
  src.push("out float vFlags;");
39231
39234
  }
39232
39235
 
39236
+ this._addRemapClipPosLines(src);
39237
+
39233
39238
  src.push("out vec4 vPickColor;");
39234
39239
 
39235
39240
  src.push("void main(void) {");
@@ -39257,7 +39262,7 @@ class TrianglesBatchingPickMeshRenderer extends VBOSceneModelTriangleBatchingRen
39257
39262
  src.push("vFragDepth = 1.0 + clipPos.w;");
39258
39263
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
39259
39264
  }
39260
- src.push("gl_Position = clipPos;");
39265
+ src.push("gl_Position = remapClipPos(clipPos);");
39261
39266
  src.push(" }");
39262
39267
  src.push("}");
39263
39268
  return src;
@@ -39356,6 +39361,9 @@ class TrianglesBatchingPickDepthRenderer extends VBOSceneModelTriangleBatchingRe
39356
39361
  src.push("out vec4 vWorldPosition;");
39357
39362
  src.push("out float vFlags;");
39358
39363
  }
39364
+
39365
+ this._addRemapClipPosLines(src);
39366
+
39359
39367
  src.push("out vec4 vViewPosition;");
39360
39368
  src.push("void main(void) {");
39361
39369
 
@@ -39381,7 +39389,7 @@ class TrianglesBatchingPickDepthRenderer extends VBOSceneModelTriangleBatchingRe
39381
39389
  src.push("vFragDepth = 1.0 + clipPos.w;");
39382
39390
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
39383
39391
  }
39384
- src.push("gl_Position = clipPos;");
39392
+ src.push("gl_Position = remapClipPos(clipPos);");
39385
39393
  src.push(" }");
39386
39394
  src.push("}");
39387
39395
  return src;
@@ -39479,6 +39487,8 @@ class TrianglesBatchingPickNormalsRenderer extends VBOSceneModelTriangleBatching
39479
39487
 
39480
39488
  this._addMatricesUniformBlockLines(src);
39481
39489
 
39490
+ this._addRemapClipPosLines(src);
39491
+
39482
39492
  if (scene.logarithmicDepthBufferEnabled) {
39483
39493
  src.push("uniform float logDepthBufFC;");
39484
39494
  src.push("out float vFragDepth;");
@@ -39523,7 +39533,7 @@ class TrianglesBatchingPickNormalsRenderer extends VBOSceneModelTriangleBatching
39523
39533
  src.push("vFragDepth = 1.0 + clipPos.w;");
39524
39534
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
39525
39535
  }
39526
- src.push("gl_Position = clipPos;");
39536
+ src.push("gl_Position = remapClipPos(clipPos);");
39527
39537
  src.push(" }");
39528
39538
  src.push("}");
39529
39539
  return src;
@@ -40626,6 +40636,8 @@ class TrianglesBatchingPickNormalsFlatRenderer extends VBOSceneModelTriangleBatc
40626
40636
 
40627
40637
  this._addMatricesUniformBlockLines(src);
40628
40638
 
40639
+ this._addRemapClipPosLines(src);
40640
+
40629
40641
  if (scene.logarithmicDepthBufferEnabled) {
40630
40642
  src.push("uniform float logDepthBufFC;");
40631
40643
  src.push("out float vFragDepth;");
@@ -40659,7 +40671,7 @@ class TrianglesBatchingPickNormalsFlatRenderer extends VBOSceneModelTriangleBatc
40659
40671
  src.push("vFragDepth = 1.0 + clipPos.w;");
40660
40672
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
40661
40673
  }
40662
- src.push("gl_Position = clipPos;");
40674
+ src.push("gl_Position = remapClipPos(clipPos);");
40663
40675
  src.push(" }");
40664
40676
  src.push("}");
40665
40677
  return src;
@@ -44355,6 +44367,8 @@ class TrianglesInstancingPickMeshRenderer extends VBOSceneModelTriangleInstancin
44355
44367
 
44356
44368
  this._addMatricesUniformBlockLines(src);
44357
44369
 
44370
+ this._addRemapClipPosLines(src);
44371
+
44358
44372
  if (scene.logarithmicDepthBufferEnabled) {
44359
44373
  src.push("uniform float logDepthBufFC;");
44360
44374
  src.push("out float vFragDepth;");
@@ -44399,7 +44413,7 @@ class TrianglesInstancingPickMeshRenderer extends VBOSceneModelTriangleInstancin
44399
44413
  src.push("vFragDepth = 1.0 + clipPos.w;");
44400
44414
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
44401
44415
  }
44402
- src.push("gl_Position = clipPos;");
44416
+ src.push("gl_Position = remapClipPos(clipPos);");
44403
44417
  src.push("}");
44404
44418
  src.push("}");
44405
44419
  return src;
@@ -44489,6 +44503,8 @@ class TrianglesInstancingPickDepthRenderer extends VBOSceneModelTriangleInstanci
44489
44503
 
44490
44504
  this._addMatricesUniformBlockLines(src);
44491
44505
 
44506
+ this._addRemapClipPosLines(src);
44507
+
44492
44508
  if (scene.logarithmicDepthBufferEnabled) {
44493
44509
  src.push("uniform float logDepthBufFC;");
44494
44510
  src.push("out float vFragDepth;");
@@ -44531,7 +44547,7 @@ class TrianglesInstancingPickDepthRenderer extends VBOSceneModelTriangleInstanci
44531
44547
  src.push("vFragDepth = 1.0 + clipPos.w;");
44532
44548
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
44533
44549
  }
44534
- src.push("gl_Position = clipPos;");
44550
+ src.push("gl_Position = remapClipPos(clipPos);");
44535
44551
  src.push("}");
44536
44552
  src.push("}");
44537
44553
  return src;
@@ -44634,6 +44650,8 @@ class TrianglesInstancingPickNormalsRenderer extends VBOSceneModelTriangleInstan
44634
44650
 
44635
44651
  this._addMatricesUniformBlockLines(src);
44636
44652
 
44653
+ this._addRemapClipPosLines(src);
44654
+
44637
44655
  if (scene.logarithmicDepthBufferEnabled) {
44638
44656
  src.push("uniform float logDepthBufFC;");
44639
44657
  src.push("out float vFragDepth;");
@@ -44682,7 +44700,7 @@ class TrianglesInstancingPickNormalsRenderer extends VBOSceneModelTriangleInstan
44682
44700
  src.push("vFragDepth = 1.0 + clipPos.w;");
44683
44701
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
44684
44702
  }
44685
- src.push("gl_Position = clipPos;");
44703
+ src.push("gl_Position = remapClipPos(clipPos);");
44686
44704
  src.push("}");
44687
44705
  src.push("}");
44688
44706
  return src;
@@ -45800,6 +45818,8 @@ class TrianglesInstancingPickNormalsFlatRenderer extends VBOSceneModelTriangleIn
45800
45818
 
45801
45819
  this._addMatricesUniformBlockLines(src);
45802
45820
 
45821
+ this._addRemapClipPosLines(src);
45822
+
45803
45823
  if (scene.logarithmicDepthBufferEnabled) {
45804
45824
  src.push("uniform float logDepthBufFC;");
45805
45825
  src.push("out float vFragDepth;");
@@ -45838,7 +45858,7 @@ class TrianglesInstancingPickNormalsFlatRenderer extends VBOSceneModelTriangleIn
45838
45858
  src.push("vFlags = flags;");
45839
45859
  }
45840
45860
 
45841
- src.push("gl_Position = clipPos;");
45861
+ src.push("gl_Position = remapClipPos(clipPos);");
45842
45862
  src.push("}");
45843
45863
  src.push("}");
45844
45864
  return src;
@@ -50722,6 +50742,8 @@ class PointsBatchingPickMeshRenderer extends VBOSceneModelPointBatchingRenderer
50722
50742
 
50723
50743
  this._addMatricesUniformBlockLines(src);
50724
50744
 
50745
+ this._addRemapClipPosLines(src);
50746
+
50725
50747
  src.push("uniform float pointSize;");
50726
50748
  if (pointsMaterial.perspectivePoints) {
50727
50749
  src.push("uniform float nearPlaneHeight;");
@@ -50763,7 +50785,7 @@ class PointsBatchingPickMeshRenderer extends VBOSceneModelPointBatchingRenderer
50763
50785
  if (scene.logarithmicDepthBufferEnabled) {
50764
50786
  src.push("vFragDepth = 1.0 + clipPos.w;");
50765
50787
  }
50766
- src.push("gl_Position = clipPos;");
50788
+ src.push("gl_Position = remapClipPos(clipPos);");
50767
50789
  if (pointsMaterial.perspectivePoints) {
50768
50790
  src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");
50769
50791
  src.push("gl_PointSize = max(gl_PointSize, " + Math.floor(pointsMaterial.minPerspectivePointSize) + ".0);");
@@ -50862,6 +50884,8 @@ class PointsBatchingPickDepthRenderer extends VBOSceneModelPointBatchingRenderer
50862
50884
 
50863
50885
  this._addMatricesUniformBlockLines(src);
50864
50886
 
50887
+ this._addRemapClipPosLines(src);
50888
+
50865
50889
  src.push("uniform float pointSize;");
50866
50890
  if (pointsMaterial.perspectivePoints) {
50867
50891
  src.push("uniform float nearPlaneHeight;");
@@ -50900,7 +50924,7 @@ class PointsBatchingPickDepthRenderer extends VBOSceneModelPointBatchingRenderer
50900
50924
  if (scene.logarithmicDepthBufferEnabled) {
50901
50925
  src.push("vFragDepth = 1.0 + clipPos.w;");
50902
50926
  }
50903
- src.push("gl_Position = clipPos;");
50927
+ src.push("gl_Position = remapClipPos(clipPos);");
50904
50928
  if (pointsMaterial.perspectivePoints) {
50905
50929
  src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");
50906
50930
  src.push("gl_PointSize = max(gl_PointSize, " + Math.floor(pointsMaterial.minPerspectivePointSize) + ".0);");
@@ -52345,6 +52369,8 @@ class PointsInstancingPickMeshRenderer extends VBOSceneModelPointInstancingRende
52345
52369
 
52346
52370
  this._addMatricesUniformBlockLines(src);
52347
52371
 
52372
+ this._addRemapClipPosLines(src);
52373
+
52348
52374
  src.push("uniform float pointSize;");
52349
52375
  if (pointsMaterial.perspectivePoints) {
52350
52376
  src.push("uniform float nearPlaneHeight;");
@@ -52386,6 +52412,7 @@ class PointsInstancingPickMeshRenderer extends VBOSceneModelPointInstancingRende
52386
52412
  src.push(" vFlags = flags;");
52387
52413
  }
52388
52414
  src.push("vec4 clipPos = projMatrix * viewPosition;");
52415
+ src.push("gl_Position = remapClipPos(clipPos);");
52389
52416
  if (scene.logarithmicDepthBufferEnabled) {
52390
52417
  src.push("vFragDepth = 1.0 + clipPos.w;");
52391
52418
  }
@@ -52496,6 +52523,8 @@ class PointsInstancingPickDepthRenderer extends VBOSceneModelPointInstancingRend
52496
52523
 
52497
52524
  this._addMatricesUniformBlockLines(src);
52498
52525
 
52526
+ this._addRemapClipPosLines(src);
52527
+
52499
52528
  src.push("uniform float pointSize;");
52500
52529
  if (pointsMaterial.perspectivePoints) {
52501
52530
  src.push("uniform float nearPlaneHeight;");
@@ -52535,10 +52564,11 @@ class PointsInstancingPickDepthRenderer extends VBOSceneModelPointInstancingRend
52535
52564
  }
52536
52565
  src.push(" vViewPosition = viewPosition;");
52537
52566
  src.push("vec4 clipPos = projMatrix * viewPosition;");
52567
+ src.push("gl_Position = remapClipPos(clipPos);");
52538
52568
  if (scene.logarithmicDepthBufferEnabled) {
52539
52569
  src.push("vFragDepth = 1.0 + clipPos.w;");
52540
52570
  }
52541
- src.push("gl_Position = clipPos;");
52571
+ src.push("gl_Position = remapClipPos(clipPos);");
52542
52572
  if (pointsMaterial.perspectivePoints) {
52543
52573
  src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");
52544
52574
  src.push("gl_PointSize = max(gl_PointSize, " + Math.floor(pointsMaterial.minPerspectivePointSize) + ".0);");
@@ -57329,7 +57359,7 @@ class TrianglesDataTexturePickMeshRenderer {
57329
57359
 
57330
57360
  getValid() {
57331
57361
  return this._hash === this._getHash();
57332
- };
57362
+ }
57333
57363
 
57334
57364
  _getHash() {
57335
57365
  return this._scene._sectionPlanesState.getHash();
@@ -57390,6 +57420,7 @@ class TrianglesDataTexturePickMeshRenderer {
57390
57420
  rtcViewMatrix = camera.viewMatrix;
57391
57421
  rtcCameraEye = camera.eye;
57392
57422
  }
57423
+ gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos);
57393
57424
  gl.uniformMatrix4fv(this._uSceneModelWorldMatrix, false, rotationMatrixConjugate);
57394
57425
  gl.uniformMatrix4fv(this._uViewMatrix, false, rtcViewMatrix);
57395
57426
  gl.uniformMatrix4fv(this._uProjMatrix, false, camera.projMatrix);
@@ -57463,6 +57494,7 @@ class TrianglesDataTexturePickMeshRenderer {
57463
57494
  const program = this._program;
57464
57495
  this._uRenderPass = program.getLocation("renderPass");
57465
57496
  this._uPickInvisible = program.getLocation("pickInvisible");
57497
+ this._uPickClipPos = program.getLocation("pickClipPos");
57466
57498
  this._uSceneModelWorldMatrix = program.getLocation("sceneModelWorldMatrix");
57467
57499
  this._uViewMatrix = program.getLocation("viewMatrix");
57468
57500
  this._uProjMatrix = program.getLocation("projMatrix");
@@ -57560,6 +57592,15 @@ class TrianglesDataTexturePickMeshRenderer {
57560
57592
  src.push("out float isPerspective;");
57561
57593
  }
57562
57594
 
57595
+ src.push("uniform vec2 pickClipPos;");
57596
+
57597
+ src.push("vec4 remapClipPos(vec4 clipPos) {");
57598
+ src.push(" clipPos.xy /= clipPos.w;");
57599
+ src.push(" clipPos.xy -= pickClipPos;");
57600
+ src.push(" clipPos.xy *= clipPos.w;");
57601
+ src.push(" return clipPos;");
57602
+ src.push("}");
57603
+
57563
57604
  src.push("bool isPerspectiveMatrix(mat4 m) {");
57564
57605
  src.push(" return (m[2][3] == - 1.0);");
57565
57606
  src.push("}");
@@ -57670,7 +57711,7 @@ class TrianglesDataTexturePickMeshRenderer {
57670
57711
  src.push("vFragDepth = 1.0 + clipPos.w;");
57671
57712
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
57672
57713
  }
57673
- src.push("gl_Position = clipPos;");
57714
+ src.push("gl_Position = remapClipPos(clipPos);");
57674
57715
  src.push(" }");
57675
57716
  src.push("}");
57676
57717
  return src;
@@ -57759,7 +57800,7 @@ class TrianglesDataTexturePickDepthRenderer {
57759
57800
 
57760
57801
  getValid() {
57761
57802
  return this._hash === this._getHash();
57762
- };
57803
+ }
57763
57804
 
57764
57805
  _getHash() {
57765
57806
  return this._scene._sectionPlanesState.getHash();
@@ -57833,6 +57874,7 @@ class TrianglesDataTexturePickDepthRenderer {
57833
57874
  gl.uniform3fv(this._uCameraEyeRtc, rtcCameraEye);
57834
57875
  gl.uniform1i(this._uRenderPass, renderPass);
57835
57876
  gl.uniform1i(this._uPickInvisible, frameCtx.pickInvisible);
57877
+ gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos);
57836
57878
  gl.uniform1f(this._uPickZNear, frameCtx.pickZNear);
57837
57879
  gl.uniform1f(this._uPickZFar, frameCtx.pickZFar);
57838
57880
  gl.uniformMatrix4fv(this._uWorldMatrix, false, rotationMatrixConjugate);
@@ -57907,6 +57949,7 @@ class TrianglesDataTexturePickDepthRenderer {
57907
57949
  const program = this._program;
57908
57950
  this._uRenderPass = program.getLocation("renderPass");
57909
57951
  this._uPickInvisible = program.getLocation("pickInvisible");
57952
+ this._uPickClipPos = program.getLocation("pickClipPos");
57910
57953
  this._uWorldMatrix = program.getLocation("worldMatrix");
57911
57954
  this._uViewMatrix = program.getLocation("viewMatrix");
57912
57955
  this._uProjMatrix = program.getLocation("projMatrix");
@@ -57996,6 +58039,15 @@ class TrianglesDataTexturePickDepthRenderer {
57996
58039
  src.push("out float isPerspective;");
57997
58040
  }
57998
58041
 
58042
+ src.push("uniform vec2 pickClipPos;");
58043
+
58044
+ src.push("vec4 remapClipPos(vec4 clipPos) {");
58045
+ src.push(" clipPos.xy /= clipPos.w;");
58046
+ src.push(" clipPos.xy -= pickClipPos;");
58047
+ src.push(" clipPos.xy *= clipPos.w;");
58048
+ src.push(" return clipPos;");
58049
+ src.push("}");
58050
+
57999
58051
  src.push("bool isPerspectiveMatrix(mat4 m) {");
58000
58052
  src.push(" return (m[2][3] == - 1.0);");
58001
58053
  src.push("}");
@@ -58102,7 +58154,7 @@ class TrianglesDataTexturePickDepthRenderer {
58102
58154
  src.push("vFragDepth = 1.0 + clipPos.w;");
58103
58155
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
58104
58156
  }
58105
- src.push("gl_Position = clipPos;");
58157
+ src.push("gl_Position = remapClipPos(clipPos);");
58106
58158
  src.push(" }");
58107
58159
  src.push("}");
58108
58160
  return src;
@@ -59063,7 +59115,7 @@ class TrianglesDataTexturePickNormalsRenderer {
59063
59115
 
59064
59116
  getValid() {
59065
59117
  return this._hash === this._getHash();
59066
- };
59118
+ }
59067
59119
 
59068
59120
  _getHash() {
59069
59121
  return this._scene._sectionPlanesState.getHash();
@@ -59121,6 +59173,7 @@ class TrianglesDataTexturePickNormalsRenderer {
59121
59173
  gl.uniform3fv(this._uCameraEyeRtc, originCameraEye);
59122
59174
 
59123
59175
  gl.uniform1i(this._uPickInvisible, frameCtx.pickInvisible);
59176
+ gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos);
59124
59177
 
59125
59178
  if (scene.logarithmicDepthBufferEnabled) {
59126
59179
  const logDepthBufFC = 2.0 / (Math.log(camera.project.far + 1.0) / Math.LN2); // TODO: Far should be from projection matrix?
@@ -59203,6 +59256,7 @@ class TrianglesDataTexturePickNormalsRenderer {
59203
59256
 
59204
59257
  this._uRenderPass = program.getLocation("renderPass");
59205
59258
  this._uPickInvisible = program.getLocation("pickInvisible");
59259
+ this._uPickClipPos = program.getLocation("pickClipPos");
59206
59260
 
59207
59261
  this._uSectionPlanes = [];
59208
59262
 
@@ -59287,6 +59341,15 @@ class TrianglesDataTexturePickNormalsRenderer {
59287
59341
  src.push("out float isPerspective;");
59288
59342
  }
59289
59343
 
59344
+ src.push("uniform vec2 pickClipPos;");
59345
+
59346
+ src.push("vec4 remapClipPos(vec4 clipPos) {");
59347
+ src.push(" clipPos.xy /= clipPos.w;");
59348
+ src.push(" clipPos.xy -= pickClipPos;");
59349
+ src.push(" clipPos.xy *= clipPos.w;");
59350
+ src.push(" return clipPos;");
59351
+ src.push("}");
59352
+
59290
59353
  src.push("bool isPerspectiveMatrix(mat4 m) {");
59291
59354
  src.push(" return (m[2][3] == - 1.0);");
59292
59355
  src.push("}");
@@ -59401,7 +59464,7 @@ class TrianglesDataTexturePickNormalsRenderer {
59401
59464
  src.push(" vWorldPosition = worldPosition;");
59402
59465
  src.push(" vFlags2 = flags2.w;");
59403
59466
  }
59404
- src.push("gl_Position = clipPos;");
59467
+ src.push("gl_Position = remapClipPos(clipPos);");
59405
59468
  src.push("}");
59406
59469
 
59407
59470
  src.push("}");
@@ -60696,7 +60759,7 @@ class TrianglesDataTexturePickNormalsFlatRenderer {
60696
60759
 
60697
60760
  getValid() {
60698
60761
  return this._hash === this._getHash();
60699
- };
60762
+ }
60700
60763
 
60701
60764
  _getHash() {
60702
60765
  return this._scene._sectionPlanesState.getHash();
@@ -60769,6 +60832,7 @@ class TrianglesDataTexturePickNormalsFlatRenderer {
60769
60832
 
60770
60833
  gl.uniform1i(this._uRenderPass, renderPass);
60771
60834
  gl.uniform1i(this._uPickInvisible, frameCtx.pickInvisible);
60835
+ gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos);
60772
60836
 
60773
60837
  gl.uniformMatrix4fv(this._uWorldMatrix, false, model.worldMatrix);
60774
60838
 
@@ -60937,6 +61001,7 @@ class TrianglesDataTexturePickNormalsFlatRenderer {
60937
61001
 
60938
61002
  this._uRenderPass = program.getLocation("renderPass");
60939
61003
  this._uPickInvisible = program.getLocation("pickInvisible");
61004
+ this._uPickClipPos = program.getLocation("pickClipPos");
60940
61005
  this._uPositionsDecodeMatrix = program.getLocation("positionsDecodeMatrix");
60941
61006
  this._uWorldMatrix = program.getLocation("worldMatrix");
60942
61007
  this._uViewMatrix = program.getLocation("viewMatrix");
@@ -61026,6 +61091,16 @@ class TrianglesDataTexturePickNormalsFlatRenderer {
61026
61091
  src.push("}");
61027
61092
  src.push("out float isPerspective;");
61028
61093
  }
61094
+
61095
+ src.push("uniform vec2 pickClipPos;");
61096
+
61097
+ src.push("vec4 remapClipPos(vec4 clipPos) {");
61098
+ src.push(" clipPos.xy /= clipPos.w;");
61099
+ src.push(" clipPos.xy -= pickClipPos;");
61100
+ src.push(" clipPos.xy *= clipPos.w;");
61101
+ src.push(" return clipPos;");
61102
+ src.push("}");
61103
+
61029
61104
  src.push("out vec4 vWorldPosition;");
61030
61105
  if (clipping) {
61031
61106
  src.push("out int vFlags2;");
@@ -61104,7 +61179,7 @@ class TrianglesDataTexturePickNormalsFlatRenderer {
61104
61179
  src.push("vFragDepth = 1.0 + clipPos.w;");
61105
61180
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
61106
61181
  }
61107
- src.push("gl_Position = clipPos;");
61182
+ src.push("gl_Position = remapClipPos(clipPos);");
61108
61183
  src.push(" }");
61109
61184
  src.push("}");
61110
61185
  return src;
@@ -73630,10 +73705,10 @@ const Renderer$1 = function (scene, options) {
73630
73705
  * Picks an Entity.
73631
73706
  * @private
73632
73707
  */
73633
- this.pick = (function () {
73708
+ this.pick = (function () {
73634
73709
 
73635
73710
  const tempVec3a = math.vec3();
73636
- const tempMat4a = math.mat4();
73711
+ math.mat4();
73637
73712
  const tempMat4b = math.mat4();
73638
73713
 
73639
73714
  const randomVec3 = math.vec3();
@@ -73675,13 +73750,11 @@ const Renderer$1 = function (scene, options) {
73675
73750
 
73676
73751
  // Picking with arbitrary World-space ray
73677
73752
  // Align camera along ray and fire ray through center of canvas
73678
-
73679
- const pickFrustumMatrix = math.frustumMat4(-1, 1, -1, 1, 0.01, scene.camera.project.far, tempMat4a);
73680
-
73753
+
73681
73754
  if (params.matrix) {
73682
73755
 
73683
73756
  pickViewMatrix = params.matrix;
73684
- pickProjMatrix = pickFrustumMatrix;
73757
+ pickProjMatrix = scene.camera.projMatrix;
73685
73758
 
73686
73759
  } else {
73687
73760
 
@@ -73698,7 +73771,7 @@ const Renderer$1 = function (scene, options) {
73698
73771
  math.cross3Vec3(worldRayDir, randomVec3, up);
73699
73772
 
73700
73773
  pickViewMatrix = math.lookAtMat4v(worldRayOrigin, look, up, tempMat4b);
73701
- pickProjMatrix = pickFrustumMatrix;
73774
+ pickProjMatrix = scene.camera.projMatrix;
73702
73775
 
73703
73776
  pickResult.origin = worldRayOrigin;
73704
73777
  pickResult.direction = worldRayDir;
@@ -73720,7 +73793,7 @@ const Renderer$1 = function (scene, options) {
73720
73793
  }
73721
73794
  }
73722
73795
 
73723
- const pickBuffer = renderBufferManager.getRenderBuffer("pick");
73796
+ const pickBuffer = renderBufferManager.getRenderBuffer("pick", { size: [1, 1] });
73724
73797
 
73725
73798
  pickBuffer.bind();
73726
73799
 
@@ -73782,10 +73855,12 @@ const Renderer$1 = function (scene, options) {
73782
73855
  frameCtx.pickViewMatrix = pickViewMatrix;
73783
73856
  frameCtx.pickProjMatrix = pickProjMatrix;
73784
73857
  frameCtx.pickInvisible = !!params.pickInvisible;
73858
+ frameCtx.pickClipPos = [
73859
+ getClipPosX(canvasPos[0], gl.drawingBufferWidth),
73860
+ getClipPosY(canvasPos[1], gl.drawingBufferHeight),
73861
+ ];
73785
73862
 
73786
- gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
73787
-
73788
- gl.clearColor(0, 0, 0, 0);
73863
+ gl.viewport(0, 0, 1, 1);
73789
73864
  gl.depthMask(true);
73790
73865
  gl.enable(gl.DEPTH_TEST);
73791
73866
  gl.disable(gl.CULL_FACE);
@@ -73819,8 +73894,7 @@ const Renderer$1 = function (scene, options) {
73819
73894
  }
73820
73895
  }
73821
73896
  }
73822
- const resolutionScale = scene.canvas.resolutionScale;
73823
- const pix = pickBuffer.read(Math.round(canvasPos[0] * resolutionScale), Math.round(canvasPos[1] * resolutionScale));
73897
+ const pix = pickBuffer.read(0, 0);
73824
73898
  let pickID = pix[0] + (pix[1] * 256) + (pix[2] * 256 * 256) + (pix[3] * 256 * 256 * 256);
73825
73899
 
73826
73900
  if (pickID < 0) {
@@ -73845,8 +73919,12 @@ const Renderer$1 = function (scene, options) {
73845
73919
  frameCtx.pickViewMatrix = pickViewMatrix; // Can be null
73846
73920
  frameCtx.pickProjMatrix = pickProjMatrix; // Can be null
73847
73921
  // frameCtx.pickInvisible = !!params.pickInvisible;
73922
+ frameCtx.pickClipPos = [
73923
+ getClipPosX(canvasPos[0], gl.drawingBufferWidth),
73924
+ getClipPosY(canvasPos[1], gl.drawingBufferHeight),
73925
+ ];
73848
73926
 
73849
- gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
73927
+ gl.viewport(0, 0, 1, 1);
73850
73928
 
73851
73929
  gl.clearColor(0, 0, 0, 0);
73852
73930
  gl.enable(gl.DEPTH_TEST);
@@ -73856,8 +73934,7 @@ const Renderer$1 = function (scene, options) {
73856
73934
 
73857
73935
  pickable.drawPickTriangles(frameCtx);
73858
73936
 
73859
- const resolutionScale = scene.canvas.resolutionScale;
73860
- const pix = pickBuffer.read(Math.round(canvasPos[0] * resolutionScale), Math.round(canvasPos[1] * resolutionScale));
73937
+ const pix = pickBuffer.read(0, 0);
73861
73938
 
73862
73939
  let primIndex = pix[0] + (pix[1] * 256) + (pix[2] * 256 * 256) + (pix[3] * 256 * 256 * 256);
73863
73940
 
@@ -73889,8 +73966,12 @@ const Renderer$1 = function (scene, options) {
73889
73966
  frameCtx.pickZFar = nearAndFar[1];
73890
73967
  frameCtx.pickElementsCount = pickable.pickElementsCount;
73891
73968
  frameCtx.pickElementsOffset = pickable.pickElementsOffset;
73892
-
73893
- gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
73969
+ frameCtx.pickClipPos = [
73970
+ getClipPosX(canvasPos[0], gl.drawingBufferWidth),
73971
+ getClipPosY(canvasPos[1], gl.drawingBufferHeight),
73972
+ ];
73973
+
73974
+ gl.viewport(0, 0, 1, 1);
73894
73975
 
73895
73976
  gl.clearColor(0, 0, 0, 0);
73896
73977
  gl.depthMask(true);
@@ -73901,8 +73982,7 @@ const Renderer$1 = function (scene, options) {
73901
73982
 
73902
73983
  pickable.drawPickDepths(frameCtx); // Draw color-encoded fragment screen-space depths
73903
73984
 
73904
- const resolutionScale = scene.canvas.resolutionScale;
73905
- const pix = pickBuffer.read(Math.round(canvasPos[0] * resolutionScale), Math.round(canvasPos[1] * resolutionScale));
73985
+ const pix = pickBuffer.read(0, 0);
73906
73986
 
73907
73987
  const screenZ = unpackDepth(pix); // Get screen-space Z at the given canvas coords
73908
73988
 
@@ -74203,12 +74283,12 @@ const Renderer$1 = function (scene, options) {
74203
74283
  frameCtx.pickOrigin = pickResult.origin;
74204
74284
  frameCtx.pickViewMatrix = pickViewMatrix;
74205
74285
  frameCtx.pickProjMatrix = pickProjMatrix;
74286
+ frameCtx.pickClipPos = [
74287
+ getClipPosX(canvasPos[0], gl.drawingBufferWidth),
74288
+ getClipPosY(canvasPos[1], gl.drawingBufferHeight),
74289
+ ];
74206
74290
 
74207
- const pickNormalBuffer = renderBufferManager.getRenderBuffer("pick-normal");
74208
-
74209
- pickNormalBuffer.bind(gl.RGBA32I);
74210
-
74211
- gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
74291
+ gl.viewport(0, 0, 1, 1);
74212
74292
 
74213
74293
  gl.enable(gl.DEPTH_TEST);
74214
74294
  gl.disable(gl.CULL_FACE);
@@ -74218,10 +74298,7 @@ const Renderer$1 = function (scene, options) {
74218
74298
 
74219
74299
  pickable.drawPickNormals(frameCtx); // Draw color-encoded fragment World-space normals
74220
74300
 
74221
- const resolutionScale = scene.canvas.resolutionScale;
74222
- const pix = pickNormalBuffer.read(Math.round(canvasPos[0] * resolutionScale), Math.round(canvasPos[1] * resolutionScale), gl.RGBA_INTEGER, gl.INT, Int32Array, 4);
74223
-
74224
- pickNormalBuffer.unbind();
74301
+ const pix = pickBuffer.read(0, 0);
74225
74302
 
74226
74303
  const worldNormal = [
74227
74304
  pix[0] / math.MAX_INT,