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

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 (183) hide show
  1. package/dist/xeokit-sdk.cjs.js +13077 -44659
  2. package/dist/xeokit-sdk.es.js +13078 -44658
  3. package/dist/xeokit-sdk.es5.js +1402 -3502
  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/ui/index.js +12 -0
  9. package/src/viewer/Viewer.js +55 -103
  10. package/src/viewer/scene/canvas/Canvas.js +3 -43
  11. package/src/viewer/scene/geometry/ReadableGeometry.js +0 -25
  12. package/src/viewer/scene/lights/CubeTexture.js +0 -13
  13. package/src/viewer/scene/lights/DirLight.js +2 -1
  14. package/src/viewer/scene/lights/PointLight.js +2 -1
  15. package/src/viewer/scene/materials/Texture.js +0 -9
  16. package/src/viewer/scene/math/rtcCoords.js +1 -38
  17. package/src/viewer/scene/mesh/Mesh.js +454 -212
  18. package/src/viewer/scene/mesh/draw/DrawShaderSource.js +305 -1502
  19. package/src/viewer/scene/mesh/draw/LambertShaderSource.js +35 -0
  20. package/src/viewer/scene/mesh/emphasis/EmphasisShaderSource.js +34 -0
  21. package/src/viewer/scene/mesh/occlusion/OcclusionShaderSource.js +9 -157
  22. package/src/viewer/scene/mesh/pick/PickMeshShaderSource.js +21 -150
  23. package/src/viewer/scene/mesh/pick/PickTriangleShaderSource.js +12 -124
  24. package/src/viewer/scene/mesh/shadow/ShadowShaderSource.js +22 -97
  25. package/src/viewer/scene/model/SceneModel.js +245 -861
  26. package/src/viewer/scene/model/SceneModelEntity.js +4 -4
  27. package/src/viewer/scene/model/SceneModelMesh.js +3 -3
  28. package/src/viewer/scene/model/layer/DTXLayer.js +940 -0
  29. package/src/viewer/scene/model/layer/Layer.js +786 -0
  30. package/src/viewer/scene/model/layer/VBOLayer.js +1019 -0
  31. package/src/viewer/scene/model/layer/programs/ColorProgram.js +35 -0
  32. package/src/viewer/scene/model/layer/programs/ColorTextureProgram.js +46 -0
  33. package/src/viewer/scene/model/layer/programs/DepthProgram.js +11 -0
  34. package/src/viewer/scene/model/layer/programs/EdgesProgram.js +12 -0
  35. package/src/viewer/scene/model/layer/programs/FlatColorProgram.js +24 -0
  36. package/src/viewer/scene/model/layer/programs/OcclusionProgram.js +12 -0
  37. package/src/viewer/scene/model/layer/programs/PBRProgram.js +180 -0
  38. package/src/viewer/scene/model/layer/programs/PickDepthProgram.js +30 -0
  39. package/src/viewer/scene/model/layer/programs/PickMeshProgram.js +12 -0
  40. package/src/viewer/scene/model/layer/programs/PickNormalsProgram.js +18 -0
  41. package/src/viewer/scene/model/layer/programs/ShadowProgram.js +23 -0
  42. package/src/viewer/scene/model/layer/programs/SilhouetteProgram.js +15 -0
  43. package/src/viewer/scene/model/layer/programs/SnapProgram.js +28 -0
  44. package/src/viewer/scene/scene/Scene.js +21 -38
  45. package/src/viewer/scene/webgl/ArrayBuf.js +5 -20
  46. package/src/viewer/scene/webgl/FrameContext.js +14 -86
  47. package/src/viewer/scene/webgl/RenderBuffer.js +62 -262
  48. package/src/viewer/scene/webgl/Renderer.js +880 -843
  49. package/src/viewer/scene/webgl/WebGLRenderer.js +612 -0
  50. package/src/viewer/scene/webgl/occlusion/OcclusionLayer.js +60 -132
  51. package/src/viewer/scene/webgl/occlusion/OcclusionTester.js +167 -328
  52. package/src/viewer/scene/mesh/draw/DrawRenderer.js +0 -996
  53. package/src/viewer/scene/mesh/emphasis/EmphasisEdgesRenderer.js +0 -259
  54. package/src/viewer/scene/mesh/emphasis/EmphasisEdgesShaderSource.js +0 -159
  55. package/src/viewer/scene/mesh/emphasis/EmphasisFillRenderer.js +0 -286
  56. package/src/viewer/scene/mesh/emphasis/EmphasisFillShaderSource.js +0 -262
  57. package/src/viewer/scene/mesh/occlusion/OcclusionRenderer.js +0 -221
  58. package/src/viewer/scene/mesh/pick/PickMeshRenderer.js +0 -223
  59. package/src/viewer/scene/mesh/pick/PickTriangleRenderer.js +0 -200
  60. package/src/viewer/scene/mesh/shadow/ShadowRenderer.js +0 -214
  61. package/src/viewer/scene/model/RENDER_PASSES.js +0 -34
  62. package/src/viewer/scene/model/dtx/BindableDataTexture.js +0 -31
  63. package/src/viewer/scene/model/dtx/lines/DTXLinesBuffer.js +0 -27
  64. package/src/viewer/scene/model/dtx/lines/DTXLinesLayer.js +0 -897
  65. package/src/viewer/scene/model/dtx/lines/DTXLinesState.js +0 -46
  66. package/src/viewer/scene/model/dtx/lines/DTXLinesTextureFactory.js +0 -411
  67. package/src/viewer/scene/model/dtx/lines/dataTextureRamStats.js +0 -49
  68. package/src/viewer/scene/model/dtx/lines/rebucketPositions.js +0 -208
  69. package/src/viewer/scene/model/dtx/lines/renderers/DTXLinesColorRenderer.js +0 -389
  70. package/src/viewer/scene/model/dtx/lines/renderers/DTXLinesRenderers.js +0 -65
  71. package/src/viewer/scene/model/dtx/triangles/DTXTrianglesLayer.js +0 -1399
  72. package/src/viewer/scene/model/dtx/triangles/lib/DTXTrianglesBuffer.js +0 -46
  73. package/src/viewer/scene/model/dtx/triangles/lib/DTXTrianglesState.js +0 -250
  74. package/src/viewer/scene/model/dtx/triangles/lib/DTXTrianglesTextureFactory.js +0 -518
  75. package/src/viewer/scene/model/dtx/triangles/lib/dataTextureRamStats.js +0 -54
  76. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesColorRenderer.js +0 -639
  77. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesDepthRenderer.js +0 -464
  78. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesEdgesColorRenderer.js +0 -423
  79. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesEdgesRenderer.js +0 -431
  80. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesNormalsRenderer.js +0 -345
  81. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesOcclusionRenderer.js +0 -436
  82. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesPickDepthRenderer.js +0 -466
  83. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesPickMeshRenderer.js +0 -437
  84. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesPickNormalsFlatRenderer.js +0 -460
  85. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesPickNormalsRenderer.js +0 -437
  86. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesRenderers.js +0 -307
  87. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesSilhouetteRenderer.js +0 -472
  88. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesSnapInitRenderer.js +0 -474
  89. package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesSnapRenderer.js +0 -435
  90. package/src/viewer/scene/model/vbo/ScratchMemory.js +0 -63
  91. package/src/viewer/scene/model/vbo/VBORenderer.js +0 -664
  92. package/src/viewer/scene/model/vbo/batching/lines/VBOBatchingLinesLayer.js +0 -704
  93. package/src/viewer/scene/model/vbo/batching/lines/lib/VBOBatchingLinesBuffer.js +0 -19
  94. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLineSnapInitRenderer.js +0 -318
  95. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesColorRenderer.js +0 -114
  96. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesRenderers.js +0 -99
  97. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesSilhouetteRenderer.js +0 -124
  98. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesSnapInitRenderer.js +0 -313
  99. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesSnapRenderer.js +0 -311
  100. package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOSceneModelLineBatchingRenderer.js +0 -24
  101. package/src/viewer/scene/model/vbo/batching/points/VBOBatchingPointsLayer.js +0 -688
  102. package/src/viewer/scene/model/vbo/batching/points/VBOBatchingPointsRenderer.js +0 -24
  103. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsColorRenderer.js +0 -168
  104. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsOcclusionRenderer.js +0 -136
  105. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsPickDepthRenderer.js +0 -156
  106. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsPickMeshRenderer.js +0 -148
  107. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsRenderers.js +0 -144
  108. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsShadowRenderer.js +0 -107
  109. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsSilhouetteRenderer.js +0 -146
  110. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsSnapInitRenderer.js +0 -315
  111. package/src/viewer/scene/model/vbo/batching/points/renderers/VBOBatchingPointsSnapRenderer.js +0 -305
  112. package/src/viewer/scene/model/vbo/batching/triangles/VBOBatchingTrianglesBuffer.js +0 -24
  113. package/src/viewer/scene/model/vbo/batching/triangles/VBOBatchingTrianglesLayer.js +0 -1346
  114. package/src/viewer/scene/model/vbo/batching/triangles/renderers/EdgesColorRenderer.js +0 -131
  115. package/src/viewer/scene/model/vbo/batching/triangles/renderers/EdgesEmphasisRenderer.js +0 -135
  116. package/src/viewer/scene/model/vbo/batching/triangles/renderers/EdgesRenderer.js +0 -12
  117. package/src/viewer/scene/model/vbo/batching/triangles/renderers/Renderers.js +0 -403
  118. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesBatchingRenderer.js +0 -35
  119. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesColorRenderer.js +0 -252
  120. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesColorTextureRenderer.js +0 -294
  121. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesDepthRenderer.js +0 -115
  122. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesFlatColorRenderer.js +0 -246
  123. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesNormalsRenderer.js +0 -139
  124. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesOcclusionRenderer.js +0 -125
  125. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPBRRenderer.js +0 -561
  126. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPickDepthRenderer.js +0 -144
  127. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPickMeshRenderer.js +0 -130
  128. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPickNormalsFlatRenderer.js +0 -121
  129. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesPickNormalsRenderer.js +0 -131
  130. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesShadowRenderer.js +0 -107
  131. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesSilhouetteRenderer.js +0 -144
  132. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesSnapInitRenderer.js +0 -313
  133. package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesSnapRenderer.js +0 -312
  134. package/src/viewer/scene/model/vbo/float16.js +0 -760
  135. package/src/viewer/scene/model/vbo/instancing/lines/VBOInstancingLinesLayer.js +0 -711
  136. package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesColorRenderer.js +0 -148
  137. package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesRenderer.js +0 -26
  138. package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesRenderers.js +0 -139
  139. package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesSilhouetteRenderer.js +0 -127
  140. package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesSnapInitRenderer.js +0 -308
  141. package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesSnapRenderer.js +0 -299
  142. package/src/viewer/scene/model/vbo/instancing/points/VBOInstancingPointsLayer.js +0 -733
  143. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsColorRenderer.js +0 -174
  144. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsDepthRenderer.js +0 -156
  145. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsOcclusionRenderer.js +0 -149
  146. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsPickDepthRenderer.js +0 -170
  147. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsPickMeshRenderer.js +0 -152
  148. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsRenderer.js +0 -26
  149. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsRenderers.js +0 -174
  150. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsShadowRenderer.js +0 -119
  151. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsSilhouetteRenderer.js +0 -154
  152. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsSnapInitRenderer.js +0 -307
  153. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingPointsSnapRenderer.js +0 -293
  154. package/src/viewer/scene/model/vbo/instancing/points/renderers/VBOInstancingTrianglesRenderer.js +0 -150
  155. package/src/viewer/scene/model/vbo/instancing/triangles/VBOInstancingTrianglesLayer.js +0 -1289
  156. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/EdgesColorRenderer.js +0 -135
  157. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/EdgesEmphasisRenderer.js +0 -137
  158. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/EdgesRenderer.js +0 -12
  159. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/Renderers.js +0 -403
  160. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesColorRenderer.js +0 -267
  161. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesColorTextureRenderer.js +0 -299
  162. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesDepthRenderer.js +0 -126
  163. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesFlatColorRenderer.js +0 -255
  164. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesFlatNormalsRenderer.js +0 -130
  165. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesInstancingRenderer.js +0 -32
  166. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesNormalsRenderer.js +0 -138
  167. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesOcclusionRenderer.js +0 -128
  168. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPBRRenderer.js +0 -561
  169. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPickDepthRenderer.js +0 -149
  170. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPickMeshRenderer.js +0 -136
  171. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPickNormalsFlatRenderer.js +0 -130
  172. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesPickNormalsRenderer.js +0 -145
  173. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesShadowRenderer.js +0 -113
  174. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesSilhouetteRenderer.js +0 -148
  175. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesSnapInitRenderer.js +0 -319
  176. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesSnapRenderer.js +0 -310
  177. package/src/viewer/scene/webgl/Attribute.js +0 -23
  178. package/src/viewer/scene/webgl/Program.js +0 -181
  179. package/src/viewer/scene/webgl/RenderBufferManager.js +0 -34
  180. package/src/viewer/scene/webgl/Sampler.js +0 -18
  181. package/src/viewer/scene/webgl/Shader.js +0 -49
  182. package/src/viewer/scene/webgl/sao/SAODepthLimitedBlurRenderer.js +0 -324
  183. package/src/viewer/scene/webgl/sao/SAOOcclusionRenderer.js +0 -384
