@rtzh/engine 0.0.9 → 0.0.10

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 (129) hide show
  1. package/Build/ThirdParty/Workers/zip-web-worker.js +586 -480
  2. package/Build/Workers/chunk-3CD4WIF4.js +101 -0
  3. package/Build/Workers/chunk-3PWX65TL.js +398 -0
  4. package/Build/Workers/chunk-4CQDMEZY.js +2058 -0
  5. package/Build/Workers/chunk-4GZLJPDW.js +8366 -0
  6. package/Build/Workers/chunk-5WKGRIN6.js +114 -0
  7. package/Build/Workers/chunk-6BNIWSFA.js +940 -0
  8. package/Build/Workers/chunk-6TWMNB7Q.js +455 -0
  9. package/Build/Workers/chunk-72Q33KL6.js +280 -0
  10. package/Build/Workers/chunk-74HENCNJ.js +171 -0
  11. package/Build/Workers/chunk-7C2MOK27.js +57 -0
  12. package/Build/Workers/chunk-7EFYX4FL.js +642 -0
  13. package/Build/Workers/chunk-7RAUHLDW.js +497 -0
  14. package/Build/Workers/chunk-B3FJJGCH.js +305 -0
  15. package/Build/Workers/chunk-BIJHMMCD.js +138 -0
  16. package/Build/Workers/chunk-CGAHG2LR.js +163 -0
  17. package/Build/Workers/chunk-CQ5PWUMS.js +37 -0
  18. package/Build/Workers/chunk-CQB3KRGK.js +198 -0
  19. package/Build/Workers/chunk-DHWZGIOA.js +139 -0
  20. package/Build/Workers/chunk-EDFDPOY6.js +55 -0
  21. package/Build/Workers/chunk-F2BQY3GT.js +1317 -0
  22. package/Build/Workers/chunk-FARHIBOA.js +75 -0
  23. package/Build/Workers/chunk-G6PDJHNG.js +476 -0
  24. package/Build/Workers/chunk-GCPD37SU.js +1054 -0
  25. package/Build/Workers/chunk-GDHDJK32.js +1045 -0
  26. package/Build/Workers/chunk-GNGGEDZK.js +352 -0
  27. package/Build/Workers/chunk-GNGZG6C6.js +162 -0
  28. package/Build/Workers/chunk-HFCJLXTG.js +55 -0
  29. package/Build/Workers/chunk-HKII76UV.js +1800 -0
  30. package/Build/Workers/chunk-HWUHUN7Z.js +387 -0
  31. package/Build/Workers/chunk-I3VVEQQ6.js +439 -0
  32. package/Build/Workers/chunk-IKMU6YHA.js +288 -0
  33. package/Build/Workers/chunk-J4PNHKWO.js +2719 -0
  34. package/Build/Workers/chunk-JFLJS4QU.js +1443 -0
  35. package/Build/Workers/chunk-JJWMDUOJ.js +44 -0
  36. package/Build/Workers/chunk-JOQFYJZ2.js +692 -0
  37. package/Build/Workers/chunk-JUJONRWD.js +788 -0
  38. package/Build/Workers/chunk-MCJRXFRL.js +102 -0
  39. package/Build/Workers/chunk-MLL4AAXV.js +1460 -0
  40. package/Build/Workers/chunk-MPCZC3G6.js +414 -0
  41. package/Build/Workers/chunk-MPHEIDPB.js +629 -0
  42. package/Build/Workers/chunk-NXZJKIYD.js +97 -0
  43. package/Build/Workers/chunk-OD7UYXFV.js +352 -0
  44. package/Build/Workers/chunk-R2AFDOIY.js +778 -0
  45. package/Build/Workers/chunk-RBLCJVK6.js +73 -0
  46. package/Build/Workers/chunk-SCF2OVAZ.js +219 -0
  47. package/Build/Workers/chunk-SJX7UJNW.js +241 -0
  48. package/Build/Workers/chunk-SZQC2TUH.js +368 -0
  49. package/Build/Workers/chunk-TAWVKT4B.js +58 -0
  50. package/Build/Workers/chunk-U267N6IJ.js +299 -0
  51. package/Build/Workers/chunk-UZXJSLDO.js +3514 -0
  52. package/Build/Workers/chunk-VP2OAU4C.js +124 -0
  53. package/Build/Workers/chunk-XMIENZET.js +256 -0
  54. package/Build/Workers/chunk-XXD3TQVI.js +837 -0
  55. package/Build/Workers/chunk-YCTK62TY.js +1483 -0
  56. package/Build/Workers/chunk-YWSB7PZP.js +511 -0
  57. package/Build/Workers/chunk-ZVXETFPZ.js +1067 -0
  58. package/Build/Workers/chunk-ZXZTWDTN.js +682 -0
  59. package/Build/Workers/combineGeometry.js +24 -24
  60. package/Build/Workers/createBoxGeometry.js +18 -18
  61. package/Build/Workers/createBoxOutlineGeometry.js +16 -16
  62. package/Build/Workers/createCircleGeometry.js +26 -26
  63. package/Build/Workers/createCircleOutlineGeometry.js +19 -19
  64. package/Build/Workers/createCoplanarPolygonGeometry.js +33 -33
  65. package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +31 -31
  66. package/Build/Workers/createCorridorGeometry.js +29 -29
  67. package/Build/Workers/createCorridorOutlineGeometry.js +28 -28
  68. package/Build/Workers/createCylinderGeometry.js +20 -20
  69. package/Build/Workers/createCylinderOutlineGeometry.js +18 -18
  70. package/Build/Workers/createEllipseGeometry.js +26 -26
  71. package/Build/Workers/createEllipseOutlineGeometry.js +19 -19
  72. package/Build/Workers/createEllipsoidGeometry.js +19 -19
  73. package/Build/Workers/createEllipsoidOutlineGeometry.js +18 -18
  74. package/Build/Workers/createFrustumGeometry.js +18 -18
  75. package/Build/Workers/createFrustumOutlineGeometry.js +18 -18
  76. package/Build/Workers/createGeometry.js +24 -24
  77. package/Build/Workers/createGroundPolylineGeometry.js +22 -22
  78. package/Build/Workers/createPlaneGeometry.js +16 -16
  79. package/Build/Workers/createPlaneOutlineGeometry.js +15 -15
  80. package/Build/Workers/createPolygonGeometry.js +32 -32
  81. package/Build/Workers/createPolygonOutlineGeometry.js +30 -30
  82. package/Build/Workers/createPolylineGeometry.js +25 -25
  83. package/Build/Workers/createPolylineVolumeGeometry.js +31 -31
  84. package/Build/Workers/createPolylineVolumeOutlineGeometry.js +27 -27
  85. package/Build/Workers/createRectangleGeometry.js +27 -27
  86. package/Build/Workers/createRectangleOutlineGeometry.js +20 -20
  87. package/Build/Workers/createSimplePolylineGeometry.js +23 -23
  88. package/Build/Workers/createSphereGeometry.js +19 -19
  89. package/Build/Workers/createSphereOutlineGeometry.js +18 -18
  90. package/Build/Workers/createTaskProcessorWorker.js +3 -3
  91. package/Build/Workers/createVectorTileClampedPolylines.js +14 -14
  92. package/Build/Workers/createVectorTileGeometries.js +24 -24
  93. package/Build/Workers/createVectorTilePoints.js +13 -13
  94. package/Build/Workers/createVectorTilePolygons.js +22 -22
  95. package/Build/Workers/createVectorTilePolylines.js +14 -14
  96. package/Build/Workers/createVerticesFromCesium3DTilesTerrain.js +25 -25
  97. package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +22 -22
  98. package/Build/Workers/createVerticesFromHeightmap.js +22 -22
  99. package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +20 -20
  100. package/Build/Workers/createWallGeometry.js +24 -24
  101. package/Build/Workers/createWallOutlineGeometry.js +23 -23
  102. package/Build/Workers/decodeDraco.js +10 -10
  103. package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
  104. package/Build/Workers/decodeI3S.js +10 -10
  105. package/Build/Workers/gaussianSplatSorter.js +4 -4
  106. package/Build/Workers/gaussianSplatTextureGenerator.js +4 -4
  107. package/Build/Workers/incrementallyBuildTerrainPicker.js +10 -10
  108. package/Build/Workers/transcodeKTX2.js +6 -6
  109. package/Build/Workers/transferTypedArrayTest.js +1 -1
  110. package/Build/Workers/upsampleQuantizedTerrainMesh.js +22 -22
  111. package/Build/Workers/upsampleVerticesFromCesium3DTilesTerrain.js +25 -25
  112. package/Source/Renderer/AutomaticUniforms.js +76 -1
  113. package/Source/Renderer/UniformState.js +108 -1
  114. package/Source/Scene/Cesium3DTileset.js +4157 -4157
  115. package/Source/Scene/Model/BarycentricWireframePipelineStage.js +462 -414
  116. package/Source/Scene/Model/LightingPipelineStage.js +17 -2
  117. package/Source/Scene/Model/Model.js +3646 -3631
  118. package/Source/Scene/Model/Model3DTileContent.js +568 -568
  119. package/Source/Scene/Model/ModelRuntimePrimitive.js +391 -391
  120. package/Source/Scene/Model/WireframePipelineStage.js +122 -122
  121. package/Source/Scene/PointLight.js +36 -0
  122. package/Source/Scene/Scene.js +9 -1
  123. package/Source/Shaders/Model/LightingStageFS.glsl +33 -0
  124. package/Source/Shaders/Model/LightingStageFS.js +33 -0
  125. package/Source/ThirdParty/Workers/zip-web-worker.js +1 -1
  126. package/Source/ThirdParty/zip-module.wasm +0 -0
  127. package/index.d.ts +809 -779
  128. package/index.js +10 -9
  129. package/package.json +1 -1
