@xeokit/xeokit-sdk 2.6.29 → 2.6.30

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 (29) hide show
  1. package/dist/xeokit-sdk.cjs.js +510 -429
  2. package/dist/xeokit-sdk.es.js +510 -429
  3. package/dist/xeokit-sdk.es5.js +315 -328
  4. package/dist/xeokit-sdk.min.cjs.js +4 -4
  5. package/dist/xeokit-sdk.min.es.js +4 -4
  6. package/dist/xeokit-sdk.min.es5.js +3 -3
  7. package/package.json +1 -1
  8. package/src/plugins/GLTFLoaderPlugin/GLTFLoaderPlugin.js +2 -110
  9. package/src/plugins/GLTFLoaderPlugin/GLTFSceneModelLoader.js +252 -222
  10. package/src/viewer/metadata/MetaScene.js +0 -2
  11. package/src/viewer/scene/model/SceneModel.js +9 -0
  12. package/src/viewer/scene/model/SceneModelTextureSet.js +5 -0
  13. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesSnapInitRenderer.js +8 -0
  14. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesSnapRenderer.js +8 -0
  15. package/src/viewer/scene/model/vbo/VBORenderer.js +10 -1
  16. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesSnapRenderer.js +1 -1
  17. package/src/viewer/scene/model/vbo/batching/triangles/VBOBatchingTrianglesLayer.js +26 -6
  18. package/src/viewer/scene/model/vbo/batching/triangles/renderers/Renderers.js +40 -12
  19. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesBatchingRenderer.js +2 -3
  20. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesColorTextureRenderer.js +25 -7
  21. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesSnapRenderer.js +1 -1
  22. package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesSnapRenderer.js +1 -1
  23. package/src/viewer/scene/model/vbo/instancing/triangles/VBOInstancingTrianglesLayer.js +17 -4
  24. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/Renderers.js +74 -47
  25. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesColorTextureRenderer.js +29 -14
  26. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesInstancingRenderer.js +5 -4
  27. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesSnapRenderer.js +1 -1
  28. package/src/viewer/scene/webgl/occlusion/OcclusionLayer.js +1 -1
  29. package/src/viewer/scene/webgl/occlusion/OcclusionTester.js +1 -4