@@ -1,996 +0,0 @@
1
- /**
2
- * @author xeolabs / https://github.com/xeolabs
3
- */
4
-
5
- import {Map} from "../../utils/Map.js";
6
- import {DrawShaderSource} from "./DrawShaderSource.js";
7
- import {Program} from "../../webgl/Program.js";
8
- import {stats} from '../../stats.js';
9
- import {WEBGL_INFO} from '../../webglInfo.js';
10
- import {math} from "../../math/math.js";
11
- import {getPlaneRTCPos} from "../../math/rtcCoords.js";
12
-
13
- const tempVec3a = math.vec3();
14
-
15
- const ids = new Map({});
16
-
17
- /**
18
- * @private
19
- */
20
- const DrawRenderer = function (hash, mesh) {
21
- this.id = ids.addItem({});
22
- this._hash = hash;
23
- this._scene = mesh.scene;
24
- this._useCount = 0;
25
- this._shaderSource = new DrawShaderSource(mesh);
26
- this._allocate(mesh);
27
- };
28
-
29
- const drawRenderers = {};
30
-
31
- DrawRenderer.get = function (mesh) {
32
- const scene = mesh.scene;
33
- const hash = [
34
- scene.canvas.canvas.id,
35
- (scene.gammaInput ? "gi;" : ";") + (scene.gammaOutput ? "go" : ""),
36
- scene._lightsState.getHash(),
37
- scene._sectionPlanesState.getHash(),
38
- mesh._geometry._state.hash,
39
- mesh._material._state.hash,
40
- mesh._state.drawHash
41
- ].join(";");
42
- let renderer = drawRenderers[hash];
43
- if (!renderer) {
44
- renderer = new DrawRenderer(hash, mesh);
45
- if (renderer.errors) {
46
- console.log(renderer.errors.join("\n"));
47
- return null;
48
- }
49
- drawRenderers[hash] = renderer;
50
- stats.memory.programs++;
51
- }
52
- renderer._useCount++;
53
- return renderer;
54
- };
55
-
56
- DrawRenderer.prototype.put = function () {
57
- if (--this._useCount === 0) {
58
- ids.removeItem(this.id);
59
- if (this._program) {
60
- this._program.destroy();
61
- }
62
- delete drawRenderers[this._hash];
63
- stats.memory.programs--;
64
- }
65
- };
66
-
67
- DrawRenderer.prototype.webglContextRestored = function () {
68
- this._program = null;
69
- };
70
-
71
- DrawRenderer.prototype.drawMesh = function (frameCtx, mesh) {
72
-
73
- if (!this._program) {
74
- this._allocate(mesh);
75
- }
76
-
77
- const maxTextureUnits = WEBGL_INFO.MAX_TEXTURE_UNITS;
78
- const scene = mesh.scene;
79
- const material = mesh._material;
80
- const gl = scene.canvas.gl;
81
- const program = this._program;
82
- const meshState = mesh._state;
83
- const materialState = mesh._material._state;
84
- const geometryState = mesh._geometry._state;
85
- const camera = scene.camera;
86
- const origin = mesh.origin;
87
- const background = meshState.background;
88
-
89
- if (frameCtx.lastProgramId !== this._program.id) {
90
- frameCtx.lastProgramId = this._program.id;
91
- if (background) {
92
- gl.depthFunc(gl.LEQUAL);
93
- }
94
- this._bindProgram(frameCtx);
95
- }
96
-
97
- gl.uniformMatrix4fv(this._uViewMatrix, false, origin ? frameCtx.getRTCViewMatrix(meshState.originHash, origin) : camera.viewMatrix);
98
- gl.uniformMatrix4fv(this._uViewNormalMatrix, false, camera.viewNormalMatrix);
99
-
100
- if (meshState.clippable) {
101
- const numAllocatedSectionPlanes = scene._sectionPlanesState.getNumAllocatedSectionPlanes();
102
- const numSectionPlanes = scene._sectionPlanesState.sectionPlanes.length;
103
- if (numAllocatedSectionPlanes > 0) {
104
- const sectionPlanes = scene._sectionPlanesState.sectionPlanes;
105
- const renderFlags = mesh.renderFlags;
106
- for (let sectionPlaneIndex = 0; sectionPlaneIndex < numAllocatedSectionPlanes; sectionPlaneIndex++) {
107
- const sectionPlaneUniforms = this._uSectionPlanes[sectionPlaneIndex];
108
- if (sectionPlaneUniforms) {
109
- if (sectionPlaneIndex < numSectionPlanes) {
110
- const active = renderFlags.sectionPlanesActivePerLayer[sectionPlaneIndex];
111
- gl.uniform1i(sectionPlaneUniforms.active, active ? 1 : 0);
112
- if (active) {
113
- const sectionPlane = sectionPlanes[sectionPlaneIndex];
114
- if (origin) {
115
- const rtcSectionPlanePos = getPlaneRTCPos(sectionPlane.dist, sectionPlane.dir, origin, tempVec3a);
116
- gl.uniform3fv(sectionPlaneUniforms.pos, rtcSectionPlanePos);
117
- } else {
118
- gl.uniform3fv(sectionPlaneUniforms.pos, sectionPlane.pos);
119
- }
120
- gl.uniform3fv(sectionPlaneUniforms.dir, sectionPlane.dir);
121
- }
122
- } else {
123
- gl.uniform1i(sectionPlaneUniforms.active, 0);
124
- }
125
- }
126
- }
127
- }
128
- }
129
-
130
- if (materialState.id !== this._lastMaterialId) {
131
-
132
- frameCtx.textureUnit = this._baseTextureUnit;
133
-
134
- const backfaces = materialState.backfaces;
135
- if (frameCtx.backfaces !== backfaces) {
136
- if (backfaces) {
137
- gl.disable(gl.CULL_FACE);
138
- } else {
139
- gl.enable(gl.CULL_FACE);
140
- }
141
- frameCtx.backfaces = backfaces;
142
- }
143
-
144
- const frontface = materialState.frontface;
145
- if (frameCtx.frontface !== frontface) {
146
- if (frontface) {
147
- gl.frontFace(gl.CCW);
148
- } else {
149
- gl.frontFace(gl.CW);
150
- }
151
- frameCtx.frontface = frontface;
152
- }
153
-
154
- if (frameCtx.lineWidth !== materialState.lineWidth) {
155
- gl.lineWidth(materialState.lineWidth);
156
- frameCtx.lineWidth = materialState.lineWidth;
157
- }
158
-
159
- if (this._uPointSize) {
160
- gl.uniform1f(this._uPointSize, materialState.pointSize);
161
- }
162
-
163
- switch (materialState.type) {
164
- case "LambertMaterial":
165
- if (this._uMaterialAmbient) {
166
- gl.uniform3fv(this._uMaterialAmbient, materialState.ambient);
167
- }
168
- if (this._uMaterialColor) {
169
- gl.uniform4f(this._uMaterialColor, materialState.color[0], materialState.color[1], materialState.color[2], materialState.alpha);
170
- }
171
- if (this._uMaterialEmissive) {
172
- gl.uniform3fv(this._uMaterialEmissive, materialState.emissive);
173
- }
174
- break;
175
-
176
- case "PhongMaterial":
177
- if (this._uMaterialShininess) {
178
- gl.uniform1f(this._uMaterialShininess, materialState.shininess);
179
- }
180
- if (this._uMaterialAmbient) {
181
- gl.uniform3fv(this._uMaterialAmbient, materialState.ambient);
182
- }
183
- if (this._uMaterialDiffuse) {
184
- gl.uniform3fv(this._uMaterialDiffuse, materialState.diffuse);
185
- }
186
- if (this._uMaterialSpecular) {
187
- gl.uniform3fv(this._uMaterialSpecular, materialState.specular);
188
- }
189
- if (this._uMaterialEmissive) {
190
- gl.uniform3fv(this._uMaterialEmissive, materialState.emissive);
191
- }
192
- if (this._uAlphaModeCutoff) {
193
- gl.uniform4f(
194
- this._uAlphaModeCutoff,
195
- 1.0 * materialState.alpha,
196
- materialState.alphaMode === 1 ? 1.0 : 0.0,
197
- materialState.alphaCutoff,
198
- 0);
199
- }
200
- if (material._ambientMap && material._ambientMap._state.texture && this._uMaterialAmbientMap) {
201
- program.bindTexture(this._uMaterialAmbientMap, material._ambientMap._state.texture, frameCtx.textureUnit);
202
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
203
- frameCtx.bindTexture++;
204
- if (this._uMaterialAmbientMapMatrix) {
205
- gl.uniformMatrix4fv(this._uMaterialAmbientMapMatrix, false, material._ambientMap._state.matrix);
206
- }
207
- }
208
- if (material._diffuseMap && material._diffuseMap._state.texture && this._uDiffuseMap) {
209
- program.bindTexture(this._uDiffuseMap, material._diffuseMap._state.texture, frameCtx.textureUnit);
210
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
211
- frameCtx.bindTexture++;
212
- if (this._uDiffuseMapMatrix) {
213
- gl.uniformMatrix4fv(this._uDiffuseMapMatrix, false, material._diffuseMap._state.matrix);
214
- }
215
- }
216
- if (material._specularMap && material._specularMap._state.texture && this._uSpecularMap) {
217
- program.bindTexture(this._uSpecularMap, material._specularMap._state.texture, frameCtx.textureUnit);
218
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
219
- frameCtx.bindTexture++;
220
- if (this._uSpecularMapMatrix) {
221
- gl.uniformMatrix4fv(this._uSpecularMapMatrix, false, material._specularMap._state.matrix);
222
- }
223
- }
224
- if (material._emissiveMap && material._emissiveMap._state.texture && this._uEmissiveMap) {
225
- program.bindTexture(this._uEmissiveMap, material._emissiveMap._state.texture, frameCtx.textureUnit);
226
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
227
- frameCtx.bindTexture++;
228
- if (this._uEmissiveMapMatrix) {
229
- gl.uniformMatrix4fv(this._uEmissiveMapMatrix, false, material._emissiveMap._state.matrix);
230
- }
231
- }
232
- if (material._alphaMap && material._alphaMap._state.texture && this._uAlphaMap) {
233
- program.bindTexture(this._uAlphaMap, material._alphaMap._state.texture, frameCtx.textureUnit);
234
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
235
- frameCtx.bindTexture++;
236
- if (this._uAlphaMapMatrix) {
237
- gl.uniformMatrix4fv(this._uAlphaMapMatrix, false, material._alphaMap._state.matrix);
238
- }
239
- }
240
- if (material._reflectivityMap && material._reflectivityMap._state.texture && this._uReflectivityMap) {
241
- program.bindTexture(this._uReflectivityMap, material._reflectivityMap._state.texture, frameCtx.textureUnit);
242
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
243
- if (this._uReflectivityMapMatrix) {
244
- gl.uniformMatrix4fv(this._uReflectivityMapMatrix, false, material._reflectivityMap._state.matrix);
245
- }
246
- }
247
- if (material._normalMap && material._normalMap._state.texture && this._uNormalMap) {
248
- program.bindTexture(this._uNormalMap, material._normalMap._state.texture, frameCtx.textureUnit);
249
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
250
- frameCtx.bindTexture++;
251
- if (this._uNormalMapMatrix) {
252
- gl.uniformMatrix4fv(this._uNormalMapMatrix, false, material._normalMap._state.matrix);
253
- }
254
- }
255
- if (material._occlusionMap && material._occlusionMap._state.texture && this._uOcclusionMap) {
256
- program.bindTexture(this._uOcclusionMap, material._occlusionMap._state.texture, frameCtx.textureUnit);
257
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
258
- frameCtx.bindTexture++;
259
- if (this._uOcclusionMapMatrix) {
260
- gl.uniformMatrix4fv(this._uOcclusionMapMatrix, false, material._occlusionMap._state.matrix);
261
- }
262
- }
263
- if (material._diffuseFresnel) {
264
- if (this._uDiffuseFresnelEdgeBias) {
265
- gl.uniform1f(this._uDiffuseFresnelEdgeBias, material._diffuseFresnel.edgeBias);
266
- }
267
- if (this._uDiffuseFresnelCenterBias) {
268
- gl.uniform1f(this._uDiffuseFresnelCenterBias, material._diffuseFresnel.centerBias);
269
- }
270
- if (this._uDiffuseFresnelEdgeColor) {
271
- gl.uniform3fv(this._uDiffuseFresnelEdgeColor, material._diffuseFresnel.edgeColor);
272
- }
273
- if (this._uDiffuseFresnelCenterColor) {
274
- gl.uniform3fv(this._uDiffuseFresnelCenterColor, material._diffuseFresnel.centerColor);
275
- }
276
- if (this._uDiffuseFresnelPower) {
277
- gl.uniform1f(this._uDiffuseFresnelPower, material._diffuseFresnel.power);
278
- }
279
- }
280
- if (material._specularFresnel) {
281
- if (this._uSpecularFresnelEdgeBias) {
282
- gl.uniform1f(this._uSpecularFresnelEdgeBias, material._specularFresnel.edgeBias);
283
- }
284
- if (this._uSpecularFresnelCenterBias) {
285
- gl.uniform1f(this._uSpecularFresnelCenterBias, material._specularFresnel.centerBias);
286
- }
287
- if (this._uSpecularFresnelEdgeColor) {
288
- gl.uniform3fv(this._uSpecularFresnelEdgeColor, material._specularFresnel.edgeColor);
289
- }
290
- if (this._uSpecularFresnelCenterColor) {
291
- gl.uniform3fv(this._uSpecularFresnelCenterColor, material._specularFresnel.centerColor);
292
- }
293
- if (this._uSpecularFresnelPower) {
294
- gl.uniform1f(this._uSpecularFresnelPower, material._specularFresnel.power);
295
- }
296
- }
297
- if (material._alphaFresnel) {
298
- if (this._uAlphaFresnelEdgeBias) {
299
- gl.uniform1f(this._uAlphaFresnelEdgeBias, material._alphaFresnel.edgeBias);
300
- }
301
- if (this._uAlphaFresnelCenterBias) {
302
- gl.uniform1f(this._uAlphaFresnelCenterBias, material._alphaFresnel.centerBias);
303
- }
304
- if (this._uAlphaFresnelEdgeColor) {
305
- gl.uniform3fv(this._uAlphaFresnelEdgeColor, material._alphaFresnel.edgeColor);
306
- }
307
- if (this._uAlphaFresnelCenterColor) {
308
- gl.uniform3fv(this._uAlphaFresnelCenterColor, material._alphaFresnel.centerColor);
309
- }
310
- if (this._uAlphaFresnelPower) {
311
- gl.uniform1f(this._uAlphaFresnelPower, material._alphaFresnel.power);
312
- }
313
- }
314
- if (material._reflectivityFresnel) {
315
- if (this._uReflectivityFresnelEdgeBias) {
316
- gl.uniform1f(this._uReflectivityFresnelEdgeBias, material._reflectivityFresnel.edgeBias);
317
- }
318
- if (this._uReflectivityFresnelCenterBias) {
319
- gl.uniform1f(this._uReflectivityFresnelCenterBias, material._reflectivityFresnel.centerBias);
320
- }
321
- if (this._uReflectivityFresnelEdgeColor) {
322
- gl.uniform3fv(this._uReflectivityFresnelEdgeColor, material._reflectivityFresnel.edgeColor);
323
- }
324
- if (this._uReflectivityFresnelCenterColor) {
325
- gl.uniform3fv(this._uReflectivityFresnelCenterColor, material._reflectivityFresnel.centerColor);
326
- }
327
- if (this._uReflectivityFresnelPower) {
328
- gl.uniform1f(this._uReflectivityFresnelPower, material._reflectivityFresnel.power);
329
- }
330
- }
331
- if (material._emissiveFresnel) {
332
- if (this._uEmissiveFresnelEdgeBias) {
333
- gl.uniform1f(this._uEmissiveFresnelEdgeBias, material._emissiveFresnel.edgeBias);
334
- }
335
- if (this._uEmissiveFresnelCenterBias) {
336
- gl.uniform1f(this._uEmissiveFresnelCenterBias, material._emissiveFresnel.centerBias);
337
- }
338
- if (this._uEmissiveFresnelEdgeColor) {
339
- gl.uniform3fv(this._uEmissiveFresnelEdgeColor, material._emissiveFresnel.edgeColor);
340
- }
341
- if (this._uEmissiveFresnelCenterColor) {
342
- gl.uniform3fv(this._uEmissiveFresnelCenterColor, material._emissiveFresnel.centerColor);
343
- }
344
- if (this._uEmissiveFresnelPower) {
345
- gl.uniform1f(this._uEmissiveFresnelPower, material._emissiveFresnel.power);
346
- }
347
- }
348
- break;
349
-
350
- case "MetallicMaterial":
351
- if (this._uBaseColor) {
352
- gl.uniform3fv(this._uBaseColor, materialState.baseColor);
353
- }
354
- if (this._uMaterialMetallic) {
355
- gl.uniform1f(this._uMaterialMetallic, materialState.metallic);
356
- }
357
- if (this._uMaterialRoughness) {
358
- gl.uniform1f(this._uMaterialRoughness, materialState.roughness);
359
- }
360
- if (this._uMaterialSpecularF0) {
361
- gl.uniform1f(this._uMaterialSpecularF0, materialState.specularF0);
362
- }
363
- if (this._uMaterialEmissive) {
364
- gl.uniform3fv(this._uMaterialEmissive, materialState.emissive);
365
- }
366
- if (this._uAlphaModeCutoff) {
367
- gl.uniform4f(
368
- this._uAlphaModeCutoff,
369
- 1.0 * materialState.alpha,
370
- materialState.alphaMode === 1 ? 1.0 : 0.0,
371
- materialState.alphaCutoff,
372
- 0.0);
373
- }
374
- const baseColorMap = material._baseColorMap;
375
- if (baseColorMap && baseColorMap._state.texture && this._uBaseColorMap) {
376
- program.bindTexture(this._uBaseColorMap, baseColorMap._state.texture, frameCtx.textureUnit);
377
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
378
- frameCtx.bindTexture++;
379
- if (this._uBaseColorMapMatrix) {
380
- gl.uniformMatrix4fv(this._uBaseColorMapMatrix, false, baseColorMap._state.matrix);
381
- }
382
- }
383
- const metallicMap = material._metallicMap;
384
- if (metallicMap && metallicMap._state.texture && this._uMetallicMap) {
385
- program.bindTexture(this._uMetallicMap, metallicMap._state.texture, frameCtx.textureUnit);
386
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
387
- frameCtx.bindTexture++;
388
- if (this._uMetallicMapMatrix) {
389
- gl.uniformMatrix4fv(this._uMetallicMapMatrix, false, metallicMap._state.matrix);
390
- }
391
- }
392
- const roughnessMap = material._roughnessMap;
393
- if (roughnessMap && roughnessMap._state.texture && this._uRoughnessMap) {
394
- program.bindTexture(this._uRoughnessMap, roughnessMap._state.texture, frameCtx.textureUnit);
395
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
396
- frameCtx.bindTexture++;
397
- if (this._uRoughnessMapMatrix) {
398
- gl.uniformMatrix4fv(this._uRoughnessMapMatrix, false, roughnessMap._state.matrix);
399
- }
400
- }
401
- const metallicRoughnessMap = material._metallicRoughnessMap;
402
- if (metallicRoughnessMap && metallicRoughnessMap._state.texture && this._uMetallicRoughnessMap) {
403
- program.bindTexture(this._uMetallicRoughnessMap, metallicRoughnessMap._state.texture, frameCtx.textureUnit);
404
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
405
- frameCtx.bindTexture++;
406
- if (this._uMetallicRoughnessMapMatrix) {
407
- gl.uniformMatrix4fv(this._uMetallicRoughnessMapMatrix, false, metallicRoughnessMap._state.matrix);
408
- }
409
- }
410
- var emissiveMap = material._emissiveMap;
411
- if (emissiveMap && emissiveMap._state.texture && this._uEmissiveMap) {
412
- program.bindTexture(this._uEmissiveMap, emissiveMap._state.texture, frameCtx.textureUnit);
413
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
414
- frameCtx.bindTexture++;
415
- if (this._uEmissiveMapMatrix) {
416
- gl.uniformMatrix4fv(this._uEmissiveMapMatrix, false, emissiveMap._state.matrix);
417
- }
418
- }
419
- var occlusionMap = material._occlusionMap;
420
- if (occlusionMap && material._occlusionMap._state.texture && this._uOcclusionMap) {
421
- program.bindTexture(this._uOcclusionMap, occlusionMap._state.texture, frameCtx.textureUnit);
422
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
423
- frameCtx.bindTexture++;
424
- if (this._uOcclusionMapMatrix) {
425
- gl.uniformMatrix4fv(this._uOcclusionMapMatrix, false, occlusionMap._state.matrix);
426
- }
427
- }
428
- var alphaMap = material._alphaMap;
429
- if (alphaMap && alphaMap._state.texture && this._uAlphaMap) {
430
- program.bindTexture(this._uAlphaMap, alphaMap._state.texture, frameCtx.textureUnit);
431
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
432
- frameCtx.bindTexture++;
433
- if (this._uAlphaMapMatrix) {
434
- gl.uniformMatrix4fv(this._uAlphaMapMatrix, false, alphaMap._state.matrix);
435
- }
436
- }
437
- var normalMap = material._normalMap;
438
- if (normalMap && normalMap._state.texture && this._uNormalMap) {
439
- program.bindTexture(this._uNormalMap, normalMap._state.texture, frameCtx.textureUnit);
440
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
441
- frameCtx.bindTexture++;
442
- if (this._uNormalMapMatrix) {
443
- gl.uniformMatrix4fv(this._uNormalMapMatrix, false, normalMap._state.matrix);
444
- }
445
- }
446
- break;
447
-
448
- case "SpecularMaterial":
449
- if (this._uMaterialDiffuse) {
450
- gl.uniform3fv(this._uMaterialDiffuse, materialState.diffuse);
451
- }
452
- if (this._uMaterialSpecular) {
453
- gl.uniform3fv(this._uMaterialSpecular, materialState.specular);
454
- }
455
- if (this._uMaterialGlossiness) {
456
- gl.uniform1f(this._uMaterialGlossiness, materialState.glossiness);
457
- }
458
- if (this._uMaterialReflectivity) {
459
- gl.uniform1f(this._uMaterialReflectivity, materialState.reflectivity);
460
- }
461
- if (this._uMaterialEmissive) {
462
- gl.uniform3fv(this._uMaterialEmissive, materialState.emissive);
463
- }
464
- if (this._uAlphaModeCutoff) {
465
- gl.uniform4f(
466
- this._uAlphaModeCutoff,
467
- 1.0 * materialState.alpha,
468
- materialState.alphaMode === 1 ? 1.0 : 0.0,
469
- materialState.alphaCutoff,
470
- 0.0);
471
- }
472
- const diffuseMap = material._diffuseMap;
473
- if (diffuseMap && diffuseMap._state.texture && this._uDiffuseMap) {
474
- program.bindTexture(this._uDiffuseMap, diffuseMap._state.texture, frameCtx.textureUnit);
475
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
476
- frameCtx.bindTexture++;
477
- if (this._uDiffuseMapMatrix) {
478
- gl.uniformMatrix4fv(this._uDiffuseMapMatrix, false, diffuseMap._state.matrix);
479
- }
480
- }
481
- const specularMap = material._specularMap;
482
- if (specularMap && specularMap._state.texture && this._uSpecularMap) {
483
- program.bindTexture(this._uSpecularMap, specularMap._state.texture, frameCtx.textureUnit);
484
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
485
- frameCtx.bindTexture++;
486
- if (this._uSpecularMapMatrix) {
487
- gl.uniformMatrix4fv(this._uSpecularMapMatrix, false, specularMap._state.matrix);
488
- }
489
- }
490
- const glossinessMap = material._glossinessMap;
491
- if (glossinessMap && glossinessMap._state.texture && this._uGlossinessMap) {
492
- program.bindTexture(this._uGlossinessMap, glossinessMap._state.texture, frameCtx.textureUnit);
493
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
494
- frameCtx.bindTexture++;
495
- if (this._uGlossinessMapMatrix) {
496
- gl.uniformMatrix4fv(this._uGlossinessMapMatrix, false, glossinessMap._state.matrix);
497
- }
498
- }
499
- const specularGlossinessMap = material._specularGlossinessMap;
500
- if (specularGlossinessMap && specularGlossinessMap._state.texture && this._uSpecularGlossinessMap) {
501
- program.bindTexture(this._uSpecularGlossinessMap, specularGlossinessMap._state.texture, frameCtx.textureUnit);
502
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
503
- frameCtx.bindTexture++;
504
- if (this._uSpecularGlossinessMapMatrix) {
505
- gl.uniformMatrix4fv(this._uSpecularGlossinessMapMatrix, false, specularGlossinessMap._state.matrix);
506
- }
507
- }
508
- var emissiveMap = material._emissiveMap;
509
- if (emissiveMap && emissiveMap._state.texture && this._uEmissiveMap) {
510
- program.bindTexture(this._uEmissiveMap, emissiveMap._state.texture, frameCtx.textureUnit);
511
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
512
- frameCtx.bindTexture++;
513
- if (this._uEmissiveMapMatrix) {
514
- gl.uniformMatrix4fv(this._uEmissiveMapMatrix, false, emissiveMap._state.matrix);
515
- }
516
- }
517
- var occlusionMap = material._occlusionMap;
518
- if (occlusionMap && occlusionMap._state.texture && this._uOcclusionMap) {
519
- program.bindTexture(this._uOcclusionMap, occlusionMap._state.texture, frameCtx.textureUnit);
520
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
521
- frameCtx.bindTexture++;
522
- if (this._uOcclusionMapMatrix) {
523
- gl.uniformMatrix4fv(this._uOcclusionMapMatrix, false, occlusionMap._state.matrix);
524
- }
525
- }
526
- var alphaMap = material._alphaMap;
527
- if (alphaMap && alphaMap._state.texture && this._uAlphaMap) {
528
- program.bindTexture(this._uAlphaMap, alphaMap._state.texture, frameCtx.textureUnit);
529
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
530
- frameCtx.bindTexture++;
531
- if (this._uAlphaMapMatrix) {
532
- gl.uniformMatrix4fv(this._uAlphaMapMatrix, false, alphaMap._state.matrix);
533
- }
534
- }
535
- var normalMap = material._normalMap;
536
- if (normalMap && normalMap._state.texture && this._uNormalMap) {
537
- program.bindTexture(this._uNormalMap, normalMap._state.texture, frameCtx.textureUnit);
538
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
539
- frameCtx.bindTexture++;
540
- if (this._uNormalMapMatrix) {
541
- gl.uniformMatrix4fv(this._uNormalMapMatrix, false, normalMap._state.matrix);
542
- }
543
- }
544
- break;
545
- }
546
- this._lastMaterialId = materialState.id;
547
- }
548
-
549
- gl.uniformMatrix4fv(this._uModelMatrix, gl.FALSE, mesh.worldMatrix);
550
- if (this._uModelNormalMatrix) {
551
- gl.uniformMatrix4fv(this._uModelNormalMatrix, gl.FALSE, mesh.worldNormalMatrix);
552
- }
553
-
554
- if (this._uClippable) {
555
- gl.uniform1i(this._uClippable, meshState.clippable);
556
- }
557
-
558
- if (this._uColorize) {
559
- const colorize = meshState.colorize;
560
- const lastColorize = this._lastColorize;
561
- if (lastColorize[0] !== colorize[0] ||
562
- lastColorize[1] !== colorize[1] ||
563
- lastColorize[2] !== colorize[2] ||
564
- lastColorize[3] !== colorize[3]) {
565
- gl.uniform4fv(this._uColorize, colorize);
566
- lastColorize[0] = colorize[0];
567
- lastColorize[1] = colorize[1];
568
- lastColorize[2] = colorize[2];
569
- lastColorize[3] = colorize[3];
570
- }
571
- }
572
-
573
- gl.uniform3fv(this._uOffset, meshState.offset);
574
-
575
- // Bind VBOs
576
-
577
- if (geometryState.id !== this._lastGeometryId) {
578
- if (this._uPositionsDecodeMatrix) {
579
- gl.uniformMatrix4fv(this._uPositionsDecodeMatrix, false, geometryState.positionsDecodeMatrix);
580
- }
581
- if (this._uUVDecodeMatrix) {
582
- gl.uniformMatrix3fv(this._uUVDecodeMatrix, false, geometryState.uvDecodeMatrix);
583
- }
584
- if (this._aPosition) {
585
- this._aPosition.bindArrayBuffer(geometryState.positionsBuf);
586
- frameCtx.bindArray++;
587
- }
588
- if (this._aNormal) {
589
- this._aNormal.bindArrayBuffer(geometryState.normalsBuf);
590
- frameCtx.bindArray++;
591
- }
592
- if (this._aUV) {
593
- this._aUV.bindArrayBuffer(geometryState.uvBuf);
594
- frameCtx.bindArray++;
595
- }
596
- if (this._aColor) {
597
- this._aColor.bindArrayBuffer(geometryState.colorsBuf);
598
- frameCtx.bindArray++;
599
- }
600
- if (this._aFlags) {
601
- this._aFlags.bindArrayBuffer(geometryState.flagsBuf);
602
- frameCtx.bindArray++;
603
- }
604
- if (geometryState.indicesBuf) {
605
- geometryState.indicesBuf.bind();
606
- frameCtx.bindArray++;
607
- }
608
- this._lastGeometryId = geometryState.id;
609
- }
610
-
611
- // Draw (indices bound in prev step)
612
-
613
- if (geometryState.indicesBuf) {
614
- gl.drawElements(geometryState.primitive, geometryState.indicesBuf.numItems, geometryState.indicesBuf.itemType, 0);
615
- frameCtx.drawElements++;
616
- } else if (geometryState.positions) {
617
- gl.drawArrays(gl.TRIANGLES, 0, geometryState.positions.numItems);
618
- frameCtx.drawArrays++;
619
- }
620
-
621
- if (background) {
622
- gl.depthFunc(gl.LESS);
623
- }
624
- };
625
-
626
- DrawRenderer.prototype._allocate = function (mesh) {
627
- const scene = mesh.scene;
628
- const gl = scene.canvas.gl;
629
- const material = mesh._material;
630
- const lightsState = scene._lightsState;
631
- const sectionPlanesState = scene._sectionPlanesState;
632
- const materialState = mesh._material._state;
633
-
634
- this._program = new Program(gl, this._shaderSource);
635
- if (this._program.errors) {
636
- this.errors = this._program.errors;
637
- return;
638
- }
639
- const program = this._program;
640
- this._uPositionsDecodeMatrix = program.getLocation("positionsDecodeMatrix");
641
- this._uUVDecodeMatrix = program.getLocation("uvDecodeMatrix");
642
- this._uModelMatrix = program.getLocation("modelMatrix");
643
- this._uModelNormalMatrix = program.getLocation("modelNormalMatrix");
644
- this._uViewMatrix = program.getLocation("viewMatrix");
645
- this._uViewNormalMatrix = program.getLocation("viewNormalMatrix");
646
- this._uProjMatrix = program.getLocation("projMatrix");
647
- this._uGammaFactor = program.getLocation("gammaFactor");
648
- this._uLightAmbient = [];
649
- this._uLightColor = [];
650
- this._uLightDir = [];
651
- this._uLightPos = [];
652
- this._uLightAttenuation = [];
653
- this._uShadowViewMatrix = [];
654
- this._uShadowProjMatrix = [];
655
-
656
- if (scene.logarithmicDepthBufferEnabled) {
657
- this._uLogDepthBufFC = program.getLocation("logDepthBufFC");
658
- }
659
-
660
- const lights = lightsState.lights;
661
- let light;
662
-
663
- for (var i = 0, len = lights.length; i < len; i++) {
664
- light = lights[i];
665
- switch (light.type) {
666
-
667
- case "ambient":
668
- this._uLightAmbient[i] = program.getLocation("lightAmbient");
669
- break;
670
-
671
- case "dir":
672
- this._uLightColor[i] = program.getLocation("lightColor" + i);
673
- this._uLightPos[i] = null;
674
- this._uLightDir[i] = program.getLocation("lightDir" + i);
675
- break;
676
-
677
- case "point":
678
- this._uLightColor[i] = program.getLocation("lightColor" + i);
679
- this._uLightPos[i] = program.getLocation("lightPos" + i);
680
- this._uLightDir[i] = null;
681
- this._uLightAttenuation[i] = program.getLocation("lightAttenuation" + i);
682
- break;
683
-
684
- case "spot":
685
- this._uLightColor[i] = program.getLocation("lightColor" + i);
686
- this._uLightPos[i] = program.getLocation("lightPos" + i);
687
- this._uLightDir[i] = program.getLocation("lightDir" + i);
688
- this._uLightAttenuation[i] = program.getLocation("lightAttenuation" + i);
689
- break;
690
- }
691
-
692
- if (light.castsShadow) {
693
- this._uShadowViewMatrix[i] = program.getLocation("shadowViewMatrix" + i);
694
- this._uShadowProjMatrix[i] = program.getLocation("shadowProjMatrix" + i);
695
- }
696
- }
697
-
698
- if (lightsState.lightMaps.length > 0) {
699
- this._uLightMap = "lightMap";
700
- }
701
-
702
- if (lightsState.reflectionMaps.length > 0) {
703
- this._uReflectionMap = "reflectionMap";
704
- }
705
-
706
- this._uSectionPlanes = [];
707
- const sectionPlanes = sectionPlanesState.sectionPlanes;
708
- for (var i = 0, len = sectionPlanes.length; i < len; i++) {
709
- this._uSectionPlanes.push({
710
- active: program.getLocation("sectionPlaneActive" + i),
711
- pos: program.getLocation("sectionPlanePos" + i),
712
- dir: program.getLocation("sectionPlaneDir" + i)
713
- });
714
- }
715
-
716
- this._uPointSize = program.getLocation("pointSize");
717
-
718
- switch (materialState.type) {
719
- case "LambertMaterial":
720
- this._uMaterialColor = program.getLocation("materialColor");
721
- this._uMaterialEmissive = program.getLocation("materialEmissive");
722
- this._uAlphaModeCutoff = program.getLocation("materialAlphaModeCutoff");
723
- break;
724
-
725
- case "PhongMaterial":
726
- this._uMaterialAmbient = program.getLocation("materialAmbient");
727
- this._uMaterialDiffuse = program.getLocation("materialDiffuse");
728
- this._uMaterialSpecular = program.getLocation("materialSpecular");
729
- this._uMaterialEmissive = program.getLocation("materialEmissive");
730
- this._uAlphaModeCutoff = program.getLocation("materialAlphaModeCutoff");
731
- this._uMaterialShininess = program.getLocation("materialShininess");
732
- if (material._ambientMap) {
733
- this._uMaterialAmbientMap = "ambientMap";
734
- this._uMaterialAmbientMapMatrix = program.getLocation("ambientMapMatrix");
735
- }
736
- if (material._diffuseMap) {
737
- this._uDiffuseMap = "diffuseMap";
738
- this._uDiffuseMapMatrix = program.getLocation("diffuseMapMatrix");
739
- }
740
- if (material._specularMap) {
741
- this._uSpecularMap = "specularMap";
742
- this._uSpecularMapMatrix = program.getLocation("specularMapMatrix");
743
- }
744
- if (material._emissiveMap) {
745
- this._uEmissiveMap = "emissiveMap";
746
- this._uEmissiveMapMatrix = program.getLocation("emissiveMapMatrix");
747
- }
748
- if (material._alphaMap) {
749
- this._uAlphaMap = "alphaMap";
750
- this._uAlphaMapMatrix = program.getLocation("alphaMapMatrix");
751
- }
752
- if (material._reflectivityMap) {
753
- this._uReflectivityMap = "reflectivityMap";
754
- this._uReflectivityMapMatrix = program.getLocation("reflectivityMapMatrix");
755
- }
756
- if (material._normalMap) {
757
- this._uNormalMap = "normalMap";
758
- this._uNormalMapMatrix = program.getLocation("normalMapMatrix");
759
- }
760
- if (material._occlusionMap) {
761
- this._uOcclusionMap = "occlusionMap";
762
- this._uOcclusionMapMatrix = program.getLocation("occlusionMapMatrix");
763
- }
764
- if (material._diffuseFresnel) {
765
- this._uDiffuseFresnelEdgeBias = program.getLocation("diffuseFresnelEdgeBias");
766
- this._uDiffuseFresnelCenterBias = program.getLocation("diffuseFresnelCenterBias");
767
- this._uDiffuseFresnelEdgeColor = program.getLocation("diffuseFresnelEdgeColor");
768
- this._uDiffuseFresnelCenterColor = program.getLocation("diffuseFresnelCenterColor");
769
- this._uDiffuseFresnelPower = program.getLocation("diffuseFresnelPower");
770
- }
771
- if (material._specularFresnel) {
772
- this._uSpecularFresnelEdgeBias = program.getLocation("specularFresnelEdgeBias");
773
- this._uSpecularFresnelCenterBias = program.getLocation("specularFresnelCenterBias");
774
- this._uSpecularFresnelEdgeColor = program.getLocation("specularFresnelEdgeColor");
775
- this._uSpecularFresnelCenterColor = program.getLocation("specularFresnelCenterColor");
776
- this._uSpecularFresnelPower = program.getLocation("specularFresnelPower");
777
- }
778
- if (material._alphaFresnel) {
779
- this._uAlphaFresnelEdgeBias = program.getLocation("alphaFresnelEdgeBias");
780
- this._uAlphaFresnelCenterBias = program.getLocation("alphaFresnelCenterBias");
781
- this._uAlphaFresnelEdgeColor = program.getLocation("alphaFresnelEdgeColor");
782
- this._uAlphaFresnelCenterColor = program.getLocation("alphaFresnelCenterColor");
783
- this._uAlphaFresnelPower = program.getLocation("alphaFresnelPower");
784
- }
785
- if (material._reflectivityFresnel) {
786
- this._uReflectivityFresnelEdgeBias = program.getLocation("reflectivityFresnelEdgeBias");
787
- this._uReflectivityFresnelCenterBias = program.getLocation("reflectivityFresnelCenterBias");
788
- this._uReflectivityFresnelEdgeColor = program.getLocation("reflectivityFresnelEdgeColor");
789
- this._uReflectivityFresnelCenterColor = program.getLocation("reflectivityFresnelCenterColor");
790
- this._uReflectivityFresnelPower = program.getLocation("reflectivityFresnelPower");
791
- }
792
- if (material._emissiveFresnel) {
793
- this._uEmissiveFresnelEdgeBias = program.getLocation("emissiveFresnelEdgeBias");
794
- this._uEmissiveFresnelCenterBias = program.getLocation("emissiveFresnelCenterBias");
795
- this._uEmissiveFresnelEdgeColor = program.getLocation("emissiveFresnelEdgeColor");
796
- this._uEmissiveFresnelCenterColor = program.getLocation("emissiveFresnelCenterColor");
797
- this._uEmissiveFresnelPower = program.getLocation("emissiveFresnelPower");
798
- }
799
- break;
800
-
801
- case "MetallicMaterial":
802
- this._uBaseColor = program.getLocation("materialBaseColor");
803
- this._uMaterialMetallic = program.getLocation("materialMetallic");
804
- this._uMaterialRoughness = program.getLocation("materialRoughness");
805
- this._uMaterialSpecularF0 = program.getLocation("materialSpecularF0");
806
- this._uMaterialEmissive = program.getLocation("materialEmissive");
807
- this._uAlphaModeCutoff = program.getLocation("materialAlphaModeCutoff");
808
- if (material._baseColorMap) {
809
- this._uBaseColorMap = "baseColorMap";
810
- this._uBaseColorMapMatrix = program.getLocation("baseColorMapMatrix");
811
- }
812
- if (material._metallicMap) {
813
- this._uMetallicMap = "metallicMap";
814
- this._uMetallicMapMatrix = program.getLocation("metallicMapMatrix");
815
- }
816
- if (material._roughnessMap) {
817
- this._uRoughnessMap = "roughnessMap";
818
- this._uRoughnessMapMatrix = program.getLocation("roughnessMapMatrix");
819
- }
820
- if (material._metallicRoughnessMap) {
821
- this._uMetallicRoughnessMap = "metallicRoughnessMap";
822
- this._uMetallicRoughnessMapMatrix = program.getLocation("metallicRoughnessMapMatrix");
823
- }
824
- if (material._emissiveMap) {
825
- this._uEmissiveMap = "emissiveMap";
826
- this._uEmissiveMapMatrix = program.getLocation("emissiveMapMatrix");
827
- }
828
- if (material._occlusionMap) {
829
- this._uOcclusionMap = "occlusionMap";
830
- this._uOcclusionMapMatrix = program.getLocation("occlusionMapMatrix");
831
- }
832
- if (material._alphaMap) {
833
- this._uAlphaMap = "alphaMap";
834
- this._uAlphaMapMatrix = program.getLocation("alphaMapMatrix");
835
- }
836
- if (material._normalMap) {
837
- this._uNormalMap = "normalMap";
838
- this._uNormalMapMatrix = program.getLocation("normalMapMatrix");
839
- }
840
- break;
841
-
842
- case "SpecularMaterial":
843
- this._uMaterialDiffuse = program.getLocation("materialDiffuse");
844
- this._uMaterialSpecular = program.getLocation("materialSpecular");
845
- this._uMaterialGlossiness = program.getLocation("materialGlossiness");
846
- this._uMaterialReflectivity = program.getLocation("reflectivityFresnel");
847
- this._uMaterialEmissive = program.getLocation("materialEmissive");
848
- this._uAlphaModeCutoff = program.getLocation("materialAlphaModeCutoff");
849
- if (material._diffuseMap) {
850
- this._uDiffuseMap = "diffuseMap";
851
- this._uDiffuseMapMatrix = program.getLocation("diffuseMapMatrix");
852
- }
853
- if (material._specularMap) {
854
- this._uSpecularMap = "specularMap";
855
- this._uSpecularMapMatrix = program.getLocation("specularMapMatrix");
856
- }
857
- if (material._glossinessMap) {
858
- this._uGlossinessMap = "glossinessMap";
859
- this._uGlossinessMapMatrix = program.getLocation("glossinessMapMatrix");
860
- }
861
- if (material._specularGlossinessMap) {
862
- this._uSpecularGlossinessMap = "materialSpecularGlossinessMap";
863
- this._uSpecularGlossinessMapMatrix = program.getLocation("materialSpecularGlossinessMapMatrix");
864
- }
865
- if (material._emissiveMap) {
866
- this._uEmissiveMap = "emissiveMap";
867
- this._uEmissiveMapMatrix = program.getLocation("emissiveMapMatrix");
868
- }
869
- if (material._occlusionMap) {
870
- this._uOcclusionMap = "occlusionMap";
871
- this._uOcclusionMapMatrix = program.getLocation("occlusionMapMatrix");
872
- }
873
- if (material._alphaMap) {
874
- this._uAlphaMap = "alphaMap";
875
- this._uAlphaMapMatrix = program.getLocation("alphaMapMatrix");
876
- }
877
- if (material._normalMap) {
878
- this._uNormalMap = "normalMap";
879
- this._uNormalMapMatrix = program.getLocation("normalMapMatrix");
880
- }
881
- break;
882
- }
883
-
884
- this._aPosition = program.getAttribute("position");
885
- this._aNormal = program.getAttribute("normal");
886
- this._aUV = program.getAttribute("uv");
887
- this._aColor = program.getAttribute("color");
888
- this._aFlags = program.getAttribute("flags");
889
-
890
- this._uClippable = program.getLocation("clippable");
891
- this._uColorize = program.getLocation("colorize");
892
- this._uOffset = program.getLocation("offset");
893
-
894
- this._lastMaterialId = null;
895
- this._lastVertexBufsId = null;
896
- this._lastGeometryId = null;
897
-
898
- this._lastColorize = new Float32Array(4);
899
-
900
- this._baseTextureUnit = 0;
901
-
902
- };
903
-
904
- DrawRenderer.prototype._bindProgram = function (frameCtx) {
905
-
906
- const maxTextureUnits = WEBGL_INFO.MAX_TEXTURE_UNITS;
907
- const scene = this._scene;
908
- const gl = scene.canvas.gl;
909
- const lightsState = scene._lightsState;
910
- const project = scene.camera.project;
911
- let light;
912
-
913
- const program = this._program;
914
-
915
- program.bind();
916
-
917
- frameCtx.useProgram++;
918
- frameCtx.textureUnit = 0;
919
-
920
- this._lastMaterialId = null;
921
- this._lastVertexBufsId = null;
922
- this._lastGeometryId = null;
923
-
924
- this._lastColorize[0] = -1;
925
- this._lastColorize[1] = -1;
926
- this._lastColorize[2] = -1;
927
- this._lastColorize[3] = -1;
928
-
929
- gl.uniformMatrix4fv(this._uProjMatrix, false, project.matrix);
930
-
931
- if (scene.logarithmicDepthBufferEnabled) {
932
- const logDepthBufFC = 2.0 / (Math.log(project.far + 1.0) / Math.LN2);
933
- gl.uniform1f(this._uLogDepthBufFC, logDepthBufFC);
934
- }
935
-
936
- for (var i = 0, len = lightsState.lights.length; i < len; i++) {
937
-
938
- light = lightsState.lights[i];
939
-
940
- if (this._uLightAmbient[i]) {
941
- gl.uniform4f(this._uLightAmbient[i], light.color[0], light.color[1], light.color[2], light.intensity);
942
-
943
- } else {
944
-
945
- if (this._uLightColor[i]) {
946
- gl.uniform4f(this._uLightColor[i], light.color[0], light.color[1], light.color[2], light.intensity);
947
- }
948
-
949
- if (this._uLightPos[i]) {
950
- gl.uniform3fv(this._uLightPos[i], light.pos);
951
- if (this._uLightAttenuation[i]) {
952
- gl.uniform1f(this._uLightAttenuation[i], light.attenuation);
953
- }
954
- }
955
-
956
- if (this._uLightDir[i]) {
957
- gl.uniform3fv(this._uLightDir[i], light.dir);
958
- }
959
-
960
- if (light.castsShadow) {
961
- if (this._uShadowViewMatrix[i]) {
962
- gl.uniformMatrix4fv(this._uShadowViewMatrix[i], false, light.getShadowViewMatrix());
963
- }
964
- if (this._uShadowProjMatrix[i]) {
965
- gl.uniformMatrix4fv(this._uShadowProjMatrix[i], false, light.getShadowProjMatrix());
966
- }
967
- const shadowRenderBuf = light.getShadowRenderBuf();
968
- if (shadowRenderBuf) {
969
- program.bindTexture("shadowMap" + i, shadowRenderBuf.getTexture(), frameCtx.textureUnit);
970
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
971
- frameCtx.bindTexture++;
972
- }
973
- }
974
- }
975
- }
976
-
977
- if (lightsState.lightMaps.length > 0 && lightsState.lightMaps[0].texture && this._uLightMap) {
978
- program.bindTexture(this._uLightMap, lightsState.lightMaps[0].texture, frameCtx.textureUnit);
979
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
980
- frameCtx.bindTexture++;
981
- }
982
-
983
- if (lightsState.reflectionMaps.length > 0 && lightsState.reflectionMaps[0].texture && this._uReflectionMap) {
984
- program.bindTexture(this._uReflectionMap, lightsState.reflectionMaps[0].texture, frameCtx.textureUnit);
985
- frameCtx.textureUnit = (frameCtx.textureUnit + 1) % maxTextureUnits;
986
- frameCtx.bindTexture++;
987
- }
988
-
989
- if (this._uGammaFactor) {
990
- gl.uniform1f(this._uGammaFactor, scene.gammaFactor);
991
- }
992
-
993
- this._baseTextureUnit = frameCtx.textureUnit;
994
- };
995
-
996
- export {DrawRenderer};