@cesium/engine 22.0.0 → 22.1.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 +10 -7
- package/Build/Workers/chunk-23T2IPHV.js +55 -0
- package/Build/Workers/{chunk-VVZ667H6.js → chunk-2AM4E2WD.js} +2 -2
- package/Build/Workers/{chunk-XQ347YWU.js → chunk-2MWF4IES.js} +16 -14
- package/Build/Workers/{chunk-75HAJIDT.js → chunk-2RCIRXNI.js} +1 -1
- package/Build/Workers/{chunk-RQRODXVN.js → chunk-3YTMGEXW.js} +5 -1424
- package/Build/Workers/{chunk-N52ZRKUE.js → chunk-4BHWJWS3.js} +6 -6
- package/Build/Workers/{chunk-5T5SY63I.js → chunk-5JKH4AMT.js} +2 -2
- package/Build/Workers/{chunk-EJO3NKMS.js → chunk-6HKAPCSO.js} +1 -1
- package/Build/Workers/{chunk-BJSNGGBM.js → chunk-A53R2F2L.js} +4 -4
- package/Build/Workers/{chunk-H7B7FU2U.js → chunk-A6YFUGJO.js} +5 -5
- package/Build/Workers/{chunk-VCVA7BMD.js → chunk-AJYWXC6I.js} +4 -4
- package/Build/Workers/{chunk-3GL53OCU.js → chunk-AOIO5VUS.js} +276 -2277
- package/Build/Workers/{chunk-SZN34LQ5.js → chunk-B7JRBTT6.js} +10 -10
- package/Build/Workers/{chunk-726NINF5.js → chunk-CHNDJRYA.js} +20 -18
- package/Build/Workers/{chunk-L7U26FFD.js → chunk-CJOV55CW.js} +20 -18
- package/Build/Workers/{chunk-NE5JTQJP.js → chunk-COGPE5Z2.js} +10 -8
- package/Build/Workers/{chunk-XPVZWY4A.js → chunk-CW7W27IZ.js} +12 -8
- package/Build/Workers/{chunk-GYRDA3XK.js → chunk-DICY26ID.js} +20 -16
- package/Build/Workers/{chunk-AOM3FHBN.js → chunk-DMEFNTUV.js} +69 -7
- package/Build/Workers/{chunk-XZO6F23E.js → chunk-DQSJEOZY.js} +1 -1
- package/Build/Workers/{chunk-MXHRZHDF.js → chunk-GDU4RZSZ.js} +16 -36
- package/Build/Workers/{chunk-JDJAPBZP.js → chunk-GKWOUMYA.js} +1 -1
- package/Build/Workers/{chunk-OUBBMEWX.js → chunk-GTY4K4IA.js} +9 -7
- package/Build/Workers/{chunk-LWJXCI3F.js → chunk-H6Q7E4BQ.js} +8 -6
- package/Build/Workers/{chunk-YLXWC7OW.js → chunk-HHGOFZVQ.js} +7 -5
- package/Build/Workers/{chunk-34YXP222.js → chunk-HXKUEOOD.js} +5 -5
- package/Build/Workers/{chunk-EZ7NJXQN.js → chunk-I4REFVXB.js} +4 -4
- package/Build/Workers/{chunk-OE22564R.js → chunk-IL5F6WEE.js} +3 -3
- package/Build/Workers/{chunk-QSMIHPUM.js → chunk-JKXPC5HD.js} +2 -2
- package/Build/Workers/{chunk-7KAXDKRU.js → chunk-KKGD7HAW.js} +13 -11
- package/Build/Workers/{chunk-YLILBDWK.js → chunk-KROSQJUA.js} +2 -2
- package/Build/Workers/{chunk-NHZNMTIR.js → chunk-L4JLDVCM.js} +5 -5
- package/Build/Workers/{chunk-2D3GLFZD.js → chunk-LIYMRHGR.js} +15 -13
- package/Build/Workers/{chunk-P2H75UV5.js → chunk-MKMZHRB3.js} +16 -11
- package/Build/Workers/{chunk-KUB64XW6.js → chunk-MO25ZQ2I.js} +12 -10
- package/Build/Workers/{chunk-ECHAJNQJ.js → chunk-O6RZEKHZ.js} +12 -12
- package/Build/Workers/{chunk-5ZF53EY6.js → chunk-OOCGX2OD.js} +4 -4
- package/Build/Workers/{chunk-NGKF5NTR.js → chunk-OXFU5HNU.js} +13 -5
- package/Build/Workers/{chunk-FA3SCJDX.js → chunk-P5CGIJUY.js} +2 -2
- package/Build/Workers/{chunk-W4PIP5PG.js → chunk-QEANVUGT.js} +2 -2
- package/Build/Workers/{chunk-AARZSH4V.js → chunk-QFBCIX7J.js} +8 -6
- package/Build/Workers/{chunk-JZFU2LEM.js → chunk-QUAH3XOT.js} +4 -4
- package/Build/Workers/{chunk-6HBKE43B.js → chunk-RXZDTDIY.js} +13 -9
- package/Build/Workers/{chunk-LEFQBK6H.js → chunk-SPA2KPH3.js} +14 -12
- package/Build/Workers/chunk-TDSVSW5A.js +1460 -0
- package/Build/Workers/{chunk-A6JAFSZT.js → chunk-UG2DPFOL.js} +8 -6
- package/Build/Workers/{chunk-U4XMLGSR.js → chunk-URGEDZBS.js} +7 -7
- package/Build/Workers/{chunk-A4DPJIWS.js → chunk-V35NQOJC.js} +8 -6
- package/Build/Workers/chunk-W4XUEDU5.js +2058 -0
- package/Build/Workers/{chunk-7XEJGXX2.js → chunk-WB4TSSBQ.js} +779 -24
- package/Build/Workers/{chunk-RCCYW6E7.js → chunk-WTLYD4FE.js} +19 -15
- package/Build/Workers/{chunk-5B7VZQZY.js → chunk-Y4ALZ4SS.js} +9 -7
- package/Build/Workers/{chunk-KGLDJRSO.js → chunk-YF2NVO5B.js} +19 -13
- package/Build/Workers/{chunk-IGX772ZQ.js → chunk-YSYSXSHF.js} +1 -1
- package/Build/Workers/{chunk-M7HRE4QR.js → chunk-YX562XOB.js} +15 -11
- package/Build/Workers/{chunk-QCMRUVVF.js → chunk-YZWA5B4R.js} +15 -13
- package/Build/Workers/{chunk-U7CX3HHE.js → chunk-Z6DFT4D3.js} +15 -11
- package/Build/Workers/combineGeometry.js +24 -21
- package/Build/Workers/createBoxGeometry.js +18 -15
- package/Build/Workers/createBoxOutlineGeometry.js +16 -13
- package/Build/Workers/createCircleGeometry.js +28 -24
- package/Build/Workers/createCircleOutlineGeometry.js +21 -17
- package/Build/Workers/createCoplanarPolygonGeometry.js +35 -31
- package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +33 -29
- package/Build/Workers/createCorridorGeometry.js +32 -28
- package/Build/Workers/createCorridorOutlineGeometry.js +30 -26
- package/Build/Workers/createCylinderGeometry.js +20 -17
- package/Build/Workers/createCylinderOutlineGeometry.js +20 -16
- package/Build/Workers/createEllipseGeometry.js +28 -24
- package/Build/Workers/createEllipseOutlineGeometry.js +21 -17
- package/Build/Workers/createEllipsoidGeometry.js +19 -16
- package/Build/Workers/createEllipsoidOutlineGeometry.js +18 -15
- package/Build/Workers/createFrustumGeometry.js +18 -15
- package/Build/Workers/createFrustumOutlineGeometry.js +18 -15
- package/Build/Workers/createGeometry.js +25 -21
- package/Build/Workers/createGroundPolylineGeometry.js +25 -21
- package/Build/Workers/createPlaneGeometry.js +16 -13
- package/Build/Workers/createPlaneOutlineGeometry.js +15 -12
- package/Build/Workers/createPolygonGeometry.js +35 -31
- package/Build/Workers/createPolygonOutlineGeometry.js +32 -28
- package/Build/Workers/createPolylineGeometry.js +27 -23
- package/Build/Workers/createPolylineVolumeGeometry.js +33 -29
- package/Build/Workers/createPolylineVolumeOutlineGeometry.js +29 -25
- package/Build/Workers/createRectangleGeometry.js +30 -26
- package/Build/Workers/createRectangleOutlineGeometry.js +23 -19
- package/Build/Workers/createSimplePolylineGeometry.js +25 -21
- package/Build/Workers/createSphereGeometry.js +19 -16
- package/Build/Workers/createSphereOutlineGeometry.js +18 -15
- package/Build/Workers/createTaskProcessorWorker.js +3 -3
- package/Build/Workers/createVectorTileClampedPolylines.js +16 -13
- package/Build/Workers/createVectorTileGeometries.js +24 -21
- package/Build/Workers/createVectorTilePoints.js +15 -12
- package/Build/Workers/createVectorTilePolygons.js +24 -20
- package/Build/Workers/createVectorTilePolylines.js +16 -13
- package/Build/Workers/createVerticesFromCesium3DTilesTerrain.js +25 -22
- package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +26 -21
- package/Build/Workers/createVerticesFromHeightmap.js +26 -21
- package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +24 -19
- package/Build/Workers/createWallGeometry.js +26 -22
- package/Build/Workers/createWallOutlineGeometry.js +25 -21
- package/Build/Workers/decodeDraco.js +10 -10
- package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
- package/Build/Workers/decodeI3S.js +13 -11
- package/Build/Workers/gaussianSplatSorter.js +4 -4
- package/Build/Workers/gaussianSplatTextureGenerator.js +4 -4
- package/Build/Workers/incrementallyBuildTerrainPicker.js +121 -0
- package/Build/Workers/transcodeKTX2.js +6 -6
- package/Build/Workers/transferTypedArrayTest.js +1 -1
- package/Build/Workers/upsampleQuantizedTerrainMesh.js +24 -20
- package/Build/Workers/upsampleVerticesFromCesium3DTilesTerrain.js +25 -22
- package/Source/Core/AxisAlignedBoundingBox.js +36 -0
- package/Source/Core/Cesium3DTilesTerrainData.js +2 -0
- package/Source/Core/Cesium3DTilesTerrainGeometryProcessor.js +2 -0
- package/Source/Core/GoogleEarthEnterpriseTerrainData.js +1 -0
- package/Source/Core/HeightmapTerrainData.js +2 -0
- package/Source/Core/IntersectionTests.js +80 -0
- package/Source/Core/Ion.js +1 -1
- package/Source/Core/QuantizedMeshTerrainData.js +1 -0
- package/Source/Core/TerrainMesh.js +207 -0
- package/Source/Core/TerrainPicker.js +607 -0
- package/Source/Core/TexturePacker.js +27 -12
- package/Source/Core/Transforms.js +28 -19
- package/Source/DataSources/BillboardGraphics.js +1 -1
- package/Source/DataSources/BillboardVisualizer.js +7 -4
- package/Source/Renderer/Buffer.js +32 -0
- package/Source/Renderer/BufferUsage.js +3 -1
- package/Source/Renderer/Context.js +85 -7
- package/Source/Renderer/Sync.js +104 -0
- package/Source/Renderer/TextureAtlas.js +67 -27
- package/Source/Scene/ArcGisMapService.js +1 -1
- package/Source/Scene/Azure2DImageryProvider.js +96 -12
- package/Source/Scene/Billboard.js +75 -28
- package/Source/Scene/BillboardCollection.js +7 -2
- package/Source/Scene/BillboardTexture.js +56 -7
- package/Source/Scene/Globe.js +3 -1
- package/Source/Scene/GlobeSurfaceTile.js +18 -66
- package/Source/Scene/GlobeSurfaceTileProvider.js +11 -0
- package/Source/Scene/Google2DImageryProvider.js +10 -15
- package/Source/Scene/PickFramebuffer.js +124 -36
- package/Source/Scene/Picking.js +99 -17
- package/Source/Scene/Scene.js +36 -4
- package/Source/Scene/TerrainFillMesh.js +1 -0
- package/Source/Shaders/BillboardCollectionFS.glsl +22 -9
- package/Source/Shaders/BillboardCollectionFS.js +22 -9
- package/Source/ThirdParty/Workers/zip-web-worker.js +1 -1
- package/Source/ThirdParty/zip-module.wasm +0 -0
- package/Source/Workers/incrementallyBuildTerrainPicker.js +108 -0
- package/index.d.ts +207 -4
- package/index.js +28 -26
- package/package.json +2 -2
|
@@ -0,0 +1,607 @@
|
|
|
1
|
+
import AxisAlignedBoundingBox from "./AxisAlignedBoundingBox.js";
|
|
2
|
+
import Cartesian3 from "./Cartesian3.js";
|
|
3
|
+
import defined from "./defined.js";
|
|
4
|
+
import IntersectionTests from "./IntersectionTests.js";
|
|
5
|
+
import Matrix4 from "./Matrix4.js";
|
|
6
|
+
import Ray from "./Ray.js";
|
|
7
|
+
import TaskProcessor from "./TaskProcessor.js";
|
|
8
|
+
import Cartographic from "./Cartographic.js";
|
|
9
|
+
import SceneMode from "../Scene/SceneMode.js";
|
|
10
|
+
import Interval from "./Interval.js";
|
|
11
|
+
import Check from "./Check.js";
|
|
12
|
+
import DeveloperError from "./DeveloperError.js";
|
|
13
|
+
|
|
14
|
+
// Terrain picker can be 4 levels deep (0-3)
|
|
15
|
+
const MAXIMUM_TERRAIN_PICKER_LEVEL = 3;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Creates an object that handles arbitrary ray intersections with a terrain mesh using a spatial acceleration structure.
|
|
19
|
+
*
|
|
20
|
+
* @alias TerrainPicker
|
|
21
|
+
* @constructor
|
|
22
|
+
*
|
|
23
|
+
* @param {Float32Array} vertices The terrain mesh's vertex buffer.
|
|
24
|
+
* @param {Uint8Array|Uint16Array|Uint32Array} indices The terrain mesh's index buffer.
|
|
25
|
+
* @param {TerrainEncoding} encoding The terrain mesh's vertex encoding.
|
|
26
|
+
*
|
|
27
|
+
* @private
|
|
28
|
+
*/
|
|
29
|
+
function TerrainPicker(vertices, indices, encoding) {
|
|
30
|
+
//>>includeStart('debug', pragmas.debug);
|
|
31
|
+
Check.defined("vertices", vertices);
|
|
32
|
+
Check.defined("indices", indices);
|
|
33
|
+
Check.defined("encoding", encoding);
|
|
34
|
+
//>>includeEnd('debug');
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The terrain mesh's vertex buffer.
|
|
38
|
+
* @type {Float32Array}
|
|
39
|
+
*/
|
|
40
|
+
this._vertices = vertices;
|
|
41
|
+
/**
|
|
42
|
+
* The terrain mesh's index buffer.
|
|
43
|
+
* @type {Uint32Array}
|
|
44
|
+
*/
|
|
45
|
+
this._indices = indices;
|
|
46
|
+
/**
|
|
47
|
+
* The terrain mesh's vertex encoding.
|
|
48
|
+
* @type {TerrainEncoding}
|
|
49
|
+
*/
|
|
50
|
+
this._encoding = encoding;
|
|
51
|
+
/**
|
|
52
|
+
* The inverse of the terrain mesh tile's transform from world space to local space.
|
|
53
|
+
* @type {Matrix4}
|
|
54
|
+
*/
|
|
55
|
+
this._inverseTransform = new Matrix4(); // Compute as-needed on rebuild
|
|
56
|
+
/**
|
|
57
|
+
* Whether or not to reset this terrain mesh's picker on the next ray intersection.
|
|
58
|
+
* @type {Boolean}
|
|
59
|
+
*/
|
|
60
|
+
this._needsRebuild = true;
|
|
61
|
+
/**
|
|
62
|
+
* The root node of the terrain picker's quadtree.
|
|
63
|
+
* @type {TerrainPickerNode}
|
|
64
|
+
*/
|
|
65
|
+
this._rootNode = new TerrainPickerNode();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const incrementallyBuildTerrainPickerTaskProcessor = new TaskProcessor(
|
|
69
|
+
"incrementallyBuildTerrainPicker",
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
Object.defineProperties(TerrainPicker.prototype, {
|
|
73
|
+
/**
|
|
74
|
+
* Indicates whether the terrain picker needs to be rebuilt due to changes in the underlying terrain mesh's vertices or indices.
|
|
75
|
+
* @type {boolean}
|
|
76
|
+
*/
|
|
77
|
+
needsRebuild: {
|
|
78
|
+
get: function () {
|
|
79
|
+
return this._needsRebuild;
|
|
80
|
+
},
|
|
81
|
+
set: function (value) {
|
|
82
|
+
this._needsRebuild = value;
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* A node in the terrain picker quadtree.
|
|
89
|
+
* @constructor
|
|
90
|
+
* @private
|
|
91
|
+
*/
|
|
92
|
+
function TerrainPickerNode() {
|
|
93
|
+
/**
|
|
94
|
+
* The tree-space x-coordinate of this node.
|
|
95
|
+
* @type {Number}
|
|
96
|
+
*/
|
|
97
|
+
this.x = 0;
|
|
98
|
+
/**
|
|
99
|
+
* The tree-space y-coordinate of this node.
|
|
100
|
+
* @type {Number}
|
|
101
|
+
*/
|
|
102
|
+
this.y = 0;
|
|
103
|
+
/**
|
|
104
|
+
* The level of this node in the quadtree.
|
|
105
|
+
* @type {Number}
|
|
106
|
+
*/
|
|
107
|
+
this.level = 0;
|
|
108
|
+
/**
|
|
109
|
+
* The axis-aligned bounding box of this node (in the tree's local space).
|
|
110
|
+
* @type {AxisAlignedBoundingBox}
|
|
111
|
+
*/
|
|
112
|
+
this.aabb = createAABBForNode(this.x, this.y, this.level);
|
|
113
|
+
/**
|
|
114
|
+
* The indices of the triangles that intersect this node.
|
|
115
|
+
* @type {Uint32Array}
|
|
116
|
+
*/
|
|
117
|
+
this.intersectingTriangles = new Uint32Array(0);
|
|
118
|
+
/**
|
|
119
|
+
* The child terrain picker nodes of this node.
|
|
120
|
+
* @type {TerrainPickerNode[]}
|
|
121
|
+
*/
|
|
122
|
+
this.children = [];
|
|
123
|
+
/**
|
|
124
|
+
* Whether or not this node is currently building its children on a worker.
|
|
125
|
+
* @type {Boolean}
|
|
126
|
+
*/
|
|
127
|
+
this.buildingChildren = false;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Adds a child node to this node.
|
|
132
|
+
*
|
|
133
|
+
* @param {number} childIdx The index of the child to add (0-3).
|
|
134
|
+
* @memberof TerrainPickerNode
|
|
135
|
+
*/
|
|
136
|
+
TerrainPickerNode.prototype.addChild = function (childIdx) {
|
|
137
|
+
//>>includeStart('debug', pragmas.debug);
|
|
138
|
+
if (childIdx < 0 || childIdx > 3) {
|
|
139
|
+
throw new DeveloperError(
|
|
140
|
+
"TerrainPickerNode child index must be between 0 and 3, inclusive.",
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
//>>includeEnd('debug');
|
|
144
|
+
|
|
145
|
+
const childNode = new TerrainPickerNode();
|
|
146
|
+
// Use bitwise operations to get child x,y from child index and parent x,y
|
|
147
|
+
childNode.x = this.x * 2 + (childIdx & 1);
|
|
148
|
+
childNode.y = this.y * 2 + ((childIdx >> 1) & 1);
|
|
149
|
+
childNode.level = this.level + 1;
|
|
150
|
+
childNode.aabb = createAABBForNode(childNode.x, childNode.y, childNode.level);
|
|
151
|
+
|
|
152
|
+
this.children[childIdx] = childNode;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const scratchTransformedRay = new Ray();
|
|
156
|
+
const scratchTrianglePoints = [
|
|
157
|
+
new Cartesian3(),
|
|
158
|
+
new Cartesian3(),
|
|
159
|
+
new Cartesian3(),
|
|
160
|
+
];
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Determines the point on the mesh where the given ray intersects.
|
|
164
|
+
* @param {Ray} ray The ray to test.
|
|
165
|
+
* @param {Matrix4} tileTransform The terrain mesh tile's transform from local space to world space.
|
|
166
|
+
* @param {Boolean} cullBackFaces Whether to consider back-facing triangles as intersections.
|
|
167
|
+
* @param {SceneMode} mode The scene mode (2D/3D/Columbus View).
|
|
168
|
+
* @param {MapProjection} projection The map projection.
|
|
169
|
+
* @returns {Cartesian3 | undefined} result The intersection point, or undefined if there is no intersection.
|
|
170
|
+
* @memberof TerrainPicker
|
|
171
|
+
* @private
|
|
172
|
+
*/
|
|
173
|
+
TerrainPicker.prototype.rayIntersect = function (
|
|
174
|
+
ray,
|
|
175
|
+
tileTransform,
|
|
176
|
+
cullBackFaces,
|
|
177
|
+
mode,
|
|
178
|
+
projection,
|
|
179
|
+
) {
|
|
180
|
+
// Lazily (re)create the terrain picker
|
|
181
|
+
if (this._needsRebuild) {
|
|
182
|
+
reset(this, tileTransform);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const invTransform = this._inverseTransform;
|
|
186
|
+
|
|
187
|
+
const transformedRay = scratchTransformedRay;
|
|
188
|
+
|
|
189
|
+
transformedRay.origin = Matrix4.multiplyByPoint(
|
|
190
|
+
invTransform,
|
|
191
|
+
ray.origin,
|
|
192
|
+
transformedRay.origin,
|
|
193
|
+
);
|
|
194
|
+
transformedRay.direction = Matrix4.multiplyByPointAsVector(
|
|
195
|
+
invTransform,
|
|
196
|
+
ray.direction,
|
|
197
|
+
transformedRay.direction,
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
const intersections = [];
|
|
201
|
+
getNodesIntersectingRay(this._rootNode, transformedRay, intersections);
|
|
202
|
+
|
|
203
|
+
return findClosestPointInClosestNode(
|
|
204
|
+
this,
|
|
205
|
+
intersections,
|
|
206
|
+
ray,
|
|
207
|
+
cullBackFaces,
|
|
208
|
+
mode,
|
|
209
|
+
projection,
|
|
210
|
+
);
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Resets the terrain picker's quadtree structure to just the root node. Done whenever the underlying terrain mesh changes.
|
|
215
|
+
* @param terrainPicker The terrain picker to reset.
|
|
216
|
+
* @private
|
|
217
|
+
*/
|
|
218
|
+
function reset(terrainPicker, tileTransform) {
|
|
219
|
+
// PERFORMANCE_IDEA: warm-start the terrain picker by building a level on a worker.
|
|
220
|
+
// This currently isn't feasible because you can only copy the vertex buffer to a worker (slow) or transfer ownership (can't do picking on main thread in meantime).
|
|
221
|
+
// SharedArrayBuffers could be used, but most environments do not support them.
|
|
222
|
+
Matrix4.inverse(tileTransform, terrainPicker._inverseTransform);
|
|
223
|
+
|
|
224
|
+
terrainPicker._needsRebuild = false;
|
|
225
|
+
const triangleCount = terrainPicker._indices.length / 3;
|
|
226
|
+
const intersectingTriangles = new Uint32Array(triangleCount);
|
|
227
|
+
|
|
228
|
+
for (let i = 0; i < triangleCount; ++i) {
|
|
229
|
+
intersectingTriangles[i] = i;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
terrainPicker._rootNode.intersectingTriangles = intersectingTriangles;
|
|
233
|
+
terrainPicker._rootNode.children.length = 0;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const scratchAABBMin = new Cartesian3();
|
|
237
|
+
const scratchAABBMax = new Cartesian3();
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Creates an axis-aligned bounding box for a quadtree node at the given tree-space coordinates and level.
|
|
241
|
+
* This AABB is in the tree's local space (where the root node of the tree is a unit cube in its own local space).
|
|
242
|
+
*
|
|
243
|
+
* @param {number} x The x coordinate of the node.
|
|
244
|
+
* @param {number} y The y coordinate of the node.
|
|
245
|
+
* @param {number} level The level of the node.
|
|
246
|
+
* @returns {AxisAlignedBoundingBox} The axis-aligned bounding box for the node.
|
|
247
|
+
*/
|
|
248
|
+
function createAABBForNode(x, y, level) {
|
|
249
|
+
const sizeAtLevel = 1.0 / Math.pow(2, level);
|
|
250
|
+
|
|
251
|
+
const aabbMin = Cartesian3.fromElements(
|
|
252
|
+
x * sizeAtLevel - 0.5,
|
|
253
|
+
y * sizeAtLevel - 0.5,
|
|
254
|
+
-0.5,
|
|
255
|
+
scratchAABBMin,
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
const aabbMax = Cartesian3.fromElements(
|
|
259
|
+
(x + 1) * sizeAtLevel - 0.5,
|
|
260
|
+
(y + 1) * sizeAtLevel - 0.5,
|
|
261
|
+
0.5,
|
|
262
|
+
scratchAABBMax,
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
return AxisAlignedBoundingBox.fromCorners(aabbMin, aabbMax);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Packs triangle vertex positions and index into provided buffers, for the worker to process.
|
|
270
|
+
* (The worker does tests to organize triangles into child nodes of the quadtree.)
|
|
271
|
+
* @param {Float32Array} trianglePositionsBuffer The buffer to pack triangle vertex positions into.
|
|
272
|
+
* @param {Uint32Array} triangleIndicesBuffer The buffer to pack triangle indices into.
|
|
273
|
+
* @param {Cartesian3[]} trianglePositions The triangle's vertex positions.
|
|
274
|
+
* @param {number} triangleIndex The triangle's index in the overall tile's index buffer.
|
|
275
|
+
* @param {number} bufferIndex The index to use to pack into the buffers.
|
|
276
|
+
* @private
|
|
277
|
+
*/
|
|
278
|
+
function packTriangleBuffers(
|
|
279
|
+
trianglePositionsBuffer,
|
|
280
|
+
triangleIndicesBuffer,
|
|
281
|
+
trianglePositions,
|
|
282
|
+
triangleIndex,
|
|
283
|
+
bufferIndex,
|
|
284
|
+
) {
|
|
285
|
+
Cartesian3.pack(
|
|
286
|
+
trianglePositions[0],
|
|
287
|
+
trianglePositionsBuffer,
|
|
288
|
+
9 * bufferIndex,
|
|
289
|
+
);
|
|
290
|
+
Cartesian3.pack(
|
|
291
|
+
trianglePositions[1],
|
|
292
|
+
trianglePositionsBuffer,
|
|
293
|
+
9 * bufferIndex + 3,
|
|
294
|
+
);
|
|
295
|
+
Cartesian3.pack(
|
|
296
|
+
trianglePositions[2],
|
|
297
|
+
trianglePositionsBuffer,
|
|
298
|
+
9 * bufferIndex + 6,
|
|
299
|
+
);
|
|
300
|
+
triangleIndicesBuffer[bufferIndex] = triangleIndex;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* @typedef {Object} IntersectingNode
|
|
305
|
+
* @property {TerrainPickerNode} node - The intersecting quadtree node.
|
|
306
|
+
* @property {Interval} interval - The interval along the ray where the intersection occurs.
|
|
307
|
+
* @private
|
|
308
|
+
*/
|
|
309
|
+
|
|
310
|
+
const scratchInterval = new Interval();
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Recursively gathers all nodes in the quadtree that intersect the ray.
|
|
314
|
+
*
|
|
315
|
+
* @param {TerrainPickerNode} currentNode The current node being tested.
|
|
316
|
+
* @param {Ray} ray The ray to test.
|
|
317
|
+
* @param {IntersectingNode[]} intersectingNodes The array to store intersecting nodes in.
|
|
318
|
+
* @private
|
|
319
|
+
*/
|
|
320
|
+
function getNodesIntersectingRay(currentNode, ray, intersectingNodes) {
|
|
321
|
+
const interval = IntersectionTests.rayAxisAlignedBoundingBox(
|
|
322
|
+
ray,
|
|
323
|
+
currentNode.aabb,
|
|
324
|
+
scratchInterval,
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
if (!defined(interval)) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
const isLeaf = !currentNode.children.length || currentNode.buildingChildren;
|
|
332
|
+
if (isLeaf) {
|
|
333
|
+
intersectingNodes.push({
|
|
334
|
+
node: currentNode,
|
|
335
|
+
interval: new Interval(interval.start, interval.stop),
|
|
336
|
+
});
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
for (let i = 0; i < currentNode.children.length; i++) {
|
|
341
|
+
getNodesIntersectingRay(currentNode.children[i], ray, intersectingNodes);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Finds the closest intersecting node along the ray, in world space, and the closest point in that node,
|
|
347
|
+
* by testing all triangles in the closest node against the ray.
|
|
348
|
+
*
|
|
349
|
+
* @param {TerrainPicker} terrainPicker The terrain picker.
|
|
350
|
+
* @param {IntersectingNode[]} intersections The nodes that intersect the ray, along with the intersection intervals along said ray.
|
|
351
|
+
* @param {Ray} ray The ray to test.
|
|
352
|
+
* @param {boolean} cullBackFaces Whether to cull back faces.
|
|
353
|
+
* @param {SceneMode} mode The scene mode (2D/3D/Columbus View).
|
|
354
|
+
* @param {MapProjection} projection The map projection.
|
|
355
|
+
* @returns The closest point in world space, or undefined if no intersection.
|
|
356
|
+
* @private
|
|
357
|
+
*/
|
|
358
|
+
function findClosestPointInClosestNode(
|
|
359
|
+
terrainPicker,
|
|
360
|
+
intersections,
|
|
361
|
+
ray,
|
|
362
|
+
cullBackFaces,
|
|
363
|
+
mode,
|
|
364
|
+
projection,
|
|
365
|
+
) {
|
|
366
|
+
const sortedIntersections = intersections.sort(function (a, b) {
|
|
367
|
+
return a.interval.start - b.interval.start;
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
let minT = Number.MAX_VALUE;
|
|
371
|
+
for (let i = 0; i < sortedIntersections.length; i++) {
|
|
372
|
+
const intersection = sortedIntersections[i];
|
|
373
|
+
const intersectionResult = getClosestTriangleInNode(
|
|
374
|
+
terrainPicker,
|
|
375
|
+
ray,
|
|
376
|
+
intersection.node,
|
|
377
|
+
cullBackFaces,
|
|
378
|
+
mode,
|
|
379
|
+
projection,
|
|
380
|
+
);
|
|
381
|
+
minT = Math.min(intersectionResult, minT);
|
|
382
|
+
if (minT !== Number.MAX_VALUE) {
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (minT !== Number.MAX_VALUE) {
|
|
388
|
+
return Ray.getPoint(ray, minT);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return undefined;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Test all triangles in the given node against the ray, returning the closest intersection t value along the ray.
|
|
396
|
+
* Additionally, collect the triangles' positions and indices along the way to launch worker process that uses them to build out child nodes.
|
|
397
|
+
*
|
|
398
|
+
* @param {TerrainPicker} terrainPicker The terrain picker.
|
|
399
|
+
* @param {Ray} ray The ray to test.
|
|
400
|
+
* @param {TerrainPickerNode} node The node to test.
|
|
401
|
+
* @param {boolean} cullBackFaces Whether to cull back faces.
|
|
402
|
+
* @param {SceneMode} mode The scene mode (2D/3D/Columbus View).
|
|
403
|
+
* @param {MapProjection} projection The map projection.
|
|
404
|
+
* @returns {number} The closest intersection t value along the ray, or Number.MAX_VALUE if no intersection.
|
|
405
|
+
* @private
|
|
406
|
+
*/
|
|
407
|
+
function getClosestTriangleInNode(
|
|
408
|
+
terrainPicker,
|
|
409
|
+
ray,
|
|
410
|
+
node,
|
|
411
|
+
cullBackFaces,
|
|
412
|
+
mode,
|
|
413
|
+
projection,
|
|
414
|
+
) {
|
|
415
|
+
let result = Number.MAX_VALUE;
|
|
416
|
+
const encoding = terrainPicker._encoding;
|
|
417
|
+
const indices = terrainPicker._indices;
|
|
418
|
+
const vertices = terrainPicker._vertices;
|
|
419
|
+
const triangleCount = node.intersectingTriangles.length;
|
|
420
|
+
const isMaxLevel = node.level >= MAXIMUM_TERRAIN_PICKER_LEVEL;
|
|
421
|
+
const shouldBuildChildren = !isMaxLevel && !node.buildingChildren;
|
|
422
|
+
|
|
423
|
+
let trianglePositions;
|
|
424
|
+
let triangleIndices;
|
|
425
|
+
if (shouldBuildChildren) {
|
|
426
|
+
// If the tree can be built deeper, prepare buffers to store triangle data for child nodes
|
|
427
|
+
trianglePositions = new Float32Array(triangleCount * 9); // 3 vertices per triangle * 3 floats per vertex
|
|
428
|
+
triangleIndices = new Uint32Array(triangleCount);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
for (let i = 0; i < triangleCount; i++) {
|
|
432
|
+
const triIndex = node.intersectingTriangles[i];
|
|
433
|
+
const v0 = getVertexPosition(
|
|
434
|
+
encoding,
|
|
435
|
+
mode,
|
|
436
|
+
projection,
|
|
437
|
+
vertices,
|
|
438
|
+
indices[3 * triIndex],
|
|
439
|
+
scratchTrianglePoints[0],
|
|
440
|
+
);
|
|
441
|
+
const v1 = getVertexPosition(
|
|
442
|
+
encoding,
|
|
443
|
+
mode,
|
|
444
|
+
projection,
|
|
445
|
+
vertices,
|
|
446
|
+
indices[3 * triIndex + 1],
|
|
447
|
+
scratchTrianglePoints[1],
|
|
448
|
+
);
|
|
449
|
+
const v2 = getVertexPosition(
|
|
450
|
+
encoding,
|
|
451
|
+
mode,
|
|
452
|
+
projection,
|
|
453
|
+
vertices,
|
|
454
|
+
indices[3 * triIndex + 2],
|
|
455
|
+
scratchTrianglePoints[2],
|
|
456
|
+
);
|
|
457
|
+
|
|
458
|
+
const triT = IntersectionTests.rayTriangleParametric(
|
|
459
|
+
ray,
|
|
460
|
+
v0,
|
|
461
|
+
v1,
|
|
462
|
+
v2,
|
|
463
|
+
cullBackFaces,
|
|
464
|
+
);
|
|
465
|
+
|
|
466
|
+
if (defined(triT) && triT < result && triT >= 0) {
|
|
467
|
+
result = triT;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
if (shouldBuildChildren) {
|
|
471
|
+
packTriangleBuffers(
|
|
472
|
+
trianglePositions,
|
|
473
|
+
triangleIndices,
|
|
474
|
+
scratchTrianglePoints,
|
|
475
|
+
triIndex,
|
|
476
|
+
i,
|
|
477
|
+
);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
if (shouldBuildChildren) {
|
|
482
|
+
for (let childIdx = 0; childIdx < 4; childIdx++) {
|
|
483
|
+
node.addChild(childIdx);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
addTrianglesToChildrenNodes(
|
|
487
|
+
terrainPicker._inverseTransform,
|
|
488
|
+
node,
|
|
489
|
+
triangleIndices,
|
|
490
|
+
trianglePositions,
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
return result;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
const scratchCartographic = new Cartographic();
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Gets a vertex position from the buffer, taking into account the exaggeration and scene mode of the terrain.
|
|
501
|
+
*
|
|
502
|
+
* @param {TerrainEncoding} encoding The terrain encoding.
|
|
503
|
+
* @param {SceneMode} mode The scene mode (2D/3D/Columbus View).
|
|
504
|
+
* @param {MapProjection} projection The map projection.
|
|
505
|
+
* @param {Float32Array} vertices The vertex buffer of the terrain mesh.
|
|
506
|
+
* @param {Number} index The index of the vertex to get.
|
|
507
|
+
* @param {Cartesian3} result The decoded, exaggerated, and possibly projected vertex position.
|
|
508
|
+
* @returns {Cartesian3} The result vertex position.
|
|
509
|
+
* @private
|
|
510
|
+
*/
|
|
511
|
+
function getVertexPosition(
|
|
512
|
+
encoding,
|
|
513
|
+
mode,
|
|
514
|
+
projection,
|
|
515
|
+
vertices,
|
|
516
|
+
index,
|
|
517
|
+
result,
|
|
518
|
+
) {
|
|
519
|
+
let position = encoding.getExaggeratedPosition(vertices, index, result);
|
|
520
|
+
if (mode === SceneMode.SCENE3D) {
|
|
521
|
+
return position;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
const ellipsoid = projection.ellipsoid;
|
|
525
|
+
const positionCartographic = ellipsoid.cartesianToCartographic(
|
|
526
|
+
position,
|
|
527
|
+
scratchCartographic,
|
|
528
|
+
);
|
|
529
|
+
position = projection.project(positionCartographic, result);
|
|
530
|
+
// Swizzle because coordinate basis are different in 2D/Columbus View
|
|
531
|
+
position = Cartesian3.fromElements(
|
|
532
|
+
position.z,
|
|
533
|
+
position.x,
|
|
534
|
+
position.y,
|
|
535
|
+
result,
|
|
536
|
+
);
|
|
537
|
+
|
|
538
|
+
return position;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
/**
|
|
542
|
+
* Adds triangles to the child nodes of the given node by launching a worker process to do AABB-triangle testing.
|
|
543
|
+
*
|
|
544
|
+
* @param {Matrix4} inverseTransform
|
|
545
|
+
* @param {TerrainNode} node
|
|
546
|
+
* @param {Uint32Array} triangleIndices
|
|
547
|
+
* @param {Float32Array} trianglePositions
|
|
548
|
+
* @returns {Promise<void>} A promise that resolves when the triangles have been added to the child nodes.
|
|
549
|
+
* @private
|
|
550
|
+
*/
|
|
551
|
+
async function addTrianglesToChildrenNodes(
|
|
552
|
+
inverseTransform,
|
|
553
|
+
node,
|
|
554
|
+
triangleIndices,
|
|
555
|
+
trianglePositions,
|
|
556
|
+
) {
|
|
557
|
+
node.buildingChildren = true;
|
|
558
|
+
|
|
559
|
+
// Prepare data to be sent to a worker
|
|
560
|
+
const inverseTransformPacked = new Float64Array(16);
|
|
561
|
+
Matrix4.pack(inverseTransform, inverseTransformPacked, 0);
|
|
562
|
+
|
|
563
|
+
const aabbArray = new Float64Array(6 * 4); // 6 elements per AABB, 4 children
|
|
564
|
+
for (let i = 0; i < 4; i++) {
|
|
565
|
+
Cartesian3.pack(node.children[i].aabb.minimum, aabbArray, i * 6);
|
|
566
|
+
Cartesian3.pack(node.children[i].aabb.maximum, aabbArray, i * 6 + 3);
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
const parameters = {
|
|
570
|
+
aabbs: aabbArray,
|
|
571
|
+
inverseTransform: inverseTransformPacked,
|
|
572
|
+
triangleIndices: triangleIndices,
|
|
573
|
+
trianglePositions: trianglePositions,
|
|
574
|
+
};
|
|
575
|
+
|
|
576
|
+
const transferableObjects = [
|
|
577
|
+
aabbArray.buffer,
|
|
578
|
+
inverseTransformPacked.buffer,
|
|
579
|
+
triangleIndices.buffer,
|
|
580
|
+
trianglePositions.buffer,
|
|
581
|
+
];
|
|
582
|
+
|
|
583
|
+
const incrementallyBuildTerrainPickerPromise =
|
|
584
|
+
incrementallyBuildTerrainPickerTaskProcessor.scheduleTask(
|
|
585
|
+
parameters,
|
|
586
|
+
transferableObjects,
|
|
587
|
+
);
|
|
588
|
+
|
|
589
|
+
if (!defined(incrementallyBuildTerrainPickerPromise)) {
|
|
590
|
+
// Failed to schedule task, retry on next pick
|
|
591
|
+
node.buildingChildren = false;
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// After worker completes, it transfers back a buffer of intersecting triangles for each child node
|
|
596
|
+
// Assign these to the child nodes
|
|
597
|
+
const result = await incrementallyBuildTerrainPickerPromise;
|
|
598
|
+
result.intersectingTrianglesArrays.forEach((buffer, index) => {
|
|
599
|
+
node.children[index].intersectingTriangles = new Uint32Array(buffer);
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
// The node's triangles have been distributed to its children
|
|
603
|
+
node.intersectingTriangles = new Uint32Array(0);
|
|
604
|
+
node.buildingChildren = false;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
export default TerrainPicker;
|
|
@@ -122,6 +122,8 @@ TexturePacker.prototype._findNode = function (node, { width, height }) {
|
|
|
122
122
|
return node;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
const borderPadding = this._borderPadding;
|
|
126
|
+
|
|
125
127
|
// Vertical split (childNode1 = left half, childNode2 = right half).
|
|
126
128
|
if (widthDifference > heightDifference) {
|
|
127
129
|
node.childNode1 = new TextureNode({
|
|
@@ -130,12 +132,18 @@ TexturePacker.prototype._findNode = function (node, { width, height }) {
|
|
|
130
132
|
width,
|
|
131
133
|
height: nodeHeight,
|
|
132
134
|
});
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
|
|
136
|
+
// Apply padding only along the vertical "cut".
|
|
137
|
+
const widthDifferencePadded = widthDifference - borderPadding;
|
|
138
|
+
|
|
139
|
+
if (widthDifferencePadded > 0) {
|
|
140
|
+
node.childNode2 = new TextureNode({
|
|
141
|
+
x: rectangle.x + width + borderPadding,
|
|
142
|
+
y: rectangle.y,
|
|
143
|
+
width: widthDifferencePadded,
|
|
144
|
+
height: nodeHeight,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
139
147
|
|
|
140
148
|
return this._findNode(node.childNode1, { width, height });
|
|
141
149
|
}
|
|
@@ -147,12 +155,19 @@ TexturePacker.prototype._findNode = function (node, { width, height }) {
|
|
|
147
155
|
width: nodeWidth,
|
|
148
156
|
height,
|
|
149
157
|
});
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
158
|
+
|
|
159
|
+
// Apply padding only along the horizontal "cut".
|
|
160
|
+
const heightDifferencePadded = heightDifference - borderPadding;
|
|
161
|
+
|
|
162
|
+
if (heightDifferencePadded > 0) {
|
|
163
|
+
node.childNode2 = new TextureNode({
|
|
164
|
+
x: rectangle.x,
|
|
165
|
+
y: rectangle.y + height + borderPadding,
|
|
166
|
+
width: nodeWidth,
|
|
167
|
+
height: heightDifferencePadded,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
156
171
|
return this._findNode(node.childNode1, { width, height });
|
|
157
172
|
}
|
|
158
173
|
|