@cesium/engine 17.0.0 → 18.0.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/z-worker-pako.js +1 -1
- package/Build/Workers/{chunk-4TIR5UPL.js → chunk-2AXPWBJG.js} +1 -1
- package/Build/Workers/{chunk-CAKU6ZPR.js → chunk-2CAYUY2B.js} +8 -8
- package/Build/Workers/{chunk-PS3OKVOQ.js → chunk-2NKHPWDY.js} +12 -12
- package/Build/Workers/{chunk-VXAKU6EV.js → chunk-2QNKQVUT.js} +5 -5
- package/Build/Workers/{chunk-ZTBZMRQT.js → chunk-3RKVDGRF.js} +8 -8
- package/Build/Workers/{chunk-J2HTPGC7.js → chunk-4DSTDGY3.js} +2 -2
- package/Build/Workers/{chunk-P2N5IDWU.js → chunk-4MIY63FM.js} +13 -13
- package/Build/Workers/{chunk-XYGBWBD5.js → chunk-5OL6XFNS.js} +1 -1
- package/Build/Workers/{chunk-E7SMO47Q.js → chunk-5WVF4BK7.js} +5 -5
- package/Build/Workers/{chunk-SQKTLDSD.js → chunk-AEGAQ6FD.js} +12 -12
- package/Build/Workers/{chunk-4BGKMM7J.js → chunk-CES6DHHV.js} +1 -1
- package/Build/Workers/{chunk-MAIKDIBS.js → chunk-DINSLSJD.js} +6 -6
- package/Build/Workers/{chunk-G6JUXZUO.js → chunk-EHB2OCQX.js} +4 -4
- package/Build/Workers/{chunk-SSLK4U3V.js → chunk-EXEZHW3P.js} +4 -4
- package/Build/Workers/{chunk-236N6BJN.js → chunk-F4ZAKN4V.js} +2 -2
- package/Build/Workers/{chunk-HBNWBMAM.js → chunk-FPYBD2P5.js} +1 -1
- package/Build/Workers/{chunk-5PC577K7.js → chunk-GAUF4F5A.js} +16 -16
- package/Build/Workers/{chunk-YE6MDFDA.js → chunk-GM55YFOB.js} +14 -14
- package/Build/Workers/{chunk-HGEGZ67N.js → chunk-GS55WTRX.js} +6 -6
- package/Build/Workers/{chunk-LPGOAMYH.js → chunk-HQE7KSR4.js} +2 -2
- package/Build/Workers/{chunk-IFIS4CVK.js → chunk-HS76VTVY.js} +2 -2
- package/Build/Workers/{chunk-7IIMO7ZZ.js → chunk-I3BAKR4S.js} +16 -16
- package/Build/Workers/{chunk-PM4Q36WX.js → chunk-IWGMVQGG.js} +9 -9
- package/Build/Workers/{chunk-UFV3YUIN.js → chunk-IWZK2AIH.js} +5 -5
- package/Build/Workers/{chunk-QJTIOB2Z.js → chunk-J4MAVE6J.js} +6 -6
- package/Build/Workers/{chunk-RX65FA7X.js → chunk-JF4IYQYC.js} +7 -7
- package/Build/Workers/{chunk-7PHT4JHA.js → chunk-KGXTCGX3.js} +12 -12
- package/Build/Workers/{chunk-K5JTWJPE.js → chunk-KNA65INJ.js} +4 -4
- package/Build/Workers/{chunk-CBFJVM6I.js → chunk-LIPZUYNR.js} +11 -11
- package/Build/Workers/{chunk-C5DCX2YQ.js → chunk-LWJWWCZ4.js} +6 -6
- package/Build/Workers/{chunk-KE45DUDH.js → chunk-LZFUG3GO.js} +10 -10
- package/Build/Workers/{chunk-P57PR3WM.js → chunk-MFGVMUN3.js} +5 -5
- package/Build/Workers/{chunk-QUFN3GEO.js → chunk-NR7KSD56.js} +3 -3
- package/Build/Workers/{chunk-MS5NWDHH.js → chunk-NVJ5JRIM.js} +2 -2
- package/Build/Workers/{chunk-CQMXZF4A.js → chunk-NWSAYFZG.js} +6 -6
- package/Build/Workers/{chunk-5YEFZMMM.js → chunk-OATG6PKE.js} +12 -12
- package/Build/Workers/{chunk-UX5JWAC7.js → chunk-OIHAAHBK.js} +10 -10
- package/Build/Workers/{chunk-DRMXU674.js → chunk-QN7JEOQV.js} +5 -5
- package/Build/Workers/{chunk-77MDEA47.js → chunk-QUSP3NWA.js} +5 -5
- package/Build/Workers/{chunk-GO3RZX2R.js → chunk-RWFYLWSF.js} +9 -9
- package/Build/Workers/{chunk-UZ6KXWCA.js → chunk-SIOVJ4L5.js} +4 -4
- package/Build/Workers/{chunk-OBHLT34A.js → chunk-T6B6H3GR.js} +7 -7
- package/Build/Workers/{chunk-IKDQX7DY.js → chunk-UK33ZN4K.js} +4 -4
- package/Build/Workers/{chunk-2BJXFXD7.js → chunk-VGJSKEIB.js} +4 -4
- package/Build/Workers/{chunk-5RPUEFSA.js → chunk-W6CPO62M.js} +6 -6
- package/Build/Workers/{chunk-37PA7GZW.js → chunk-WGHUCZMX.js} +7 -7
- package/Build/Workers/{chunk-UC7KH56Y.js → chunk-WTFZHPUW.js} +5 -5
- package/Build/Workers/{chunk-NZSBSY5K.js → chunk-WYCR5DWQ.js} +2 -2
- package/Build/Workers/{chunk-WP3IJYLC.js → chunk-YV37YFUM.js} +9 -9
- package/Build/Workers/{chunk-LVGYWPEX.js → chunk-ZADJ6FRX.js} +4 -4
- package/Build/Workers/{chunk-CC2WKHIW.js → chunk-ZIP27IX6.js} +6 -6
- package/Build/Workers/combineGeometry.js +21 -21
- package/Build/Workers/createBoxGeometry.js +15 -15
- package/Build/Workers/createBoxOutlineGeometry.js +13 -13
- package/Build/Workers/createCircleGeometry.js +23 -23
- package/Build/Workers/createCircleOutlineGeometry.js +16 -16
- package/Build/Workers/createCoplanarPolygonGeometry.js +30 -30
- package/Build/Workers/createCoplanarPolygonOutlineGeometry.js +28 -28
- package/Build/Workers/createCorridorGeometry.js +26 -26
- package/Build/Workers/createCorridorOutlineGeometry.js +25 -25
- package/Build/Workers/createCylinderGeometry.js +17 -17
- package/Build/Workers/createCylinderOutlineGeometry.js +15 -15
- package/Build/Workers/createEllipseGeometry.js +23 -23
- package/Build/Workers/createEllipseOutlineGeometry.js +16 -16
- package/Build/Workers/createEllipsoidGeometry.js +16 -16
- package/Build/Workers/createEllipsoidOutlineGeometry.js +15 -15
- package/Build/Workers/createFrustumGeometry.js +15 -15
- package/Build/Workers/createFrustumOutlineGeometry.js +15 -15
- package/Build/Workers/createGeometry.js +21 -21
- package/Build/Workers/createGroundPolylineGeometry.js +19 -19
- package/Build/Workers/createPlaneGeometry.js +13 -13
- package/Build/Workers/createPlaneOutlineGeometry.js +12 -12
- package/Build/Workers/createPolygonGeometry.js +29 -29
- package/Build/Workers/createPolygonOutlineGeometry.js +27 -27
- package/Build/Workers/createPolylineGeometry.js +22 -22
- package/Build/Workers/createPolylineVolumeGeometry.js +28 -28
- package/Build/Workers/createPolylineVolumeOutlineGeometry.js +24 -24
- package/Build/Workers/createRectangleGeometry.js +24 -24
- package/Build/Workers/createRectangleOutlineGeometry.js +17 -17
- package/Build/Workers/createSimplePolylineGeometry.js +20 -20
- package/Build/Workers/createSphereGeometry.js +16 -16
- package/Build/Workers/createSphereOutlineGeometry.js +15 -15
- package/Build/Workers/createTaskProcessorWorker.js +3 -3
- package/Build/Workers/createVectorTileClampedPolylines.js +12 -12
- package/Build/Workers/createVectorTileGeometries.js +21 -21
- package/Build/Workers/createVectorTilePoints.js +11 -11
- package/Build/Workers/createVectorTilePolygons.js +19 -19
- package/Build/Workers/createVectorTilePolylines.js +12 -12
- package/Build/Workers/createVerticesFromGoogleEarthEnterpriseBuffer.js +19 -19
- package/Build/Workers/createVerticesFromHeightmap.js +19 -19
- package/Build/Workers/createVerticesFromQuantizedTerrainMesh.js +16 -16
- package/Build/Workers/createWallGeometry.js +21 -21
- package/Build/Workers/createWallOutlineGeometry.js +20 -20
- package/Build/Workers/decodeDraco.js +10 -10
- package/Build/Workers/decodeGoogleEarthEnterprisePacket.js +5 -5
- package/Build/Workers/decodeI3S.js +9 -9
- package/Build/Workers/transcodeKTX2.js +25 -6
- package/Build/Workers/transferTypedArrayTest.js +1 -1
- package/Build/Workers/upsampleQuantizedTerrainMesh.js +19 -19
- package/Source/Core/Ion.js +1 -1
- package/Source/Core/PixelFormat.js +36 -0
- package/Source/Renderer/Texture3D.js +568 -0
- package/Source/Renderer/createUniform.js +1 -0
- package/Source/Renderer/createUniformArray.js +1 -0
- package/Source/Scene/ArcGisMapService.js +1 -1
- package/Source/Scene/Cesium3DTileset.js +138 -0
- package/Source/Scene/GlobeSurfaceShaderSet.js +4 -5
- package/Source/Scene/ImageryLayer.js +19 -4
- package/Source/Scene/ImageryLayerCollection.js +3 -2
- package/Source/Scene/Model/CartesianRectangle.js +108 -0
- package/Source/Scene/Model/ImageryConfiguration.js +25 -0
- package/Source/Scene/Model/ImageryCoverage.js +488 -0
- package/Source/Scene/Model/ImageryFlags.js +31 -0
- package/Source/Scene/Model/ImageryInput.js +60 -0
- package/Source/Scene/Model/ImageryPipelineStage.js +1040 -0
- package/Source/Scene/Model/MappedPositions.js +84 -0
- package/Source/Scene/Model/Model.js +38 -0
- package/Source/Scene/Model/ModelImagery.js +403 -0
- package/Source/Scene/Model/ModelImageryMapping.js +489 -0
- package/Source/Scene/Model/ModelPrimitiveImagery.js +972 -0
- package/Source/Scene/Model/ModelReader.js +810 -0
- package/Source/Scene/Model/ModelRenderResources.js +13 -0
- package/Source/Scene/Model/ModelRuntimePrimitive.js +19 -0
- package/Source/Scene/Model/ModelSceneGraph.js +133 -27
- package/Source/Scene/Model/NodeRenderResources.js +10 -0
- package/Source/Scene/ModelComponents.js +10 -0
- package/Source/Scene/VoxelPrimitive.js +22 -37
- package/Source/Scene/VoxelRenderResources.js +1 -1
- package/Source/Scene/processVoxelProperties.js +41 -100
- package/Source/Shaders/Builtin/Functions/windowToEyeCoordinates.glsl +0 -1
- package/Source/Shaders/Builtin/Functions/windowToEyeCoordinates.js +0 -1
- package/Source/Shaders/GlobeFS.glsl +22 -0
- package/Source/Shaders/GlobeFS.js +22 -0
- package/Source/Shaders/Model/MaterialStageFS.glsl +4 -0
- package/Source/Shaders/Model/MaterialStageFS.js +4 -0
- package/Source/Shaders/Model/ModelVS.glsl +4 -0
- package/Source/Shaders/Model/ModelVS.js +4 -0
- package/Source/Shaders/Voxels/IntersectDepth.glsl +10 -3
- package/Source/Shaders/Voxels/IntersectDepth.js +10 -3
- package/Source/Shaders/Voxels/Intersection.glsl +1 -3
- package/Source/Shaders/Voxels/Intersection.js +1 -3
- package/Source/Shaders/Voxels/IntersectionUtils.glsl +1 -0
- package/Source/Shaders/Voxels/IntersectionUtils.js +1 -0
- package/Source/Shaders/Voxels/VoxelFS.glsl +37 -24
- package/Source/Shaders/Voxels/VoxelFS.js +37 -24
- package/Source/ThirdParty/Workers/z-worker-pako.js +1 -1
- package/index.d.ts +50 -2
- package/index.js +100 -88
- package/package.json +3 -3
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
import defined from "../../Core/defined.js";
|
|
2
|
+
import Cartesian2 from "../../Core/Cartesian2.js";
|
|
3
|
+
import Cartesian3 from "../../Core/Cartesian3.js";
|
|
4
|
+
import Matrix4 from "../../Core/Matrix4.js";
|
|
5
|
+
import Rectangle from "../../Core/Rectangle.js";
|
|
6
|
+
import Cartographic from "../../Core/Cartographic.js";
|
|
7
|
+
import BoundingRectangle from "../../Core/BoundingRectangle.js";
|
|
8
|
+
import ComponentDatatype from "../../Core/ComponentDatatype.js";
|
|
9
|
+
import Check from "../../Core/Check.js";
|
|
10
|
+
|
|
11
|
+
import AttributeType from "../AttributeType.js";
|
|
12
|
+
import ModelReader from "./ModelReader.js";
|
|
13
|
+
import VertexAttributeSemantic from "../VertexAttributeSemantic.js";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A class for computing the texture coordinates of imagery that is
|
|
17
|
+
* supposed to be mapped on a <code>ModelComponents.Primitive</code>.
|
|
18
|
+
*
|
|
19
|
+
* @private
|
|
20
|
+
*/
|
|
21
|
+
class ModelImageryMapping {
|
|
22
|
+
/**
|
|
23
|
+
* Creates a typed array that contains texture coordinates for
|
|
24
|
+
* the given <code>MappedPositions</code>, using the given
|
|
25
|
+
* projection.
|
|
26
|
+
*
|
|
27
|
+
* This will be a typed array that contains the texture coordinates
|
|
28
|
+
* that result from projecting the given positions with the given
|
|
29
|
+
* projection, and normalizing them to their bounding rectangle.
|
|
30
|
+
*
|
|
31
|
+
* @param {MappedPositions} mappedPositions The positions
|
|
32
|
+
* @param {MapProjection} projection The projection that should be used
|
|
33
|
+
* @returns {TypedArray} The result
|
|
34
|
+
*/
|
|
35
|
+
static createTextureCoordinatesForMappedPositions(
|
|
36
|
+
mappedPositions,
|
|
37
|
+
projection,
|
|
38
|
+
) {
|
|
39
|
+
//>>includeStart('debug', pragmas.debug);
|
|
40
|
+
Check.defined("mappedPositions", mappedPositions);
|
|
41
|
+
Check.defined("projection", projection);
|
|
42
|
+
//>>includeEnd('debug');
|
|
43
|
+
|
|
44
|
+
const cartographicPositions = mappedPositions.cartographicPositions;
|
|
45
|
+
const cartographicBoundingRectangle =
|
|
46
|
+
mappedPositions.cartographicBoundingRectangle;
|
|
47
|
+
const numPositions = mappedPositions.numPositions;
|
|
48
|
+
return ModelImageryMapping._createTextureCoordinates(
|
|
49
|
+
cartographicPositions,
|
|
50
|
+
numPositions,
|
|
51
|
+
cartographicBoundingRectangle,
|
|
52
|
+
projection,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Creates a typed array that contains texture coordinates for
|
|
58
|
+
* a primitive with the given positions, using the given
|
|
59
|
+
* projection.
|
|
60
|
+
*
|
|
61
|
+
* This will be a typed array of size <code>numPositions*2</code>
|
|
62
|
+
* that contains the texture coordinates that result from
|
|
63
|
+
* projecting the given positions with the given projection,
|
|
64
|
+
* and normalizing them to the given bounding rectangle.
|
|
65
|
+
*
|
|
66
|
+
* @param {Iterable<Cartographic>} cartographicPositions The
|
|
67
|
+
* cartographic positions
|
|
68
|
+
* @param {number} numPositions The number of positions (vertices)
|
|
69
|
+
* @param {Rectangle} cartographicBoundingRectangle The bounding
|
|
70
|
+
* rectangle of the cartographic positions
|
|
71
|
+
* @param {MapProjection} projection The projection that should be used
|
|
72
|
+
* @returns {TypedArray} The result
|
|
73
|
+
* @private
|
|
74
|
+
*/
|
|
75
|
+
static _createTextureCoordinates(
|
|
76
|
+
cartographicPositions,
|
|
77
|
+
numPositions,
|
|
78
|
+
cartographicBoundingRectangle,
|
|
79
|
+
projection,
|
|
80
|
+
) {
|
|
81
|
+
//>>includeStart('debug', pragmas.debug);
|
|
82
|
+
Check.defined("cartographicPositions", cartographicPositions);
|
|
83
|
+
Check.typeOf.number.greaterThanOrEquals("numPositions", numPositions, 0);
|
|
84
|
+
Check.defined(
|
|
85
|
+
"cartographicBoundingRectangle",
|
|
86
|
+
cartographicBoundingRectangle,
|
|
87
|
+
);
|
|
88
|
+
Check.defined("projection", projection);
|
|
89
|
+
//>>includeEnd('debug');
|
|
90
|
+
|
|
91
|
+
// Convert the bounding `Rectangle`(!) of the cartographic positions
|
|
92
|
+
// into a `BoundingRectangle`(!) using the given projection
|
|
93
|
+
const boundingRectangle = new BoundingRectangle();
|
|
94
|
+
BoundingRectangle.fromRectangle(
|
|
95
|
+
cartographicBoundingRectangle,
|
|
96
|
+
projection,
|
|
97
|
+
boundingRectangle,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
// Compute the projected positions, using the given projection
|
|
101
|
+
const projectedPositions = ModelImageryMapping.createProjectedPositions(
|
|
102
|
+
cartographicPositions,
|
|
103
|
+
projection,
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
// Relativize the projected positions into the bounding rectangle
|
|
107
|
+
// to obtain texture coordinates
|
|
108
|
+
const texCoords = ModelImageryMapping.computeTexCoords(
|
|
109
|
+
projectedPositions,
|
|
110
|
+
boundingRectangle,
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
// Convert the texture coordinates into a typed array
|
|
114
|
+
const texCoordsTypedArray =
|
|
115
|
+
ModelImageryMapping.createTypedArrayFromCartesians2(
|
|
116
|
+
numPositions,
|
|
117
|
+
texCoords,
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
return texCoordsTypedArray;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Creates the `ModelComponents.Attribute` for the texture coordinates
|
|
125
|
+
* for a primitive
|
|
126
|
+
*
|
|
127
|
+
* This will create an attribute with
|
|
128
|
+
* - semantic: VertexAttributeSemantic.TEXCOORD
|
|
129
|
+
* - type: AttributeType.VEC2
|
|
130
|
+
* - count: mappedPositions.numPositions
|
|
131
|
+
* that contains the texture coordinates for the given vertex positions,
|
|
132
|
+
* after they are projected using the given projection, normalized to
|
|
133
|
+
* their bounding rectangle.
|
|
134
|
+
*
|
|
135
|
+
* @param {Iterable<Cartographic>} cartographicPositions The
|
|
136
|
+
* cartographic positions
|
|
137
|
+
* @param {number} numPositions The number of positions (vertices)
|
|
138
|
+
* @param {Rectangle} cartographicBoundingRectangle The bounding
|
|
139
|
+
* rectangle of the cartographic positions
|
|
140
|
+
* @param {MapProjection} projection The projection that should be used
|
|
141
|
+
* @returns {ModelComponents.Attribute} The new attribute
|
|
142
|
+
*/
|
|
143
|
+
static createTextureCoordinatesAttributeForMappedPositions(
|
|
144
|
+
mappedPositions,
|
|
145
|
+
projection,
|
|
146
|
+
) {
|
|
147
|
+
//>>includeStart('debug', pragmas.debug);
|
|
148
|
+
Check.defined("mappedPositions", mappedPositions);
|
|
149
|
+
Check.defined("projection", projection);
|
|
150
|
+
//>>includeEnd('debug');
|
|
151
|
+
|
|
152
|
+
// Create the typed array that contains the texture coordinates
|
|
153
|
+
const texCoordsTypedArray =
|
|
154
|
+
ModelImageryMapping.createTextureCoordinatesForMappedPositions(
|
|
155
|
+
mappedPositions,
|
|
156
|
+
projection,
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
// Create an attribute from the texture coordinates typed array
|
|
160
|
+
const texCoordAttribute =
|
|
161
|
+
ModelImageryMapping.createTexCoordAttribute(texCoordsTypedArray);
|
|
162
|
+
|
|
163
|
+
return texCoordAttribute;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Create an iterable that provides the cartographic positions
|
|
168
|
+
* of the given POSITION attribute, based on the given ellipsoid
|
|
169
|
+
*
|
|
170
|
+
* @param {ModelComponents.Attribute} primitivePositionAttribute
|
|
171
|
+
* The "POSITION" attribute of the primitive.
|
|
172
|
+
* @param {Matrix4} primitivePositionTransform The full transform of the primitive
|
|
173
|
+
* @param {Elliposid} ellipsoid The ellipsoid that should be used
|
|
174
|
+
* @returns {Iterable<Cartographic>} The iterable over `Cartographic` objects
|
|
175
|
+
*/
|
|
176
|
+
static createCartographicPositions(
|
|
177
|
+
primitivePositionAttribute,
|
|
178
|
+
primitivePositionTransform,
|
|
179
|
+
ellipsoid,
|
|
180
|
+
) {
|
|
181
|
+
//>>includeStart('debug', pragmas.debug);
|
|
182
|
+
Check.defined("primitivePositionAttribute", primitivePositionAttribute);
|
|
183
|
+
Check.defined("primitivePositionTransform", primitivePositionTransform);
|
|
184
|
+
Check.defined("ellipsoid", ellipsoid);
|
|
185
|
+
//>>includeEnd('debug');
|
|
186
|
+
|
|
187
|
+
// Extract the positions as a typed array
|
|
188
|
+
const typedArray = ModelReader.readAttributeAsTypedArray(
|
|
189
|
+
primitivePositionAttribute,
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
// Create an iterable over the positions
|
|
193
|
+
const type = primitivePositionAttribute.type;
|
|
194
|
+
const numComponents = AttributeType.getNumberOfComponents(type);
|
|
195
|
+
const positions =
|
|
196
|
+
ModelImageryMapping.createIterableCartesian3FromTypedArray(
|
|
197
|
+
typedArray,
|
|
198
|
+
numComponents,
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
// Compute the positions after they are transformed with the given matrix
|
|
202
|
+
const transformedPositions = ModelImageryMapping.transformCartesians3(
|
|
203
|
+
positions,
|
|
204
|
+
primitivePositionTransform,
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
// Compute the cartographic positions for the given ellipsoid
|
|
208
|
+
const cartographicPositions = ModelImageryMapping.transformToCartographic(
|
|
209
|
+
transformedPositions,
|
|
210
|
+
ellipsoid,
|
|
211
|
+
);
|
|
212
|
+
return cartographicPositions;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Creates an iterable over `Cartesian3` objects from the given
|
|
217
|
+
* typed array.
|
|
218
|
+
*
|
|
219
|
+
* The resulting iterable will always return the same `Cartesian3`
|
|
220
|
+
* object. Clients should not store and modify this object.
|
|
221
|
+
*
|
|
222
|
+
* @param {TypedArray} typedArray The typed array
|
|
223
|
+
* @param {number} stride The stride between to consecutive
|
|
224
|
+
* `Cartesian3` elements in the given array. Must be at least 3.
|
|
225
|
+
* @returns {Iterable<Cartesian3>} The iterable
|
|
226
|
+
*/
|
|
227
|
+
static createIterableCartesian3FromTypedArray(typedArray, stride) {
|
|
228
|
+
//>>includeStart('debug', pragmas.debug);
|
|
229
|
+
Check.defined("typedArray", typedArray);
|
|
230
|
+
Check.typeOf.number.greaterThanOrEquals("stride", stride, 3);
|
|
231
|
+
//>>includeEnd('debug');
|
|
232
|
+
|
|
233
|
+
const cartesian = new Cartesian3();
|
|
234
|
+
const numElements = typedArray.length / stride;
|
|
235
|
+
const result = {
|
|
236
|
+
[Symbol.iterator]: function* () {
|
|
237
|
+
for (let i = 0; i < numElements; i++) {
|
|
238
|
+
cartesian.x = typedArray[i * stride + 0];
|
|
239
|
+
cartesian.y = typedArray[i * stride + 1];
|
|
240
|
+
cartesian.z = typedArray[i * stride + 2];
|
|
241
|
+
yield cartesian;
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
};
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Creates a new iterable that applies the given mapper to the given iterable.
|
|
250
|
+
*
|
|
251
|
+
* @param {Iterable} iterable The input iterable
|
|
252
|
+
* @param {Function} mapper The mapper
|
|
253
|
+
* @returns {Iterable} The mapped iterable
|
|
254
|
+
*/
|
|
255
|
+
static map(iterable, mapper) {
|
|
256
|
+
//>>includeStart('debug', pragmas.debug);
|
|
257
|
+
Check.defined("iterable", iterable);
|
|
258
|
+
Check.defined("mapper", mapper);
|
|
259
|
+
//>>includeEnd('debug');
|
|
260
|
+
|
|
261
|
+
const result = {
|
|
262
|
+
[Symbol.iterator]: function* () {
|
|
263
|
+
for (const element of iterable) {
|
|
264
|
+
yield mapper(element);
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
return result;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Computes the bounding rectangle of the given cartographic positions,
|
|
273
|
+
* stores it in the given result, and returns it.
|
|
274
|
+
*
|
|
275
|
+
* If the given result is `undefined`, a new rectangle will be created
|
|
276
|
+
* and returned.
|
|
277
|
+
*
|
|
278
|
+
* @param {Iterable<Cartographic>} cartographicPositions The cartographics
|
|
279
|
+
* @param {Rectangle} [result] The result
|
|
280
|
+
* @returns {Rectangle} The result
|
|
281
|
+
*/
|
|
282
|
+
static computeCartographicBoundingRectangle(cartographicPositions, result) {
|
|
283
|
+
//>>includeStart('debug', pragmas.debug);
|
|
284
|
+
Check.defined("cartographicPositions", cartographicPositions);
|
|
285
|
+
//>>includeEnd('debug');
|
|
286
|
+
|
|
287
|
+
if (!defined(result)) {
|
|
288
|
+
result = new Rectangle();
|
|
289
|
+
}
|
|
290
|
+
// One could store these directly in the result, but that would
|
|
291
|
+
// violate the constraint of the PI-related ranges..
|
|
292
|
+
let north = Number.NEGATIVE_INFINITY;
|
|
293
|
+
let south = Number.POSITIVE_INFINITY;
|
|
294
|
+
let east = Number.NEGATIVE_INFINITY;
|
|
295
|
+
let west = Number.POSITIVE_INFINITY;
|
|
296
|
+
for (const cartographicPosition of cartographicPositions) {
|
|
297
|
+
north = Math.max(north, cartographicPosition.latitude);
|
|
298
|
+
south = Math.min(south, cartographicPosition.latitude);
|
|
299
|
+
east = Math.max(east, cartographicPosition.longitude);
|
|
300
|
+
west = Math.min(west, cartographicPosition.longitude);
|
|
301
|
+
}
|
|
302
|
+
result.north = north;
|
|
303
|
+
result.south = south;
|
|
304
|
+
result.east = east;
|
|
305
|
+
result.west = west;
|
|
306
|
+
return result;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Creates a new iterable that provides `Cartesian3` objects that
|
|
311
|
+
* are created by transforming the `Cartesian3` objects of the
|
|
312
|
+
* given iterable with the given matrix.
|
|
313
|
+
*
|
|
314
|
+
* The resulting iterable will always return the same `Cartesian3`
|
|
315
|
+
* object. Clients should not store and modify this object.
|
|
316
|
+
*
|
|
317
|
+
* @param {Iterable<Cartesian3>} positions The positions
|
|
318
|
+
* @param {Matrix4} matrix The matrix
|
|
319
|
+
* @returns {Iterable<Cartesian3>} The transformed cartesians
|
|
320
|
+
*/
|
|
321
|
+
static transformCartesians3(positions, matrix) {
|
|
322
|
+
//>>includeStart('debug', pragmas.debug);
|
|
323
|
+
Check.defined("positions", positions);
|
|
324
|
+
Check.defined("matrix", matrix);
|
|
325
|
+
//>>includeEnd('debug');
|
|
326
|
+
|
|
327
|
+
const transformedPosition = new Cartesian3();
|
|
328
|
+
const transformedPositions = ModelImageryMapping.map(positions, (p) => {
|
|
329
|
+
Matrix4.multiplyByPoint(matrix, p, transformedPosition);
|
|
330
|
+
return transformedPosition;
|
|
331
|
+
});
|
|
332
|
+
return transformedPositions;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Creates a new iterable that provides `Cartographic` objects that
|
|
337
|
+
* are created by converting the given `Cartesian3` objects to
|
|
338
|
+
* cartographics, based on the given ellipsoid.
|
|
339
|
+
*
|
|
340
|
+
* The resulting iterable will always return the same `Cartographic`
|
|
341
|
+
* object. Clients should not store and modify this object.
|
|
342
|
+
*
|
|
343
|
+
* @param {Iterable<Cartesian3>} positions The positions
|
|
344
|
+
* @param {Ellipsoid} ellipsoid The ellipsoid
|
|
345
|
+
* @returns {Iterable<Cartographic>} The cartographic positions
|
|
346
|
+
*/
|
|
347
|
+
static transformToCartographic(positions, ellipsoid) {
|
|
348
|
+
//>>includeStart('debug', pragmas.debug);
|
|
349
|
+
Check.defined("positions", positions);
|
|
350
|
+
Check.defined("ellipsoid", ellipsoid);
|
|
351
|
+
//>>includeEnd('debug');
|
|
352
|
+
|
|
353
|
+
const cartographicPosition = new Cartographic();
|
|
354
|
+
const cartographicPositions = ModelImageryMapping.map(positions, (p) => {
|
|
355
|
+
// Note: This will not yield valid results for p=(0,0,0).
|
|
356
|
+
// But there is no sensible cartographic position for
|
|
357
|
+
// that, so simply accept the unspecified output here.
|
|
358
|
+
ellipsoid.cartesianToCartographic(p, cartographicPosition);
|
|
359
|
+
return cartographicPosition;
|
|
360
|
+
});
|
|
361
|
+
return cartographicPositions;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Creates an iterable over the results of applying the given projection
|
|
366
|
+
* to the given cartographic positions.
|
|
367
|
+
*
|
|
368
|
+
* The resulting iterable will always return the same `Cartesian3`
|
|
369
|
+
* object. Clients should not store and modify this object.
|
|
370
|
+
*
|
|
371
|
+
* @param {Iterable<Cartographic>} cartographicPositions The cartographic
|
|
372
|
+
* positions
|
|
373
|
+
* @param {MapProjection} projection The projection to use
|
|
374
|
+
* @returns {Iterable<Cartesian3>} The projected positions
|
|
375
|
+
*/
|
|
376
|
+
static createProjectedPositions(cartographicPositions, projection) {
|
|
377
|
+
//>>includeStart('debug', pragmas.debug);
|
|
378
|
+
Check.defined("cartographicPositions", cartographicPositions);
|
|
379
|
+
Check.defined("projection", projection);
|
|
380
|
+
//>>includeEnd('debug');
|
|
381
|
+
|
|
382
|
+
const projectedPosition = new Cartesian3();
|
|
383
|
+
const projectedPositions = ModelImageryMapping.map(
|
|
384
|
+
cartographicPositions,
|
|
385
|
+
(c) => {
|
|
386
|
+
projection.project(c, projectedPosition);
|
|
387
|
+
return projectedPosition;
|
|
388
|
+
},
|
|
389
|
+
);
|
|
390
|
+
return projectedPositions;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Computes the texture coordinates for the given positions, relative
|
|
395
|
+
* to the given bounding rectangle.
|
|
396
|
+
*
|
|
397
|
+
* This will make the x/y coordinates of the given cartesians relative
|
|
398
|
+
* to the given bounding rectangle and clamp them to [0,0]-[1,1].
|
|
399
|
+
*
|
|
400
|
+
* NOTE: This could be broken down into
|
|
401
|
+
* 1. mapping to 2D
|
|
402
|
+
* 2. relativizing for the bounding recangle
|
|
403
|
+
* 3. clamping to [0,0]-[1,1]
|
|
404
|
+
*
|
|
405
|
+
* @param {Iterable<Cartesian3>} positions The positions
|
|
406
|
+
* @param {BoundingRectangle} boundingRectangle The rectangle
|
|
407
|
+
* @returns {Iterable<Cartesian2>} The texture coordinates
|
|
408
|
+
*/
|
|
409
|
+
static computeTexCoords(positions, boundingRectangle) {
|
|
410
|
+
//>>includeStart('debug', pragmas.debug);
|
|
411
|
+
Check.defined("positions", positions);
|
|
412
|
+
Check.defined("boundingRectangle", boundingRectangle);
|
|
413
|
+
//>>includeEnd('debug');
|
|
414
|
+
|
|
415
|
+
const texCoord = new Cartesian2();
|
|
416
|
+
const invSizeX = 1.0 / boundingRectangle.width;
|
|
417
|
+
const invSizeY = 1.0 / boundingRectangle.height;
|
|
418
|
+
const texCoords = ModelImageryMapping.map(positions, (p) => {
|
|
419
|
+
const uRaw = (p.x - boundingRectangle.x) * invSizeX;
|
|
420
|
+
const vRaw = (p.y - boundingRectangle.y) * invSizeY;
|
|
421
|
+
const u = Math.min(Math.max(uRaw, 0.0), 1.0);
|
|
422
|
+
const v = Math.min(Math.max(vRaw, 0.0), 1.0);
|
|
423
|
+
texCoord.x = u;
|
|
424
|
+
texCoord.y = v;
|
|
425
|
+
return texCoord;
|
|
426
|
+
});
|
|
427
|
+
return texCoords;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Creates a new typed array from the given `Cartesian2` objects.
|
|
432
|
+
*
|
|
433
|
+
* @param {number} numElements The number of elements
|
|
434
|
+
* @param {Iterable<Cartesian2>} elements The elements
|
|
435
|
+
* @returns {TypedArray} The typed array
|
|
436
|
+
*/
|
|
437
|
+
static createTypedArrayFromCartesians2(numElements, elements) {
|
|
438
|
+
//>>includeStart('debug', pragmas.debug);
|
|
439
|
+
Check.typeOf.number.greaterThanOrEquals("numElements", numElements, 0);
|
|
440
|
+
Check.defined("elements", elements);
|
|
441
|
+
//>>includeEnd('debug');
|
|
442
|
+
|
|
443
|
+
const typedArray = new Float32Array(numElements * 2);
|
|
444
|
+
let index = 0;
|
|
445
|
+
for (const element of elements) {
|
|
446
|
+
typedArray[index * 2 + 0] = element.x;
|
|
447
|
+
typedArray[index * 2 + 1] = element.y;
|
|
448
|
+
index++;
|
|
449
|
+
}
|
|
450
|
+
return typedArray;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Create a new texture coordinates attribute from the given data.
|
|
455
|
+
*
|
|
456
|
+
* This will create an attribute with
|
|
457
|
+
* - semantic: VertexAttributeSemantic.TEXCOORD
|
|
458
|
+
* - type: AttributeType.VEC2
|
|
459
|
+
* - count: texCoordsTypedArray.length / 2
|
|
460
|
+
* that contains the data from the given typed array.
|
|
461
|
+
*
|
|
462
|
+
* @param {TypedArray} texCoordsTypedArray The typed array
|
|
463
|
+
* @returns {ModelComponents.Attribute} The attribute
|
|
464
|
+
*/
|
|
465
|
+
static createTexCoordAttribute(texCoordsTypedArray) {
|
|
466
|
+
//>>includeStart('debug', pragmas.debug);
|
|
467
|
+
Check.defined("texCoordsTypedArray", texCoordsTypedArray);
|
|
468
|
+
//>>includeEnd('debug');
|
|
469
|
+
|
|
470
|
+
const texCoordAttribute = {
|
|
471
|
+
name: "Imagery Texture Coordinates",
|
|
472
|
+
semantic: VertexAttributeSemantic.TEXCOORD,
|
|
473
|
+
setIndex: 0,
|
|
474
|
+
componentDatatype: ComponentDatatype.FLOAT,
|
|
475
|
+
type: AttributeType.VEC2,
|
|
476
|
+
normalized: false,
|
|
477
|
+
count: texCoordsTypedArray.length / 2,
|
|
478
|
+
min: undefined,
|
|
479
|
+
max: undefined,
|
|
480
|
+
constant: new Cartesian2(0, 0),
|
|
481
|
+
quantization: undefined,
|
|
482
|
+
typedArray: texCoordsTypedArray,
|
|
483
|
+
byteOffset: 0,
|
|
484
|
+
byteStride: undefined,
|
|
485
|
+
};
|
|
486
|
+
return texCoordAttribute;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
export default ModelImageryMapping;
|