@xeokit/xeokit-sdk 2.6.85-renderers-refactor-v2 → 2.6.86

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 +44618 -13007
  2. package/dist/xeokit-sdk.es.js +44617 -13008
  3. package/dist/xeokit-sdk.es5.js +3488 -1387
  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/lib/html/MenuEvent.js +2 -2
  9. package/src/viewer/Viewer.js +103 -55
  10. package/src/viewer/scene/canvas/Canvas.js +43 -3
  11. package/src/viewer/scene/geometry/ReadableGeometry.js +25 -0
  12. package/src/viewer/scene/lights/CubeTexture.js +13 -0
  13. package/src/viewer/scene/lights/DirLight.js +1 -2
  14. package/src/viewer/scene/lights/PointLight.js +1 -2
  15. package/src/viewer/scene/materials/Texture.js +9 -0
  16. package/src/viewer/scene/math/rtcCoords.js +38 -1
  17. package/src/viewer/scene/mesh/Mesh.js +212 -454
  18. package/src/viewer/scene/mesh/draw/DrawRenderer.js +998 -0
  19. package/src/viewer/scene/mesh/draw/DrawShaderSource.js +1504 -305
  20. package/src/viewer/scene/mesh/emphasis/EmphasisEdgesRenderer.js +259 -0
  21. package/src/viewer/scene/mesh/emphasis/EmphasisEdgesShaderSource.js +160 -0
  22. package/src/viewer/scene/mesh/emphasis/EmphasisFillRenderer.js +286 -0
  23. package/src/viewer/scene/mesh/emphasis/EmphasisFillShaderSource.js +263 -0
  24. package/src/viewer/scene/mesh/occlusion/OcclusionRenderer.js +221 -0
  25. package/src/viewer/scene/mesh/occlusion/OcclusionShaderSource.js +158 -9
  26. package/src/viewer/scene/mesh/pick/PickMeshRenderer.js +223 -0
  27. package/src/viewer/scene/mesh/pick/PickMeshShaderSource.js +151 -21
  28. package/src/viewer/scene/mesh/pick/PickTriangleRenderer.js +200 -0
  29. package/src/viewer/scene/mesh/pick/PickTriangleShaderSource.js +124 -12
  30. package/src/viewer/scene/mesh/shadow/ShadowRenderer.js +214 -0
  31. package/src/viewer/scene/mesh/shadow/ShadowShaderSource.js +97 -22
  32. package/src/viewer/scene/model/RENDER_PASSES.js +34 -0
  33. package/src/viewer/scene/model/SceneModel.js +861 -245
  34. package/src/viewer/scene/model/SceneModelEntity.js +4 -4
  35. package/src/viewer/scene/model/SceneModelMesh.js +3 -3
  36. package/src/viewer/scene/model/dtx/BindableDataTexture.js +31 -0
  37. package/src/viewer/scene/model/dtx/lines/DTXLinesBuffer.js +27 -0
  38. package/src/viewer/scene/model/dtx/lines/DTXLinesLayer.js +897 -0
  39. package/src/viewer/scene/model/dtx/lines/DTXLinesState.js +46 -0
  40. package/src/viewer/scene/model/dtx/lines/DTXLinesTextureFactory.js +411 -0
  41. package/src/viewer/scene/model/dtx/lines/dataTextureRamStats.js +49 -0
  42. package/src/viewer/scene/model/dtx/lines/rebucketPositions.js +208 -0
  43. package/src/viewer/scene/model/dtx/lines/renderers/DTXLinesColorRenderer.js +389 -0
  44. package/src/viewer/scene/model/dtx/lines/renderers/DTXLinesRenderers.js +65 -0
  45. package/src/viewer/scene/model/dtx/triangles/DTXTrianglesLayer.js +1399 -0
  46. package/src/viewer/scene/model/dtx/triangles/lib/DTXTrianglesBuffer.js +46 -0
  47. package/src/viewer/scene/model/dtx/triangles/lib/DTXTrianglesState.js +250 -0
  48. package/src/viewer/scene/model/dtx/triangles/lib/DTXTrianglesTextureFactory.js +518 -0
  49. package/src/viewer/scene/model/dtx/triangles/lib/dataTextureRamStats.js +54 -0
  50. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesColorRenderer.js +639 -0
  51. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesDepthRenderer.js +464 -0
  52. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesEdgesColorRenderer.js +423 -0
  53. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesEdgesRenderer.js +431 -0
  54. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesNormalsRenderer.js +345 -0
  55. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesOcclusionRenderer.js +436 -0
  56. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesPickDepthRenderer.js +466 -0
  57. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesPickMeshRenderer.js +437 -0
  58. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesPickNormalsFlatRenderer.js +460 -0
  59. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesPickNormalsRenderer.js +437 -0
  60. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesRenderers.js +307 -0
  61. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesSilhouetteRenderer.js +472 -0
  62. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesSnapInitRenderer.js +474 -0
  63. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesSnapRenderer.js +435 -0
  64. package/src/viewer/scene/model/vbo/ScratchMemory.js +63 -0
  65. package/src/viewer/scene/model/vbo/VBORenderer.js +664 -0
  66. package/src/viewer/scene/model/vbo/batching/lines/VBOBatchingLinesLayer.js +704 -0
  67. package/src/viewer/scene/model/vbo/batching/lines/lib/VBOBatchingLinesBuffer.js +19 -0
  68. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLineSnapInitRenderer.js +318 -0
  69. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesColorRenderer.js +114 -0
  70. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesRenderers.js +99 -0
  71. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesSilhouetteRenderer.js +124 -0
  72. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesSnapInitRenderer.js +313 -0
  73. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesSnapRenderer.js +311 -0
  74. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOSceneModelLineBatchingRenderer.js +24 -0
  75. package/src/viewer/scene/model/vbo/batching/points/VBOBatchingPointsLayer.js +688 -0
  76. package/src/viewer/scene/model/vbo/batching/points/VBOBatchingPointsRenderer.js +24 -0
  77. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsColorRenderer.js +168 -0
  78. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsOcclusionRenderer.js +136 -0
  79. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsPickDepthRenderer.js +156 -0
  80. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsPickMeshRenderer.js +148 -0
  81. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsRenderers.js +144 -0
  82. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsShadowRenderer.js +107 -0
  83. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsSilhouetteRenderer.js +146 -0
  84. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsSnapInitRenderer.js +315 -0
  85. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsSnapRenderer.js +305 -0
  86. package/src/viewer/scene/model/vbo/batching/triangles/VBOBatchingTrianglesBuffer.js +24 -0
  87. package/src/viewer/scene/model/vbo/batching/triangles/VBOBatchingTrianglesLayer.js +1346 -0
  88. package/src/viewer/scene/model/vbo/batching/triangles/renderers/EdgesColorRenderer.js +131 -0
  89. package/src/viewer/scene/model/vbo/batching/triangles/renderers/EdgesEmphasisRenderer.js +135 -0
  90. package/src/viewer/scene/model/vbo/batching/triangles/renderers/EdgesRenderer.js +12 -0
  91. package/src/viewer/scene/model/vbo/batching/triangles/renderers/Renderers.js +403 -0
  92. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesBatchingRenderer.js +35 -0
  93. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesColorRenderer.js +252 -0
  94. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesColorTextureRenderer.js +294 -0
  95. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesDepthRenderer.js +115 -0
  96. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesFlatColorRenderer.js +246 -0
  97. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesNormalsRenderer.js +139 -0
  98. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesOcclusionRenderer.js +125 -0
  99. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPBRRenderer.js +561 -0
  100. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPickDepthRenderer.js +144 -0
  101. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPickMeshRenderer.js +130 -0
  102. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPickNormalsFlatRenderer.js +121 -0
  103. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPickNormalsRenderer.js +131 -0
  104. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesShadowRenderer.js +107 -0
  105. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesSilhouetteRenderer.js +144 -0
  106. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesSnapInitRenderer.js +313 -0
  107. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesSnapRenderer.js +312 -0
  108. package/src/viewer/scene/model/vbo/float16.js +760 -0
  109. package/src/viewer/scene/model/vbo/instancing/lines/VBOInstancingLinesLayer.js +711 -0
  110. package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesColorRenderer.js +148 -0
  111. package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesRenderer.js +26 -0
  112. package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesRenderers.js +139 -0
  113. package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesSilhouetteRenderer.js +127 -0
  114. package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesSnapInitRenderer.js +308 -0
  115. package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesSnapRenderer.js +299 -0
  116. package/src/viewer/scene/model/vbo/instancing/points/VBOInstancingPointsLayer.js +733 -0
  117. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsColorRenderer.js +174 -0
  118. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsDepthRenderer.js +156 -0
  119. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsOcclusionRenderer.js +149 -0
  120. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsPickDepthRenderer.js +170 -0
  121. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsPickMeshRenderer.js +152 -0
  122. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsRenderer.js +26 -0
  123. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsRenderers.js +174 -0
  124. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsShadowRenderer.js +119 -0
  125. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsSilhouetteRenderer.js +154 -0
  126. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsSnapInitRenderer.js +307 -0
  127. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsSnapRenderer.js +293 -0
  128. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingTrianglesRenderer.js +150 -0
  129. package/src/viewer/scene/model/vbo/instancing/triangles/VBOInstancingTrianglesLayer.js +1289 -0
  130. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/EdgesColorRenderer.js +135 -0
  131. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/EdgesEmphasisRenderer.js +137 -0
  132. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/EdgesRenderer.js +12 -0
  133. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/Renderers.js +403 -0
  134. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesColorRenderer.js +267 -0
  135. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesColorTextureRenderer.js +299 -0
  136. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesDepthRenderer.js +126 -0
  137. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesFlatColorRenderer.js +255 -0
  138. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesFlatNormalsRenderer.js +130 -0
  139. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesInstancingRenderer.js +32 -0
  140. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesNormalsRenderer.js +138 -0
  141. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesOcclusionRenderer.js +128 -0
  142. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPBRRenderer.js +561 -0
  143. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPickDepthRenderer.js +149 -0
  144. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPickMeshRenderer.js +136 -0
  145. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPickNormalsFlatRenderer.js +130 -0
  146. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPickNormalsRenderer.js +145 -0
  147. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesShadowRenderer.js +113 -0
  148. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesSilhouetteRenderer.js +148 -0
  149. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesSnapInitRenderer.js +319 -0
  150. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesSnapRenderer.js +310 -0
  151. package/src/viewer/scene/scene/Scene.js +38 -21
  152. package/src/viewer/scene/webgl/ArrayBuf.js +20 -5
  153. package/src/viewer/scene/webgl/Attribute.js +23 -0
  154. package/src/viewer/scene/webgl/FrameContext.js +86 -14
  155. package/src/viewer/scene/webgl/Program.js +181 -0
  156. package/src/viewer/scene/webgl/RenderBuffer.js +262 -62
  157. package/src/viewer/scene/webgl/RenderBufferManager.js +34 -0
  158. package/src/viewer/scene/webgl/Renderer.js +843 -880
  159. package/src/viewer/scene/webgl/Sampler.js +18 -0
  160. package/src/viewer/scene/webgl/Shader.js +49 -0
  161. package/src/viewer/scene/webgl/occlusion/OcclusionLayer.js +132 -60
  162. package/src/viewer/scene/webgl/occlusion/OcclusionTester.js +328 -167
  163. package/src/viewer/scene/webgl/sao/SAODepthLimitedBlurRenderer.js +324 -0
  164. package/src/viewer/scene/webgl/sao/SAOOcclusionRenderer.js +384 -0
  165. package/src/viewer/utils/os.js +9 -0
  166. package/src/viewer/scene/mesh/draw/LambertShaderSource.js +0 -35
  167. package/src/viewer/scene/mesh/emphasis/EmphasisShaderSource.js +0 -34
  168. package/src/viewer/scene/model/layer/DTXLayer.js +0 -940
  169. package/src/viewer/scene/model/layer/Layer.js +0 -786
  170. package/src/viewer/scene/model/layer/VBOLayer.js +0 -1019
  171. package/src/viewer/scene/model/layer/programs/ColorProgram.js +0 -35
  172. package/src/viewer/scene/model/layer/programs/ColorTextureProgram.js +0 -46
  173. package/src/viewer/scene/model/layer/programs/DepthProgram.js +0 -11
  174. package/src/viewer/scene/model/layer/programs/EdgesProgram.js +0 -12
  175. package/src/viewer/scene/model/layer/programs/FlatColorProgram.js +0 -24
  176. package/src/viewer/scene/model/layer/programs/OcclusionProgram.js +0 -12
  177. package/src/viewer/scene/model/layer/programs/PBRProgram.js +0 -180
  178. package/src/viewer/scene/model/layer/programs/PickDepthProgram.js +0 -30
  179. package/src/viewer/scene/model/layer/programs/PickMeshProgram.js +0 -12
  180. package/src/viewer/scene/model/layer/programs/PickNormalsProgram.js +0 -18
  181. package/src/viewer/scene/model/layer/programs/ShadowProgram.js +0 -23
  182. package/src/viewer/scene/model/layer/programs/SilhouetteProgram.js +0 -15
  183. package/src/viewer/scene/model/layer/programs/SnapProgram.js +0 -28
  184. package/src/viewer/scene/webgl/WebGLRenderer.js +0 -612
