@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,391 +1,391 @@
1
- import Check from "../../Core/Check.js";
2
- import Frozen from "../../Core/Frozen.js";
3
- import defined from "../../Core/defined.js";
4
- import PrimitiveType from "../../Core/PrimitiveType.js";
5
- import SceneMode from "../SceneMode.js";
6
- import AlphaPipelineStage from "./AlphaPipelineStage.js";
7
- import BatchTexturePipelineStage from "./BatchTexturePipelineStage.js";
8
- import ClassificationPipelineStage from "./ClassificationPipelineStage.js";
9
- import CPUStylingPipelineStage from "./CPUStylingPipelineStage.js";
10
- import CustomShaderMode from "./CustomShaderMode.js";
11
- import CustomShaderPipelineStage from "./CustomShaderPipelineStage.js";
12
- import DequantizationPipelineStage from "./DequantizationPipelineStage.js";
13
- import EdgeDetectionPipelineStage from "./EdgeDetectionPipelineStage.js";
14
- import EdgeVisibilityPipelineStage from "./EdgeVisibilityPipelineStage.js";
15
- import FeatureIdPipelineStage from "./FeatureIdPipelineStage.js";
16
- import GeometryPipelineStage from "./GeometryPipelineStage.js";
17
- import ImageryPipelineStage from "./ImageryPipelineStage.js";
18
- import LightingPipelineStage from "./LightingPipelineStage.js";
19
- import MaterialPipelineStage from "./MaterialPipelineStage.js";
20
- import MetadataPickingPipelineStage from "./MetadataPickingPipelineStage.js";
21
- import MetadataPipelineStage from "./MetadataPipelineStage.js";
22
- import ModelUtility from "./ModelUtility.js";
23
- import MorphTargetsPipelineStage from "./MorphTargetsPipelineStage.js";
24
- import PickingPipelineStage from "./PickingPipelineStage.js";
25
- import PointCloudStylingPipelineStage from "./PointCloudStylingPipelineStage.js";
26
- import PrimitiveOutlinePipelineStage from "./PrimitiveOutlinePipelineStage.js";
27
- import PrimitiveStatisticsPipelineStage from "./PrimitiveStatisticsPipelineStage.js";
28
- import SceneMode2DPipelineStage from "./SceneMode2DPipelineStage.js";
29
- import SelectedFeatureIdPipelineStage from "./SelectedFeatureIdPipelineStage.js";
30
- import SkinningPipelineStage from "./SkinningPipelineStage.js";
31
- import VerticalExaggerationPipelineStage from "./VerticalExaggerationPipelineStage.js";
32
- import WireframePipelineStage from "./WireframePipelineStage.js";
33
- import BarycentricWireframePipelineStage from "./BarycentricWireframePipelineStage.js";
34
- import oneTimeWarning from "../../Core/oneTimeWarning.js";
35
-
36
- /**
37
- * In memory representation of a single primitive, that is, a primitive
38
- * and its corresponding mesh.
39
- *
40
- * @param {object} options An object containing the following options:
41
- * @param {ModelComponents.Primitive} options.primitive The primitive component.
42
- * @param {ModelComponents.Node} options.node The node that this primitive belongs to.
43
- * @param {Model} options.model The {@link Model} this primitive belongs to.
44
- *
45
- * @alias ModelRuntimePrimitive
46
- * @constructor
47
- *
48
- * @private
49
- */
50
- function ModelRuntimePrimitive(options) {
51
- options = options ?? Frozen.EMPTY_OBJECT;
52
-
53
- const primitive = options.primitive;
54
- const node = options.node;
55
- const model = options.model;
56
- //>>includeStart('debug', pragmas.debug);
57
- Check.typeOf.object("options.primitive", primitive);
58
- Check.typeOf.object("options.node", node);
59
- Check.typeOf.object("options.model", model);
60
- //>>includeEnd('debug');
61
-
62
- /**
63
- * The primitive component associated with this primitive.
64
- *
65
- * @type {ModelComponents.Primitive}
66
- *
67
- * @private
68
- */
69
- this.primitive = primitive;
70
-
71
- /**
72
- * A reference to the node this primitive belongs to.
73
- *
74
- * @type {ModelComponents.Node}
75
- *
76
- * @private
77
- */
78
- this.node = node;
79
-
80
- /**
81
- * A reference to the model
82
- *
83
- * @type {Model}
84
- *
85
- * @private
86
- */
87
- this.model = model;
88
-
89
- /**
90
- * Pipeline stages to apply to this primitive. This
91
- * is an array of classes, each with a static method called
92
- * <code>process()</code>
93
- *
94
- * @type {object[]}
95
- * @readonly
96
- *
97
- * @private
98
- */
99
- this.pipelineStages = [];
100
-
101
- /**
102
- * The generated {@link ModelDrawCommand} or {@link ClassificationModelDrawCommand}
103
- * associated with this primitive.
104
- *
105
- * @type {ModelDrawCommand|ClassificationModelDrawCommand}
106
- *
107
- * @private
108
- */
109
- this.drawCommand = undefined;
110
-
111
- /**
112
- * The bounding sphere of this primitive in object-space.
113
- *
114
- * @type {BoundingSphere}
115
- *
116
- * @private
117
- */
118
- this.boundingSphere = undefined;
119
-
120
- /**
121
- * The bounding sphere of this primitive in 2D world space.
122
- *
123
- * @type {BoundingSphere}
124
- *
125
- * @private
126
- */
127
- this.boundingSphere2D = undefined;
128
-
129
- /**
130
- * A buffer containing the primitive's positions projected to 2D world
131
- * coordinates. This is generated by SceneMode2DPipelineStage and used for
132
- * rendering in 2D / CV mode. The memory is managed by Model; this is just
133
- * a reference.
134
- *
135
- * @type {Buffer}
136
- *
137
- * @private
138
- */
139
- this.positionBuffer2D = undefined;
140
-
141
- /**
142
- * An array containing the lengths of the vertex batches for classification.
143
- * Vertices with the same feature ID are batched together, and each batch is
144
- * drawn with a different draw command in order to properly classify other
145
- * assets.
146
- * <p>
147
- * This is generated by ClassificationPipelineStage. The memory is managed by
148
- * Model; this is just a reference.
149
- * </p>
150
- *
151
- * @type {number[]}
152
- *
153
- * @private
154
- */
155
- this.batchLengths = undefined;
156
-
157
- /**
158
- * An array containing the offsets of the vertex batches for classification.
159
- * Vertices with the same feature ID are batched together, and each batch is
160
- * drawn with a different draw command in order to properly classify other
161
- * assets.
162
- * <p>
163
- * This is generated by ClassificationPipelineStage. The memory is managed by
164
- * Model; this is just a reference.
165
- * </p>
166
- *
167
- * @type {number[]}
168
- *
169
- * @private
170
- */
171
- this.batchOffsets = undefined;
172
-
173
- /**
174
- * Update stages to apply to this primitive.
175
- *
176
- * @type {object[]}
177
- * @readonly
178
- *
179
- * @private
180
- */
181
- this.updateStages = [];
182
- }
183
-
184
- /**
185
- * Configure the primitive pipeline stages. If the pipeline needs to be re-run,
186
- * call this method again to ensure the correct sequence of pipeline stages are
187
- * used.
188
- *
189
- * @param {FrameState} frameState The frame state.
190
- *
191
- * @private
192
- */
193
- ModelRuntimePrimitive.prototype.configurePipeline = function (frameState) {
194
- const pipelineStages = this.pipelineStages;
195
- pipelineStages.length = 0;
196
-
197
- const primitive = this.primitive;
198
- const node = this.node;
199
- const model = this.model;
200
-
201
- const customShader = model.customShader;
202
- const style = model.style;
203
-
204
- const useWebgl2 = frameState.context.webgl2;
205
- const mode = frameState.mode;
206
- const use2D =
207
- mode !== SceneMode.SCENE3D && !frameState.scene3DOnly && model._projectTo2D;
208
- const hasVerticalExaggeration =
209
- frameState.verticalExaggeration !== 1.0 && model.hasVerticalExaggeration;
210
-
211
- const hasMorphTargets =
212
- defined(primitive.morphTargets) && primitive.morphTargets.length > 0;
213
- const hasSkinning = defined(node.skin);
214
-
215
- // Check whether the model is part of a `Model3DTileContent` that
216
- // belongs to a tileset that has imagery layers. If this is the
217
- // case, then the `ImageryPipelineStage` will be required.
218
- const hasImageryLayers = defined(model.imageryLayers);
219
-
220
- const hasCustomShader = defined(customShader);
221
- const hasCustomFragmentShader =
222
- hasCustomShader && defined(customShader.fragmentShaderText);
223
- const materialsEnabled =
224
- !hasCustomFragmentShader ||
225
- customShader.mode !== CustomShaderMode.REPLACE_MATERIAL;
226
- const hasQuantization = ModelUtility.hasQuantizedAttributes(
227
- primitive.attributes,
228
- );
229
-
230
- const generateWireframeIndices =
231
- model.debugWireframe &&
232
- PrimitiveType.isTriangles(primitive.primitiveType) &&
233
- model.debugWireframeMode === "lines" &&
234
- // Generating index buffers for wireframes is always possible in WebGL2.
235
- // However, this will only work in WebGL1 if the model was constructed with
236
- // enableDebugWireframe set to true.
237
- (model._enableDebugWireframe || useWebgl2);
238
-
239
- const generateBarycentricWireframe =
240
- model.debugWireframe &&
241
- PrimitiveType.isTriangles(primitive.primitiveType) &&
242
- model.debugWireframeMode === "barycentric";
243
-
244
- const pointCloudShading = model.pointCloudShading;
245
- const hasAttenuation =
246
- defined(pointCloudShading) && pointCloudShading.attenuation;
247
- const hasPointCloudBackFaceCulling =
248
- defined(pointCloudShading) && pointCloudShading.backFaceCulling;
249
- const hasPointCloudStyle =
250
- primitive.primitiveType === PrimitiveType.POINTS &&
251
- (defined(style) || hasAttenuation || hasPointCloudBackFaceCulling);
252
-
253
- const hasOutlines =
254
- model._enableShowOutline && defined(primitive.outlineCoordinates);
255
-
256
- const hasEdgeVisibility = defined(primitive.edgeVisibility);
257
-
258
- const featureIdFlags = inspectFeatureIds(model, node, primitive);
259
-
260
- const hasClassification = defined(model.classificationType);
261
-
262
- // Start of pipeline -----------------------------------------------------
263
- if (use2D) {
264
- pipelineStages.push(SceneMode2DPipelineStage);
265
- }
266
-
267
- pipelineStages.push(GeometryPipelineStage);
268
-
269
- if (generateWireframeIndices) {
270
- pipelineStages.push(WireframePipelineStage);
271
- }
272
-
273
- if (generateBarycentricWireframe) {
274
- pipelineStages.push(BarycentricWireframePipelineStage);
275
- }
276
-
277
- if (hasClassification) {
278
- pipelineStages.push(ClassificationPipelineStage);
279
- }
280
-
281
- if (hasMorphTargets) {
282
- pipelineStages.push(MorphTargetsPipelineStage);
283
- }
284
-
285
- if (hasSkinning) {
286
- pipelineStages.push(SkinningPipelineStage);
287
- }
288
-
289
- if (hasPointCloudStyle) {
290
- pipelineStages.push(PointCloudStylingPipelineStage);
291
- }
292
-
293
- if (hasQuantization) {
294
- pipelineStages.push(DequantizationPipelineStage);
295
- }
296
-
297
- if (hasImageryLayers) {
298
- if (hasOutlines) {
299
- oneTimeWarning(
300
- "outlines-and-draping",
301
- "Primitive outlines disable imagery draping",
302
- );
303
- } else {
304
- pipelineStages.push(ImageryPipelineStage);
305
- }
306
- }
307
-
308
- if (materialsEnabled) {
309
- pipelineStages.push(MaterialPipelineStage);
310
- }
311
-
312
- // These stages are always run to ensure structs
313
- // are declared to avoid compilation errors.
314
- pipelineStages.push(FeatureIdPipelineStage);
315
- pipelineStages.push(MetadataPipelineStage);
316
- pipelineStages.push(MetadataPickingPipelineStage);
317
-
318
- if (featureIdFlags.hasPropertyTable && model.featureTables.length > 0) {
319
- pipelineStages.push(SelectedFeatureIdPipelineStage);
320
- pipelineStages.push(BatchTexturePipelineStage);
321
- pipelineStages.push(CPUStylingPipelineStage);
322
- }
323
-
324
- if (hasVerticalExaggeration) {
325
- pipelineStages.push(VerticalExaggerationPipelineStage);
326
- }
327
-
328
- if (hasCustomShader) {
329
- pipelineStages.push(CustomShaderPipelineStage);
330
- }
331
-
332
- pipelineStages.push(LightingPipelineStage);
333
-
334
- if (model.allowPicking) {
335
- pipelineStages.push(PickingPipelineStage);
336
- }
337
-
338
- if (hasOutlines) {
339
- pipelineStages.push(PrimitiveOutlinePipelineStage);
340
- }
341
-
342
- if (hasEdgeVisibility) {
343
- // Indicate to Scene (after primitive updates) that the edge MRT should be enabled.
344
- frameState.edgeVisibilityRequested = true;
345
- pipelineStages.push(EdgeVisibilityPipelineStage);
346
- pipelineStages.push(EdgeDetectionPipelineStage);
347
- }
348
-
349
- pipelineStages.push(AlphaPipelineStage);
350
-
351
- pipelineStages.push(PrimitiveStatisticsPipelineStage);
352
-
353
- return;
354
- };
355
-
356
- function inspectFeatureIds(model, node, primitive) {
357
- let featureIds;
358
- // Check instances first, as this is the most specific type of
359
- // feature ID
360
- if (defined(node.instances)) {
361
- featureIds = ModelUtility.getFeatureIdsByLabel(
362
- node.instances.featureIds,
363
- model.instanceFeatureIdLabel,
364
- );
365
-
366
- if (defined(featureIds)) {
367
- return {
368
- hasFeatureIds: true,
369
- hasPropertyTable: defined(featureIds.propertyTableId),
370
- };
371
- }
372
- }
373
-
374
- featureIds = ModelUtility.getFeatureIdsByLabel(
375
- primitive.featureIds,
376
- model.featureIdLabel,
377
- );
378
- if (defined(featureIds)) {
379
- return {
380
- hasFeatureIds: true,
381
- hasPropertyTable: defined(featureIds.propertyTableId),
382
- };
383
- }
384
-
385
- return {
386
- hasFeatureIds: false,
387
- hasPropertyTable: false,
388
- };
389
- }
390
-
391
- export default ModelRuntimePrimitive;
1
+ import Check from "../../Core/Check.js";
2
+ import Frozen from "../../Core/Frozen.js";
3
+ import defined from "../../Core/defined.js";
4
+ import PrimitiveType from "../../Core/PrimitiveType.js";
5
+ import SceneMode from "../SceneMode.js";
6
+ import AlphaPipelineStage from "./AlphaPipelineStage.js";
7
+ import BatchTexturePipelineStage from "./BatchTexturePipelineStage.js";
8
+ import ClassificationPipelineStage from "./ClassificationPipelineStage.js";
9
+ import CPUStylingPipelineStage from "./CPUStylingPipelineStage.js";
10
+ import CustomShaderMode from "./CustomShaderMode.js";
11
+ import CustomShaderPipelineStage from "./CustomShaderPipelineStage.js";
12
+ import DequantizationPipelineStage from "./DequantizationPipelineStage.js";
13
+ import EdgeDetectionPipelineStage from "./EdgeDetectionPipelineStage.js";
14
+ import EdgeVisibilityPipelineStage from "./EdgeVisibilityPipelineStage.js";
15
+ import FeatureIdPipelineStage from "./FeatureIdPipelineStage.js";
16
+ import GeometryPipelineStage from "./GeometryPipelineStage.js";
17
+ import ImageryPipelineStage from "./ImageryPipelineStage.js";
18
+ import LightingPipelineStage from "./LightingPipelineStage.js";
19
+ import MaterialPipelineStage from "./MaterialPipelineStage.js";
20
+ import MetadataPickingPipelineStage from "./MetadataPickingPipelineStage.js";
21
+ import MetadataPipelineStage from "./MetadataPipelineStage.js";
22
+ import ModelUtility from "./ModelUtility.js";
23
+ import MorphTargetsPipelineStage from "./MorphTargetsPipelineStage.js";
24
+ import PickingPipelineStage from "./PickingPipelineStage.js";
25
+ import PointCloudStylingPipelineStage from "./PointCloudStylingPipelineStage.js";
26
+ import PrimitiveOutlinePipelineStage from "./PrimitiveOutlinePipelineStage.js";
27
+ import PrimitiveStatisticsPipelineStage from "./PrimitiveStatisticsPipelineStage.js";
28
+ import SceneMode2DPipelineStage from "./SceneMode2DPipelineStage.js";
29
+ import SelectedFeatureIdPipelineStage from "./SelectedFeatureIdPipelineStage.js";
30
+ import SkinningPipelineStage from "./SkinningPipelineStage.js";
31
+ import VerticalExaggerationPipelineStage from "./VerticalExaggerationPipelineStage.js";
32
+ import WireframePipelineStage from "./WireframePipelineStage.js";
33
+ import BarycentricWireframePipelineStage from "./BarycentricWireframePipelineStage.js";
34
+ import oneTimeWarning from "../../Core/oneTimeWarning.js";
35
+
36
+ /**
37
+ * In memory representation of a single primitive, that is, a primitive
38
+ * and its corresponding mesh.
39
+ *
40
+ * @param {object} options An object containing the following options:
41
+ * @param {ModelComponents.Primitive} options.primitive The primitive component.
42
+ * @param {ModelComponents.Node} options.node The node that this primitive belongs to.
43
+ * @param {Model} options.model The {@link Model} this primitive belongs to.
44
+ *
45
+ * @alias ModelRuntimePrimitive
46
+ * @constructor
47
+ *
48
+ * @private
49
+ */
50
+ function ModelRuntimePrimitive(options) {
51
+ options = options ?? Frozen.EMPTY_OBJECT;
52
+
53
+ const primitive = options.primitive;
54
+ const node = options.node;
55
+ const model = options.model;
56
+ //>>includeStart('debug', pragmas.debug);
57
+ Check.typeOf.object("options.primitive", primitive);
58
+ Check.typeOf.object("options.node", node);
59
+ Check.typeOf.object("options.model", model);
60
+ //>>includeEnd('debug');
61
+
62
+ /**
63
+ * The primitive component associated with this primitive.
64
+ *
65
+ * @type {ModelComponents.Primitive}
66
+ *
67
+ * @private
68
+ */
69
+ this.primitive = primitive;
70
+
71
+ /**
72
+ * A reference to the node this primitive belongs to.
73
+ *
74
+ * @type {ModelComponents.Node}
75
+ *
76
+ * @private
77
+ */
78
+ this.node = node;
79
+
80
+ /**
81
+ * A reference to the model
82
+ *
83
+ * @type {Model}
84
+ *
85
+ * @private
86
+ */
87
+ this.model = model;
88
+
89
+ /**
90
+ * Pipeline stages to apply to this primitive. This
91
+ * is an array of classes, each with a static method called
92
+ * <code>process()</code>
93
+ *
94
+ * @type {object[]}
95
+ * @readonly
96
+ *
97
+ * @private
98
+ */
99
+ this.pipelineStages = [];
100
+
101
+ /**
102
+ * The generated {@link ModelDrawCommand} or {@link ClassificationModelDrawCommand}
103
+ * associated with this primitive.
104
+ *
105
+ * @type {ModelDrawCommand|ClassificationModelDrawCommand}
106
+ *
107
+ * @private
108
+ */
109
+ this.drawCommand = undefined;
110
+
111
+ /**
112
+ * The bounding sphere of this primitive in object-space.
113
+ *
114
+ * @type {BoundingSphere}
115
+ *
116
+ * @private
117
+ */
118
+ this.boundingSphere = undefined;
119
+
120
+ /**
121
+ * The bounding sphere of this primitive in 2D world space.
122
+ *
123
+ * @type {BoundingSphere}
124
+ *
125
+ * @private
126
+ */
127
+ this.boundingSphere2D = undefined;
128
+
129
+ /**
130
+ * A buffer containing the primitive's positions projected to 2D world
131
+ * coordinates. This is generated by SceneMode2DPipelineStage and used for
132
+ * rendering in 2D / CV mode. The memory is managed by Model; this is just
133
+ * a reference.
134
+ *
135
+ * @type {Buffer}
136
+ *
137
+ * @private
138
+ */
139
+ this.positionBuffer2D = undefined;
140
+
141
+ /**
142
+ * An array containing the lengths of the vertex batches for classification.
143
+ * Vertices with the same feature ID are batched together, and each batch is
144
+ * drawn with a different draw command in order to properly classify other
145
+ * assets.
146
+ * <p>
147
+ * This is generated by ClassificationPipelineStage. The memory is managed by
148
+ * Model; this is just a reference.
149
+ * </p>
150
+ *
151
+ * @type {number[]}
152
+ *
153
+ * @private
154
+ */
155
+ this.batchLengths = undefined;
156
+
157
+ /**
158
+ * An array containing the offsets of the vertex batches for classification.
159
+ * Vertices with the same feature ID are batched together, and each batch is
160
+ * drawn with a different draw command in order to properly classify other
161
+ * assets.
162
+ * <p>
163
+ * This is generated by ClassificationPipelineStage. The memory is managed by
164
+ * Model; this is just a reference.
165
+ * </p>
166
+ *
167
+ * @type {number[]}
168
+ *
169
+ * @private
170
+ */
171
+ this.batchOffsets = undefined;
172
+
173
+ /**
174
+ * Update stages to apply to this primitive.
175
+ *
176
+ * @type {object[]}
177
+ * @readonly
178
+ *
179
+ * @private
180
+ */
181
+ this.updateStages = [];
182
+ }
183
+
184
+ /**
185
+ * Configure the primitive pipeline stages. If the pipeline needs to be re-run,
186
+ * call this method again to ensure the correct sequence of pipeline stages are
187
+ * used.
188
+ *
189
+ * @param {FrameState} frameState The frame state.
190
+ *
191
+ * @private
192
+ */
193
+ ModelRuntimePrimitive.prototype.configurePipeline = function (frameState) {
194
+ const pipelineStages = this.pipelineStages;
195
+ pipelineStages.length = 0;
196
+
197
+ const primitive = this.primitive;
198
+ const node = this.node;
199
+ const model = this.model;
200
+
201
+ const customShader = model.customShader;
202
+ const style = model.style;
203
+
204
+ const useWebgl2 = frameState.context.webgl2;
205
+ const mode = frameState.mode;
206
+ const use2D =
207
+ mode !== SceneMode.SCENE3D && !frameState.scene3DOnly && model._projectTo2D;
208
+ const hasVerticalExaggeration =
209
+ frameState.verticalExaggeration !== 1.0 && model.hasVerticalExaggeration;
210
+
211
+ const hasMorphTargets =
212
+ defined(primitive.morphTargets) && primitive.morphTargets.length > 0;
213
+ const hasSkinning = defined(node.skin);
214
+
215
+ // Check whether the model is part of a `Model3DTileContent` that
216
+ // belongs to a tileset that has imagery layers. If this is the
217
+ // case, then the `ImageryPipelineStage` will be required.
218
+ const hasImageryLayers = defined(model.imageryLayers);
219
+
220
+ const hasCustomShader = defined(customShader);
221
+ const hasCustomFragmentShader =
222
+ hasCustomShader && defined(customShader.fragmentShaderText);
223
+ const materialsEnabled =
224
+ !hasCustomFragmentShader ||
225
+ customShader.mode !== CustomShaderMode.REPLACE_MATERIAL;
226
+ const hasQuantization = ModelUtility.hasQuantizedAttributes(
227
+ primitive.attributes,
228
+ );
229
+
230
+ const generateWireframeIndices =
231
+ model.debugWireframe &&
232
+ PrimitiveType.isTriangles(primitive.primitiveType) &&
233
+ model.debugWireframeMode === "lines" &&
234
+ // Generating index buffers for wireframes is always possible in WebGL2.
235
+ // However, this will only work in WebGL1 if the model was constructed with
236
+ // enableDebugWireframe set to true.
237
+ (model._enableDebugWireframe || useWebgl2);
238
+
239
+ const generateBarycentricWireframe =
240
+ model.debugWireframe &&
241
+ PrimitiveType.isTriangles(primitive.primitiveType) &&
242
+ model.debugWireframeMode === "barycentric";
243
+
244
+ const pointCloudShading = model.pointCloudShading;
245
+ const hasAttenuation =
246
+ defined(pointCloudShading) && pointCloudShading.attenuation;
247
+ const hasPointCloudBackFaceCulling =
248
+ defined(pointCloudShading) && pointCloudShading.backFaceCulling;
249
+ const hasPointCloudStyle =
250
+ primitive.primitiveType === PrimitiveType.POINTS &&
251
+ (defined(style) || hasAttenuation || hasPointCloudBackFaceCulling);
252
+
253
+ const hasOutlines =
254
+ model._enableShowOutline && defined(primitive.outlineCoordinates);
255
+
256
+ const hasEdgeVisibility = defined(primitive.edgeVisibility);
257
+
258
+ const featureIdFlags = inspectFeatureIds(model, node, primitive);
259
+
260
+ const hasClassification = defined(model.classificationType);
261
+
262
+ // Start of pipeline -----------------------------------------------------
263
+ if (use2D) {
264
+ pipelineStages.push(SceneMode2DPipelineStage);
265
+ }
266
+
267
+ pipelineStages.push(GeometryPipelineStage);
268
+
269
+ if (generateWireframeIndices) {
270
+ pipelineStages.push(WireframePipelineStage);
271
+ }
272
+
273
+ if (generateBarycentricWireframe) {
274
+ pipelineStages.push(BarycentricWireframePipelineStage);
275
+ }
276
+
277
+ if (hasClassification) {
278
+ pipelineStages.push(ClassificationPipelineStage);
279
+ }
280
+
281
+ if (hasMorphTargets) {
282
+ pipelineStages.push(MorphTargetsPipelineStage);
283
+ }
284
+
285
+ if (hasSkinning) {
286
+ pipelineStages.push(SkinningPipelineStage);
287
+ }
288
+
289
+ if (hasPointCloudStyle) {
290
+ pipelineStages.push(PointCloudStylingPipelineStage);
291
+ }
292
+
293
+ if (hasQuantization) {
294
+ pipelineStages.push(DequantizationPipelineStage);
295
+ }
296
+
297
+ if (hasImageryLayers) {
298
+ if (hasOutlines) {
299
+ oneTimeWarning(
300
+ "outlines-and-draping",
301
+ "Primitive outlines disable imagery draping",
302
+ );
303
+ } else {
304
+ pipelineStages.push(ImageryPipelineStage);
305
+ }
306
+ }
307
+
308
+ if (materialsEnabled) {
309
+ pipelineStages.push(MaterialPipelineStage);
310
+ }
311
+
312
+ // These stages are always run to ensure structs
313
+ // are declared to avoid compilation errors.
314
+ pipelineStages.push(FeatureIdPipelineStage);
315
+ pipelineStages.push(MetadataPipelineStage);
316
+ pipelineStages.push(MetadataPickingPipelineStage);
317
+
318
+ if (featureIdFlags.hasPropertyTable && model.featureTables.length > 0) {
319
+ pipelineStages.push(SelectedFeatureIdPipelineStage);
320
+ pipelineStages.push(BatchTexturePipelineStage);
321
+ pipelineStages.push(CPUStylingPipelineStage);
322
+ }
323
+
324
+ if (hasVerticalExaggeration) {
325
+ pipelineStages.push(VerticalExaggerationPipelineStage);
326
+ }
327
+
328
+ if (hasCustomShader) {
329
+ pipelineStages.push(CustomShaderPipelineStage);
330
+ }
331
+
332
+ pipelineStages.push(LightingPipelineStage);
333
+
334
+ if (model.allowPicking) {
335
+ pipelineStages.push(PickingPipelineStage);
336
+ }
337
+
338
+ if (hasOutlines) {
339
+ pipelineStages.push(PrimitiveOutlinePipelineStage);
340
+ }
341
+
342
+ if (hasEdgeVisibility) {
343
+ // Indicate to Scene (after primitive updates) that the edge MRT should be enabled.
344
+ frameState.edgeVisibilityRequested = true;
345
+ pipelineStages.push(EdgeVisibilityPipelineStage);
346
+ pipelineStages.push(EdgeDetectionPipelineStage);
347
+ }
348
+
349
+ pipelineStages.push(AlphaPipelineStage);
350
+
351
+ pipelineStages.push(PrimitiveStatisticsPipelineStage);
352
+
353
+ return;
354
+ };
355
+
356
+ function inspectFeatureIds(model, node, primitive) {
357
+ let featureIds;
358
+ // Check instances first, as this is the most specific type of
359
+ // feature ID
360
+ if (defined(node.instances)) {
361
+ featureIds = ModelUtility.getFeatureIdsByLabel(
362
+ node.instances.featureIds,
363
+ model.instanceFeatureIdLabel,
364
+ );
365
+
366
+ if (defined(featureIds)) {
367
+ return {
368
+ hasFeatureIds: true,
369
+ hasPropertyTable: defined(featureIds.propertyTableId),
370
+ };
371
+ }
372
+ }
373
+
374
+ featureIds = ModelUtility.getFeatureIdsByLabel(
375
+ primitive.featureIds,
376
+ model.featureIdLabel,
377
+ );
378
+ if (defined(featureIds)) {
379
+ return {
380
+ hasFeatureIds: true,
381
+ hasPropertyTable: defined(featureIds.propertyTableId),
382
+ };
383
+ }
384
+
385
+ return {
386
+ hasFeatureIds: false,
387
+ hasPropertyTable: false,
388
+ };
389
+ }
390
+
391
+ export default ModelRuntimePrimitive;