@xeokit/xeokit-sdk 2.6.91 → 2.6.93

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 (184) hide show
  1. package/dist/xeokit-sdk.cjs.js +13128 -44669
  2. package/dist/xeokit-sdk.es.js +13129 -44668
  3. package/dist/xeokit-sdk.es5.js +1414 -3498
  4. package/dist/xeokit-sdk.min.cjs.js +8 -8
  5. package/dist/xeokit-sdk.min.es.js +8 -8
  6. package/dist/xeokit-sdk.min.es5.js +7 -7
  7. package/package.json +1 -1
  8. package/src/plugins/AngleMeasurementsPlugin/AngleMeasurement.js +21 -1
  9. package/src/plugins/DistanceMeasurementsPlugin/DistanceMeasurement.js +32 -6
  10. package/src/viewer/Viewer.js +55 -103
  11. package/src/viewer/scene/canvas/Canvas.js +3 -43
  12. package/src/viewer/scene/geometry/ReadableGeometry.js +0 -25
  13. package/src/viewer/scene/lights/CubeTexture.js +0 -13
  14. package/src/viewer/scene/lights/DirLight.js +2 -1
  15. package/src/viewer/scene/lights/PointLight.js +2 -1
  16. package/src/viewer/scene/materials/Texture.js +0 -9
  17. package/src/viewer/scene/math/rtcCoords.js +1 -38
  18. package/src/viewer/scene/mesh/Mesh.js +454 -212
  19. package/src/viewer/scene/mesh/draw/DrawShaderSource.js +305 -1504
  20. package/src/viewer/scene/mesh/draw/LambertShaderSource.js +35 -0
  21. package/src/viewer/scene/mesh/emphasis/EmphasisShaderSource.js +34 -0
  22. package/src/viewer/scene/mesh/occlusion/OcclusionShaderSource.js +9 -158
  23. package/src/viewer/scene/mesh/pick/PickMeshShaderSource.js +21 -151
  24. package/src/viewer/scene/mesh/pick/PickTriangleShaderSource.js +12 -124
  25. package/src/viewer/scene/mesh/shadow/ShadowShaderSource.js +22 -97
  26. package/src/viewer/scene/model/SceneModel.js +248 -852
  27. package/src/viewer/scene/model/SceneModelEntity.js +4 -4
  28. package/src/viewer/scene/model/SceneModelMesh.js +3 -3
  29. package/src/viewer/scene/model/layer/DTXLayer.js +940 -0
  30. package/src/viewer/scene/model/layer/Layer.js +788 -0
  31. package/src/viewer/scene/model/layer/VBOLayer.js +1019 -0
  32. package/src/viewer/scene/model/layer/programs/ColorProgram.js +35 -0
  33. package/src/viewer/scene/model/layer/programs/ColorTextureProgram.js +46 -0
  34. package/src/viewer/scene/model/layer/programs/DepthProgram.js +11 -0
  35. package/src/viewer/scene/model/layer/programs/EdgesProgram.js +12 -0
  36. package/src/viewer/scene/model/layer/programs/FlatColorProgram.js +24 -0
  37. package/src/viewer/scene/model/layer/programs/OcclusionProgram.js +12 -0
  38. package/src/viewer/scene/model/layer/programs/PBRProgram.js +180 -0
  39. package/src/viewer/scene/model/layer/programs/PickDepthProgram.js +30 -0
  40. package/src/viewer/scene/model/layer/programs/PickMeshProgram.js +12 -0
  41. package/src/viewer/scene/model/layer/programs/PickNormalsProgram.js +18 -0
  42. package/src/viewer/scene/model/layer/programs/ShadowProgram.js +23 -0
  43. package/src/viewer/scene/model/layer/programs/SilhouetteProgram.js +15 -0
  44. package/src/viewer/scene/model/layer/programs/SnapProgram.js +29 -0
  45. package/src/viewer/scene/scene/Scene.js +21 -38
  46. package/src/viewer/scene/webgl/ArrayBuf.js +5 -20
  47. package/src/viewer/scene/webgl/FrameContext.js +14 -86
  48. package/src/viewer/scene/webgl/RenderBuffer.js +62 -262
  49. package/src/viewer/scene/webgl/Renderer.js +880 -843
  50. package/src/viewer/scene/webgl/WebGLRenderer.js +612 -0
  51. package/src/viewer/scene/webgl/occlusion/OcclusionLayer.js +60 -132
  52. package/src/viewer/scene/webgl/occlusion/OcclusionTester.js +167 -328
  53. package/src/viewer/scene/mesh/draw/DrawRenderer.js +0 -998
  54. package/src/viewer/scene/mesh/emphasis/EmphasisEdgesRenderer.js +0 -259
  55. package/src/viewer/scene/mesh/emphasis/EmphasisEdgesShaderSource.js +0 -160
  56. package/src/viewer/scene/mesh/emphasis/EmphasisFillRenderer.js +0 -286
  57. package/src/viewer/scene/mesh/emphasis/EmphasisFillShaderSource.js +0 -263
  58. package/src/viewer/scene/mesh/occlusion/OcclusionRenderer.js +0 -221
  59. package/src/viewer/scene/mesh/pick/PickMeshRenderer.js +0 -223
  60. package/src/viewer/scene/mesh/pick/PickTriangleRenderer.js +0 -200
  61. package/src/viewer/scene/mesh/shadow/ShadowRenderer.js +0 -214
  62. package/src/viewer/scene/model/RENDER_PASSES.js +0 -34
  63. package/src/viewer/scene/model/dtx/BindableDataTexture.js +0 -31
  64. package/src/viewer/scene/model/dtx/lines/DTXLinesBuffer.js +0 -27
  65. package/src/viewer/scene/model/dtx/lines/DTXLinesLayer.js +0 -897
  66. package/src/viewer/scene/model/dtx/lines/DTXLinesState.js +0 -46
  67. package/src/viewer/scene/model/dtx/lines/DTXLinesTextureFactory.js +0 -411
  68. package/src/viewer/scene/model/dtx/lines/dataTextureRamStats.js +0 -49
  69. package/src/viewer/scene/model/dtx/lines/rebucketPositions.js +0 -208
  70. package/src/viewer/scene/model/dtx/lines/renderers/DTXLinesColorRenderer.js +0 -389
  71. package/src/viewer/scene/model/dtx/lines/renderers/DTXLinesRenderers.js +0 -65
  72. package/src/viewer/scene/model/dtx/triangles/DTXTrianglesLayer.js +0 -1399
  73. package/src/viewer/scene/model/dtx/triangles/lib/DTXTrianglesBuffer.js +0 -46
  74. package/src/viewer/scene/model/dtx/triangles/lib/DTXTrianglesState.js +0 -250
  75. package/src/viewer/scene/model/dtx/triangles/lib/DTXTrianglesTextureFactory.js +0 -518
  76. package/src/viewer/scene/model/dtx/triangles/lib/dataTextureRamStats.js +0 -54
  77. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesColorRenderer.js +0 -639
  78. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesDepthRenderer.js +0 -464
  79. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesEdgesColorRenderer.js +0 -423
  80. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesEdgesRenderer.js +0 -431
  81. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesNormalsRenderer.js +0 -345
  82. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesOcclusionRenderer.js +0 -436
  83. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesPickDepthRenderer.js +0 -466
  84. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesPickMeshRenderer.js +0 -437
  85. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesPickNormalsFlatRenderer.js +0 -460
  86. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesPickNormalsRenderer.js +0 -437
  87. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesRenderers.js +0 -307
  88. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesSilhouetteRenderer.js +0 -472
  89. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesSnapInitRenderer.js +0 -474
  90. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesSnapRenderer.js +0 -435
  91. package/src/viewer/scene/model/vbo/ScratchMemory.js +0 -63
  92. package/src/viewer/scene/model/vbo/VBORenderer.js +0 -664
  93. package/src/viewer/scene/model/vbo/batching/lines/VBOBatchingLinesLayer.js +0 -704
  94. package/src/viewer/scene/model/vbo/batching/lines/lib/VBOBatchingLinesBuffer.js +0 -19
  95. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLineSnapInitRenderer.js +0 -318
  96. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesColorRenderer.js +0 -114
  97. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesRenderers.js +0 -99
  98. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesSilhouetteRenderer.js +0 -124
  99. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesSnapInitRenderer.js +0 -313
  100. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesSnapRenderer.js +0 -311
  101. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOSceneModelLineBatchingRenderer.js +0 -24
  102. package/src/viewer/scene/model/vbo/batching/points/VBOBatchingPointsLayer.js +0 -688
  103. package/src/viewer/scene/model/vbo/batching/points/VBOBatchingPointsRenderer.js +0 -24
  104. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsColorRenderer.js +0 -168
  105. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsOcclusionRenderer.js +0 -136
  106. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsPickDepthRenderer.js +0 -156
  107. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsPickMeshRenderer.js +0 -148
  108. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsRenderers.js +0 -144
  109. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsShadowRenderer.js +0 -107
  110. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsSilhouetteRenderer.js +0 -146
  111. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsSnapInitRenderer.js +0 -315
  112. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsSnapRenderer.js +0 -305
  113. package/src/viewer/scene/model/vbo/batching/triangles/VBOBatchingTrianglesBuffer.js +0 -24
  114. package/src/viewer/scene/model/vbo/batching/triangles/VBOBatchingTrianglesLayer.js +0 -1346
  115. package/src/viewer/scene/model/vbo/batching/triangles/renderers/EdgesColorRenderer.js +0 -131
  116. package/src/viewer/scene/model/vbo/batching/triangles/renderers/EdgesEmphasisRenderer.js +0 -135
  117. package/src/viewer/scene/model/vbo/batching/triangles/renderers/EdgesRenderer.js +0 -12
  118. package/src/viewer/scene/model/vbo/batching/triangles/renderers/Renderers.js +0 -403
  119. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesBatchingRenderer.js +0 -35
  120. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesColorRenderer.js +0 -252
  121. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesColorTextureRenderer.js +0 -294
  122. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesDepthRenderer.js +0 -115
  123. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesFlatColorRenderer.js +0 -246
  124. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesNormalsRenderer.js +0 -139
  125. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesOcclusionRenderer.js +0 -125
  126. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPBRRenderer.js +0 -561
  127. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPickDepthRenderer.js +0 -144
  128. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPickMeshRenderer.js +0 -130
  129. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPickNormalsFlatRenderer.js +0 -121
  130. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPickNormalsRenderer.js +0 -131
  131. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesShadowRenderer.js +0 -107
  132. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesSilhouetteRenderer.js +0 -144
  133. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesSnapInitRenderer.js +0 -313
  134. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesSnapRenderer.js +0 -312
  135. package/src/viewer/scene/model/vbo/float16.js +0 -760
  136. package/src/viewer/scene/model/vbo/instancing/lines/VBOInstancingLinesLayer.js +0 -711
  137. package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesColorRenderer.js +0 -148
  138. package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesRenderer.js +0 -26
  139. package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesRenderers.js +0 -139
  140. package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesSilhouetteRenderer.js +0 -127
  141. package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesSnapInitRenderer.js +0 -308
  142. package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesSnapRenderer.js +0 -299
  143. package/src/viewer/scene/model/vbo/instancing/points/VBOInstancingPointsLayer.js +0 -733
  144. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsColorRenderer.js +0 -174
  145. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsDepthRenderer.js +0 -156
  146. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsOcclusionRenderer.js +0 -149
  147. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsPickDepthRenderer.js +0 -170
  148. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsPickMeshRenderer.js +0 -152
  149. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsRenderer.js +0 -26
  150. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsRenderers.js +0 -174
  151. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsShadowRenderer.js +0 -119
  152. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsSilhouetteRenderer.js +0 -154
  153. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsSnapInitRenderer.js +0 -307
  154. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsSnapRenderer.js +0 -293
  155. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingTrianglesRenderer.js +0 -150
  156. package/src/viewer/scene/model/vbo/instancing/triangles/VBOInstancingTrianglesLayer.js +0 -1289
  157. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/EdgesColorRenderer.js +0 -135
  158. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/EdgesEmphasisRenderer.js +0 -137
  159. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/EdgesRenderer.js +0 -12
  160. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/Renderers.js +0 -403
  161. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesColorRenderer.js +0 -267
  162. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesColorTextureRenderer.js +0 -299
  163. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesDepthRenderer.js +0 -126
  164. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesFlatColorRenderer.js +0 -255
  165. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesFlatNormalsRenderer.js +0 -130
  166. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesInstancingRenderer.js +0 -32
  167. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesNormalsRenderer.js +0 -138
  168. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesOcclusionRenderer.js +0 -128
  169. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPBRRenderer.js +0 -561
  170. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPickDepthRenderer.js +0 -149
  171. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPickMeshRenderer.js +0 -136
  172. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPickNormalsFlatRenderer.js +0 -130
  173. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPickNormalsRenderer.js +0 -145
  174. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesShadowRenderer.js +0 -113
  175. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesSilhouetteRenderer.js +0 -148
  176. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesSnapInitRenderer.js +0 -319
  177. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesSnapRenderer.js +0 -310
  178. package/src/viewer/scene/webgl/Attribute.js +0 -23
  179. package/src/viewer/scene/webgl/Program.js +0 -181
  180. package/src/viewer/scene/webgl/RenderBufferManager.js +0 -34
  181. package/src/viewer/scene/webgl/Sampler.js +0 -18
  182. package/src/viewer/scene/webgl/Shader.js +0 -49
  183. package/src/viewer/scene/webgl/sao/SAODepthLimitedBlurRenderer.js +0 -324
  184. package/src/viewer/scene/webgl/sao/SAOOcclusionRenderer.js +0 -384