@@ -0,0 +1,664 @@
1
+ import {createRTCViewMat, getPlaneRTCPos} from "../../math/rtcCoords.js";
2
+ import {math} from "../../math/math.js";
3
+ import {Program} from "../../webgl/Program.js";
4
+ import {stats} from "../../stats.js"
5
+ import {WEBGL_INFO} from "../../webglInfo.js";
6
+ import {RENDER_PASSES} from "./../RENDER_PASSES.js";
7
+
8
+ const defaultColor = new Float32Array([1, 1, 1, 1]);
9
+ const edgesDefaultColor = new Float32Array([0, 0, 0, 1]);
10
+
11
+ const tempVec4 = math.vec4();
12
+ const tempVec3a = math.vec3();
13
+ const tempVec3c = math.vec3();
14
+ const tempMat4a = math.mat4();
15
+
16
+ /**
17
+ * @private
18
+ */
19
+ export class VBORenderer {
20
+ constructor(scene, withSAO = false, {instancing = false, edges = false, useAlphaCutoff = false} = {}) {
21
+ this._scene = scene;
22
+ this._withSAO = withSAO;
23
+ this._instancing = instancing;
24
+ this._edges = edges;
25
+ this._useAlphaCutoff = useAlphaCutoff;
26
+ this._hash = this._getHash();
27
+
28
+ /**
29
+ * Matrices Uniform Block Buffer
30
+ *
31
+ * In shaders, matrices in the Matrices Uniform Block MUST be set in this order:
32
+ * - worldMatrix
33
+ * - viewMatrix
34
+ * - projMatrix
35
+ * - positionsDecodeMatrix
36
+ * - worldNormalMatrix
37
+ * - viewNormalMatrix
38
+ */
39
+ this._matricesUniformBlockBufferBindingPoint = 0;
40
+
41
+ this._matricesUniformBlockBuffer = this._scene.canvas.gl.createBuffer();
42
+ this._matricesUniformBlockBufferData = new Float32Array(4 * 4 * 6); // there is 6 mat4
43
+
44
+ /**
45
+ * A Vertex Array Object by Layer
46
+ */
47
+ this._vaoCache = new WeakMap();
48
+
49
+ this._allocate();
50
+ }
51
+
52
+ /**
53
+ * Should be overrided by subclasses if it does not only "depend" on section planes state.
54
+ * @returns { string }
55
+ */
56
+ _getHash() {
57
+ return this._scene._sectionPlanesState.getHash();
58
+ }
59
+
60
+ _buildShader() {
61
+ return {
62
+ vertex: this._buildVertexShader(),
63
+ fragment: this._buildFragmentShader()
64
+ };
65
+ }
66
+
67
+ _buildVertexShader() {
68
+ return [""];
69
+ }
70
+
71
+ _buildFragmentShader() {
72
+ return [""];
73
+ }
74
+
75
+ _addMatricesUniformBlockLines(src, normals = false) {
76
+ src.push("uniform Matrices {");
77
+ src.push(" mat4 worldMatrix;");
78
+ src.push(" mat4 viewMatrix;");
79
+ src.push(" mat4 projMatrix;");
80
+ src.push(" mat4 positionsDecodeMatrix;");
81
+ if (normals) {
82
+ src.push(" mat4 worldNormalMatrix;");
83
+ src.push(" mat4 viewNormalMatrix;");
84
+ }
85
+ src.push("};");
86
+ return src;
87
+ }
88
+
89
+ _addRemapClipPosLines(src, viewportSize = 1) {
90
+ src.push("uniform vec2 drawingBufferSize;");
91
+ src.push("uniform vec2 pickClipPos;");
92
+
93
+ src.push("vec4 remapClipPos(vec4 clipPos) {");
94
+ src.push(" clipPos.xy /= clipPos.w;");
95
+ if (viewportSize === 1) {
96
+ src.push(" clipPos.xy = (clipPos.xy - pickClipPos) * drawingBufferSize;");
97
+ } else {
98
+ src.push(` clipPos.xy = (clipPos.xy - pickClipPos) * (drawingBufferSize / float(${viewportSize}));`);
99
+ }
100
+ src.push(" clipPos.xy *= clipPos.w;")
101
+ src.push(" return clipPos;")
102
+ src.push("}");
103
+ return src;
104
+ }
105
+
106
+ getValid() {
107
+ return this._hash === this._getHash();
108
+ }
109
+
110
+ setSectionPlanesStateUniforms(layer) {
111
+ const scene = this._scene;
112
+ const {gl} = scene.canvas;
113
+ const {model, layerIndex} = layer;
114
+
115
+ const numAllocatedSectionPlanes = scene._sectionPlanesState.getNumAllocatedSectionPlanes();
116
+ const numSectionPlanes = scene._sectionPlanesState.sectionPlanes.length;
117
+ if (numAllocatedSectionPlanes > 0) {
118
+ const sectionPlanes = scene._sectionPlanesState.sectionPlanes;
119
+ const baseIndex = layerIndex * numSectionPlanes;
120
+ const renderFlags = model.renderFlags;
121
+ if (scene.crossSections) {
122
+ gl.uniform4fv(this._uSliceColor, scene.crossSections.sliceColor);
123
+ gl.uniform1f(this._uSliceThickness, scene.crossSections.sliceThickness);
124
+ }
125
+ for (let sectionPlaneIndex = 0; sectionPlaneIndex < numAllocatedSectionPlanes; sectionPlaneIndex++) {
126
+ const sectionPlaneUniforms = this._uSectionPlanes[sectionPlaneIndex];
127
+ if (sectionPlaneUniforms) {
128
+ if (sectionPlaneIndex < numSectionPlanes) {
129
+ const active = renderFlags.sectionPlanesActivePerLayer[baseIndex + sectionPlaneIndex];
130
+ gl.uniform1i(sectionPlaneUniforms.active, active ? 1 : 0);
131
+ if (active) {
132
+ const sectionPlane = sectionPlanes[sectionPlaneIndex];
133
+ const origin = layer._state.origin;
134
+ if (origin) {
135
+ const rtcSectionPlanePos = getPlaneRTCPos(sectionPlane.dist, sectionPlane.dir, origin, tempVec3a, model.matrix);
136
+ gl.uniform3fv(sectionPlaneUniforms.pos, rtcSectionPlanePos);
137
+ } else {
138
+ gl.uniform3fv(sectionPlaneUniforms.pos, sectionPlane.pos);
139
+ }
140
+ gl.uniform3fv(sectionPlaneUniforms.dir, sectionPlane.dir);
141
+ }
142
+ } else {
143
+ gl.uniform1i(sectionPlaneUniforms.active, 0);
144
+ }
145
+ }
146
+ }
147
+ }
148
+ }
149
+
150
+
151
+ _allocate() {
152
+ const scene = this._scene;
153
+ const gl = scene.canvas.gl;
154
+ const lightsState = scene._lightsState;
155
+
156
+ this._program = new Program(gl, this._buildShader());
157
+
158
+ if (this._program.errors) {
159
+ this.errors = this._program.errors;
160
+ return;
161
+ }
162
+
163
+ const program = this._program;
164
+
165
+ this._uRenderPass = program.getLocation("renderPass");
166
+
167
+ this._uColor = program.getLocation("color");
168
+ if (!this._uColor) {
169
+ // some shader may have color as attribute, in this case the uniform must be renamed silhouetteColor
170
+ this._uColor = program.getLocation("silhouetteColor");
171
+ }
172
+ this._uUVDecodeMatrix = program.getLocation("uvDecodeMatrix");
173
+ this._uPickInvisible = program.getLocation("pickInvisible");
174
+ this._uGammaFactor = program.getLocation("gammaFactor");
175
+
176
+ gl.uniformBlockBinding(
177
+ program.handle,
178
+ gl.getUniformBlockIndex(program.handle, "Matrices"),
179
+ this._matricesUniformBlockBufferBindingPoint
180
+ );
181
+
182
+ this._uShadowViewMatrix = program.getLocation("shadowViewMatrix");
183
+ this._uShadowProjMatrix = program.getLocation("shadowProjMatrix");
184
+ if (scene.logarithmicDepthBufferEnabled) {
185
+ this._uZFar = program.getLocation("zFar");
186
+ }
187
+
188
+ this._uLightAmbient = program.getLocation("lightAmbient");
189
+ this._uLightColor = [];
190
+ this._uLightDir = [];
191
+ this._uLightPos = [];
192
+ this._uLightAttenuation = [];
193
+
194
+ // TODO add a gard to prevent light params if not affected by light ?
195
+ const lights = lightsState.lights;
196
+ let light;
197
+
198
+ for (let i = 0, len = lights.length; i < len; i++) {
199
+ light = lights[i];
200
+ switch (light.type) {
201
+ case "dir":
202
+ this._uLightColor[i] = program.getLocation("lightColor" + i);
203
+ this._uLightPos[i] = null;
204
+ this._uLightDir[i] = program.getLocation("lightDir" + i);
205
+ break;
206
+ case "point":
207
+ this._uLightColor[i] = program.getLocation("lightColor" + i);
208
+ this._uLightPos[i] = program.getLocation("lightPos" + i);
209
+ this._uLightDir[i] = null;
210
+ this._uLightAttenuation[i] = program.getLocation("lightAttenuation" + i);
211
+ break;
212
+ case "spot":
213
+ this._uLightColor[i] = program.getLocation("lightColor" + i);
214
+ this._uLightPos[i] = program.getLocation("lightPos" + i);
215
+ this._uLightDir[i] = program.getLocation("lightDir" + i);
216
+ this._uLightAttenuation[i] = program.getLocation("lightAttenuation" + i);
217
+ break;
218
+ }
219
+ }
220
+
221
+ if (lightsState.reflectionMaps.length > 0) {
222
+ this._uReflectionMap = "reflectionMap";
223
+ }
224
+
225
+ if (lightsState.lightMaps.length > 0) {
226
+ this._uLightMap = "lightMap";
227
+ }
228
+
229
+ this._uSectionPlanes = [];
230
+
231
+ for (let i = 0, len = scene._sectionPlanesState.getNumAllocatedSectionPlanes(); i < len; i++) {
232
+ this._uSectionPlanes.push({
233
+ active: program.getLocation("sectionPlaneActive" + i),
234
+ pos: program.getLocation("sectionPlanePos" + i),
235
+ dir: program.getLocation("sectionPlaneDir" + i)
236
+ });
237
+ }
238
+
239
+ this._aPosition = program.getAttribute("position");
240
+ this._aOffset = program.getAttribute("offset");
241
+ this._aNormal = program.getAttribute("normal");
242
+ this._aUV = program.getAttribute("uv");
243
+ this._aColor = program.getAttribute("color");
244
+ this._aMetallicRoughness = program.getAttribute("metallicRoughness");
245
+ this._aFlags = program.getAttribute("flags");
246
+ this._aPickColor = program.getAttribute("pickColor");
247
+ this._uPickZNear = program.getLocation("pickZNear");
248
+ this._uPickZFar = program.getLocation("pickZFar");
249
+ this._uPickClipPos = program.getLocation("pickClipPos");
250
+ this._uDrawingBufferSize = program.getLocation("drawingBufferSize");
251
+
252
+ this._uColorMap = "uColorMap";
253
+ this._uMetallicRoughMap = "uMetallicRoughMap";
254
+ this._uEmissiveMap = "uEmissiveMap";
255
+ this._uNormalMap = "uNormalMap";
256
+ this._uAOMap = "uAOMap";
257
+
258
+ if (this._instancing) {
259
+
260
+ this._aModelMatrix = program.getAttribute("modelMatrix");
261
+
262
+ this._aModelMatrixCol0 = program.getAttribute("modelMatrixCol0");
263
+ this._aModelMatrixCol1 = program.getAttribute("modelMatrixCol1");
264
+ this._aModelMatrixCol2 = program.getAttribute("modelMatrixCol2");
265
+
266
+ this._aModelNormalMatrixCol0 = program.getAttribute("modelNormalMatrixCol0");
267
+ this._aModelNormalMatrixCol1 = program.getAttribute("modelNormalMatrixCol1");
268
+ this._aModelNormalMatrixCol2 = program.getAttribute("modelNormalMatrixCol2");
269
+ }
270
+
271
+ if (this._withSAO) {
272
+ this._uOcclusionTexture = "uOcclusionTexture";
273
+ this._uSAOParams = program.getLocation("uSAOParams");
274
+ }
275
+
276
+ if (this._useAlphaCutoff) {
277
+ this._alphaCutoffLocation = program.getLocation("materialAlphaCutoff");
278
+ }
279
+
280
+ if (scene.logarithmicDepthBufferEnabled) {
281
+ this._uLogDepthBufFC = program.getLocation("logDepthBufFC");
282
+ }
283
+
284
+ if (scene.pointsMaterial._state.filterIntensity) {
285
+ this._uIntensityRange = program.getLocation("intensityRange");
286
+ }
287
+
288
+ this._uPointSize = program.getLocation("pointSize");
289
+ this._uNearPlaneHeight = program.getLocation("nearPlaneHeight");
290
+
291
+ if (scene.crossSections) {
292
+ this._uSliceColor = program.getLocation("sliceColor");
293
+ this._uSliceThickness = program.getLocation("sliceThickness");
294
+ }
295
+ }
296
+
297
+ _bindProgram(frameCtx) {
298
+ const scene = this._scene;
299
+ const gl = scene.canvas.gl;
300
+ const program = this._program;
301
+ const lightsState = scene._lightsState;
302
+ const lights = lightsState.lights;
303
+
304
+ program.bind();
305
+
306
+ frameCtx.textureUnit = 0;
307
+
308
+ if (this._uLightAmbient) {
309
+ gl.uniform4fv(this._uLightAmbient, lightsState.getAmbientColorAndIntensity());
310
+ }
311
+
312
+ if (this._uGammaFactor) {
313
+ gl.uniform1f(this._uGammaFactor, scene.gammaFactor);
314
+ }
315
+
316
+ for (let i = 0, len = lights.length; i < len; i++) {
317
+
318
+ const light = lights[i];
319
+
320
+ if (this._uLightColor[i]) {
321
+ gl.uniform4f(this._uLightColor[i], light.color[0], light.color[1], light.color[2], light.intensity);
322
+ }
323
+ if (this._uLightPos[i]) {
324
+ gl.uniform3fv(this._uLightPos[i], light.pos);
325
+ if (this._uLightAttenuation[i]) {
326
+ gl.uniform1f(this._uLightAttenuation[i], light.attenuation);
327
+ }
328
+ }
329
+ if (this._uLightDir[i]) {
330
+ gl.uniform3fv(this._uLightDir[i], light.dir);
331
+ }
332
+ }
333
+ }
334
+
335
+ _makeVAO(state) {
336
+ const gl = this._scene.canvas.gl;
337
+ const vao = gl.createVertexArray();
338
+ gl.bindVertexArray(vao);
339
+
340
+ if (this._instancing) {
341
+ this._aModelMatrixCol0.bindArrayBuffer(state.modelMatrixCol0Buf);
342
+ this._aModelMatrixCol1.bindArrayBuffer(state.modelMatrixCol1Buf);
343
+ this._aModelMatrixCol2.bindArrayBuffer(state.modelMatrixCol2Buf);
344
+
345
+ gl.vertexAttribDivisor(this._aModelMatrixCol0.location, 1);
346
+ gl.vertexAttribDivisor(this._aModelMatrixCol1.location, 1);
347
+ gl.vertexAttribDivisor(this._aModelMatrixCol2.location, 1);
348
+
349
+ if (this._aModelNormalMatrixCol0) {
350
+ this._aModelNormalMatrixCol0.bindArrayBuffer(state.modelNormalMatrixCol0Buf);
351
+ gl.vertexAttribDivisor(this._aModelNormalMatrixCol0.location, 1);
352
+ }
353
+ if (this._aModelNormalMatrixCol1) {
354
+ this._aModelNormalMatrixCol1.bindArrayBuffer(state.modelNormalMatrixCol1Buf);
355
+ gl.vertexAttribDivisor(this._aModelNormalMatrixCol1.location, 1);
356
+ }
357
+ if (this._aModelNormalMatrixCol2) {
358
+ this._aModelNormalMatrixCol2.bindArrayBuffer(state.modelNormalMatrixCol2Buf);
359
+ gl.vertexAttribDivisor(this._aModelNormalMatrixCol2.location, 1);
360
+ }
361
+
362
+ }
363
+
364
+ this._aPosition.bindArrayBuffer(state.positionsBuf);
365
+
366
+ if (this._aUV) {
367
+ this._aUV.bindArrayBuffer(state.uvBuf);
368
+ }
369
+
370
+ if (this._aNormal) {
371
+ this._aNormal.bindArrayBuffer(state.normalsBuf);
372
+ }
373
+
374
+ if (this._aMetallicRoughness) {
375
+ this._aMetallicRoughness.bindArrayBuffer(state.metallicRoughnessBuf);
376
+ if (this._instancing) {
377
+ gl.vertexAttribDivisor(this._aMetallicRoughness.location, 1);
378
+ }
379
+ }
380
+
381
+ if (this._aColor) {
382
+ this._aColor.bindArrayBuffer(state.colorsBuf);
383
+ if (this._instancing && state.colorsBuf) {
384
+ gl.vertexAttribDivisor(this._aColor.location, 1);
385
+ }
386
+ }
387
+
388
+ if (this._aFlags) {
389
+ this._aFlags.bindArrayBuffer(state.flagsBuf);
390
+ if (this._instancing) {
391
+ gl.vertexAttribDivisor(this._aFlags.location, 1);
392
+ }
393
+ }
394
+
395
+ if (this._aOffset) {
396
+ this._aOffset.bindArrayBuffer(state.offsetsBuf);
397
+ if (this._instancing) {
398
+ gl.vertexAttribDivisor(this._aOffset.location, 1);
399
+ }
400
+ }
401
+
402
+ if (this._aPickColor) {
403
+ this._aPickColor.bindArrayBuffer(state.pickColorsBuf);
404
+ if (this._instancing) {
405
+ gl.vertexAttribDivisor(this._aPickColor.location, 1);
406
+ }
407
+ }
408
+
409
+ if (this._instancing) {
410
+ if (this._edges && state.edgeIndicesBuf) {
411
+ state.edgeIndicesBuf.bind();
412
+ } else {
413
+ if (state.indicesBuf) {
414
+ state.indicesBuf.bind();
415
+ }
416
+ }
417
+ } else {
418
+ if (this._edges && state.edgeIndicesBuf) {
419
+ state.edgeIndicesBuf.bind();
420
+ } else {
421
+ if (state.indicesBuf) {
422
+ state.indicesBuf.bind();
423
+ }
424
+ }
425
+ }
426
+
427
+ return vao;
428
+ }
429
+
430
+ drawLayer(frameCtx, layer, renderPass, {colorUniform = false, incrementDrawState = false} = {}) {
431
+ const maxTextureUnits = WEBGL_INFO.MAX_TEXTURE_IMAGE_UNITS;
432
+
433
+ const scene = this._scene;
434
+ const gl = scene.canvas.gl;
435
+ const {_state: state, model} = layer;
436
+ const {textureSet, origin, positionsDecodeMatrix} = state;
437
+ const lightsState = scene._lightsState;
438
+ const pointsMaterial = scene.pointsMaterial;
439
+ const {camera} = model.scene;
440
+ const {viewNormalMatrix, project} = camera;
441
+ const viewMatrix = frameCtx.pickViewMatrix || camera.viewMatrix
442
+ const {position, rotationMatrix, worldNormalMatrix} = model;
443
+
444
+ if (!this._program) {
445
+ this._allocate();
446
+ if (this.errors) {
447
+ return;
448
+ }
449
+ }
450
+
451
+ if (frameCtx.lastProgramId !== this._program.id) {
452
+ frameCtx.lastProgramId = this._program.id;
453
+ this._bindProgram(frameCtx);
454
+ }
455
+
456
+ if (this._vaoCache.has(layer)) {
457
+ gl.bindVertexArray(this._vaoCache.get(layer));
458
+ } else {
459
+ this._vaoCache.set(layer, this._makeVAO(state))
460
+ }
461
+
462
+ let offset = 0;
463
+ const mat4Size = 4 * 4;
464
+
465
+ this._matricesUniformBlockBufferData.set(rotationMatrix, 0);
466
+
467
+ const gotOrigin = (origin[0] !== 0 || origin[1] !== 0 || origin[2] !== 0);
468
+ const gotPosition = (position[0] !== 0 || position[1] !== 0 || position[2] !== 0);
469
+ if (gotOrigin || gotPosition) {
470
+ const rtcOrigin = tempVec3a;
471
+ if (gotOrigin) {
472
+ const rotatedOrigin = math.transformPoint3(rotationMatrix, origin, tempVec3c);
473
+ rtcOrigin[0] = rotatedOrigin[0];
474
+ rtcOrigin[1] = rotatedOrigin[1];
475
+ rtcOrigin[2] = rotatedOrigin[2];
476
+ } else {
477
+ rtcOrigin[0] = 0;
478
+ rtcOrigin[1] = 0;
479
+ rtcOrigin[2] = 0;
480
+ }
481
+ rtcOrigin[0] += position[0];
482
+ rtcOrigin[1] += position[1];
483
+ rtcOrigin[2] += position[2];
484
+ this._matricesUniformBlockBufferData.set(createRTCViewMat(viewMatrix, rtcOrigin, tempMat4a), offset += mat4Size);
485
+ } else {
486
+ this._matricesUniformBlockBufferData.set(viewMatrix, offset += mat4Size);
487
+ }
488
+
489
+ this._matricesUniformBlockBufferData.set(frameCtx.pickProjMatrix || project.matrix, offset += mat4Size);
490
+ this._matricesUniformBlockBufferData.set(positionsDecodeMatrix, offset += mat4Size);
491
+ this._matricesUniformBlockBufferData.set(worldNormalMatrix, offset += mat4Size);
492
+ this._matricesUniformBlockBufferData.set(viewNormalMatrix, offset += mat4Size);
493
+
494
+ gl.bindBuffer(gl.UNIFORM_BUFFER, this._matricesUniformBlockBuffer);
495
+ gl.bufferData(gl.UNIFORM_BUFFER, this._matricesUniformBlockBufferData, gl.DYNAMIC_DRAW);
496
+
497
+ gl.bindBufferBase(
498
+ gl.UNIFORM_BUFFER,
499
+ this._matricesUniformBlockBufferBindingPoint,
500
+ this._matricesUniformBlockBuffer);
501
+
502
+
503
+ gl.uniform1i(this._uRenderPass, renderPass);
504
+
505
+ this.setSectionPlanesStateUniforms(layer);
506
+
507
+ if (scene.logarithmicDepthBufferEnabled) {
508
+ if (this._uLogDepthBufFC) {
509
+ const logDepthBufFC = 2.0 / (Math.log(frameCtx.pickZFar + 1.0) / Math.LN2); // TODO: Far from pick project matrix?
510
+ gl.uniform1f(this._uLogDepthBufFC, logDepthBufFC);
511
+ }
512
+ if (this._uZFar) {
513
+ gl.uniform1f(this._uZFar, scene.camera.project.far)
514
+ }
515
+ }
516
+
517
+ if (this._uPickInvisible) {
518
+ gl.uniform1i(this._uPickInvisible, frameCtx.pickInvisible);
519
+ }
520
+
521
+ if (this._uPickZNear) {
522
+ gl.uniform1f(this._uPickZNear, frameCtx.pickZNear);
523
+ }
524
+
525
+ if (this._uPickZFar) {
526
+ gl.uniform1f(this._uPickZFar, frameCtx.pickZFar);
527
+ }
528
+
529
+ if (this._uPickClipPos) {
530
+ gl.uniform2fv(this._uPickClipPos, frameCtx.pickClipPos);
531
+ }
532
+
533
+ if (this._uDrawingBufferSize) {
534
+ gl.uniform2f(this._uDrawingBufferSize, gl.drawingBufferWidth, gl.drawingBufferHeight);
535
+ }
536
+
537
+ if (this._uUVDecodeMatrix) {
538
+ gl.uniformMatrix3fv(this._uUVDecodeMatrix, false, state.uvDecodeMatrix);
539
+ }
540
+
541
+ if (this._uIntensityRange && pointsMaterial.filterIntensity) {
542
+ gl.uniform2f(this._uIntensityRange, pointsMaterial.minIntensity, pointsMaterial.maxIntensity);
543
+ }
544
+
545
+ if (this._uPointSize) {
546
+ gl.uniform1f(this._uPointSize, pointsMaterial.pointSize);
547
+ }
548
+
549
+ if (this._uNearPlaneHeight) {
550
+ const nearPlaneHeight = (scene.camera.projection === "ortho") ?
551
+ 1.0
552
+ : (gl.drawingBufferHeight / (2 * Math.tan(0.5 * scene.camera.perspective.fov * Math.PI / 180.0)));
553
+ gl.uniform1f(this._uNearPlaneHeight, nearPlaneHeight);
554
+ }
555
+
556
+ if (textureSet) {
557
+ const {
558
+ colorTexture,
559
+ metallicRoughnessTexture,
560
+ emissiveTexture,
561
+ normalsTexture,
562
+ occlusionTexture,
563
+ } = textureSet;
564
+
565
+ if (this._uColorMap && colorTexture) {
566
+ this._program.bindTexture(this._uColorMap, colorTexture.texture, frameCtx.textureUnit);
567
+ frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
568
+ }
569
+ if (this._uMetallicRoughMap && metallicRoughnessTexture) {
570
+ this._program.bindTexture(this._uMetallicRoughMap, metallicRoughnessTexture.texture, frameCtx.textureUnit);
571
+ frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
572
+ }
573
+ if (this._uEmissiveMap && emissiveTexture) {
574
+ this._program.bindTexture(this._uEmissiveMap, emissiveTexture.texture, frameCtx.textureUnit);
575
+ frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
576
+ }
577
+ if (this._uNormalMap && normalsTexture) {
578
+ this._program.bindTexture(this._uNormalMap, normalsTexture.texture, frameCtx.textureUnit);
579
+ frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
580
+ }
581
+ if (this._uAOMap && occlusionTexture) {
582
+ this._program.bindTexture(this._uAOMap, occlusionTexture.texture, frameCtx.textureUnit);
583
+ frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
584
+ }
585
+
586
+ }
587
+
588
+ if (lightsState.reflectionMaps.length > 0 && lightsState.reflectionMaps[0].texture && this._uReflectionMap) {
589
+ this._program.bindTexture(this._uReflectionMap, lightsState.reflectionMaps[0].texture, frameCtx.textureUnit);
590
+ frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
591
+ frameCtx.bindTexture++;
592
+ }
593
+
594
+ if (lightsState.lightMaps.length > 0 && lightsState.lightMaps[0].texture && this._uLightMap) {
595
+ this._program.bindTexture(this._uLightMap, lightsState.lightMaps[0].texture, frameCtx.textureUnit);
596
+ frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
597
+ frameCtx.bindTexture++;
598
+ }
599
+
600
+ if (this._withSAO) {
601
+ const sao = scene.sao;
602
+ const saoEnabled = sao.possible;
603
+ if (saoEnabled) {
604
+ const viewportWidth = gl.drawingBufferWidth;
605
+ const viewportHeight = gl.drawingBufferHeight;
606
+ tempVec4[0] = viewportWidth;
607
+ tempVec4[1] = viewportHeight;
608
+ tempVec4[2] = sao.blendCutoff;
609
+ tempVec4[3] = sao.blendFactor;
610
+ gl.uniform4fv(this._uSAOParams, tempVec4);
611
+ this._program.bindTexture(this._uOcclusionTexture, frameCtx.occlusionTexture, frameCtx.textureUnit);
612
+ frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
613
+ frameCtx.bindTexture++;
614
+ }
615
+ }
616
+
617
+ if (this._useAlphaCutoff) {
618
+ gl.uniform1f(this._alphaCutoffLocation, textureSet.alphaCutoff);
619
+ }
620
+
621
+ if (colorUniform) {
622
+ const colorKey = this._edges ? "edgeColor" : "fillColor";
623
+ const alphaKey = this._edges ? "edgeAlpha" : "fillAlpha";
624
+
625
+ if (renderPass === RENDER_PASSES[`${this._edges ? "EDGES" : "SILHOUETTE"}_XRAYED`]) {
626
+ const material = scene.xrayMaterial._state;
627
+ const color = material[colorKey];
628
+ const alpha = material[alphaKey];
629
+ gl.uniform4f(this._uColor, color[0], color[1], color[2], alpha);
630
+
631
+ } else if (renderPass === RENDER_PASSES[`${this._edges ? "EDGES" : "SILHOUETTE"}_HIGHLIGHTED`]) {
632
+ const material = scene.highlightMaterial._state;
633
+ const color = material[colorKey];
634
+ const alpha = material[alphaKey];
635
+ gl.uniform4f(this._uColor, color[0], color[1], color[2], alpha);
636
+
637
+ } else if (renderPass === RENDER_PASSES[`${this._edges ? "EDGES" : "SILHOUETTE"}_SELECTED`]) {
638
+ const material = scene.selectedMaterial._state;
639
+ const color = material[colorKey];
640
+ const alpha = material[alphaKey];
641
+ gl.uniform4f(this._uColor, color[0], color[1], color[2], alpha);
642
+
643
+ } else {
644
+ gl.uniform4fv(this._uColor, this._edges ? edgesDefaultColor : defaultColor);
645
+ }
646
+ }
647
+
648
+ this._draw({state, frameCtx, incrementDrawState});
649
+
650
+ gl.bindVertexArray(null);
651
+ }
652
+
653
+ webglContextRestored() {
654
+ this._program = null;
655
+ }
656
+
657
+ destroy() {
658
+ if (this._program) {
659
+ this._program.destroy();
660
+ }
661
+ this._program = null;
662
+ stats.memory.programs--;
663
+ }
664
+ }