@xeokit/xeokit-sdk 2.6.30 → 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);
@@ -1539,13 +1517,16 @@ const Renderer = function (scene, options) {
1539
1517
  }
1540
1518
 
1541
1519
  const snappedEntity = (snappedPickable && snappedPickable.delegatePickedEntity) ? snappedPickable.delegatePickedEntity() : snappedPickable;
1520
+ if (!snappedEntity && pickable) {
1521
+ pickable = pickable.delegatePickedEntity ? pickable.delegatePickedEntity() : pickable;
1522
+ }
1542
1523
 
1543
1524
  pickResult.reset();
1544
1525
  pickResult.snappedToEdge = (snapType === "edge");
1545
1526
  pickResult.snappedToVertex = (snapType === "vertex");
1546
- pickResult.worldPos = snappedWorldPos;
1547
- pickResult.worldNormal = snappedWorldNormal;
1548
- pickResult.entity = snappedEntity;
1527
+ pickResult.worldPos = snappedWorldPos || worldPos;
1528
+ pickResult.worldNormal = snappedWorldNormal || worldNormal;
1529
+ pickResult.entity = snappedEntity || pickable;
1549
1530
  pickResult.canvasPos = canvasPos || scene.camera.projectWorldPos(worldPos || snappedWorldPos);
1550
1531
  pickResult.snappedCanvasPos = snappedCanvasPos || canvasPos;
1551
1532
 
@@ -1652,19 +1633,16 @@ const Renderer = function (scene, options) {
1652
1633
  gl.disable(gl.BLEND);
1653
1634
  gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
1654
1635
 
1655
- for (let type in drawableTypeInfo) {
1656
- if (drawableTypeInfo.hasOwnProperty(type)) {
1657
- const drawableInfo = drawableTypeInfo[type];
1658
- const drawableList = drawableInfo.drawableList;
1659
- for (let i = 0, len = drawableList.length; i < len; i++) {
1660
- const drawable = drawableList[i];
1661
- if (!drawable.drawOcclusion || drawable.culled === true || drawable.visible === false || drawable.pickable === false) { // TODO: Option to exclude transparent?
1662
- continue;
1663
- }
1664
1636
 
1665
- drawable.drawOcclusion(frameCtx);
1666
- }
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;
1667
1643
  }
1644
+
1645
+ drawable.drawOcclusion(frameCtx);
1668
1646
  }
1669
1647
 
1670
1648
  this._occlusionTester.drawMarkers(frameCtx);
@@ -1791,4 +1769,4 @@ const Renderer = function (scene, options) {
1791
1769
  };
1792
1770
  };
1793
1771
 
1794
- export {Renderer};
1772
+ export {Renderer};
@@ -1,4 +1,4 @@
1
- import { Plugin, Viewer, Entity, IFCObjectDefaults } from "../../viewer";
1
+ import { Entity, IFCObjectDefaults, Plugin, SceneModel, Viewer } from "../../viewer";
2
2
 
3
3
  export declare interface IGLTFDefaultDataSource {
4
4
  /**
@@ -77,6 +77,8 @@ export declare type LoadGLTFModel = {
77
77
  edgeThreshold?: number[]
78
78
  /** Set ````false```` to load all the materials and textures provided by the glTF file, otherwise leave ````true```` to load the default high-performance representation optimized for low memory usage and efficient rendering. */
79
79
  performance?: boolean;
80
+ /** When true, generate a single MetaObject that represents the entire glTF model, and a MetaObject for each entity within it. */
81
+ autoMetaModel?: boolean;
80
82
  };
81
83
 
82
84
  /**
@@ -134,7 +136,7 @@ export declare class GLTFLoaderPlugin extends Plugin {
134
136
  * Loads a glTF model from a file into this GLTFLoaderPlugin's {@link Viewer}.
135
137
  *
136
138
  * @param {LoadGLTFModel} params Loading parameters.
137
- * @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}
139
+ * @returns {SceneModel} SceneModel representing the model, which will have {@link Entity.isModel} set ````true```` and will be registered by {@link Entity.id} in {@link Scene.models}.
138
140
  */
139
- load(params: LoadGLTFModel): Entity;
141
+ load(params: LoadGLTFModel): SceneModel;
140
142
  }
@@ -1,4 +1,4 @@
1
- import { Entity, Plugin, Viewer } from "../../viewer";
1
+ import { Entity, Plugin, SceneModel, Viewer } from "../../viewer";
2
2
  import { ModelStats } from "../index";
3
3
 
4
4
  export declare interface ILASDefaultDataSource {
@@ -142,5 +142,5 @@ export declare class LASLoaderPlugin extends Plugin {
142
142
  * @param {LoadLASModel} params Loading parameters.
143
143
  * @returns {SceneModel} SceneModel representing the model, which will have {@link Entity.isModel} set ````true```` and will be registered by {@link Entity.id} in {@link Scene.models}.
144
144
  */
145
- load(params?: LoadLASModel): Entity;
145
+ load(params?: LoadLASModel): SceneModel;
146
146
  }
@@ -1,4 +1,4 @@
1
- import { Plugin, Viewer, Entity } from "../../viewer";
1
+ import { Entity, Node, Plugin, Viewer } from "../../viewer";
2
2
 
3
3
  export declare type LoadOBJModel = {
4
4
  /** ID to assign to the model's root {@link Entity}, unique among all components in the Viewer's {@link Scene}. */
@@ -38,7 +38,7 @@ export declare class OBJLoaderPlugin extends Plugin {
38
38
  * Loads an OBJ model from a file into this OBJLoader's {@link Viewer}.
39
39
  *
40
40
  * @param {LoadOBJModel} params Loading parameters.
41
- * @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}
41
+ * @returns {Node} An {@link Entity} that is a scene graph node that can have child Nodes and {@link Mesh}es.
42
42
  */
43
- load(params: LoadOBJModel): Entity;
43
+ load(params: LoadOBJModel): Node;
44
44
  }