@cesium/engine 26.3.0 → 26.3.1-wasm.0
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/Build/ThirdParty/Workers/zip-web-worker.js +504 -535
- package/Build/Workers/chunk-2P3WKV6V.js +290 -0
- package/Build/Workers/{chunk-MUW4DJV7.js → chunk-2U5272QU.js} +17 -17
- package/Build/Workers/{chunk-7WXBTNRV.js → chunk-4KCOC6OZ.js} +8 -10
- package/Build/Workers/{chunk-GS7RY2DH.js → chunk-5FULJNWY.js} +11 -13
- package/Build/Workers/{chunk-2PWVICP6.js → chunk-65ZF23AQ.js} +1 -1
- package/Build/Workers/{chunk-SEJIXZZ4.js → chunk-6D5534B7.js} +10 -12
- package/Build/Workers/{chunk-MDDKCLMF.js → chunk-6GFMBHBD.js} +19 -19
- package/Build/Workers/{chunk-PKZA44LH.js → chunk-6VRGQF3D.js} +4 -4
- package/Build/Workers/{chunk-JBJ6BRIM.js → chunk-6XUIECFB.js} +4 -6
- package/Build/Workers/{chunk-DKSANM4A.js → chunk-7KWUH6RK.js} +14 -14
- package/Build/Workers/{chunk-6BSNYZZG.js → chunk-7ZBJRQQT.js} +7 -7
- package/Build/Workers/{chunk-XRZCS3HE.js → chunk-AEHANE5A.js} +991 -5612
- package/Build/Workers/chunk-AUU74SIZ.js +2420 -0
- package/Build/Workers/{chunk-2YY724ZX.js → chunk-B6V5NMIE.js} +13 -11
- package/Build/Workers/{chunk-5JCZHJUU.js → chunk-BRQ52ASU.js} +15 -17
- package/Build/Workers/{chunk-Z2DW5NM2.js → chunk-FVLSQBPH.js} +7 -14
- package/Build/Workers/{chunk-L73K5UPP.js → chunk-IFKM2GZR.js} +12 -12
- package/Build/Workers/{chunk-F34TJJLA.js → chunk-KF6OEWVT.js} +17 -17
- package/Build/Workers/{chunk-JL4NWWQY.js → chunk-KOAXSU77.js} +5 -7
- package/Build/Workers/{chunk-CKK6CUXK.js → chunk-KRVYCMGN.js} +6 -6
- package/Build/Workers/{chunk-KBGAHN5R.js → chunk-LTZRLNQP.js} +1 -1
- package/Build/Workers/{chunk-CQ4TZXAT.js → chunk-M7WEAGWT.js} +8 -8
- package/Build/Workers/{chunk-A7SMPV6B.js → chunk-MJTLGN63.js} +14 -14
- package/Build/Workers/{chunk-DZK34ZVD.js → chunk-MUNZ77KV.js} +1 -1
- package/Build/Workers/{chunk-X27HKF5E.js → chunk-NC5BUJEF.js} +2 -2
- package/Build/Workers/chunk-NYKURYFR.js +2131 -0
- package/Build/Workers/{chunk-5KG7KDDW.js → chunk-NZAQG57U.js} +7 -7
- package/Build/Workers/{chunk-JKTWW7IO.js → chunk-O5GUOP2G.js} +5 -7
- package/Build/Workers/{chunk-6R6SGKYN.js → chunk-OQUOLQTN.js} +8 -10
- package/Build/Workers/chunk-OUG5JB2K.js +46 -0
- package/Build/Workers/{chunk-HDD3RFLT.js → chunk-P4SDLSGF.js} +13 -6
- package/Build/Workers/{chunk-M6W46OAP.js → chunk-P6PC2OIM.js} +7 -7
- package/Build/Workers/{chunk-XSIUYAT6.js → chunk-PPRK3XQU.js} +31 -35
- package/Build/Workers/{chunk-4LRFYRBX.js → chunk-QGTYLWOT.js} +2 -2
- package/Build/Workers/{chunk-COKOYTRS.js → chunk-QHTLIQUH.js} +5 -7
- package/Build/Workers/{chunk-N5YK44FS.js → chunk-ROHWZQZ5.js} +5 -5
- package/Build/Workers/{chunk-XBY3354M.js → chunk-SNUWISJO.js} +6 -8
- package/Build/Workers/{chunk-EDETO6NY.js → chunk-T67YY3KP.js} +4 -2
- package/Build/Workers/{chunk-4DMAXPKB.js → chunk-TF5473GK.js} +13 -13
- package/Build/Workers/{chunk-B7Q2WF6Q.js → chunk-THHFTMAL.js} +4 -6
- package/Build/Workers/{chunk-SL2HCFYW.js → chunk-UFCZ62WM.js} +15 -13
- package/Build/Workers/{chunk-NZQUP52G.js → chunk-UV2YC2Q5.js} +11 -11
- package/Build/Workers/{chunk-E7G32DWL.js → chunk-V4ICCWYA.js} +1 -1
- package/Build/Workers/{chunk-75BC2IHI.js → chunk-VC6XXI2Z.js} +9 -9
- package/Build/Workers/{chunk-JMUUAW4X.js → chunk-VXJ6P4UI.js} +10 -10
- package/Build/Workers/{chunk-QTAEVUED.js → chunk-W2BKP7G7.js} +15 -17
- package/Build/Workers/{chunk-VRECSMG3.js → chunk-WMVGNBSH.js} +2 -2
- package/Build/Workers/{chunk-7SESBH2I.js → chunk-XFZMQZSZ.js} +4 -4
- package/Build/Workers/{chunk-Q2JS5LCB.js → chunk-XJ532R6R.js} +20 -20
- package/Build/Workers/{chunk-SLHK3KAR.js → chunk-YJNU4SM4.js} +5 -5
- package/Build/Workers/{chunk-LL2SGJYH.js → chunk-YJRDTEHQ.js} +8 -8
- package/Build/Workers/chunk-YUICDZKO.js +2660 -0
- package/Build/Workers/{chunk-ATSXKJ3L.js → chunk-Z3DEVGJV.js} +7 -7
- package/Build/Workers/{chunk-6V2KDEHL.js → chunk-ZECGI7UZ.js} +4 -4
- package/Build/Workers/{chunk-LYJUL4XQ.js → chunk-ZFLPVPUJ.js} +6 -8
- package/Build/Workers/{chunk-BNDSDQ7D.js → chunk-ZIM5H2DB.js} +11 -11
- package/Build/Workers/{chunk-KEWK6VZL.js → chunk-ZSQMGGSB.js} +14 -16
- package/Build/Workers/{chunk-2DKJSPYF.js → chunk-ZWYRGMBK.js} +16 -18
- package/Build/Workers/{chunk-UZY5XRL2.js → chunk-ZY733NZA.js} +1 -1
- package/Build/Workers/combineGeometry.js +24 -24
- package/Build/Workers/createBoxGeometry.js +18 -18
- package/Build/Workers/createBoxOutlineGeometry.js +20 -19
- package/Build/Workers/createCircleGeometry.js +28 -27
- package/Build/Workers/createCircleOutlineGeometry.js +21 -20
- package/Build/Workers/createCoplanarPolygonGeometry.js +34 -34
- package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +33 -32
- package/Build/Workers/createCorridorGeometry.js +31 -31
- package/Build/Workers/createCorridorOutlineGeometry.js +30 -30
- package/Build/Workers/createCylinderGeometry.js +20 -20
- package/Build/Workers/createCylinderOutlineGeometry.js +22 -21
- package/Build/Workers/createEllipseGeometry.js +26 -26
- package/Build/Workers/createEllipseOutlineGeometry.js +19 -19
- package/Build/Workers/createEllipsoidGeometry.js +19 -19
- package/Build/Workers/createEllipsoidOutlineGeometry.js +18 -18
- package/Build/Workers/createFrustumGeometry.js +18 -18
- package/Build/Workers/createFrustumOutlineGeometry.js +18 -18
- package/Build/Workers/createGeometry.js +27 -26
- package/Build/Workers/createGroundPolylineGeometry.js +27 -26
- package/Build/Workers/createPlaneGeometry.js +18 -17
- package/Build/Workers/createPlaneOutlineGeometry.js +15 -15
- package/Build/Workers/createPolygonGeometry.js +35 -35
- package/Build/Workers/createPolygonOutlineGeometry.js +34 -34
- package/Build/Workers/createPolylineGeometry.js +28 -29
- package/Build/Workers/createPolylineVolumeGeometry.js +34 -35
- package/Build/Workers/createPolylineVolumeOutlineGeometry.js +30 -31
- package/Build/Workers/createRectangleGeometry.js +30 -30
- package/Build/Workers/createRectangleOutlineGeometry.js +23 -24
- package/Build/Workers/createSimplePolylineGeometry.js +26 -27
- package/Build/Workers/createSphereGeometry.js +19 -19
- package/Build/Workers/createSphereOutlineGeometry.js +18 -18
- package/Build/Workers/createTaskProcessorWorker.js +3 -3
- package/Build/Workers/createVectorTileClampedPolylines.js +17 -16
- package/Build/Workers/createVectorTileGeometries.js +24 -24
- package/Build/Workers/createVectorTilePoints.js +13 -13
- package/Build/Workers/createVectorTilePolygons.js +22 -22
- package/Build/Workers/createVectorTilePolylines.js +17 -16
- package/Build/Workers/createVerticesFromCesium3DTilesTerrain.js +36 -26
- package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +24 -24
- package/Build/Workers/createVerticesFromHeightmap.js +24 -25
- package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +20 -20
- package/Build/Workers/createWallGeometry.js +27 -28
- package/Build/Workers/createWallOutlineGeometry.js +26 -27
- package/Build/Workers/decodeDraco.js +16 -12
- package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +336 -337
- package/Build/Workers/decodeI3S.js +17 -12
- package/Build/Workers/{chunk-GLHDTTTO.js → decodeMeshopt.js} +23 -29
- package/Build/Workers/decodeSpz.js +1960 -0
- package/Build/Workers/gaussianSplatSorter.js +13 -6
- package/Build/Workers/gaussianSplatTextureGenerator.js +13 -6
- package/Build/Workers/incrementallyBuildTerrainPicker.js +9 -10
- package/Build/Workers/transcodeKTX2.js +26 -12
- package/Build/Workers/transferTypedArrayTest.js +1 -1
- package/Build/Workers/upsampleQuantizedTerrainMesh.js +24 -24
- package/Build/Workers/upsampleVerticesFromCesium3DTilesTerrain.js +25 -25
- package/Source/Core/Cesium3DTilesTerrainData.js +11 -1
- package/Source/Core/Cesium3DTilesTerrainGeometryProcessor.js +33 -23
- package/Source/Core/KTX2Transcoder.js +99 -5
- package/Source/Core/Resource.js +2 -0
- package/Source/Core/TaskProcessor.js +249 -129
- package/Source/Core/TrustedServers.js +34 -1
- package/Source/Core/WebAssemblyWorkerInitializer.js +125 -0
- package/Source/Core/fetchWebAssemblyBinary.js +52 -0
- package/Source/Scene/GaussianSplatPrimitive.js +153 -66
- package/Source/Scene/GltfBufferViewLoader.js +25 -13
- package/Source/Scene/GltfSpzLoader.js +5 -4
- package/Source/Scene/SpzDecoder.js +106 -0
- package/Source/ThirdParty/Workers/zip-web-worker.js +1 -1
- package/Source/ThirdParty/zip-module.wasm +0 -0
- package/Source/Workers/createTaskProcessorWorker.js +2 -0
- package/Source/Workers/createVerticesFromCesium3DTilesTerrain.js +13 -1
- package/Source/Workers/decodeDraco.js +7 -3
- package/Source/Workers/decodeI3S.js +7 -3
- package/Source/Workers/decodeMeshopt.js +21 -0
- package/Source/Workers/decodeSpz.js +20 -0
- package/Source/Workers/gaussianSplatSorter.js +7 -3
- package/Source/Workers/gaussianSplatTextureGenerator.js +7 -3
- package/Source/Workers/transcodeKTX2.js +22 -5
- package/index.d.ts +93 -0
- package/index.js +4 -1
- package/package.json +1 -1
- package/Build/Workers/chunk-B4AVL7VI.js +0 -82
- package/Build/Workers/chunk-HDPNFEPP.js +0 -3820
|
@@ -0,0 +1,2420 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Cesium - https://github.com/CesiumGS/cesium
|
|
4
|
+
* Version 1.145.1-wasm.0
|
|
5
|
+
*
|
|
6
|
+
* Copyright 2011-2022 Cesium Contributors
|
|
7
|
+
*
|
|
8
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License.
|
|
10
|
+
* You may obtain a copy of the License at
|
|
11
|
+
*
|
|
12
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
13
|
+
*
|
|
14
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
15
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
16
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
|
+
* See the License for the specific language governing permissions and
|
|
18
|
+
* limitations under the License.
|
|
19
|
+
*
|
|
20
|
+
* Columbus View (Pat. Pend.)
|
|
21
|
+
*
|
|
22
|
+
* Portions licensed separately.
|
|
23
|
+
* See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import {
|
|
27
|
+
TerrainProvider_default
|
|
28
|
+
} from "./chunk-KOAXSU77.js";
|
|
29
|
+
import {
|
|
30
|
+
EllipsoidalOccluder_default,
|
|
31
|
+
TerrainEncoding_default,
|
|
32
|
+
VerticalExaggeration_default
|
|
33
|
+
} from "./chunk-TF5473GK.js";
|
|
34
|
+
import {
|
|
35
|
+
WebMercatorProjection_default
|
|
36
|
+
} from "./chunk-SNUWISJO.js";
|
|
37
|
+
import {
|
|
38
|
+
OrientedBoundingBox_default
|
|
39
|
+
} from "./chunk-MJTLGN63.js";
|
|
40
|
+
import {
|
|
41
|
+
AttributeCompression_default
|
|
42
|
+
} from "./chunk-UV2YC2Q5.js";
|
|
43
|
+
import {
|
|
44
|
+
AxisAlignedBoundingBox_default
|
|
45
|
+
} from "./chunk-ROHWZQZ5.js";
|
|
46
|
+
import {
|
|
47
|
+
IntersectionTests_default,
|
|
48
|
+
Ray_default
|
|
49
|
+
} from "./chunk-VC6XXI2Z.js";
|
|
50
|
+
import {
|
|
51
|
+
BoundingSphere_default,
|
|
52
|
+
Interval_default
|
|
53
|
+
} from "./chunk-ZIM5H2DB.js";
|
|
54
|
+
import {
|
|
55
|
+
Rectangle_default,
|
|
56
|
+
Transforms_default,
|
|
57
|
+
binarySearch_default,
|
|
58
|
+
buildModuleUrl_default
|
|
59
|
+
} from "./chunk-AEHANE5A.js";
|
|
60
|
+
import {
|
|
61
|
+
Matrix4_default
|
|
62
|
+
} from "./chunk-OQUOLQTN.js";
|
|
63
|
+
import {
|
|
64
|
+
ComponentDatatype_default
|
|
65
|
+
} from "./chunk-6XUIECFB.js";
|
|
66
|
+
import {
|
|
67
|
+
Cartesian2_default,
|
|
68
|
+
Cartographic_default,
|
|
69
|
+
Ellipsoid_default,
|
|
70
|
+
FeatureDetection_default
|
|
71
|
+
} from "./chunk-7ZBJRQQT.js";
|
|
72
|
+
import {
|
|
73
|
+
Cartesian3_default,
|
|
74
|
+
Matrix3_default
|
|
75
|
+
} from "./chunk-FVLSQBPH.js";
|
|
76
|
+
import {
|
|
77
|
+
Event_default,
|
|
78
|
+
isCrossOriginUrl_default
|
|
79
|
+
} from "./chunk-NYKURYFR.js";
|
|
80
|
+
import {
|
|
81
|
+
Frozen_default,
|
|
82
|
+
Math_default
|
|
83
|
+
} from "./chunk-P4SDLSGF.js";
|
|
84
|
+
import {
|
|
85
|
+
Check_default,
|
|
86
|
+
RuntimeError_default
|
|
87
|
+
} from "./chunk-PPRK3XQU.js";
|
|
88
|
+
import {
|
|
89
|
+
DeveloperError_default,
|
|
90
|
+
TrustedServers_default,
|
|
91
|
+
__toESM,
|
|
92
|
+
defined_default,
|
|
93
|
+
require_URI
|
|
94
|
+
} from "./chunk-YUICDZKO.js";
|
|
95
|
+
|
|
96
|
+
// packages/engine/Source/Scene/Axis.js
|
|
97
|
+
var Axis = {
|
|
98
|
+
/**
|
|
99
|
+
* Denotes the x-axis.
|
|
100
|
+
*
|
|
101
|
+
* @type {number}
|
|
102
|
+
* @constant
|
|
103
|
+
*/
|
|
104
|
+
X: 0,
|
|
105
|
+
/**
|
|
106
|
+
* Denotes the y-axis.
|
|
107
|
+
*
|
|
108
|
+
* @type {number}
|
|
109
|
+
* @constant
|
|
110
|
+
*/
|
|
111
|
+
Y: 1,
|
|
112
|
+
/**
|
|
113
|
+
* Denotes the z-axis.
|
|
114
|
+
*
|
|
115
|
+
* @type {number}
|
|
116
|
+
* @constant
|
|
117
|
+
*/
|
|
118
|
+
Z: 2
|
|
119
|
+
};
|
|
120
|
+
Axis.Y_UP_TO_Z_UP = Matrix4_default.fromRotationTranslation(
|
|
121
|
+
// Rotation about PI/2 around the X-axis
|
|
122
|
+
Matrix3_default.fromArray([1, 0, 0, 0, 0, 1, 0, -1, 0])
|
|
123
|
+
);
|
|
124
|
+
Axis.Z_UP_TO_Y_UP = Matrix4_default.fromRotationTranslation(
|
|
125
|
+
// Rotation about -PI/2 around the X-axis
|
|
126
|
+
Matrix3_default.fromArray([1, 0, 0, 0, 0, -1, 0, 1, 0])
|
|
127
|
+
);
|
|
128
|
+
Axis.X_UP_TO_Z_UP = Matrix4_default.fromRotationTranslation(
|
|
129
|
+
// Rotation about -PI/2 around the Y-axis
|
|
130
|
+
Matrix3_default.fromArray([0, 0, 1, 0, 1, 0, -1, 0, 0])
|
|
131
|
+
);
|
|
132
|
+
Axis.Z_UP_TO_X_UP = Matrix4_default.fromRotationTranslation(
|
|
133
|
+
// Rotation about PI/2 around the Y-axis
|
|
134
|
+
Matrix3_default.fromArray([0, 0, -1, 0, 1, 0, 1, 0, 0])
|
|
135
|
+
);
|
|
136
|
+
Axis.X_UP_TO_Y_UP = Matrix4_default.fromRotationTranslation(
|
|
137
|
+
// Rotation about PI/2 around the Z-axis
|
|
138
|
+
Matrix3_default.fromArray([0, 1, 0, -1, 0, 0, 0, 0, 1])
|
|
139
|
+
);
|
|
140
|
+
Axis.Y_UP_TO_X_UP = Matrix4_default.fromRotationTranslation(
|
|
141
|
+
// Rotation about -PI/2 around the Z-axis
|
|
142
|
+
Matrix3_default.fromArray([0, -1, 0, 1, 0, 0, 0, 0, 1])
|
|
143
|
+
);
|
|
144
|
+
Axis.fromName = function(name) {
|
|
145
|
+
Check_default.typeOf.string("name", name);
|
|
146
|
+
return Axis[name];
|
|
147
|
+
};
|
|
148
|
+
Object.freeze(Axis);
|
|
149
|
+
var Axis_default = Axis;
|
|
150
|
+
|
|
151
|
+
// packages/engine/Source/Scene/SceneMode.js
|
|
152
|
+
var SceneMode = {
|
|
153
|
+
/**
|
|
154
|
+
* Morphing between mode, e.g., 3D to 2D.
|
|
155
|
+
*
|
|
156
|
+
* @type {number}
|
|
157
|
+
* @constant
|
|
158
|
+
*/
|
|
159
|
+
MORPHING: 0,
|
|
160
|
+
/**
|
|
161
|
+
* Columbus View mode. A 2.5D perspective view where the map is laid out
|
|
162
|
+
* flat and objects with non-zero height are drawn above it.
|
|
163
|
+
*
|
|
164
|
+
* @type {number}
|
|
165
|
+
* @constant
|
|
166
|
+
*/
|
|
167
|
+
COLUMBUS_VIEW: 1,
|
|
168
|
+
/**
|
|
169
|
+
* 2D mode. The map is viewed top-down with an orthographic projection.
|
|
170
|
+
*
|
|
171
|
+
* @type {number}
|
|
172
|
+
* @constant
|
|
173
|
+
*/
|
|
174
|
+
SCENE2D: 2,
|
|
175
|
+
/**
|
|
176
|
+
* 3D mode. A traditional 3D perspective view of the globe.
|
|
177
|
+
*
|
|
178
|
+
* @type {number}
|
|
179
|
+
* @constant
|
|
180
|
+
*/
|
|
181
|
+
SCENE3D: 3
|
|
182
|
+
};
|
|
183
|
+
SceneMode.getMorphTime = function(value) {
|
|
184
|
+
if (value === SceneMode.SCENE3D) {
|
|
185
|
+
return 1;
|
|
186
|
+
} else if (value === SceneMode.MORPHING) {
|
|
187
|
+
return void 0;
|
|
188
|
+
}
|
|
189
|
+
return 0;
|
|
190
|
+
};
|
|
191
|
+
Object.freeze(SceneMode);
|
|
192
|
+
var SceneMode_default = SceneMode;
|
|
193
|
+
|
|
194
|
+
// packages/engine/Source/Core/TaskProcessor.js
|
|
195
|
+
var import_urijs = __toESM(require_URI(), 1);
|
|
196
|
+
|
|
197
|
+
// packages/engine/Source/Core/destroyObject.js
|
|
198
|
+
function returnTrue() {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
function destroyObject(object, message) {
|
|
202
|
+
message = message ?? "This object was destroyed, i.e., destroy() was called.";
|
|
203
|
+
function throwOnDestroyed() {
|
|
204
|
+
throw new DeveloperError_default(message);
|
|
205
|
+
}
|
|
206
|
+
for (const key in object) {
|
|
207
|
+
if (typeof object[key] === "function") {
|
|
208
|
+
object[key] = throwOnDestroyed;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
object.isDestroyed = returnTrue;
|
|
212
|
+
return void 0;
|
|
213
|
+
}
|
|
214
|
+
var destroyObject_default = destroyObject;
|
|
215
|
+
|
|
216
|
+
// packages/engine/Source/Core/WebAssemblyWorkerInitializer.js
|
|
217
|
+
function getWebAssemblyLoaderConfig(workerPath, wasmOptions) {
|
|
218
|
+
const config = {
|
|
219
|
+
modulePath: void 0,
|
|
220
|
+
wasmBinaryFile: void 0
|
|
221
|
+
};
|
|
222
|
+
if (!FeatureDetection_default.supportsWebAssembly()) {
|
|
223
|
+
if (!defined_default(wasmOptions.fallbackModulePath)) {
|
|
224
|
+
throw new RuntimeError_default(
|
|
225
|
+
`This browser does not support Web Assembly, and no backup module was provided for ${workerPath}`
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
config.modulePath = buildModuleUrl_default(wasmOptions.fallbackModulePath);
|
|
229
|
+
return config;
|
|
230
|
+
}
|
|
231
|
+
config.wasmBinaryFile = buildModuleUrl_default(wasmOptions.wasmBinaryFile);
|
|
232
|
+
if (defined_default(wasmOptions.modulePath)) {
|
|
233
|
+
config.modulePath = buildModuleUrl_default(wasmOptions.modulePath);
|
|
234
|
+
}
|
|
235
|
+
return config;
|
|
236
|
+
}
|
|
237
|
+
function WebAssemblyWorkerInitializer(workerPath, options) {
|
|
238
|
+
this._config = defined_default(options) ? getWebAssemblyLoaderConfig(workerPath, options) : void 0;
|
|
239
|
+
this._worker = void 0;
|
|
240
|
+
this._pending = void 0;
|
|
241
|
+
this.promise = void 0;
|
|
242
|
+
}
|
|
243
|
+
WebAssemblyWorkerInitializer.prototype._settle = function(error, result) {
|
|
244
|
+
const pending = this._pending;
|
|
245
|
+
if (!defined_default(pending)) {
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
this._pending = void 0;
|
|
249
|
+
this._worker.removeEventListener("message", pending.listener);
|
|
250
|
+
if (defined_default(error)) {
|
|
251
|
+
pending.reject(error);
|
|
252
|
+
} else {
|
|
253
|
+
pending.resolve(result);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
WebAssemblyWorkerInitializer.prototype.initialize = function(worker, canTransferArrayBuffer2, deserializeError) {
|
|
257
|
+
this._worker = worker;
|
|
258
|
+
const response = new Promise((resolve, reject) => {
|
|
259
|
+
const listener = ({ data }) => {
|
|
260
|
+
if (!defined_default(data) || typeof data !== "object" || !Object.prototype.hasOwnProperty.call(data, "result") && !Object.prototype.hasOwnProperty.call(data, "error")) {
|
|
261
|
+
this._settle(new RuntimeError_default("Could not configure wasm module"));
|
|
262
|
+
} else if (defined_default(data.error)) {
|
|
263
|
+
this._settle(deserializeError(data.error));
|
|
264
|
+
} else {
|
|
265
|
+
this._settle(void 0, data.result);
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
this._pending = { listener, resolve, reject };
|
|
269
|
+
worker.addEventListener("message", listener);
|
|
270
|
+
});
|
|
271
|
+
this.promise = (async () => {
|
|
272
|
+
try {
|
|
273
|
+
const canTransfer = await canTransferArrayBuffer2();
|
|
274
|
+
if (this._worker === worker && defined_default(this._pending)) {
|
|
275
|
+
worker.postMessage({
|
|
276
|
+
canTransferArrayBuffer: canTransfer,
|
|
277
|
+
baseUrl: buildModuleUrl_default.getCesiumBaseUrl().url,
|
|
278
|
+
trustedServers: TrustedServers_default.pack(),
|
|
279
|
+
parameters: { webAssemblyConfig: this._config }
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
} catch (error) {
|
|
283
|
+
if (this._worker === worker) {
|
|
284
|
+
this._settle(error);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return response;
|
|
288
|
+
})();
|
|
289
|
+
return this.promise;
|
|
290
|
+
};
|
|
291
|
+
WebAssemblyWorkerInitializer.prototype.reset = function(worker, error) {
|
|
292
|
+
if (this._worker !== worker) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
this._settle(error);
|
|
296
|
+
this._worker = void 0;
|
|
297
|
+
this.promise = void 0;
|
|
298
|
+
};
|
|
299
|
+
var WebAssemblyWorkerInitializer_default = WebAssemblyWorkerInitializer;
|
|
300
|
+
|
|
301
|
+
// packages/engine/Source/Core/TaskProcessor.js
|
|
302
|
+
function canTransferArrayBuffer() {
|
|
303
|
+
if (!defined_default(TaskProcessor._canTransferArrayBuffer)) {
|
|
304
|
+
const worker = createWorker("transferTypedArrayTest");
|
|
305
|
+
worker.postMessage = worker.webkitPostMessage ?? worker.postMessage;
|
|
306
|
+
const value = 99;
|
|
307
|
+
const array = new Int8Array([value]);
|
|
308
|
+
let settled = false;
|
|
309
|
+
let settle;
|
|
310
|
+
const promise = new Promise((resolve) => {
|
|
311
|
+
const cleanup = () => {
|
|
312
|
+
worker.removeEventListener("message", onMessage);
|
|
313
|
+
worker.removeEventListener("error", onFailure);
|
|
314
|
+
worker.removeEventListener("messageerror", onFailure);
|
|
315
|
+
worker.terminate();
|
|
316
|
+
};
|
|
317
|
+
settle = (result) => {
|
|
318
|
+
if (settled) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
settled = true;
|
|
322
|
+
cleanup();
|
|
323
|
+
TaskProcessor._canTransferArrayBuffer = result;
|
|
324
|
+
resolve(result);
|
|
325
|
+
};
|
|
326
|
+
const onMessage = (event) => {
|
|
327
|
+
const array2 = event.data?.array;
|
|
328
|
+
settle(defined_default(array2) && array2[0] === value);
|
|
329
|
+
};
|
|
330
|
+
const onFailure = () => settle(false);
|
|
331
|
+
worker.addEventListener("message", onMessage);
|
|
332
|
+
worker.addEventListener("error", onFailure);
|
|
333
|
+
worker.addEventListener("messageerror", onFailure);
|
|
334
|
+
});
|
|
335
|
+
TaskProcessor._canTransferArrayBuffer = promise;
|
|
336
|
+
try {
|
|
337
|
+
worker.postMessage(
|
|
338
|
+
{
|
|
339
|
+
array
|
|
340
|
+
},
|
|
341
|
+
[array.buffer]
|
|
342
|
+
);
|
|
343
|
+
} catch (e) {
|
|
344
|
+
settle(false);
|
|
345
|
+
return TaskProcessor._canTransferArrayBuffer;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return TaskProcessor._canTransferArrayBuffer;
|
|
349
|
+
}
|
|
350
|
+
var taskCompletedEvent = new Event_default();
|
|
351
|
+
function urlFromScript(script) {
|
|
352
|
+
let blob;
|
|
353
|
+
try {
|
|
354
|
+
blob = new Blob([script], {
|
|
355
|
+
type: "application/javascript"
|
|
356
|
+
});
|
|
357
|
+
} catch (e) {
|
|
358
|
+
const BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder;
|
|
359
|
+
const blobBuilder = new BlobBuilder();
|
|
360
|
+
blobBuilder.append(script);
|
|
361
|
+
blob = blobBuilder.getBlob("application/javascript");
|
|
362
|
+
}
|
|
363
|
+
const URL = window.URL || window.webkitURL;
|
|
364
|
+
return URL.createObjectURL(blob);
|
|
365
|
+
}
|
|
366
|
+
function createWorker(url) {
|
|
367
|
+
const uri = new import_urijs.default(url);
|
|
368
|
+
const isUri = uri.scheme().length !== 0;
|
|
369
|
+
const moduleID = url.replace(/\.js$/, "");
|
|
370
|
+
const options = {};
|
|
371
|
+
let workerPath;
|
|
372
|
+
let crossOriginUrl;
|
|
373
|
+
if (isCrossOriginUrl_default(url)) {
|
|
374
|
+
crossOriginUrl = url;
|
|
375
|
+
} else if (!isUri) {
|
|
376
|
+
const moduleAbsoluteUrl = buildModuleUrl_default(
|
|
377
|
+
`${TaskProcessor._workerModulePrefix}/${moduleID}.js`
|
|
378
|
+
);
|
|
379
|
+
if (isCrossOriginUrl_default(moduleAbsoluteUrl)) {
|
|
380
|
+
crossOriginUrl = moduleAbsoluteUrl;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (crossOriginUrl) {
|
|
384
|
+
const script = `import "${crossOriginUrl}";`;
|
|
385
|
+
workerPath = urlFromScript(script);
|
|
386
|
+
options.type = "module";
|
|
387
|
+
return new Worker(workerPath, options);
|
|
388
|
+
}
|
|
389
|
+
if (!isUri && typeof CESIUM_WORKERS !== "undefined") {
|
|
390
|
+
const script = `
|
|
391
|
+
importScripts("${urlFromScript(CESIUM_WORKERS)}");
|
|
392
|
+
CesiumWorkers["${moduleID}"]();
|
|
393
|
+
`;
|
|
394
|
+
workerPath = urlFromScript(script);
|
|
395
|
+
return new Worker(workerPath, options);
|
|
396
|
+
}
|
|
397
|
+
workerPath = url;
|
|
398
|
+
if (!isUri) {
|
|
399
|
+
workerPath = buildModuleUrl_default(
|
|
400
|
+
`${TaskProcessor._workerModulePrefix + moduleID}.js`
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
if (!FeatureDetection_default.supportsEsmWebWorkers()) {
|
|
404
|
+
throw new RuntimeError_default(
|
|
405
|
+
"This browser is not supported. Please update your browser to continue."
|
|
406
|
+
);
|
|
407
|
+
}
|
|
408
|
+
options.type = "module";
|
|
409
|
+
return new Worker(workerPath, options);
|
|
410
|
+
}
|
|
411
|
+
function TaskProcessor(workerPath, maximumActiveTasks) {
|
|
412
|
+
this._workerPath = workerPath;
|
|
413
|
+
this._maximumActiveTasks = maximumActiveTasks ?? Number.POSITIVE_INFINITY;
|
|
414
|
+
this._activeTasks = 0;
|
|
415
|
+
this._nextID = 0;
|
|
416
|
+
this._webAssemblyInitializer = void 0;
|
|
417
|
+
this._pendingTasks = /* @__PURE__ */ new Map();
|
|
418
|
+
this._workerFailureHandlers = /* @__PURE__ */ new Map();
|
|
419
|
+
}
|
|
420
|
+
function deserializeWorkerError(serializedError) {
|
|
421
|
+
let error = serializedError;
|
|
422
|
+
if (error.name === "RuntimeError") {
|
|
423
|
+
error = new RuntimeError_default(serializedError.message);
|
|
424
|
+
error.stack = serializedError.stack;
|
|
425
|
+
} else if (error.name === "DeveloperError") {
|
|
426
|
+
error = new DeveloperError_default(serializedError.message);
|
|
427
|
+
error.stack = serializedError.stack;
|
|
428
|
+
} else if (error.name === "Error") {
|
|
429
|
+
error = new Error(serializedError.message);
|
|
430
|
+
error.stack = serializedError.stack;
|
|
431
|
+
} else if (defined_default(error.name) && defined_default(error.message)) {
|
|
432
|
+
error = new Error(`${serializedError.name}: ${serializedError.message}`);
|
|
433
|
+
error.stack = serializedError.stack;
|
|
434
|
+
}
|
|
435
|
+
return error;
|
|
436
|
+
}
|
|
437
|
+
function workerFailureToError(event) {
|
|
438
|
+
if (defined_default(event.error)) {
|
|
439
|
+
if (event.error instanceof Error) {
|
|
440
|
+
return event.error;
|
|
441
|
+
}
|
|
442
|
+
if (defined_default(event.error.message)) {
|
|
443
|
+
const error = new Error(event.error.message);
|
|
444
|
+
if (defined_default(event.error.name)) {
|
|
445
|
+
error.name = event.error.name;
|
|
446
|
+
}
|
|
447
|
+
if (defined_default(event.error.stack)) {
|
|
448
|
+
error.stack = event.error.stack;
|
|
449
|
+
}
|
|
450
|
+
return error;
|
|
451
|
+
}
|
|
452
|
+
return new Error(String(event.error));
|
|
453
|
+
}
|
|
454
|
+
return new Error(event.message ?? "Worker failed");
|
|
455
|
+
}
|
|
456
|
+
function removeWorkerFailureHandler(processor, worker) {
|
|
457
|
+
const handlers = processor._workerFailureHandlers;
|
|
458
|
+
if (!defined_default(handlers)) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
const handler = handlers.get(worker);
|
|
462
|
+
if (!defined_default(handler)) {
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
worker.removeEventListener("error", handler);
|
|
466
|
+
worker.removeEventListener("messageerror", handler);
|
|
467
|
+
handlers.delete(worker);
|
|
468
|
+
}
|
|
469
|
+
function settleTask(processor, id, error, result) {
|
|
470
|
+
if (!defined_default(processor._pendingTasks)) {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
const pendingTask = processor._pendingTasks.get(id);
|
|
474
|
+
if (!defined_default(pendingTask)) {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
processor._pendingTasks.delete(id);
|
|
478
|
+
pendingTask.worker.removeEventListener("message", pendingTask.listener);
|
|
479
|
+
if (defined_default(error)) {
|
|
480
|
+
taskCompletedEvent.raiseEvent(error);
|
|
481
|
+
pendingTask.reject(error);
|
|
482
|
+
} else {
|
|
483
|
+
taskCompletedEvent.raiseEvent();
|
|
484
|
+
pendingTask.resolve(result);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
function cleanupWorker(processor, worker, error) {
|
|
488
|
+
processor._webAssemblyInitializer?.reset(worker, error);
|
|
489
|
+
removeWorkerFailureHandler(processor, worker);
|
|
490
|
+
if (defined_default(error) && defined_default(processor._pendingTasks)) {
|
|
491
|
+
for (const [id, pendingTask] of Array.from(
|
|
492
|
+
processor._pendingTasks.entries()
|
|
493
|
+
)) {
|
|
494
|
+
if (pendingTask.worker === worker) {
|
|
495
|
+
settleTask(processor, id, error);
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
worker.terminate();
|
|
500
|
+
if (processor._worker === worker) {
|
|
501
|
+
processor._worker = void 0;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
function handleWorkerFailure(processor, worker, event) {
|
|
505
|
+
const error = workerFailureToError(event);
|
|
506
|
+
cleanupWorker(processor, worker, error);
|
|
507
|
+
}
|
|
508
|
+
function createProcessorWorker(processor) {
|
|
509
|
+
const worker = createWorker(processor._workerPath);
|
|
510
|
+
const failureHandler = (event) => handleWorkerFailure(processor, worker, event);
|
|
511
|
+
worker.addEventListener("error", failureHandler);
|
|
512
|
+
worker.addEventListener("messageerror", failureHandler);
|
|
513
|
+
processor._workerFailureHandlers.set(worker, failureHandler);
|
|
514
|
+
return worker;
|
|
515
|
+
}
|
|
516
|
+
async function getWorker(processor) {
|
|
517
|
+
if (!defined_default(processor._webAssemblyInitializer)) {
|
|
518
|
+
if (!defined_default(processor._worker)) {
|
|
519
|
+
processor._worker = createProcessorWorker(processor);
|
|
520
|
+
}
|
|
521
|
+
return processor._worker;
|
|
522
|
+
}
|
|
523
|
+
await processor.initWebAssemblyModule();
|
|
524
|
+
return processor._worker;
|
|
525
|
+
}
|
|
526
|
+
var emptyTransferableObjectArray = [];
|
|
527
|
+
async function runTask(processor, parameters, transferableObjects) {
|
|
528
|
+
const id = processor._nextID++;
|
|
529
|
+
const worker = defined_default(processor._webAssemblyInitializer) ? await getWorker(processor) : processor._worker;
|
|
530
|
+
if (processor.isDestroyed()) {
|
|
531
|
+
throw new RuntimeError_default("TaskProcessor was destroyed.");
|
|
532
|
+
}
|
|
533
|
+
const promise = new Promise((resolve, reject) => {
|
|
534
|
+
const listener = ({ data }) => {
|
|
535
|
+
if (!defined_default(data) || data.id !== id) {
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
if (defined_default(data.error)) {
|
|
539
|
+
settleTask(processor, id, deserializeWorkerError(data.error));
|
|
540
|
+
} else {
|
|
541
|
+
settleTask(processor, id, void 0, data.result);
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
processor._pendingTasks.set(id, {
|
|
545
|
+
worker,
|
|
546
|
+
listener,
|
|
547
|
+
resolve,
|
|
548
|
+
reject
|
|
549
|
+
});
|
|
550
|
+
worker.addEventListener("message", listener);
|
|
551
|
+
});
|
|
552
|
+
try {
|
|
553
|
+
const canTransfer = await Promise.resolve(canTransferArrayBuffer());
|
|
554
|
+
if (!processor._pendingTasks.has(id)) {
|
|
555
|
+
return promise;
|
|
556
|
+
}
|
|
557
|
+
if (!defined_default(transferableObjects)) {
|
|
558
|
+
transferableObjects = emptyTransferableObjectArray;
|
|
559
|
+
} else if (!canTransfer) {
|
|
560
|
+
transferableObjects.length = 0;
|
|
561
|
+
}
|
|
562
|
+
worker.postMessage(
|
|
563
|
+
{
|
|
564
|
+
id,
|
|
565
|
+
baseUrl: buildModuleUrl_default.getCesiumBaseUrl().url,
|
|
566
|
+
trustedServers: TrustedServers_default.pack(),
|
|
567
|
+
parameters,
|
|
568
|
+
canTransferArrayBuffer: canTransfer
|
|
569
|
+
},
|
|
570
|
+
transferableObjects
|
|
571
|
+
);
|
|
572
|
+
} catch (error) {
|
|
573
|
+
settleTask(processor, id, error);
|
|
574
|
+
}
|
|
575
|
+
return promise;
|
|
576
|
+
}
|
|
577
|
+
async function scheduleTask(processor, parameters, transferableObjects) {
|
|
578
|
+
++processor._activeTasks;
|
|
579
|
+
try {
|
|
580
|
+
const result = await runTask(processor, parameters, transferableObjects);
|
|
581
|
+
--processor._activeTasks;
|
|
582
|
+
return result;
|
|
583
|
+
} catch (error) {
|
|
584
|
+
--processor._activeTasks;
|
|
585
|
+
throw error;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
TaskProcessor.prototype.scheduleTask = function(parameters, transferableObjects) {
|
|
589
|
+
if (!defined_default(this._worker)) {
|
|
590
|
+
if (!defined_default(this._webAssemblyInitializer)) {
|
|
591
|
+
this._worker = createProcessorWorker(this);
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
if (this._activeTasks >= this._maximumActiveTasks) {
|
|
595
|
+
return void 0;
|
|
596
|
+
}
|
|
597
|
+
return scheduleTask(this, parameters, transferableObjects);
|
|
598
|
+
};
|
|
599
|
+
TaskProcessor.prototype.initWebAssemblyModule = async function(webAssemblyOptions) {
|
|
600
|
+
let initializer = this._webAssemblyInitializer;
|
|
601
|
+
if (defined_default(initializer?.promise)) {
|
|
602
|
+
return initializer.promise;
|
|
603
|
+
}
|
|
604
|
+
if (defined_default(webAssemblyOptions) || !defined_default(initializer)) {
|
|
605
|
+
initializer = new WebAssemblyWorkerInitializer_default(
|
|
606
|
+
this._workerPath,
|
|
607
|
+
webAssemblyOptions
|
|
608
|
+
);
|
|
609
|
+
this._webAssemblyInitializer = initializer;
|
|
610
|
+
}
|
|
611
|
+
const worker = this._worker = createProcessorWorker(this);
|
|
612
|
+
try {
|
|
613
|
+
return await initializer.initialize(
|
|
614
|
+
worker,
|
|
615
|
+
canTransferArrayBuffer,
|
|
616
|
+
deserializeWorkerError
|
|
617
|
+
);
|
|
618
|
+
} catch (error) {
|
|
619
|
+
if (this._workerFailureHandlers.has(worker)) {
|
|
620
|
+
cleanupWorker(this, worker, error);
|
|
621
|
+
}
|
|
622
|
+
throw error;
|
|
623
|
+
}
|
|
624
|
+
};
|
|
625
|
+
TaskProcessor.prototype.isDestroyed = function() {
|
|
626
|
+
return false;
|
|
627
|
+
};
|
|
628
|
+
TaskProcessor.prototype.destroy = function() {
|
|
629
|
+
const error = new RuntimeError_default("TaskProcessor was destroyed.");
|
|
630
|
+
for (const worker of this._workerFailureHandlers.keys()) {
|
|
631
|
+
cleanupWorker(this, worker, error);
|
|
632
|
+
}
|
|
633
|
+
return destroyObject_default(this);
|
|
634
|
+
};
|
|
635
|
+
TaskProcessor.taskCompletedEvent = taskCompletedEvent;
|
|
636
|
+
TaskProcessor._defaultWorkerModulePrefix = "Workers/";
|
|
637
|
+
TaskProcessor._workerModulePrefix = TaskProcessor._defaultWorkerModulePrefix;
|
|
638
|
+
TaskProcessor._canTransferArrayBuffer = void 0;
|
|
639
|
+
var TaskProcessor_default = TaskProcessor;
|
|
640
|
+
|
|
641
|
+
// packages/engine/Source/Core/TerrainPicker.js
|
|
642
|
+
var MAXIMUM_TERRAIN_PICKER_LEVEL = 3;
|
|
643
|
+
var TerrainPicker = class {
|
|
644
|
+
/**
|
|
645
|
+
* @param {Float64Array} vertices The terrain mesh's vertex buffer.
|
|
646
|
+
* @param {Uint8Array|Uint16Array|Uint32Array} indices The terrain mesh's index buffer.
|
|
647
|
+
* @param {TerrainEncoding} encoding The terrain mesh's vertex encoding.
|
|
648
|
+
*/
|
|
649
|
+
constructor(vertices, indices, encoding) {
|
|
650
|
+
Check_default.defined("vertices", vertices);
|
|
651
|
+
Check_default.defined("indices", indices);
|
|
652
|
+
Check_default.defined("encoding", encoding);
|
|
653
|
+
this._vertices = vertices;
|
|
654
|
+
this._indices = indices;
|
|
655
|
+
this._encoding = encoding;
|
|
656
|
+
this._inverseTransform = new Matrix4_default();
|
|
657
|
+
this._needsRebuild = true;
|
|
658
|
+
this._rootNode = new TerrainPickerNode();
|
|
659
|
+
}
|
|
660
|
+
/**
|
|
661
|
+
* Indicates whether the terrain picker needs to be rebuilt due to changes in the underlying terrain mesh's vertices or indices.
|
|
662
|
+
* @type {boolean}
|
|
663
|
+
*/
|
|
664
|
+
get needsRebuild() {
|
|
665
|
+
return this._needsRebuild;
|
|
666
|
+
}
|
|
667
|
+
set needsRebuild(value) {
|
|
668
|
+
this._needsRebuild = value;
|
|
669
|
+
}
|
|
670
|
+
/**
|
|
671
|
+
* Determines the point on the mesh where the given ray intersects.
|
|
672
|
+
* @param {Ray} ray The ray to test.
|
|
673
|
+
* @param {Matrix4} tileTransform The terrain mesh tile's transform from local space to world space.
|
|
674
|
+
* @param {Boolean} cullBackFaces Whether to consider back-facing triangles as intersections.
|
|
675
|
+
* @param {SceneMode} mode The scene mode (2D/3D/Columbus View).
|
|
676
|
+
* @param {MapProjection} projection The map projection.
|
|
677
|
+
* @returns {Cartesian3 | undefined} result The intersection point, or undefined if there is no intersection.
|
|
678
|
+
* @private
|
|
679
|
+
*/
|
|
680
|
+
rayIntersect(ray, tileTransform, cullBackFaces, mode, projection) {
|
|
681
|
+
if (this._needsRebuild) {
|
|
682
|
+
reset(this, tileTransform);
|
|
683
|
+
}
|
|
684
|
+
const invTransform = this._inverseTransform;
|
|
685
|
+
const transformedRay = scratchTransformedRay;
|
|
686
|
+
transformedRay.origin = Matrix4_default.multiplyByPoint(
|
|
687
|
+
invTransform,
|
|
688
|
+
ray.origin,
|
|
689
|
+
transformedRay.origin
|
|
690
|
+
);
|
|
691
|
+
transformedRay.direction = Matrix4_default.multiplyByPointAsVector(
|
|
692
|
+
invTransform,
|
|
693
|
+
ray.direction,
|
|
694
|
+
transformedRay.direction
|
|
695
|
+
);
|
|
696
|
+
const intersections = [];
|
|
697
|
+
getNodesIntersectingRay(this._rootNode, transformedRay, intersections);
|
|
698
|
+
return findClosestPointInClosestNode(
|
|
699
|
+
this,
|
|
700
|
+
intersections,
|
|
701
|
+
ray,
|
|
702
|
+
cullBackFaces,
|
|
703
|
+
mode,
|
|
704
|
+
projection
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
var incrementallyBuildTerrainPickerTaskProcessor = new TaskProcessor_default(
|
|
709
|
+
"incrementallyBuildTerrainPicker"
|
|
710
|
+
);
|
|
711
|
+
var TerrainPickerNode = class _TerrainPickerNode {
|
|
712
|
+
constructor() {
|
|
713
|
+
this.x = 0;
|
|
714
|
+
this.y = 0;
|
|
715
|
+
this.level = 0;
|
|
716
|
+
this.aabb = createAABBForNode(this.x, this.y, this.level);
|
|
717
|
+
this.intersectingTriangles = new Uint32Array(0);
|
|
718
|
+
this.children = [];
|
|
719
|
+
this.buildingChildren = false;
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* Adds a child node to this node.
|
|
723
|
+
*
|
|
724
|
+
* @param {number} childIdx The index of the child to add (0-3).
|
|
725
|
+
*/
|
|
726
|
+
addChild(childIdx) {
|
|
727
|
+
if (childIdx < 0 || childIdx > 3) {
|
|
728
|
+
throw new DeveloperError_default(
|
|
729
|
+
"TerrainPickerNode child index must be between 0 and 3, inclusive."
|
|
730
|
+
);
|
|
731
|
+
}
|
|
732
|
+
const childNode = new _TerrainPickerNode();
|
|
733
|
+
childNode.x = this.x * 2 + (childIdx & 1);
|
|
734
|
+
childNode.y = this.y * 2 + (childIdx >> 1 & 1);
|
|
735
|
+
childNode.level = this.level + 1;
|
|
736
|
+
childNode.aabb = createAABBForNode(
|
|
737
|
+
childNode.x,
|
|
738
|
+
childNode.y,
|
|
739
|
+
childNode.level
|
|
740
|
+
);
|
|
741
|
+
this.children[childIdx] = childNode;
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
var scratchTransformedRay = new Ray_default();
|
|
745
|
+
var scratchTrianglePoints = [
|
|
746
|
+
new Cartesian3_default(),
|
|
747
|
+
new Cartesian3_default(),
|
|
748
|
+
new Cartesian3_default()
|
|
749
|
+
];
|
|
750
|
+
function reset(terrainPicker, tileTransform) {
|
|
751
|
+
Matrix4_default.inverse(tileTransform, terrainPicker._inverseTransform);
|
|
752
|
+
terrainPicker._needsRebuild = false;
|
|
753
|
+
const triangleCount = terrainPicker._indices.length / 3;
|
|
754
|
+
const intersectingTriangles = new Uint32Array(triangleCount);
|
|
755
|
+
for (let i = 0; i < triangleCount; ++i) {
|
|
756
|
+
intersectingTriangles[i] = i;
|
|
757
|
+
}
|
|
758
|
+
terrainPicker._rootNode.intersectingTriangles = intersectingTriangles;
|
|
759
|
+
terrainPicker._rootNode.children.length = 0;
|
|
760
|
+
}
|
|
761
|
+
var scratchAABBMin = new Cartesian3_default();
|
|
762
|
+
var scratchAABBMax = new Cartesian3_default();
|
|
763
|
+
function createAABBForNode(x, y, level) {
|
|
764
|
+
const sizeAtLevel = 1 / Math.pow(2, level);
|
|
765
|
+
const aabbMin = Cartesian3_default.fromElements(
|
|
766
|
+
x * sizeAtLevel - 0.5,
|
|
767
|
+
y * sizeAtLevel - 0.5,
|
|
768
|
+
-0.5,
|
|
769
|
+
scratchAABBMin
|
|
770
|
+
);
|
|
771
|
+
const aabbMax = Cartesian3_default.fromElements(
|
|
772
|
+
(x + 1) * sizeAtLevel - 0.5,
|
|
773
|
+
(y + 1) * sizeAtLevel - 0.5,
|
|
774
|
+
0.5,
|
|
775
|
+
scratchAABBMax
|
|
776
|
+
);
|
|
777
|
+
return AxisAlignedBoundingBox_default.fromCorners(aabbMin, aabbMax);
|
|
778
|
+
}
|
|
779
|
+
function packTriangleBuffers(trianglePositionsBuffer, triangleIndicesBuffer, trianglePositions, triangleIndex, bufferIndex) {
|
|
780
|
+
Cartesian3_default.pack(
|
|
781
|
+
trianglePositions[0],
|
|
782
|
+
// @ts-expect-error https://github.com/CesiumGS/cesium/pull/13302
|
|
783
|
+
trianglePositionsBuffer,
|
|
784
|
+
9 * bufferIndex
|
|
785
|
+
);
|
|
786
|
+
Cartesian3_default.pack(
|
|
787
|
+
trianglePositions[1],
|
|
788
|
+
// @ts-expect-error https://github.com/CesiumGS/cesium/pull/13302
|
|
789
|
+
trianglePositionsBuffer,
|
|
790
|
+
9 * bufferIndex + 3
|
|
791
|
+
);
|
|
792
|
+
Cartesian3_default.pack(
|
|
793
|
+
trianglePositions[2],
|
|
794
|
+
// @ts-expect-error https://github.com/CesiumGS/cesium/pull/13302
|
|
795
|
+
trianglePositionsBuffer,
|
|
796
|
+
9 * bufferIndex + 6
|
|
797
|
+
);
|
|
798
|
+
triangleIndicesBuffer[bufferIndex] = triangleIndex;
|
|
799
|
+
}
|
|
800
|
+
var scratchInterval = new Interval_default();
|
|
801
|
+
function getNodesIntersectingRay(currentNode, ray, intersectingNodes) {
|
|
802
|
+
const interval = IntersectionTests_default.rayAxisAlignedBoundingBox(
|
|
803
|
+
ray,
|
|
804
|
+
currentNode.aabb,
|
|
805
|
+
scratchInterval
|
|
806
|
+
);
|
|
807
|
+
if (!defined_default(interval)) {
|
|
808
|
+
return;
|
|
809
|
+
}
|
|
810
|
+
const isLeaf = !currentNode.children.length || currentNode.buildingChildren;
|
|
811
|
+
if (isLeaf) {
|
|
812
|
+
intersectingNodes.push({
|
|
813
|
+
node: currentNode,
|
|
814
|
+
interval: new Interval_default(interval.start, interval.stop)
|
|
815
|
+
});
|
|
816
|
+
return;
|
|
817
|
+
}
|
|
818
|
+
for (let i = 0; i < currentNode.children.length; i++) {
|
|
819
|
+
getNodesIntersectingRay(currentNode.children[i], ray, intersectingNodes);
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
function findClosestPointInClosestNode(terrainPicker, intersections, ray, cullBackFaces, mode, projection) {
|
|
823
|
+
const sortedIntersections = intersections.sort(function(a, b) {
|
|
824
|
+
return a.interval.start - b.interval.start;
|
|
825
|
+
});
|
|
826
|
+
let minT = Number.MAX_VALUE;
|
|
827
|
+
for (let i = 0; i < sortedIntersections.length; i++) {
|
|
828
|
+
const intersection = sortedIntersections[i];
|
|
829
|
+
const intersectionResult = getClosestTriangleInNode(
|
|
830
|
+
terrainPicker,
|
|
831
|
+
ray,
|
|
832
|
+
intersection.node,
|
|
833
|
+
cullBackFaces,
|
|
834
|
+
mode,
|
|
835
|
+
projection
|
|
836
|
+
);
|
|
837
|
+
minT = Math.min(intersectionResult, minT);
|
|
838
|
+
if (minT !== Number.MAX_VALUE) {
|
|
839
|
+
break;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
if (minT !== Number.MAX_VALUE) {
|
|
843
|
+
return Ray_default.getPoint(ray, minT);
|
|
844
|
+
}
|
|
845
|
+
return void 0;
|
|
846
|
+
}
|
|
847
|
+
function getClosestTriangleInNode(terrainPicker, ray, node, cullBackFaces, mode, projection) {
|
|
848
|
+
let result = Number.MAX_VALUE;
|
|
849
|
+
const encoding = terrainPicker._encoding;
|
|
850
|
+
const indices = terrainPicker._indices;
|
|
851
|
+
const vertices = terrainPicker._vertices;
|
|
852
|
+
const triangleCount = node.intersectingTriangles.length;
|
|
853
|
+
const isMaxLevel = node.level >= MAXIMUM_TERRAIN_PICKER_LEVEL;
|
|
854
|
+
const shouldBuildChildren = !isMaxLevel && !node.buildingChildren;
|
|
855
|
+
let trianglePositions;
|
|
856
|
+
let triangleIndices;
|
|
857
|
+
if (shouldBuildChildren) {
|
|
858
|
+
trianglePositions = new Float64Array(triangleCount * 9);
|
|
859
|
+
triangleIndices = new Uint32Array(triangleCount);
|
|
860
|
+
}
|
|
861
|
+
for (let i = 0; i < triangleCount; i++) {
|
|
862
|
+
const triIndex = node.intersectingTriangles[i];
|
|
863
|
+
const v0 = getVertexPosition(
|
|
864
|
+
encoding,
|
|
865
|
+
mode,
|
|
866
|
+
projection,
|
|
867
|
+
ray,
|
|
868
|
+
vertices,
|
|
869
|
+
indices[3 * triIndex],
|
|
870
|
+
scratchTrianglePoints[0]
|
|
871
|
+
);
|
|
872
|
+
const v1 = getVertexPosition(
|
|
873
|
+
encoding,
|
|
874
|
+
mode,
|
|
875
|
+
projection,
|
|
876
|
+
ray,
|
|
877
|
+
vertices,
|
|
878
|
+
indices[3 * triIndex + 1],
|
|
879
|
+
scratchTrianglePoints[1]
|
|
880
|
+
);
|
|
881
|
+
const v2 = getVertexPosition(
|
|
882
|
+
encoding,
|
|
883
|
+
mode,
|
|
884
|
+
projection,
|
|
885
|
+
ray,
|
|
886
|
+
vertices,
|
|
887
|
+
indices[3 * triIndex + 2],
|
|
888
|
+
scratchTrianglePoints[2]
|
|
889
|
+
);
|
|
890
|
+
const triT = IntersectionTests_default.rayTriangleParametric(
|
|
891
|
+
ray,
|
|
892
|
+
v0,
|
|
893
|
+
v1,
|
|
894
|
+
v2,
|
|
895
|
+
cullBackFaces
|
|
896
|
+
);
|
|
897
|
+
if (defined_default(triT) && triT < result && triT >= 0) {
|
|
898
|
+
result = triT;
|
|
899
|
+
}
|
|
900
|
+
if (shouldBuildChildren) {
|
|
901
|
+
packTriangleBuffers(
|
|
902
|
+
trianglePositions,
|
|
903
|
+
triangleIndices,
|
|
904
|
+
scratchTrianglePoints,
|
|
905
|
+
triIndex,
|
|
906
|
+
i
|
|
907
|
+
);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
if (shouldBuildChildren) {
|
|
911
|
+
for (let childIdx = 0; childIdx < 4; childIdx++) {
|
|
912
|
+
node.addChild(childIdx);
|
|
913
|
+
}
|
|
914
|
+
addTrianglesToChildrenNodes(
|
|
915
|
+
terrainPicker._inverseTransform,
|
|
916
|
+
node,
|
|
917
|
+
triangleIndices,
|
|
918
|
+
trianglePositions
|
|
919
|
+
);
|
|
920
|
+
}
|
|
921
|
+
return result;
|
|
922
|
+
}
|
|
923
|
+
var scratchCartographic = new Cartographic_default();
|
|
924
|
+
function getVertexPosition(encoding, mode, projection, ray, vertices, index, result) {
|
|
925
|
+
let position = encoding.getExaggeratedPosition(vertices, index, result);
|
|
926
|
+
if (mode === SceneMode_default.SCENE3D) {
|
|
927
|
+
return position;
|
|
928
|
+
}
|
|
929
|
+
const ellipsoid = projection.ellipsoid;
|
|
930
|
+
const positionCartographic = ellipsoid.cartesianToCartographic(
|
|
931
|
+
position,
|
|
932
|
+
scratchCartographic
|
|
933
|
+
);
|
|
934
|
+
position = projection.project(positionCartographic, result);
|
|
935
|
+
position = Cartesian3_default.fromElements(
|
|
936
|
+
position.z,
|
|
937
|
+
position.x,
|
|
938
|
+
position.y,
|
|
939
|
+
result
|
|
940
|
+
);
|
|
941
|
+
const worldWidth = Math_default.TWO_PI * projection.ellipsoid.maximumRadius;
|
|
942
|
+
const k = Math.round((ray.origin.y - position.y) / worldWidth);
|
|
943
|
+
position.y += k * worldWidth;
|
|
944
|
+
return position;
|
|
945
|
+
}
|
|
946
|
+
async function addTrianglesToChildrenNodes(inverseTransform, node, triangleIndices, trianglePositions) {
|
|
947
|
+
node.buildingChildren = true;
|
|
948
|
+
const inverseTransformPacked = new Float64Array(16);
|
|
949
|
+
Matrix4_default.pack(inverseTransform, inverseTransformPacked, 0);
|
|
950
|
+
const aabbArray = new Float64Array(6 * 4);
|
|
951
|
+
for (let i = 0; i < 4; i++) {
|
|
952
|
+
Cartesian3_default.pack(node.children[i].aabb.minimum, aabbArray, i * 6);
|
|
953
|
+
Cartesian3_default.pack(node.children[i].aabb.maximum, aabbArray, i * 6 + 3);
|
|
954
|
+
}
|
|
955
|
+
const parameters = {
|
|
956
|
+
aabbs: aabbArray,
|
|
957
|
+
inverseTransform: inverseTransformPacked,
|
|
958
|
+
triangleIndices,
|
|
959
|
+
trianglePositions
|
|
960
|
+
};
|
|
961
|
+
const transferableObjects = [
|
|
962
|
+
aabbArray.buffer,
|
|
963
|
+
inverseTransformPacked.buffer,
|
|
964
|
+
triangleIndices.buffer,
|
|
965
|
+
trianglePositions.buffer
|
|
966
|
+
];
|
|
967
|
+
const incrementallyBuildTerrainPickerPromise = incrementallyBuildTerrainPickerTaskProcessor.scheduleTask(
|
|
968
|
+
parameters,
|
|
969
|
+
transferableObjects
|
|
970
|
+
);
|
|
971
|
+
if (!defined_default(incrementallyBuildTerrainPickerPromise)) {
|
|
972
|
+
node.buildingChildren = false;
|
|
973
|
+
return;
|
|
974
|
+
}
|
|
975
|
+
const result = (
|
|
976
|
+
/** @type {{intersectingTrianglesArrays: ArrayBuffer[]}} */
|
|
977
|
+
await incrementallyBuildTerrainPickerPromise
|
|
978
|
+
);
|
|
979
|
+
result.intersectingTrianglesArrays.forEach((buffer, index) => {
|
|
980
|
+
if (defined_default(node.children[index])) {
|
|
981
|
+
node.children[index].intersectingTriangles = new Uint32Array(buffer);
|
|
982
|
+
}
|
|
983
|
+
});
|
|
984
|
+
node.intersectingTriangles = new Uint32Array(0);
|
|
985
|
+
node.buildingChildren = false;
|
|
986
|
+
}
|
|
987
|
+
var TerrainPicker_default = TerrainPicker;
|
|
988
|
+
|
|
989
|
+
// packages/engine/Source/Core/TerrainMesh.js
|
|
990
|
+
function TerrainMesh(center, vertices, indices, indexCountWithoutSkirts, vertexCountWithoutSkirts, minimumHeight, maximumHeight, rectangle, boundingSphere3D, occludeePointInScaledSpace, vertexStride, orientedBoundingBox, encoding, westIndicesSouthToNorth, southIndicesEastToWest, eastIndicesNorthToSouth, northIndicesWestToEast) {
|
|
991
|
+
this.center = center;
|
|
992
|
+
this.vertices = vertices;
|
|
993
|
+
this.stride = vertexStride ?? 6;
|
|
994
|
+
this.indices = indices;
|
|
995
|
+
this.indexCountWithoutSkirts = indexCountWithoutSkirts;
|
|
996
|
+
this.vertexCountWithoutSkirts = vertexCountWithoutSkirts;
|
|
997
|
+
this.minimumHeight = minimumHeight;
|
|
998
|
+
this.maximumHeight = maximumHeight;
|
|
999
|
+
this.rectangle = rectangle;
|
|
1000
|
+
this.boundingSphere3D = boundingSphere3D;
|
|
1001
|
+
this.occludeePointInScaledSpace = occludeePointInScaledSpace;
|
|
1002
|
+
this.orientedBoundingBox = orientedBoundingBox;
|
|
1003
|
+
this.encoding = encoding;
|
|
1004
|
+
this.westIndicesSouthToNorth = westIndicesSouthToNorth;
|
|
1005
|
+
this.southIndicesEastToWest = southIndicesEastToWest;
|
|
1006
|
+
this.eastIndicesNorthToSouth = eastIndicesNorthToSouth;
|
|
1007
|
+
this.northIndicesWestToEast = northIndicesWestToEast;
|
|
1008
|
+
this._transform = new Matrix4_default();
|
|
1009
|
+
this._lastPickSceneMode = void 0;
|
|
1010
|
+
this._terrainPicker = new TerrainPicker_default(vertices, indices, encoding);
|
|
1011
|
+
}
|
|
1012
|
+
TerrainMesh.prototype.getTransform = function(mode, projection) {
|
|
1013
|
+
if (this._lastPickSceneMode === mode) {
|
|
1014
|
+
return this._transform;
|
|
1015
|
+
}
|
|
1016
|
+
this._terrainPicker.needsRebuild = true;
|
|
1017
|
+
if (!defined_default(mode) || mode === SceneMode_default.SCENE3D) {
|
|
1018
|
+
return computeTransform(this, this._transform);
|
|
1019
|
+
}
|
|
1020
|
+
return computeTransform2D(this, projection, this._transform);
|
|
1021
|
+
};
|
|
1022
|
+
function computeTransform(mesh, result) {
|
|
1023
|
+
const exaggeration = mesh.encoding.exaggeration;
|
|
1024
|
+
const exaggerationRelativeHeight = mesh.encoding.exaggerationRelativeHeight;
|
|
1025
|
+
const exaggeratedMinHeight = VerticalExaggeration_default.getHeight(
|
|
1026
|
+
mesh.minimumHeight,
|
|
1027
|
+
exaggeration,
|
|
1028
|
+
exaggerationRelativeHeight
|
|
1029
|
+
);
|
|
1030
|
+
const exaggeratedMaxHeight = VerticalExaggeration_default.getHeight(
|
|
1031
|
+
mesh.maximumHeight,
|
|
1032
|
+
exaggeration,
|
|
1033
|
+
exaggerationRelativeHeight
|
|
1034
|
+
);
|
|
1035
|
+
const obb = OrientedBoundingBox_default.fromRectangle(
|
|
1036
|
+
mesh.rectangle,
|
|
1037
|
+
exaggeratedMinHeight,
|
|
1038
|
+
exaggeratedMaxHeight,
|
|
1039
|
+
Ellipsoid_default.default,
|
|
1040
|
+
mesh.orientedBoundingBox
|
|
1041
|
+
);
|
|
1042
|
+
OrientedBoundingBox_default.computeTransformation(obb, result);
|
|
1043
|
+
const zScale = Matrix4_default.getScale(result, scratchScale).z;
|
|
1044
|
+
if (zScale <= Math_default.EPSILON16) {
|
|
1045
|
+
scratchScale.z = 1;
|
|
1046
|
+
Matrix4_default.setScale(result, scratchScale, result);
|
|
1047
|
+
}
|
|
1048
|
+
return result;
|
|
1049
|
+
}
|
|
1050
|
+
var scratchSWCartesian = new Cartesian3_default();
|
|
1051
|
+
var scratchNECartesian = new Cartesian3_default();
|
|
1052
|
+
var scratchSWCartographic = new Cartographic_default();
|
|
1053
|
+
var scratchNECartographic = new Cartographic_default();
|
|
1054
|
+
var scratchScale2D = new Cartesian3_default();
|
|
1055
|
+
var scratchCenter2D = new Cartesian3_default();
|
|
1056
|
+
var scratchScale = new Cartesian3_default();
|
|
1057
|
+
function computeTransform2D(mesh, projection, result) {
|
|
1058
|
+
const exaggeration = mesh.encoding.exaggeration;
|
|
1059
|
+
const exaggerationRelativeHeight = mesh.encoding.exaggerationRelativeHeight;
|
|
1060
|
+
const exaggeratedMinHeight = VerticalExaggeration_default.getHeight(
|
|
1061
|
+
mesh.minimumHeight,
|
|
1062
|
+
exaggeration,
|
|
1063
|
+
exaggerationRelativeHeight
|
|
1064
|
+
);
|
|
1065
|
+
const exaggeratedMaxHeight = VerticalExaggeration_default.getHeight(
|
|
1066
|
+
mesh.maximumHeight,
|
|
1067
|
+
exaggeration,
|
|
1068
|
+
exaggerationRelativeHeight
|
|
1069
|
+
);
|
|
1070
|
+
const southwest = projection.project(
|
|
1071
|
+
Cartographic_default.fromRadians(
|
|
1072
|
+
mesh.rectangle.west,
|
|
1073
|
+
mesh.rectangle.south,
|
|
1074
|
+
0,
|
|
1075
|
+
scratchSWCartographic
|
|
1076
|
+
),
|
|
1077
|
+
scratchSWCartesian
|
|
1078
|
+
);
|
|
1079
|
+
const northeast = projection.project(
|
|
1080
|
+
Cartographic_default.fromRadians(
|
|
1081
|
+
mesh.rectangle.east,
|
|
1082
|
+
mesh.rectangle.north,
|
|
1083
|
+
0,
|
|
1084
|
+
scratchNECartographic
|
|
1085
|
+
),
|
|
1086
|
+
scratchNECartesian
|
|
1087
|
+
);
|
|
1088
|
+
const heightRange = exaggeratedMaxHeight - exaggeratedMinHeight;
|
|
1089
|
+
const scale = Cartesian3_default.fromElements(
|
|
1090
|
+
northeast.x - southwest.x,
|
|
1091
|
+
northeast.y - southwest.y,
|
|
1092
|
+
heightRange > 0 ? heightRange : 1,
|
|
1093
|
+
// Avoid zero scale
|
|
1094
|
+
scratchScale2D
|
|
1095
|
+
);
|
|
1096
|
+
const center = Cartesian3_default.fromElements(
|
|
1097
|
+
southwest.x + scale.x * 0.5,
|
|
1098
|
+
southwest.y + scale.y * 0.5,
|
|
1099
|
+
exaggeratedMinHeight + scale.z * 0.5,
|
|
1100
|
+
scratchCenter2D
|
|
1101
|
+
);
|
|
1102
|
+
Matrix4_default.fromTranslation(center, result);
|
|
1103
|
+
Matrix4_default.setScale(result, scale, result);
|
|
1104
|
+
Matrix4_default.multiply(Transforms_default.SWIZZLE_3D_TO_2D_MATRIX, result, result);
|
|
1105
|
+
return result;
|
|
1106
|
+
}
|
|
1107
|
+
TerrainMesh.prototype.pick = function(ray, cullBackFaces, mode, projection) {
|
|
1108
|
+
const intersection = this._terrainPicker.rayIntersect(
|
|
1109
|
+
ray,
|
|
1110
|
+
this.getTransform(mode, projection),
|
|
1111
|
+
cullBackFaces,
|
|
1112
|
+
mode,
|
|
1113
|
+
projection
|
|
1114
|
+
);
|
|
1115
|
+
this._lastPickSceneMode = mode;
|
|
1116
|
+
return intersection;
|
|
1117
|
+
};
|
|
1118
|
+
TerrainMesh.prototype.updateExaggeration = function(exaggeration, exaggerationRelativeHeight) {
|
|
1119
|
+
this._terrainPicker._vertices = this.vertices;
|
|
1120
|
+
this._terrainPicker.needsRebuild = true;
|
|
1121
|
+
this._lastPickSceneMode = void 0;
|
|
1122
|
+
};
|
|
1123
|
+
TerrainMesh.prototype.updateSceneMode = function(mode) {
|
|
1124
|
+
this._terrainPicker.needsRebuild = true;
|
|
1125
|
+
this._lastPickSceneMode = void 0;
|
|
1126
|
+
};
|
|
1127
|
+
var TerrainMesh_default = TerrainMesh;
|
|
1128
|
+
|
|
1129
|
+
// packages/engine/Source/Core/Cesium3DTilesTerrainGeometryProcessor.js
|
|
1130
|
+
var Cesium3DTilesTerrainGeometryProcessor = {};
|
|
1131
|
+
var scratchGltfInfo = {
|
|
1132
|
+
positions: void 0,
|
|
1133
|
+
normals: void 0,
|
|
1134
|
+
indices: void 0,
|
|
1135
|
+
edgeIndicesWest: void 0,
|
|
1136
|
+
edgeIndicesSouth: void 0,
|
|
1137
|
+
edgeIndicesEast: void 0,
|
|
1138
|
+
edgeIndicesNorth: void 0
|
|
1139
|
+
};
|
|
1140
|
+
var scratchCenterCartographic = new Cartographic_default();
|
|
1141
|
+
var scratchCenterCartesian = new Cartesian3_default();
|
|
1142
|
+
var scratchEnuToEcef = new Matrix4_default();
|
|
1143
|
+
var scratchEcefToEnu = new Matrix4_default();
|
|
1144
|
+
var scratchTilesetTransform = new Matrix4_default();
|
|
1145
|
+
var scratchMinimumPositionENU = new Cartesian3_default();
|
|
1146
|
+
var scratchMaximumPositionENU = new Cartesian3_default();
|
|
1147
|
+
var scratchPosLocal = new Cartesian3_default();
|
|
1148
|
+
var scratchPosEcef = new Cartesian3_default();
|
|
1149
|
+
var scratchCartographic2 = new Cartographic_default();
|
|
1150
|
+
var scratchUV = new Cartesian2_default();
|
|
1151
|
+
var scratchNormal = new Cartesian3_default();
|
|
1152
|
+
var scratchNormalOct = new Cartesian2_default();
|
|
1153
|
+
var scratchGeodeticSurfaceNormal = new Cartesian3_default();
|
|
1154
|
+
var scratchPosEnu = new Cartesian3_default();
|
|
1155
|
+
var sortedEdgeCompare = function(a, b) {
|
|
1156
|
+
return a - b;
|
|
1157
|
+
};
|
|
1158
|
+
Cesium3DTilesTerrainGeometryProcessor.createMesh = async function(options) {
|
|
1159
|
+
options = options ?? Frozen_default.EMPTY_OBJECT;
|
|
1160
|
+
const {
|
|
1161
|
+
exaggeration = 1,
|
|
1162
|
+
exaggerationRelativeHeight = 0,
|
|
1163
|
+
hasVertexNormals,
|
|
1164
|
+
hasWebMercatorT,
|
|
1165
|
+
gltf,
|
|
1166
|
+
minimumHeight,
|
|
1167
|
+
maximumHeight,
|
|
1168
|
+
skirtHeight
|
|
1169
|
+
} = options;
|
|
1170
|
+
Check_default.typeOf.object("options.ellipsoid", options.ellipsoid);
|
|
1171
|
+
Check_default.typeOf.object("options.rectangle", options.rectangle);
|
|
1172
|
+
Check_default.typeOf.bool("options.hasVertexNormals", hasVertexNormals);
|
|
1173
|
+
Check_default.typeOf.bool("options.hasWebMercatorT", hasWebMercatorT);
|
|
1174
|
+
Check_default.typeOf.object("options.gltf", gltf);
|
|
1175
|
+
Check_default.typeOf.number("options.minimumHeight", minimumHeight);
|
|
1176
|
+
Check_default.typeOf.number("options.maximumHeight", maximumHeight);
|
|
1177
|
+
Check_default.typeOf.object("options.boundingSphere", options.boundingSphere);
|
|
1178
|
+
Check_default.typeOf.object(
|
|
1179
|
+
"options.orientedBoundingBox",
|
|
1180
|
+
options.orientedBoundingBox
|
|
1181
|
+
);
|
|
1182
|
+
Check_default.typeOf.object(
|
|
1183
|
+
"options.horizonOcclusionPoint",
|
|
1184
|
+
options.horizonOcclusionPoint
|
|
1185
|
+
);
|
|
1186
|
+
Check_default.typeOf.number("options.skirtHeight", skirtHeight);
|
|
1187
|
+
const hasExaggeration = exaggeration !== 1;
|
|
1188
|
+
const hasGeodeticSurfaceNormals = hasExaggeration;
|
|
1189
|
+
const boundingSphere = BoundingSphere_default.clone(
|
|
1190
|
+
options.boundingSphere,
|
|
1191
|
+
new BoundingSphere_default()
|
|
1192
|
+
);
|
|
1193
|
+
const orientedBoundingBox = OrientedBoundingBox_default.clone(
|
|
1194
|
+
options.orientedBoundingBox,
|
|
1195
|
+
new OrientedBoundingBox_default()
|
|
1196
|
+
);
|
|
1197
|
+
const horizonOcclusionPoint = Cartesian3_default.clone(
|
|
1198
|
+
options.horizonOcclusionPoint,
|
|
1199
|
+
new Cartesian3_default()
|
|
1200
|
+
);
|
|
1201
|
+
const ellipsoid = Ellipsoid_default.clone(options.ellipsoid, new Ellipsoid_default());
|
|
1202
|
+
const rectangle = Rectangle_default.clone(options.rectangle, new Rectangle_default());
|
|
1203
|
+
const hasMeshOptCompression = gltf.extensionsRequired !== void 0 && gltf.extensionsRequired.indexOf("EXT_meshopt_compression") !== -1;
|
|
1204
|
+
if (hasMeshOptCompression) {
|
|
1205
|
+
Check_default.typeOf.object("options.meshoptDecoder", options.meshoptDecoder);
|
|
1206
|
+
}
|
|
1207
|
+
const tileMinLongitude = rectangle.west;
|
|
1208
|
+
const tileMinLatitude = rectangle.south;
|
|
1209
|
+
const tileMaxLatitude = rectangle.north;
|
|
1210
|
+
const tileLengthLongitude = rectangle.width;
|
|
1211
|
+
const tileLengthLatitude = rectangle.height;
|
|
1212
|
+
const approximateCenterCartographic = Rectangle_default.center(
|
|
1213
|
+
rectangle,
|
|
1214
|
+
scratchCenterCartographic
|
|
1215
|
+
);
|
|
1216
|
+
approximateCenterCartographic.height = 0.5 * (minimumHeight + maximumHeight);
|
|
1217
|
+
const approximateCenterPosition = Cartographic_default.toCartesian(
|
|
1218
|
+
approximateCenterCartographic,
|
|
1219
|
+
ellipsoid,
|
|
1220
|
+
scratchCenterCartesian
|
|
1221
|
+
);
|
|
1222
|
+
const enuToEcef = Transforms_default.eastNorthUpToFixedFrame(
|
|
1223
|
+
approximateCenterPosition,
|
|
1224
|
+
ellipsoid,
|
|
1225
|
+
scratchEnuToEcef
|
|
1226
|
+
);
|
|
1227
|
+
const ecefToEnu = Matrix4_default.inverseTransformation(enuToEcef, scratchEcefToEnu);
|
|
1228
|
+
let tilesetTransform = Matrix4_default.unpack(
|
|
1229
|
+
gltf.nodes[0].matrix,
|
|
1230
|
+
0,
|
|
1231
|
+
scratchTilesetTransform
|
|
1232
|
+
);
|
|
1233
|
+
tilesetTransform = Matrix4_default.multiply(
|
|
1234
|
+
Axis_default.Y_UP_TO_Z_UP,
|
|
1235
|
+
tilesetTransform,
|
|
1236
|
+
tilesetTransform
|
|
1237
|
+
);
|
|
1238
|
+
const gltfInfo = decodeGltf(
|
|
1239
|
+
gltf,
|
|
1240
|
+
hasVertexNormals,
|
|
1241
|
+
options.meshoptDecoder,
|
|
1242
|
+
scratchGltfInfo
|
|
1243
|
+
);
|
|
1244
|
+
const skirtVertexCount = TerrainProvider_default.getSkirtVertexCount(
|
|
1245
|
+
gltfInfo.edgeIndicesWest,
|
|
1246
|
+
gltfInfo.edgeIndicesSouth,
|
|
1247
|
+
gltfInfo.edgeIndicesEast,
|
|
1248
|
+
gltfInfo.edgeIndicesNorth
|
|
1249
|
+
);
|
|
1250
|
+
const positionsLocalWithoutSkirts = gltfInfo.positions;
|
|
1251
|
+
const normalsWithoutSkirts = gltfInfo.normals;
|
|
1252
|
+
const indicesWithoutSkirts = gltfInfo.indices;
|
|
1253
|
+
const vertexCountWithoutSkirts = positionsLocalWithoutSkirts.length / 3;
|
|
1254
|
+
const vertexCountWithSkirts = vertexCountWithoutSkirts + skirtVertexCount;
|
|
1255
|
+
const indexCountWithoutSkirts = indicesWithoutSkirts.length;
|
|
1256
|
+
const skirtIndexCount = TerrainProvider_default.getSkirtIndexCountWithFilledCorners(skirtVertexCount);
|
|
1257
|
+
const SizedIndexTypeWithSkirts = vertexCountWithSkirts <= 65535 ? Uint16Array : Uint32Array;
|
|
1258
|
+
const indexBufferWithSkirts = new SizedIndexTypeWithSkirts(
|
|
1259
|
+
indexCountWithoutSkirts + skirtIndexCount
|
|
1260
|
+
);
|
|
1261
|
+
indexBufferWithSkirts.set(indicesWithoutSkirts);
|
|
1262
|
+
const westIndices = new SizedIndexTypeWithSkirts(gltfInfo.edgeIndicesWest);
|
|
1263
|
+
const southIndices = new SizedIndexTypeWithSkirts(gltfInfo.edgeIndicesSouth);
|
|
1264
|
+
const eastIndices = new SizedIndexTypeWithSkirts(gltfInfo.edgeIndicesEast);
|
|
1265
|
+
const northIndices = new SizedIndexTypeWithSkirts(gltfInfo.edgeIndicesNorth);
|
|
1266
|
+
const sortedWestIndices = new SizedIndexTypeWithSkirts(westIndices).sort();
|
|
1267
|
+
const sortedSouthIndices = new SizedIndexTypeWithSkirts(southIndices).sort();
|
|
1268
|
+
const sortedEastIndices = new SizedIndexTypeWithSkirts(eastIndices).sort();
|
|
1269
|
+
const sortedNorthIndices = new SizedIndexTypeWithSkirts(northIndices).sort();
|
|
1270
|
+
const southMercatorAngle = WebMercatorProjection_default.geodeticLatitudeToMercatorAngle(tileMinLatitude);
|
|
1271
|
+
const northMercatorAngle = WebMercatorProjection_default.geodeticLatitudeToMercatorAngle(tileMaxLatitude);
|
|
1272
|
+
const oneOverMercatorHeight = 1 / (northMercatorAngle - southMercatorAngle);
|
|
1273
|
+
let minPosEnu = Cartesian3_default.fromElements(
|
|
1274
|
+
Number.POSITIVE_INFINITY,
|
|
1275
|
+
Number.POSITIVE_INFINITY,
|
|
1276
|
+
Number.POSITIVE_INFINITY,
|
|
1277
|
+
scratchMinimumPositionENU
|
|
1278
|
+
);
|
|
1279
|
+
let maxPosEnu = Cartesian3_default.fromElements(
|
|
1280
|
+
Number.NEGATIVE_INFINITY,
|
|
1281
|
+
Number.NEGATIVE_INFINITY,
|
|
1282
|
+
Number.NEGATIVE_INFINITY,
|
|
1283
|
+
scratchMaximumPositionENU
|
|
1284
|
+
);
|
|
1285
|
+
const tempTerrainEncoding = new TerrainEncoding_default(
|
|
1286
|
+
boundingSphere.center,
|
|
1287
|
+
void 0,
|
|
1288
|
+
void 0,
|
|
1289
|
+
void 0,
|
|
1290
|
+
void 0,
|
|
1291
|
+
hasVertexNormals,
|
|
1292
|
+
hasWebMercatorT,
|
|
1293
|
+
hasGeodeticSurfaceNormals,
|
|
1294
|
+
exaggeration,
|
|
1295
|
+
exaggerationRelativeHeight
|
|
1296
|
+
);
|
|
1297
|
+
const tempBufferStride = tempTerrainEncoding.stride;
|
|
1298
|
+
const tempBuffer = new Float32Array(vertexCountWithSkirts * tempBufferStride);
|
|
1299
|
+
let tempBufferOffset = 0;
|
|
1300
|
+
for (let i = 0; i < vertexCountWithoutSkirts; i++) {
|
|
1301
|
+
const posLocal = Cartesian3_default.unpack(
|
|
1302
|
+
positionsLocalWithoutSkirts,
|
|
1303
|
+
i * 3,
|
|
1304
|
+
scratchPosLocal
|
|
1305
|
+
);
|
|
1306
|
+
const posECEF = Matrix4_default.multiplyByPoint(
|
|
1307
|
+
tilesetTransform,
|
|
1308
|
+
posLocal,
|
|
1309
|
+
scratchPosEcef
|
|
1310
|
+
);
|
|
1311
|
+
const cartographic = Cartographic_default.fromCartesian(
|
|
1312
|
+
posECEF,
|
|
1313
|
+
ellipsoid,
|
|
1314
|
+
scratchCartographic2
|
|
1315
|
+
);
|
|
1316
|
+
const { longitude, latitude, height } = cartographic;
|
|
1317
|
+
let u = (longitude - tileMinLongitude) / tileLengthLongitude;
|
|
1318
|
+
let v = (latitude - tileMinLatitude) / tileLengthLatitude;
|
|
1319
|
+
u = Math_default.clamp(u, 0, 1);
|
|
1320
|
+
v = Math_default.clamp(v, 0, 1);
|
|
1321
|
+
if (binarySearch_default(sortedWestIndices, i, sortedEdgeCompare) >= 0) {
|
|
1322
|
+
u = 0;
|
|
1323
|
+
} else if (binarySearch_default(sortedEastIndices, i, sortedEdgeCompare) >= 0) {
|
|
1324
|
+
u = 1;
|
|
1325
|
+
}
|
|
1326
|
+
if (binarySearch_default(sortedSouthIndices, i, sortedEdgeCompare) >= 0) {
|
|
1327
|
+
v = 0;
|
|
1328
|
+
} else if (binarySearch_default(sortedNorthIndices, i, sortedEdgeCompare) >= 0) {
|
|
1329
|
+
v = 1;
|
|
1330
|
+
}
|
|
1331
|
+
const uv = Cartesian2_default.fromElements(u, v, scratchUV);
|
|
1332
|
+
let normalOct;
|
|
1333
|
+
if (hasVertexNormals) {
|
|
1334
|
+
let normal = Cartesian3_default.unpack(
|
|
1335
|
+
normalsWithoutSkirts,
|
|
1336
|
+
i * 3,
|
|
1337
|
+
scratchNormal
|
|
1338
|
+
);
|
|
1339
|
+
normal = Matrix4_default.multiplyByPointAsVector(
|
|
1340
|
+
tilesetTransform,
|
|
1341
|
+
normal,
|
|
1342
|
+
scratchNormal
|
|
1343
|
+
);
|
|
1344
|
+
normal = Cartesian3_default.normalize(normal, scratchNormal);
|
|
1345
|
+
normalOct = AttributeCompression_default.octEncode(normal, scratchNormalOct);
|
|
1346
|
+
}
|
|
1347
|
+
let webMercatorT;
|
|
1348
|
+
if (hasWebMercatorT) {
|
|
1349
|
+
const mercatorAngle = WebMercatorProjection_default.geodeticLatitudeToMercatorAngle(latitude);
|
|
1350
|
+
webMercatorT = (mercatorAngle - southMercatorAngle) * oneOverMercatorHeight;
|
|
1351
|
+
}
|
|
1352
|
+
let geodeticSurfaceNormal;
|
|
1353
|
+
if (hasGeodeticSurfaceNormals) {
|
|
1354
|
+
geodeticSurfaceNormal = ellipsoid.geodeticSurfaceNormal(
|
|
1355
|
+
posECEF,
|
|
1356
|
+
scratchGeodeticSurfaceNormal
|
|
1357
|
+
);
|
|
1358
|
+
}
|
|
1359
|
+
tempBufferOffset = tempTerrainEncoding.encode(
|
|
1360
|
+
tempBuffer,
|
|
1361
|
+
tempBufferOffset,
|
|
1362
|
+
posECEF,
|
|
1363
|
+
uv,
|
|
1364
|
+
height,
|
|
1365
|
+
normalOct,
|
|
1366
|
+
webMercatorT,
|
|
1367
|
+
geodeticSurfaceNormal
|
|
1368
|
+
);
|
|
1369
|
+
const posEnu = Matrix4_default.multiplyByPoint(ecefToEnu, posECEF, scratchPosEnu);
|
|
1370
|
+
minPosEnu = Cartesian3_default.minimumByComponent(posEnu, minPosEnu, minPosEnu);
|
|
1371
|
+
maxPosEnu = Cartesian3_default.maximumByComponent(posEnu, maxPosEnu, maxPosEnu);
|
|
1372
|
+
}
|
|
1373
|
+
const mesh = new TerrainMesh_default(
|
|
1374
|
+
Cartesian3_default.clone(tempTerrainEncoding.center, new Cartesian3_default()),
|
|
1375
|
+
tempBuffer,
|
|
1376
|
+
indexBufferWithSkirts,
|
|
1377
|
+
indexCountWithoutSkirts,
|
|
1378
|
+
vertexCountWithoutSkirts,
|
|
1379
|
+
minimumHeight,
|
|
1380
|
+
maximumHeight,
|
|
1381
|
+
rectangle,
|
|
1382
|
+
BoundingSphere_default.clone(boundingSphere, new BoundingSphere_default()),
|
|
1383
|
+
Cartesian3_default.clone(horizonOcclusionPoint, new Cartesian3_default()),
|
|
1384
|
+
tempBufferStride,
|
|
1385
|
+
OrientedBoundingBox_default.clone(orientedBoundingBox, new OrientedBoundingBox_default()),
|
|
1386
|
+
tempTerrainEncoding,
|
|
1387
|
+
westIndices,
|
|
1388
|
+
southIndices,
|
|
1389
|
+
eastIndices,
|
|
1390
|
+
northIndices
|
|
1391
|
+
);
|
|
1392
|
+
addSkirtsToMesh(
|
|
1393
|
+
mesh,
|
|
1394
|
+
rectangle,
|
|
1395
|
+
ellipsoid,
|
|
1396
|
+
minPosEnu,
|
|
1397
|
+
maxPosEnu,
|
|
1398
|
+
enuToEcef,
|
|
1399
|
+
ecefToEnu,
|
|
1400
|
+
skirtHeight
|
|
1401
|
+
);
|
|
1402
|
+
return Promise.resolve(mesh);
|
|
1403
|
+
};
|
|
1404
|
+
var scratchMinUV = new Cartesian2_default();
|
|
1405
|
+
var scratchMaxUV = new Cartesian2_default();
|
|
1406
|
+
var scratchPolygonIndices = new Array(6);
|
|
1407
|
+
var scratchUvA = new Cartesian2_default();
|
|
1408
|
+
var scratchUvB = new Cartesian2_default();
|
|
1409
|
+
var scratchUvC = new Cartesian2_default();
|
|
1410
|
+
var scratchNormalA = new Cartesian3_default();
|
|
1411
|
+
var scratchNormalB = new Cartesian3_default();
|
|
1412
|
+
var scratchNormalC = new Cartesian3_default();
|
|
1413
|
+
var scratchCenterCartographicUpsample = new Cartographic_default();
|
|
1414
|
+
var scratchCenterCartesianUpsample = new Cartesian3_default();
|
|
1415
|
+
var scratchCartographicSkirt = new Cartographic_default();
|
|
1416
|
+
var scratchCartographicUpsample = new Cartographic_default();
|
|
1417
|
+
var scratchPosEcefSkirt = new Cartesian3_default();
|
|
1418
|
+
var scratchPosEcefUpsample = new Cartesian3_default();
|
|
1419
|
+
var scratchPosEnuSkirt = new Cartesian3_default();
|
|
1420
|
+
var scratchPosEnuUpsample = new Cartesian3_default();
|
|
1421
|
+
var scratchMinimumPositionENUSkirt = new Cartesian3_default();
|
|
1422
|
+
var scratchMaximumPositionENUSkirt = new Cartesian3_default();
|
|
1423
|
+
var scratchMinimumPositionENUUpsample = new Cartesian3_default();
|
|
1424
|
+
var scratchMaximumPositionENUUpsample = new Cartesian3_default();
|
|
1425
|
+
var scratchEnuToEcefUpsample = new Matrix4_default();
|
|
1426
|
+
var scratchEcefToEnuUpsample = new Matrix4_default();
|
|
1427
|
+
var scratchUVSkirt = new Cartesian2_default();
|
|
1428
|
+
var scratchUVUpsample = new Cartesian2_default();
|
|
1429
|
+
var scratchHorizonOcclusionPoint = new Cartesian3_default();
|
|
1430
|
+
var scratchBoundingSphere = new BoundingSphere_default();
|
|
1431
|
+
var scratchOrientedBoundingBox = new OrientedBoundingBox_default();
|
|
1432
|
+
var scratchAABBEnuSkirt = new AxisAlignedBoundingBox_default();
|
|
1433
|
+
var scratchNormalUpsample = new Cartesian3_default();
|
|
1434
|
+
var scratchNormalOctSkirt = new Cartesian2_default();
|
|
1435
|
+
var scratchNormalOctUpsample = new Cartesian2_default();
|
|
1436
|
+
var scratchGeodeticSurfaceNormalSkirt = new Cartesian3_default();
|
|
1437
|
+
var scratchGeodeticSurfaceNormalUpsample = new Cartesian3_default();
|
|
1438
|
+
function decodePositions(gltf, meshoptDecoder) {
|
|
1439
|
+
const primitive = gltf.meshes[0].primitives[0];
|
|
1440
|
+
const accessor = gltf.accessors[primitive.attributes["POSITION"]];
|
|
1441
|
+
const bufferView = gltf.bufferViews[accessor.bufferView];
|
|
1442
|
+
const positionCount = accessor.count;
|
|
1443
|
+
const bufferViewMeshOpt = bufferView.extensions ? bufferView.extensions["EXT_meshopt_compression"] : void 0;
|
|
1444
|
+
if (bufferViewMeshOpt === void 0) {
|
|
1445
|
+
const buffer2 = gltf.buffers[bufferView.buffer].extras._pipeline.source;
|
|
1446
|
+
return new Float32Array(
|
|
1447
|
+
buffer2.buffer,
|
|
1448
|
+
buffer2.byteOffset + // offset from the start of the glb
|
|
1449
|
+
(bufferView.byteOffset ?? 0) + (accessor.byteOffset ?? 0),
|
|
1450
|
+
positionCount * 3
|
|
1451
|
+
);
|
|
1452
|
+
}
|
|
1453
|
+
const buffer = gltf.buffers[bufferViewMeshOpt.buffer].extras._pipeline.source;
|
|
1454
|
+
const compressedBuffer = new Uint8Array(
|
|
1455
|
+
buffer.buffer,
|
|
1456
|
+
buffer.byteOffset + // offset from the start of the glb
|
|
1457
|
+
(bufferViewMeshOpt.byteOffset ?? 0) + (accessor.byteOffset ?? 0),
|
|
1458
|
+
bufferViewMeshOpt.byteLength
|
|
1459
|
+
);
|
|
1460
|
+
const positionByteLength = bufferViewMeshOpt.byteStride;
|
|
1461
|
+
const PositionType = positionByteLength === 4 ? Uint8Array : Uint16Array;
|
|
1462
|
+
const positionsResult = new PositionType(positionCount * 4);
|
|
1463
|
+
meshoptDecoder.decodeVertexBuffer(
|
|
1464
|
+
new Uint8Array(positionsResult.buffer),
|
|
1465
|
+
positionCount,
|
|
1466
|
+
positionByteLength,
|
|
1467
|
+
compressedBuffer
|
|
1468
|
+
);
|
|
1469
|
+
const positionStorageValueMax = (1 << positionsResult.BYTES_PER_ELEMENT * 8) - 1;
|
|
1470
|
+
const positions = new Float32Array(positionCount * 3);
|
|
1471
|
+
for (let p = 0; p < positionCount; p++) {
|
|
1472
|
+
positions[p * 3 + 0] = positionsResult[p * 4 + 0] / positionStorageValueMax;
|
|
1473
|
+
positions[p * 3 + 1] = positionsResult[p * 4 + 1] / positionStorageValueMax;
|
|
1474
|
+
positions[p * 3 + 2] = positionsResult[p * 4 + 2] / positionStorageValueMax;
|
|
1475
|
+
}
|
|
1476
|
+
return positions;
|
|
1477
|
+
}
|
|
1478
|
+
function decodeNormals(gltf, meshoptDecoder) {
|
|
1479
|
+
const primitive = gltf.meshes[0].primitives[0];
|
|
1480
|
+
const accessor = gltf.accessors[primitive.attributes["NORMAL"]];
|
|
1481
|
+
const bufferView = gltf.bufferViews[accessor.bufferView];
|
|
1482
|
+
const normalCount = accessor.count;
|
|
1483
|
+
const bufferViewMeshOpt = bufferView.extensions ? bufferView.extensions["EXT_meshopt_compression"] : void 0;
|
|
1484
|
+
if (bufferViewMeshOpt === void 0) {
|
|
1485
|
+
const buffer2 = gltf.buffers[bufferView.buffer].extras._pipeline.source;
|
|
1486
|
+
return new Float32Array(
|
|
1487
|
+
buffer2.buffer,
|
|
1488
|
+
buffer2.byteOffset + // offset from the start of the glb
|
|
1489
|
+
(bufferView.byteOffset ?? 0) + (accessor.byteOffset ?? 0),
|
|
1490
|
+
normalCount * 3
|
|
1491
|
+
);
|
|
1492
|
+
}
|
|
1493
|
+
const buffer = gltf.buffers[bufferViewMeshOpt.buffer].extras._pipeline.source;
|
|
1494
|
+
const compressedBuffer = new Uint8Array(
|
|
1495
|
+
buffer.buffer,
|
|
1496
|
+
buffer.byteOffset + // offset from the start of the glb
|
|
1497
|
+
(bufferViewMeshOpt.byteOffset ?? 0) + (accessor.byteOffset ?? 0),
|
|
1498
|
+
bufferViewMeshOpt.byteLength
|
|
1499
|
+
);
|
|
1500
|
+
const normalByteLength = bufferViewMeshOpt.byteStride;
|
|
1501
|
+
const normalsResult = new Int8Array(normalCount * normalByteLength);
|
|
1502
|
+
meshoptDecoder.decodeVertexBuffer(
|
|
1503
|
+
new Uint8Array(normalsResult.buffer),
|
|
1504
|
+
normalCount,
|
|
1505
|
+
normalByteLength,
|
|
1506
|
+
compressedBuffer
|
|
1507
|
+
);
|
|
1508
|
+
const normals = new Float32Array(normalCount * 3);
|
|
1509
|
+
for (let i = 0; i < normalCount; i++) {
|
|
1510
|
+
let octX = Math.max(normalsResult[i * 4 + 0] / 127, -1);
|
|
1511
|
+
let octY = Math.max(normalsResult[i * 4 + 1] / 127, -1);
|
|
1512
|
+
const octZ = 1 - (Math.abs(octX) + Math.abs(octY));
|
|
1513
|
+
if (octZ < 0) {
|
|
1514
|
+
const oldX = octX;
|
|
1515
|
+
const oldY = octY;
|
|
1516
|
+
octX = (1 - Math.abs(oldY)) * Math_default.signNotZero(oldX);
|
|
1517
|
+
octY = (1 - Math.abs(oldX)) * Math_default.signNotZero(oldY);
|
|
1518
|
+
}
|
|
1519
|
+
let normal = scratchNormal;
|
|
1520
|
+
normal.x = octX;
|
|
1521
|
+
normal.y = octY;
|
|
1522
|
+
normal.z = octZ;
|
|
1523
|
+
normal = Cartesian3_default.normalize(normal, scratchNormal);
|
|
1524
|
+
normals[i * 3 + 0] = normal.x;
|
|
1525
|
+
normals[i * 3 + 1] = normal.y;
|
|
1526
|
+
normals[i * 3 + 2] = normal.z;
|
|
1527
|
+
}
|
|
1528
|
+
return normals;
|
|
1529
|
+
}
|
|
1530
|
+
function decodeIndices(gltf, meshoptDecoder) {
|
|
1531
|
+
const primitive = gltf.meshes[0].primitives[0];
|
|
1532
|
+
const accessor = gltf.accessors[primitive.indices];
|
|
1533
|
+
const bufferView = gltf.bufferViews[accessor.bufferView];
|
|
1534
|
+
const indexCount = accessor.count;
|
|
1535
|
+
const SizedIndexType = accessor.componentType === ComponentDatatype_default.UNSIGNED_SHORT ? Uint16Array : Uint32Array;
|
|
1536
|
+
const bufferViewMeshOpt = bufferView.extensions ? bufferView.extensions["EXT_meshopt_compression"] : void 0;
|
|
1537
|
+
if (bufferViewMeshOpt === void 0) {
|
|
1538
|
+
const buffer2 = gltf.buffers[bufferView.buffer].extras._pipeline.source;
|
|
1539
|
+
return new SizedIndexType(
|
|
1540
|
+
buffer2.buffer,
|
|
1541
|
+
buffer2.byteOffset + // offset from the glb
|
|
1542
|
+
(bufferView.byteOffset ?? 0) + (accessor.byteOffset ?? 0),
|
|
1543
|
+
indexCount
|
|
1544
|
+
);
|
|
1545
|
+
}
|
|
1546
|
+
const buffer = gltf.buffers[bufferViewMeshOpt.buffer].extras._pipeline.source;
|
|
1547
|
+
const compressedBuffer = new Uint8Array(
|
|
1548
|
+
buffer.buffer,
|
|
1549
|
+
buffer.byteOffset + // offset from the start of the glb
|
|
1550
|
+
(bufferViewMeshOpt.byteOffset ?? 0) + (accessor.byteOffset ?? 0),
|
|
1551
|
+
bufferViewMeshOpt.byteLength
|
|
1552
|
+
);
|
|
1553
|
+
const indices = new SizedIndexType(indexCount);
|
|
1554
|
+
meshoptDecoder.decodeIndexBuffer(
|
|
1555
|
+
new Uint8Array(indices.buffer),
|
|
1556
|
+
indexCount,
|
|
1557
|
+
bufferViewMeshOpt.byteStride,
|
|
1558
|
+
compressedBuffer
|
|
1559
|
+
);
|
|
1560
|
+
return indices;
|
|
1561
|
+
}
|
|
1562
|
+
function decodeEdgeIndices(gltf, name, meshoptDecoder) {
|
|
1563
|
+
const primitive = gltf.meshes[0].primitives[0];
|
|
1564
|
+
const accessor = gltf.accessors[primitive.extensions.CESIUM_tile_edges[name]];
|
|
1565
|
+
const bufferView = gltf.bufferViews[accessor.bufferView];
|
|
1566
|
+
const indexCount = accessor.count;
|
|
1567
|
+
const SizedIndexType = accessor.componentType === ComponentDatatype_default.UNSIGNED_SHORT ? Uint16Array : Uint32Array;
|
|
1568
|
+
const bufferViewMeshOpt = bufferView.extensions ? bufferView.extensions["EXT_meshopt_compression"] : void 0;
|
|
1569
|
+
if (bufferViewMeshOpt === void 0) {
|
|
1570
|
+
const buffer2 = gltf.buffers[bufferView.buffer].extras._pipeline.source;
|
|
1571
|
+
return new SizedIndexType(
|
|
1572
|
+
buffer2.buffer,
|
|
1573
|
+
buffer2.byteOffset + // offset from the glb
|
|
1574
|
+
(bufferView.byteOffset ?? 0) + (accessor.byteOffset ?? 0),
|
|
1575
|
+
indexCount
|
|
1576
|
+
);
|
|
1577
|
+
}
|
|
1578
|
+
const buffer = gltf.buffers[bufferViewMeshOpt.buffer].extras._pipeline.source;
|
|
1579
|
+
const compressedBuffer = new Uint8Array(
|
|
1580
|
+
buffer.buffer,
|
|
1581
|
+
buffer.byteOffset + // offset from the start of the glb
|
|
1582
|
+
(bufferViewMeshOpt.byteOffset ?? 0) + (accessor.byteOffset ?? 0),
|
|
1583
|
+
bufferViewMeshOpt.byteLength
|
|
1584
|
+
);
|
|
1585
|
+
const indices = new SizedIndexType(indexCount);
|
|
1586
|
+
const indexByteLength = bufferViewMeshOpt.byteStride;
|
|
1587
|
+
meshoptDecoder.decodeIndexSequence(
|
|
1588
|
+
new Uint8Array(indices.buffer),
|
|
1589
|
+
indexCount,
|
|
1590
|
+
indexByteLength,
|
|
1591
|
+
compressedBuffer
|
|
1592
|
+
);
|
|
1593
|
+
return indices;
|
|
1594
|
+
}
|
|
1595
|
+
function decodeGltf(gltf, hasNormals, meshoptDecoder, result) {
|
|
1596
|
+
result.positions = decodePositions(gltf, meshoptDecoder);
|
|
1597
|
+
result.normals = hasNormals ? decodeNormals(gltf, meshoptDecoder) : void 0;
|
|
1598
|
+
result.indices = decodeIndices(gltf, meshoptDecoder);
|
|
1599
|
+
result.edgeIndicesWest = decodeEdgeIndices(gltf, "left", meshoptDecoder);
|
|
1600
|
+
result.edgeIndicesSouth = decodeEdgeIndices(gltf, "bottom", meshoptDecoder);
|
|
1601
|
+
result.edgeIndicesEast = decodeEdgeIndices(gltf, "right", meshoptDecoder);
|
|
1602
|
+
result.edgeIndicesNorth = decodeEdgeIndices(gltf, "top", meshoptDecoder);
|
|
1603
|
+
return result;
|
|
1604
|
+
}
|
|
1605
|
+
Cesium3DTilesTerrainGeometryProcessor.upsampleMesh = function(options) {
|
|
1606
|
+
options = options ?? Frozen_default.EMPTY_OBJECT;
|
|
1607
|
+
const {
|
|
1608
|
+
isEastChild,
|
|
1609
|
+
isNorthChild,
|
|
1610
|
+
parentMinimumHeight,
|
|
1611
|
+
parentMaximumHeight,
|
|
1612
|
+
skirtHeight
|
|
1613
|
+
} = options;
|
|
1614
|
+
Check_default.typeOf.bool("options.isEastChild", isEastChild);
|
|
1615
|
+
Check_default.typeOf.bool("options.isNorthChild", isNorthChild);
|
|
1616
|
+
Check_default.typeOf.object("options.parentVertices", options.parentVertices);
|
|
1617
|
+
Check_default.typeOf.object("options.parentIndices", options.parentIndices);
|
|
1618
|
+
Check_default.typeOf.number(
|
|
1619
|
+
"options.parentVertexCountWithoutSkirts",
|
|
1620
|
+
options.parentVertexCountWithoutSkirts
|
|
1621
|
+
);
|
|
1622
|
+
Check_default.typeOf.number(
|
|
1623
|
+
"options.parentIndexCountWithoutSkirts",
|
|
1624
|
+
options.parentIndexCountWithoutSkirts
|
|
1625
|
+
);
|
|
1626
|
+
Check_default.typeOf.number("options.parentMinimumHeight", parentMinimumHeight);
|
|
1627
|
+
Check_default.typeOf.number("options.parentMaximumHeight", parentMaximumHeight);
|
|
1628
|
+
Check_default.typeOf.object("options.parentEncoding", options.parentEncoding);
|
|
1629
|
+
Check_default.typeOf.object("options.rectangle", options.rectangle);
|
|
1630
|
+
Check_default.typeOf.number("options.skirtHeight", skirtHeight);
|
|
1631
|
+
Check_default.typeOf.object("options.ellipsoid", options.ellipsoid);
|
|
1632
|
+
const indexCount = options.parentIndexCountWithoutSkirts;
|
|
1633
|
+
const indices = options.parentIndices;
|
|
1634
|
+
const vertexCount = options.parentVertexCountWithoutSkirts;
|
|
1635
|
+
const vertexBuffer = options.parentVertices;
|
|
1636
|
+
const encoding = TerrainEncoding_default.clone(
|
|
1637
|
+
options.parentEncoding,
|
|
1638
|
+
new TerrainEncoding_default()
|
|
1639
|
+
);
|
|
1640
|
+
const hasVertexNormals = encoding.hasVertexNormals;
|
|
1641
|
+
const hasWebMercatorT = encoding.hasWebMercatorT;
|
|
1642
|
+
const exaggeration = encoding.exaggeration;
|
|
1643
|
+
const exaggerationRelativeHeight = encoding.exaggerationRelativeHeight;
|
|
1644
|
+
const hasExaggeration = exaggeration !== 1;
|
|
1645
|
+
const hasGeodeticSurfaceNormals = hasExaggeration;
|
|
1646
|
+
const upsampleRectangle = Rectangle_default.clone(options.rectangle, new Rectangle_default());
|
|
1647
|
+
const ellipsoid = Ellipsoid_default.clone(options.ellipsoid);
|
|
1648
|
+
const upsampledTriIDs = [];
|
|
1649
|
+
const upsampledUVs = [];
|
|
1650
|
+
const upsampledBarys = [];
|
|
1651
|
+
const upsampledIndices = [];
|
|
1652
|
+
const upsampledWestIndices = [];
|
|
1653
|
+
const upsampledSouthIndices = [];
|
|
1654
|
+
const upsampledEastIndices = [];
|
|
1655
|
+
const upsampledNorthIndices = [];
|
|
1656
|
+
clipTileFromQuadrant(
|
|
1657
|
+
isEastChild,
|
|
1658
|
+
isNorthChild,
|
|
1659
|
+
indexCount,
|
|
1660
|
+
indices,
|
|
1661
|
+
vertexCount,
|
|
1662
|
+
vertexBuffer,
|
|
1663
|
+
encoding,
|
|
1664
|
+
upsampledIndices,
|
|
1665
|
+
upsampledWestIndices,
|
|
1666
|
+
upsampledSouthIndices,
|
|
1667
|
+
upsampledEastIndices,
|
|
1668
|
+
upsampledNorthIndices,
|
|
1669
|
+
upsampledTriIDs,
|
|
1670
|
+
upsampledBarys,
|
|
1671
|
+
upsampledUVs
|
|
1672
|
+
);
|
|
1673
|
+
const approximateCenterCartographic = Rectangle_default.center(
|
|
1674
|
+
upsampleRectangle,
|
|
1675
|
+
scratchCenterCartographicUpsample
|
|
1676
|
+
);
|
|
1677
|
+
approximateCenterCartographic.height = 0.5 * (parentMinimumHeight + parentMaximumHeight);
|
|
1678
|
+
const approximateCenterPosition = Cartographic_default.toCartesian(
|
|
1679
|
+
approximateCenterCartographic,
|
|
1680
|
+
ellipsoid,
|
|
1681
|
+
scratchCenterCartesianUpsample
|
|
1682
|
+
);
|
|
1683
|
+
const upsampledVertexCountWithoutSkirts = upsampledTriIDs.length;
|
|
1684
|
+
const upsampledTerrainEncoding = new TerrainEncoding_default(
|
|
1685
|
+
approximateCenterPosition,
|
|
1686
|
+
void 0,
|
|
1687
|
+
void 0,
|
|
1688
|
+
void 0,
|
|
1689
|
+
void 0,
|
|
1690
|
+
hasVertexNormals,
|
|
1691
|
+
hasWebMercatorT,
|
|
1692
|
+
hasGeodeticSurfaceNormals,
|
|
1693
|
+
exaggeration,
|
|
1694
|
+
exaggerationRelativeHeight
|
|
1695
|
+
);
|
|
1696
|
+
const upsampledVertexBufferStride = upsampledTerrainEncoding.stride;
|
|
1697
|
+
const upsampledSkirtVertexCount = TerrainProvider_default.getSkirtVertexCount(
|
|
1698
|
+
upsampledWestIndices,
|
|
1699
|
+
upsampledSouthIndices,
|
|
1700
|
+
upsampledEastIndices,
|
|
1701
|
+
upsampledNorthIndices
|
|
1702
|
+
);
|
|
1703
|
+
const upsampledVertexCountWithSkirts = upsampledVertexCountWithoutSkirts + upsampledSkirtVertexCount;
|
|
1704
|
+
const upsampledIndexCountWithoutSkirts = upsampledIndices.length;
|
|
1705
|
+
const upsampledSkirtIndexCount = TerrainProvider_default.getSkirtIndexCountWithFilledCorners(
|
|
1706
|
+
upsampledSkirtVertexCount
|
|
1707
|
+
);
|
|
1708
|
+
const upsampledIndexCountWithSkirts = upsampledIndexCountWithoutSkirts + upsampledSkirtIndexCount;
|
|
1709
|
+
const SizedIndexTypeWithSkirts = upsampledVertexCountWithSkirts <= 65535 ? Uint16Array : Uint32Array;
|
|
1710
|
+
const upsampledIndexBuffer = new SizedIndexTypeWithSkirts(
|
|
1711
|
+
upsampledIndexCountWithSkirts
|
|
1712
|
+
);
|
|
1713
|
+
upsampledIndexBuffer.set(upsampledIndices);
|
|
1714
|
+
const upsampledWestIndicesBuffer = new SizedIndexTypeWithSkirts(
|
|
1715
|
+
upsampledWestIndices
|
|
1716
|
+
);
|
|
1717
|
+
const upsampledSouthIndicesBuffer = new SizedIndexTypeWithSkirts(
|
|
1718
|
+
upsampledSouthIndices
|
|
1719
|
+
);
|
|
1720
|
+
const upsampledEastIndicesBuffer = new SizedIndexTypeWithSkirts(
|
|
1721
|
+
upsampledEastIndices
|
|
1722
|
+
);
|
|
1723
|
+
const upsampledNorthIndicesBuffer = new SizedIndexTypeWithSkirts(
|
|
1724
|
+
upsampledNorthIndices
|
|
1725
|
+
);
|
|
1726
|
+
const upsampledVertexBuffer = new Float32Array(
|
|
1727
|
+
upsampledVertexCountWithSkirts * upsampledVertexBufferStride
|
|
1728
|
+
);
|
|
1729
|
+
let upsampledVertexBufferOffset = 0;
|
|
1730
|
+
const enuToEcef = Transforms_default.eastNorthUpToFixedFrame(
|
|
1731
|
+
approximateCenterPosition,
|
|
1732
|
+
ellipsoid,
|
|
1733
|
+
scratchEnuToEcefUpsample
|
|
1734
|
+
);
|
|
1735
|
+
const ecefToEnu = Matrix4_default.inverseTransformation(
|
|
1736
|
+
enuToEcef,
|
|
1737
|
+
scratchEcefToEnuUpsample
|
|
1738
|
+
);
|
|
1739
|
+
const minimumLongitude = upsampleRectangle.west;
|
|
1740
|
+
const maximumLongitude = upsampleRectangle.east;
|
|
1741
|
+
const minimumLatitude = upsampleRectangle.south;
|
|
1742
|
+
const maximumLatitude = upsampleRectangle.north;
|
|
1743
|
+
const southMercatorAngle = WebMercatorProjection_default.geodeticLatitudeToMercatorAngle(minimumLatitude);
|
|
1744
|
+
const northMercatorAngle = WebMercatorProjection_default.geodeticLatitudeToMercatorAngle(maximumLatitude);
|
|
1745
|
+
const oneOverMercatorHeight = 1 / (northMercatorAngle - southMercatorAngle);
|
|
1746
|
+
let minimumHeight = Number.POSITIVE_INFINITY;
|
|
1747
|
+
let maximumHeight = Number.NEGATIVE_INFINITY;
|
|
1748
|
+
let minPosEnu = Cartesian3_default.fromElements(
|
|
1749
|
+
Number.POSITIVE_INFINITY,
|
|
1750
|
+
Number.POSITIVE_INFINITY,
|
|
1751
|
+
Number.POSITIVE_INFINITY,
|
|
1752
|
+
scratchMinimumPositionENUUpsample
|
|
1753
|
+
);
|
|
1754
|
+
let maxPosEnu = Cartesian3_default.fromElements(
|
|
1755
|
+
Number.NEGATIVE_INFINITY,
|
|
1756
|
+
Number.NEGATIVE_INFINITY,
|
|
1757
|
+
Number.NEGATIVE_INFINITY,
|
|
1758
|
+
scratchMaximumPositionENUUpsample
|
|
1759
|
+
);
|
|
1760
|
+
for (let i = 0; i < upsampledVertexCountWithoutSkirts; i++) {
|
|
1761
|
+
const triId = upsampledTriIDs[i];
|
|
1762
|
+
const indexA = indices[triId * 3 + 0];
|
|
1763
|
+
const indexB = indices[triId * 3 + 1];
|
|
1764
|
+
const indexC = indices[triId * 3 + 2];
|
|
1765
|
+
const uv = scratchUVUpsample;
|
|
1766
|
+
uv.x = upsampledUVs[i * 2 + 0];
|
|
1767
|
+
uv.y = upsampledUVs[i * 2 + 1];
|
|
1768
|
+
const u = uv.x;
|
|
1769
|
+
const v = uv.y;
|
|
1770
|
+
const baryA = upsampledBarys[i * 2 + 0];
|
|
1771
|
+
const baryB = upsampledBarys[i * 2 + 1];
|
|
1772
|
+
const baryC = 1 - baryA - baryB;
|
|
1773
|
+
const heightA = encoding.decodeHeight(vertexBuffer, indexA);
|
|
1774
|
+
const heightB = encoding.decodeHeight(vertexBuffer, indexB);
|
|
1775
|
+
const heightC = encoding.decodeHeight(vertexBuffer, indexC);
|
|
1776
|
+
const height = heightA * baryA + heightB * baryB + heightC * baryC;
|
|
1777
|
+
minimumHeight = Math.min(height, minimumHeight);
|
|
1778
|
+
maximumHeight = Math.max(height, maximumHeight);
|
|
1779
|
+
const lon = Math_default.lerp(minimumLongitude, maximumLongitude, u);
|
|
1780
|
+
const lat = Math_default.lerp(minimumLatitude, maximumLatitude, v);
|
|
1781
|
+
const carto = Cartographic_default.fromRadians(
|
|
1782
|
+
lon,
|
|
1783
|
+
lat,
|
|
1784
|
+
height,
|
|
1785
|
+
scratchCartographicUpsample
|
|
1786
|
+
);
|
|
1787
|
+
const position = Cartographic_default.toCartesian(
|
|
1788
|
+
carto,
|
|
1789
|
+
ellipsoid,
|
|
1790
|
+
scratchPosEcefUpsample
|
|
1791
|
+
);
|
|
1792
|
+
const posEnu = Matrix4_default.multiplyByPoint(
|
|
1793
|
+
ecefToEnu,
|
|
1794
|
+
position,
|
|
1795
|
+
scratchPosEnuUpsample
|
|
1796
|
+
);
|
|
1797
|
+
minPosEnu = Cartesian3_default.minimumByComponent(posEnu, minPosEnu, minPosEnu);
|
|
1798
|
+
maxPosEnu = Cartesian3_default.maximumByComponent(posEnu, maxPosEnu, maxPosEnu);
|
|
1799
|
+
let normalOct;
|
|
1800
|
+
if (hasVertexNormals) {
|
|
1801
|
+
const normalA = encoding.decodeNormal(
|
|
1802
|
+
vertexBuffer,
|
|
1803
|
+
indexA,
|
|
1804
|
+
scratchNormalA
|
|
1805
|
+
);
|
|
1806
|
+
const normalB = encoding.decodeNormal(
|
|
1807
|
+
vertexBuffer,
|
|
1808
|
+
indexB,
|
|
1809
|
+
scratchNormalB
|
|
1810
|
+
);
|
|
1811
|
+
const normalC = encoding.decodeNormal(
|
|
1812
|
+
vertexBuffer,
|
|
1813
|
+
indexC,
|
|
1814
|
+
scratchNormalC
|
|
1815
|
+
);
|
|
1816
|
+
let normal = Cartesian3_default.fromElements(
|
|
1817
|
+
normalA.x * baryA + normalB.x * baryB + normalC.x * baryC,
|
|
1818
|
+
normalA.y * baryA + normalB.y * baryB + normalC.y * baryC,
|
|
1819
|
+
normalA.z * baryA + normalB.z * baryB + normalC.z * baryC,
|
|
1820
|
+
scratchNormalUpsample
|
|
1821
|
+
);
|
|
1822
|
+
normal = Cartesian3_default.normalize(normal, scratchNormalUpsample);
|
|
1823
|
+
normalOct = AttributeCompression_default.octEncode(
|
|
1824
|
+
normal,
|
|
1825
|
+
scratchNormalOctUpsample
|
|
1826
|
+
);
|
|
1827
|
+
}
|
|
1828
|
+
let webMercatorT;
|
|
1829
|
+
if (hasWebMercatorT) {
|
|
1830
|
+
const mercatorAngle = WebMercatorProjection_default.geodeticLatitudeToMercatorAngle(lat);
|
|
1831
|
+
webMercatorT = (mercatorAngle - southMercatorAngle) * oneOverMercatorHeight;
|
|
1832
|
+
}
|
|
1833
|
+
let geodeticSurfaceNormal;
|
|
1834
|
+
if (hasGeodeticSurfaceNormals) {
|
|
1835
|
+
geodeticSurfaceNormal = ellipsoid.geodeticSurfaceNormal(
|
|
1836
|
+
position,
|
|
1837
|
+
scratchGeodeticSurfaceNormalUpsample
|
|
1838
|
+
);
|
|
1839
|
+
}
|
|
1840
|
+
upsampledVertexBufferOffset = upsampledTerrainEncoding.encode(
|
|
1841
|
+
upsampledVertexBuffer,
|
|
1842
|
+
upsampledVertexBufferOffset,
|
|
1843
|
+
position,
|
|
1844
|
+
uv,
|
|
1845
|
+
height,
|
|
1846
|
+
normalOct,
|
|
1847
|
+
webMercatorT,
|
|
1848
|
+
geodeticSurfaceNormal
|
|
1849
|
+
);
|
|
1850
|
+
}
|
|
1851
|
+
const orientedBoundingBox = OrientedBoundingBox_default.fromRectangle(
|
|
1852
|
+
upsampleRectangle,
|
|
1853
|
+
minimumHeight,
|
|
1854
|
+
maximumHeight,
|
|
1855
|
+
ellipsoid,
|
|
1856
|
+
scratchOrientedBoundingBox
|
|
1857
|
+
);
|
|
1858
|
+
const boundingSphere = BoundingSphere_default.fromVertices(
|
|
1859
|
+
upsampledVertexBuffer,
|
|
1860
|
+
upsampledTerrainEncoding.center,
|
|
1861
|
+
upsampledVertexBufferStride,
|
|
1862
|
+
scratchBoundingSphere
|
|
1863
|
+
);
|
|
1864
|
+
const occluder = new EllipsoidalOccluder_default(ellipsoid);
|
|
1865
|
+
const horizonOcclusionPoint = occluder.computeHorizonCullingPointFromVerticesPossiblyUnderEllipsoid(
|
|
1866
|
+
upsampledTerrainEncoding.center,
|
|
1867
|
+
// vector from ellipsoid center to horizon occlusion point
|
|
1868
|
+
upsampledVertexBuffer,
|
|
1869
|
+
upsampledVertexBufferStride,
|
|
1870
|
+
upsampledTerrainEncoding.center,
|
|
1871
|
+
minimumHeight,
|
|
1872
|
+
scratchHorizonOcclusionPoint
|
|
1873
|
+
);
|
|
1874
|
+
const upsampledMesh = new TerrainMesh_default(
|
|
1875
|
+
Cartesian3_default.clone(upsampledTerrainEncoding.center, new Cartesian3_default()),
|
|
1876
|
+
upsampledVertexBuffer,
|
|
1877
|
+
upsampledIndexBuffer,
|
|
1878
|
+
upsampledIndexCountWithoutSkirts,
|
|
1879
|
+
upsampledVertexCountWithoutSkirts,
|
|
1880
|
+
minimumHeight,
|
|
1881
|
+
maximumHeight,
|
|
1882
|
+
upsampleRectangle,
|
|
1883
|
+
BoundingSphere_default.clone(boundingSphere),
|
|
1884
|
+
Cartesian3_default.clone(horizonOcclusionPoint),
|
|
1885
|
+
upsampledVertexBufferStride,
|
|
1886
|
+
OrientedBoundingBox_default.clone(orientedBoundingBox),
|
|
1887
|
+
upsampledTerrainEncoding,
|
|
1888
|
+
upsampledWestIndicesBuffer,
|
|
1889
|
+
upsampledSouthIndicesBuffer,
|
|
1890
|
+
upsampledEastIndicesBuffer,
|
|
1891
|
+
upsampledNorthIndicesBuffer
|
|
1892
|
+
);
|
|
1893
|
+
addSkirtsToMesh(
|
|
1894
|
+
upsampledMesh,
|
|
1895
|
+
upsampleRectangle,
|
|
1896
|
+
ellipsoid,
|
|
1897
|
+
minPosEnu,
|
|
1898
|
+
maxPosEnu,
|
|
1899
|
+
enuToEcef,
|
|
1900
|
+
ecefToEnu,
|
|
1901
|
+
skirtHeight
|
|
1902
|
+
);
|
|
1903
|
+
return upsampledMesh;
|
|
1904
|
+
};
|
|
1905
|
+
function addSkirtsToMesh(mesh, rectangle, ellipsoid, enuMinimum, enuMaximum, enuToEcef, ecefToEnu, skirtHeight) {
|
|
1906
|
+
const { encoding } = mesh;
|
|
1907
|
+
const vertexStride = encoding.stride;
|
|
1908
|
+
const vertexBuffer = mesh.vertices;
|
|
1909
|
+
const {
|
|
1910
|
+
hasVertexNormals,
|
|
1911
|
+
hasWebMercatorT,
|
|
1912
|
+
exaggeration,
|
|
1913
|
+
exaggerationRelativeHeight
|
|
1914
|
+
} = encoding;
|
|
1915
|
+
const hasExaggeration = exaggeration !== 1;
|
|
1916
|
+
const hasGeodeticSurfaceNormals = hasExaggeration;
|
|
1917
|
+
const vertexCountWithoutSkirts = mesh.vertexCountWithoutSkirts;
|
|
1918
|
+
let vertexBufferOffset = vertexCountWithoutSkirts * vertexStride;
|
|
1919
|
+
const vertexCountWithSkirts = vertexBuffer.length / vertexStride;
|
|
1920
|
+
const skirtVertexCount = vertexCountWithSkirts - vertexCountWithoutSkirts;
|
|
1921
|
+
const indices = mesh.indices;
|
|
1922
|
+
const indexCountWithoutSkirts = mesh.indexCountWithoutSkirts;
|
|
1923
|
+
const westIndices = mesh.westIndicesSouthToNorth;
|
|
1924
|
+
const southIndices = mesh.southIndicesEastToWest;
|
|
1925
|
+
const eastIndices = mesh.eastIndicesNorthToSouth;
|
|
1926
|
+
const northIndices = mesh.northIndicesWestToEast;
|
|
1927
|
+
TerrainProvider_default.addSkirtIndicesWithFilledCorners(
|
|
1928
|
+
westIndices,
|
|
1929
|
+
southIndices,
|
|
1930
|
+
eastIndices,
|
|
1931
|
+
northIndices,
|
|
1932
|
+
vertexCountWithoutSkirts,
|
|
1933
|
+
indices,
|
|
1934
|
+
indexCountWithoutSkirts
|
|
1935
|
+
);
|
|
1936
|
+
const westOffset = 0;
|
|
1937
|
+
const southOffset = westOffset + westIndices.length;
|
|
1938
|
+
const eastOffset = southOffset + southIndices.length;
|
|
1939
|
+
const northOffset = eastOffset + eastIndices.length;
|
|
1940
|
+
const edges = [westIndices, southIndices, eastIndices, northIndices];
|
|
1941
|
+
const edgeIndexOffset = [westOffset, southOffset, eastOffset, northOffset];
|
|
1942
|
+
const edgeLongitudeSign = [-1, 0, 1, 0];
|
|
1943
|
+
const edgeLatitudeSign = [0, -1, 0, 1];
|
|
1944
|
+
const minimumPositionENUWithSkirts = Cartesian3_default.clone(
|
|
1945
|
+
enuMinimum,
|
|
1946
|
+
scratchMinimumPositionENUSkirt
|
|
1947
|
+
);
|
|
1948
|
+
const maximumPositionENUWithSkirts = Cartesian3_default.clone(
|
|
1949
|
+
enuMaximum,
|
|
1950
|
+
scratchMaximumPositionENUSkirt
|
|
1951
|
+
);
|
|
1952
|
+
const maximumHeight = mesh.maximumHeight;
|
|
1953
|
+
const minimumHeightWithSkirts = mesh.minimumHeight - skirtHeight;
|
|
1954
|
+
for (let skirtId = 0; skirtId < skirtVertexCount; skirtId++) {
|
|
1955
|
+
let side;
|
|
1956
|
+
for (side = 0; side < 3; side++) {
|
|
1957
|
+
if (skirtId < edgeIndexOffset[side + 1]) {
|
|
1958
|
+
break;
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
const vertexIndex = edges[side][skirtId - edgeIndexOffset[side]];
|
|
1962
|
+
const uv = encoding.decodeTextureCoordinates(
|
|
1963
|
+
vertexBuffer,
|
|
1964
|
+
vertexIndex,
|
|
1965
|
+
scratchUVSkirt
|
|
1966
|
+
);
|
|
1967
|
+
const skirtLonLatOffsetPercent = 1e-4;
|
|
1968
|
+
const longitudeT = uv.x + edgeLongitudeSign[side] * skirtLonLatOffsetPercent;
|
|
1969
|
+
const latitudeT = uv.y + edgeLatitudeSign[side] * skirtLonLatOffsetPercent;
|
|
1970
|
+
const longitude = Math_default.lerp(
|
|
1971
|
+
rectangle.west,
|
|
1972
|
+
rectangle.east,
|
|
1973
|
+
longitudeT
|
|
1974
|
+
);
|
|
1975
|
+
const latitude = Math_default.clamp(
|
|
1976
|
+
Math_default.lerp(rectangle.south, rectangle.north, latitudeT),
|
|
1977
|
+
-Math_default.PI_OVER_TWO,
|
|
1978
|
+
+Math_default.PI_OVER_TWO
|
|
1979
|
+
);
|
|
1980
|
+
const vertHeight = encoding.decodeHeight(vertexBuffer, vertexIndex);
|
|
1981
|
+
const height = vertHeight - skirtHeight;
|
|
1982
|
+
const cartographic = Cartographic_default.fromRadians(
|
|
1983
|
+
longitude,
|
|
1984
|
+
latitude,
|
|
1985
|
+
height,
|
|
1986
|
+
scratchCartographicSkirt
|
|
1987
|
+
);
|
|
1988
|
+
const positionEcef = Cartographic_default.toCartesian(
|
|
1989
|
+
cartographic,
|
|
1990
|
+
ellipsoid,
|
|
1991
|
+
scratchPosEcefSkirt
|
|
1992
|
+
);
|
|
1993
|
+
let normalOct;
|
|
1994
|
+
if (hasVertexNormals) {
|
|
1995
|
+
normalOct = encoding.getOctEncodedNormal(
|
|
1996
|
+
vertexBuffer,
|
|
1997
|
+
vertexIndex,
|
|
1998
|
+
scratchNormalOctSkirt
|
|
1999
|
+
);
|
|
2000
|
+
}
|
|
2001
|
+
let webMercatorT;
|
|
2002
|
+
if (hasWebMercatorT) {
|
|
2003
|
+
webMercatorT = encoding.decodeWebMercatorT(vertexBuffer, vertexIndex);
|
|
2004
|
+
}
|
|
2005
|
+
let geodeticSurfaceNormal;
|
|
2006
|
+
if (hasGeodeticSurfaceNormals) {
|
|
2007
|
+
geodeticSurfaceNormal = ellipsoid.geodeticSurfaceNormal(
|
|
2008
|
+
positionEcef,
|
|
2009
|
+
scratchGeodeticSurfaceNormalSkirt
|
|
2010
|
+
);
|
|
2011
|
+
}
|
|
2012
|
+
vertexBufferOffset = encoding.encode(
|
|
2013
|
+
vertexBuffer,
|
|
2014
|
+
vertexBufferOffset,
|
|
2015
|
+
positionEcef,
|
|
2016
|
+
uv,
|
|
2017
|
+
height,
|
|
2018
|
+
normalOct,
|
|
2019
|
+
webMercatorT,
|
|
2020
|
+
geodeticSurfaceNormal
|
|
2021
|
+
);
|
|
2022
|
+
const positionENU = Matrix4_default.multiplyByPoint(
|
|
2023
|
+
ecefToEnu,
|
|
2024
|
+
positionEcef,
|
|
2025
|
+
scratchPosEnuSkirt
|
|
2026
|
+
);
|
|
2027
|
+
Cartesian3_default.minimumByComponent(
|
|
2028
|
+
positionENU,
|
|
2029
|
+
minimumPositionENUWithSkirts,
|
|
2030
|
+
minimumPositionENUWithSkirts
|
|
2031
|
+
);
|
|
2032
|
+
Cartesian3_default.maximumByComponent(
|
|
2033
|
+
positionENU,
|
|
2034
|
+
maximumPositionENUWithSkirts,
|
|
2035
|
+
maximumPositionENUWithSkirts
|
|
2036
|
+
);
|
|
2037
|
+
}
|
|
2038
|
+
const aabbEnuWithSkirts = AxisAlignedBoundingBox_default.fromCorners(
|
|
2039
|
+
minimumPositionENUWithSkirts,
|
|
2040
|
+
maximumPositionENUWithSkirts,
|
|
2041
|
+
scratchAABBEnuSkirt
|
|
2042
|
+
);
|
|
2043
|
+
const encodingWithSkirts = new TerrainEncoding_default(
|
|
2044
|
+
encoding.center,
|
|
2045
|
+
aabbEnuWithSkirts,
|
|
2046
|
+
minimumHeightWithSkirts,
|
|
2047
|
+
maximumHeight,
|
|
2048
|
+
enuToEcef,
|
|
2049
|
+
encoding.hasVertexNormals,
|
|
2050
|
+
encoding.hasWebMercatorT,
|
|
2051
|
+
hasGeodeticSurfaceNormals,
|
|
2052
|
+
exaggeration,
|
|
2053
|
+
exaggerationRelativeHeight
|
|
2054
|
+
);
|
|
2055
|
+
if (encoding.quantization !== encodingWithSkirts.quantization) {
|
|
2056
|
+
const finalEncoding = encodingWithSkirts;
|
|
2057
|
+
const finalVertexStride = finalEncoding.stride;
|
|
2058
|
+
const finalVertexBuffer = new Float32Array(
|
|
2059
|
+
vertexCountWithSkirts * finalVertexStride
|
|
2060
|
+
);
|
|
2061
|
+
let finalVertexBufferOffset = 0;
|
|
2062
|
+
for (let i = 0; i < vertexCountWithSkirts; i++) {
|
|
2063
|
+
finalVertexBufferOffset = finalEncoding.encode(
|
|
2064
|
+
finalVertexBuffer,
|
|
2065
|
+
finalVertexBufferOffset,
|
|
2066
|
+
encoding.decodePosition(vertexBuffer, i, scratchPosEcefSkirt),
|
|
2067
|
+
encoding.decodeTextureCoordinates(vertexBuffer, i, scratchUVSkirt),
|
|
2068
|
+
encoding.decodeHeight(vertexBuffer, i),
|
|
2069
|
+
encoding.hasVertexNormals ? encoding.getOctEncodedNormal(vertexBuffer, i, scratchNormalOctSkirt) : void 0,
|
|
2070
|
+
encoding.hasWebMercatorT ? encoding.decodeWebMercatorT(vertexBuffer, i) : void 0,
|
|
2071
|
+
encoding.hasGeodeticSurfaceNormals ? encoding.decodeGeodeticSurfaceNormal(
|
|
2072
|
+
vertexBuffer,
|
|
2073
|
+
i,
|
|
2074
|
+
scratchGeodeticSurfaceNormalSkirt
|
|
2075
|
+
) : void 0
|
|
2076
|
+
);
|
|
2077
|
+
}
|
|
2078
|
+
mesh.vertices = finalVertexBuffer;
|
|
2079
|
+
mesh.stride = finalVertexStride;
|
|
2080
|
+
mesh.encoding = finalEncoding;
|
|
2081
|
+
}
|
|
2082
|
+
return mesh;
|
|
2083
|
+
}
|
|
2084
|
+
var EDGE_ID_LEFT = 0;
|
|
2085
|
+
var EDGE_ID_TOP = 1;
|
|
2086
|
+
var EDGE_ID_RIGHT = 2;
|
|
2087
|
+
var EDGE_ID_BOTTOM = 3;
|
|
2088
|
+
var EDGE_COUNT = 4;
|
|
2089
|
+
var scratchIntersection = new Cartesian3_default();
|
|
2090
|
+
var scratchInBarys = [
|
|
2091
|
+
new Cartesian3_default(),
|
|
2092
|
+
new Cartesian3_default(),
|
|
2093
|
+
new Cartesian3_default(),
|
|
2094
|
+
new Cartesian3_default(),
|
|
2095
|
+
new Cartesian3_default(),
|
|
2096
|
+
new Cartesian3_default()
|
|
2097
|
+
];
|
|
2098
|
+
var scratchInPoints = [
|
|
2099
|
+
new Cartesian2_default(),
|
|
2100
|
+
new Cartesian2_default(),
|
|
2101
|
+
new Cartesian2_default(),
|
|
2102
|
+
new Cartesian2_default(),
|
|
2103
|
+
new Cartesian2_default(),
|
|
2104
|
+
new Cartesian2_default()
|
|
2105
|
+
];
|
|
2106
|
+
var scratchOutBarys = [
|
|
2107
|
+
new Cartesian3_default(),
|
|
2108
|
+
new Cartesian3_default(),
|
|
2109
|
+
new Cartesian3_default(),
|
|
2110
|
+
new Cartesian3_default(),
|
|
2111
|
+
new Cartesian3_default(),
|
|
2112
|
+
new Cartesian3_default()
|
|
2113
|
+
];
|
|
2114
|
+
var scratchOutPoints = [
|
|
2115
|
+
new Cartesian2_default(),
|
|
2116
|
+
new Cartesian2_default(),
|
|
2117
|
+
new Cartesian2_default(),
|
|
2118
|
+
new Cartesian2_default(),
|
|
2119
|
+
new Cartesian2_default(),
|
|
2120
|
+
new Cartesian2_default()
|
|
2121
|
+
];
|
|
2122
|
+
function inside(boxMinimum, boxMaximum, edgeId, p) {
|
|
2123
|
+
switch (edgeId) {
|
|
2124
|
+
case EDGE_ID_LEFT:
|
|
2125
|
+
return Math_default.sign(p.x - boxMinimum.x);
|
|
2126
|
+
case EDGE_ID_RIGHT:
|
|
2127
|
+
return Math_default.sign(boxMaximum.x - p.x);
|
|
2128
|
+
case EDGE_ID_BOTTOM:
|
|
2129
|
+
return Math_default.sign(p.y - boxMinimum.y);
|
|
2130
|
+
default:
|
|
2131
|
+
return Math_default.sign(boxMaximum.y - p.y);
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
function intersect(boxMinimum, boxMaximum, edgeId, a, b, result) {
|
|
2135
|
+
let t, intersectX, intersectY;
|
|
2136
|
+
switch (edgeId) {
|
|
2137
|
+
case EDGE_ID_LEFT:
|
|
2138
|
+
t = (boxMinimum.x - a.x) / (b.x - a.x);
|
|
2139
|
+
intersectX = boxMinimum.x;
|
|
2140
|
+
intersectY = a.y + (b.y - a.y) * t;
|
|
2141
|
+
break;
|
|
2142
|
+
case EDGE_ID_RIGHT:
|
|
2143
|
+
t = (boxMaximum.x - a.x) / (b.x - a.x);
|
|
2144
|
+
intersectX = boxMaximum.x;
|
|
2145
|
+
intersectY = a.y + (b.y - a.y) * t;
|
|
2146
|
+
break;
|
|
2147
|
+
case EDGE_ID_BOTTOM:
|
|
2148
|
+
t = (boxMinimum.y - a.y) / (b.y - a.y);
|
|
2149
|
+
intersectX = a.x + (b.x - a.x) * t;
|
|
2150
|
+
intersectY = boxMinimum.y;
|
|
2151
|
+
break;
|
|
2152
|
+
default:
|
|
2153
|
+
t = (boxMaximum.y - a.y) / (b.y - a.y);
|
|
2154
|
+
intersectX = a.x + (b.x - a.x) * t;
|
|
2155
|
+
intersectY = boxMaximum.y;
|
|
2156
|
+
break;
|
|
2157
|
+
}
|
|
2158
|
+
return Cartesian3_default.fromElements(intersectX, intersectY, t, result);
|
|
2159
|
+
}
|
|
2160
|
+
var scratchPolygon = {
|
|
2161
|
+
length: 0,
|
|
2162
|
+
coordinates: [
|
|
2163
|
+
new Cartesian2_default(),
|
|
2164
|
+
new Cartesian2_default(),
|
|
2165
|
+
new Cartesian2_default(),
|
|
2166
|
+
new Cartesian2_default(),
|
|
2167
|
+
new Cartesian2_default(),
|
|
2168
|
+
new Cartesian2_default()
|
|
2169
|
+
],
|
|
2170
|
+
barycentricCoordinates: [
|
|
2171
|
+
new Cartesian3_default(),
|
|
2172
|
+
new Cartesian3_default(),
|
|
2173
|
+
new Cartesian3_default(),
|
|
2174
|
+
new Cartesian3_default(),
|
|
2175
|
+
new Cartesian3_default(),
|
|
2176
|
+
new Cartesian3_default()
|
|
2177
|
+
]
|
|
2178
|
+
};
|
|
2179
|
+
function clipTriangleAgainstBoxEdgeRange(edgeStart, edgeCount, boxMinimum, boxMaximum, p0, p1, p2, result) {
|
|
2180
|
+
let inputLength;
|
|
2181
|
+
let inputPoints = scratchInPoints;
|
|
2182
|
+
let inputBarys = scratchInBarys;
|
|
2183
|
+
let outputLength = 3;
|
|
2184
|
+
let outputPoints = scratchOutPoints;
|
|
2185
|
+
Cartesian2_default.clone(p0, outputPoints[0]);
|
|
2186
|
+
Cartesian2_default.clone(p1, outputPoints[1]);
|
|
2187
|
+
Cartesian2_default.clone(p2, outputPoints[2]);
|
|
2188
|
+
let outputBarys = scratchOutBarys;
|
|
2189
|
+
Cartesian3_default.fromElements(1, 0, 0, outputBarys[0]);
|
|
2190
|
+
Cartesian3_default.fromElements(0, 1, 0, outputBarys[1]);
|
|
2191
|
+
Cartesian3_default.fromElements(0, 0, 1, outputBarys[2]);
|
|
2192
|
+
for (let e = 0; e < edgeCount; e++) {
|
|
2193
|
+
const edgeId = (edgeStart + e) % EDGE_COUNT;
|
|
2194
|
+
const tempPoints = inputPoints;
|
|
2195
|
+
const tempBarys = inputBarys;
|
|
2196
|
+
inputPoints = outputPoints;
|
|
2197
|
+
inputBarys = outputBarys;
|
|
2198
|
+
inputLength = outputLength;
|
|
2199
|
+
outputPoints = tempPoints;
|
|
2200
|
+
outputBarys = tempBarys;
|
|
2201
|
+
outputLength = 0;
|
|
2202
|
+
const prevIdx = inputLength - 1;
|
|
2203
|
+
let prevPoint = inputPoints[prevIdx];
|
|
2204
|
+
let prevBary = inputBarys[prevIdx];
|
|
2205
|
+
let prevInside = inside(boxMinimum, boxMaximum, edgeId, prevPoint);
|
|
2206
|
+
for (let currIdx = 0; currIdx < inputLength; currIdx++) {
|
|
2207
|
+
const currPoint = inputPoints[currIdx];
|
|
2208
|
+
const currBary = inputBarys[currIdx];
|
|
2209
|
+
const currInside = inside(boxMinimum, boxMaximum, edgeId, currPoint);
|
|
2210
|
+
if (prevInside * currInside === -1) {
|
|
2211
|
+
const intersection = intersect(
|
|
2212
|
+
boxMinimum,
|
|
2213
|
+
boxMaximum,
|
|
2214
|
+
edgeId,
|
|
2215
|
+
prevPoint,
|
|
2216
|
+
currPoint,
|
|
2217
|
+
scratchIntersection
|
|
2218
|
+
);
|
|
2219
|
+
const { x, y, z: t } = intersection;
|
|
2220
|
+
const tInv = 1 - t;
|
|
2221
|
+
const baryA = prevBary.x * tInv + currBary.x * t;
|
|
2222
|
+
const baryB = prevBary.y * tInv + currBary.y * t;
|
|
2223
|
+
const baryC = prevBary.z * tInv + currBary.z * t;
|
|
2224
|
+
Cartesian2_default.fromElements(x, y, outputPoints[outputLength]);
|
|
2225
|
+
Cartesian3_default.fromElements(baryA, baryB, baryC, outputBarys[outputLength]);
|
|
2226
|
+
outputLength++;
|
|
2227
|
+
}
|
|
2228
|
+
if (currInside >= 0) {
|
|
2229
|
+
Cartesian2_default.clone(currPoint, outputPoints[outputLength]);
|
|
2230
|
+
Cartesian3_default.clone(currBary, outputBarys[outputLength]);
|
|
2231
|
+
outputLength++;
|
|
2232
|
+
}
|
|
2233
|
+
prevPoint = currPoint;
|
|
2234
|
+
prevBary = currBary;
|
|
2235
|
+
prevInside = currInside;
|
|
2236
|
+
}
|
|
2237
|
+
if (outputLength === 0) {
|
|
2238
|
+
break;
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
result.length = outputLength;
|
|
2242
|
+
for (let i = 0; i < outputLength; i++) {
|
|
2243
|
+
Cartesian2_default.clone(outputPoints[i], result.coordinates[i]);
|
|
2244
|
+
Cartesian3_default.clone(outputBarys[i], result.barycentricCoordinates[i]);
|
|
2245
|
+
}
|
|
2246
|
+
return result;
|
|
2247
|
+
}
|
|
2248
|
+
function clipTriangleFromQuadrant(isEastChild, isNorthChild, boxMinimum, boxMaximum, p0, p1, p2, result) {
|
|
2249
|
+
const edgeStart = isEastChild ? isNorthChild ? EDGE_ID_BOTTOM : EDGE_ID_LEFT : isNorthChild ? EDGE_ID_RIGHT : EDGE_ID_TOP;
|
|
2250
|
+
return clipTriangleAgainstBoxEdgeRange(
|
|
2251
|
+
edgeStart,
|
|
2252
|
+
2,
|
|
2253
|
+
boxMinimum,
|
|
2254
|
+
boxMaximum,
|
|
2255
|
+
p0,
|
|
2256
|
+
p1,
|
|
2257
|
+
p2,
|
|
2258
|
+
result
|
|
2259
|
+
);
|
|
2260
|
+
}
|
|
2261
|
+
var lookUpTableBaryToPrim = [
|
|
2262
|
+
[],
|
|
2263
|
+
// 000
|
|
2264
|
+
[0],
|
|
2265
|
+
// 001
|
|
2266
|
+
[1],
|
|
2267
|
+
// 010
|
|
2268
|
+
[0, 1],
|
|
2269
|
+
// 011
|
|
2270
|
+
[2],
|
|
2271
|
+
// 100
|
|
2272
|
+
[0, 2],
|
|
2273
|
+
// 101
|
|
2274
|
+
[1, 2],
|
|
2275
|
+
// 110
|
|
2276
|
+
[0, 1, 2]
|
|
2277
|
+
// 111
|
|
2278
|
+
];
|
|
2279
|
+
function clipTileFromQuadrant(isEastChild, isNorthChild, indexCount, indices, vertexCount, vertices, vertexEncoding, resultIndices, resultWestIndices, resultSouthIndices, resultEastIndices, resultNorthIndices, resultTriIds, resultBary, resultUVs) {
|
|
2280
|
+
const upsampledVertexMap = {};
|
|
2281
|
+
const minU = isEastChild ? 0.5 : 0;
|
|
2282
|
+
const maxU = isEastChild ? 1 : 0.5;
|
|
2283
|
+
const minV = isNorthChild ? 0.5 : 0;
|
|
2284
|
+
const maxV = isNorthChild ? 1 : 0.5;
|
|
2285
|
+
const minUV = scratchMinUV;
|
|
2286
|
+
minUV.x = minU;
|
|
2287
|
+
minUV.y = minV;
|
|
2288
|
+
const maxUV = scratchMaxUV;
|
|
2289
|
+
maxUV.x = maxU;
|
|
2290
|
+
maxUV.y = maxV;
|
|
2291
|
+
let upsampledVertexCount = 0;
|
|
2292
|
+
for (let i = 0; i < indexCount; i += 3) {
|
|
2293
|
+
const indexA = indices[i + 0];
|
|
2294
|
+
const indexB = indices[i + 1];
|
|
2295
|
+
const indexC = indices[i + 2];
|
|
2296
|
+
const uvA = vertexEncoding.decodeTextureCoordinates(
|
|
2297
|
+
vertices,
|
|
2298
|
+
indexA,
|
|
2299
|
+
scratchUvA
|
|
2300
|
+
);
|
|
2301
|
+
const uvB = vertexEncoding.decodeTextureCoordinates(
|
|
2302
|
+
vertices,
|
|
2303
|
+
indexB,
|
|
2304
|
+
scratchUvB
|
|
2305
|
+
);
|
|
2306
|
+
const uvC = vertexEncoding.decodeTextureCoordinates(
|
|
2307
|
+
vertices,
|
|
2308
|
+
indexC,
|
|
2309
|
+
scratchUvC
|
|
2310
|
+
);
|
|
2311
|
+
const clippedPolygon = clipTriangleFromQuadrant(
|
|
2312
|
+
isEastChild,
|
|
2313
|
+
isNorthChild,
|
|
2314
|
+
minUV,
|
|
2315
|
+
maxUV,
|
|
2316
|
+
uvA,
|
|
2317
|
+
uvB,
|
|
2318
|
+
uvC,
|
|
2319
|
+
scratchPolygon
|
|
2320
|
+
);
|
|
2321
|
+
const clippedPolygonLength = clippedPolygon.length;
|
|
2322
|
+
if (clippedPolygonLength < 3) {
|
|
2323
|
+
continue;
|
|
2324
|
+
}
|
|
2325
|
+
const polygonUpsampledIndices = scratchPolygonIndices;
|
|
2326
|
+
for (let p = 0; p < clippedPolygonLength; p++) {
|
|
2327
|
+
const polygonBary = clippedPolygon.barycentricCoordinates[p];
|
|
2328
|
+
const bA = polygonBary.x;
|
|
2329
|
+
const bB = polygonBary.y;
|
|
2330
|
+
const bC = polygonBary.z;
|
|
2331
|
+
const baryId = Math.ceil(bA) | Math.ceil(bB) << 1 | Math.ceil(bC) << 2;
|
|
2332
|
+
const primitiveIds = lookUpTableBaryToPrim[baryId];
|
|
2333
|
+
let upsampledIndex;
|
|
2334
|
+
let isNewVertex = false;
|
|
2335
|
+
if (primitiveIds.length === 1) {
|
|
2336
|
+
const pointPrimitiveId = primitiveIds[0];
|
|
2337
|
+
const pointIndex = indices[i + pointPrimitiveId];
|
|
2338
|
+
const pointKey = pointIndex;
|
|
2339
|
+
upsampledIndex = upsampledVertexMap[pointKey];
|
|
2340
|
+
if (upsampledIndex === void 0) {
|
|
2341
|
+
isNewVertex = true;
|
|
2342
|
+
upsampledIndex = upsampledVertexCount++;
|
|
2343
|
+
upsampledVertexMap[pointKey] = upsampledIndex;
|
|
2344
|
+
}
|
|
2345
|
+
} else if (primitiveIds.length === 2) {
|
|
2346
|
+
const edgePrimitiveIdA = primitiveIds[0];
|
|
2347
|
+
const edgePrimitiveIdB = primitiveIds[1];
|
|
2348
|
+
const edgeIndexA = indices[i + edgePrimitiveIdA];
|
|
2349
|
+
const edgeIndexB = indices[i + edgePrimitiveIdB];
|
|
2350
|
+
const prevBary = clippedPolygon.barycentricCoordinates[(p + clippedPolygonLength - 1) % clippedPolygonLength];
|
|
2351
|
+
const prevBaryId = Math.ceil(prevBary.x) | Math.ceil(prevBary.y) << 1 | Math.ceil(prevBary.z) << 2;
|
|
2352
|
+
const sameEdge = baryId === prevBaryId;
|
|
2353
|
+
const minIndex = Math.min(edgeIndexA, edgeIndexB);
|
|
2354
|
+
const maxIndex = Math.max(edgeIndexA, edgeIndexB);
|
|
2355
|
+
const baseKey = vertexCount + 2 * (minIndex * vertexCount + maxIndex);
|
|
2356
|
+
const firstKey = baseKey + 0;
|
|
2357
|
+
const secondKey = baseKey + 1;
|
|
2358
|
+
const firstEntry = upsampledVertexMap[firstKey];
|
|
2359
|
+
const secondEntry = upsampledVertexMap[secondKey];
|
|
2360
|
+
const useFirst = !sameEdge === (firstEntry === void 0 || secondEntry === void 0);
|
|
2361
|
+
upsampledIndex = useFirst ? firstEntry : secondEntry;
|
|
2362
|
+
if (upsampledIndex === void 0) {
|
|
2363
|
+
isNewVertex = true;
|
|
2364
|
+
upsampledIndex = upsampledVertexCount++;
|
|
2365
|
+
const edgeKey = useFirst ? firstKey : secondKey;
|
|
2366
|
+
upsampledVertexMap[edgeKey] = upsampledIndex;
|
|
2367
|
+
}
|
|
2368
|
+
} else {
|
|
2369
|
+
isNewVertex = true;
|
|
2370
|
+
upsampledIndex = upsampledVertexCount++;
|
|
2371
|
+
}
|
|
2372
|
+
polygonUpsampledIndices[p] = upsampledIndex;
|
|
2373
|
+
if (isNewVertex) {
|
|
2374
|
+
const triId = i / 3;
|
|
2375
|
+
resultTriIds.push(triId);
|
|
2376
|
+
const polygonUV = clippedPolygon.coordinates[p];
|
|
2377
|
+
const u = (polygonUV.x - minU) / (maxU - minU);
|
|
2378
|
+
const v = (polygonUV.y - minV) / (maxV - minV);
|
|
2379
|
+
resultUVs.push(u, v);
|
|
2380
|
+
resultBary.push(bA, bB);
|
|
2381
|
+
if (u === 0) {
|
|
2382
|
+
resultWestIndices.push(upsampledIndex);
|
|
2383
|
+
} else if (u === 1) {
|
|
2384
|
+
resultEastIndices.push(upsampledIndex);
|
|
2385
|
+
}
|
|
2386
|
+
if (v === 0) {
|
|
2387
|
+
resultSouthIndices.push(upsampledIndex);
|
|
2388
|
+
} else if (v === 1) {
|
|
2389
|
+
resultNorthIndices.push(upsampledIndex);
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
}
|
|
2393
|
+
const ui0 = polygonUpsampledIndices[0];
|
|
2394
|
+
let ui1 = polygonUpsampledIndices[1];
|
|
2395
|
+
let ui2 = polygonUpsampledIndices[2];
|
|
2396
|
+
resultIndices.push(ui0, ui1, ui2);
|
|
2397
|
+
for (let j = 3; j < clippedPolygonLength; j++) {
|
|
2398
|
+
ui1 = ui2;
|
|
2399
|
+
ui2 = polygonUpsampledIndices[j];
|
|
2400
|
+
resultIndices.push(ui0, ui1, ui2);
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
resultWestIndices.sort(function(a, b) {
|
|
2404
|
+
return resultUVs[a * 2 + 1] - resultUVs[b * 2 + 1];
|
|
2405
|
+
});
|
|
2406
|
+
resultSouthIndices.sort(function(a, b) {
|
|
2407
|
+
return resultUVs[b * 2 + 0] - resultUVs[a * 2 + 0];
|
|
2408
|
+
});
|
|
2409
|
+
resultEastIndices.sort(function(a, b) {
|
|
2410
|
+
return resultUVs[b * 2 + 1] - resultUVs[a * 2 + 1];
|
|
2411
|
+
});
|
|
2412
|
+
resultNorthIndices.sort(function(a, b) {
|
|
2413
|
+
return resultUVs[a * 2 + 0] - resultUVs[b * 2 + 0];
|
|
2414
|
+
});
|
|
2415
|
+
}
|
|
2416
|
+
var Cesium3DTilesTerrainGeometryProcessor_default = Cesium3DTilesTerrainGeometryProcessor;
|
|
2417
|
+
|
|
2418
|
+
export {
|
|
2419
|
+
Cesium3DTilesTerrainGeometryProcessor_default
|
|
2420
|
+
};
|