@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
@@ -23996,6 +23996,16 @@ function buildVertex$3(mesh) {
23996
23996
  src.push(" mat[2][2] =1.0;");
23997
23997
  src.push("}");
23998
23998
  }
23999
+
24000
+ src.push("uniform vec2 pickClipPos;");
24001
+
24002
+ src.push("vec4 remapClipPos(vec4 clipPos) {");
24003
+ src.push(" clipPos.xy /= clipPos.w;");
24004
+ src.push(" clipPos.xy -= pickClipPos;");
24005
+ src.push(" clipPos.xy *= clipPos.w;");
24006
+ src.push(" return clipPos;");
24007
+ src.push("}");
24008
+
23999
24009
  src.push("void main(void) {");
24000
24010
  src.push("vec4 localPosition = vec4(position, 1.0); ");
24001
24011
  if (quantizedGeometry) {
@@ -24022,7 +24032,7 @@ function buildVertex$3(mesh) {
24022
24032
  src.push("vFragDepth = 1.0 + clipPos.w;");
24023
24033
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
24024
24034
  }
24025
- src.push("gl_Position = clipPos;");
24035
+ src.push("gl_Position = remapClipPos(clipPos);");
24026
24036
  src.push("}");
24027
24037
  return src;
24028
24038
  }
@@ -24225,6 +24235,8 @@ PickMeshRenderer.prototype.drawMesh = function (frameCtx, mesh) {
24225
24235
  const r = pickID & 0xFF;
24226
24236
  gl.uniform4f(this._uPickColor, r / 255, g / 255, b / 255, a / 255);
24227
24237
 
24238
+ gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos);
24239
+
24228
24240
  if (geometryState.indicesBuf) {
24229
24241
  gl.drawElements(geometryState.primitive, geometryState.indicesBuf.numItems, geometryState.indicesBuf.itemType, 0);
24230
24242
  frameCtx.drawElements++;
@@ -24258,6 +24270,7 @@ PickMeshRenderer.prototype._allocate = function (mesh) {
24258
24270
  this._aPosition = program.getAttribute("position");
24259
24271
  this._uClippable = program.getLocation("clippable");
24260
24272
  this._uPickColor = program.getLocation("pickColor");
24273
+ this._uPickClipPos = program.getLocation("pickClipPos");
24261
24274
  this._uOffset = program.getLocation("offset");
24262
24275
  if (scene.logarithmicDepthBufferEnabled ) {
24263
24276
  this._uLogDepthBufFC = program.getLocation("logDepthBufFC");
@@ -24295,8 +24308,6 @@ function buildVertex$2(mesh) {
24295
24308
  const scene = mesh.scene;
24296
24309
  const clipping = scene._sectionPlanesState.sectionPlanes.length > 0;
24297
24310
  const quantizedGeometry = !!mesh._geometry._state.compressGeometry;
24298
- mesh._state.billboard;
24299
- mesh._state.stationary;
24300
24311
  const src = [];
24301
24312
  src.push('#version 300 es');
24302
24313
  src.push("// Surface picking vertex shader");
@@ -24318,6 +24329,16 @@ function buildVertex$2(mesh) {
24318
24329
  src.push("}");
24319
24330
  src.push("out float isPerspective;");
24320
24331
  }
24332
+
24333
+ src.push("uniform vec2 pickClipPos;");
24334
+
24335
+ src.push("vec4 remapClipPos(vec4 clipPos) {");
24336
+ src.push(" clipPos.xy /= clipPos.w;");
24337
+ src.push(" clipPos.xy -= pickClipPos;");
24338
+ src.push(" clipPos.xy *= clipPos.w;");
24339
+ src.push(" return clipPos;");
24340
+ src.push("}");
24341
+
24321
24342
  src.push("out vec4 vColor;");
24322
24343
  if (quantizedGeometry) {
24323
24344
  src.push("uniform mat4 positionsDecodeMatrix;");
@@ -24339,7 +24360,7 @@ function buildVertex$2(mesh) {
24339
24360
  src.push("vFragDepth = 1.0 + clipPos.w;");
24340
24361
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
24341
24362
  }
24342
- src.push("gl_Position = clipPos;");
24363
+ src.push("gl_Position = remapClipPos(clipPos);");
24343
24364
  src.push("}");
24344
24365
  return src;
24345
24366
  }
@@ -24532,6 +24553,9 @@ PickTriangleRenderer.prototype.drawMesh = function (frameCtx, mesh) {
24532
24553
  } else {
24533
24554
  this._aPosition.bindArrayBuffer(positionsBuf);
24534
24555
  }
24556
+
24557
+ gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos);
24558
+
24535
24559
  pickColorsBuf.bind();
24536
24560
  gl.enableVertexAttribArray(this._aColor.location);
24537
24561
  gl.vertexAttribPointer(this._aColor.location, pickColorsBuf.itemSize, pickColorsBuf.itemType, true, 0, 0); // Normalize
@@ -24563,6 +24587,7 @@ PickTriangleRenderer.prototype._allocate = function (mesh) {
24563
24587
  }
24564
24588
  this._aPosition = program.getAttribute("position");
24565
24589
  this._aColor = program.getAttribute("color");
24590
+ this._uPickClipPos = program.getLocation("pickClipPos");
24566
24591
  this._uClippable = program.getLocation("clippable");
24567
24592
  this._uOffset = program.getLocation("offset");
24568
24593
  if (scene.logarithmicDepthBufferEnabled ) {
@@ -34353,7 +34378,7 @@ class RenderBuffer {
34353
34378
 
34354
34379
  read(pickX, pickY, glFormat = null, glType = null, arrayType = Uint8Array, arrayMultiplier = 4) {
34355
34380
  const x = pickX;
34356
- const y = (this.buffer.height || this.gl.drawingBufferHeight) - pickY;
34381
+ const y = this.buffer.height ? (this.buffer.height - pickY - 1) : (this.gl.drawingBufferHeight - pickY);
34357
34382
  const pix = new arrayType(arrayMultiplier);
34358
34383
  const gl = this.gl;
34359
34384
  gl.readPixels(x, y, 1, 1, glFormat || gl.RGBA, glType || gl.UNSIGNED_BYTE, pix, 0);
@@ -37541,7 +37566,6 @@ const edgesDefaultColor = new Float32Array([0, 0, 0, 1]);
37541
37566
 
37542
37567
  const tempVec4 = math.vec4();
37543
37568
  const tempVec3a$w = math.vec3();
37544
- math.vec3();
37545
37569
  const tempVec3c$n = math.vec3();
37546
37570
  const tempMat4a$f = math.mat4();
37547
37571
 
@@ -37614,6 +37638,18 @@ class VBOSceneModelRenderer {
37614
37638
  return src;
37615
37639
  }
37616
37640
 
37641
+ _addRemapClipPosLines(src) {
37642
+ src.push("uniform vec2 pickClipPos;");
37643
+
37644
+ src.push("vec4 remapClipPos(vec4 clipPos) {");
37645
+ src.push(" clipPos.xy /= clipPos.w;");
37646
+ src.push(" clipPos.xy -= pickClipPos;");
37647
+ src.push(" clipPos.xy *= clipPos.w;");
37648
+ src.push(" return clipPos;");
37649
+ src.push("}");
37650
+ return src;
37651
+ }
37652
+
37617
37653
  getValid() {
37618
37654
  return this._hash === this._getHash();
37619
37655
  }
@@ -37747,6 +37783,7 @@ class VBOSceneModelRenderer {
37747
37783
  this._aPickColor = program.getAttribute("pickColor");
37748
37784
  this._uPickZNear = program.getLocation("pickZNear");
37749
37785
  this._uPickZFar = program.getLocation("pickZFar");
37786
+ this._uPickClipPos = program.getLocation("pickClipPos");
37750
37787
 
37751
37788
  this._uColorMap = "uColorMap";
37752
37789
  this._uMetallicRoughMap = "uMetallicRoughMap";
@@ -37787,7 +37824,6 @@ class VBOSceneModelRenderer {
37787
37824
  const program = this._program;
37788
37825
  const lightsState = scene._lightsState;
37789
37826
  const lights = lightsState.lights;
37790
- const project = scene.camera.project;
37791
37827
 
37792
37828
  program.bind();
37793
37829
 
@@ -37814,43 +37850,6 @@ class VBOSceneModelRenderer {
37814
37850
  gl.uniform3fv(this._uLightDir[i], light.dir);
37815
37851
  }
37816
37852
  }
37817
-
37818
- if (this._withSAO) {
37819
- const sao = scene.sao;
37820
- const saoEnabled = sao.possible;
37821
- if (saoEnabled) {
37822
- const viewportWidth = gl.drawingBufferWidth;
37823
- const viewportHeight = gl.drawingBufferHeight;
37824
- tempVec4[0] = viewportWidth;
37825
- tempVec4[1] = viewportHeight;
37826
- tempVec4[2] = sao.blendCutoff;
37827
- tempVec4[3] = sao.blendFactor;
37828
- gl.uniform4fv(this._uSAOParams, tempVec4);
37829
- this._program.bindTexture(this._uOcclusionTexture, frameCtx.occlusionTexture, 0);
37830
- }
37831
- }
37832
-
37833
- if (scene.logarithmicDepthBufferEnabled) {
37834
- const logDepthBufFC = 2.0 / (Math.log(project.far + 1.0) / Math.LN2);
37835
- gl.uniform1f(this._uLogDepthBufFC, logDepthBufFC);
37836
- }
37837
-
37838
- if (this._uGammaFactor) {
37839
- gl.uniform1f(this._uGammaFactor, scene.gammaFactor);
37840
- }
37841
-
37842
- if (this._uPickInvisible) {
37843
- gl.uniform1i(this._uPickInvisible, frameCtx.pickInvisible);
37844
- }
37845
-
37846
-
37847
- if (this._uShadowViewMatrix) {
37848
- gl.uniformMatrix4fv(this._uShadowViewMatrix, false, frameCtx.shadowViewMatrix);
37849
- }
37850
-
37851
- if (this._uShadowProjMatrix) {
37852
- gl.uniformMatrix4fv(this._uShadowProjMatrix, false, frameCtx.shadowProjMatrix);
37853
- }
37854
37853
  }
37855
37854
 
37856
37855
  _makeVAO(state) {
@@ -38047,6 +38046,10 @@ class VBOSceneModelRenderer {
38047
38046
  gl.uniform1f(this._uPickZFar, frameCtx.pickZFar);
38048
38047
  }
38049
38048
 
38049
+ if (this._uPickClipPos) {
38050
+ gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos);
38051
+ }
38052
+
38050
38053
  if (this._uPositionsDecodeMatrix) {
38051
38054
  gl.uniformMatrix4fv(this._uPositionsDecodeMatrix, false, state.positionsDecodeMatrix);
38052
38055
  }
@@ -39226,6 +39229,8 @@ class TrianglesBatchingPickMeshRenderer extends VBOSceneModelTriangleBatchingRen
39226
39229
  src.push("out float vFlags;");
39227
39230
  }
39228
39231
 
39232
+ this._addRemapClipPosLines(src);
39233
+
39229
39234
  src.push("out vec4 vPickColor;");
39230
39235
 
39231
39236
  src.push("void main(void) {");
@@ -39253,7 +39258,7 @@ class TrianglesBatchingPickMeshRenderer extends VBOSceneModelTriangleBatchingRen
39253
39258
  src.push("vFragDepth = 1.0 + clipPos.w;");
39254
39259
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
39255
39260
  }
39256
- src.push("gl_Position = clipPos;");
39261
+ src.push("gl_Position = remapClipPos(clipPos);");
39257
39262
  src.push(" }");
39258
39263
  src.push("}");
39259
39264
  return src;
@@ -39352,6 +39357,9 @@ class TrianglesBatchingPickDepthRenderer extends VBOSceneModelTriangleBatchingRe
39352
39357
  src.push("out vec4 vWorldPosition;");
39353
39358
  src.push("out float vFlags;");
39354
39359
  }
39360
+
39361
+ this._addRemapClipPosLines(src);
39362
+
39355
39363
  src.push("out vec4 vViewPosition;");
39356
39364
  src.push("void main(void) {");
39357
39365
 
@@ -39377,7 +39385,7 @@ class TrianglesBatchingPickDepthRenderer extends VBOSceneModelTriangleBatchingRe
39377
39385
  src.push("vFragDepth = 1.0 + clipPos.w;");
39378
39386
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
39379
39387
  }
39380
- src.push("gl_Position = clipPos;");
39388
+ src.push("gl_Position = remapClipPos(clipPos);");
39381
39389
  src.push(" }");
39382
39390
  src.push("}");
39383
39391
  return src;
@@ -39475,6 +39483,8 @@ class TrianglesBatchingPickNormalsRenderer extends VBOSceneModelTriangleBatching
39475
39483
 
39476
39484
  this._addMatricesUniformBlockLines(src);
39477
39485
 
39486
+ this._addRemapClipPosLines(src);
39487
+
39478
39488
  if (scene.logarithmicDepthBufferEnabled) {
39479
39489
  src.push("uniform float logDepthBufFC;");
39480
39490
  src.push("out float vFragDepth;");
@@ -39519,7 +39529,7 @@ class TrianglesBatchingPickNormalsRenderer extends VBOSceneModelTriangleBatching
39519
39529
  src.push("vFragDepth = 1.0 + clipPos.w;");
39520
39530
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
39521
39531
  }
39522
- src.push("gl_Position = clipPos;");
39532
+ src.push("gl_Position = remapClipPos(clipPos);");
39523
39533
  src.push(" }");
39524
39534
  src.push("}");
39525
39535
  return src;
@@ -40622,6 +40632,8 @@ class TrianglesBatchingPickNormalsFlatRenderer extends VBOSceneModelTriangleBatc
40622
40632
 
40623
40633
  this._addMatricesUniformBlockLines(src);
40624
40634
 
40635
+ this._addRemapClipPosLines(src);
40636
+
40625
40637
  if (scene.logarithmicDepthBufferEnabled) {
40626
40638
  src.push("uniform float logDepthBufFC;");
40627
40639
  src.push("out float vFragDepth;");
@@ -40655,7 +40667,7 @@ class TrianglesBatchingPickNormalsFlatRenderer extends VBOSceneModelTriangleBatc
40655
40667
  src.push("vFragDepth = 1.0 + clipPos.w;");
40656
40668
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
40657
40669
  }
40658
- src.push("gl_Position = clipPos;");
40670
+ src.push("gl_Position = remapClipPos(clipPos);");
40659
40671
  src.push(" }");
40660
40672
  src.push("}");
40661
40673
  return src;
@@ -44351,6 +44363,8 @@ class TrianglesInstancingPickMeshRenderer extends VBOSceneModelTriangleInstancin
44351
44363
 
44352
44364
  this._addMatricesUniformBlockLines(src);
44353
44365
 
44366
+ this._addRemapClipPosLines(src);
44367
+
44354
44368
  if (scene.logarithmicDepthBufferEnabled) {
44355
44369
  src.push("uniform float logDepthBufFC;");
44356
44370
  src.push("out float vFragDepth;");
@@ -44395,7 +44409,7 @@ class TrianglesInstancingPickMeshRenderer extends VBOSceneModelTriangleInstancin
44395
44409
  src.push("vFragDepth = 1.0 + clipPos.w;");
44396
44410
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
44397
44411
  }
44398
- src.push("gl_Position = clipPos;");
44412
+ src.push("gl_Position = remapClipPos(clipPos);");
44399
44413
  src.push("}");
44400
44414
  src.push("}");
44401
44415
  return src;
@@ -44485,6 +44499,8 @@ class TrianglesInstancingPickDepthRenderer extends VBOSceneModelTriangleInstanci
44485
44499
 
44486
44500
  this._addMatricesUniformBlockLines(src);
44487
44501
 
44502
+ this._addRemapClipPosLines(src);
44503
+
44488
44504
  if (scene.logarithmicDepthBufferEnabled) {
44489
44505
  src.push("uniform float logDepthBufFC;");
44490
44506
  src.push("out float vFragDepth;");
@@ -44527,7 +44543,7 @@ class TrianglesInstancingPickDepthRenderer extends VBOSceneModelTriangleInstanci
44527
44543
  src.push("vFragDepth = 1.0 + clipPos.w;");
44528
44544
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
44529
44545
  }
44530
- src.push("gl_Position = clipPos;");
44546
+ src.push("gl_Position = remapClipPos(clipPos);");
44531
44547
  src.push("}");
44532
44548
  src.push("}");
44533
44549
  return src;
@@ -44630,6 +44646,8 @@ class TrianglesInstancingPickNormalsRenderer extends VBOSceneModelTriangleInstan
44630
44646
 
44631
44647
  this._addMatricesUniformBlockLines(src);
44632
44648
 
44649
+ this._addRemapClipPosLines(src);
44650
+
44633
44651
  if (scene.logarithmicDepthBufferEnabled) {
44634
44652
  src.push("uniform float logDepthBufFC;");
44635
44653
  src.push("out float vFragDepth;");
@@ -44678,7 +44696,7 @@ class TrianglesInstancingPickNormalsRenderer extends VBOSceneModelTriangleInstan
44678
44696
  src.push("vFragDepth = 1.0 + clipPos.w;");
44679
44697
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
44680
44698
  }
44681
- src.push("gl_Position = clipPos;");
44699
+ src.push("gl_Position = remapClipPos(clipPos);");
44682
44700
  src.push("}");
44683
44701
  src.push("}");
44684
44702
  return src;
@@ -45796,6 +45814,8 @@ class TrianglesInstancingPickNormalsFlatRenderer extends VBOSceneModelTriangleIn
45796
45814
 
45797
45815
  this._addMatricesUniformBlockLines(src);
45798
45816
 
45817
+ this._addRemapClipPosLines(src);
45818
+
45799
45819
  if (scene.logarithmicDepthBufferEnabled) {
45800
45820
  src.push("uniform float logDepthBufFC;");
45801
45821
  src.push("out float vFragDepth;");
@@ -45834,7 +45854,7 @@ class TrianglesInstancingPickNormalsFlatRenderer extends VBOSceneModelTriangleIn
45834
45854
  src.push("vFlags = flags;");
45835
45855
  }
45836
45856
 
45837
- src.push("gl_Position = clipPos;");
45857
+ src.push("gl_Position = remapClipPos(clipPos);");
45838
45858
  src.push("}");
45839
45859
  src.push("}");
45840
45860
  return src;
@@ -50718,6 +50738,8 @@ class PointsBatchingPickMeshRenderer extends VBOSceneModelPointBatchingRenderer
50718
50738
 
50719
50739
  this._addMatricesUniformBlockLines(src);
50720
50740
 
50741
+ this._addRemapClipPosLines(src);
50742
+
50721
50743
  src.push("uniform float pointSize;");
50722
50744
  if (pointsMaterial.perspectivePoints) {
50723
50745
  src.push("uniform float nearPlaneHeight;");
@@ -50759,7 +50781,7 @@ class PointsBatchingPickMeshRenderer extends VBOSceneModelPointBatchingRenderer
50759
50781
  if (scene.logarithmicDepthBufferEnabled) {
50760
50782
  src.push("vFragDepth = 1.0 + clipPos.w;");
50761
50783
  }
50762
- src.push("gl_Position = clipPos;");
50784
+ src.push("gl_Position = remapClipPos(clipPos);");
50763
50785
  if (pointsMaterial.perspectivePoints) {
50764
50786
  src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");
50765
50787
  src.push("gl_PointSize = max(gl_PointSize, " + Math.floor(pointsMaterial.minPerspectivePointSize) + ".0);");
@@ -50858,6 +50880,8 @@ class PointsBatchingPickDepthRenderer extends VBOSceneModelPointBatchingRenderer
50858
50880
 
50859
50881
  this._addMatricesUniformBlockLines(src);
50860
50882
 
50883
+ this._addRemapClipPosLines(src);
50884
+
50861
50885
  src.push("uniform float pointSize;");
50862
50886
  if (pointsMaterial.perspectivePoints) {
50863
50887
  src.push("uniform float nearPlaneHeight;");
@@ -50896,7 +50920,7 @@ class PointsBatchingPickDepthRenderer extends VBOSceneModelPointBatchingRenderer
50896
50920
  if (scene.logarithmicDepthBufferEnabled) {
50897
50921
  src.push("vFragDepth = 1.0 + clipPos.w;");
50898
50922
  }
50899
- src.push("gl_Position = clipPos;");
50923
+ src.push("gl_Position = remapClipPos(clipPos);");
50900
50924
  if (pointsMaterial.perspectivePoints) {
50901
50925
  src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");
50902
50926
  src.push("gl_PointSize = max(gl_PointSize, " + Math.floor(pointsMaterial.minPerspectivePointSize) + ".0);");
@@ -52341,6 +52365,8 @@ class PointsInstancingPickMeshRenderer extends VBOSceneModelPointInstancingRende
52341
52365
 
52342
52366
  this._addMatricesUniformBlockLines(src);
52343
52367
 
52368
+ this._addRemapClipPosLines(src);
52369
+
52344
52370
  src.push("uniform float pointSize;");
52345
52371
  if (pointsMaterial.perspectivePoints) {
52346
52372
  src.push("uniform float nearPlaneHeight;");
@@ -52382,6 +52408,7 @@ class PointsInstancingPickMeshRenderer extends VBOSceneModelPointInstancingRende
52382
52408
  src.push(" vFlags = flags;");
52383
52409
  }
52384
52410
  src.push("vec4 clipPos = projMatrix * viewPosition;");
52411
+ src.push("gl_Position = remapClipPos(clipPos);");
52385
52412
  if (scene.logarithmicDepthBufferEnabled) {
52386
52413
  src.push("vFragDepth = 1.0 + clipPos.w;");
52387
52414
  }
@@ -52492,6 +52519,8 @@ class PointsInstancingPickDepthRenderer extends VBOSceneModelPointInstancingRend
52492
52519
 
52493
52520
  this._addMatricesUniformBlockLines(src);
52494
52521
 
52522
+ this._addRemapClipPosLines(src);
52523
+
52495
52524
  src.push("uniform float pointSize;");
52496
52525
  if (pointsMaterial.perspectivePoints) {
52497
52526
  src.push("uniform float nearPlaneHeight;");
@@ -52531,10 +52560,11 @@ class PointsInstancingPickDepthRenderer extends VBOSceneModelPointInstancingRend
52531
52560
  }
52532
52561
  src.push(" vViewPosition = viewPosition;");
52533
52562
  src.push("vec4 clipPos = projMatrix * viewPosition;");
52563
+ src.push("gl_Position = remapClipPos(clipPos);");
52534
52564
  if (scene.logarithmicDepthBufferEnabled) {
52535
52565
  src.push("vFragDepth = 1.0 + clipPos.w;");
52536
52566
  }
52537
- src.push("gl_Position = clipPos;");
52567
+ src.push("gl_Position = remapClipPos(clipPos);");
52538
52568
  if (pointsMaterial.perspectivePoints) {
52539
52569
  src.push("gl_PointSize = (nearPlaneHeight * pointSize) / clipPos.w;");
52540
52570
  src.push("gl_PointSize = max(gl_PointSize, " + Math.floor(pointsMaterial.minPerspectivePointSize) + ".0);");
@@ -57325,7 +57355,7 @@ class TrianglesDataTexturePickMeshRenderer {
57325
57355
 
57326
57356
  getValid() {
57327
57357
  return this._hash === this._getHash();
57328
- };
57358
+ }
57329
57359
 
57330
57360
  _getHash() {
57331
57361
  return this._scene._sectionPlanesState.getHash();
@@ -57386,6 +57416,7 @@ class TrianglesDataTexturePickMeshRenderer {
57386
57416
  rtcViewMatrix = camera.viewMatrix;
57387
57417
  rtcCameraEye = camera.eye;
57388
57418
  }
57419
+ gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos);
57389
57420
  gl.uniformMatrix4fv(this._uSceneModelWorldMatrix, false, rotationMatrixConjugate);
57390
57421
  gl.uniformMatrix4fv(this._uViewMatrix, false, rtcViewMatrix);
57391
57422
  gl.uniformMatrix4fv(this._uProjMatrix, false, camera.projMatrix);
@@ -57459,6 +57490,7 @@ class TrianglesDataTexturePickMeshRenderer {
57459
57490
  const program = this._program;
57460
57491
  this._uRenderPass = program.getLocation("renderPass");
57461
57492
  this._uPickInvisible = program.getLocation("pickInvisible");
57493
+ this._uPickClipPos = program.getLocation("pickClipPos");
57462
57494
  this._uSceneModelWorldMatrix = program.getLocation("sceneModelWorldMatrix");
57463
57495
  this._uViewMatrix = program.getLocation("viewMatrix");
57464
57496
  this._uProjMatrix = program.getLocation("projMatrix");
@@ -57556,6 +57588,15 @@ class TrianglesDataTexturePickMeshRenderer {
57556
57588
  src.push("out float isPerspective;");
57557
57589
  }
57558
57590
 
57591
+ src.push("uniform vec2 pickClipPos;");
57592
+
57593
+ src.push("vec4 remapClipPos(vec4 clipPos) {");
57594
+ src.push(" clipPos.xy /= clipPos.w;");
57595
+ src.push(" clipPos.xy -= pickClipPos;");
57596
+ src.push(" clipPos.xy *= clipPos.w;");
57597
+ src.push(" return clipPos;");
57598
+ src.push("}");
57599
+
57559
57600
  src.push("bool isPerspectiveMatrix(mat4 m) {");
57560
57601
  src.push(" return (m[2][3] == - 1.0);");
57561
57602
  src.push("}");
@@ -57666,7 +57707,7 @@ class TrianglesDataTexturePickMeshRenderer {
57666
57707
  src.push("vFragDepth = 1.0 + clipPos.w;");
57667
57708
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
57668
57709
  }
57669
- src.push("gl_Position = clipPos;");
57710
+ src.push("gl_Position = remapClipPos(clipPos);");
57670
57711
  src.push(" }");
57671
57712
  src.push("}");
57672
57713
  return src;
@@ -57755,7 +57796,7 @@ class TrianglesDataTexturePickDepthRenderer {
57755
57796
 
57756
57797
  getValid() {
57757
57798
  return this._hash === this._getHash();
57758
- };
57799
+ }
57759
57800
 
57760
57801
  _getHash() {
57761
57802
  return this._scene._sectionPlanesState.getHash();
@@ -57829,6 +57870,7 @@ class TrianglesDataTexturePickDepthRenderer {
57829
57870
  gl.uniform3fv(this._uCameraEyeRtc, rtcCameraEye);
57830
57871
  gl.uniform1i(this._uRenderPass, renderPass);
57831
57872
  gl.uniform1i(this._uPickInvisible, frameCtx.pickInvisible);
57873
+ gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos);
57832
57874
  gl.uniform1f(this._uPickZNear, frameCtx.pickZNear);
57833
57875
  gl.uniform1f(this._uPickZFar, frameCtx.pickZFar);
57834
57876
  gl.uniformMatrix4fv(this._uWorldMatrix, false, rotationMatrixConjugate);
@@ -57903,6 +57945,7 @@ class TrianglesDataTexturePickDepthRenderer {
57903
57945
  const program = this._program;
57904
57946
  this._uRenderPass = program.getLocation("renderPass");
57905
57947
  this._uPickInvisible = program.getLocation("pickInvisible");
57948
+ this._uPickClipPos = program.getLocation("pickClipPos");
57906
57949
  this._uWorldMatrix = program.getLocation("worldMatrix");
57907
57950
  this._uViewMatrix = program.getLocation("viewMatrix");
57908
57951
  this._uProjMatrix = program.getLocation("projMatrix");
@@ -57992,6 +58035,15 @@ class TrianglesDataTexturePickDepthRenderer {
57992
58035
  src.push("out float isPerspective;");
57993
58036
  }
57994
58037
 
58038
+ src.push("uniform vec2 pickClipPos;");
58039
+
58040
+ src.push("vec4 remapClipPos(vec4 clipPos) {");
58041
+ src.push(" clipPos.xy /= clipPos.w;");
58042
+ src.push(" clipPos.xy -= pickClipPos;");
58043
+ src.push(" clipPos.xy *= clipPos.w;");
58044
+ src.push(" return clipPos;");
58045
+ src.push("}");
58046
+
57995
58047
  src.push("bool isPerspectiveMatrix(mat4 m) {");
57996
58048
  src.push(" return (m[2][3] == - 1.0);");
57997
58049
  src.push("}");
@@ -58098,7 +58150,7 @@ class TrianglesDataTexturePickDepthRenderer {
58098
58150
  src.push("vFragDepth = 1.0 + clipPos.w;");
58099
58151
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
58100
58152
  }
58101
- src.push("gl_Position = clipPos;");
58153
+ src.push("gl_Position = remapClipPos(clipPos);");
58102
58154
  src.push(" }");
58103
58155
  src.push("}");
58104
58156
  return src;
@@ -59059,7 +59111,7 @@ class TrianglesDataTexturePickNormalsRenderer {
59059
59111
 
59060
59112
  getValid() {
59061
59113
  return this._hash === this._getHash();
59062
- };
59114
+ }
59063
59115
 
59064
59116
  _getHash() {
59065
59117
  return this._scene._sectionPlanesState.getHash();
@@ -59117,6 +59169,7 @@ class TrianglesDataTexturePickNormalsRenderer {
59117
59169
  gl.uniform3fv(this._uCameraEyeRtc, originCameraEye);
59118
59170
 
59119
59171
  gl.uniform1i(this._uPickInvisible, frameCtx.pickInvisible);
59172
+ gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos);
59120
59173
 
59121
59174
  if (scene.logarithmicDepthBufferEnabled) {
59122
59175
  const logDepthBufFC = 2.0 / (Math.log(camera.project.far + 1.0) / Math.LN2); // TODO: Far should be from projection matrix?
@@ -59199,6 +59252,7 @@ class TrianglesDataTexturePickNormalsRenderer {
59199
59252
 
59200
59253
  this._uRenderPass = program.getLocation("renderPass");
59201
59254
  this._uPickInvisible = program.getLocation("pickInvisible");
59255
+ this._uPickClipPos = program.getLocation("pickClipPos");
59202
59256
 
59203
59257
  this._uSectionPlanes = [];
59204
59258
 
@@ -59283,6 +59337,15 @@ class TrianglesDataTexturePickNormalsRenderer {
59283
59337
  src.push("out float isPerspective;");
59284
59338
  }
59285
59339
 
59340
+ src.push("uniform vec2 pickClipPos;");
59341
+
59342
+ src.push("vec4 remapClipPos(vec4 clipPos) {");
59343
+ src.push(" clipPos.xy /= clipPos.w;");
59344
+ src.push(" clipPos.xy -= pickClipPos;");
59345
+ src.push(" clipPos.xy *= clipPos.w;");
59346
+ src.push(" return clipPos;");
59347
+ src.push("}");
59348
+
59286
59349
  src.push("bool isPerspectiveMatrix(mat4 m) {");
59287
59350
  src.push(" return (m[2][3] == - 1.0);");
59288
59351
  src.push("}");
@@ -59397,7 +59460,7 @@ class TrianglesDataTexturePickNormalsRenderer {
59397
59460
  src.push(" vWorldPosition = worldPosition;");
59398
59461
  src.push(" vFlags2 = flags2.w;");
59399
59462
  }
59400
- src.push("gl_Position = clipPos;");
59463
+ src.push("gl_Position = remapClipPos(clipPos);");
59401
59464
  src.push("}");
59402
59465
 
59403
59466
  src.push("}");
@@ -60692,7 +60755,7 @@ class TrianglesDataTexturePickNormalsFlatRenderer {
60692
60755
 
60693
60756
  getValid() {
60694
60757
  return this._hash === this._getHash();
60695
- };
60758
+ }
60696
60759
 
60697
60760
  _getHash() {
60698
60761
  return this._scene._sectionPlanesState.getHash();
@@ -60765,6 +60828,7 @@ class TrianglesDataTexturePickNormalsFlatRenderer {
60765
60828
 
60766
60829
  gl.uniform1i(this._uRenderPass, renderPass);
60767
60830
  gl.uniform1i(this._uPickInvisible, frameCtx.pickInvisible);
60831
+ gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos);
60768
60832
 
60769
60833
  gl.uniformMatrix4fv(this._uWorldMatrix, false, model.worldMatrix);
60770
60834
 
@@ -60933,6 +60997,7 @@ class TrianglesDataTexturePickNormalsFlatRenderer {
60933
60997
 
60934
60998
  this._uRenderPass = program.getLocation("renderPass");
60935
60999
  this._uPickInvisible = program.getLocation("pickInvisible");
61000
+ this._uPickClipPos = program.getLocation("pickClipPos");
60936
61001
  this._uPositionsDecodeMatrix = program.getLocation("positionsDecodeMatrix");
60937
61002
  this._uWorldMatrix = program.getLocation("worldMatrix");
60938
61003
  this._uViewMatrix = program.getLocation("viewMatrix");
@@ -61022,6 +61087,16 @@ class TrianglesDataTexturePickNormalsFlatRenderer {
61022
61087
  src.push("}");
61023
61088
  src.push("out float isPerspective;");
61024
61089
  }
61090
+
61091
+ src.push("uniform vec2 pickClipPos;");
61092
+
61093
+ src.push("vec4 remapClipPos(vec4 clipPos) {");
61094
+ src.push(" clipPos.xy /= clipPos.w;");
61095
+ src.push(" clipPos.xy -= pickClipPos;");
61096
+ src.push(" clipPos.xy *= clipPos.w;");
61097
+ src.push(" return clipPos;");
61098
+ src.push("}");
61099
+
61025
61100
  src.push("out vec4 vWorldPosition;");
61026
61101
  if (clipping) {
61027
61102
  src.push("out int vFlags2;");
@@ -61100,7 +61175,7 @@ class TrianglesDataTexturePickNormalsFlatRenderer {
61100
61175
  src.push("vFragDepth = 1.0 + clipPos.w;");
61101
61176
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
61102
61177
  }
61103
- src.push("gl_Position = clipPos;");
61178
+ src.push("gl_Position = remapClipPos(clipPos);");
61104
61179
  src.push(" }");
61105
61180
  src.push("}");
61106
61181
  return src;
@@ -73626,10 +73701,10 @@ const Renderer$1 = function (scene, options) {
73626
73701
  * Picks an Entity.
73627
73702
  * @private
73628
73703
  */
73629
- this.pick = (function () {
73704
+ this.pick = (function () {
73630
73705
 
73631
73706
  const tempVec3a = math.vec3();
73632
- const tempMat4a = math.mat4();
73707
+ math.mat4();
73633
73708
  const tempMat4b = math.mat4();
73634
73709
 
73635
73710
  const randomVec3 = math.vec3();
@@ -73671,13 +73746,11 @@ const Renderer$1 = function (scene, options) {
73671
73746
 
73672
73747
  // Picking with arbitrary World-space ray
73673
73748
  // Align camera along ray and fire ray through center of canvas
73674
-
73675
- const pickFrustumMatrix = math.frustumMat4(-1, 1, -1, 1, 0.01, scene.camera.project.far, tempMat4a);
73676
-
73749
+
73677
73750
  if (params.matrix) {
73678
73751
 
73679
73752
  pickViewMatrix = params.matrix;
73680
- pickProjMatrix = pickFrustumMatrix;
73753
+ pickProjMatrix = scene.camera.projMatrix;
73681
73754
 
73682
73755
  } else {
73683
73756
 
@@ -73694,7 +73767,7 @@ const Renderer$1 = function (scene, options) {
73694
73767
  math.cross3Vec3(worldRayDir, randomVec3, up);
73695
73768
 
73696
73769
  pickViewMatrix = math.lookAtMat4v(worldRayOrigin, look, up, tempMat4b);
73697
- pickProjMatrix = pickFrustumMatrix;
73770
+ pickProjMatrix = scene.camera.projMatrix;
73698
73771
 
73699
73772
  pickResult.origin = worldRayOrigin;
73700
73773
  pickResult.direction = worldRayDir;
@@ -73716,7 +73789,7 @@ const Renderer$1 = function (scene, options) {
73716
73789
  }
73717
73790
  }
73718
73791
 
73719
- const pickBuffer = renderBufferManager.getRenderBuffer("pick");
73792
+ const pickBuffer = renderBufferManager.getRenderBuffer("pick", { size: [1, 1] });
73720
73793
 
73721
73794
  pickBuffer.bind();
73722
73795
 
@@ -73778,10 +73851,12 @@ const Renderer$1 = function (scene, options) {
73778
73851
  frameCtx.pickViewMatrix = pickViewMatrix;
73779
73852
  frameCtx.pickProjMatrix = pickProjMatrix;
73780
73853
  frameCtx.pickInvisible = !!params.pickInvisible;
73854
+ frameCtx.pickClipPos = [
73855
+ getClipPosX(canvasPos[0], gl.drawingBufferWidth),
73856
+ getClipPosY(canvasPos[1], gl.drawingBufferHeight),
73857
+ ];
73781
73858
 
73782
- gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
73783
-
73784
- gl.clearColor(0, 0, 0, 0);
73859
+ gl.viewport(0, 0, 1, 1);
73785
73860
  gl.depthMask(true);
73786
73861
  gl.enable(gl.DEPTH_TEST);
73787
73862
  gl.disable(gl.CULL_FACE);
@@ -73815,8 +73890,7 @@ const Renderer$1 = function (scene, options) {
73815
73890
  }
73816
73891
  }
73817
73892
  }
73818
- const resolutionScale = scene.canvas.resolutionScale;
73819
- const pix = pickBuffer.read(Math.round(canvasPos[0] * resolutionScale), Math.round(canvasPos[1] * resolutionScale));
73893
+ const pix = pickBuffer.read(0, 0);
73820
73894
  let pickID = pix[0] + (pix[1] * 256) + (pix[2] * 256 * 256) + (pix[3] * 256 * 256 * 256);
73821
73895
 
73822
73896
  if (pickID < 0) {
@@ -73841,8 +73915,12 @@ const Renderer$1 = function (scene, options) {
73841
73915
  frameCtx.pickViewMatrix = pickViewMatrix; // Can be null
73842
73916
  frameCtx.pickProjMatrix = pickProjMatrix; // Can be null
73843
73917
  // frameCtx.pickInvisible = !!params.pickInvisible;
73918
+ frameCtx.pickClipPos = [
73919
+ getClipPosX(canvasPos[0], gl.drawingBufferWidth),
73920
+ getClipPosY(canvasPos[1], gl.drawingBufferHeight),
73921
+ ];
73844
73922
 
73845
- gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
73923
+ gl.viewport(0, 0, 1, 1);
73846
73924
 
73847
73925
  gl.clearColor(0, 0, 0, 0);
73848
73926
  gl.enable(gl.DEPTH_TEST);
@@ -73852,8 +73930,7 @@ const Renderer$1 = function (scene, options) {
73852
73930
 
73853
73931
  pickable.drawPickTriangles(frameCtx);
73854
73932
 
73855
- const resolutionScale = scene.canvas.resolutionScale;
73856
- const pix = pickBuffer.read(Math.round(canvasPos[0] * resolutionScale), Math.round(canvasPos[1] * resolutionScale));
73933
+ const pix = pickBuffer.read(0, 0);
73857
73934
 
73858
73935
  let primIndex = pix[0] + (pix[1] * 256) + (pix[2] * 256 * 256) + (pix[3] * 256 * 256 * 256);
73859
73936
 
@@ -73885,8 +73962,12 @@ const Renderer$1 = function (scene, options) {
73885
73962
  frameCtx.pickZFar = nearAndFar[1];
73886
73963
  frameCtx.pickElementsCount = pickable.pickElementsCount;
73887
73964
  frameCtx.pickElementsOffset = pickable.pickElementsOffset;
73888
-
73889
- gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
73965
+ frameCtx.pickClipPos = [
73966
+ getClipPosX(canvasPos[0], gl.drawingBufferWidth),
73967
+ getClipPosY(canvasPos[1], gl.drawingBufferHeight),
73968
+ ];
73969
+
73970
+ gl.viewport(0, 0, 1, 1);
73890
73971
 
73891
73972
  gl.clearColor(0, 0, 0, 0);
73892
73973
  gl.depthMask(true);
@@ -73897,8 +73978,7 @@ const Renderer$1 = function (scene, options) {
73897
73978
 
73898
73979
  pickable.drawPickDepths(frameCtx); // Draw color-encoded fragment screen-space depths
73899
73980
 
73900
- const resolutionScale = scene.canvas.resolutionScale;
73901
- const pix = pickBuffer.read(Math.round(canvasPos[0] * resolutionScale), Math.round(canvasPos[1] * resolutionScale));
73981
+ const pix = pickBuffer.read(0, 0);
73902
73982
 
73903
73983
  const screenZ = unpackDepth(pix); // Get screen-space Z at the given canvas coords
73904
73984
 
@@ -74199,12 +74279,12 @@ const Renderer$1 = function (scene, options) {
74199
74279
  frameCtx.pickOrigin = pickResult.origin;
74200
74280
  frameCtx.pickViewMatrix = pickViewMatrix;
74201
74281
  frameCtx.pickProjMatrix = pickProjMatrix;
74282
+ frameCtx.pickClipPos = [
74283
+ getClipPosX(canvasPos[0], gl.drawingBufferWidth),
74284
+ getClipPosY(canvasPos[1], gl.drawingBufferHeight),
74285
+ ];
74202
74286
 
74203
- const pickNormalBuffer = renderBufferManager.getRenderBuffer("pick-normal");
74204
-
74205
- pickNormalBuffer.bind(gl.RGBA32I);
74206
-
74207
- gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
74287
+ gl.viewport(0, 0, 1, 1);
74208
74288
 
74209
74289
  gl.enable(gl.DEPTH_TEST);
74210
74290
  gl.disable(gl.CULL_FACE);
@@ -74214,10 +74294,7 @@ const Renderer$1 = function (scene, options) {
74214
74294
 
74215
74295
  pickable.drawPickNormals(frameCtx); // Draw color-encoded fragment World-space normals
74216
74296
 
74217
- const resolutionScale = scene.canvas.resolutionScale;
74218
- const pix = pickNormalBuffer.read(Math.round(canvasPos[0] * resolutionScale), Math.round(canvasPos[1] * resolutionScale), gl.RGBA_INTEGER, gl.INT, Int32Array, 4);
74219
-
74220
- pickNormalBuffer.unbind();
74297
+ const pix = pickBuffer.read(0, 0);
74221
74298
 
74222
74299
  const worldNormal = [
74223
74300
  pix[0] / math.MAX_INT,