@xeokit/xeokit-sdk 2.4.0-alpha-4 → 2.4.0-alpha-6

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.
@@ -15105,7 +15105,9 @@ class SAOOcclusionRenderer {
15105
15105
 
15106
15106
  const uv = new Float32Array([1, 1, 0, 1, 0, 0, 1, 0]);
15107
15107
  const positions = new Float32Array([1, 1, 0, -1, 1, 0, -1, -1, 0, 1, -1, 0]);
15108
- const indices = new Uint8Array([0, 1, 2, 0, 2, 3]);
15108
+
15109
+ // Mitigation: if Uint8Array is used, the geometry is corrupted on OSX when using Chrome with data-textures
15110
+ const indices = new Uint32Array([0, 1, 2, 0, 2, 3]);
15109
15111
 
15110
15112
  this._positionsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, positions, positions.length, 3, gl.STATIC_DRAW);
15111
15113
  this._uvBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, uv, uv.length, 2, gl.STATIC_DRAW);
@@ -15341,7 +15343,9 @@ class SAODepthLimitedBlurRenderer {
15341
15343
 
15342
15344
  const uv = new Float32Array([1, 1, 0, 1, 0, 0, 1, 0]);
15343
15345
  const positions = new Float32Array([1, 1, 0, -1, 1, 0, -1, -1, 0, 1, -1, 0]);
15344
- const indices = new Uint8Array([0, 1, 2, 0, 2, 3]);
15346
+
15347
+ // Mitigation: if Uint8Array is used, the geometry is corrupted on OSX when using Chrome with data-textures
15348
+ const indices = new Uint32Array([0, 1, 2, 0, 2, 3]);
15345
15349
 
15346
15350
  this._positionsBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, positions, positions.length, 3, gl.STATIC_DRAW);
15347
15351
  this._uvBuf = new ArrayBuf(gl, gl.ARRAY_BUFFER, uv, uv.length, 2, gl.STATIC_DRAW);
@@ -19891,7 +19895,7 @@ class TrianglesDataTextureColorRenderer {
19891
19895
  tempVec4$9[2] = sao.blendCutoff;
19892
19896
  tempVec4$9[3] = sao.blendFactor;
19893
19897
  gl.uniform4fv(this._uSAOParams, tempVec4$9);
19894
- this._program.bindTexture(this._uOcclusionTexture, frameCtx.occlusionTexture, 0);
19898
+ this._program.bindTexture(this._uOcclusionTexture, frameCtx.occlusionTexture, 10);
19895
19899
  }
19896
19900
  }
19897
19901
 
@@ -20222,7 +20226,7 @@ class TrianglesDataTextureColorRenderer {
20222
20226
  src.push(" float blendCutoff = uSAOParams[2];");
20223
20227
  src.push(" float blendFactor = uSAOParams[3];");
20224
20228
  src.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);");
20225
- src.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture2D(uOcclusionTexture, uv))) * blendFactor;");
20229
+ src.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;");
20226
20230
  src.push(" outColor = vec4(vColor.rgb * ambient, 1.0);");
20227
20231
  } else {
20228
20232
  src.push(" outColor = vColor;");
@@ -23080,6 +23084,7 @@ class TrianglesDataTextureOcclusionRenderer {
23080
23084
  }
23081
23085
  }
23082
23086
 
23087
+ math.vec4();
23083
23088
  const tempVec3a$17 = math.vec3();
23084
23089
 