@@ -17471,7 +17471,7 @@ class OcclusionLayer {
17471
17471
  for (let i = 0; i < this.numMarkers; i++) {
17472
17472
  if (this.markerList[i]) {
17473
17473
  const marker = this.markerList[i];
17474
- const worldPos = marker.worldPos;
17474
+ const worldPos = marker.rtcPos;
17475
17475
  this.positions[j++] = worldPos[0];
17476
17476
  this.positions[j++] = worldPos[1];
17477
17477
  this.positions[j++] = worldPos[2];
@@ -17913,10 +17913,7 @@ class OcclusionTester {
17913
17913
  continue;
17914
17914
  }
17915
17915
 
17916
- // The `origin` has been changed from `occlusionLayer.origin` to `[ 0, 0, 0 ]`
17917
- // because OcclusionLayer markers' transformation is being applied through the
17918
- // OcclusionLayer::positions array. See XEOK-33
17919
- const origin = [ 0, 0, 0 ];
17916
+ const origin = occlusionLayer.origin;
17920
17917
 
17921
17918
  gl.uniformMatrix4fv(this._uViewMatrix, false, createRTCViewMat(camera.viewMatrix, origin));
17922
17919
 
@@ -51506,11 +51503,12 @@ const tempMat4a$r = math.mat4();
51506
51503
  * @private
51507
51504
  */
51508
51505
  class VBORenderer {
51509
- constructor(scene, withSAO = false, {instancing = false, edges = false} = {}) {
51506
+ constructor(scene, withSAO = false, {instancing = false, edges = false, useAlphaCutoff = false} = {}) {
51510
51507
  this._scene = scene;
51511
51508
  this._withSAO = withSAO;
51512
51509
  this._instancing = instancing;
51513
51510
  this._edges = edges;
51511
+ this._useAlphaCutoff = useAlphaCutoff;
51514
51512
  this._hash = this._getHash();
51515
51513
 
51516
51514
  /**
@@ -51761,6 +51759,10 @@ class VBORenderer {
51761
51759
  this._uSAOParams = program.getLocation("uSAOParams");
51762
51760
  }
51763
51761
 
51762
+ if (this._useAlphaCutoff) {
51763
+ this._alphaCutoffLocation = program.getLocation("materialAlphaCutoff");
51764
+ }
51765
+
51764
51766
  if (scene.logarithmicDepthBufferEnabled) {
51765
51767
  this._uLogDepthBufFC = program.getLocation("logDepthBufFC");
51766
51768
  }
@@ -52098,6 +52100,10 @@ class VBORenderer {
52098
52100
  }
52099
52101
  }
52100
52102
 
52103
+ if (this._useAlphaCutoff) {
52104
+ gl.uniform1f(this._alphaCutoffLocation, textureSet.alphaCutoff);
52105
+ }
52106
+
52101
52107
  if (colorUniform) {
52102
52108
  const colorKey = this._edges ? "edgeColor" : "fillColor";
52103
52109
  const alphaKey = this._edges ? "edgeAlpha" : "fillAlpha";
@@ -52148,8 +52154,8 @@ class VBORenderer {
52148
52154
  */
52149
52155
  class TrianglesBatchingRenderer extends VBORenderer {
52150
52156
 
52151
- constructor(scene, withSAO, {edges = false} = {}) {
52152
- super(scene, withSAO, {instancing: false, edges});
52157
+ constructor(scene, withSAO, {edges = false, useAlphaCutoff = false} = {}) {
52158
+ super(scene, withSAO, {instancing: false, edges, useAlphaCutoff});
52153
52159
  }
52154
52160
 
52155
52161
  _draw(drawCfg) {
@@ -52166,7 +52172,6 @@ class TrianglesBatchingRenderer extends VBORenderer {
52166
52172
  } else {
52167
52173
  const count = frameCtx.pickElementsCount || state.indicesBuf.numItems;
52168
52174
  const offset = frameCtx.pickElementsOffset ? frameCtx.pickElementsOffset * state.indicesBuf.itemByteSize : 0;
52169
-
52170
52175
  gl.drawElements(gl.TRIANGLES, count, state.indicesBuf.itemType, offset);
52171
52176
 
52172
52177
  if (incrementDrawState) {
@@ -54619,6 +54624,7 @@ class TrianglesPickNormalsFlatRenderer$1 extends TrianglesBatchingRenderer {
54619
54624
  /**
54620
54625
  * @private
54621
54626
  */
54627
+
54622
54628
  class TrianglesColorTextureRenderer$1 extends TrianglesBatchingRenderer {
54623
54629
  _getHash() {
54624
54630
  const scene = this._scene;
@@ -54626,11 +54632,10 @@ class TrianglesColorTextureRenderer$1 extends TrianglesBatchingRenderer {
54626
54632
  }
54627
54633
 
54628
54634
  drawLayer(frameCtx, layer, renderPass) {
54629
- super.drawLayer(frameCtx, layer, renderPass, {incrementDrawState: true});
54635
+ super.drawLayer(frameCtx, layer, renderPass, { incrementDrawState: true });
54630
54636
  }
54631
54637
 
54632
54638
  _buildVertexShader() {
54633
-
54634
54639
  const scene = this._scene;
54635
54640
  const sectionPlanesState = scene._sectionPlanesState;
54636
54641
  const clipping = sectionPlanesState.getNumAllocatedSectionPlanes() > 0;
@@ -54685,6 +54690,7 @@ class TrianglesColorTextureRenderer$1 extends TrianglesBatchingRenderer {
54685
54690
  if (scene.entityOffsetsEnabled) {
54686
54691
  src.push("worldPosition.xyz = worldPosition.xyz + offset;");
54687
54692
  }
54693
+
54688
54694
  src.push("vec4 viewPosition = viewMatrix * worldPosition; ");
54689
54695
  src.push("vViewPosition = viewPosition;");
54690
54696
  src.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);");
@@ -54695,10 +54701,12 @@ class TrianglesColorTextureRenderer$1 extends TrianglesBatchingRenderer {
54695
54701
  src.push("vFragDepth = 1.0 + clipPos.w;");
54696
54702
  src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
54697
54703
  }
54704
+
54698
54705
  if (clipping) {
54699
54706
  src.push("vWorldPosition = worldPosition;");
54700
54707
  src.push("vFlags = flags;");
54701
54708
  }
54709
+
54702
54710
  src.push("gl_Position = clipPos;");
54703
54711
  src.push("}");
54704
54712
  src.push("}");
@@ -54711,6 +54719,7 @@ class TrianglesColorTextureRenderer$1 extends TrianglesBatchingRenderer {
54711
54719
  const lightsState = scene._lightsState;
54712
54720
  const sectionPlanesState = scene._sectionPlanesState;
54713
54721
  const clipping = sectionPlanesState.getNumAllocatedSectionPlanes() > 0;
54722
+ const useAlphaCutoff = this._useAlphaCutoff;
54714
54723
  const src = [];
54715
54724
  src.push("#version 300 es");
54716
54725
  src.push("// Triangles batching color texture fragment shader");
@@ -54769,6 +54778,7 @@ class TrianglesColorTextureRenderer$1 extends TrianglesBatchingRenderer {
54769
54778
  src.push("uniform vec4 sliceColor;");
54770
54779
  }
54771
54780
  this._addMatricesUniformBlockLines(src);
54781
+
54772
54782
  src.push("uniform vec4 lightAmbient;");
54773
54783
  for (let i = 0, len = lightsState.lights.length; i < len; i++) {
54774
54784
  const light = lightsState.lights[i];
@@ -54788,6 +54798,10 @@ class TrianglesColorTextureRenderer$1 extends TrianglesBatchingRenderer {
54788
54798
  }
54789
54799
  }
54790
54800
 
54801
+ if (useAlphaCutoff) {
54802
+ src.push("uniform float materialAlphaCutoff;");
54803
+ }
54804
+
54791
54805
  src.push("in vec4 vViewPosition;");
54792
54806
  src.push("in vec4 vColor;");
54793
54807
  src.push("in vec2 vUV;");
@@ -54855,11 +54869,21 @@ class TrianglesColorTextureRenderer$1 extends TrianglesBatchingRenderer {
54855
54869
  }
54856
54870
 
54857
54871
  src.push("vec4 color = vec4((lightAmbient.rgb * lightAmbient.a * newColor.rgb) + (reflectedColor * newColor.rgb), newColor.a);");
54872
+
54873
+ src.push("vec4 sampleColor = texture(uColorMap, vUV);");
54874
+
54875
+ if (useAlphaCutoff) {
54876
+ src.push("if (sampleColor.a < materialAlphaCutoff) {");
54877
+ src.push(" discard;");
54878
+ src.push("}");
54879
+ }
54880
+
54858
54881
  if (gammaOutput) {
54859
- src.push("vec4 colorTexel = color * sRGBToLinear(texture(uColorMap, vUV));");
54860
- } else {
54861
- src.push("vec4 colorTexel = color * texture(uColorMap, vUV);");
54882
+ src.push("sampleColor = sRGBToLinear(sampleColor);");
54862
54883
  }
54884
+
54885
+ src.push("vec4 colorTexel = color * sampleColor;");
54886
+
54863
54887
  src.push("float opacity = color.a;");
54864
54888
 
54865
54889
  if (this._withSAO) {
@@ -55406,7 +55430,7 @@ class TrianglesSnapRenderer$1 extends VBORenderer{
55406
55430
 
55407
55431
  src.push(`int pickFlag = int(flags) >> 12 & 0xF;`);
55408
55432
  src.push(`if (pickFlag != renderPass) {`);
55409
- src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"); // Cull vertex
55433
+ src.push(" gl_Position = vec4(2.0, 0.0, 0.0, 0.0);"); // Cull vertex
55410
55434
  src.push(" } else {");
55411
55435
  src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");
55412
55436
  if (scene.entityOffsetsEnabled) {
@@ -55533,6 +55557,14 @@ class Renderers$1 {
55533
55557
  this._colorTextureRendererWithSAO.destroy();
55534
55558
  this._colorTextureRendererWithSAO = null;
55535
55559
  }
55560
+ if (this._colorTextureRendererAlphaCutoff && (!this._colorTextureRendererAlphaCutoff.getValid())) {
55561
+ this._colorTextureRendererAlphaCutoff.destroy();
55562
+ this._colorTextureRendererAlphaCutoff = null;
55563
+ }
55564
+ if (this._colorTextureRendererWithSAOAlphaCutoff && (!this._colorTextureRendererWithSAOAlphaCutoff.getValid())) {
55565
+ this._colorTextureRendererWithSAOAlphaCutoff.destroy();
55566
+ this._colorTextureRendererWithSAOAlphaCutoff = null;
55567
+ }
55536
55568
  if (this._pbrRenderer && (!this._pbrRenderer.getValid())) {
55537
55569
  this._pbrRenderer.destroy();
55538
55570
  this._pbrRenderer = null;
@@ -55660,6 +55692,20 @@ class Renderers$1 {
55660
55692
  return this._colorTextureRendererWithSAO;
55661
55693
  }
55662
55694
 
55695
+ get colorTextureRendererAlphaCutoff() {
55696
+ if (!this._colorTextureRendererAlphaCutoff) {
55697
+ this._colorTextureRendererAlphaCutoff = new TrianglesColorTextureRenderer$1(this._scene, false, { useAlphaCutoff: true });
55698
+ }
55699
+ return this._colorTextureRendererAlphaCutoff;
55700
+ }
55701
+
55702
+ get colorTextureRendererWithSAOAlphaCutoff() {
55703
+ if (!this._colorTextureRendererWithSAOAlphaCutoff) {
55704
+ this._colorTextureRendererWithSAOAlphaCutoff = new TrianglesColorTextureRenderer$1(this._scene, true, { useAlphaCutoff: true });
55705
+ }
55706
+ return this._colorTextureRendererWithSAOAlphaCutoff;
55707
+ }
55708
+
55663
55709
  get pbrRenderer() {
55664
55710
  if (!this._pbrRenderer) {
55665
55711
  this._pbrRenderer = new TrianglesPBRRenderer$1(this._scene, false);
@@ -55784,6 +55830,12 @@ class Renderers$1 {
55784
55830
  if (this._colorTextureRendererWithSAO) {
55785
55831
  this._colorTextureRendererWithSAO.destroy();
55786
55832
  }
55833
+ if (this._colorTextureRendererAlphaCutoff) {
55834
+ this._colorTextureRendererAlphaCutoff.destroy();
55835
+ }
55836
+ if (this._colorTextureRendererWithSAOAlphaCutoff) {
55837
+ this._colorTextureRendererWithSAOAlphaCutoff.destroy();
55838
+ }
55787
55839
  if (this._pbrRenderer) {
55788
55840
  this._pbrRenderer.destroy();
55789
55841
  }
@@ -55832,29 +55884,29 @@ class Renderers$1 {
55832
55884
  }
55833
55885
  }
55834
55886
 
55835
- const cachdRenderers$1 = {};
55887
+ const cachedRenderers$6 = {};
55836
55888
 
55837
55889
  /**
55838
55890
  * @private
55839
55891
  */
55840
55892
  function getRenderers$7(scene) {
55841
55893
  const sceneId = scene.id;
55842
- let batchingRenderers = cachdRenderers$1[sceneId];
55843
- if (!batchingRenderers) {
55844
- batchingRenderers = new Renderers$1(scene);
55845
- cachdRenderers$1[sceneId] = batchingRenderers;
55846
- batchingRenderers._compile();
55847
- batchingRenderers.eagerCreateRenders();
55894
+ let renderers = cachedRenderers$6[sceneId];
55895
+ if (!renderers) {
55896
+ renderers = new Renderers$1(scene);
55897
+ cachedRenderers$6[sceneId] = renderers;
55898
+ renderers._compile();
55899
+ renderers.eagerCreateRenders();
55848
55900
  scene.on("compile", () => {
55849
- batchingRenderers._compile();
55850
- batchingRenderers.eagerCreateRenders();
55901
+ renderers._compile();
55902
+ renderers.eagerCreateRenders();
55851
55903
  });
55852
55904
  scene.on("destroyed", () => {
55853
- delete cachdRenderers$1[sceneId];
55854
- batchingRenderers._destroy();
55905
+ delete cachedRenderers$6[sceneId];
55906
+ renderers._destroy();
55855
55907
  });
55856
55908
  }
55857
- return batchingRenderers;
55909
+ return renderers;
55858
55910
  }
55859
55911
 
55860
55912
  let maxDataTextureHeight = 1 << 16;
@@ -57018,14 +57070,21 @@ class VBOBatchingTrianglesLayer {
57018
57070
  return;
57019
57071
  }
57020
57072
  this._updateBackfaceCull(renderFlags, frameCtx);
57073
+ const useAlphaCutoff = this._state.textureSet && (typeof(this._state.textureSet.alphaCutoff) === "number");
57021
57074
  if (frameCtx.withSAO && this.model.saoEnabled) {
57022
57075
  if (frameCtx.pbrEnabled && this.model.pbrEnabled && this._state.pbrSupported) {
57023
57076
  if (this._renderers.pbrRendererWithSAO) {
57024
57077
  this._renderers.pbrRendererWithSAO.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
57025
57078
  }
57026
57079
  } else if (frameCtx.colorTextureEnabled && this.model.colorTextureEnabled && this._state.colorTextureSupported) {
57027
- if (this._renderers.colorTextureRendererWithSAO) {
57028
- this._renderers.colorTextureRendererWithSAO.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
57080
+ if (useAlphaCutoff) {
57081
+ if (this._renderers.colorTextureRendererWithSAOAlphaCutoff) {
57082
+ this._renderers.colorTextureRendererWithSAOAlphaCutoff.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
57083
+ }
57084
+ } else {
57085
+ if (this._renderers.colorTextureRendererWithSAO) {
57086
+ this._renderers.colorTextureRendererWithSAO.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
57087
+ }
57029
57088
  }
57030
57089
  } else if (this._state.normalsBuf) {
57031
57090
  if (this._renderers.colorRendererWithSAO) {
@@ -57042,8 +57101,14 @@ class VBOBatchingTrianglesLayer {
57042
57101
  this._renderers.pbrRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
57043
57102
  }
57044
57103
  } else if (frameCtx.colorTextureEnabled && this.model.colorTextureEnabled && this._state.colorTextureSupported) {
57045
- if (this._renderers.colorTextureRenderer) {
57046
- this._renderers.colorTextureRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
57104
+ if (useAlphaCutoff) {
57105
+ if (this._renderers.colorTextureRendererAlphaCutoff) {
57106
+ this._renderers.colorTextureRendererAlphaCutoff.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
57107
+ }
57108
+ } else {
57109
+ if (this._renderers.colorTextureRenderer) {
57110
+ this._renderers.colorTextureRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
57111
+ }
57047
57112
  }
57048
57113
  } else if (this._state.normalsBuf) {
57049
57114
  if (this._renderers.colorRenderer) {
@@ -57080,8 +57145,15 @@ class VBOBatchingTrianglesLayer {
57080
57145
  this._renderers.pbrRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_TRANSPARENT);
57081
57146
  }
57082
57147
  } else if (frameCtx.colorTextureEnabled && this.model.colorTextureEnabled && this._state.colorTextureSupported) {
57083
- if (this._renderers.colorTextureRenderer) {
57084
- this._renderers.colorTextureRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_TRANSPARENT);
57148
+ const useAlphaCutoff = this._state.textureSet && (typeof(this._state.textureSet.alphaCutoff) === "number");
57149
+ if (useAlphaCutoff) {
57150
+ if (this._renderers.colorTextureRendererAlphaCutoff) {
57151
+ this._renderers.colorTextureRendererAlphaCutoff.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_TRANSPARENT);
57152
+ }
57153
+ } else {
57154
+ if (this._renderers.colorTextureRenderer) {
57155
+ this._renderers.colorTextureRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_TRANSPARENT);
57156
+ }
57085
57157
  }
57086
57158
  } else if (this._state.normalsBuf) {
57087
57159
  if (this._renderers.colorRenderer) {
@@ -57425,8 +57497,8 @@ class VBOBatchingTrianglesLayer {
57425
57497
  * @private
57426
57498
  */
57427
57499
  class TrianglesInstancingRenderer extends VBORenderer {
57428
- constructor(scene, withSAO, {edges = false} = {}) {
57429
- super(scene, withSAO, {instancing: true, edges});
57500
+ constructor(scene, withSAO, {edges = false, useAlphaCutoff = false} = {}) {
57501
+ super(scene, withSAO, {instancing: true, edges, useAlphaCutoff});
57430
57502
  }
57431
57503
 
57432
57504
  _draw(drawCfg) {
@@ -57435,13 +57507,14 @@ class TrianglesInstancingRenderer extends VBORenderer {
57435
57507
  const {
57436
57508
  state,
57437
57509
  frameCtx,
57438
- incrementDrawState,
57510
+ incrementDrawState
57439
57511
  } = drawCfg;
57440
57512
 
57441
57513
  if (this._edges) {
57442
57514
  gl.drawElementsInstanced(gl.LINES, state.edgeIndicesBuf.numItems, state.edgeIndicesBuf.itemType, 0, state.numInstances);
57443
57515
  } else {
57444
57516
  gl.drawElementsInstanced(gl.TRIANGLES, state.indicesBuf.numItems, state.indicesBuf.itemType, 0, state.numInstances);
57517
+
57445
57518
  if (incrementDrawState) {
57446
57519
  frameCtx.drawElements++;
57447
57520
  }
@@ -59970,7 +60043,6 @@ class TrianglesPickNormalsFlatRenderer extends TrianglesInstancingRenderer {
59970
60043
  * @private
59971
60044
  */
59972
60045
 
59973
-
59974
60046
  class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
59975
60047
  _getHash() {
59976
60048
  const scene = this._scene;
@@ -60039,7 +60111,7 @@ class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
60039
60111
  src.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");
60040
60112
  src.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");
60041
60113
  if (scene.entityOffsetsEnabled) {
60042
- src.push(" worldPosition.xyz = worldPosition.xyz + offset;");
60114
+ src.push("worldPosition.xyz = worldPosition.xyz + offset;");
60043
60115
  }
60044
60116
 
60045
60117
  src.push("vec4 viewPosition = viewMatrix * worldPosition; ");
@@ -60067,11 +60139,10 @@ class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
60067
60139
  _buildFragmentShader() {
60068
60140
  const scene = this._scene;
60069
60141
  const gammaOutput = scene.gammaOutput; // If set, then it expects that all textures and colors need to be outputted in premultiplied gamma. Default is false.
60070
- const sectionPlanesState = scene._sectionPlanesState;
60071
60142
  const lightsState = scene._lightsState;
60072
- let i;
60073
- let len;
60143
+ const sectionPlanesState = scene._sectionPlanesState;
60074
60144
  const clipping = sectionPlanesState.getNumAllocatedSectionPlanes() > 0;
60145
+ const useAlphaCutoff = this._useAlphaCutoff;
60075
60146
  const src = [];
60076
60147
  src.push("#version 300 es");
60077
60148
  src.push("// Instancing geometry drawing fragment shader");
@@ -60083,6 +60154,7 @@ class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
60083
60154
  src.push("precision mediump float;");
60084
60155
  src.push("precision mediump int;");
60085
60156
  src.push("#endif");
60157
+
60086
60158
  if (scene.logarithmicDepthBufferEnabled) {
60087
60159
  src.push("in float isPerspective;");
60088
60160
  src.push("uniform float logDepthBufFC;");
@@ -60131,7 +60203,7 @@ class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
60131
60203
  this._addMatricesUniformBlockLines(src);
60132
60204
 
60133
60205
  src.push("uniform vec4 lightAmbient;");
60134
- for (i = 0, len = lightsState.lights.length; i < len; i++) {
60206
+ for (let i = 0, len = lightsState.lights.length; i < len; i++) {
60135
60207
  const light = lightsState.lights[i];
60136
60208
  if (light.type === "ambient") {
60137
60209
  continue;
@@ -60149,6 +60221,10 @@ class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
60149
60221
  }
60150
60222
  }
60151
60223
 
60224
+ if (useAlphaCutoff) {
60225
+ src.push("uniform float materialAlphaCutoff;");
60226
+ }
60227
+
60152
60228
  src.push("in vec4 vViewPosition;");
60153
60229
  src.push("in vec4 vColor;");
60154
60230
  src.push("in vec2 vUV;");
@@ -60184,7 +60260,7 @@ class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
60184
60260
  src.push("vec3 yTangent = dFdy( vViewPosition.xyz );");
60185
60261
  src.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");
60186
60262
 
60187
- for (i = 0, len = lightsState.lights.length; i < len; i++) {
60263
+ for (let i = 0, len = lightsState.lights.length; i < len; i++) {
60188
60264
  const light = lightsState.lights[i];
60189
60265
  if (light.type === "ambient") {
60190
60266
  continue;
@@ -60210,16 +60286,27 @@ class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
60210
60286
  } else {
60211
60287
  continue;
60212
60288
  }
60289
+
60213
60290
  src.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);");
60214
60291
  src.push("reflectedColor += lambertian * (lightColor" + i + ".rgb * lightColor" + i + ".a);");
60215
60292
  }
60216
60293
 
60217
60294
  src.push("vec4 color = vec4((lightAmbient.rgb * lightAmbient.a * newColor.rgb) + (reflectedColor * newColor.rgb), newColor.a);");
60295
+
60296
+ src.push("vec4 sampleColor = texture(uColorMap, vUV);");
60297
+
60298
+ if (useAlphaCutoff) {
60299
+ src.push("if (sampleColor.a < materialAlphaCutoff) {");
60300
+ src.push(" discard;");
60301
+ src.push("}");
60302
+ }
60303
+
60218
60304
  if (gammaOutput) {
60219
- src.push("vec4 colorTexel = color * sRGBToLinear(texture(uColorMap, vUV));");
60220
- } else {
60221
- src.push("vec4 colorTexel = color * texture(uColorMap, vUV);");
60305
+ src.push("sampleColor = sRGBToLinear(sampleColor);");
60222
60306
  }
60307
+
60308
+ src.push("vec4 colorTexel = color * sampleColor;");
60309
+
60223
60310
  src.push("float opacity = color.a;");
60224
60311
 
60225
60312
  if (this._withSAO) {
@@ -60231,9 +60318,10 @@ class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
60231
60318
  src.push(" float blendFactor = uSAOParams[3];");
60232
60319
  src.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);");
60233
60320
  src.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;");
60234
- src.push(" outColor = vec4(newColor.rgb * colorTexel.rgb * ambient, opacity);");
60321
+
60322
+ src.push(" outColor = vec4(colorTexel.rgb * ambient, opacity);");
60235
60323
  } else {
60236
- src.push(" outColor = vec4(newColor.rgb * colorTexel.rgb, opacity);");
60324
+ src.push(" outColor = vec4(colorTexel.rgb, opacity);");
60237
60325
  }
60238
60326
 
60239
60327
  if (gammaOutput) {
@@ -60241,7 +60329,7 @@ class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
60241
60329
  }
60242
60330
 
60243
60331
  if (scene.logarithmicDepthBufferEnabled) {
60244
- src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
60332
+ src.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
60245
60333
  }
60246
60334
 
60247
60335
  src.push("}");
@@ -60811,7 +60899,7 @@ class TrianglesSnapRenderer extends VBORenderer {
60811
60899
  // renderPass = PICK
60812
60900
  src.push(`int pickFlag = int(flags) >> 12 & 0xF;`);
60813
60901
  src.push(`if (pickFlag != renderPass) {`);
60814
- src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"); // Cull vertex
60902
+ src.push(" gl_Position = vec4(2.0, 0.0, 0.0, 0.0);"); // Cull vertex
60815
60903
  src.push("} else {");
60816
60904
  src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");
60817
60905
  src.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");
@@ -60931,14 +61019,6 @@ class Renderers {
60931
61019
  this._flatColorRendererWithSAO.destroy();
60932
61020
  this._flatColorRendererWithSAO = null;
60933
61021
  }
60934
- if (this._pbrRenderer && (!this._pbrRenderer.getValid())) {
60935
- this._pbrRenderer.destroy();
60936
- this._pbrRenderer = null;
60937
- }
60938
- if (this._pbrRendererWithSAO && (!this._pbrRendererWithSAO.getValid())) {
60939
- this._pbrRendererWithSAO.destroy();
60940
- this._pbrRendererWithSAO = null;
60941
- }
60942
61022
  if (this._colorTextureRenderer && (!this._colorTextureRenderer.getValid())) {
60943
61023
  this._colorTextureRenderer.destroy();
60944
61024
  this._colorTextureRenderer = null;
@@ -60947,6 +61027,22 @@ class Renderers {
60947
61027
  this._colorTextureRendererWithSAO.destroy();
60948
61028
  this._colorTextureRendererWithSAO = null;
60949
61029
  }
61030
+ if (this._colorTextureRendererAlphaCutoff && (!this._colorTextureRendererAlphaCutoff.getValid())) {
61031
+ this._colorTextureRendererAlphaCutoff.destroy();
61032
+ this._colorTextureRendererAlphaCutoff = null;
61033
+ }
61034
+ if (this._colorTextureRendererWithSAOAlphaCutoff && (!this._colorTextureRendererWithSAOAlphaCutoff.getValid())) {
61035
+ this._colorTextureRendererWithSAOAlphaCutoff.destroy();
61036
+ this._colorTextureRendererWithSAOAlphaCutoff = null;
61037
+ }
61038
+ if (this._pbrRenderer && (!this._pbrRenderer.getValid())) {
61039
+ this._pbrRenderer.destroy();
61040
+ this._pbrRenderer = null;
61041
+ }
61042
+ if (this._pbrRendererWithSAO && (!this._pbrRendererWithSAO.getValid())) {
61043
+ this._pbrRendererWithSAO.destroy();
61044
+ this._pbrRendererWithSAO = null;
61045
+ }
60950
61046
  if (this._depthRenderer && (!this._depthRenderer.getValid())) {
60951
61047
  this._depthRenderer.destroy();
60952
61048
  this._depthRenderer = null;
@@ -60979,7 +61075,7 @@ class Renderers {
60979
61075
  this._pickNormalsRenderer.destroy();
60980
61076
  this._pickNormalsRenderer = null;
60981
61077
  }
60982
- if (this._pickNormalsFlatRenderer && (!this._pickNormalsFlatRenderer.getValid())) {
61078
+ if (this._pickNormalsFlatRenderer && this._pickNormalsFlatRenderer.getValid() === false) {
60983
61079
  this._pickNormalsFlatRenderer.destroy();
60984
61080
  this._pickNormalsFlatRenderer = null;
60985
61081
  }
@@ -61052,20 +61148,6 @@ class Renderers {
61052
61148
  return this._flatColorRendererWithSAO;
61053
61149
  }
61054
61150
 
61055
- get pbrRenderer() {
61056
- if (!this._pbrRenderer) {
61057
- this._pbrRenderer = new TrianglesPBRRenderer(this._scene, false);
61058
- }
61059
- return this._pbrRenderer;
61060
- }
61061
-
61062
- get pbrRendererWithSAO() {
61063
- if (!this._pbrRendererWithSAO) {
61064
- this._pbrRendererWithSAO = new TrianglesPBRRenderer(this._scene, true);
61065
- }
61066
- return this._pbrRendererWithSAO;
61067
- }
61068
-
61069
61151
  get colorTextureRenderer() {
61070
61152
  if (!this._colorTextureRenderer) {
61071
61153
  this._colorTextureRenderer = new TrianglesColorTextureRenderer(this._scene, false);
@@ -61080,6 +61162,34 @@ class Renderers {
61080
61162
  return this._colorTextureRendererWithSAO;
61081
61163
  }
61082
61164
 
61165
+ get colorTextureRendererAlphaCutoff() {
61166
+ if (!this._colorTextureRendererAlphaCutoff) {
61167
+ this._colorTextureRendererAlphaCutoff = new TrianglesColorTextureRenderer(this._scene, false, { useAlphaCutoff: true });
61168
+ }
61169
+ return this._colorTextureRendererAlphaCutoff;
61170
+ }
61171
+
61172
+ get colorTextureRendererWithSAOAlphaCutoff() {
61173
+ if (!this._colorTextureRendererWithSAOAlphaCutoff) {
61174
+ this._colorTextureRendererWithSAOAlphaCutoff = new TrianglesColorTextureRenderer(this._scene, true, { useAlphaCutoff: true });
61175
+ }
61176
+ return this._colorTextureRendererWithSAOAlphaCutoff;
61177
+ }
61178
+
61179
+ get pbrRenderer() {
61180
+ if (!this._pbrRenderer) {
61181
+ this._pbrRenderer = new TrianglesPBRRenderer(this._scene, false);
61182
+ }
61183
+ return this._pbrRenderer;
61184
+ }
61185
+
61186
+ get pbrRendererWithSAO() {
61187
+ if (!this._pbrRendererWithSAO) {
61188
+ this._pbrRendererWithSAO = new TrianglesPBRRenderer(this._scene, true);
61189
+ }
61190
+ return this._pbrRendererWithSAO;
61191
+ }
61192
+
61083
61193
  get silhouetteRenderer() {
61084
61194
  if (!this._silhouetteRenderer) {
61085
61195
  this._silhouetteRenderer = new TrianglesSilhouetteRenderer(this._scene);
@@ -61157,13 +61267,6 @@ class Renderers {
61157
61267
  return this._shadowRenderer;
61158
61268
  }
61159
61269
 
61160
- get snapInitRenderer() {
61161
- if (!this._snapInitRenderer) {
61162
- this._snapInitRenderer = new TrianglesSnapInitRenderer(this._scene, false);
61163
- }
61164
- return this._snapInitRenderer;
61165
- }
61166
-
61167
61270
  get snapRenderer() {
61168
61271
  if (!this._snapRenderer) {
61169
61272
  this._snapRenderer = new TrianglesSnapRenderer(this._scene);
@@ -61171,6 +61274,13 @@ class Renderers {
61171
61274
  return this._snapRenderer;
61172
61275
  }
61173
61276
 
61277
+ get snapInitRenderer() {
61278
+ if (!this._snapInitRenderer) {
61279
+ this._snapInitRenderer = new TrianglesSnapInitRenderer(this._scene);
61280
+ }
61281
+ return this._snapInitRenderer;
61282
+ }
61283
+
61174
61284
  _destroy() {
61175
61285
  if (this._colorRenderer) {
61176
61286
  this._colorRenderer.destroy();
@@ -61184,18 +61294,24 @@ class Renderers {
61184
61294
  if (this._flatColorRendererWithSAO) {
61185
61295
  this._flatColorRendererWithSAO.destroy();
61186
61296
  }
61187
- if (this._pbrRenderer) {
61188
- this._pbrRenderer.destroy();
61189
- }
61190
- if (this._pbrRendererWithSAO) {
61191
- this._pbrRendererWithSAO.destroy();
61192
- }
61193
61297
  if (this._colorTextureRenderer) {
61194
61298
  this._colorTextureRenderer.destroy();
61195
61299
  }
61196
61300
  if (this._colorTextureRendererWithSAO) {
61197
61301
  this._colorTextureRendererWithSAO.destroy();
61198
61302
  }
61303
+ if (this._colorTextureRendererAlphaCutoff) {
61304
+ this._colorTextureRendererAlphaCutoff.destroy();
61305
+ }
61306
+ if (this._colorTextureRendererWithSAOAlphaCutoff) {
61307
+ this._colorTextureRendererWithSAOAlphaCutoff.destroy();
61308
+ }
61309
+ if (this._pbrRenderer) {
61310
+ this._pbrRenderer.destroy();
61311
+ }
61312
+ if (this._pbrRendererWithSAO) {
61313
+ this._pbrRendererWithSAO.destroy();
61314
+ }
61199
61315
  if (this._depthRenderer) {
61200
61316
  this._depthRenderer.destroy();
61201
61317
  }
@@ -61245,22 +61361,22 @@ const cachedRenderers$5 = {};
61245
61361
  */
61246
61362
  function getRenderers$6(scene) {
61247
61363
  const sceneId = scene.id;
61248
- let instancingRenderers = cachedRenderers$5[sceneId];
61249
- if (!instancingRenderers) {
61250
- instancingRenderers = new Renderers(scene);
61251
- cachedRenderers$5[sceneId] = instancingRenderers;
61252
- instancingRenderers._compile();
61253
- instancingRenderers.eagerCreateRenders();
61364
+ let renderers = cachedRenderers$5[sceneId];
61365
+ if (!renderers) {
61366
+ renderers = new Renderers(scene);
61367
+ cachedRenderers$5[sceneId] = renderers;
61368
+ renderers._compile();
61369
+ renderers.eagerCreateRenders();
61254
61370
  scene.on("compile", () => {
61255
- instancingRenderers._compile();
61256
- instancingRenderers.eagerCreateRenders();
61371
+ renderers._compile();
61372
+ renderers.eagerCreateRenders();
61257
61373
  });
61258
61374
  scene.on("destroyed", () => {
61259
61375
  delete cachedRenderers$5[sceneId];
61260
- instancingRenderers._destroy();
61376
+ renderers._destroy();
61261
61377
  });
61262
61378
  }
61263
- return instancingRenderers;
61379
+ return renderers;
61264
61380
  }
61265
61381
 
61266
61382
  const tempUint8Vec4$2 = new Uint8Array(4);
@@ -62042,14 +62158,21 @@ class VBOInstancingTrianglesLayer {
62042
62158
  return;
62043
62159
  }
62044
62160
  this._updateBackfaceCull(renderFlags, frameCtx);
62161
+ const useAlphaCutoff = this._state.textureSet && (typeof(this._state.textureSet.alphaCutoff) === "number");
62045
62162
  if (frameCtx.withSAO && this.model.saoEnabled) {
62046
62163
  if (frameCtx.pbrEnabled && this.model.pbrEnabled && this._state.pbrSupported) {
62047
62164
  if (this._renderers.pbrRendererWithSAO) {
62048
62165
  this._renderers.pbrRendererWithSAO.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
62049
62166
  }
62050
62167
  } else if (frameCtx.colorTextureEnabled && this.model.colorTextureEnabled && this._state.colorTextureSupported) {
62051
- if (this._renderers.colorTextureRendererWithSAO) {
62052
- this._renderers.colorTextureRendererWithSAO.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
62168
+ if (useAlphaCutoff) {
62169
+ if (this._renderers.colorTextureRendererWithSAOAlphaCutoff) {
62170
+ this._renderers.colorTextureRendererWithSAOAlphaCutoff.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
62171
+ }
62172
+ } else {
62173
+ if (this._renderers.colorTextureRendererWithSAO) {
62174
+ this._renderers.colorTextureRendererWithSAO.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
62175
+ }
62053
62176
  }
62054
62177
  } else if (this._state.normalsBuf) {
62055
62178
  if (this._renderers.colorRendererWithSAO) {
@@ -62065,8 +62188,14 @@ class VBOInstancingTrianglesLayer {
62065
62188
  this._renderers.pbrRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
62066
62189
  }
62067
62190
  } else if (frameCtx.colorTextureEnabled && this.model.colorTextureEnabled && this._state.colorTextureSupported) {
62068
- if (this._renderers.colorTextureRenderer) {
62069
- this._renderers.colorTextureRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
62191
+ if (useAlphaCutoff) {
62192
+ if (this._renderers.colorTextureRendererAlphaCutoff) {
62193
+ this._renderers.colorTextureRendererAlphaCutoff.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
62194
+ }
62195
+ } else {
62196
+ if (this._renderers.colorTextureRenderer) {
62197
+ this._renderers.colorTextureRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
62198
+ }
62070
62199
  }
62071
62200
  } else if (this._state.normalsBuf) {
62072
62201
  if (this._renderers.colorRenderer) {
@@ -63241,7 +63370,7 @@ class VBOBatchingLinesSnapRenderer extends VBORenderer{
63241
63370
 
63242
63371
  src.push(`int pickFlag = int(flags) >> 12 & 0xF;`);
63243
63372
  src.push(`if (pickFlag != renderPass) {`);
63244
- src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"); // Cull vertex
63373
+ src.push(" gl_Position = vec4(2.0, 0.0, 0.0, 0.0);"); // Cull vertex
63245
63374
  src.push(" } else {");
63246
63375
  src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");
63247
63376
  if (scene.entityOffsetsEnabled) {
@@ -64983,7 +65112,7 @@ class VBOInstancingLinesSnapRenderer extends VBORenderer {
64983
65112
  // renderPass = PICK
64984
65113
  src.push(`int pickFlag = int(flags) >> 12 & 0xF;`);
64985
65114
  src.push(`if (pickFlag != renderPass) {`);
64986
- src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"); // Cull vertex
65115
+ src.push(" gl_Position = vec4(2.0, 0.0, 0.0, 0.0);"); // Cull vertex
64987
65116
  src.push("} else {");
64988
65117
  src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");
64989
65118
  src.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");
@@ -75750,6 +75879,14 @@ class DTXTrianglesSnapRenderer {
75750
75879
  src.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);");
75751
75880
  src.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);");
75752
75881
 
75882
+ // flags.w = NOT_RENDERED | PICK
75883
+ // renderPass = PICK
75884
+
75885
+ src.push(`if (int(flags.w) != renderPass) {`);
75886
+ src.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"); // Cull vertex
75887
+ src.push(" return;"); // Cull vertex
75888
+ src.push("}");
75889
+
75753
75890
  src.push("{");
75754
75891
 
75755
75892
  // get vertex base
@@ -76165,6 +76302,14 @@ class DTXTrianglesSnapInitRenderer {
76165
76302
  src.push("uvec4 flags = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+2, objectIndexCoords.y), 0);");
76166
76303
  src.push("uvec4 flags2 = texelFetch (uObjectPerObjectColorsAndFlags, ivec2(objectIndexCoords.x*8+3, objectIndexCoords.y), 0);");
76167
76304
 
76305
+ // flags.w = NOT_RENDERED | PICK
76306
+ // renderPass = PICK
76307
+
76308
+ src.push(`if (int(flags.w) != renderPass) {`);
76309
+ src.push(" gl_Position = vec4(3.0, 3.0, 3.0, 1.0);"); // Cull vertex
76310
+ src.push(" return;"); // Cull vertex
76311
+ src.push("}");
76312
+
76168
76313
  src.push("{");
76169
76314
 
76170
76315
  // get color
@@ -80557,6 +80702,11 @@ class SceneModelTextureSet {
80557
80702
  */
80558
80703
  this.colorTexture = cfg.colorTexture;
80559
80704
 
80705
+ /**
80706
+ * The alpha cutoff [float]
80707
+ */
80708
+ this.alphaCutoff = cfg.alphaCutoff;
80709
+
80560
80710
  /**
80561
80711
  * The metallic-roughness texture.
80562
80712
  * @type {SceneModelTexture|*}
@@ -85113,6 +85263,7 @@ class SceneModel extends Component {
85113
85263
  id: textureSetId,
85114
85264
  model: this,
85115
85265
  colorTexture,
85266
+ alphaCutoff: cfg.alphaCutoff,
85116
85267
  metallicRoughnessTexture,
85117
85268
  normalsTexture,
85118
85269
  emissiveTexture,
@@ -85546,6 +85697,14 @@ class SceneModel extends Component {
85546
85697
  return this._createMesh(cfg);
85547
85698
  }
85548
85699
 
85700
+ _createDefaultIndices(numIndices) {
85701
+ const indices = [];
85702
+ for (let i = 0; i < numIndices; i++) {
85703
+ indices.push(i);
85704
+ }
85705
+ return indices;
85706
+ }
85707
+
85549
85708
  _createMesh(cfg) {
85550
85709
  const mesh = new SceneModelMesh(this, cfg.id, cfg.color, cfg.opacity, cfg.transform, cfg.textureSet);
85551
85710
  mesh.pickId = this.scene._renderer.getPickID(mesh);
@@ -101595,8 +101754,6 @@ class MetaScene {
101595
101754
  * @param {String} modelId ID for the new {@link MetaModel}, which will have {@link MetaModel#id} set to this value.
101596
101755
  * @param {Object} metaModelData Data for the {@link MetaModel}.
101597
101756
  * @param {Object} [options] Options for creating the {@link MetaModel}.
101598
- * @param {Object} [options.includeTypes] When provided, only create {@link MetaObject}s with types in this list.
101599
- * @param {Object} [options.excludeTypes] When provided, never create {@link MetaObject}s with types in this list.
101600
101757
  * @param {Boolean} [options.globalizeObjectIds=false] Whether to globalize each {@link MetaObject#id}. Set this ````true```` when you need to load multiple instances of the same meta model, to avoid ID clashes between the meta objects in the different instances.
101601
101758
  * @returns {MetaModel} The new MetaModel.
101602
101759
  */
@@ -117582,40 +117739,6 @@ class GLTFSceneModelLoader {
117582
117739
  }
117583
117740
  }
117584
117741
 
117585
- function getMetaModelCorrections(metaModelJSON) {
117586
- const eachRootStats = {};
117587
- const eachChildRoot = {};
117588
- const metaObjects = metaModelJSON.metaObjects || [];
117589
- const metaObjectsMap = {};
117590
- for (let i = 0, len = metaObjects.length; i < len; i++) {
117591
- const metaObject = metaObjects[i];
117592
- metaObjectsMap[metaObject.id] = metaObject;
117593
- }
117594
- for (let i = 0, len = metaObjects.length; i < len; i++) {
117595
- const metaObject = metaObjects[i];
117596
- if (metaObject.parent !== undefined && metaObject.parent !== null) {
117597
- const metaObjectParent = metaObjectsMap[metaObject.parent];
117598
- if (metaObject.type === metaObjectParent.type) {
117599
- let rootMetaObject = metaObjectParent;
117600
- while (rootMetaObject.parent && metaObjectsMap[rootMetaObject.parent].type === rootMetaObject.type) {
117601
- rootMetaObject = metaObjectsMap[rootMetaObject.parent];
117602
- }
117603
- const rootStats = eachRootStats[rootMetaObject.id] || (eachRootStats[rootMetaObject.id] = {
117604
- numChildren: 0,
117605
- countChildren: 0
117606
- });
117607
- rootStats.numChildren++;
117608
- eachChildRoot[metaObject.id] = rootMetaObject;
117609
- }
117610
- }
117611
- }
117612
- return {
117613
- metaObjectsMap,
117614
- eachRootStats,
117615
- eachChildRoot
117616
- };
117617
- }
117618
-
117619
117742
  function loadGLTF(plugin, src, metaModelJSON, options, sceneModel, ok, error) {
117620
117743
  const spinner = plugin.viewer.scene.canvas.spinner;
117621
117744
  spinner.processes++;
@@ -117657,7 +117780,9 @@ function parseGLTF(plugin, src, gltf, metaModelJSON, options, sceneModel, ok) {
117657
117780
  const ctx = {
117658
117781
  src: src,
117659
117782
  entityId: options.entityId,
117660
- metaModelCorrections: metaModelJSON ? getMetaModelCorrections(metaModelJSON) : null,
117783
+ metaModelJSON,
117784
+ autoMetaModel: options.autoMetaModel,
117785
+ metaObjects: [],
117661
117786
  loadBuffer: options.loadBuffer,
117662
117787
  basePath: options.basePath,
117663
117788
  handlenode: options.handlenode,
@@ -117676,8 +117801,20 @@ function parseGLTF(plugin, src, gltf, metaModelJSON, options, sceneModel, ok) {
117676
117801
  };
117677
117802
  loadTextures(ctx);
117678
117803
  loadMaterials(ctx);
117804
+ if (options.autoMetaModel) {
117805
+ ctx.metaObjects.push({
117806
+ id: sceneModel.id,
117807
+ type: "Default",
117808
+ name: sceneModel.id
117809
+ });
117810
+ }
117679
117811
  loadDefaultScene(ctx);
117680
117812
  sceneModel.finalize();
117813
+ if (options.autoMetaModel) {
117814
+ plugin.viewer.metaScene.createMetaModel(sceneModel.id, {
117815
+ metaObjects: ctx.metaObjects
117816
+ });
117817
+ }
117681
117818
  spinner.processes--;
117682
117819
  ok();
117683
117820
  });
@@ -117806,23 +117943,17 @@ function loadTextureSet(ctx, material) {
117806
117943
  if (material.emissiveTexture) {
117807
117944
  textureSetCfg.emissiveTextureId = material.emissiveTexture.texture._textureId;
117808
117945
  }
117809
- // const alphaMode = material.alphaMode;
117810
- // switch (alphaMode) {
117811
- // case "NORMAL_OPAQUE":
117812
- // materialCfg.alphaMode = "opaque";
117813
- // break;
117814
- // case "MASK":
117815
- // materialCfg.alphaMode = "mask";
117816
- // break;
117817
- // case "BLEND":
117818
- // materialCfg.alphaMode = "blend";
117819
- // break;
117820
- // default:
117821
- // }
117822
- // const alphaCutoff = material.alphaCutoff;
117823
- // if (alphaCutoff !== undefined) {
117824
- // materialCfg.alphaCutoff = alphaCutoff;
117825
- // }
117946
+
117947
+ switch (material.alphaMode) {
117948
+ case "OPAQUE":
117949
+ break;
117950
+ case "MASK":
117951
+ const alphaCutoff = material.alphaCutoff;
117952
+ // Default from the spec https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#reference-material
117953
+ textureSetCfg.alphaCutoff = (alphaCutoff !== undefined) ? alphaCutoff : 0.5;
117954
+ break;
117955
+ }
117956
+
117826
117957
  const metallicPBR = material.pbrMetallicRoughness;
117827
117958
  if (material.pbrMetallicRoughness) {
117828
117959
  const pbrMetallicRoughness = material.pbrMetallicRoughness;
@@ -117868,7 +117999,7 @@ function loadMaterialAttributes(ctx, material) { // Substitute RGBA for material
117868
117999
  opacity: 1,
117869
118000
  metallic: 0,
117870
118001
  roughness: 1,
117871
- doubleSided : true
118002
+ doubleSided: true
117872
118003
  };
117873
118004
  if (extensions) {
117874
118005
  const specularPBR = extensions["KHR_materials_pbrSpecularGlossiness"];
@@ -117942,9 +118073,22 @@ function loadScene(ctx, scene) {
117942
118073
  const node = nodes[i];
117943
118074
  countMeshUsage(ctx, node);
117944
118075
  }
117945
- for (let i = 0, len = nodes.length; i < len; i++) {
118076
+ for (let i = 0, len = nodes.length; i < len && !ctx.nodesHaveNames; i++) {
117946
118077
  const node = nodes[i];
117947
- loadNode(ctx, node, 0, null);
118078
+ if (testIfNodesHaveNames(node)) {
118079
+ ctx.nodesHaveNames = true;
118080
+ }
118081
+ }
118082
+ if (!ctx.nodesHaveNames) {
118083
+ for (let i = 0, len = nodes.length; i < len; i++) {
118084
+ const node = nodes[i];
118085
+ parseNodesWithoutNames(ctx, node, 0, null);
118086
+ }
118087
+ } else {
118088
+ for (let i = 0, len = nodes.length; i < len; i++) {
118089
+ const node = nodes[i];
118090
+ parseNodesWithNames(ctx, node, 0, null);
118091
+ }
117948
118092
  }
117949
118093
  }
117950
118094
 
@@ -117966,10 +118110,131 @@ function countMeshUsage(ctx, node) {
117966
118110
  }
117967
118111
  }
117968
118112
 
117969
- const deferredMeshIds = [];
118113
+ function testIfNodesHaveNames(node) {
118114
+ if (node.name) {
118115
+ return true;
118116
+ }
118117
+ if (node.children) {
118118
+ const children = node.children;
118119
+ for (let i = 0, len = children.length; i < len; i++) {
118120
+ const childNode = children[i];
118121
+ if (testIfNodesHaveNames(childNode)) {
118122
+ return true;
118123
+ }
118124
+ }
118125
+ }
118126
+ return false;
118127
+ }
118128
+
118129
+ /**
118130
+ * Parses a glTF node hierarchy that is known to NOT contain "name" attributes on the nodes.
118131
+ * Create a SceneMesh for each mesh primitive, and a single SceneObject.
118132
+ */
118133
+ const parseNodesWithoutNames = (function () {
118134
+ const meshIds = [];
118135
+ return function (ctx, node, depth, matrix, parentNode) {
118136
+ matrix = parseNodeMatrix(node, matrix);
118137
+ if (node.mesh) {
118138
+ parseNodeMesh(node, ctx, matrix, meshIds);
118139
+ }
118140
+ if (node.children) {
118141
+ const children = node.children;
118142
+ for (let i = 0, len = children.length; i < len; i++) {
118143
+ const childNode = children[i];
118144
+ parseNodesWithoutNames(ctx, childNode, depth + 1, matrix, node);
118145
+ }
118146
+ }
118147
+ if (depth === 0) {
118148
+ let entityId = "entity-" + ctx.nextId++;
118149
+ if (meshIds && meshIds.length > 0) {
118150
+ ctx.sceneModel.createEntity({
118151
+ id: entityId,
118152
+ meshIds,
118153
+ isObject: true
118154
+ });
118155
+ if (ctx.autoMetaModel) {
118156
+ ctx.metaObjects.push({
118157
+ id: entityId,
118158
+ type: "Default",
118159
+ name: entityId,
118160
+ parent: ctx.sceneModel.id
118161
+ });
118162
+ }
118163
+ meshIds.length = 0;
118164
+ }
118165
+ }
118166
+ }
118167
+ })();
118168
+
118169
+ const parseNodesWithNames = (function () {
118170
+
118171
+ const objectIdStack = [];
118172
+ const meshIdsStack = [];
118173
+ let meshIds = null;
118174
+
118175
+ return function (ctx, node, depth, matrix) {
118176
+ matrix = parseNodeMatrix(node, matrix);
118177
+ if (meshIds && node.mesh) {
118178
+ parseNodeMesh(node, ctx, matrix, meshIds);
118179
+ }
118180
+
118181
+ if (node.name) {
118182
+ meshIds = [];
118183
+ let entityId = node.name;
118184
+ if (!!entityId && ctx.sceneModel.objects[entityId]) ;
118185
+ while (!entityId || ctx.sceneModel.objects[entityId]) {
118186
+ entityId = "entity-" + ctx.nextId++;
118187
+ }
118188
+ objectIdStack.push(entityId);
118189
+ meshIdsStack.push(meshIds);
118190
+ }
118191
+
118192
+ if (node.children) {
118193
+ const children = node.children;
118194
+ for (let i = 0, len = children.length; i < len; i++) {
118195
+ const childNode = children[i];
118196
+ parseNodesWithNames(ctx, childNode, depth + 1, matrix);
118197
+ }
118198
+ }
118199
+
118200
+ // Post-order visit scene node
117970
118201
 
117971
- function loadNode(ctx, node, depth, matrix) {
117972
- ctx.gltfData;
118202
+ const nodeName = node.name;
118203
+ if ((nodeName !== undefined && nodeName !== null) || depth === 0) {
118204
+ let entityId = objectIdStack.pop();
118205
+ if (!entityId) { // For when there are no nodes with names
118206
+ entityId = "entity-" + ctx.nextId++;
118207
+ }
118208
+ let entityMeshIds = meshIdsStack.pop();
118209
+ if (meshIds && meshIds.length > 0) {
118210
+ ctx.sceneModel.createEntity({
118211
+ id: entityId,
118212
+ meshIds: entityMeshIds,
118213
+ isObject: true
118214
+ });
118215
+ if (ctx.autoMetaModel) {
118216
+ ctx.metaObjects.push({
118217
+ id: entityId,
118218
+ type: "Default",
118219
+ name: entityId,
118220
+ parent: ctx.sceneModel.id
118221
+ });
118222
+ }
118223
+ }
118224
+ meshIds = meshIdsStack.length > 0 ? meshIdsStack[meshIdsStack.length - 1] : null;
118225
+ }
118226
+ };
118227
+ })();
118228
+
118229
+
118230
+ /**
118231
+ * Parses transform at the given glTF node.
118232
+ *
118233
+ * @param node the glTF node
118234
+ * @param matrix Transfor matrix from parent nodes
118235
+ * @returns {*} Transform matrix for the node
118236
+ */
118237
+ function parseNodeMatrix(node, matrix) {
117973
118238
  let localMatrix;
117974
118239
  if (node.matrix) {
117975
118240
  localMatrix = node.matrix;
@@ -118003,171 +118268,92 @@ function loadNode(ctx, node, depth, matrix) {
118003
118268
  matrix = localMatrix;
118004
118269
  }
118005
118270
  }
118271
+ return matrix;
118272
+ }
118006
118273
 
118007
- const sceneModel = ctx.sceneModel;
118008
- if (node.mesh) {
118009
- const mesh = node.mesh;
118010
- if (ctx.handlenode) {
118011
- const actions = {};
118012
- if (!ctx.handlenode(ctx.sceneModel.id, node, actions)) {
118013
- return;
118014
- }
118015
- if (actions.createEntity) ;
118016
- }
118017
- const worldMatrix = matrix ? matrix.slice() : math.identityMat4();
118018
- const numPrimitives = mesh.primitives.length;
118019
-
118020
- if (numPrimitives > 0) {
118021
-
118022
- for (let i = 0; i < numPrimitives; i++) {
118023
-
118024
- const primitive = mesh.primitives[i];
118025
- if (primitive.mode < 4) {
118026
- continue;
118027
- }
118028
-
118029
- const meshCfg = {
118030
- id: sceneModel.id + "." + ctx.numObjects++
118031
- };
118032
-
118033
- const material = primitive.material;
118034
- if (material) {
118035
- meshCfg.textureSetId = material._textureSetId;
118036
- meshCfg.color = material._attributes.color;
118037
- meshCfg.opacity = material._attributes.opacity;
118038
- meshCfg.metallic = material._attributes.metallic;
118039
- meshCfg.roughness = material._attributes.roughness;
118040
- } else {
118041
- meshCfg.color = new Float32Array([1.0, 1.0, 1.0]);
118042
- meshCfg.opacity = 1.0;
118043
- }
118044
-
118045
- const backfaces = ((ctx.backfaces !== false) || (material && material.doubleSided !== false));
118046
-
118047
- switch (primitive.mode) {
118048
- case 0: // POINTS
118049
- meshCfg.primitive = "points";
118050
- break;
118051
- case 1: // LINES
118052
- meshCfg.primitive = "lines";
118053
- break;
118054
- case 2: // LINE_LOOP
118055
- meshCfg.primitive = "lines";
118056
- break;
118057
- case 3: // LINE_STRIP
118058
- meshCfg.primitive = "lines";
118059
- break;
118060
- case 4: // TRIANGLES
118061
- meshCfg.primitive = backfaces ? "triangles" : "solid";
118062
- break;
118063
- case 5: // TRIANGLE_STRIP
118064
- meshCfg.primitive = backfaces ? "triangles" : "solid";
118065
- break;
118066
- case 6: // TRIANGLE_FAN
118067
- meshCfg.primitive = backfaces ? "triangles" : "solid";
118068
- break;
118069
- default:
118070
- meshCfg.primitive = backfaces ? "triangles" : "solid";
118071
- }
118072
-
118073
- const POSITION = primitive.attributes.POSITION;
118074
- if (!POSITION) {
118075
- continue;
118076
- }
118077
- meshCfg.localPositions = POSITION.value;
118078
- meshCfg.positions = new Float64Array(meshCfg.localPositions.length);
118079
-
118080
- if (primitive.attributes.NORMAL) {
118081
- meshCfg.normals = primitive.attributes.NORMAL.value;
118082
- }
118083
-
118084
- if (primitive.attributes.TEXCOORD_0) {
118085
- meshCfg.uv = primitive.attributes.TEXCOORD_0.value;
118086
- }
118087
-
118088
- if (primitive.indices) {
118089
- meshCfg.indices = primitive.indices.value;
118090
- }
118091
-
118092
- math.transformPositions3(worldMatrix, meshCfg.localPositions, meshCfg.positions);
118093
- const origin = math.vec3();
118094
- const rtcNeeded = worldToRTCPositions(meshCfg.positions, meshCfg.positions, origin); // Small cellsize guarantees better accuracy
118095
- if (rtcNeeded) {
118096
- meshCfg.origin = origin;
118097
- }
118098
-
118099
- sceneModel.createMesh(meshCfg);
118100
- deferredMeshIds.push(meshCfg.id);
118101
- }
118102
- }
118103
- }
118104
-
118105
- if (node.children) {
118106
- const children = node.children;
118107
- for (let i = 0, len = children.length; i < len; i++) {
118108
- const childNode = children[i];
118109
- loadNode(ctx, childNode, depth + 1, matrix);
118110
- }
118274
+ /**
118275
+ * Parses primitives referenced by the mesh belonging to the given node, creating XKTMeshes in the XKTModel.
118276
+ *
118277
+ * @param node glTF node
118278
+ * @param ctx Parsing context
118279
+ * @param matrix Matrix for the XKTMeshes
118280
+ * @param meshIds returns IDs of the new XKTMeshes
118281
+ */
118282
+ function parseNodeMesh(node, ctx, matrix, meshIds) {
118283
+ const mesh = node.mesh;
118284
+ if (!mesh) {
118285
+ return;
118111
118286
  }
118112
-
118113
- // Post-order visit scene node
118114
-
118115
- if (ctx.entityId) {
118116
- if (depth ===0) {
118117
- sceneModel.createEntity({
118118
- id: ctx.entityId,
118119
- meshIds: deferredMeshIds,
118120
- isObject: true
118121
- });
118122
- deferredMeshIds.length = 0;
118123
- }
118124
- } else {
118125
- const nodeName = node.name;
118126
- if (((nodeName !== undefined && nodeName !== null) || depth === 0) && deferredMeshIds.length > 0) {
118127
- if (nodeName === undefined || nodeName === null) {
118128
- ctx.log(`Warning: 'name' properties not found on glTF scene nodes - will randomly-generate object IDs in XKT`);
118287
+ const numPrimitives = mesh.primitives.length;
118288
+ if (numPrimitives > 0) {
118289
+ for (let i = 0; i < numPrimitives; i++) {
118290
+ const primitive = mesh.primitives[i];
118291
+ if (primitive.mode < 4) {
118292
+ continue;
118129
118293
  }
118130
- let entityId = nodeName; // Fall back on generated ID when `name` not found on glTF scene node(s)
118131
- // if (!!entityId && sceneModel.entities[entityId]) {
118132
- // ctx.log(`Warning: Two or more glTF nodes found with same 'name' attribute: '${nodeName} - will randomly-generating an object ID in XKT`);
118133
- // }
118134
- // while (!entityId || sceneModel.entities[entityId]) {
118135
- // entityId = "entity-" + ctx.nextId++;
118136
- // }
118137
- if (ctx.metaModelCorrections) {
118138
- // Merging meshes into XKTObjects that map to metaobjects
118139
- const rootMetaObject = ctx.metaModelCorrections.eachChildRoot[entityId];
118140
- if (rootMetaObject) {
118141
- const rootMetaObjectStats = ctx.metaModelCorrections.eachRootStats[rootMetaObject.id];
118142
- rootMetaObjectStats.countChildren++;
118143
- if (rootMetaObjectStats.countChildren >= rootMetaObjectStats.numChildren) {
118144
- sceneModel.createEntity({
118145
- id: rootMetaObject.id,
118146
- meshIds: deferredMeshIds,
118147
- isObject: true
118148
- });
118149
- deferredMeshIds.length = 0;
118150
- }
118151
- } else {
118152
- const metaObject = ctx.metaModelCorrections.metaObjectsMap[entityId];
118153
- if (metaObject) {
118154
- sceneModel.createEntity({
118155
- id: entityId,
118156
- meshIds: deferredMeshIds,
118157
- isObject: true
118158
- });
118159
- deferredMeshIds.length = 0;
118160
- }
118161
- }
118294
+ const meshCfg = {
118295
+ id: ctx.sceneModel.id + "." + ctx.numObjects++
118296
+ };
118297
+ const material = primitive.material;
118298
+ if (material) {
118299
+ meshCfg.textureSetId = material._textureSetId;
118300
+ meshCfg.color = material._attributes.color;
118301
+ meshCfg.opacity = material._attributes.opacity;
118302
+ meshCfg.metallic = material._attributes.metallic;
118303
+ meshCfg.roughness = material._attributes.roughness;
118162
118304
  } else {
118163
- // Create an XKTObject from the meshes at each named glTF node, don't care about metaobjects
118164
- sceneModel.createEntity({
118165
- id: entityId,
118166
- meshIds: deferredMeshIds,
118167
- isObject: true
118168
- });
118169
- deferredMeshIds.length = 0;
118305
+ meshCfg.color = new Float32Array([1.0, 1.0, 1.0]);
118306
+ meshCfg.opacity = 1.0;
118307
+ }
118308
+ const backfaces = ((ctx.backfaces !== false) || (material && material.doubleSided !== false));
118309
+ switch (primitive.mode) {
118310
+ case 0: // POINTS
118311
+ meshCfg.primitive = "points";
118312
+ break;
118313
+ case 1: // LINES
118314
+ meshCfg.primitive = "lines";
118315
+ break;
118316
+ case 2: // LINE_LOOP
118317
+ meshCfg.primitive = "lines";
118318
+ break;
118319
+ case 3: // LINE_STRIP
118320
+ meshCfg.primitive = "lines";
118321
+ break;
118322
+ case 4: // TRIANGLES
118323
+ meshCfg.primitive = backfaces ? "triangles" : "solid";
118324
+ break;
118325
+ case 5: // TRIANGLE_STRIP
118326
+ meshCfg.primitive = backfaces ? "triangles" : "solid";
118327
+ break;
118328
+ case 6: // TRIANGLE_FAN
118329
+ meshCfg.primitive = backfaces ? "triangles" : "solid";
118330
+ break;
118331
+ default:
118332
+ meshCfg.primitive = backfaces ? "triangles" : "solid";
118333
+ }
118334
+ const POSITION = primitive.attributes.POSITION;
118335
+ if (!POSITION) {
118336
+ continue;
118337
+ }
118338
+ meshCfg.localPositions = POSITION.value;
118339
+ meshCfg.positions = new Float64Array(meshCfg.localPositions.length);
118340
+ if (primitive.attributes.NORMAL) {
118341
+ meshCfg.normals = primitive.attributes.NORMAL.value;
118342
+ }
118343
+ if (primitive.attributes.TEXCOORD_0) {
118344
+ meshCfg.uv = primitive.attributes.TEXCOORD_0.value;
118345
+ }
118346
+ if (primitive.indices) {
118347
+ meshCfg.indices = primitive.indices.value;
118348
+ }
118349
+ math.transformPositions3(matrix, meshCfg.localPositions, meshCfg.positions);
118350
+ const origin = math.vec3();
118351
+ const rtcNeeded = worldToRTCPositions(meshCfg.positions, meshCfg.positions, origin); // Small cellsize guarantees better accuracy
118352
+ if (rtcNeeded) {
118353
+ meshCfg.origin = origin;
118170
118354
  }
118355
+ ctx.sceneModel.createMesh(meshCfg);
118356
+ meshIds.push(meshCfg.id);
118171
118357
  }
118172
118358
  }
118173
118359
  }
@@ -118494,8 +118680,6 @@ class GLTFLoaderPlugin extends Plugin {
118494
118680
  * @param {String} [params.metaModelSrc] Path to an optional metadata file, as an alternative to the ````metaModelJSON```` parameter.
118495
118681
  * @param {*} [params.metaModelJSON] JSON model metadata, as an alternative to the ````metaModelSrc```` parameter.
118496
118682
  * @param {{String:Object}} [params.objectDefaults] Map of initial default states for each loaded {@link Entity} that represents an object. Default value is {@link IFCObjectDefaults}.
118497
- * @param {String[]} [params.includeTypes] When loading metadata, only loads objects that have {@link MetaObject}s with {@link MetaObject#type} values in this list.
118498
- * @param {String[]} [params.excludeTypes] When loading metadata, never loads objects that have {@link MetaObject}s with {@link MetaObject#type} values in this list.
118499
118683
  * @param {Boolean} [params.edges=false] Whether or not xeokit renders the model with edges emphasized.
118500
118684
  * @param {Number[]} [params.origin=[0,0,0]] The double-precision World-space origin of the model's coordinates.
118501
118685
  * @param {Number[]} [params.position=[0,0,0]] The single-precision position, relative to ````origin````.
@@ -118511,150 +118695,47 @@ class GLTFLoaderPlugin extends Plugin {
118511
118695
  * represent the returned model. Set false to always use vertex buffer objects (VBOs). Note that DTX is only applicable
118512
118696
  * to non-textured triangle meshes, and that VBOs are always used for meshes that have textures, line segments, or point
118513
118697
  * primitives. Only works while {@link DTX#enabled} is also ````true````.
118514
- * @param {String} [params.entityId] When supplied, causes the entire model to be loaded into a single {@link Entity} that gets this ID.
118698
+ * @param {Boolean} [params.autoMetaModel] When supplied, creates a default MetaModel with a single MetaObject.
118515
118699
  * @returns {Entity} Entity representing the model, which will have {@link Entity#isModel} set ````true```` and will be registered by {@link Entity#id} in {@link Scene#models}
118516
118700
  */
118517
118701
  load(params = {}) {
118518
-
118519
118702
  if (params.id && this.viewer.scene.components[params.id]) {
118520
118703
  this.error("Component with this ID already exists in viewer: " + params.id + " - will autogenerate this ID");
118521
118704
  delete params.id;
118522
118705
  }
118523
-
118524
118706
  const sceneModel = new SceneModel(this.viewer.scene, utils.apply(params, {
118525
118707
  isModel: true,
118526
118708
  dtxEnabled: params.dtxEnabled
118527
118709
  }));
118528
-
118529
118710
  const modelId = sceneModel.id; // In case ID was auto-generated
118530
-
118531
118711
  if (!params.src && !params.gltf) {
118532
118712
  this.error("load() param expected: src or gltf");
118533
118713
  return sceneModel; // Return new empty model
118534
118714
  }
118535
-
118536
118715
  if (params.metaModelSrc || params.metaModelJSON) {
118537
-
118538
- const objectDefaults = params.objectDefaults || this._objectDefaults || IFCObjectDefaults;
118539
-
118540
118716
  const processMetaModelJSON = (metaModelJSON) => {
118541
-
118542
- this.viewer.metaScene.createMetaModel(modelId, metaModelJSON, {
118543
- includeTypes: params.includeTypes,
118544
- excludeTypes: params.excludeTypes
118545
- });
118546
-
118717
+ this.viewer.metaScene.createMetaModel(modelId, metaModelJSON, {});
118547
118718
  this.viewer.scene.canvas.spinner.processes--;
118548
-
118549
- let includeTypes;
118550
- if (params.includeTypes) {
118551
- includeTypes = {};
118552
- for (let i = 0, len = params.includeTypes.length; i < len; i++) {
118553
- includeTypes[params.includeTypes[i]] = true;
118554
- }
118555
- }
118556
- if (params.excludeTypes) {
118557
- if (!includeTypes) {
118558
- includeTypes = {};
118559
- }
118560
- for (let i = 0, len = params.excludeTypes.length; i < len; i++) {
118561
- includeTypes[params.excludeTypes[i]] = true;
118562
- }
118563
- }
118564
-
118565
- params.readableGeometry = false;
118566
-
118567
- params.handleGLTFNode = (modelId, glTFNode, actions) => {
118568
-
118569
- const name = glTFNode.name;
118570
-
118571
- if (!name) {
118572
- return true; // Continue descending this node subtree
118573
- }
118574
-
118575
- const nodeId = name;
118576
- const metaObject = this.viewer.metaScene.metaObjects[nodeId];
118577
- const type = (metaObject ? metaObject.type : "DEFAULT") || "DEFAULT";
118578
-
118579
- actions.createEntity = {
118580
- id: nodeId,
118581
- isObject: true // Registers the Entity in Scene#objects
118582
- };
118583
-
118584
- const props = objectDefaults[type];
118585
-
118586
- if (props) { // Set Entity's initial rendering state for recognized type
118587
-
118588
- if (props.visible === false) {
118589
- actions.createEntity.visible = false;
118590
- }
118591
-
118592
- if (props.colorize) {
118593
- actions.createEntity.colorize = props.colorize;
118594
- }
118595
-
118596
- if (props.pickable === false) {
118597
- actions.createEntity.pickable = false;
118598
- }
118599
-
118600
- if (props.opacity !== undefined && props.opacity !== null) {
118601
- actions.createEntity.opacity = props.opacity;
118602
- }
118603
- }
118604
-
118605
- return true; // Continue descending this glTF node subtree
118606
- };
118607
-
118608
118719
  if (params.src) {
118609
118720
  this._sceneModelLoader.load(this, params.src, metaModelJSON, params, sceneModel);
118610
118721
  } else {
118611
118722
  this._sceneModelLoader.parse(this, params.gltf, metaModelJSON, params, sceneModel);
118612
118723
  }
118613
118724
  };
118614
-
118615
118725
  if (params.metaModelSrc) {
118616
-
118617
118726
  const metaModelSrc = params.metaModelSrc;
118618
-
118619
118727
  this.viewer.scene.canvas.spinner.processes++;
118620
-
118621
118728
  this._dataSource.getMetaModel(metaModelSrc, (metaModelJSON) => {
118622
-
118623
118729
  this.viewer.scene.canvas.spinner.processes--;
118624
-
118625
118730
  processMetaModelJSON(metaModelJSON);
118626
-
118627
118731
  }, (errMsg) => {
118628
118732
  this.error(`load(): Failed to load model metadata for model '${modelId} from '${metaModelSrc}' - ${errMsg}`);
118629
118733
  this.viewer.scene.canvas.spinner.processes--;
118630
118734
  });
118631
-
118632
118735
  } else if (params.metaModelJSON) {
118633
-
118634
118736
  processMetaModelJSON(params.metaModelJSON);
118635
118737
  }
118636
-
118637
118738
  } else {
118638
-
118639
- params.handleGLTFNode = (modelId, glTFNode, actions) => {
118640
-
118641
- const name = glTFNode.name;
118642
-
118643
- if (!name) {
118644
- return true; // Continue descending this node subtree
118645
- }
118646
-
118647
- const id = name;
118648
-
118649
- actions.createEntity = { // Create an Entity for this glTF scene node
118650
- id: id,
118651
- isObject: true // Registers the Entity in Scene#objects
118652
- };
118653
-
118654
- return true; // Continue descending this glTF node subtree
118655
- };
118656
-
118657
-
118658
118739
  if (params.src) {
118659
118740
  this._sceneModelLoader.load(this, params.src, null, params, sceneModel);
118660
118741
  } else {