@@ -1,1399 +0,0 @@
1
- import {math} from "../../../math/math.js";
2
- import {RenderState} from "../../../webgl/RenderState.js";
3
- import {Configs} from "../../../../Configs.js";
4
- import {ENTITY_FLAGS} from '../../ENTITY_FLAGS.js';
5
- import {RENDER_PASSES} from '../../RENDER_PASSES.js';
6
- import {getRenderers} from "./renderers/DTXTrianglesRenderers.js";
7
- import {DTXTrianglesBuffer} from "./lib/DTXTrianglesBuffer.js";
8
- import {DTXTrianglesState} from "./lib/DTXTrianglesState.js"
9
- import {dataTextureRamStats} from "./lib/dataTextureRamStats.js";
10
- import {DTXTrianglesTextureFactory} from "./lib/DTXTrianglesTextureFactory.js";
11
-
12
- const configs = new Configs();
13
-
14
- /**
15
- * 12-bits allowed for object ids.
16
- * Limits the per-object texture height in the layer.
17
- */
18
- const MAX_NUMBER_OF_OBJECTS_IN_LAYER = (1 << 16);
19
-
20
- /**
21
- * 4096 is max data texture height.
22
- * Limits the aggregated geometry texture height in the layer.
23
- */
24
- const MAX_DATA_TEXTURE_HEIGHT = configs.maxDataTextureHeight;
25
-
26
- /**
27
- * Align `indices` and `edgeIndices` memory layout to 8 elements.
28
- *
29
- * Used as an optimization for the `...portionIds...` texture, so it
30
- * can just be stored 1 out of 8 `portionIds` corresponding to a given
31
- * `triangle-index` or `edge-index`.
32
- */
33
- const INDICES_EDGE_INDICES_ALIGNEMENT_SIZE = 8;
34
-
35
- /**
36
- * Number of maximum allowed per-object flags update per render frame
37
- * before switching to batch update mode.
38
- */
39
- const MAX_OBJECT_UPDATES_IN_FRAME_WITHOUT_BATCHED_UPDATE = 10;
40
-
41
- const tempVec4a = math.vec4();
42
- const tempMat4a = new Float32Array(16);
43
- const tempUint8Array4 = new Uint8Array(4);
44
- const tempFloat32Array3 = new Float32Array(3);
45
-
46
- let numLayers = 0;
47
-
48
- const DEFAULT_MATRIX = math.identityMat4();
49
-
50
- /**
51
- * @private
52
- */
53
- export class DTXTrianglesLayer {
54
-
55
- constructor(model, cfg) {
56
-
57
- //console.info("Creating DTXTrianglesLayer");
58
-
59
- dataTextureRamStats.numberOfLayers++;
60
-
61
- this._layerNumber = numLayers++;
62
- this.sortId = `TriDTX-${this._layerNumber}`; // State sorting key.
63
- this.layerIndex = cfg.layerIndex; // Index of this TrianglesDataTextureLayer in {@link SceneModel#_layerList}.
64
-
65
- this._renderers = getRenderers(model.scene);
66
- this.model = model;
67
- this._buffer = new DTXTrianglesBuffer();
68
- this._dtxState = new DTXTrianglesState();
69
- this._dtxTextureFactory = new DTXTrianglesTextureFactory();
70
-
71
- this._state = new RenderState({
72
- origin: math.vec3(cfg.origin),
73
- metallicRoughnessBuf: null,
74
- textureState: this._dtxState,
75
- numIndices8Bits: 0,
76
- numIndices16Bits: 0,
77
- numIndices32Bits: 0,
78
- numEdgeIndices8Bits: 0,
79
- numEdgeIndices16Bits: 0,
80
- numEdgeIndices32Bits: 0,
81
- numVertices: 0,
82
- });
83
-
84
- this._numPortions = 0; // These counts are used to avoid unnecessary render passes
85
- this._numVisibleLayerPortions = 0;
86
- this._numTransparentLayerPortions = 0;
87
- this._numXRayedLayerPortions = 0;
88
- this._numSelectedLayerPortions = 0;
89
- this._numHighlightedLayerPortions = 0;
90
- this._numClippableLayerPortions = 0;
91
- this._numEdgesLayerPortions = 0;
92
- this._numPickableLayerPortions = 0;
93
- this._numCulledLayerPortions = 0;
94
-
95
- this._subPortions = [];
96
-
97
- if (this.model.scene.readableGeometryEnabled) {
98
- this._subPortionReadableGeometries = {};
99
- }
100
-
101
- /**
102
- * Due to `index rebucketting` process in ```prepareMeshGeometry``` function, it's possible that a single
103
- * portion is expanded to more than 1 real sub-portion.
104
- *
105
- * This Array tracks the mapping between:
106
- *
107
- * - external `portionIds` as seen by consumers of this class.
108
- * - internal `sub-portionIds` actually managed by this class.
109
- *
110
- * The outer index of this array is the externally seen `portionId`.
111
- * The inner value of the array, are `sub-portionIds` corresponding to the `portionId`.
112
- */
113
- this._portionToSubPortionsMap = [];
114
-
115
- this._bucketGeometries = {};
116
-
117
- this._meshes = [];
118
-
119
- /**
120
- * The axis-aligned World-space boundary of this TrianglesDataTextureLayer's positions.
121
- */
122
- this._aabb = math.collapseAABB3();
123
- this.aabbDirty = true;
124
-
125
- /**
126
- * The number of updates in the current frame;
127
- */
128
- this._numUpdatesInFrame = 0;
129
-
130
- /**
131
- * The type of primitives in this layer.
132
- */
133
- this.primitive = cfg.primitive;
134
-
135
- this._finalized = false;
136
- }
137
-
138
- get aabb() {
139
- if (this.aabbDirty) {
140
- math.collapseAABB3(this._aabb);
141
- for (let i = 0, len = this._meshes.length; i < len; i++) {
142
- math.expandAABB3(this._aabb, this._meshes[i].aabb);
143
- }
144
- this.aabbDirty = false;
145
- }
146
- return this._aabb;
147
- }
148
-
149
- /**
150
- * Returns whether the ```TrianglesDataTextureLayer``` has room for more portions.
151
- *
152
- * @param {object} portionCfg An object containing the geometrical data (`positions`, `indices`, `edgeIndices`) for the portion.
153
- * @returns {Boolean} Wheter the requested portion can be created
154
- */
155
- canCreatePortion(portionCfg) {
156
- if (this._finalized) {
157
- throw "Already finalized";
158
- }
159
- const numNewPortions = portionCfg.buckets.length;
160
- if ((this._numPortions + numNewPortions) > MAX_NUMBER_OF_OBJECTS_IN_LAYER) {
161
- dataTextureRamStats.cannotCreatePortion.because10BitsObjectId++;
162
- }
163
- let retVal = (this._numPortions + numNewPortions) <= MAX_NUMBER_OF_OBJECTS_IN_LAYER;
164
- const bucketIndex = 0; // TODO: Is this a bug?
165
- const bucketGeometryId = portionCfg.geometryId !== undefined && portionCfg.geometryId !== null
166
- ? `${portionCfg.geometryId}#${bucketIndex}`
167
- : `${portionCfg.id}#${bucketIndex}`;
168
- const alreadyHasPortionGeometry = this._bucketGeometries[bucketGeometryId];
169
- if (!alreadyHasPortionGeometry) {
170
- const maxIndicesOfAnyBits = Math.max(this._state.numIndices8Bits, this._state.numIndices16Bits, this._state.numIndices32Bits,);
171
- let numVertices = 0;
172
- let numIndices = 0;
173
- portionCfg.buckets.forEach(bucket => {
174
- numVertices += bucket.positionsCompressed.length / 3;
175
- numIndices += bucket.indices.length / 3;
176
- });
177
- if ((this._state.numVertices + numVertices) > MAX_DATA_TEXTURE_HEIGHT * 4096 ||
178
- (maxIndicesOfAnyBits + numIndices) > MAX_DATA_TEXTURE_HEIGHT * 4096) {
179
- dataTextureRamStats.cannotCreatePortion.becauseTextureSize++;
180
- }
181
- retVal &&=
182
- (this._state.numVertices + numVertices) <= MAX_DATA_TEXTURE_HEIGHT * 4096 &&
183
- (maxIndicesOfAnyBits + numIndices) <= MAX_DATA_TEXTURE_HEIGHT * 4096;
184
- }
185
- return retVal;
186
- }
187
-
188
- /**
189
- * Creates a new portion within this TrianglesDataTextureLayer, returns the new portion ID.
190
- *
191
- * Gives the portion the specified geometry, color and matrix.
192
- *
193
- * @param mesh The SceneModelMesh that owns the portion
194
- * @param portionCfg.positionsCompressed Flat float Local-space positionsCompressed array.
195
- * @param [portionCfg.normals] Flat float normals array.
196
- * @param [portionCfg.colors] Flat float colors array.
197
- * @param portionCfg.indices Flat int indices array.
198
- * @param [portionCfg.edgeIndices] Flat int edges indices array.
199
- * @param portionCfg.color Quantized RGB color [0..255,0..255,0..255,0..255]
200
- * @param portionCfg.metallic Metalness factor [0..255]
201
- * @param portionCfg.roughness Roughness factor [0..255]
202
- * @param portionCfg.opacity Opacity [0..255]
203
- * @param [portionCfg.meshMatrix] Flat float 4x4 matrix - transforms the portion within the coordinate system that's local to the SceneModel
204
- * @param portionCfg.worldAABB Flat float AABB World-space AABB
205
- * @param portionCfg.pickColor Quantized pick color
206
- * @returns {number} Portion ID
207
- */
208
- createPortion(mesh, portionCfg) {
209
- if (this._finalized) {
210
- throw "Already finalized";
211
- }
212
- const subPortionIds = [];
213
- // const portionAABB = portionCfg.worldAABB;
214
- portionCfg.buckets.forEach((bucket, bucketIndex) => {
215
- const bucketGeometryId = portionCfg.geometryId !== undefined && portionCfg.geometryId !== null
216
- ? `${portionCfg.geometryId}#${bucketIndex}`
217
- : `${portionCfg.id}#${bucketIndex}`;
218
- let bucketGeometry = this._bucketGeometries[bucketGeometryId];
219
- if (!bucketGeometry) {
220
- bucketGeometry = this._createBucketGeometry(portionCfg, bucket);
221
- this._bucketGeometries[bucketGeometryId] = bucketGeometry;
222
- }
223
- // const subPortionAABB = math.collapseAABB3(tempAABB3b);
224
- const subPortionId = this._createSubPortion(portionCfg, bucketGeometry, bucket);
225
- //math.expandAABB3(portionAABB, subPortionAABB);
226
- subPortionIds.push(subPortionId);
227
- });
228
- const portionId = this._portionToSubPortionsMap.length;
229
- this._portionToSubPortionsMap.push(subPortionIds);
230
- this.model.numPortions++;
231
- this._meshes.push(mesh);
232
- return portionId;
233
- }
234
-
235
- _createBucketGeometry(portionCfg, bucket) {
236
-
237
- // Indices alignement
238
- // This will make every mesh consume a multiple of INDICES_EDGE_INDICES_ALIGNEMENT_SIZE
239
- // array items for storing the triangles of the mesh, and it supports:
240
- // - a memory optimization of factor INDICES_EDGE_INDICES_ALIGNEMENT_SIZE
241
- // - in exchange for a small RAM overhead
242
- // (by adding some padding until a size that is multiple of INDICES_EDGE_INDICES_ALIGNEMENT_SIZE)
243
-
244
- if (bucket.indices) {
245
- const alignedIndicesLen = Math.ceil((bucket.indices.length / 3) / INDICES_EDGE_INDICES_ALIGNEMENT_SIZE) * INDICES_EDGE_INDICES_ALIGNEMENT_SIZE * 3;
246
- dataTextureRamStats.overheadSizeAlignementIndices += 2 * (alignedIndicesLen - bucket.indices.length);
247
- const alignedIndices = new Uint32Array(alignedIndicesLen);
248
- alignedIndices.fill(0);
249
- alignedIndices.set(bucket.indices);
250
- bucket.indices = alignedIndices;
251
- }
252
-
253
- // EdgeIndices alignement
254
- // This will make every mesh consume a multiple of INDICES_EDGE_INDICES_ALIGNEMENT_SIZE
255
- // array items for storing the edges of the mesh, and it supports:
256
- // - a memory optimization of factor INDICES_EDGE_INDICES_ALIGNEMENT_SIZE
257
- // - in exchange for a small RAM overhead
258
- // (by adding some padding until a size that is multiple of INDICES_EDGE_INDICES_ALIGNEMENT_SIZE)
259
-
260
- if (bucket.edgeIndices) {
261
- const alignedEdgeIndicesLen = Math.ceil((bucket.edgeIndices.length / 2) / INDICES_EDGE_INDICES_ALIGNEMENT_SIZE) * INDICES_EDGE_INDICES_ALIGNEMENT_SIZE * 2;
262
- dataTextureRamStats.overheadSizeAlignementEdgeIndices += 2 * (alignedEdgeIndicesLen - bucket.edgeIndices.length);
263
- const alignedEdgeIndices = new Uint32Array(alignedEdgeIndicesLen);
264
- alignedEdgeIndices.fill(0);
265
- alignedEdgeIndices.set(bucket.edgeIndices);
266
- bucket.edgeIndices = alignedEdgeIndices;
267
- }
268
-
269
- const positionsCompressed = bucket.positionsCompressed;
270
- const indices = bucket.indices;
271
- const edgeIndices = bucket.edgeIndices;
272
- const buffer = this._buffer;
273
-
274
- buffer.positionsCompressed.push(positionsCompressed)
275
- const vertexBase = buffer.lenPositionsCompressed / 3;
276
- const numVertices = positionsCompressed.length / 3;
277
- buffer.lenPositionsCompressed += positionsCompressed.length;
278
-
279
- let indicesBase;
280
- let numTriangles = 0;
281
- if (indices) {
282
- numTriangles = indices.length / 3;
283
- let indicesBuffer;
284
- if (numVertices <= (1 << 8)) {
285
- indicesBuffer = buffer.indices8Bits;
286
- indicesBase = buffer.lenIndices8Bits / 3;
287
- buffer.lenIndices8Bits += indices.length;
288
- } else if (numVertices <= (1 << 16)) {
289
- indicesBuffer = buffer.indices16Bits;
290
- indicesBase = buffer.lenIndices16Bits / 3;
291
- buffer.lenIndices16Bits += indices.length;
292
- } else {
293
- indicesBuffer = buffer.indices32Bits;
294
- indicesBase = buffer.lenIndices32Bits / 3;
295
- buffer.lenIndices32Bits += indices.length;
296
- }
297
- indicesBuffer.push(indices);
298
- }
299
-
300
- let edgeIndicesBase;
301
- let numEdges = 0;
302
- if (edgeIndices) {
303
- numEdges = edgeIndices.length / 2;
304
- let edgeIndicesBuffer;
305
- if (numVertices <= (1 << 8)) {
306
- edgeIndicesBuffer = buffer.edgeIndices8Bits;
307
- edgeIndicesBase = buffer.lenEdgeIndices8Bits / 2;
308
- buffer.lenEdgeIndices8Bits += edgeIndices.length;
309
- } else if (numVertices <= (1 << 16)) {
310
- edgeIndicesBuffer = buffer.edgeIndices16Bits;
311
- edgeIndicesBase = buffer.lenEdgeIndices16Bits / 2;
312
- buffer.lenEdgeIndices16Bits += edgeIndices.length;
313
- } else {
314
- edgeIndicesBuffer = buffer.edgeIndices32Bits;
315
- edgeIndicesBase = buffer.lenEdgeIndices32Bits / 2;
316
- buffer.lenEdgeIndices32Bits += edgeIndices.length;
317
- }
318
- edgeIndicesBuffer.push(edgeIndices);
319
- }
320
-
321
- this._state.numVertices += numVertices;
322
-
323
- dataTextureRamStats.numberOfGeometries++;
324
-
325
- const bucketGeometry = {
326
- vertexBase,
327
- numVertices,
328
- numTriangles,
329
- numEdges,
330
- indicesBase,
331
- edgeIndicesBase
332
- };
333
-
334
- return bucketGeometry;
335
- }
336
-
337
- _createSubPortion(portionCfg, bucketGeometry, bucket, subPortionAABB) {
338
-
339
- const color = portionCfg.color;
340
- const metallic = portionCfg.metallic;
341
- const roughness = portionCfg.roughness;
342
- const colors = portionCfg.colors;
343
- const opacity = portionCfg.opacity;
344
- const meshMatrix = portionCfg.meshMatrix;
345
- const pickColor = portionCfg.pickColor;
346
- const buffer = this._buffer;
347
- const state = this._state;
348
-
349
- buffer.perObjectPositionsDecodeMatrices.push(portionCfg.positionsDecodeMatrix);
350
- buffer.perObjectInstancePositioningMatrices.push(meshMatrix || DEFAULT_MATRIX);
351
-
352
- buffer.perObjectSolid.push(!!portionCfg.solid);
353
-
354
- if (colors) {
355
- buffer.perObjectColors.push([colors[0] * 255, colors[1] * 255, colors[2] * 255, 255]);
356
- } else if (color) { // Color is pre-quantized by SceneModel
357
- buffer.perObjectColors.push([color[0], color[1], color[2], opacity]);
358
- }
359
-
360
- buffer.perObjectPickColors.push(pickColor);
361
- buffer.perObjectVertexBases.push(bucketGeometry.vertexBase);
362
-
363
- {
364
- let currentNumIndices;
365
- if (bucketGeometry.numVertices <= (1 << 8)) {
366
- currentNumIndices = state.numIndices8Bits;
367
- } else if (bucketGeometry.numVertices <= (1 << 16)) {
368
- currentNumIndices = state.numIndices16Bits;
369
- } else {
370
- currentNumIndices = state.numIndices32Bits;
371
- }
372
- buffer.perObjectIndexBaseOffsets.push(currentNumIndices / 3 - bucketGeometry.indicesBase);
373
- }
374
-
375
- {
376
- let currentNumEdgeIndices;
377
- if (bucketGeometry.numVertices <= (1 << 8)) {
378
- currentNumEdgeIndices = state.numEdgeIndices8Bits;
379
- } else if (bucketGeometry.numVertices <= (1 << 16)) {
380
- currentNumEdgeIndices = state.numEdgeIndices16Bits;
381
- } else {
382
- currentNumEdgeIndices = state.numEdgeIndices32Bits;
383
- }
384
- buffer.perObjectEdgeIndexBaseOffsets.push(currentNumEdgeIndices / 2 - bucketGeometry.edgeIndicesBase);
385
- }
386
-
387
- const subPortionId = this._subPortions.length;
388
- if (bucketGeometry.numTriangles > 0) {
389
- let numIndices = bucketGeometry.numTriangles * 3;
390
- let indicesPortionIdBuffer;
391
- if (bucketGeometry.numVertices <= (1 << 8)) {
392
- indicesPortionIdBuffer = buffer.perTriangleNumberPortionId8Bits;
393
- state.numIndices8Bits += numIndices;
394
- dataTextureRamStats.totalPolygons8Bits += bucketGeometry.numTriangles;
395
- } else if (bucketGeometry.numVertices <= (1 << 16)) {
396
- indicesPortionIdBuffer = buffer.perTriangleNumberPortionId16Bits;
397
- state.numIndices16Bits += numIndices;
398
- dataTextureRamStats.totalPolygons16Bits += bucketGeometry.numTriangles;
399
- } else {
400
- indicesPortionIdBuffer = buffer.perTriangleNumberPortionId32Bits;
401
- state.numIndices32Bits += numIndices;
402
- dataTextureRamStats.totalPolygons32Bits += bucketGeometry.numTriangles;
403
- }
404
- dataTextureRamStats.totalPolygons += bucketGeometry.numTriangles;
405
- for (let i = 0; i < bucketGeometry.numTriangles; i += INDICES_EDGE_INDICES_ALIGNEMENT_SIZE) {
406
- indicesPortionIdBuffer.push(subPortionId);
407
- }
408
- }
409
-
410
- if (bucketGeometry.numEdges > 0) {
411
- let numEdgeIndices = bucketGeometry.numEdges * 2;
412
- let edgeIndicesPortionIdBuffer;
413
- if (bucketGeometry.numVertices <= (1 << 8)) {
414
- edgeIndicesPortionIdBuffer = buffer.perEdgeNumberPortionId8Bits;
415
- state.numEdgeIndices8Bits += numEdgeIndices;
416
- dataTextureRamStats.totalEdges8Bits += bucketGeometry.numEdges;
417
- } else if (bucketGeometry.numVertices <= (1 << 16)) {
418
- edgeIndicesPortionIdBuffer = buffer.perEdgeNumberPortionId16Bits;
419
- state.numEdgeIndices16Bits += numEdgeIndices;
420
- dataTextureRamStats.totalEdges16Bits += bucketGeometry.numEdges;
421
- } else {
422
- edgeIndicesPortionIdBuffer = buffer.perEdgeNumberPortionId32Bits;
423
- state.numEdgeIndices32Bits += numEdgeIndices;
424
- dataTextureRamStats.totalEdges32Bits += bucketGeometry.numEdges;
425
- }
426
- dataTextureRamStats.totalEdges += bucketGeometry.numEdges;
427
- for (let i = 0; i < bucketGeometry.numEdges; i += INDICES_EDGE_INDICES_ALIGNEMENT_SIZE) {
428
- edgeIndicesPortionIdBuffer.push(subPortionId);
429
- }
430
- }
431
-
432
- // buffer.perObjectOffsets.push([0, 0, 0]);
433
-
434
- this._subPortions.push({
435
- // vertsBase: vertsIndex,
436
- numVertices: bucketGeometry.numTriangles
437
- });
438
-
439
- if (this.model.scene.readableGeometryEnabled) {
440
- this._subPortionReadableGeometries[subPortionId] = {
441
- indices: bucket.indices,
442
- positionsCompressed: bucket.positionsCompressed,
443
- positionsDecodeMatrix: portionCfg.positionsDecodeMatrix,
444
- meshMatrix: portionCfg.meshMatrix
445
- };
446
- }
447
-
448
- this._numPortions++;
449
-
450
- dataTextureRamStats.numberOfPortions++;
451
-
452
- return subPortionId;
453
- }
454
-
455
- /**
456
- * Builds data textures from the appended geometries and loads them into the GPU.
457
- *
458
- * No more portions can then be created.
459
- */
460
- finalize() {
461
-
462
- if (this._finalized) {
463
- return;
464
- }
465
-
466
- const state = this._state;
467
- const textureState = this._dtxState;
468
- const gl = this.model.scene.canvas.gl;
469
- const buffer = this._buffer;
470
-
471
- state.gl = gl;
472
- textureState.texturePerObjectColorsAndFlags = this._dtxTextureFactory.createTextureForColorsAndFlags(
473
- gl,
474
- buffer.perObjectColors,
475
- buffer.perObjectPickColors,
476
- buffer.perObjectVertexBases,
477
- buffer.perObjectIndexBaseOffsets,
478
- buffer.perObjectEdgeIndexBaseOffsets,
479
- buffer.perObjectSolid);
480
-
481
- textureState.texturePerObjectInstanceMatrices
482
- = this._dtxTextureFactory.createTextureForInstancingMatrices(gl, buffer.perObjectInstancePositioningMatrices);
483
-
484
- textureState.texturePerObjectPositionsDecodeMatrix
485
- = this._dtxTextureFactory.createTextureForPositionsDecodeMatrices(
486
- gl,
487
- buffer.perObjectPositionsDecodeMatrices);
488
-
489
- textureState.texturePerVertexIdCoordinates = this._dtxTextureFactory.createTextureForPositions(
490
- gl,
491
- buffer.positionsCompressed,
492
- buffer.lenPositionsCompressed);
493
-
494
- textureState.texturePerPolygonIdPortionIds8Bits = this._dtxTextureFactory.createTextureForPackedPortionIds(
495
- gl,
496
- buffer.perTriangleNumberPortionId8Bits);
497
-
498
- textureState.texturePerPolygonIdPortionIds16Bits = this._dtxTextureFactory.createTextureForPackedPortionIds(
499
- gl,
500
- buffer.perTriangleNumberPortionId16Bits);
501
-
502
- textureState.texturePerPolygonIdPortionIds32Bits = this._dtxTextureFactory.createTextureForPackedPortionIds(
503
- gl,
504
- buffer.perTriangleNumberPortionId32Bits);
505
-
506
- if (buffer.perEdgeNumberPortionId8Bits.length > 0) {
507
- textureState.texturePerEdgeIdPortionIds8Bits = this._dtxTextureFactory.createTextureForPackedPortionIds(
508
- gl,
509
- buffer.perEdgeNumberPortionId8Bits);
510
- }
511
-
512
- if (buffer.perEdgeNumberPortionId16Bits.length > 0) {
513
- textureState.texturePerEdgeIdPortionIds16Bits = this._dtxTextureFactory.createTextureForPackedPortionIds(
514
- gl,
515
- buffer.perEdgeNumberPortionId16Bits);
516
- }
517
-
518
- if (buffer.perEdgeNumberPortionId32Bits.length > 0) {
519
- textureState.texturePerEdgeIdPortionIds32Bits = this._dtxTextureFactory.createTextureForPackedPortionIds(
520
- gl,
521
- buffer.perEdgeNumberPortionId32Bits);
522
- }
523
-
524
- if (buffer.lenIndices8Bits > 0) {
525
- textureState.texturePerPolygonIdIndices8Bits = this._dtxTextureFactory.createTextureFor8BitIndices(
526
- gl,
527
- buffer.indices8Bits, buffer.lenIndices8Bits);
528
- }
529
-
530
- if (buffer.lenIndices16Bits > 0) {
531
- textureState.texturePerPolygonIdIndices16Bits = this._dtxTextureFactory.createTextureFor16BitIndices(
532
- gl,
533
- buffer.indices16Bits, buffer.lenIndices16Bits);
534
- }
535
-
536
- if (buffer.lenIndices32Bits > 0) {
537
- textureState.texturePerPolygonIdIndices32Bits = this._dtxTextureFactory.createTextureFor32BitIndices(
538
- gl,
539
- buffer.indices32Bits, buffer.lenIndices32Bits);
540
- }
541
-
542
- if (buffer.lenEdgeIndices8Bits > 0) {
543
- textureState.texturePerPolygonIdEdgeIndices8Bits = this._dtxTextureFactory.createTextureFor8BitsEdgeIndices(
544
- gl,
545
- buffer.edgeIndices8Bits, buffer.lenEdgeIndices8Bits);
546
- }
547
-
548
- if (buffer.lenEdgeIndices16Bits > 0) {
549
- textureState.texturePerPolygonIdEdgeIndices16Bits = this._dtxTextureFactory.createTextureFor16BitsEdgeIndices(
550
- gl,
551
- buffer.edgeIndices16Bits, buffer.lenEdgeIndices16Bits);
552
- }
553
-
554
- if (buffer.lenEdgeIndices32Bits > 0) {
555
- textureState.texturePerPolygonIdEdgeIndices32Bits = this._dtxTextureFactory.createTextureFor32BitsEdgeIndices(
556
- gl,
557
- buffer.edgeIndices32Bits, buffer.lenEdgeIndices32Bits);
558
- }
559
-
560
- textureState.finalize();
561
-
562
- // Free up memory
563
- this._buffer = null;
564
- this._bucketGeometries = {};
565
- this._finalized = true;
566
- this._deferredSetFlagsDirty = false; //
567
-
568
- this._onSceneRendering = this.model.scene.on("rendering", () => {
569
- if (this._deferredSetFlagsDirty) {
570
- this._uploadDeferredFlags();
571
- }
572
- this._numUpdatesInFrame = 0;
573
- });
574
- }
575
-
576
- isEmpty() {
577
- return this._numPortions === 0;
578
- }
579
-
580
- initFlags(portionId, flags, meshTransparent) {
581
- if (flags & ENTITY_FLAGS.VISIBLE) {
582
- this._numVisibleLayerPortions++;
583
- this.model.numVisibleLayerPortions++;
584
- }
585
- if (flags & ENTITY_FLAGS.HIGHLIGHTED) {
586
- this._numHighlightedLayerPortions++;
587
- this.model.numHighlightedLayerPortions++;
588
- }
589
- if (flags & ENTITY_FLAGS.XRAYED) {
590
- this._numXRayedLayerPortions++;
591
- this.model.numXRayedLayerPortions++;
592
- }
593
- if (flags & ENTITY_FLAGS.SELECTED) {
594
- this._numSelectedLayerPortions++;
595
- this.model.numSelectedLayerPortions++;
596
- }
597
- if (flags & ENTITY_FLAGS.CLIPPABLE) {
598
- this._numClippableLayerPortions++;
599
- this.model.numClippableLayerPortions++;
600
- }
601
- if (flags & ENTITY_FLAGS.EDGES) {
602
- this._numEdgesLayerPortions++;
603
- this.model.numEdgesLayerPortions++;
604
- }
605
- if (flags & ENTITY_FLAGS.PICKABLE) {
606
- this._numPickableLayerPortions++;
607
- this.model.numPickableLayerPortions++;
608
- }
609
- if (flags & ENTITY_FLAGS.CULLED) {
610
- this._numCulledLayerPortions++;
611
- this.model.numCulledLayerPortions++;
612
- }
613
- if (meshTransparent) {
614
- this._numTransparentLayerPortions++;
615
- this.model.numTransparentLayerPortions++;
616
- }
617
- const deferred = true;
618
- this._setFlags(portionId, flags, meshTransparent, deferred);
619
- this._setFlags2(portionId, flags, deferred);
620
- }
621
-
622
- flushInitFlags() {
623
- this._setDeferredFlags();
624
- this._setDeferredFlags2();
625
- }
626
-
627
- setVisible(portionId, flags, transparent) {
628
- if (!this._finalized) {
629
- throw "Not finalized";
630
- }
631
- if (flags & ENTITY_FLAGS.VISIBLE) {
632
- this._numVisibleLayerPortions++;
633
- this.model.numVisibleLayerPortions++;
634
- } else {
635
- this._numVisibleLayerPortions--;
636
- this.model.numVisibleLayerPortions--;
637
- }
638
- this._setFlags(portionId, flags, transparent);
639
- }
640
-
641
- setHighlighted(portionId, flags, transparent) {
642
- if (!this._finalized) {
643
- throw "Not finalized";
644
- }
645
- if (flags & ENTITY_FLAGS.HIGHLIGHTED) {
646
- this._numHighlightedLayerPortions++;
647
- this.model.numHighlightedLayerPortions++;
648
- } else {
649
- this._numHighlightedLayerPortions--;
650
- this.model.numHighlightedLayerPortions--;
651
- }
652
- this._setFlags(portionId, flags, transparent);
653
- }
654
-
655
- setXRayed(portionId, flags, transparent) {
656
- if (!this._finalized) {
657
- throw "Not finalized";
658
- }
659
- if (flags & ENTITY_FLAGS.XRAYED) {
660
- this._numXRayedLayerPortions++;
661
- this.model.numXRayedLayerPortions++;
662
- } else {
663
- this._numXRayedLayerPortions--;
664
- this.model.numXRayedLayerPortions--;
665
- }
666
- this._setFlags(portionId, flags, transparent);
667
- }
668
-
669
- setSelected(portionId, flags, transparent) {
670
- if (!this._finalized) {
671
- throw "Not finalized";
672
- }
673
- if (flags & ENTITY_FLAGS.SELECTED) {
674
- this._numSelectedLayerPortions++;
675
- this.model.numSelectedLayerPortions++;
676
- } else {
677
- this._numSelectedLayerPortions--;
678
- this.model.numSelectedLayerPortions--;
679
- }
680
- this._setFlags(portionId, flags, transparent);
681
- }
682
-
683
- setEdges(portionId, flags, transparent) {
684
- if (!this._finalized) {
685
- throw "Not finalized";
686
- }
687
- if (flags & ENTITY_FLAGS.EDGES) {
688
- this._numEdgesLayerPortions++;
689
- this.model.numEdgesLayerPortions++;
690
- } else {
691
- this._numEdgesLayerPortions--;
692
- this.model.numEdgesLayerPortions--;
693
- }
694
- this._setFlags(portionId, flags, transparent);
695
- }
696
-
697
- setClippable(portionId, flags) {
698
- if (!this._finalized) {
699
- throw "Not finalized";
700
- }
701
- if (flags & ENTITY_FLAGS.CLIPPABLE) {
702
- this._numClippableLayerPortions++;
703
- this.model.numClippableLayerPortions++;
704
- } else {
705
- this._numClippableLayerPortions--;
706
- this.model.numClippableLayerPortions--;
707
- }
708
- this._setFlags2(portionId, flags);
709
- }
710
-
711
- /**
712
- * This will _start_ a "set-flags transaction".
713
- *
714
- * After invoking this method, calling setFlags/setFlags2 will not update
715
- * the colors+flags texture but only store the new flags/flag2 in the
716
- * colors+flags texture data array.
717
- *
718
- * After invoking this method, and when all desired setFlags/setFlags2 have
719
- * been called on needed portions of the layer, invoke `_uploadDeferredFlags`
720
- * to actually upload the data array into the texture.
721
- *
722
- * In massive "set-flags" scenarios like VFC or LOD mechanisms, the combination of
723
- * `_beginDeferredFlags` + `_uploadDeferredFlags`brings a speed-up of
724
- * up to 80x when e.g. objects are massively (un)culled 🚀.
725
- */
726
- _beginDeferredFlags() {
727
- this._deferredSetFlagsActive = true;
728
- }
729
-
730
- /**
731
- * This will _commit_ a "set-flags transaction".
732
- *
733
- * Invoking this method will update the colors+flags texture data with new
734
- * flags/flags2 set since the previous invocation of `_beginDeferredFlags`.
735
- */
736
- _uploadDeferredFlags() {
737
- this._deferredSetFlagsActive = false;
738
- if (!this._deferredSetFlagsDirty) {
739
- return;
740
- }
741
- this._deferredSetFlagsDirty = false;
742
- const gl = this.model.scene.canvas.gl;
743
- const textureState = this._dtxState;
744
- gl.bindTexture(gl.TEXTURE_2D, textureState.texturePerObjectColorsAndFlags._texture);
745
- gl.texSubImage2D(
746
- gl.TEXTURE_2D,
747
- 0, // level
748
- 0, // xoffset
749
- 0, // yoffset
750
- textureState.texturePerObjectColorsAndFlags._textureWidth, // width
751
- textureState.texturePerObjectColorsAndFlags._textureHeight, // width
752
- gl.RGBA_INTEGER,
753
- gl.UNSIGNED_BYTE,
754
- textureState.texturePerObjectColorsAndFlags._textureData
755
- );
756
- // gl.bindTexture(gl.TEXTURE_2D, textureState.texturePerObjectInstanceMatrices._texture);
757
- // gl.texSubImage2D(
758
- // gl.TEXTURE_2D,
759
- // 0, // level
760
- // 0, // xoffset
761
- // 0, // yoffset
762
- // textureState.texturePerObjectInstanceMatrices._textureWidth, // width
763
- // textureState.texturePerObjectInstanceMatrices._textureHeight, // width
764
- // gl.RGB,
765
- // gl.FLOAT,
766
- // textureState.texturePerObjectInstanceMatrices._textureData
767
- // );
768
- }
769
-
770
- setCulled(portionId, flags, transparent) {
771
- if (!this._finalized) {
772
- throw "Not finalized";
773
- }
774
- if (flags & ENTITY_FLAGS.CULLED) {
775
- this._numCulledLayerPortions += this._portionToSubPortionsMap[portionId].length;
776
- this.model.numCulledLayerPortions++;
777
- } else {
778
- this._numCulledLayerPortions -= this._portionToSubPortionsMap[portionId].length;
779
- this.model.numCulledLayerPortions--;
780
- }
781
- this._setFlags(portionId, flags, transparent);
782
- }
783
-
784
- setCollidable(portionId, flags) {
785
- if (!this._finalized) {
786
- throw "Not finalized";
787
- }
788
- }
789
-
790
- setPickable(portionId, flags, transparent) {
791
- if (!this._finalized) {
792
- throw "Not finalized";
793
- }
794
- if (flags & ENTITY_FLAGS.PICKABLE) {
795
- this._numPickableLayerPortions++;
796
- this.model.numPickableLayerPortions++;
797
- } else {
798
- this._numPickableLayerPortions--;
799
- this.model.numPickableLayerPortions--;
800
- }
801
- this._setFlags(portionId, flags, transparent);
802
- }
803
-
804
- setColor(portionId, color) {
805
- const subPortionIds = this._portionToSubPortionsMap[portionId];
806
- for (let i = 0, len = subPortionIds.length; i < len; i++) {
807
- this._subPortionSetColor(subPortionIds[i], color);
808
- }
809
- }
810
-
811
- _subPortionSetColor(subPortionId, color) {
812
- if (!this._finalized) {
813
- throw "Not finalized";
814
- }
815
- // Color
816
- const textureState = this._dtxState;
817
- const gl = this.model.scene.canvas.gl;
818
- tempUint8Array4 [0] = color[0];
819
- tempUint8Array4 [1] = color[1];
820
- tempUint8Array4 [2] = color[2];
821
- tempUint8Array4 [3] = color[3];
822
- // object colors
823
- textureState.texturePerObjectColorsAndFlags._textureData.set(tempUint8Array4, subPortionId * 32);
824
- if (this._deferredSetFlagsActive) {
825
- //console.info("_subPortionSetColor defer");
826
- this._deferredSetFlagsDirty = true;
827
- return;
828
- }
829
- if (++this._numUpdatesInFrame >= MAX_OBJECT_UPDATES_IN_FRAME_WITHOUT_BATCHED_UPDATE) {
830
- this._beginDeferredFlags(); // Subsequent flags updates now deferred
831
- }
832
- //console.info("_subPortionSetColor write through");
833
- gl.bindTexture(gl.TEXTURE_2D, textureState.texturePerObjectColorsAndFlags._texture);
834
- gl.texSubImage2D(
835
- gl.TEXTURE_2D,
836
- 0, // level
837
- (subPortionId % 512) * 8, // xoffset
838
- Math.floor(subPortionId / 512), // yoffset
839
- 1, // width
840
- 1, //height
841
- gl.RGBA_INTEGER,
842
- gl.UNSIGNED_BYTE,
843
- tempUint8Array4
844
- );
845
- // gl.bindTexture (gl.TEXTURE_2D, null);
846
- }
847
-
848
- setTransparent(portionId, flags, transparent) {
849
- if (transparent) {
850
- this._numTransparentLayerPortions++;
851
- this.model.numTransparentLayerPortions++;
852
- } else {
853
- this._numTransparentLayerPortions--;
854
- this.model.numTransparentLayerPortions--;
855
- }
856
- this._setFlags(portionId, flags, transparent);
857
- }
858
-
859
- _setFlags(portionId, flags, transparent, deferred = false) {
860
- const subPortionIds = this._portionToSubPortionsMap[portionId];
861
- for (let i = 0, len = subPortionIds.length; i < len; i++) {
862
- this._subPortionSetFlags(subPortionIds[i], flags, transparent, deferred);
863
- }
864
- }
865
-
866
- _subPortionSetFlags(subPortionId, flags, transparent, deferred = false) {
867
- if (!this._finalized) {
868
- throw "Not finalized";
869
- }
870
-
871
- const visible = !!(flags & ENTITY_FLAGS.VISIBLE);
872
- const xrayed = !!(flags & ENTITY_FLAGS.XRAYED);
873
- const highlighted = !!(flags & ENTITY_FLAGS.HIGHLIGHTED);
874
- const selected = !!(flags & ENTITY_FLAGS.SELECTED);
875
- const edges = !!(flags & ENTITY_FLAGS.EDGES);
876
- const pickable = !!(flags & ENTITY_FLAGS.PICKABLE);
877
- const culled = !!(flags & ENTITY_FLAGS.CULLED);
878
-
879
- // Color
880
-
881
- let f0;
882
- if (!visible || culled || xrayed
883
- || (highlighted && !this.model.scene.highlightMaterial.glowThrough)
884
- || (selected && !this.model.scene.selectedMaterial.glowThrough)) {
885
- f0 = RENDER_PASSES.NOT_RENDERED;
886
- } else {
887
- if (transparent) {
888
- f0 = RENDER_PASSES.COLOR_TRANSPARENT;
889
- } else {
890
- f0 = RENDER_PASSES.COLOR_OPAQUE;
891
- }
892
- }
893
-
894
- // Silhouette
895
-
896
- let f1;
897
- if (!visible || culled) {
898
- f1 = RENDER_PASSES.NOT_RENDERED;
899
- } else if (selected) {
900
- f1 = RENDER_PASSES.SILHOUETTE_SELECTED;
901
- } else if (highlighted) {
902
- f1 = RENDER_PASSES.SILHOUETTE_HIGHLIGHTED;
903
- } else if (xrayed) {
904
- f1 = RENDER_PASSES.SILHOUETTE_XRAYED;
905
- } else {
906
- f1 = RENDER_PASSES.NOT_RENDERED;
907
- }
908
-
909
- // Edges
910
-
911
- let f2 = 0;
912
- if (!visible || culled) {
913
- f2 = RENDER_PASSES.NOT_RENDERED;
914
- } else if (selected) {
915
- f2 = RENDER_PASSES.EDGES_SELECTED;
916
- } else if (highlighted) {
917
- f2 = RENDER_PASSES.EDGES_HIGHLIGHTED;
918
- } else if (xrayed) {
919
- f2 = RENDER_PASSES.EDGES_XRAYED;
920
- } else if (edges) {
921
- if (transparent) {
922
- f2 = RENDER_PASSES.EDGES_COLOR_TRANSPARENT;
923
- } else {
924
- f2 = RENDER_PASSES.EDGES_COLOR_OPAQUE;
925
- }
926
- } else {
927
- f2 = RENDER_PASSES.NOT_RENDERED;
928
- }
929
-
930
- // Pick
931
-
932
- let f3 = (visible && (!culled) && pickable) ? RENDER_PASSES.PICK : RENDER_PASSES.NOT_RENDERED;
933
- const textureState = this._dtxState;
934
- const gl = this.model.scene.canvas.gl;
935
- tempUint8Array4 [0] = f0;
936
- tempUint8Array4 [1] = f1;
937
- tempUint8Array4 [2] = f2;
938
- tempUint8Array4 [3] = f3;
939
- // object flags
940
- textureState.texturePerObjectColorsAndFlags._textureData.set(tempUint8Array4, subPortionId * 32 + 8);
941
- if (this._deferredSetFlagsActive || deferred) {
942
- this._deferredSetFlagsDirty = true;
943
- return;
944
- }
945
- if (++this._numUpdatesInFrame >= MAX_OBJECT_UPDATES_IN_FRAME_WITHOUT_BATCHED_UPDATE) {
946
- this._beginDeferredFlags(); // Subsequent flags updates now deferred
947
- }
948
- gl.bindTexture(gl.TEXTURE_2D, textureState.texturePerObjectColorsAndFlags._texture);
949
- gl.texSubImage2D(
950
- gl.TEXTURE_2D,
951
- 0, // level
952
- (subPortionId % 512) * 8 + 2, // xoffset
953
- Math.floor(subPortionId / 512), // yoffset
954
- 1, // width
955
- 1, //height
956
- gl.RGBA_INTEGER,
957
- gl.UNSIGNED_BYTE,
958
- tempUint8Array4
959
- );
960
- // gl.bindTexture (gl.TEXTURE_2D, null);
961
- }
962
-
963
- _setDeferredFlags() {
964
- }
965
-
966
- _setFlags2(portionId, flags, deferred = false) {
967
- const subPortionIds = this._portionToSubPortionsMap[portionId];
968
- for (let i = 0, len = subPortionIds.length; i < len; i++) {
969
- this._subPortionSetFlags2(subPortionIds[i], flags, deferred);
970
- }
971
- }
972
-
973
- _subPortionSetFlags2(subPortionId, flags, deferred = false) {
974
- if (!this._finalized) {
975
- throw "Not finalized";
976
- }
977
- const clippable = !!(flags & ENTITY_FLAGS.CLIPPABLE) ? 255 : 0;
978
- const textureState = this._dtxState;
979
- const gl = this.model.scene.canvas.gl;
980
- tempUint8Array4 [0] = clippable;
981
- tempUint8Array4 [1] = 0;
982
- tempUint8Array4 [2] = 1;
983
- tempUint8Array4 [3] = 2;
984
- // object flags2
985
- textureState.texturePerObjectColorsAndFlags._textureData.set(tempUint8Array4, subPortionId * 32 + 12);
986
- if (this._deferredSetFlagsActive || deferred) {
987
- // console.log("_subPortionSetFlags2 set flags defer");
988
- this._deferredSetFlagsDirty = true;
989
- return;
990
- }
991
- if (++this._numUpdatesInFrame >= MAX_OBJECT_UPDATES_IN_FRAME_WITHOUT_BATCHED_UPDATE) {
992
- this._beginDeferredFlags(); // Subsequent flags updates now deferred
993
- }
994
- gl.bindTexture(gl.TEXTURE_2D, textureState.texturePerObjectColorsAndFlags._texture);
995
- gl.texSubImage2D(
996
- gl.TEXTURE_2D,
997
- 0, // level
998
- (subPortionId % 512) * 8 + 3, // xoffset
999
- Math.floor(subPortionId / 512), // yoffset
1000
- 1, // width
1001
- 1, //height
1002
- gl.RGBA_INTEGER,
1003
- gl.UNSIGNED_BYTE,
1004
- tempUint8Array4
1005
- );
1006
- // gl.bindTexture (gl.TEXTURE_2D, null);
1007
- }
1008
-
1009
- _setDeferredFlags2() {
1010
- }
1011
-
1012
- setOffset(portionId, offset) {
1013
- const subPortionIds = this._portionToSubPortionsMap[portionId];
1014
- for (let i = 0, len = subPortionIds.length; i < len; i++) {
1015
- this._subPortionSetOffset(subPortionIds[i], offset);
1016
- }
1017
- }
1018
-
1019
- _subPortionSetOffset(subPortionId, offset) {
1020
- if (!this._finalized) {
1021
- throw "Not finalized";
1022
- }
1023
- // if (!this.model.scene.entityOffsetsEnabled) {
1024
- // this.model.error("Entity#offset not enabled for this Viewer"); // See Viewer entityOffsetsEnabled
1025
- // return;
1026
- // }
1027
- const textureState = this._dtxState;
1028
- const gl = this.model.scene.canvas.gl;
1029
- tempFloat32Array3 [0] = offset[0];
1030
- tempFloat32Array3 [1] = offset[1];
1031
- tempFloat32Array3 [2] = offset[2];
1032
- // object offset
1033
- textureState.texturePerObjectOffsets._textureData.set(tempFloat32Array3, subPortionId * 3);
1034
- if (this._deferredSetFlagsActive) {
1035
- this._deferredSetFlagsDirty = true;
1036
- return;
1037
- }
1038
- if (++this._numUpdatesInFrame >= MAX_OBJECT_UPDATES_IN_FRAME_WITHOUT_BATCHED_UPDATE) {
1039
- this._beginDeferredFlags(); // Subsequent flags updates now deferred
1040
- }
1041
- gl.bindTexture(gl.TEXTURE_2D, textureState.texturePerObjectOffsets._texture);
1042
- gl.texSubImage2D(
1043
- gl.TEXTURE_2D,
1044
- 0, // level
1045
- 0, // x offset
1046
- subPortionId, // yoffset
1047
- 1, // width
1048
- 1, // height
1049
- gl.RGB,
1050
- gl.FLOAT,
1051
- tempFloat32Array3
1052
- );
1053
- // gl.bindTexture (gl.TEXTURE_2D, null);
1054
- }
1055
-
1056
- setMatrix(portionId, matrix) {
1057
- const subPortionIds = this._portionToSubPortionsMap[portionId];
1058
- for (let i = 0, len = subPortionIds.length; i < len; i++) {
1059
- this._subPortionSetMatrix(subPortionIds[i], matrix);
1060
- }
1061
- }
1062
-
1063
- _subPortionSetMatrix(subPortionId, matrix) {
1064
- if (!this._finalized) {
1065
- throw "Not finalized";
1066
- }
1067
- // if (!this.model.scene.entityMatrixsEnabled) {
1068
- // this.model.error("Entity#matrix not enabled for this Viewer"); // See Viewer entityMatrixsEnabled
1069
- // return;
1070
- // }
1071
- const textureState = this._dtxState;
1072
- const gl = this.model.scene.canvas.gl;
1073
- tempMat4a.set(matrix);
1074
- textureState.texturePerObjectInstanceMatrices._textureData.set(tempMat4a, subPortionId * 16);
1075
- if (this._deferredSetFlagsActive) {
1076
- this._deferredSetFlagsDirty = true;
1077
- return;
1078
- }
1079
- if (++this._numUpdatesInFrame >= MAX_OBJECT_UPDATES_IN_FRAME_WITHOUT_BATCHED_UPDATE) {
1080
- this._beginDeferredFlags(); // Subsequent flags updates now deferred
1081
- }
1082
- gl.bindTexture(gl.TEXTURE_2D, textureState.texturePerObjectInstanceMatrices._texture);
1083
- gl.texSubImage2D(
1084
- gl.TEXTURE_2D,
1085
- 0, // level
1086
- (subPortionId % 512) * 4, // xoffset
1087
- Math.floor(subPortionId / 512), // yoffset
1088
- // 1,
1089
- 4, // width
1090
- 1, // height
1091
- gl.RGBA,
1092
- gl.FLOAT,
1093
- tempMat4a
1094
- );
1095
- // gl.bindTexture (gl.TEXTURE_2D, null);
1096
- }
1097
-
1098
- getEachVertex(portionId, callback) {
1099
- if (!this.model.scene.readableGeometryEnabled) {
1100
- return;
1101
- }
1102
- const state = this._state;
1103
- const subPortionIds = this._portionToSubPortionsMap[portionId];
1104
- if (!subPortionIds) {
1105
- this.model.error("portion not found: " + portionId);
1106
- return;
1107
- }
1108
- for (let i = 0, len = subPortionIds.length; i < len; i++) {
1109
- const subPortionId = subPortionIds[i];
1110
- const subPortionReadableGeometry = this._subPortionReadableGeometries[subPortionId];
1111
- const positions = subPortionReadableGeometry.positionsCompressed;
1112
- const positionsDecodeMatrix = subPortionReadableGeometry.positionsDecodeMatrix;
1113
- const meshMatrix = subPortionReadableGeometry.meshMatrix;
1114
- const origin = state.origin;
1115
- const offsetX = origin[0] ;
1116
- const offsetY = origin[1] ;
1117
- const offsetZ = origin[2] ;
1118
- const worldPos = tempVec4a;
1119
- for (let i = 0, len = positions.length; i < len; i += 3) {
1120
- worldPos[0] = positions[i];
1121
- worldPos[1] = positions[i + 1];
1122
- worldPos[2] = positions[i + 2];
1123
- worldPos[3] = 1.0;
1124
- math.decompressPosition(worldPos, positionsDecodeMatrix);
1125
- math.mulMat4v4(this.model.worldMatrix, worldPos, worldPos);
1126
- worldPos[0] += offsetX;
1127
- worldPos[1] += offsetY;
1128
- worldPos[2] += offsetZ;
1129
- callback(worldPos);
1130
- }
1131
- }
1132
- }
1133
-
1134
- getEachIndex(portionId, callback) {
1135
- if (!this.model.scene.readableGeometryEnabled) {
1136
- return;
1137
- }
1138
- const subPortionIds = this._portionToSubPortionsMap[portionId];
1139
- if (!subPortionIds) {
1140
- this.model.error("portion not found: " + portionId);
1141
- return;
1142
- }
1143
- for (let i = 0, len = subPortionIds.length; i < len; i++) {
1144
- const subPortionId = subPortionIds[i];
1145
- const subPortionReadableGeometry = this._subPortionReadableGeometries[subPortionId];
1146
- const indices = subPortionReadableGeometry.indices;
1147
- for (let i = 0, len = indices.length; i < len; i++) {
1148
- callback(indices[i]);
1149
- }
1150
- }
1151
- }
1152
-
1153
-
1154
- // ---------------------- COLOR RENDERING -----------------------------------
1155
-
1156
- drawColorOpaque(renderFlags, frameCtx) {
1157
- if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numTransparentLayerPortions === this._numPortions || this._numXRayedLayerPortions === this._numPortions) {
1158
- return;
1159
- }
1160
- this._updateBackfaceCull(renderFlags, frameCtx);
1161
- if (frameCtx.withSAO && this.model.saoEnabled) {
1162
- if (this._renderers.colorRendererWithSAO) {
1163
- this._renderers.colorRendererWithSAO.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
1164
- }
1165
- } else {
1166
- if (this._renderers.colorRenderer) {
1167
- this._renderers.colorRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
1168
- }
1169
- }
1170
- }
1171
-
1172
- _updateBackfaceCull(renderFlags, frameCtx) {
1173
- const backfaces = true; // See XCD-230
1174
- if (frameCtx.backfaces !== backfaces) {
1175
- const gl = frameCtx.gl;
1176
- if (backfaces) {
1177
- gl.disable(gl.CULL_FACE);
1178
- } else {
1179
- gl.enable(gl.CULL_FACE);
1180
- }
1181
- frameCtx.backfaces = backfaces;
1182
- }
1183
- }
1184
-
1185
- drawColorTransparent(renderFlags, frameCtx) {
1186
- if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numTransparentLayerPortions === 0 || this._numXRayedLayerPortions === this._numPortions) {
1187
- return;
1188
- }
1189
- this._updateBackfaceCull(renderFlags, frameCtx);
1190
- if (this._renderers.colorRenderer) {
1191
- this._renderers.colorRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_TRANSPARENT);
1192
- }
1193
- }
1194
-
1195
- // ---------------------- RENDERING SAO POST EFFECT TARGETS --------------
1196
-
1197
- drawDepth(renderFlags, frameCtx) {
1198
- if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numTransparentLayerPortions === this._numPortions || this._numXRayedLayerPortions === this._numPortions) {
1199
- return;
1200
- }
1201
- this._updateBackfaceCull(renderFlags, frameCtx);
1202
- if (this._renderers.depthRenderer) {
1203
- this._renderers.depthRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE); // Assume whatever post-effect uses depth (eg SAO) does not apply to transparent objects
1204
- }
1205
- }
1206
-
1207
- drawNormals(renderFlags, frameCtx) {
1208
- if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numTransparentLayerPortions === this._numPortions || this._numXRayedLayerPortions === this._numPortions) {
1209
- return;
1210
- }
1211
- this._updateBackfaceCull(renderFlags, frameCtx);
1212
- if (this._renderers.normalsRenderer) {
1213
- this._renderers.normalsRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE); // Assume whatever post-effect uses normals (eg SAO) does not apply to transparent objects
1214
- }
1215
- }
1216
-
1217
- // ---------------------- SILHOUETTE RENDERING -----------------------------------
1218
-
1219
- drawSilhouetteXRayed(renderFlags, frameCtx) {
1220
- if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numXRayedLayerPortions === 0) {
1221
- return;
1222
- }
1223
- this._updateBackfaceCull(renderFlags, frameCtx);
1224
- if (this._renderers.silhouetteRenderer) {
1225
- this._renderers.silhouetteRenderer.drawLayer(frameCtx, this, RENDER_PASSES.SILHOUETTE_XRAYED);
1226
- }
1227
- }
1228
-
1229
- drawSilhouetteHighlighted(renderFlags, frameCtx) {
1230
- if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numHighlightedLayerPortions === 0) {
1231
- return;
1232
- }
1233
- this._updateBackfaceCull(renderFlags, frameCtx);
1234
- if (this._renderers.silhouetteRenderer) {
1235
- this._renderers.silhouetteRenderer.drawLayer(frameCtx, this, RENDER_PASSES.SILHOUETTE_HIGHLIGHTED);
1236
- }
1237
- }
1238
-
1239
- drawSilhouetteSelected(renderFlags, frameCtx) {
1240
- if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numSelectedLayerPortions === 0) {
1241
- return;
1242
- }
1243
- this._updateBackfaceCull(renderFlags, frameCtx);
1244
- if (this._renderers.silhouetteRenderer) {
1245
- this._renderers.silhouetteRenderer.drawLayer(frameCtx, this, RENDER_PASSES.SILHOUETTE_SELECTED);
1246
- }
1247
- }
1248
-
1249
- // ---------------------- EDGES RENDERING -----------------------------------
1250
-
1251
- drawEdgesColorOpaque(renderFlags, frameCtx) {
1252
- if (this.model.scene.logarithmicDepthBufferEnabled) {
1253
- if (!this.model.scene._loggedWarning) {
1254
- console.log("Edge enhancement for SceneModel data texture layers currently disabled with logarithmic depth buffer");
1255
- this.model.scene._loggedWarning = true;
1256
- }
1257
- return;
1258
- }
1259
- if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numEdgesLayerPortions === 0) {
1260
- return;
1261
- }
1262
- if (this._renderers.edgesColorRenderer) {
1263
- this._renderers.edgesColorRenderer.drawLayer(frameCtx, this, RENDER_PASSES.EDGES_COLOR_OPAQUE);
1264
- }
1265
- }
1266
-
1267
- drawEdgesColorTransparent(renderFlags, frameCtx) {
1268
- if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numEdgesLayerPortions === 0 || this._numTransparentLayerPortions === 0) {
1269
- return;
1270
- }
1271
- if (this._renderers.edgesColorRenderer) {
1272
- this._renderers.edgesColorRenderer.drawLayer(frameCtx, this, RENDER_PASSES.EDGES_COLOR_TRANSPARENT);
1273
- }
1274
- }
1275
-
1276
- drawEdgesHighlighted(renderFlags, frameCtx) {
1277
- if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numHighlightedLayerPortions === 0) {
1278
- return;
1279
- }
1280
- if (this._renderers.edgesRenderer) {
1281
- this._renderers.edgesRenderer.drawLayer(frameCtx, this, RENDER_PASSES.EDGES_HIGHLIGHTED);
1282
- }
1283
- }
1284
-
1285
- drawEdgesSelected(renderFlags, frameCtx) {
1286
- if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numSelectedLayerPortions === 0) {
1287
- return;
1288
- }
1289
- if (this._renderers.edgesRenderer) {
1290
- this._renderers.edgesRenderer.drawLayer(frameCtx, this, RENDER_PASSES.EDGES_SELECTED);
1291
- }
1292
- }
1293
-
1294
- drawEdgesXRayed(renderFlags, frameCtx) {
1295
- if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0 || this._numXRayedLayerPortions === 0) {
1296
- return;
1297
- }
1298
- if (this._renderers.edgesRenderer) {
1299
- this._renderers.edgesRenderer.drawLayer(frameCtx, this, RENDER_PASSES.EDGES_XRAYED);
1300
- }
1301
- }
1302
-
1303
- // ---------------------- OCCLUSION CULL RENDERING -----------------------------------
1304
-
1305
- drawOcclusion(renderFlags, frameCtx) {
1306
- if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0) {
1307
- return;
1308
- }
1309
- this._updateBackfaceCull(renderFlags, frameCtx);
1310
- if (this._renderers.occlusionRenderer) {
1311
- this._renderers.occlusionRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
1312
- }
1313
- }
1314
-
1315
- // ---------------------- SHADOW BUFFER RENDERING -----------------------------------
1316
-
1317
- drawShadow(renderFlags, frameCtx) {
1318
- if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0) {
1319
- return;
1320
- }
1321
- this._updateBackfaceCull(renderFlags, frameCtx);
1322
- if (this._renderers.shadowRenderer) {
1323
- this._renderers.shadowRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
1324
- }
1325
- }
1326
-
1327
- //---- PICKING ----------------------------------------------------------------------------------------------------
1328
-
1329
- setPickMatrices(pickViewMatrix, pickProjMatrix) {
1330
- // if (this._numVisibleLayerPortions === 0) {
1331
- // return;
1332
- // }
1333
- // this._dtxState.texturePickCameraMatrices.updateViewMatrix(pickViewMatrix, pickProjMatrix);
1334
- }
1335
-
1336
- drawPickMesh(renderFlags, frameCtx) {
1337
- if (this._numVisibleLayerPortions === 0) {
1338
- return;
1339
- }
1340
- this._updateBackfaceCull(renderFlags, frameCtx);
1341
- if (this._renderers.pickMeshRenderer) {
1342
- this._renderers.pickMeshRenderer.drawLayer(frameCtx, this, RENDER_PASSES.PICK);
1343
- }
1344
- }
1345
-
1346
- drawPickDepths(renderFlags, frameCtx) {
1347
- if (this._numVisibleLayerPortions === 0) {
1348
- return;
1349
- }
1350
- this._updateBackfaceCull(renderFlags, frameCtx);
1351
- if (this._renderers.pickDepthRenderer) {
1352
- this._renderers.pickDepthRenderer.drawLayer(frameCtx, this, RENDER_PASSES.PICK);
1353
- }
1354
- }
1355
-
1356
- drawSnapInit(renderFlags, frameCtx) {
1357
- if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0) {
1358
- return;
1359
- }
1360
- this._updateBackfaceCull(renderFlags, frameCtx);
1361
- if (this._renderers.snapInitRenderer) {
1362
- this._renderers.snapInitRenderer.drawLayer(frameCtx, this, RENDER_PASSES.PICK);
1363
- }
1364
- }
1365
-
1366
- drawSnap(renderFlags, frameCtx) {
1367
- if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0) {
1368
- return;
1369
- }
1370
- this._updateBackfaceCull(renderFlags, frameCtx);
1371
- if (this._renderers.snapRenderer) {
1372
- this._renderers.snapRenderer.drawLayer(frameCtx, this, RENDER_PASSES.PICK);
1373
- }
1374
- }
1375
-
1376
- drawPickNormals(renderFlags, frameCtx) {
1377
- if (this._numCulledLayerPortions === this._numPortions || this._numVisibleLayerPortions === 0) {
1378
- return;
1379
- }
1380
- this._updateBackfaceCull(renderFlags, frameCtx);
1381
- if (this._renderers.pickNormalsRenderer) {
1382
- this._renderers.pickNormalsRenderer.drawLayer(frameCtx, this, RENDER_PASSES.PICK);
1383
- }
1384
- }
1385
-
1386
- destroy() {
1387
- if (this._destroyed) {
1388
- return;
1389
- }
1390
- const state = this._state;
1391
- if (state.metallicRoughnessBuf) {
1392
- state.metallicRoughnessBuf.destroy();
1393
- state.metallicRoughnessBuf = null;
1394
- }
1395
- this.model.scene.off(this._onSceneRendering);
1396
- state.destroy();
1397
- this._destroyed = true;
1398
- }
1399
- }