23085
23090
  /**
@@ -23102,12 +23107,12 @@ class TrianglesDataTextureDepthRenderer {
23102
23107
  }
23103
23108
 
23104
23109
  drawLayer(frameCtx, dataTextureLayer, renderPass) {
23105
-
23106
- const model = dataTextureLayer.model;
23107
- const scene = model.scene;
23110
+ const scene = this._scene;
23108
23111
  const camera = scene.camera;
23112
+ const model = dataTextureLayer.model;
23109
23113
  const gl = scene.canvas.gl;
23110
23114
  const state = dataTextureLayer._state;
23115
+ const textureState = state.textureState;
23111
23116
  const origin = dataTextureLayer._state.origin;
23112
23117
 
23113
23118
  if (!this._program) {
@@ -23119,13 +23124,38 @@ class TrianglesDataTextureDepthRenderer {
23119
23124
 
23120
23125
  if (frameCtx.lastProgramId !== this._program.id) {
23121
23126
  frameCtx.lastProgramId = this._program.id;
23122
- this._bindProgram();
23127
+ this._bindProgram(frameCtx, state);
23123
23128
  }
23129
+
23130
+ textureState.bindCommonTextures (
23131
+ this._program,
23132
+ this._uTexturePerObjectIdPositionsDecodeMatrix,
23133
+ this._uTexturePerVertexIdCoordinates,
23134
+ this._uTexturePerObjectIdColorsAndFlags,
23135
+ this._uTextureCameraMatrices,
23136
+ this._uTextureModelMatrices,
23137
+ this._uTexturePerObjectIdOffsets
23138
+ );
23124
23139
 
23125
- gl.uniform1i(this._uRenderPass, renderPass);
23140
+ let cameraEye = camera.eye;
23126
23141
 
23127
- gl.uniformMatrix4fv(this._uWorldMatrix, false, model.worldMatrix);
23128
- gl.uniformMatrix4fv(this._uViewMatrix, false, (origin) ? createRTCViewMat(camera.viewMatrix, origin) : camera.viewMatrix);
23142
+ if (frameCtx.pickViewMatrix) {
23143
+ textureState.bindPickCameraTexture (
23144
+ this._program,
23145
+ this._uTextureCameraMatrices
23146
+ );
23147
+ cameraEye = frameCtx.pickOrigin || cameraEye;
23148
+ }
23149
+
23150
+ const originCameraEye = [
23151
+ cameraEye[0] - origin[0],
23152
+ cameraEye[1] - origin[1],
23153
+ cameraEye[2] - origin[2],
23154
+ ];
23155
+
23156
+ gl.uniform3fv(this._uCameraEyeRtc, originCameraEye);
23157
+
23158
+ gl.uniform1i(this._uRenderPass, renderPass);
23129
23159
 
23130
23160
  const numSectionPlanes = scene._sectionPlanesState.sectionPlanes.length;
23131
23161
  if (numSectionPlanes > 0) {
@@ -23151,23 +23181,43 @@ class TrianglesDataTextureDepthRenderer {
23151
23181
  }
23152
23182
  }
23153
23183
 
23154
- gl.uniformMatrix4fv(this._uPositionsDecodeMatrix, false, dataTextureLayer._state.positionsDecodeMatrix);
23155
-
23156
- this._aPosition.bindArrayBuffer(state.positionsBuf);
23184
+ if (state.numIndices8Bits > 0)
23185
+ {
23186
+ textureState.bindTriangleIndicesTextures(
23187
+ this._program,
23188
+ this._uTexturePerPolygonIdPortionIds,
23189
+ this._uTexturePerPolygonIdIndices,
23190
+ 8 // 8 bits indices
23191
+ );
23157
23192
 
23158
- if (this._aOffset) {
23159
- this._aOffset.bindArrayBuffer(state.offsetsBuf);
23193
+ gl.drawArrays(gl.TRIANGLES, 0, state.numIndices8Bits);
23160
23194
  }
23161
23195
 
23162
- this._aFlags.bindArrayBuffer(state.flagsBuf);
23196
+ if (state.numIndices16Bits > 0)
23197
+ {
23198
+ textureState.bindTriangleIndicesTextures(
23199
+ this._program,
23200
+ this._uTexturePerPolygonIdPortionIds,
23201
+ this._uTexturePerPolygonIdIndices,
23202
+ 16 // 16 bits indices
23203
+ );
23163
23204
 
23164
- if (this._aFlags2) {
23165
- this._aFlags2.bindArrayBuffer(state.flags2Buf);
23205
+ gl.drawArrays(gl.TRIANGLES, 0, state.numIndices16Bits);
23166
23206
  }
23207
+
23208
+ if (state.numIndices32Bits > 0)
23209
+ {
23210
+ textureState.bindTriangleIndicesTextures(
23211
+ this._program,
23212
+ this._uTexturePerPolygonIdPortionIds,
23213
+ this._uTexturePerPolygonIdIndices,
23214
+ 32 // 32 bits indices
23215
+ );
23167
23216
 
23168
- state.indicesBuf.bind();
23217
+ gl.drawArrays(gl.TRIANGLES, 0, state.numIndices32Bits);
23218
+ }
23169
23219
 
23170
- gl.drawElements(gl.TRIANGLES, state.indicesBuf.numItems, state.indicesBuf.itemType, 0);
23220
+ frameCtx.drawElements++;
23171
23221
  }
23172
23222
 
23173
23223
  _allocate() {
@@ -23199,23 +23249,30 @@ class TrianglesDataTextureDepthRenderer {
23199
23249
  });
23200
23250
  }
23201
23251
 
23202
- this._aPosition = program.getAttribute("position");
23203
- this._aOffset = program.getAttribute("offset");
23204
- this._aFlags = program.getAttribute("flags");
23205
- this._aFlags2 = program.getAttribute("flags2");
23206
-
23207
23252
  if (scene.logarithmicDepthBufferEnabled) {
23208
23253
  this._uLogDepthBufFC = program.getLocation("logDepthBufFC");
23209
23254
  }
23255
+
23256
+ this._uTexturePerObjectIdPositionsDecodeMatrix = "uTexturePerObjectIdPositionsDecodeMatrix"; // chipmunk
23257
+ this._uTexturePerObjectIdColorsAndFlags = "uTexturePerObjectIdColorsAndFlags"; // chipmunk
23258
+ this._uTexturePerVertexIdCoordinates = "uTexturePerVertexIdCoordinates"; // chipmunk
23259
+ this._uTexturePerPolygonIdNormals = "uTexturePerPolygonIdNormals"; // chipmunk
23260
+ this._uTexturePerPolygonIdIndices = "uTexturePerPolygonIdIndices"; // chipmunk
23261
+ this._uTexturePerPolygonIdPortionIds = "uTexturePerPolygonIdPortionIds"; // chipmunk
23262
+ this._uTextureCameraMatrices = "uTextureCameraMatrices"; // chipmunk
23263
+ this._uTextureModelMatrices = "uTextureModelMatrices"; // chipmunk
23264
+ this._uTexturePerObjectIdOffsets = "uTexturePerObjectIdOffsets"; // chipmunk
23265
+ this._uCameraEyeRtc = program.getLocation("uCameraEyeRtc"); // chipmunk
23210
23266
  }
23211
23267
 
23212
- _bindProgram() {
23268
+ _bindProgram(frameCtx) {
23213
23269
 
23214
23270
  const scene = this._scene;
23215
23271
  const gl = scene.canvas.gl;
23272
+ const program = this._program;
23216
23273
  const project = scene.camera.project;
23217
23274
 
23218
- this._program.bind();
23275
+ program.bind();
23219
23276
 
23220
23277
  gl.uniformMatrix4fv(this._uProjMatrix, false, project.matrix);
23221
23278
 
@@ -23234,131 +23291,241 @@ class TrianglesDataTextureDepthRenderer {
23234
23291
 
23235
23292
  _buildVertexShader() {
23236
23293
  const scene = this._scene;
23237
- const clipping = scene._sectionPlanesState.sectionPlanes.length > 0;
23294
+ const sectionPlanesState = scene._sectionPlanesState;
23295
+ scene._lightsState;
23296
+ const clipping = sectionPlanesState.sectionPlanes.length > 0;
23238
23297
  const src = [];
23239
- src.push("// Triangles dataTexture depth vertex shader");
23240
- if (scene.logarithmicDepthBufferEnabled && WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]) {
23241
- src.push("#extension GL_EXT_frag_depth : enable");
23242
- }
23298
+ src.push("#version 300 es");
23299
+ src.push("// Triangles dataTexture draw vertex shader");
23300
+
23301
+ src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");
23302
+ src.push("precision highp float;");
23303
+ src.push("precision highp int;");
23304
+ src.push("precision highp usampler2D;");
23305
+ src.push("precision highp isampler2D;");
23306
+ src.push("precision highp sampler2D;");
23307
+ src.push("#else");
23308
+ src.push("precision mediump float;");
23309
+ src.push("precision mediump int;");
23310
+ src.push("precision mediump usampler2D;");
23311
+ src.push("precision mediump isampler2D;");
23312
+ src.push("precision mediump sampler2D;");
23313
+ src.push("#endif");
23314
+
23243
23315
  src.push("uniform int renderPass;");
23244
- src.push("attribute vec3 position;");
23316
+
23245
23317
  if (scene.entityOffsetsEnabled) {
23246
- src.push("attribute vec3 offset;");
23318
+ src.push("in vec3 offset;");
23247
23319
  }
23248
- src.push("attribute vec4 flags;");
23249
- src.push("attribute vec4 flags2;");
23250
- src.push("uniform mat4 worldMatrix;");
23251
- src.push("uniform mat4 viewMatrix;");
23252
- src.push("uniform mat4 projMatrix;");
23253
- src.push("uniform mat4 positionsDecodeMatrix;");
23320
+
23321
+ // src.push("uniform sampler2D uOcclusionTexture;"); // chipmunk
23322
+
23323
+ src.push("uniform highp sampler2D uTexturePerObjectIdPositionsDecodeMatrix;"); // chipmunk
23324
+ src.push("uniform lowp usampler2D uTexturePerObjectIdColorsAndFlags;"); // chipmunk
23325
+ src.push("uniform highp sampler2D uTexturePerObjectIdOffsets;"); // chipmunk
23326
+ src.push("uniform mediump usampler2D uTexturePerVertexIdCoordinates;"); // chipmunk
23327
+ src.push("uniform highp usampler2D uTexturePerPolygonIdIndices;"); // chipmunk
23328
+ src.push("uniform mediump usampler2D uTexturePerPolygonIdPortionIds;"); // chipmunk
23329
+ src.push("uniform highp sampler2D uTextureCameraMatrices;"); // chipmunk
23330
+ src.push("uniform highp sampler2D uTextureModelMatrices;"); // chipmunk
23331
+ src.push("uniform vec3 uCameraEyeRtc;"); // chipmunk
23332
+
23333
+ src.push("vec3 positions[3];");
23334
+
23254
23335
  if (scene.logarithmicDepthBufferEnabled) {
23255
23336
  src.push("uniform float logDepthBufFC;");
23256
- if (WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]) {
23257
- src.push("varying float vFragDepth;");
23258
- }
23259
- src.push("bool isPerspectiveMatrix(mat4 m) {");
23260
- src.push(" return (m[2][3] == - 1.0);");
23261
- src.push("}");
23262
- src.push("varying float isPerspective;");
23337
+ src.push("out float vFragDepth;");
23338
+ src.push("out float isPerspective;");
23263
23339
  }
23340
+
23341
+ src.push("bool isPerspectiveMatrix(mat4 m) {");
23342
+ src.push(" return (m[2][3] == - 1.0);");
23343
+ src.push("}");
23344
+
23345
+ src.push("out highp vec2 vHighPrecisionZW;");
23346
+
23264
23347
  if (clipping) {
23265
- src.push("varying vec4 vWorldPosition;");
23266
- src.push("varying vec4 vFlags2;");
23348
+ src.push("out vec4 vWorldPosition;");
23349
+ src.push("flat out uint vFlags2;");
23267
23350
  }
23268
- src.push("varying vec2 vHighPrecisionZW;");
23351
+
23269
23352
  src.push("void main(void) {");
23270
23353
 
23354
+ // camera matrices
23355
+ src.push ("mat4 viewMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 0), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 0), 0));");
23356
+ src.push ("mat4 viewNormalMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 1), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 1), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 1), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 1), 0));");
23357
+ src.push ("mat4 projMatrix = mat4 (texelFetch (uTextureCameraMatrices, ivec2(0, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(1, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(2, 2), 0), texelFetch (uTextureCameraMatrices, ivec2(3, 2), 0));");
23358
+
23359
+ // model matrices
23360
+ src.push ("mat4 worldMatrix = mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 0), 0), texelFetch (uTextureModelMatrices, ivec2(1, 0), 0), texelFetch (uTextureModelMatrices, ivec2(2, 0), 0), texelFetch (uTextureModelMatrices, ivec2(3, 0), 0));");
23361
+ src.push ("mat4 worldNormalMatrix = mat4 (texelFetch (uTextureModelMatrices, ivec2(0, 1), 0), texelFetch (uTextureModelMatrices, ivec2(1, 1), 0), texelFetch (uTextureModelMatrices, ivec2(2, 1), 0), texelFetch (uTextureModelMatrices, ivec2(3, 1), 0));");
23362
+
23363
+ // constants
23364
+ src.push("int polygonIndex = gl_VertexID / 3;");
23365
+
23366
+ // get packed object-id
23367
+ src.push("int h_packed_object_id_index = (polygonIndex >> 3) & 4095;");
23368
+ src.push("int v_packed_object_id_index = (polygonIndex >> 3) >> 12;");
23369
+
23370
+ src.push("int objectIndex = int(texelFetch(uTexturePerPolygonIdPortionIds, ivec2(h_packed_object_id_index, v_packed_object_id_index), 0).r);");
23371
+ src.push("ivec2 objectIndexCoords = ivec2(objectIndex % 512, objectIndex / 512);");
23372
+
23373
+ // get flags & flags2
23374
+ src.push("uvec4 flags = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);"); // chipmunk
23375
+ src.push("uvec4 flags2 = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);"); // chipmunk
23376
+
23271
23377
  // flags.x = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
23272
23378
  // renderPass = COLOR_OPAQUE
23273
23379
 
23274
- src.push(`if (int(flags.x) != renderPass) {`);
23275
- src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"); // Cull vertex
23276
- src.push(" } else {");
23277
- src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");
23278
- if (scene.entityOffsetsEnabled) {
23279
- src.push(" worldPosition.xyz = worldPosition.xyz + offset;");
23280
- }
23281
- src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");
23282
- if (clipping) {
23283
- src.push(" vWorldPosition = worldPosition;");
23284
- src.push(" vFlags2 = flags2;");
23285
- }
23380
+ // src.push(`if (int(flags.x) != renderPass) {`);
23381
+ // src.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"); // Cull vertex
23382
+ // src.push(" return;"); // Cull vertex
23383
+ // src.push("} else {");
23384
+ src.push("{");
23385
+
23386
+ // get vertex base
23387
+ src.push("ivec4 packedVertexBase = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0));"); // chipmunk
23388
+
23389
+ src.push("ivec4 packedIndexBaseOffset = ivec4(texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0));"); // chipmunk
23390
+
23391
+ src.push("int indexBaseOffset = (packedIndexBaseOffset.r << 24) + (packedIndexBaseOffset.g << 16) + (packedIndexBaseOffset.b << 8) + packedIndexBaseOffset.a;");
23392
+
23393
+ src.push("int h_index = (polygonIndex - indexBaseOffset) & 4095;");
23394
+ src.push("int v_index = (polygonIndex - indexBaseOffset) >> 12;");
23395
+
23396
+ src.push("ivec3 vertexIndices = ivec3(texelFetch(uTexturePerPolygonIdIndices, ivec2(h_index, v_index), 0));");
23397
+ src.push("ivec3 uniqueVertexIndexes = vertexIndices + (packedVertexBase.r << 24) + (packedVertexBase.g << 16) + (packedVertexBase.b << 8) + packedVertexBase.a;");
23398
+
23399
+ src.push("ivec3 indexPositionH = uniqueVertexIndexes & 4095;");
23400
+ src.push("ivec3 indexPositionV = uniqueVertexIndexes >> 12;");
23401
+
23402
+ src.push("mat4 positionsDecodeMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*8+1, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0));");
23403
+ src.push("mat4 entityMatrix = mat4 (texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*8+4, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*8+5, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*8+6, objectIndexCoords.y), 0), texelFetch (uTexturePerObjectIdPositionsDecodeMatrix, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0));");
23404
+
23405
+ src.push("positionsDecodeMatrix = entityMatrix * positionsDecodeMatrix;");
23406
+
23407
+ src.push("uint solid = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+7, objectIndexCoords.y), 0).r;"); // chipmunk
23408
+
23409
+ // get position
23410
+ src.push("positions[0] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.r, indexPositionV.r), 0));");
23411
+ src.push("positions[1] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.g, indexPositionV.g), 0));");
23412
+ src.push("positions[2] = vec3(texelFetch(uTexturePerVertexIdCoordinates, ivec2(indexPositionH.b, indexPositionV.b), 0));");
23413
+
23414
+ // get color
23415
+ src.push("uvec4 color = texelFetch (uTexturePerObjectIdColorsAndFlags, ivec2(objectIndexCoords.x*8+0, objectIndexCoords.y), 0);"); // chipmunk
23416
+
23417
+ src.push(`if (color.a == 0u) {`);
23418
+ src.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"); // Cull vertex
23419
+ src.push(" return;");
23420
+ src.push("};");
23421
+
23422
+ // get normal
23423
+ src.push("vec3 normal = normalize(cross(positions[2] - positions[0], positions[1] - positions[0]));");
23424
+
23425
+ src.push("vec3 position;");
23426
+ src.push("position = positions[gl_VertexID % 3];");
23427
+
23428
+ src.push("vec3 viewNormal = -normalize((transpose(inverse(viewMatrix*positionsDecodeMatrix)) * vec4(normal,1)).xyz);");
23429
+
23430
+ // when the geometry is not solid, if needed, flip the triangle winding
23431
+ src.push("if (solid != 1u) {");
23432
+ src.push("if (isPerspectiveMatrix(projMatrix)) {");
23433
+ src.push("vec3 uCameraEyeRtcInQuantizedSpace = (inverse(worldMatrix * positionsDecodeMatrix) * vec4(uCameraEyeRtc, 1)).xyz;");
23434
+ src.push("if (dot(position.xyz - uCameraEyeRtcInQuantizedSpace, normal) < 0.0) {");
23435
+ src.push("position = positions[2 - (gl_VertexID % 3)];");
23436
+ src.push("viewNormal = -viewNormal;");
23437
+ src.push("}");
23438
+ src.push("} else {");
23439
+ src.push("if (viewNormal.z < 0.0) {");
23440
+ src.push("position = positions[2 - (gl_VertexID % 3)];");
23441
+ src.push("viewNormal = -viewNormal;");
23442
+ src.push("}");
23443
+ src.push("}");
23444
+ src.push("}");
23445
+
23446
+ src.push("vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");
23447
+
23448
+ // get XYZ offset
23449
+ src.push("vec4 offset = vec4(texelFetch (uTexturePerObjectIdOffsets, objectIndexCoords, 0).rgb, 0.0);");
23450
+
23451
+ src.push("worldPosition.xyz = worldPosition.xyz + offset.xyz;");
23452
+
23453
+ src.push("vec4 viewPosition = viewMatrix * worldPosition; ");
23454
+
23286
23455
  src.push("vec4 clipPos = projMatrix * viewPosition;");
23287
23456
  if (scene.logarithmicDepthBufferEnabled) {
23288
- if (WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]) {
23289
- src.push("vFragDepth = 1.0 + clipPos.w;");
23290
- } else {
23291
- src.push("clipPos.z = log2( max( 1e-6, clipPos.w + 1.0 ) ) * logDepthBufFC - 1.0;");
23292
- src.push("clipPos.z *= clipPos.w;");
23293
- }
23457
+ src.push("vFragDepth = 1.0 + clipPos.w;");
23294
23458
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
23295
23459
  }
23460
+ if (clipping) {
23461
+ src.push("vWorldPosition = worldPosition;");
23462
+ src.push("vFlags2 = flags2.r;");
23463
+ }
23296
23464
  src.push("gl_Position = clipPos;");
23297
23465
  src.push("vHighPrecisionZW = gl_Position.zw;");
23298
- src.push(" }");
23299
23466
  src.push("}");
23467
+
23468
+ src.push("}");
23469
+
23300
23470
  return src;
23301
23471
  }
23302
23472
 
23303
23473
  _buildFragmentShader() {
23304
23474
  const scene = this._scene;
23305
23475
  const sectionPlanesState = scene._sectionPlanesState;
23306
- const clipping = (sectionPlanesState.sectionPlanes.length > 0);
23476
+ const clipping = sectionPlanesState.sectionPlanes.length > 0;
23307
23477
  const src = [];
23308
- src.push("// Triangles dataTexture depth fragment shader");
23309
- if (scene.logarithmicDepthBufferEnabled && WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]) {
23310
- src.push("#extension GL_EXT_frag_depth : enable");
23311
- }
23478
+ src.push ('#version 300 es');
23479
+ src.push("// Triangles dataTexture draw fragment shader");
23480
+ src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");
23312
23481
  src.push("precision highp float;");
23313
23482
  src.push("precision highp int;");
23314
- if (scene.logarithmicDepthBufferEnabled && WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]) {
23315
- src.push("varying float isPerspective;");
23483
+ src.push("#else");
23484
+ src.push("precision mediump float;");
23485
+ src.push("precision mediump int;");
23486
+ src.push("#endif");
23487
+
23488
+ src.push("in highp vec2 vHighPrecisionZW;");
23489
+ src.push("out vec4 outColor;");
23490
+
23491
+ if (scene.logarithmicDepthBufferEnabled) {
23492
+ src.push("in float isPerspective;");
23316
23493
  src.push("uniform float logDepthBufFC;");
23317
- src.push("varying float vFragDepth;");
23494
+ src.push("in float vFragDepth;");
23318
23495
  }
23319
23496
  if (clipping) {
23320
- src.push("varying vec4 vWorldPosition;");
23321
- src.push("varying vec4 vFlags2;");
23322
- for (let i = 0; i < sectionPlanesState.sectionPlanes.length; i++) {
23497
+ src.push("in vec4 vWorldPosition;");
23498
+ src.push("flat in uint vFlags2;");
23499
+ for (let i = 0, len = sectionPlanesState.sectionPlanes.length; i < len; i++) {
23323
23500
  src.push("uniform bool sectionPlaneActive" + i + ";");
23324
23501
  src.push("uniform vec3 sectionPlanePos" + i + ";");
23325
23502
  src.push("uniform vec3 sectionPlaneDir" + i + ";");
23326
23503
  }
23327
23504
  }
23328
- src.push("const float packUpScale = 256. / 255.;");
23329
- src.push("const float unpackDownscale = 255. / 256.;");
23330
- src.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );");
23331
- src.push("const vec4 unpackFactors = unpackDownscale / vec4( packFactors, 1. );");
23332
- src.push("const float shiftRight8 = 1.0 / 256.;");
23333
-
23334
- src.push("vec4 packDepthToRGBA( const in float v ) {");
23335
- src.push(" vec4 r = vec4( fract( v * packFactors ), v );");
23336
- src.push(" r.yzw -= r.xyz * shiftRight8;");
23337
- src.push(" return r * packUpScale;");
23338
- src.push("}");
23339
- src.push("varying vec2 vHighPrecisionZW;");
23340
23505
  src.push("void main(void) {");
23506
+
23341
23507
  if (clipping) {
23342
- src.push(" bool clippable = (float(vFlags2.x) > 0.0);");
23508
+ src.push(" bool clippable = vFlags2 > 0u;");
23343
23509
  src.push(" if (clippable) {");
23344
- src.push(" float dist = 0.0;");
23345
- for (var i = 0; i < sectionPlanesState.sectionPlanes.length; i++) {
23346
- src.push(" if (sectionPlaneActive" + i + ") {");
23347
- src.push(" dist += clamp(dot(-sectionPlaneDir" + i + ".xyz, vWorldPosition.xyz - sectionPlanePos" + i + ".xyz), 0.0, 1000.0);");
23348
- src.push(" }");
23510
+ src.push(" float dist = 0.0;");
23511
+ for (let i = 0, len = sectionPlanesState.sectionPlanes.length; i < len; i++) {
23512
+ src.push("if (sectionPlaneActive" + i + ") {");
23513
+ src.push(" dist += clamp(dot(-sectionPlaneDir" + i + ".xyz, vWorldPosition.xyz - sectionPlanePos" + i + ".xyz), 0.0, 1000.0);");
23514
+ src.push("}");
23349
23515
  }
23350
- src.push(" if (dist > 0.0) { discard; }");
23351
- src.push(" }");
23516
+ src.push(" if (dist > 0.0) { ");
23517
+ src.push(" discard;");
23518
+ src.push(" }");
23519
+ src.push("}");
23352
23520
  }
23353
- if (scene.logarithmicDepthBufferEnabled && WEBGL_INFO.SUPPORTED_EXTENSIONS["EXT_frag_depth"]) {
23354
- src.push(" gl_FragDepthEXT = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
23521
+
23522
+ if (scene.logarithmicDepthBufferEnabled) {
23523
+ // src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
23524
+ src.push(" gl_FragDepth = log2( vFragDepth ) * logDepthBufFC * 0.5;");
23355
23525
  }
23356
23526
  src.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;");
23357
- if (WEBGL_INFO.SUPPORTED_EXTENSIONS["WEBGL_depth_texture"]) {
23358
- src.push(" gl_FragColor = vec4(vec3(1.0 - fragCoordZ), 1.0); ");
23359
- } else {
23360
- src.push(" gl_FragColor = packDepthToRGBA(fragCoordZ); "); // Must be linear depth
23361
- }
23527
+ src.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); ");
23528
+ // src.push(" outColor = vec4(1.0, 1.0, 1.0, 1.0); ");
23362
23529
  src.push("}");
23363
23530
  return src;
23364
23531
  }
@@ -23372,7 +23539,6 @@ class TrianglesDataTextureDepthRenderer {
23372
23539
  this._program.destroy();
23373
23540
  }
23374
23541
  this._program = null;
23375
- stats.memory.programs--;
23376
23542
  }
23377
23543
  }
23378
23544
 
@@ -29218,40 +29384,49 @@ class TrianglesDataTextureLayer {
29218
29384
  *
29219
29385
  * @returns {object} The mesh information enrichened with `.preparedBuckets` key.
29220
29386
  */
