@xeokit/xeokit-sdk 2.6.29 → 2.6.30
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.
- package/dist/xeokit-sdk.cjs.js +510 -429
- package/dist/xeokit-sdk.es.js +510 -429
- package/dist/xeokit-sdk.es5.js +315 -328
- package/dist/xeokit-sdk.min.cjs.js +4 -4
- package/dist/xeokit-sdk.min.es.js +4 -4
- package/dist/xeokit-sdk.min.es5.js +3 -3
- package/package.json +1 -1
- package/src/plugins/GLTFLoaderPlugin/GLTFLoaderPlugin.js +2 -110
- package/src/plugins/GLTFLoaderPlugin/GLTFSceneModelLoader.js +252 -222
- package/src/viewer/metadata/MetaScene.js +0 -2
- package/src/viewer/scene/model/SceneModel.js +9 -0
- package/src/viewer/scene/model/SceneModelTextureSet.js +5 -0
- package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesSnapInitRenderer.js +8 -0
- package/src/viewer/scene/model/dtx/triangles/renderers/DTXTrianglesSnapRenderer.js +8 -0
- package/src/viewer/scene/model/vbo/VBORenderer.js +10 -1
- package/src/viewer/scene/model/vbo/batching/lines/renderers/VBOBatchingLinesSnapRenderer.js +1 -1
- package/src/viewer/scene/model/vbo/batching/triangles/VBOBatchingTrianglesLayer.js +26 -6
- package/src/viewer/scene/model/vbo/batching/triangles/renderers/Renderers.js +40 -12
- package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesBatchingRenderer.js +2 -3
- package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesColorTextureRenderer.js +25 -7
- package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesSnapRenderer.js +1 -1
- package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesSnapRenderer.js +1 -1
- package/src/viewer/scene/model/vbo/instancing/triangles/VBOInstancingTrianglesLayer.js +17 -4
- package/src/viewer/scene/model/vbo/instancing/triangles/renderers/Renderers.js +74 -47
- package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesColorTextureRenderer.js +29 -14
- package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesInstancingRenderer.js +5 -4
- package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesSnapRenderer.js +1 -1
- package/src/viewer/scene/webgl/occlusion/OcclusionLayer.js +1 -1
- package/src/viewer/scene/webgl/occlusion/OcclusionTester.js +1 -4
|
@@ -872,14 +872,21 @@ export class VBOBatchingTrianglesLayer {
|
|
|
872
872
|
return;
|
|
873
873
|
}
|
|
874
874
|
this._updateBackfaceCull(renderFlags, frameCtx);
|
|
875
|
+
const useAlphaCutoff = this._state.textureSet && (typeof(this._state.textureSet.alphaCutoff) === "number");
|
|
875
876
|
if (frameCtx.withSAO && this.model.saoEnabled) {
|
|
876
877
|
if (frameCtx.pbrEnabled && this.model.pbrEnabled && this._state.pbrSupported) {
|
|
877
878
|
if (this._renderers.pbrRendererWithSAO) {
|
|
878
879
|
this._renderers.pbrRendererWithSAO.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
|
|
879
880
|
}
|
|
880
881
|
} else if (frameCtx.colorTextureEnabled && this.model.colorTextureEnabled && this._state.colorTextureSupported) {
|
|
881
|
-
if (
|
|
882
|
-
this._renderers.
|
|
882
|
+
if (useAlphaCutoff) {
|
|
883
|
+
if (this._renderers.colorTextureRendererWithSAOAlphaCutoff) {
|
|
884
|
+
this._renderers.colorTextureRendererWithSAOAlphaCutoff.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
|
|
885
|
+
}
|
|
886
|
+
} else {
|
|
887
|
+
if (this._renderers.colorTextureRendererWithSAO) {
|
|
888
|
+
this._renderers.colorTextureRendererWithSAO.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
|
|
889
|
+
}
|
|
883
890
|
}
|
|
884
891
|
} else if (this._state.normalsBuf) {
|
|
885
892
|
if (this._renderers.colorRendererWithSAO) {
|
|
@@ -896,8 +903,14 @@ export class VBOBatchingTrianglesLayer {
|
|
|
896
903
|
this._renderers.pbrRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
|
|
897
904
|
}
|
|
898
905
|
} else if (frameCtx.colorTextureEnabled && this.model.colorTextureEnabled && this._state.colorTextureSupported) {
|
|
899
|
-
if (
|
|
900
|
-
this._renderers.
|
|
906
|
+
if (useAlphaCutoff) {
|
|
907
|
+
if (this._renderers.colorTextureRendererAlphaCutoff) {
|
|
908
|
+
this._renderers.colorTextureRendererAlphaCutoff.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
|
|
909
|
+
}
|
|
910
|
+
} else {
|
|
911
|
+
if (this._renderers.colorTextureRenderer) {
|
|
912
|
+
this._renderers.colorTextureRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
|
|
913
|
+
}
|
|
901
914
|
}
|
|
902
915
|
} else if (this._state.normalsBuf) {
|
|
903
916
|
if (this._renderers.colorRenderer) {
|
|
@@ -934,8 +947,15 @@ export class VBOBatchingTrianglesLayer {
|
|
|
934
947
|
this._renderers.pbrRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_TRANSPARENT);
|
|
935
948
|
}
|
|
936
949
|
} else if (frameCtx.colorTextureEnabled && this.model.colorTextureEnabled && this._state.colorTextureSupported) {
|
|
937
|
-
|
|
938
|
-
|
|
950
|
+
const useAlphaCutoff = this._state.textureSet && (typeof(this._state.textureSet.alphaCutoff) === "number");
|
|
951
|
+
if (useAlphaCutoff) {
|
|
952
|
+
if (this._renderers.colorTextureRendererAlphaCutoff) {
|
|
953
|
+
this._renderers.colorTextureRendererAlphaCutoff.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_TRANSPARENT);
|
|
954
|
+
}
|
|
955
|
+
} else {
|
|
956
|
+
if (this._renderers.colorTextureRenderer) {
|
|
957
|
+
this._renderers.colorTextureRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_TRANSPARENT);
|
|
958
|
+
}
|
|
939
959
|
}
|
|
940
960
|
} else if (this._state.normalsBuf) {
|
|
941
961
|
if (this._renderers.colorRenderer) {
|
|
@@ -50,6 +50,14 @@ class Renderers {
|
|
|
50
50
|
this._colorTextureRendererWithSAO.destroy();
|
|
51
51
|
this._colorTextureRendererWithSAO = null;
|
|
52
52
|
}
|
|
53
|
+
if (this._colorTextureRendererAlphaCutoff && (!this._colorTextureRendererAlphaCutoff.getValid())) {
|
|
54
|
+
this._colorTextureRendererAlphaCutoff.destroy();
|
|
55
|
+
this._colorTextureRendererAlphaCutoff = null;
|
|
56
|
+
}
|
|
57
|
+
if (this._colorTextureRendererWithSAOAlphaCutoff && (!this._colorTextureRendererWithSAOAlphaCutoff.getValid())) {
|
|
58
|
+
this._colorTextureRendererWithSAOAlphaCutoff.destroy();
|
|
59
|
+
this._colorTextureRendererWithSAOAlphaCutoff = null;
|
|
60
|
+
}
|
|
53
61
|
if (this._pbrRenderer && (!this._pbrRenderer.getValid())) {
|
|
54
62
|
this._pbrRenderer.destroy();
|
|
55
63
|
this._pbrRenderer = null;
|
|
@@ -177,6 +185,20 @@ class Renderers {
|
|
|
177
185
|
return this._colorTextureRendererWithSAO;
|
|
178
186
|
}
|
|
179
187
|
|
|
188
|
+
get colorTextureRendererAlphaCutoff() {
|
|
189
|
+
if (!this._colorTextureRendererAlphaCutoff) {
|
|
190
|
+
this._colorTextureRendererAlphaCutoff = new TrianglesColorTextureRenderer(this._scene, false, { useAlphaCutoff: true });
|
|
191
|
+
}
|
|
192
|
+
return this._colorTextureRendererAlphaCutoff;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
get colorTextureRendererWithSAOAlphaCutoff() {
|
|
196
|
+
if (!this._colorTextureRendererWithSAOAlphaCutoff) {
|
|
197
|
+
this._colorTextureRendererWithSAOAlphaCutoff = new TrianglesColorTextureRenderer(this._scene, true, { useAlphaCutoff: true });
|
|
198
|
+
}
|
|
199
|
+
return this._colorTextureRendererWithSAOAlphaCutoff;
|
|
200
|
+
}
|
|
201
|
+
|
|
180
202
|
get pbrRenderer() {
|
|
181
203
|
if (!this._pbrRenderer) {
|
|
182
204
|
this._pbrRenderer = new TrianglesPBRRenderer(this._scene, false);
|
|
@@ -301,6 +323,12 @@ class Renderers {
|
|
|
301
323
|
if (this._colorTextureRendererWithSAO) {
|
|
302
324
|
this._colorTextureRendererWithSAO.destroy();
|
|
303
325
|
}
|
|
326
|
+
if (this._colorTextureRendererAlphaCutoff) {
|
|
327
|
+
this._colorTextureRendererAlphaCutoff.destroy();
|
|
328
|
+
}
|
|
329
|
+
if (this._colorTextureRendererWithSAOAlphaCutoff) {
|
|
330
|
+
this._colorTextureRendererWithSAOAlphaCutoff.destroy();
|
|
331
|
+
}
|
|
304
332
|
if (this._pbrRenderer) {
|
|
305
333
|
this._pbrRenderer.destroy();
|
|
306
334
|
}
|
|
@@ -349,27 +377,27 @@ class Renderers {
|
|
|
349
377
|
}
|
|
350
378
|
}
|
|
351
379
|
|
|
352
|
-
const
|
|
380
|
+
const cachedRenderers = {};
|
|
353
381
|
|
|
354
382
|
/**
|
|
355
383
|
* @private
|
|
356
384
|
*/
|
|
357
385
|
export function getRenderers(scene) {
|
|
358
386
|
const sceneId = scene.id;
|
|
359
|
-
let
|
|
360
|
-
if (!
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
387
|
+
let renderers = cachedRenderers[sceneId];
|
|
388
|
+
if (!renderers) {
|
|
389
|
+
renderers = new Renderers(scene);
|
|
390
|
+
cachedRenderers[sceneId] = renderers;
|
|
391
|
+
renderers._compile();
|
|
392
|
+
renderers.eagerCreateRenders();
|
|
365
393
|
scene.on("compile", () => {
|
|
366
|
-
|
|
367
|
-
|
|
394
|
+
renderers._compile();
|
|
395
|
+
renderers.eagerCreateRenders();
|
|
368
396
|
});
|
|
369
397
|
scene.on("destroyed", () => {
|
|
370
|
-
delete
|
|
371
|
-
|
|
398
|
+
delete cachedRenderers[sceneId];
|
|
399
|
+
renderers._destroy();
|
|
372
400
|
});
|
|
373
401
|
}
|
|
374
|
-
return
|
|
402
|
+
return renderers;
|
|
375
403
|
}
|
package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesBatchingRenderer.js
CHANGED
|
@@ -5,8 +5,8 @@ import {VBORenderer} from "./../../../VBORenderer.js";
|
|
|
5
5
|
*/
|
|
6
6
|
export class TrianglesBatchingRenderer extends VBORenderer {
|
|
7
7
|
|
|
8
|
-
constructor(scene, withSAO, {edges = false} = {}) {
|
|
9
|
-
super(scene, withSAO, {instancing: false, edges});
|
|
8
|
+
constructor(scene, withSAO, {edges = false, useAlphaCutoff = false} = {}) {
|
|
9
|
+
super(scene, withSAO, {instancing: false, edges, useAlphaCutoff});
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
_draw(drawCfg) {
|
|
@@ -23,7 +23,6 @@ export class TrianglesBatchingRenderer extends VBORenderer {
|
|
|
23
23
|
} else {
|
|
24
24
|
const count = frameCtx.pickElementsCount || state.indicesBuf.numItems;
|
|
25
25
|
const offset = frameCtx.pickElementsOffset ? frameCtx.pickElementsOffset * state.indicesBuf.itemByteSize : 0;
|
|
26
|
-
|
|
27
26
|
gl.drawElements(gl.TRIANGLES, count, state.indicesBuf.itemType, offset);
|
|
28
27
|
|
|
29
28
|
if (incrementDrawState) {
|
package/src/viewer/scene/model/vbo/batching/triangles/renderers/TrianglesColorTextureRenderer.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {TrianglesBatchingRenderer} from "./TrianglesBatchingRenderer.js";
|
|
2
2
|
|
|
3
|
-
|
|
4
3
|
/**
|
|
5
4
|
* @private
|
|
6
5
|
*/
|
|
6
|
+
|
|
7
7
|
export class TrianglesColorTextureRenderer extends TrianglesBatchingRenderer {
|
|
8
8
|
_getHash() {
|
|
9
9
|
const scene = this._scene;
|
|
@@ -11,11 +11,10 @@ export class TrianglesColorTextureRenderer extends TrianglesBatchingRenderer {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
drawLayer(frameCtx, layer, renderPass) {
|
|
14
|
-
super.drawLayer(frameCtx, layer, renderPass, {incrementDrawState: true});
|
|
14
|
+
super.drawLayer(frameCtx, layer, renderPass, { incrementDrawState: true });
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
_buildVertexShader() {
|
|
18
|
-
|
|
19
18
|
const scene = this._scene;
|
|
20
19
|
const sectionPlanesState = scene._sectionPlanesState;
|
|
21
20
|
const clipping = sectionPlanesState.getNumAllocatedSectionPlanes() > 0;
|
|
@@ -36,7 +35,7 @@ export class TrianglesColorTextureRenderer extends TrianglesBatchingRenderer {
|
|
|
36
35
|
|
|
37
36
|
this._addMatricesUniformBlockLines(src);
|
|
38
37
|
|
|
39
|
-
src.push("uniform mat3 uvDecodeMatrix;")
|
|
38
|
+
src.push("uniform mat3 uvDecodeMatrix;");
|
|
40
39
|
|
|
41
40
|
if (scene.logarithmicDepthBufferEnabled) {
|
|
42
41
|
src.push("uniform float logDepthBufFC;");
|
|
@@ -70,6 +69,7 @@ export class TrianglesColorTextureRenderer extends TrianglesBatchingRenderer {
|
|
|
70
69
|
if (scene.entityOffsetsEnabled) {
|
|
71
70
|
src.push("worldPosition.xyz = worldPosition.xyz + offset;");
|
|
72
71
|
}
|
|
72
|
+
|
|
73
73
|
src.push("vec4 viewPosition = viewMatrix * worldPosition; ");
|
|
74
74
|
src.push("vViewPosition = viewPosition;");
|
|
75
75
|
src.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);");
|
|
@@ -80,10 +80,12 @@ export class TrianglesColorTextureRenderer extends TrianglesBatchingRenderer {
|
|
|
80
80
|
src.push("vFragDepth = 1.0 + clipPos.w;");
|
|
81
81
|
src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
|
|
82
82
|
}
|
|
83
|
+
|
|
83
84
|
if (clipping) {
|
|
84
85
|
src.push("vWorldPosition = worldPosition;");
|
|
85
86
|
src.push("vFlags = flags;");
|
|
86
87
|
}
|
|
88
|
+
|
|
87
89
|
src.push("gl_Position = clipPos;");
|
|
88
90
|
src.push("}");
|
|
89
91
|
src.push("}");
|
|
@@ -96,6 +98,7 @@ export class TrianglesColorTextureRenderer extends TrianglesBatchingRenderer {
|
|
|
96
98
|
const lightsState = scene._lightsState;
|
|
97
99
|
const sectionPlanesState = scene._sectionPlanesState;
|
|
98
100
|
const clipping = sectionPlanesState.getNumAllocatedSectionPlanes() > 0;
|
|
101
|
+
const useAlphaCutoff = this._useAlphaCutoff;
|
|
99
102
|
const src = [];
|
|
100
103
|
src.push("#version 300 es");
|
|
101
104
|
src.push("// Triangles batching color texture fragment shader");
|
|
@@ -154,6 +157,7 @@ export class TrianglesColorTextureRenderer extends TrianglesBatchingRenderer {
|
|
|
154
157
|
src.push("uniform vec4 sliceColor;");
|
|
155
158
|
}
|
|
156
159
|
this._addMatricesUniformBlockLines(src);
|
|
160
|
+
|
|
157
161
|
src.push("uniform vec4 lightAmbient;");
|
|
158
162
|
for (let i = 0, len = lightsState.lights.length; i < len; i++) {
|
|
159
163
|
const light = lightsState.lights[i];
|
|
@@ -173,6 +177,10 @@ export class TrianglesColorTextureRenderer extends TrianglesBatchingRenderer {
|
|
|
173
177
|
}
|
|
174
178
|
}
|
|
175
179
|
|
|
180
|
+
if (useAlphaCutoff) {
|
|
181
|
+
src.push("uniform float materialAlphaCutoff;");
|
|
182
|
+
}
|
|
183
|
+
|
|
176
184
|
src.push("in vec4 vViewPosition;");
|
|
177
185
|
src.push("in vec4 vColor;");
|
|
178
186
|
src.push("in vec2 vUV;");
|
|
@@ -240,11 +248,21 @@ export class TrianglesColorTextureRenderer extends TrianglesBatchingRenderer {
|
|
|
240
248
|
}
|
|
241
249
|
|
|
242
250
|
src.push("vec4 color = vec4((lightAmbient.rgb * lightAmbient.a * newColor.rgb) + (reflectedColor * newColor.rgb), newColor.a);");
|
|
251
|
+
|
|
252
|
+
src.push("vec4 sampleColor = texture(uColorMap, vUV);");
|
|
253
|
+
|
|
254
|
+
if (useAlphaCutoff) {
|
|
255
|
+
src.push("if (sampleColor.a < materialAlphaCutoff) {");
|
|
256
|
+
src.push(" discard;");
|
|
257
|
+
src.push("}");
|
|
258
|
+
}
|
|
259
|
+
|
|
243
260
|
if (gammaOutput) {
|
|
244
|
-
src.push("
|
|
245
|
-
} else {
|
|
246
|
-
src.push("vec4 colorTexel = color * texture(uColorMap, vUV);");
|
|
261
|
+
src.push("sampleColor = sRGBToLinear(sampleColor);");
|
|
247
262
|
}
|
|
263
|
+
|
|
264
|
+
src.push("vec4 colorTexel = color * sampleColor;");
|
|
265
|
+
|
|
248
266
|
src.push("float opacity = color.a;");
|
|
249
267
|
|
|
250
268
|
if (this._withSAO) {
|
|
@@ -214,7 +214,7 @@ export class TrianglesSnapRenderer extends VBORenderer{
|
|
|
214
214
|
|
|
215
215
|
src.push(`int pickFlag = int(flags) >> 12 & 0xF;`);
|
|
216
216
|
src.push(`if (pickFlag != renderPass) {`);
|
|
217
|
-
src.push(" gl_Position = vec4(
|
|
217
|
+
src.push(" gl_Position = vec4(2.0, 0.0, 0.0, 0.0);"); // Cull vertex
|
|
218
218
|
src.push(" } else {");
|
|
219
219
|
src.push(" vec4 worldPosition = worldMatrix * (positionsDecodeMatrix * vec4(position, 1.0)); ");
|
|
220
220
|
if (scene.entityOffsetsEnabled) {
|
package/src/viewer/scene/model/vbo/instancing/lines/renderers/VBOInstancingLinesSnapRenderer.js
CHANGED
|
@@ -221,7 +221,7 @@ export class VBOInstancingLinesSnapRenderer extends VBORenderer {
|
|
|
221
221
|
// renderPass = PICK
|
|
222
222
|
src.push(`int pickFlag = int(flags) >> 12 & 0xF;`);
|
|
223
223
|
src.push(`if (pickFlag != renderPass) {`);
|
|
224
|
-
src.push(" gl_Position = vec4(
|
|
224
|
+
src.push(" gl_Position = vec4(2.0, 0.0, 0.0, 0.0);"); // Cull vertex
|
|
225
225
|
src.push("} else {");
|
|
226
226
|
src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");
|
|
227
227
|
src.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");
|
|
@@ -785,14 +785,21 @@ export class VBOInstancingTrianglesLayer {
|
|
|
785
785
|
return;
|
|
786
786
|
}
|
|
787
787
|
this._updateBackfaceCull(renderFlags, frameCtx);
|
|
788
|
+
const useAlphaCutoff = this._state.textureSet && (typeof(this._state.textureSet.alphaCutoff) === "number");
|
|
788
789
|
if (frameCtx.withSAO && this.model.saoEnabled) {
|
|
789
790
|
if (frameCtx.pbrEnabled && this.model.pbrEnabled && this._state.pbrSupported) {
|
|
790
791
|
if (this._renderers.pbrRendererWithSAO) {
|
|
791
792
|
this._renderers.pbrRendererWithSAO.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
|
|
792
793
|
}
|
|
793
794
|
} else if (frameCtx.colorTextureEnabled && this.model.colorTextureEnabled && this._state.colorTextureSupported) {
|
|
794
|
-
if (
|
|
795
|
-
this._renderers.
|
|
795
|
+
if (useAlphaCutoff) {
|
|
796
|
+
if (this._renderers.colorTextureRendererWithSAOAlphaCutoff) {
|
|
797
|
+
this._renderers.colorTextureRendererWithSAOAlphaCutoff.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
|
|
798
|
+
}
|
|
799
|
+
} else {
|
|
800
|
+
if (this._renderers.colorTextureRendererWithSAO) {
|
|
801
|
+
this._renderers.colorTextureRendererWithSAO.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
|
|
802
|
+
}
|
|
796
803
|
}
|
|
797
804
|
} else if (this._state.normalsBuf) {
|
|
798
805
|
if (this._renderers.colorRendererWithSAO) {
|
|
@@ -808,8 +815,14 @@ export class VBOInstancingTrianglesLayer {
|
|
|
808
815
|
this._renderers.pbrRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
|
|
809
816
|
}
|
|
810
817
|
} else if (frameCtx.colorTextureEnabled && this.model.colorTextureEnabled && this._state.colorTextureSupported) {
|
|
811
|
-
if (
|
|
812
|
-
this._renderers.
|
|
818
|
+
if (useAlphaCutoff) {
|
|
819
|
+
if (this._renderers.colorTextureRendererAlphaCutoff) {
|
|
820
|
+
this._renderers.colorTextureRendererAlphaCutoff.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
|
|
821
|
+
}
|
|
822
|
+
} else {
|
|
823
|
+
if (this._renderers.colorTextureRenderer) {
|
|
824
|
+
this._renderers.colorTextureRenderer.drawLayer(frameCtx, this, RENDER_PASSES.COLOR_OPAQUE);
|
|
825
|
+
}
|
|
813
826
|
}
|
|
814
827
|
} else if (this._state.normalsBuf) {
|
|
815
828
|
if (this._renderers.colorRenderer) {
|
|
@@ -42,14 +42,6 @@ class Renderers {
|
|
|
42
42
|
this._flatColorRendererWithSAO.destroy();
|
|
43
43
|
this._flatColorRendererWithSAO = null;
|
|
44
44
|
}
|
|
45
|
-
if (this._pbrRenderer && (!this._pbrRenderer.getValid())) {
|
|
46
|
-
this._pbrRenderer.destroy();
|
|
47
|
-
this._pbrRenderer = null;
|
|
48
|
-
}
|
|
49
|
-
if (this._pbrRendererWithSAO && (!this._pbrRendererWithSAO.getValid())) {
|
|
50
|
-
this._pbrRendererWithSAO.destroy();
|
|
51
|
-
this._pbrRendererWithSAO = null;
|
|
52
|
-
}
|
|
53
45
|
if (this._colorTextureRenderer && (!this._colorTextureRenderer.getValid())) {
|
|
54
46
|
this._colorTextureRenderer.destroy();
|
|
55
47
|
this._colorTextureRenderer = null;
|
|
@@ -58,6 +50,22 @@ class Renderers {
|
|
|
58
50
|
this._colorTextureRendererWithSAO.destroy();
|
|
59
51
|
this._colorTextureRendererWithSAO = null;
|
|
60
52
|
}
|
|
53
|
+
if (this._colorTextureRendererAlphaCutoff && (!this._colorTextureRendererAlphaCutoff.getValid())) {
|
|
54
|
+
this._colorTextureRendererAlphaCutoff.destroy();
|
|
55
|
+
this._colorTextureRendererAlphaCutoff = null;
|
|
56
|
+
}
|
|
57
|
+
if (this._colorTextureRendererWithSAOAlphaCutoff && (!this._colorTextureRendererWithSAOAlphaCutoff.getValid())) {
|
|
58
|
+
this._colorTextureRendererWithSAOAlphaCutoff.destroy();
|
|
59
|
+
this._colorTextureRendererWithSAOAlphaCutoff = null;
|
|
60
|
+
}
|
|
61
|
+
if (this._pbrRenderer && (!this._pbrRenderer.getValid())) {
|
|
62
|
+
this._pbrRenderer.destroy();
|
|
63
|
+
this._pbrRenderer = null;
|
|
64
|
+
}
|
|
65
|
+
if (this._pbrRendererWithSAO && (!this._pbrRendererWithSAO.getValid())) {
|
|
66
|
+
this._pbrRendererWithSAO.destroy();
|
|
67
|
+
this._pbrRendererWithSAO = null;
|
|
68
|
+
}
|
|
61
69
|
if (this._depthRenderer && (!this._depthRenderer.getValid())) {
|
|
62
70
|
this._depthRenderer.destroy();
|
|
63
71
|
this._depthRenderer = null;
|
|
@@ -90,7 +98,7 @@ class Renderers {
|
|
|
90
98
|
this._pickNormalsRenderer.destroy();
|
|
91
99
|
this._pickNormalsRenderer = null;
|
|
92
100
|
}
|
|
93
|
-
if (this._pickNormalsFlatRenderer &&
|
|
101
|
+
if (this._pickNormalsFlatRenderer && this._pickNormalsFlatRenderer.getValid() === false) {
|
|
94
102
|
this._pickNormalsFlatRenderer.destroy();
|
|
95
103
|
this._pickNormalsFlatRenderer = null;
|
|
96
104
|
}
|
|
@@ -163,20 +171,6 @@ class Renderers {
|
|
|
163
171
|
return this._flatColorRendererWithSAO;
|
|
164
172
|
}
|
|
165
173
|
|
|
166
|
-
get pbrRenderer() {
|
|
167
|
-
if (!this._pbrRenderer) {
|
|
168
|
-
this._pbrRenderer = new TrianglesPBRRenderer(this._scene, false);
|
|
169
|
-
}
|
|
170
|
-
return this._pbrRenderer;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
get pbrRendererWithSAO() {
|
|
174
|
-
if (!this._pbrRendererWithSAO) {
|
|
175
|
-
this._pbrRendererWithSAO = new TrianglesPBRRenderer(this._scene, true);
|
|
176
|
-
}
|
|
177
|
-
return this._pbrRendererWithSAO;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
174
|
get colorTextureRenderer() {
|
|
181
175
|
if (!this._colorTextureRenderer) {
|
|
182
176
|
this._colorTextureRenderer = new TrianglesColorTextureRenderer(this._scene, false);
|
|
@@ -191,6 +185,34 @@ class Renderers {
|
|
|
191
185
|
return this._colorTextureRendererWithSAO;
|
|
192
186
|
}
|
|
193
187
|
|
|
188
|
+
get colorTextureRendererAlphaCutoff() {
|
|
189
|
+
if (!this._colorTextureRendererAlphaCutoff) {
|
|
190
|
+
this._colorTextureRendererAlphaCutoff = new TrianglesColorTextureRenderer(this._scene, false, { useAlphaCutoff: true });
|
|
191
|
+
}
|
|
192
|
+
return this._colorTextureRendererAlphaCutoff;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
get colorTextureRendererWithSAOAlphaCutoff() {
|
|
196
|
+
if (!this._colorTextureRendererWithSAOAlphaCutoff) {
|
|
197
|
+
this._colorTextureRendererWithSAOAlphaCutoff = new TrianglesColorTextureRenderer(this._scene, true, { useAlphaCutoff: true });
|
|
198
|
+
}
|
|
199
|
+
return this._colorTextureRendererWithSAOAlphaCutoff;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
get pbrRenderer() {
|
|
203
|
+
if (!this._pbrRenderer) {
|
|
204
|
+
this._pbrRenderer = new TrianglesPBRRenderer(this._scene, false);
|
|
205
|
+
}
|
|
206
|
+
return this._pbrRenderer;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
get pbrRendererWithSAO() {
|
|
210
|
+
if (!this._pbrRendererWithSAO) {
|
|
211
|
+
this._pbrRendererWithSAO = new TrianglesPBRRenderer(this._scene, true);
|
|
212
|
+
}
|
|
213
|
+
return this._pbrRendererWithSAO;
|
|
214
|
+
}
|
|
215
|
+
|
|
194
216
|
get silhouetteRenderer() {
|
|
195
217
|
if (!this._silhouetteRenderer) {
|
|
196
218
|
this._silhouetteRenderer = new TrianglesSilhouetteRenderer(this._scene);
|
|
@@ -268,13 +290,6 @@ class Renderers {
|
|
|
268
290
|
return this._shadowRenderer;
|
|
269
291
|
}
|
|
270
292
|
|
|
271
|
-
get snapInitRenderer() {
|
|
272
|
-
if (!this._snapInitRenderer) {
|
|
273
|
-
this._snapInitRenderer = new TrianglesSnapInitRenderer(this._scene, false);
|
|
274
|
-
}
|
|
275
|
-
return this._snapInitRenderer;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
293
|
get snapRenderer() {
|
|
279
294
|
if (!this._snapRenderer) {
|
|
280
295
|
this._snapRenderer = new TrianglesSnapRenderer(this._scene);
|
|
@@ -282,6 +297,13 @@ class Renderers {
|
|
|
282
297
|
return this._snapRenderer;
|
|
283
298
|
}
|
|
284
299
|
|
|
300
|
+
get snapInitRenderer() {
|
|
301
|
+
if (!this._snapInitRenderer) {
|
|
302
|
+
this._snapInitRenderer = new TrianglesSnapInitRenderer(this._scene);
|
|
303
|
+
}
|
|
304
|
+
return this._snapInitRenderer;
|
|
305
|
+
}
|
|
306
|
+
|
|
285
307
|
_destroy() {
|
|
286
308
|
if (this._colorRenderer) {
|
|
287
309
|
this._colorRenderer.destroy();
|
|
@@ -295,18 +317,24 @@ class Renderers {
|
|
|
295
317
|
if (this._flatColorRendererWithSAO) {
|
|
296
318
|
this._flatColorRendererWithSAO.destroy();
|
|
297
319
|
}
|
|
298
|
-
if (this._pbrRenderer) {
|
|
299
|
-
this._pbrRenderer.destroy();
|
|
300
|
-
}
|
|
301
|
-
if (this._pbrRendererWithSAO) {
|
|
302
|
-
this._pbrRendererWithSAO.destroy();
|
|
303
|
-
}
|
|
304
320
|
if (this._colorTextureRenderer) {
|
|
305
321
|
this._colorTextureRenderer.destroy();
|
|
306
322
|
}
|
|
307
323
|
if (this._colorTextureRendererWithSAO) {
|
|
308
324
|
this._colorTextureRendererWithSAO.destroy();
|
|
309
325
|
}
|
|
326
|
+
if (this._colorTextureRendererAlphaCutoff) {
|
|
327
|
+
this._colorTextureRendererAlphaCutoff.destroy();
|
|
328
|
+
}
|
|
329
|
+
if (this._colorTextureRendererWithSAOAlphaCutoff) {
|
|
330
|
+
this._colorTextureRendererWithSAOAlphaCutoff.destroy();
|
|
331
|
+
}
|
|
332
|
+
if (this._pbrRenderer) {
|
|
333
|
+
this._pbrRenderer.destroy();
|
|
334
|
+
}
|
|
335
|
+
if (this._pbrRendererWithSAO) {
|
|
336
|
+
this._pbrRendererWithSAO.destroy();
|
|
337
|
+
}
|
|
310
338
|
if (this._depthRenderer) {
|
|
311
339
|
this._depthRenderer.destroy();
|
|
312
340
|
}
|
|
@@ -356,21 +384,20 @@ const cachedRenderers = {};
|
|
|
356
384
|
*/
|
|
357
385
|
export function getRenderers(scene) {
|
|
358
386
|
const sceneId = scene.id;
|
|
359
|
-
let
|
|
360
|
-
if (!
|
|
361
|
-
|
|
362
|
-
cachedRenderers[sceneId] =
|
|
363
|
-
|
|
364
|
-
|
|
387
|
+
let renderers = cachedRenderers[sceneId];
|
|
388
|
+
if (!renderers) {
|
|
389
|
+
renderers = new Renderers(scene);
|
|
390
|
+
cachedRenderers[sceneId] = renderers;
|
|
391
|
+
renderers._compile();
|
|
392
|
+
renderers.eagerCreateRenders();
|
|
365
393
|
scene.on("compile", () => {
|
|
366
|
-
|
|
367
|
-
|
|
394
|
+
renderers._compile();
|
|
395
|
+
renderers.eagerCreateRenders();
|
|
368
396
|
});
|
|
369
397
|
scene.on("destroyed", () => {
|
|
370
398
|
delete cachedRenderers[sceneId];
|
|
371
|
-
|
|
399
|
+
renderers._destroy();
|
|
372
400
|
});
|
|
373
401
|
}
|
|
374
|
-
return
|
|
402
|
+
return renderers;
|
|
375
403
|
}
|
|
376
|
-
|
package/src/viewer/scene/model/vbo/instancing/triangles/renderers/TrianglesColorTextureRenderer.js
CHANGED
|
@@ -4,7 +4,6 @@ import {TrianglesInstancingRenderer} from "./TrianglesInstancingRenderer.js";
|
|
|
4
4
|
* @private
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
8
7
|
export class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
|
|
9
8
|
_getHash() {
|
|
10
9
|
const scene = this._scene;
|
|
@@ -40,7 +39,7 @@ export class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
|
|
|
40
39
|
|
|
41
40
|
this._addMatricesUniformBlockLines(src);
|
|
42
41
|
|
|
43
|
-
src.push("uniform mat3 uvDecodeMatrix;")
|
|
42
|
+
src.push("uniform mat3 uvDecodeMatrix;");
|
|
44
43
|
|
|
45
44
|
if (scene.logarithmicDepthBufferEnabled) {
|
|
46
45
|
src.push("uniform float logDepthBufFC;");
|
|
@@ -73,7 +72,7 @@ export class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
|
|
|
73
72
|
src.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");
|
|
74
73
|
src.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");
|
|
75
74
|
if (scene.entityOffsetsEnabled) {
|
|
76
|
-
src.push("
|
|
75
|
+
src.push("worldPosition.xyz = worldPosition.xyz + offset;");
|
|
77
76
|
}
|
|
78
77
|
|
|
79
78
|
src.push("vec4 viewPosition = viewMatrix * worldPosition; ");
|
|
@@ -101,11 +100,10 @@ export class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
|
|
|
101
100
|
_buildFragmentShader() {
|
|
102
101
|
const scene = this._scene;
|
|
103
102
|
const gammaOutput = scene.gammaOutput; // If set, then it expects that all textures and colors need to be outputted in premultiplied gamma. Default is false.
|
|
104
|
-
const sectionPlanesState = scene._sectionPlanesState;
|
|
105
103
|
const lightsState = scene._lightsState;
|
|
106
|
-
|
|
107
|
-
let len;
|
|
104
|
+
const sectionPlanesState = scene._sectionPlanesState;
|
|
108
105
|
const clipping = sectionPlanesState.getNumAllocatedSectionPlanes() > 0;
|
|
106
|
+
const useAlphaCutoff = this._useAlphaCutoff;
|
|
109
107
|
const src = [];
|
|
110
108
|
src.push("#version 300 es");
|
|
111
109
|
src.push("// Instancing geometry drawing fragment shader");
|
|
@@ -117,6 +115,7 @@ export class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
|
|
|
117
115
|
src.push("precision mediump float;");
|
|
118
116
|
src.push("precision mediump int;");
|
|
119
117
|
src.push("#endif");
|
|
118
|
+
|
|
120
119
|
if (scene.logarithmicDepthBufferEnabled) {
|
|
121
120
|
src.push("in float isPerspective;");
|
|
122
121
|
src.push("uniform float logDepthBufFC;");
|
|
@@ -165,7 +164,7 @@ export class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
|
|
|
165
164
|
this._addMatricesUniformBlockLines(src);
|
|
166
165
|
|
|
167
166
|
src.push("uniform vec4 lightAmbient;");
|
|
168
|
-
for (i = 0, len = lightsState.lights.length; i < len; i++) {
|
|
167
|
+
for (let i = 0, len = lightsState.lights.length; i < len; i++) {
|
|
169
168
|
const light = lightsState.lights[i];
|
|
170
169
|
if (light.type === "ambient") {
|
|
171
170
|
continue;
|
|
@@ -183,6 +182,10 @@ export class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
|
|
|
183
182
|
}
|
|
184
183
|
}
|
|
185
184
|
|
|
185
|
+
if (useAlphaCutoff) {
|
|
186
|
+
src.push("uniform float materialAlphaCutoff;");
|
|
187
|
+
}
|
|
188
|
+
|
|
186
189
|
src.push("in vec4 vViewPosition;");
|
|
187
190
|
src.push("in vec4 vColor;");
|
|
188
191
|
src.push("in vec2 vUV;");
|
|
@@ -218,7 +221,7 @@ export class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
|
|
|
218
221
|
src.push("vec3 yTangent = dFdy( vViewPosition.xyz );");
|
|
219
222
|
src.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");
|
|
220
223
|
|
|
221
|
-
for (i = 0, len = lightsState.lights.length; i < len; i++) {
|
|
224
|
+
for (let i = 0, len = lightsState.lights.length; i < len; i++) {
|
|
222
225
|
const light = lightsState.lights[i];
|
|
223
226
|
if (light.type === "ambient") {
|
|
224
227
|
continue;
|
|
@@ -244,16 +247,27 @@ export class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
|
|
|
244
247
|
} else {
|
|
245
248
|
continue;
|
|
246
249
|
}
|
|
250
|
+
|
|
247
251
|
src.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);");
|
|
248
252
|
src.push("reflectedColor += lambertian * (lightColor" + i + ".rgb * lightColor" + i + ".a);");
|
|
249
253
|
}
|
|
250
254
|
|
|
251
255
|
src.push("vec4 color = vec4((lightAmbient.rgb * lightAmbient.a * newColor.rgb) + (reflectedColor * newColor.rgb), newColor.a);");
|
|
256
|
+
|
|
257
|
+
src.push("vec4 sampleColor = texture(uColorMap, vUV);");
|
|
258
|
+
|
|
259
|
+
if (useAlphaCutoff) {
|
|
260
|
+
src.push("if (sampleColor.a < materialAlphaCutoff) {");
|
|
261
|
+
src.push(" discard;");
|
|
262
|
+
src.push("}");
|
|
263
|
+
}
|
|
264
|
+
|
|
252
265
|
if (gammaOutput) {
|
|
253
|
-
src.push("
|
|
254
|
-
} else {
|
|
255
|
-
src.push("vec4 colorTexel = color * texture(uColorMap, vUV);");
|
|
266
|
+
src.push("sampleColor = sRGBToLinear(sampleColor);");
|
|
256
267
|
}
|
|
268
|
+
|
|
269
|
+
src.push("vec4 colorTexel = color * sampleColor;");
|
|
270
|
+
|
|
257
271
|
src.push("float opacity = color.a;");
|
|
258
272
|
|
|
259
273
|
if (this._withSAO) {
|
|
@@ -265,9 +279,10 @@ export class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
|
|
|
265
279
|
src.push(" float blendFactor = uSAOParams[3];");
|
|
266
280
|
src.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);");
|
|
267
281
|
src.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;");
|
|
268
|
-
|
|
282
|
+
|
|
283
|
+
src.push(" outColor = vec4(colorTexel.rgb * ambient, opacity);");
|
|
269
284
|
} else {
|
|
270
|
-
src.push(" outColor = vec4(
|
|
285
|
+
src.push(" outColor = vec4(colorTexel.rgb, opacity);");
|
|
271
286
|
}
|
|
272
287
|
|
|
273
288
|
if (gammaOutput) {
|
|
@@ -275,7 +290,7 @@ export class TrianglesColorTextureRenderer extends TrianglesInstancingRenderer {
|
|
|
275
290
|
}
|
|
276
291
|
|
|
277
292
|
if (scene.logarithmicDepthBufferEnabled) {
|
|
278
|
-
src.push("
|
|
293
|
+
src.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
|
|
279
294
|
}
|
|
280
295
|
|
|
281
296
|
src.push("}");
|