@xeokit/xeokit-sdk 2.6.31 → 2.6.32

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.
@@ -32,6 +32,9 @@ const Renderer = function (scene, options) {
32
32
  let drawableTypeInfo = {};
33
33
  let drawables = {};
34
34
 
35
+ let postSortDrawableList = [];
36
+ let postCullDrawableList = [];
37
+
35
38
  let drawableListDirty = true;
36
39
  let stateSortDirty = true;
37
40
  let imageDirty = true;
@@ -264,33 +267,33 @@ const Renderer = function (scene, options) {
264
267
  }
265
268
 
266
269
  function sortDrawableList() {
270
+ let lenDrawableList = 0;
267
271
  for (let type in drawableTypeInfo) {
268
272
  if (drawableTypeInfo.hasOwnProperty(type)) {
269
273
  const drawableInfo = drawableTypeInfo[type];
270
- if (drawableInfo.isStateSortable) {
271
- drawableInfo.drawableListPreCull.sort(drawableInfo.stateSortCompare);
274
+ const drawableListPreCull = drawableInfo.drawableListPreCull;
275
+ for (let i = 0, len = drawableListPreCull.length; i < len; i++) {
276
+ const drawable = drawableListPreCull[i];
277
+ postSortDrawableList[lenDrawableList++] = drawable;
272
278
  }
273
279
  }
274
280
  }
281
+ postSortDrawableList.length = lenDrawableList;
282
+ postSortDrawableList.sort((a, b) => {
283
+ return a.renderOrder - b.renderOrder;
284
+ });
275
285
  }
276
286
 
277
287
  function cullDrawableList() {
278
- for (let type in drawableTypeInfo) {
279
- if (drawableTypeInfo.hasOwnProperty(type)) {
280
- const drawableInfo = drawableTypeInfo[type];
281
- const drawableListPreCull = drawableInfo.drawableListPreCull;
282
- const drawableList = drawableInfo.drawableList;
283
- let lenDrawableList = 0;
284
- for (let i = 0, len = drawableListPreCull.length; i < len; i++) {
285
- const drawable = drawableListPreCull[i];
286
- drawable.rebuildRenderFlags();
287
- if (!drawable.renderFlags.culled) {
288
- drawableList[lenDrawableList++] = drawable;
289
- }
290
- }
291
- drawableList.length = lenDrawableList;
288
+ let lenDrawableList = 0;
289
+ for (let i = 0, len = postSortDrawableList.length; i < len; i++) {
290
+ const drawable = postSortDrawableList[i];
291
+ drawable.rebuildRenderFlags();
292
+ if (!drawable.renderFlags.culled) {
293
+ postCullDrawableList[lenDrawableList++] = drawable;
292
294
  }
293
295
  }
296
+ postCullDrawableList.length = lenDrawableList;
294
297
  }
295
298
 
296
299
  function draw(params) {
@@ -366,25 +369,16 @@ const Renderer = function (scene, options) {
366
369
  if (params.clear !== false) {
367
370
  gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
368
371
  }
372
+ for (let i = 0, len = postCullDrawableList.length; i < len; i++) {
369
373
 
370
- for (let type in drawableTypeInfo) {
371
- if (drawableTypeInfo.hasOwnProperty(type)) {
372
-
373
- const drawableInfo = drawableTypeInfo[type];
374
- const drawableList = drawableInfo.drawableList;
375
-
376
- for (let i = 0, len = drawableList.length; i < len; i++) {
377
-
378
- const drawable = drawableList[i];
374
+ const drawable = postCullDrawableList[i];
379
375
 
380
- if (drawable.culled === true || drawable.visible === false || !drawable.drawDepth || !drawable.saoEnabled) {
381
- continue;
382
- }
376
+ if (drawable.culled === true || drawable.visible === false || !drawable.drawDepth || !drawable.saoEnabled) {
377
+ continue;
378
+ }
383
379
 
384
- if (drawable.renderFlags.colorOpaque) {
385
- drawable.drawDepth(frameCtx);
386
- }
387
- }
380
+ if (drawable.renderFlags.colorOpaque) {
381
+ drawable.drawDepth(frameCtx);
388
382
  }
389
383
  }
390
384
 
@@ -567,93 +561,85 @@ const Renderer = function (scene, options) {
567
561
  // Render normal opaque solids, defer others to bins to render after
568
562
  //------------------------------------------------------------------------------------------------------
569
563
 
570
- for (let type in drawableTypeInfo) {
571
- if (drawableTypeInfo.hasOwnProperty(type)) {
572
-
573
- const drawableInfo = drawableTypeInfo[type];
574
- const drawableList = drawableInfo.drawableList;
575
-
576
- for (i = 0, len = drawableList.length; i < len; i++) {
564
+ for (let i = 0, len = postCullDrawableList.length; i < len; i++) {
577
565
 
578
- drawable = drawableList[i];
566
+ drawable = postCullDrawableList[i];
579
567
 
580
- if (drawable.culled === true || drawable.visible === false) {
581
- continue;
582
- }
568
+ if (drawable.culled === true || drawable.visible === false) {
569
+ continue;
570
+ }
583
571
 
584
- const renderFlags = drawable.renderFlags;
572
+ const renderFlags = drawable.renderFlags;
585
573
 
586
- if (renderFlags.colorOpaque) {
587
- if (saoEnabled && saoPossible && drawable.saoEnabled) {
588
- normalDrawSAOBin[normalDrawSAOBinLen++] = drawable;
589
- } else {
590
- drawable.drawColorOpaque(frameCtx);
591
- }
592
- }
574
+ if (renderFlags.colorOpaque) {
575
+ if (saoEnabled && saoPossible && drawable.saoEnabled) {
576
+ normalDrawSAOBin[normalDrawSAOBinLen++] = drawable;
577
+ } else {
578
+ drawable.drawColorOpaque(frameCtx);
579
+ }
580
+ }
593
581
 
594
- if (transparentEnabled) {
595
- if (renderFlags.colorTransparent) {
596
- normalFillTransparentBin[normalFillTransparentBinLen++] = drawable;
597
- }
598
- }
582
+ if (transparentEnabled) {
583
+ if (renderFlags.colorTransparent) {
584
+ normalFillTransparentBin[normalFillTransparentBinLen++] = drawable;
585
+ }
586
+ }
599
587
 
600
- if (renderFlags.xrayedSilhouetteTransparent) {
601
- xrayedFillTransparentBin[xrayedFillTransparentBinLen++] = drawable;
602
- }
588
+ if (renderFlags.xrayedSilhouetteTransparent) {
589
+ xrayedFillTransparentBin[xrayedFillTransparentBinLen++] = drawable;
590
+ }
603
591
 
604
- if (renderFlags.xrayedSilhouetteOpaque) {
605
- xrayedFillOpaqueBin[xrayedFillOpaqueBinLen++] = drawable;
606
- }
592
+ if (renderFlags.xrayedSilhouetteOpaque) {
593
+ xrayedFillOpaqueBin[xrayedFillOpaqueBinLen++] = drawable;
594
+ }
607
595
 
608
- if (renderFlags.highlightedSilhouetteTransparent) {
609
- highlightedFillTransparentBin[highlightedFillTransparentBinLen++] = drawable;
610
- }
596
+ if (renderFlags.highlightedSilhouetteTransparent) {
597
+ highlightedFillTransparentBin[highlightedFillTransparentBinLen++] = drawable;
598
+ }
611
599
 
612
- if (renderFlags.highlightedSilhouetteOpaque) {
613
- highlightedFillOpaqueBin[highlightedFillOpaqueBinLen++] = drawable;
614
- }
600
+ if (renderFlags.highlightedSilhouetteOpaque) {
601
+ highlightedFillOpaqueBin[highlightedFillOpaqueBinLen++] = drawable;
602
+ }
615
603
 
616
- if (renderFlags.selectedSilhouetteTransparent) {
617
- selectedFillTransparentBin[selectedFillTransparentBinLen++] = drawable;
618
- }
604
+ if (renderFlags.selectedSilhouetteTransparent) {
605
+ selectedFillTransparentBin[selectedFillTransparentBinLen++] = drawable;
606
+ }
619
607
 
620
- if (renderFlags.selectedSilhouetteOpaque) {
621
- selectedFillOpaqueBin[selectedFillOpaqueBinLen++] = drawable;
622
- }
608
+ if (renderFlags.selectedSilhouetteOpaque) {
609
+ selectedFillOpaqueBin[selectedFillOpaqueBinLen++] = drawable;
610
+ }
623
611
 
624
- if (drawable.edges && edgesEnabled) {
625
- if (renderFlags.edgesOpaque) {
626
- normalEdgesOpaqueBin[normalEdgesOpaqueBinLen++] = drawable;
627
- }
612
+ if (drawable.edges && edgesEnabled) {
613
+ if (renderFlags.edgesOpaque) {
614
+ normalEdgesOpaqueBin[normalEdgesOpaqueBinLen++] = drawable;
615
+ }
628
616
 
629
- if (renderFlags.edgesTransparent) {
630
- normalEdgesTransparentBin[normalEdgesTransparentBinLen++] = drawable;
631
- }
617
+ if (renderFlags.edgesTransparent) {
618
+ normalEdgesTransparentBin[normalEdgesTransparentBinLen++] = drawable;
619
+ }
632
620
 
633
- if (renderFlags.selectedEdgesTransparent) {
634
- selectedEdgesTransparentBin[selectedEdgesTransparentBinLen++] = drawable;
635
- }
621
+ if (renderFlags.selectedEdgesTransparent) {
622
+ selectedEdgesTransparentBin[selectedEdgesTransparentBinLen++] = drawable;
623
+ }
636
624
 
637
- if (renderFlags.selectedEdgesOpaque) {
638
- selectedEdgesOpaqueBin[selectedEdgesOpaqueBinLen++] = drawable;
639
- }
625
+ if (renderFlags.selectedEdgesOpaque) {
626
+ selectedEdgesOpaqueBin[selectedEdgesOpaqueBinLen++] = drawable;
627
+ }
640
628
 
641
- if (renderFlags.xrayedEdgesTransparent) {
642
- xrayEdgesTransparentBin[xrayEdgesTransparentBinLen++] = drawable;
643
- }
629
+ if (renderFlags.xrayedEdgesTransparent) {
630
+ xrayEdgesTransparentBin[xrayEdgesTransparentBinLen++] = drawable;
631
+ }
644
632
 
645
- if (renderFlags.xrayedEdgesOpaque) {
646
- xrayEdgesOpaqueBin[xrayEdgesOpaqueBinLen++] = drawable;
647
- }
633
+ if (renderFlags.xrayedEdgesOpaque) {
634
+ xrayEdgesOpaqueBin[xrayEdgesOpaqueBinLen++] = drawable;
635
+ }
648
636
 
649
- if (renderFlags.highlightedEdgesTransparent) {
650
- highlightedEdgesTransparentBin[highlightedEdgesTransparentBinLen++] = drawable;
651
- }
637
+ if (renderFlags.highlightedEdgesTransparent) {
638
+ highlightedEdgesTransparentBin[highlightedEdgesTransparentBinLen++] = drawable;
639
+ }
652
640
 
653
- if (renderFlags.highlightedEdgesOpaque) {
654
- highlightedEdgesOpaqueBin[highlightedEdgesOpaqueBinLen++] = drawable;
655
- }
656
- }
641
+ if (renderFlags.highlightedEdgesOpaque) {
642
+ highlightedEdgesOpaqueBin[highlightedEdgesOpaqueBinLen++] = drawable;
657
643
  }
658
644
  }
659
645
  }
@@ -1063,7 +1049,7 @@ const Renderer = function (scene, options) {
1063
1049
  frameCtx.pickInvisible = !!params.pickInvisible;
1064
1050
  frameCtx.pickClipPos = [
1065
1051
  getClipPosX(canvasPos[0] * resolutionScale, gl.drawingBufferWidth),
1066
- getClipPosY(canvasPos[1] * resolutionScale, gl.drawingBufferHeight),
1052
+ getClipPosY(canvasPos[1] * resolutionScale, gl.drawingBufferHeight)
1067
1053
  ];
1068
1054
 
1069
1055
  gl.viewport(0, 0, 1, 1);
@@ -1076,30 +1062,23 @@ const Renderer = function (scene, options) {
1076
1062
  const includeEntityIds = params.includeEntityIds;
1077
1063
  const excludeEntityIds = params.excludeEntityIds;
1078
1064
 
1079
- for (let type in drawableTypeInfo) {
1080
- if (drawableTypeInfo.hasOwnProperty(type)) {
1081
-
1082
- const drawableInfo = drawableTypeInfo[type];
1083
- const drawableList = drawableInfo.drawableList;
1084
-
1085
- for (let i = 0, len = drawableList.length; i < len; i++) {
1086
-
1087
- const drawable = drawableList[i];
1088
-
1089
- if (!drawable.drawPickMesh || (params.pickInvisible !== true && drawable.visible === false) || drawable.pickable === false) {
1090
- continue;
1091
- }
1092
- if (includeEntityIds && !includeEntityIds[drawable.id]) { // TODO: push this logic into drawable
1093
- continue;
1094
- }
1095
- if (excludeEntityIds && excludeEntityIds[drawable.id]) {
1096
- continue;
1097
- }
1098
-
1099
- drawable.drawPickMesh(frameCtx);
1100
- }
1065
+ for (let i = 0, len = postCullDrawableList.length; i < len; i++) {
1066
+ const drawable = postCullDrawableList[i];
1067
+ if (drawable.culled === true || drawable.visible === false) {
1068
+ continue;
1069
+ }
1070
+ if (!drawable.drawPickMesh || (params.pickInvisible !== true && drawable.visible === false) || drawable.pickable === false) {
1071
+ continue;
1072
+ }
1073
+ if (includeEntityIds && !includeEntityIds[drawable.id]) { // TODO: push this logic into drawable
1074
+ continue;
1101
1075
  }
1076
+ if (excludeEntityIds && excludeEntityIds[drawable.id]) {
1077
+ continue;
1078
+ }
1079
+ drawable.drawPickMesh(frameCtx);
1102
1080
  }
1081
+
1103
1082
  const pix = pickBuffer.read(0, 0);
1104
1083
  const pickID = pix[0] + (pix[1] << 8) + (pix[2] << 16) + (pix[3] << 24);
1105
1084
 
@@ -1129,7 +1108,7 @@ const Renderer = function (scene, options) {
1129
1108
  // frameCtx.pickInvisible = !!params.pickInvisible;
1130
1109
  frameCtx.pickClipPos = [
1131
1110
  getClipPosX(canvasPos[0] * resolutionScale, gl.drawingBufferWidth),
1132
- getClipPosY(canvasPos[1] * resolutionScale, gl.drawingBufferHeight),
1111
+ getClipPosY(canvasPos[1] * resolutionScale, gl.drawingBufferHeight)
1133
1112
  ];
1134
1113
 
1135
1114
  gl.viewport(0, 0, 1, 1);
@@ -1178,7 +1157,7 @@ const Renderer = function (scene, options) {
1178
1157
  frameCtx.pickElementsOffset = pickable.pickElementsOffset;
1179
1158
  frameCtx.pickClipPos = [
1180
1159
  getClipPosX(canvasPos[0] * resolutionScale, gl.drawingBufferWidth),
1181
- getClipPosY(canvasPos[1] * resolutionScale, gl.drawingBufferHeight),
1160
+ getClipPosY(canvasPos[1] * resolutionScale, gl.drawingBufferHeight)
1182
1161
  ];
1183
1162
 
1184
1163
  gl.viewport(0, 0, 1, 1);
@@ -1243,15 +1222,14 @@ const Renderer = function (scene, options) {
1243
1222
  function drawSnapInit(frameCtx) {
1244
1223
  frameCtx.snapPickLayerParams = [];
1245
1224
  frameCtx.snapPickLayerNumber = 0;
1246
- for (let type in drawableTypeInfo) {
1247
- const drawableInfo = drawableTypeInfo[type];
1248
- const drawableList = drawableInfo.drawableList;
1249
- for (let i = 0, len = drawableList.length; i < len; i++) {
1250
- const drawable = drawableList[i];
1251
- if (drawable.drawSnapInit) {
1252
- if (!drawable.culled && drawable.visible && drawable.pickable) {
1253
- drawable.drawSnapInit(frameCtx);
1254
- }
1225
+
1226
+ for (let i = 0, len = postCullDrawableList.length; i < len; i++) {
1227
+
1228
+ const drawable = postCullDrawableList[i];
1229
+
1230
+ if (drawable.drawSnapInit) {
1231
+ if (!drawable.culled && drawable.visible && drawable.pickable) {
1232
+ drawable.drawSnapInit(frameCtx);
1255
1233
  }
1256
1234
  }
1257
1235
  }
@@ -1261,11 +1239,11 @@ const Renderer = function (scene, options) {
1261
1239
  function drawSnap(frameCtx) {
1262
1240
  frameCtx.snapPickLayerParams = frameCtx.snapPickLayerParams || [];
1263
1241
  frameCtx.snapPickLayerNumber = frameCtx.snapPickLayerParams.length;
1264
- for (let type in drawableTypeInfo) {
1265
- const drawableInfo = drawableTypeInfo[type];
1266
- const drawableList = drawableInfo.drawableList;
1267
- for (let i = 0, len = drawableList.length; i < len; i++) {
1268
- const drawable = drawableList[i];
1242
+ for (let i = 0, len = postCullDrawableList.length; i < len; i++) {
1243
+
1244
+ const drawable = postCullDrawableList[i];
1245
+
1246
+ if (drawable.drawSnapInit) {
1269
1247
  if (drawable.drawSnap) {
1270
1248
  if (!drawable.culled && drawable.visible && drawable.pickable) {
1271
1249
  drawable.drawSnap(frameCtx);
@@ -1655,19 +1633,16 @@ const Renderer = function (scene, options) {
1655
1633
  gl.disable(gl.BLEND);
1656
1634
  gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
1657
1635
 
1658
- for (let type in drawableTypeInfo) {
1659
- if (drawableTypeInfo.hasOwnProperty(type)) {
1660
- const drawableInfo = drawableTypeInfo[type];
1661
- const drawableList = drawableInfo.drawableList;
1662
- for (let i = 0, len = drawableList.length; i < len; i++) {
1663
- const drawable = drawableList[i];
1664
- if (!drawable.drawOcclusion || drawable.culled === true || drawable.visible === false || drawable.pickable === false) { // TODO: Option to exclude transparent?
1665
- continue;
1666
- }
1667
1636
 
1668
- drawable.drawOcclusion(frameCtx);
1669
- }
1637
+ for (let i = 0, len = postCullDrawableList.length; i < len; i++) {
1638
+
1639
+ const drawable = postCullDrawableList[i];
1640
+
1641
+ if (!drawable.drawOcclusion || drawable.culled === true || drawable.visible === false || drawable.pickable === false) { // TODO: Option to exclude transparent?
1642
+ continue;
1670
1643
  }
1644
+
1645
+ drawable.drawOcclusion(frameCtx);
1671
1646
  }
1672
1647
 
1673
1648
  this._occlusionTester.drawMarkers(frameCtx);
@@ -1794,4 +1769,4 @@ const Renderer = function (scene, options) {
1794
1769
  };
1795
1770
  };
1796
1771
 
1797
- export {Renderer};
1772
+ export {Renderer};