29221
- function prepareMeshGeometry (geometryCfg) {
29387
+ function prepareMeshGeometry (geometryCfg, enableVertexWelding, enableIndexRebucketing) {
29222
29388
  let uniquePositions, uniqueIndices, uniqueEdgeIndices;
29223
29389
 
29224
- [
29225
- uniquePositions,
29226
- uniqueIndices,
29227
- uniqueEdgeIndices,
29228
- ] = uniquifyPositions ({
29229
- positions: geometryCfg.positions,
29230
- indices: geometryCfg.indices,
29231
- edgeIndices: geometryCfg.edgeIndices
29232
- });
29390
+ if (enableVertexWelding) {
29391
+ [
29392
+ uniquePositions,
29393
+ uniqueIndices,
29394
+ uniqueEdgeIndices,
29395
+ ] = uniquifyPositions ({
29396
+ positions: geometryCfg.positions,
29397
+ indices: geometryCfg.indices,
29398
+ edgeIndices: geometryCfg.edgeIndices
29399
+ });
29400
+ } else {
29401
+ uniquePositions = geometryCfg.positions;
29402
+ uniqueIndices = geometryCfg.indices;
29403
+ uniqueEdgeIndices = geometryCfg.edgeIndices;
29404
+ }
29233
29405
 
29234
- let numUniquePositions = uniquePositions.length / 3;
29406
+ let buckets;
29235
29407
 
29236
- let buckets = rebucketPositions (
29237
- {
29408
+ if (enableIndexRebucketing) {
29409
+ let numUniquePositions = uniquePositions.length / 3;
29410
+
29411
+ buckets = rebucketPositions (
29412
+ {
29413
+ positions: uniquePositions,
29414
+ indices: uniqueIndices,
29415
+ edgeIndices: uniqueEdgeIndices,
29416
+ },
29417
+ (numUniquePositions > (1<< 16)) ? 16 : 8,
29418
+ // true
29419
+ );
29420
+ } else {
29421
+ buckets = [{
29238
29422
  positions: uniquePositions,
29239
29423
  indices: uniqueIndices,
29240
29424
  edgeIndices: uniqueEdgeIndices,
29241
- },
29242
- (numUniquePositions > (1<< 16)) ? 16 : 8,
29243
- // true
29244
- );
29425
+ }];
29426
+ }
29245
29427
 
29246
29428
  geometryCfg.preparedBuckets = buckets;
29247
29429
 
29248
- // chipmunk
29249
- // geometryCfg.preparedBuckets = [{
29250
- // positions: uniquePositions,
29251
- // indices: uniqueIndices,
29252
- // edgeIndices: uniqueEdgeIndices,
29253
- // }];
29254
-
29255
29430
  return geometryCfg;
29256
29431
  }
29257
29432
 
@@ -31479,7 +31654,7 @@ const VISIBILITY_CHECK_ENVOLVES_V = (1 << 14);
31479
31654
  this._camera = model.scene.camera;
31480
31655
  }