@@ -1,414 +1,462 @@
1
- import Buffer from "../../Renderer/Buffer.js";
2
- import BufferUsage from "../../Renderer/BufferUsage.js";
3
- import Cartesian3 from "../../Core/Cartesian3.js";
4
- import Color from "../../Core/Color.js";
5
- import ComponentDatatype from "../../Core/ComponentDatatype.js";
6
- import defined from "../../Core/defined.js";
7
- import ModelUtility from "./ModelUtility.js";
8
- import PrimitiveType from "../../Core/PrimitiveType.js";
9
- import ShaderDestination from "../../Renderer/ShaderDestination.js";
10
- import VertexAttributeSemantic from "../VertexAttributeSemantic.js";
11
- import oneTimeWarning from "../../Core/oneTimeWarning.js";
12
- import AttributeType from "../AttributeType.js";
13
- import Pass from "../../Renderer/Pass.js";
14
-
15
- const BarycentricWireframePipelineStage = {
16
- name: "BarycentricWireframePipelineStage",
17
- };
18
-
19
- const defaultScanAxis = new Cartesian3(0, 0, 1);
20
-
21
- BarycentricWireframePipelineStage.process = function (
22
- renderResources,
23
- primitive,
24
- frameState,
25
- ) {
26
- const shaderBuilder = renderResources.shaderBuilder;
27
- const model = renderResources.model;
28
- const webgl2 = frameState.context.webgl2;
29
-
30
- if (!webgl2) {
31
- oneTimeWarning(
32
- "barycentric-wireframe-webgl1",
33
- "Barycentric wireframe mode requires WebGL 2. Falling back to lines mode.",
34
- );
35
- return;
36
- }
37
-
38
- const barycentricAttributeLocation = shaderBuilder.addAttribute(
39
- "vec3",
40
- "a_barycentric",
41
- );
42
-
43
- shaderBuilder.addDefine(
44
- "HAS_BARYCENTRIC_WIREFRAME",
45
- undefined,
46
- ShaderDestination.BOTH,
47
- );
48
-
49
- const scanlineEnabled = (model._debugWireframeScanSpeed ?? 0.0) > 0.0;
50
-
51
- if (model.debugWireframeOverlay) {
52
- shaderBuilder.addDefine(
53
- "WIREFRAME_OVERLAY",
54
- undefined,
55
- ShaderDestination.FRAGMENT,
56
- );
57
- }
58
-
59
- if (scanlineEnabled) {
60
- shaderBuilder.addDefine(
61
- "WIREFRAME_SCANLINE",
62
- undefined,
63
- ShaderDestination.BOTH,
64
- );
65
- }
66
-
67
- shaderBuilder.addVarying("vec3", "v_barycentric");
68
- if (scanlineEnabled) {
69
- shaderBuilder.addVarying("vec3", "v_wireframeWorldPos");
70
- }
71
-
72
- shaderBuilder.addUniform("float", "u_wireframeWidth", ShaderDestination.FRAGMENT);
73
- shaderBuilder.addUniform("vec4", "u_wireframeColor", ShaderDestination.FRAGMENT);
74
- shaderBuilder.addUniform("float", "u_wireframeFillAlpha", ShaderDestination.FRAGMENT);
75
- shaderBuilder.addUniform("float", "u_wireframeGlow", ShaderDestination.FRAGMENT);
76
-
77
- const hasFillColor = defined(model._debugWireframeFillColor);
78
- if (hasFillColor) {
79
- shaderBuilder.addDefine(
80
- "HAS_WIREFRAME_FILL_COLOR",
81
- undefined,
82
- ShaderDestination.FRAGMENT,
83
- );
84
- shaderBuilder.addUniform("vec4", "u_wireframeFillColor", ShaderDestination.FRAGMENT);
85
- }
86
-
87
- if (scanlineEnabled) {
88
- shaderBuilder.addUniform("float", "u_wireframeScanSpeed", ShaderDestination.FRAGMENT);
89
- shaderBuilder.addUniform("float", "u_wireframeTime", ShaderDestination.FRAGMENT);
90
- shaderBuilder.addUniform("vec3", "u_wireframeScanAxis", ShaderDestination.FRAGMENT);
91
- shaderBuilder.addUniform("float", "u_wireframeScanMin", ShaderDestination.FRAGMENT);
92
- shaderBuilder.addUniform("float", "u_wireframeScanMax", ShaderDestination.FRAGMENT);
93
- }
94
-
95
- const stageUniforms = renderResources.uniformMap;
96
- stageUniforms.u_wireframeWidth = function () {
97
- return model.debugWireframeLineWidth ?? 1.0;
98
- };
99
- stageUniforms.u_wireframeColor = function () {
100
- return model.debugWireframeColor ?? Color.WHITE;
101
- };
102
- stageUniforms.u_wireframeFillAlpha = function () {
103
- return defined(model._debugWireframeFillColor)
104
- ? 1.0
105
- : (model._debugWireframeFillAlpha ?? 1.0);
106
- };
107
- if (hasFillColor) {
108
- stageUniforms.u_wireframeFillColor = function () {
109
- return model._debugWireframeFillColor;
110
- };
111
- }
112
- stageUniforms.u_wireframeGlow = function () {
113
- return model._debugWireframeGlow ?? 0.0;
114
- };
115
-
116
- if (scanlineEnabled) {
117
- stageUniforms.u_wireframeScanSpeed = function () {
118
- return model._debugWireframeScanSpeed ?? 0.0;
119
- };
120
- stageUniforms.u_wireframeTime = function () {
121
- return frameState.time.secondsOfDay;
122
- };
123
- stageUniforms.u_wireframeScanAxis = function () {
124
- return model._debugWireframeScanAxis ?? defaultScanAxis;
125
- };
126
- stageUniforms.u_wireframeScanMin = function () {
127
- return model._debugWireframeScanMin ?? 0.0;
128
- };
129
- stageUniforms.u_wireframeScanMax = function () {
130
- return model._debugWireframeScanMax ?? 1.0;
131
- };
132
- }
133
-
134
- // Enable alpha blending when fillAlpha < 1.0 or fillColor alpha < 1.0
135
- const fillAlphaValue = defined(model._debugWireframeFillColor)
136
- ? model._debugWireframeFillColor.alpha
137
- : (model._debugWireframeFillAlpha ?? 1.0);
138
- if (fillAlphaValue < 1.0) {
139
- renderResources.alphaOptions.pass = Pass.TRANSLUCENT;
140
- }
141
-
142
- deindexGeometryAndAddBarycentric(
143
- renderResources,
144
- primitive,
145
- barycentricAttributeLocation,
146
- frameState,
147
- model.debugWireframeOverlay,
148
- );
149
- };
150
-
151
- function getAttributeIndex(shaderBuilder, semantic, setIndex) {
152
- return shaderBuilder.attributeLocations[semantic + "_" + (setIndex ?? 0)];
153
- }
154
-
155
- function getComponentsFromType(type) {
156
- return AttributeType.getNumberOfComponents(type);
157
- }
158
-
159
- function extractAttributeData(attribute) {
160
- if (!defined(attribute)) {
161
- return undefined;
162
- }
163
-
164
- const typedArray = attribute.typedArray;
165
- if (!defined(typedArray)) {
166
- return undefined;
167
- }
168
-
169
- const componentDatatype = attribute.componentDatatype;
170
- const componentsPerAttribute = getComponentsFromType(attribute.type);
171
- const count = attribute.count;
172
- const byteOffset = attribute.byteOffset ?? 0;
173
- const byteStride = attribute.byteStride;
174
- const componentSize = ComponentDatatype.getSizeInBytes(componentDatatype);
175
- const stride = defined(byteStride) && byteStride !== 0
176
- ? byteStride
177
- : componentsPerAttribute * componentSize;
178
-
179
- const result = ComponentDatatype.createTypedArray(
180
- componentDatatype,
181
- count * componentsPerAttribute,
182
- );
183
-
184
- const baseOffset = byteOffset;
185
- for (let i = 0; i < count; i++) {
186
- const byteIndex = baseOffset + i * stride;
187
- const elementIndex = byteIndex / componentSize;
188
- for (let c = 0; c < componentsPerAttribute; c++) {
189
- result[i * componentsPerAttribute + c] = typedArray[elementIndex + c];
190
- }
191
- }
192
-
193
- return {
194
- data: result,
195
- count: count,
196
- componentsPerAttribute: componentsPerAttribute,
197
- componentDatatype: componentDatatype,
198
- normalized: attribute.normalized,
199
- };
200
- }
201
-
202
- function extractIndicesData(primitive) {
203
- const indices = primitive.indices;
204
- if (!defined(indices)) {
205
- return undefined;
206
- }
207
-
208
- const typedArray = indices.typedArray;
209
- if (defined(typedArray)) {
210
- return typedArray;
211
- }
212
-
213
- return undefined;
214
- }
215
-
216
- function deindexAttributeData(
217
- originalData,
218
- originalIndices,
219
- componentsPerAttribute,
220
- componentDatatype,
221
- ) {
222
- const newVertexCount = originalIndices.length;
223
- const totalComponents = newVertexCount * componentsPerAttribute;
224
- const newData = ComponentDatatype.createTypedArray(componentDatatype, totalComponents);
225
-
226
- for (let i = 0; i < newVertexCount; i++) {
227
- const oldIndex = originalIndices[i];
228
- const srcOffset = oldIndex * componentsPerAttribute;
229
- const dstOffset = i * componentsPerAttribute;
230
- for (let c = 0; c < componentsPerAttribute; c++) {
231
- newData[dstOffset + c] = originalData[srcOffset + c];
232
- }
233
- }
234
-
235
- return newData;
236
- }
237
-
238
- function createVertexBuffer(typedArray, frameState, model) {
239
- const buffer = Buffer.createVertexBuffer({
240
- context: frameState.context,
241
- typedArray: typedArray,
242
- usage: BufferUsage.STATIC_DRAW,
243
- });
244
- model._pipelineResources.push(buffer);
245
- return buffer;
246
- }
247
-
248
- function deindexGeometryAndAddBarycentric(
249
- renderResources,
250
- primitive,
251
- barycentricAttributeLocation,
252
- frameState,
253
- overlay,
254
- ) {
255
- const model = renderResources.model;
256
- const shaderBuilder = renderResources.shaderBuilder;
257
- const originalIndices = extractIndicesData(primitive);
258
- const positionAttr = ModelUtility.getAttributeBySemantic(
259
- primitive,
260
- VertexAttributeSemantic.POSITION,
261
- );
262
-
263
- if (!defined(positionAttr)) {
264
- return;
265
- }
266
-
267
- const originalVertexCount = positionAttr.count;
268
-
269
- if (!defined(originalIndices)) {
270
- const barycentricValues = new Float32Array(originalVertexCount * 3);
271
- for (let i = 0; i < originalVertexCount; i += 3) {
272
- barycentricValues[i * 3] = 1.0;
273
- barycentricValues[i * 3 + 1] = 0.0;
274
- barycentricValues[i * 3 + 2] = 0.0;
275
-
276
- barycentricValues[(i + 1) * 3] = 0.0;
277
- barycentricValues[(i + 1) * 3 + 1] = 1.0;
278
- barycentricValues[(i + 1) * 3 + 2] = 0.0;
279
-
280
- barycentricValues[(i + 2) * 3] = 0.0;
281
- barycentricValues[(i + 2) * 3 + 1] = 0.0;
282
- barycentricValues[(i + 2) * 3 + 2] = 1.0;
283
- }
284
-
285
- const barycentricBuffer = createVertexBuffer(barycentricValues, frameState, model);
286
-
287
- const barycentricAttribute = {
288
- index: barycentricAttributeLocation,
289
- vertexBuffer: barycentricBuffer,
290
- count: originalVertexCount,
291
- componentsPerAttribute: 3,
292
- componentDatatype: ComponentDatatype.FLOAT,
293
- offsetInBytes: 0,
294
- strideInBytes: 0,
295
- normalize: false,
296
- };
297
- renderResources.attributes.push(barycentricAttribute);
298
- return;
299
- }
300
-
301
- const primitiveType = primitive.primitiveType;
302
- if (!PrimitiveType.isTriangles(primitiveType)) {
303
- return;
304
- }
305
-
306
- const newVertexCount = originalIndices.length;
307
- const newAttributes = [];
308
- const originalAttributes = primitive.attributes;
309
-
310
- for (let i = 0; i < originalAttributes.length; i++) {
311
- const attr = originalAttributes[i];
312
- const semantic = attr.semantic;
313
- const setIndex = attr.setIndex;
314
-
315
- let attributeIndex;
316
- if (semantic === VertexAttributeSemantic.POSITION) {
317
- attributeIndex = shaderBuilder.attributeLocations.position;
318
- } else if (overlay) {
319
- // Only deindex non-position attributes in overlay mode
320
- // (overlay needs original material for blending)
321
- if (semantic === VertexAttributeSemantic.NORMAL) {
322
- attributeIndex = shaderBuilder.attributeLocations.normal;
323
- } else if (semantic === VertexAttributeSemantic.TANGENT) {
324
- attributeIndex = shaderBuilder.attributeLocations.tangent;
325
- } else if (semantic === VertexAttributeSemantic.TEXCOORD) {
326
- attributeIndex = shaderBuilder.attributeLocations["texCoord_" + setIndex];
327
- } else if (semantic === VertexAttributeSemantic.COLOR) {
328
- attributeIndex = shaderBuilder.attributeLocations["color_" + setIndex];
329
- } else if (semantic === VertexAttributeSemantic.JOINTS) {
330
- attributeIndex = shaderBuilder.attributeLocations["joints_" + setIndex];
331
- } else if (semantic === VertexAttributeSemantic.WEIGHTS) {
332
- attributeIndex = shaderBuilder.attributeLocations["weights_" + setIndex];
333
- } else {
334
- continue;
335
- }
336
- } else {
337
- continue;
338
- }
339
-
340
- if (!defined(attributeIndex)) {
341
- continue;
342
- }
343
-
344
- const extracted = extractAttributeData(attr);
345
- if (!defined(extracted)) {
346
- continue;
347
- }
348
-
349
- const newData = deindexAttributeData(
350
- extracted.data,
351
- originalIndices,
352
- extracted.componentsPerAttribute,
353
- extracted.componentDatatype,
354
- );
355
-
356
- const newBuffer = createVertexBuffer(newData, frameState, model);
357
-
358
- newAttributes.push({
359
- index: attributeIndex,
360
- vertexBuffer: newBuffer,
361
- count: newVertexCount,
362
- componentsPerAttribute: extracted.componentsPerAttribute,
363
- componentDatatype: extracted.componentDatatype,
364
- offsetInBytes: 0,
365
- strideInBytes: 0,
366
- normalize: extracted.normalized,
367
- });
368
- }
369
-
370
- const instanceAttributes = renderResources.attributes.filter(
371
- function (attr) {
372
- return attr.instanceDivisor === 1;
373
- },
374
- );
375
- for (let i = 0; i < instanceAttributes.length; i++) {
376
- newAttributes.push(instanceAttributes[i]);
377
- }
378
-
379
- const barycentricValues = new Float32Array(newVertexCount * 3);
380
- for (let i = 0; i < newVertexCount; i += 3) {
381
- barycentricValues[i * 3] = 1.0;
382
- barycentricValues[i * 3 + 1] = 0.0;
383
- barycentricValues[i * 3 + 2] = 0.0;
384
-
385
- barycentricValues[(i + 1) * 3] = 0.0;
386
- barycentricValues[(i + 1) * 3 + 1] = 1.0;
387
- barycentricValues[(i + 1) * 3 + 2] = 0.0;
388
-
389
- barycentricValues[(i + 2) * 3] = 0.0;
390
- barycentricValues[(i + 2) * 3 + 1] = 0.0;
391
- barycentricValues[(i + 2) * 3 + 2] = 1.0;
392
- }
393
-
394
- const barycentricBuffer = createVertexBuffer(barycentricValues, frameState, model);
395
-
396
- newAttributes.push({
397
- index: barycentricAttributeLocation,
398
- vertexBuffer: barycentricBuffer,
399
- count: newVertexCount,
400
- componentsPerAttribute: 3,
401
- componentDatatype: ComponentDatatype.FLOAT,
402
- offsetInBytes: 0,
403
- strideInBytes: 0,
404
- normalize: false,
405
- });
406
-
407
- renderResources.attributes = newAttributes;
408
- renderResources.indices = undefined;
409
- renderResources.count = newVertexCount;
410
- renderResources.primitiveType = PrimitiveType.TRIANGLES;
411
- renderResources.wireframeIndexBuffer = undefined;
412
- }
413
-
414
- export default BarycentricWireframePipelineStage;
1
+ import Buffer from "../../Renderer/Buffer.js";
2
+ import BufferUsage from "../../Renderer/BufferUsage.js";
3
+ import Cartesian3 from "../../Core/Cartesian3.js";
4
+ import Color from "../../Core/Color.js";
5
+ import ComponentDatatype from "../../Core/ComponentDatatype.js";
6
+ import defined from "../../Core/defined.js";
7
+ import ModelUtility from "./ModelUtility.js";
8
+ import PrimitiveType from "../../Core/PrimitiveType.js";
9
+ import ShaderDestination from "../../Renderer/ShaderDestination.js";
10
+ import VertexAttributeSemantic from "../VertexAttributeSemantic.js";
11
+ import oneTimeWarning from "../../Core/oneTimeWarning.js";
12
+ import AttributeType from "../AttributeType.js";
13
+ import Pass from "../../Renderer/Pass.js";
14
+
15
+ const BarycentricWireframePipelineStage = {
16
+ name: "BarycentricWireframePipelineStage",
17
+ };
18
+
19
+ const defaultScanAxis = new Cartesian3(0, 0, 1);
20
+
21
+ BarycentricWireframePipelineStage.process = function (
22
+ renderResources,
23
+ primitive,
24
+ frameState,
25
+ ) {
26
+ const shaderBuilder = renderResources.shaderBuilder;
27
+ const model = renderResources.model;
28
+ const webgl2 = frameState.context.webgl2;
29
+
30
+ if (!webgl2) {
31
+ oneTimeWarning(
32
+ "barycentric-wireframe-webgl1",
33
+ "Barycentric wireframe mode requires WebGL 2. Falling back to lines mode.",
34
+ );
35
+ return;
36
+ }
37
+
38
+ const barycentricAttributeLocation = shaderBuilder.addAttribute(
39
+ "vec3",
40
+ "a_barycentric",
41
+ );
42
+
43
+ shaderBuilder.addDefine(
44
+ "HAS_BARYCENTRIC_WIREFRAME",
45
+ undefined,
46
+ ShaderDestination.BOTH,
47
+ );
48
+
49
+ const scanlineEnabled = (model._debugWireframeScanSpeed ?? 0.0) > 0.0;
50
+
51
+ if (model.debugWireframeOverlay) {
52
+ shaderBuilder.addDefine(
53
+ "WIREFRAME_OVERLAY",
54
+ undefined,
55
+ ShaderDestination.FRAGMENT,
56
+ );
57
+ }
58
+
59
+ if (scanlineEnabled) {
60
+ shaderBuilder.addDefine(
61
+ "WIREFRAME_SCANLINE",
62
+ undefined,
63
+ ShaderDestination.BOTH,
64
+ );
65
+ }
66
+
67
+ shaderBuilder.addVarying("vec3", "v_barycentric");
68
+ if (scanlineEnabled) {
69
+ shaderBuilder.addVarying("vec3", "v_wireframeWorldPos");
70
+ }
71
+
72
+ shaderBuilder.addUniform(
73
+ "float",
74
+ "u_wireframeWidth",
75
+ ShaderDestination.FRAGMENT,
76
+ );
77
+ shaderBuilder.addUniform(
78
+ "vec4",
79
+ "u_wireframeColor",
80
+ ShaderDestination.FRAGMENT,
81
+ );
82
+ shaderBuilder.addUniform(
83
+ "float",
84
+ "u_wireframeFillAlpha",
85
+ ShaderDestination.FRAGMENT,
86
+ );
87
+ shaderBuilder.addUniform(
88
+ "float",
89
+ "u_wireframeGlow",
90
+ ShaderDestination.FRAGMENT,
91
+ );
92
+
93
+ const hasFillColor = defined(model._debugWireframeFillColor);
94
+ if (hasFillColor) {
95
+ shaderBuilder.addDefine(
96
+ "HAS_WIREFRAME_FILL_COLOR",
97
+ undefined,
98
+ ShaderDestination.FRAGMENT,
99
+ );
100
+ shaderBuilder.addUniform(
101
+ "vec4",
102
+ "u_wireframeFillColor",
103
+ ShaderDestination.FRAGMENT,
104
+ );
105
+ }
106
+
107
+ if (scanlineEnabled) {
108
+ shaderBuilder.addUniform(
109
+ "float",
110
+ "u_wireframeScanSpeed",
111
+ ShaderDestination.FRAGMENT,
112
+ );
113
+ shaderBuilder.addUniform(
114
+ "float",
115
+ "u_wireframeTime",
116
+ ShaderDestination.FRAGMENT,
117
+ );
118
+ shaderBuilder.addUniform(
119
+ "vec3",
120
+ "u_wireframeScanAxis",
121
+ ShaderDestination.FRAGMENT,
122
+ );
123
+ shaderBuilder.addUniform(
124
+ "float",
125
+ "u_wireframeScanMin",
126
+ ShaderDestination.FRAGMENT,
127
+ );
128
+ shaderBuilder.addUniform(
129
+ "float",
130
+ "u_wireframeScanMax",
131
+ ShaderDestination.FRAGMENT,
132
+ );
133
+ }
134
+
135
+ const stageUniforms = renderResources.uniformMap;
136
+ stageUniforms.u_wireframeWidth = function () {
137
+ return model.debugWireframeLineWidth ?? 1.0;
138
+ };
139
+ stageUniforms.u_wireframeColor = function () {
140
+ return model.debugWireframeColor ?? Color.WHITE;
141
+ };
142
+ stageUniforms.u_wireframeFillAlpha = function () {
143
+ return defined(model._debugWireframeFillColor)
144
+ ? 1.0
145
+ : (model._debugWireframeFillAlpha ?? 1.0);
146
+ };
147
+ if (hasFillColor) {
148
+ stageUniforms.u_wireframeFillColor = function () {
149
+ return model._debugWireframeFillColor;
150
+ };
151
+ }
152
+ stageUniforms.u_wireframeGlow = function () {
153
+ return model._debugWireframeGlow ?? 0.0;
154
+ };
155
+
156
+ if (scanlineEnabled) {
157
+ stageUniforms.u_wireframeScanSpeed = function () {
158
+ return model._debugWireframeScanSpeed ?? 0.0;
159
+ };
160
+ stageUniforms.u_wireframeTime = function () {
161
+ return frameState.time.secondsOfDay;
162
+ };
163
+ stageUniforms.u_wireframeScanAxis = function () {
164
+ return model._debugWireframeScanAxis ?? defaultScanAxis;
165
+ };
166
+ stageUniforms.u_wireframeScanMin = function () {
167
+ return model._debugWireframeScanMin ?? 0.0;
168
+ };
169
+ stageUniforms.u_wireframeScanMax = function () {
170
+ return model._debugWireframeScanMax ?? 1.0;
171
+ };
172
+ }
173
+
174
+ // Enable alpha blending when fillAlpha < 1.0 or fillColor alpha < 1.0
175
+ const fillAlphaValue = defined(model._debugWireframeFillColor)
176
+ ? model._debugWireframeFillColor.alpha
177
+ : (model._debugWireframeFillAlpha ?? 1.0);
178
+ if (fillAlphaValue < 1.0) {
179
+ renderResources.alphaOptions.pass = Pass.TRANSLUCENT;
180
+ }
181
+
182
+ deindexGeometryAndAddBarycentric(
183
+ renderResources,
184
+ primitive,
185
+ barycentricAttributeLocation,
186
+ frameState,
187
+ model.debugWireframeOverlay,
188
+ );
189
+ };
190
+
191
+ function getComponentsFromType(type) {
192
+ return AttributeType.getNumberOfComponents(type);
193
+ }
194
+
195
+ function extractAttributeData(attribute) {
196
+ if (!defined(attribute)) {
197
+ return undefined;
198
+ }
199
+
200
+ const typedArray = attribute.typedArray;
201
+ if (!defined(typedArray)) {
202
+ return undefined;
203
+ }
204
+
205
+ const componentDatatype = attribute.componentDatatype;
206
+ const componentsPerAttribute = getComponentsFromType(attribute.type);
207
+ const count = attribute.count;
208
+ const byteOffset = attribute.byteOffset ?? 0;
209
+ const byteStride = attribute.byteStride;
210
+ const componentSize = ComponentDatatype.getSizeInBytes(componentDatatype);
211
+ const stride =
212
+ defined(byteStride) && byteStride !== 0
213
+ ? byteStride
214
+ : componentsPerAttribute * componentSize;
215
+
216
+ const result = ComponentDatatype.createTypedArray(
217
+ componentDatatype,
218
+ count * componentsPerAttribute,
219
+ );
220
+
221
+ const baseOffset = byteOffset;
222
+ for (let i = 0; i < count; i++) {
223
+ const byteIndex = baseOffset + i * stride;
224
+ const elementIndex = byteIndex / componentSize;
225
+ for (let c = 0; c < componentsPerAttribute; c++) {
226
+ result[i * componentsPerAttribute + c] = typedArray[elementIndex + c];
227
+ }
228
+ }
229
+
230
+ return {
231
+ data: result,
232
+ count: count,
233
+ componentsPerAttribute: componentsPerAttribute,
234
+ componentDatatype: componentDatatype,
235
+ normalized: attribute.normalized,
236
+ };
237
+ }
238
+
239
+ function extractIndicesData(primitive) {
240
+ const indices = primitive.indices;
241
+ if (!defined(indices)) {
242
+ return undefined;
243
+ }
244
+
245
+ const typedArray = indices.typedArray;
246
+ if (defined(typedArray)) {
247
+ return typedArray;
248
+ }
249
+
250
+ return undefined;
251
+ }
252
+
253
+ function deindexAttributeData(
254
+ originalData,
255
+ originalIndices,
256
+ componentsPerAttribute,
257
+ componentDatatype,
258
+ ) {
259
+ const newVertexCount = originalIndices.length;
260
+ const totalComponents = newVertexCount * componentsPerAttribute;
261
+ const newData = ComponentDatatype.createTypedArray(
262
+ componentDatatype,
263
+ totalComponents,
264
+ );
265
+
266
+ for (let i = 0; i < newVertexCount; i++) {
267
+ const oldIndex = originalIndices[i];
268
+ const srcOffset = oldIndex * componentsPerAttribute;
269
+ const dstOffset = i * componentsPerAttribute;
270
+ for (let c = 0; c < componentsPerAttribute; c++) {
271
+ newData[dstOffset + c] = originalData[srcOffset + c];
272
+ }
273
+ }
274
+
275
+ return newData;
276
+ }
277
+
278
+ function createVertexBuffer(typedArray, frameState, model) {
279
+ const buffer = Buffer.createVertexBuffer({
280
+ context: frameState.context,
281
+ typedArray: typedArray,
282
+ usage: BufferUsage.STATIC_DRAW,
283
+ });
284
+ model._pipelineResources.push(buffer);
285
+ return buffer;
286
+ }
287
+
288
+ function deindexGeometryAndAddBarycentric(
289
+ renderResources,
290
+ primitive,
291
+ barycentricAttributeLocation,
292
+ frameState,
293
+ overlay,
294
+ ) {
295
+ const model = renderResources.model;
296
+ const shaderBuilder = renderResources.shaderBuilder;
297
+ const originalIndices = extractIndicesData(primitive);
298
+ const positionAttr = ModelUtility.getAttributeBySemantic(
299
+ primitive,
300
+ VertexAttributeSemantic.POSITION,
301
+ );
302
+
303
+ if (!defined(positionAttr)) {
304
+ return;
305
+ }
306
+
307
+ const originalVertexCount = positionAttr.count;
308
+
309
+ if (!defined(originalIndices)) {
310
+ const barycentricValues = new Float32Array(originalVertexCount * 3);
311
+ for (let i = 0; i < originalVertexCount; i += 3) {
312
+ barycentricValues[i * 3] = 1.0;
313
+ barycentricValues[i * 3 + 1] = 0.0;
314
+ barycentricValues[i * 3 + 2] = 0.0;
315
+
316
+ barycentricValues[(i + 1) * 3] = 0.0;
317
+ barycentricValues[(i + 1) * 3 + 1] = 1.0;
318
+ barycentricValues[(i + 1) * 3 + 2] = 0.0;
319
+
320
+ barycentricValues[(i + 2) * 3] = 0.0;
321
+ barycentricValues[(i + 2) * 3 + 1] = 0.0;
322
+ barycentricValues[(i + 2) * 3 + 2] = 1.0;
323
+ }
324
+
325
+ const barycentricBuffer = createVertexBuffer(
326
+ barycentricValues,
327
+ frameState,
328
+ model,
329
+ );
330
+
331
+ const barycentricAttribute = {
332
+ index: barycentricAttributeLocation,
333
+ vertexBuffer: barycentricBuffer,
334
+ count: originalVertexCount,
335
+ componentsPerAttribute: 3,
336
+ componentDatatype: ComponentDatatype.FLOAT,
337
+ offsetInBytes: 0,
338
+ strideInBytes: 0,
339
+ normalize: false,
340
+ };
341
+ renderResources.attributes.push(barycentricAttribute);
342
+ return;
343
+ }
344
+
345
+ const primitiveType = primitive.primitiveType;
346
+ if (!PrimitiveType.isTriangles(primitiveType)) {
347
+ return;
348
+ }
349
+
350
+ const newVertexCount = originalIndices.length;
351
+ const newAttributes = [];
352
+ const originalAttributes = primitive.attributes;
353
+
354
+ for (let i = 0; i < originalAttributes.length; i++) {
355
+ const attr = originalAttributes[i];
356
+ const semantic = attr.semantic;
357
+ const setIndex = attr.setIndex;
358
+
359
+ let attributeIndex;
360
+ if (semantic === VertexAttributeSemantic.POSITION) {
361
+ attributeIndex = shaderBuilder.attributeLocations.position;
362
+ } else if (overlay) {
363
+ // Only deindex non-position attributes in overlay mode
364
+ // (overlay needs original material for blending)
365
+ if (semantic === VertexAttributeSemantic.NORMAL) {
366
+ attributeIndex = shaderBuilder.attributeLocations.normal;
367
+ } else if (semantic === VertexAttributeSemantic.TANGENT) {
368
+ attributeIndex = shaderBuilder.attributeLocations.tangent;
369
+ } else if (semantic === VertexAttributeSemantic.TEXCOORD) {
370
+ attributeIndex =
371
+ shaderBuilder.attributeLocations[`texCoord_${setIndex}`];
372
+ } else if (semantic === VertexAttributeSemantic.COLOR) {
373
+ attributeIndex = shaderBuilder.attributeLocations[`color_${setIndex}`];
374
+ } else if (semantic === VertexAttributeSemantic.JOINTS) {
375
+ attributeIndex = shaderBuilder.attributeLocations[`joints_${setIndex}`];
376
+ } else if (semantic === VertexAttributeSemantic.WEIGHTS) {
377
+ attributeIndex =
378
+ shaderBuilder.attributeLocations[`weights_${setIndex}`];
379
+ } else {
380
+ continue;
381
+ }
382
+ } else {
383
+ continue;
384
+ }
385
+
386
+ if (!defined(attributeIndex)) {
387
+ continue;
388
+ }
389
+
390
+ const extracted = extractAttributeData(attr);
391
+ if (!defined(extracted)) {
392
+ continue;
393
+ }
394
+
395
+ const newData = deindexAttributeData(
396
+ extracted.data,
397
+ originalIndices,
398
+ extracted.componentsPerAttribute,
399
+ extracted.componentDatatype,
400
+ );
401
+
402
+ const newBuffer = createVertexBuffer(newData, frameState, model);
403
+
404
+ newAttributes.push({
405
+ index: attributeIndex,
406
+ vertexBuffer: newBuffer,
407
+ count: newVertexCount,
408
+ componentsPerAttribute: extracted.componentsPerAttribute,
409
+ componentDatatype: extracted.componentDatatype,
410
+ offsetInBytes: 0,
411
+ strideInBytes: 0,
412
+ normalize: extracted.normalized,
413
+ });
414
+ }
415
+
416
+ const instanceAttributes = renderResources.attributes.filter(function (attr) {
417
+ return attr.instanceDivisor === 1;
418
+ });
419
+ for (let i = 0; i < instanceAttributes.length; i++) {
420
+ newAttributes.push(instanceAttributes[i]);
421
+ }
422
+
423
+ const barycentricValues = new Float32Array(newVertexCount * 3);
424
+ for (let i = 0; i < newVertexCount; i += 3) {
425
+ barycentricValues[i * 3] = 1.0;
426
+ barycentricValues[i * 3 + 1] = 0.0;
427
+ barycentricValues[i * 3 + 2] = 0.0;
428
+
429
+ barycentricValues[(i + 1) * 3] = 0.0;
430
+ barycentricValues[(i + 1) * 3 + 1] = 1.0;
431
+ barycentricValues[(i + 1) * 3 + 2] = 0.0;
432
+
433
+ barycentricValues[(i + 2) * 3] = 0.0;
434
+ barycentricValues[(i + 2) * 3 + 1] = 0.0;
435
+ barycentricValues[(i + 2) * 3 + 2] = 1.0;
436
+ }
437
+
438
+ const barycentricBuffer = createVertexBuffer(
439
+ barycentricValues,
440
+ frameState,
441
+ model,
442
+ );
443
+
444
+ newAttributes.push({
445
+ index: barycentricAttributeLocation,
446
+ vertexBuffer: barycentricBuffer,
447
+ count: newVertexCount,
448
+ componentsPerAttribute: 3,
449
+ componentDatatype: ComponentDatatype.FLOAT,
450
+ offsetInBytes: 0,
451
+ strideInBytes: 0,
452
+ normalize: false,
453
+ });
454
+
455
+ renderResources.attributes = newAttributes;
456
+ renderResources.indices = undefined;
457
+ renderResources.count = newVertexCount;
458
+ renderResources.primitiveType = PrimitiveType.TRIANGLES;
459
+ renderResources.wireframeIndexBuffer = undefined;
460
+ }
461
+
462
+ export default BarycentricWireframePipelineStage;