31481
31656
 
31482
- this._ensureFrustumPropsUpdated ();
31657
+ this._ensureFrustumPropsUpdated (model);
31483
31658
 
31484
31659
  this._initializeCullingDataIfNeeded (model);
31485
31660
 
@@ -31658,9 +31833,11 @@ const VISIBILITY_CHECK_ENVOLVES_V = (1 << 14);
31658
31833
  }
31659
31834
 
31660
31835
  /**
31836
+ * @param {DataTextureSceneModel} model
31837
+ *
31661
31838
  * @private
31662
31839
  */
31663
- _ensureFrustumPropsUpdated ()
31840
+ _ensureFrustumPropsUpdated (model)
31664
31841
  {
31665
31842
  // Assuming "min" for fovAxis
31666
31843
  const min = Math.min (
@@ -31689,10 +31866,33 @@ const VISIBILITY_CHECK_ENVOLVES_V = (1 << 14);
31689
31866
  // return;
31690
31867
  // }
31691
31868
 
31869
+ // Adjust camera eye/look to take into account the `model.worldMatrix`:
31870
+ // - the entities' AABBs don't take it into account
31871
+ // - and they can't, since `model.worldMatrix` is dynamic
31872
+ // So, instead of transformating the positions of the r*tree's AABBs,
31873
+ // apply the inverse transform to the camera eye/look, since the culling
31874
+ // result is equivalent.
31875
+ const invWorldMatrix = math.inverseMat4(
31876
+ model.worldMatrix,
31877
+ math.mat4()
31878
+ );
31879
+
31880
+ const modelCamEye = math.transformVec3(
31881
+ this._camera.eye,
31882
+ invWorldMatrix,
31883
+ [ 0, 0, 0 ]
31884
+ );
31885
+
31886
+ const modelCamLook = math.transformVec3(
31887
+ this._camera.look,
31888
+ invWorldMatrix,
31889
+ [ 0, 0, 0 ]
31890
+ );
31891
+
31692
31892
  this._frustumProps.forward = math.normalizeVec3 (
31693
31893
  math.subVec3 (
31694
- this._camera.look,
31695
- this._camera.eye,
31894
+ modelCamLook,
31895
+ modelCamEye,
31696
31896
  [ 0, 0, 0]
31697
31897
  ),
31698
31898
  [ 0, 0, 0]
@@ -31712,7 +31912,7 @@ const VISIBILITY_CHECK_ENVOLVES_V = (1 << 14);
31712
31912
  [ 0, 0, 0 ]
31713
31913
  );
31714
31914
 
31715
- this._frustumProps.eye = this._camera.eye.slice ();
31915
+ this._frustumProps.eye = modelCamEye.slice ();
31716
31916
 
31717
31917
  this._frustumProps.CAM_FACTOR_1 = this._frustumProps.fov / 2 * this._frustumProps.wMultiply / _180_DIV_MATH_PI;
31718
31918
  this._frustumProps.CAM_FACTOR_2 = this._frustumProps.fov / 2 * this._frustumProps.hMultiply / _180_DIV_MATH_PI;
@@ -31983,6 +32183,8 @@ class DataTextureSceneModel extends Component {
31983
32183
  * @param {Boolean} [cfg.saoEnabled=true] Indicates if Scalable Ambient Obscurance (SAO) will apply to this dataTexturePerformanceModel. SAO is configured by the Scene's {@link SAO} component.
31984
32184
  * @param {Boolean} [cfg.pbrEnabled=false] Indicates if physically-based rendering (PBR) will apply to the dataTexturePerformanceModel. Only works when {@link Scene#pbrEnabled} is also ````true````.
31985
32185
  * @param {Number} [cfg.edgeThreshold=10] When xraying, highlighting, selecting or edging, this is the threshold angle between normals of adjacent triangles, below which their shared wireframe edge is not drawn.
32186
+ * @param {Boolean} [cfg.disableVertexWelding] Disable vertex welding when loading geometry into the GPU. Default is ```false```.
32187
+ * @param {Boolean} [cfg.disableIndexRebucketing] Disable index rebucketing when loading geometry into the GPU. Default is ```false```.
31986
32188
  */
31987
32189
  constructor(owner, cfg = {}) {
31988
32190
  super(owner, cfg);
@@ -31991,6 +32193,24 @@ class DataTextureSceneModel extends Component {
31991
32193
  throw "Using a DataTextureSceneModel requires the usage of webgl2";
31992
32194
  }
31993
32195
 
32196
+ /**
32197
+ * Enable welding vertices when loading geometry into the ```TrianglesDataTextureLayer```.
32198
+ *
32199
+ * The welding is applied per-geometry.
32200
+ *
32201
+ * @type {Boolean}
32202
+ */
32203
+ this._enableVertexWelding = !cfg.disableVertexWelding;
32204
+
32205
+ /**
32206
+ * Enable demotion of index bitness then loading geometry into the ```TrianglesDataTextureLayer```.
32207
+ *
32208
+ * The rebucketing is applied per-geometry.
32209
+ *
32210
+ * @type {Boolean}
32211
+ */
32212
+ this._enableIndexRebucketing = !cfg.disableIndexRebucketing;
32213
+
31994
32214
  this._targetLodFps = cfg.targetLodFps;
31995
32215
 
31996
32216
  if (cfg.enableViewFrustumCulling) {
@@ -33042,7 +33262,11 @@ class DataTextureSceneModel extends Component {
33042
33262
 
33043
33263
  geometryCfg.edgeIndices = edgeIndices;
33044
33264
 
33045
- preparedGeometryCfg = prepareMeshGeometry (geometryCfg);
33265
+ preparedGeometryCfg = prepareMeshGeometry (
33266
+ geometryCfg,
33267
+ this._enableVertexWelding,
33268
+ this._enableIndexRebucketing
33269
+ );
33046
33270
 
33047
33271
  if (instancing) {
33048
33272
  this._preparedInstancingGeometries[geometryId] = preparedGeometryCfg;
@@ -34140,7 +34364,7 @@ const Renderer = function (scene, options) {
34140
34364
 
34141
34365
  const drawable = drawableList[i];
34142
34366
 
34143
- if (drawable.culled === true || drawable.visible === false || !drawable.drawDepth) {
34367
+ if (drawable.culled === true || drawable.visible === false || !drawable.drawDepth || !drawable.saoEnabled) {
34144
34368
  continue;
34145
34369
  }
34146
34370
 
@@ -131491,6 +131715,8 @@ class XKTLoaderPlugin extends Plugin {
131491
131715
  origin: params.origin,
131492
131716
  targetLodFps: params.useDataTextures.targetLodFps || false,
131493
131717
  enableViewFrustumCulling: params.useDataTextures.enableViewFrustumCulling || false,
131718
+ disableVertexWelding: params.useDataTextures.disableVertexWelding || false,
131719
+ disableIndexRebucketing: params.useDataTextures.disableIndexRebucketing || false,
131494
131720
  }));
131495
131721
  } else {
131496
131722
  sceneModel = new VBOSceneModel(this.viewer.scene, utils.apply(params, {