@@ -10,6 +10,7 @@ define([
10
10
'./CoplanarPolygonGeometryLibrary' ,
11
11
'./defaultValue' ,
12
12
'./defined' ,
13
+ './Ellipsoid' ,
13
14
'./Geometry' ,
14
15
'./GeometryAttribute' ,
15
16
'./GeometryAttributes' ,
@@ -34,6 +35,7 @@ define([
34
35
CoplanarPolygonGeometryLibrary ,
35
36
defaultValue ,
36
37
defined ,
38
+ Ellipsoid ,
37
39
Geometry ,
38
40
GeometryAttribute ,
39
41
GeometryAttributes ,
@@ -62,6 +64,7 @@ define([
62
64
var quaternionScratch = new Quaternion ( ) ;
63
65
var textureMatrixScratch = new Matrix3 ( ) ;
64
66
var tangentRotationScratch = new Matrix3 ( ) ;
67
+ var surfaceNormalScratch = new Cartesian3 ( ) ;
65
68
66
69
function createGeometryFromPolygon ( polygon , vertexFormat , boundingRectangle , stRotation , projectPointTo2D , normal , tangent , bitangent ) {
67
70
var positions = polygon . positions ;
@@ -208,6 +211,7 @@ define([
208
211
* @param {PolygonHierarchy } options.polygonHierarchy A polygon hierarchy that can include holes.
209
212
* @param {Number } [options.stRotation=0.0] The rotation of the texture coordinates, in radians. A positive rotation is counter-clockwise.
210
213
* @param {VertexFormat } [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
214
+ * @param {Ellipsoid } [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.
211
215
*
212
216
* @example
213
217
* var polygon = new Cesium.CoplanarPolygonGeometry({
@@ -233,13 +237,14 @@ define([
233
237
this . _vertexFormat = VertexFormat . clone ( vertexFormat ) ;
234
238
this . _polygonHierarchy = polygonHierarchy ;
235
239
this . _stRotation = defaultValue ( options . stRotation , 0.0 ) ;
240
+ this . _ellipsoid = Ellipsoid . clone ( defaultValue ( options . ellipsoid , Ellipsoid . WGS84 ) ) ;
236
241
this . _workerName = 'createCoplanarPolygonGeometry' ;
237
242
238
243
/**
239
244
* The number of elements used to pack the object into an array.
240
245
* @type {Number }
241
246
*/
242
- this . packedLength = PolygonGeometryLibrary . computeHierarchyPackedLength ( polygonHierarchy ) + VertexFormat . packedLength + 2 ;
247
+ this . packedLength = PolygonGeometryLibrary . computeHierarchyPackedLength ( polygonHierarchy ) + VertexFormat . packedLength + Ellipsoid . packedLength + 2 ;
243
248
}
244
249
245
250
/**
@@ -249,6 +254,7 @@ define([
249
254
* @param {Cartesian3[] } options.positions An array of positions that defined the corner points of the polygon.
250
255
* @param {VertexFormat } [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
251
256
* @param {Number } [options.stRotation=0.0] The rotation of the texture coordinates, in radians. A positive rotation is counter-clockwise.
257
+ * @param {Ellipsoid } [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.
252
258
* @returns {CoplanarPolygonGeometry }
253
259
*
254
260
* @example
@@ -278,7 +284,8 @@ define([
278
284
positions : options . positions
279
285
} ,
280
286
vertexFormat : options . vertexFormat ,
281
- stRotation : options . stRotation
287
+ stRotation : options . stRotation ,
288
+ ellipsoid : options . ellipsoid
282
289
} ;
283
290
return new CoplanarPolygonGeometry ( newOptions ) ;
284
291
} ;
@@ -302,6 +309,9 @@ define([
302
309
303
310
startingIndex = PolygonGeometryLibrary . packPolygonHierarchy ( value . _polygonHierarchy , array , startingIndex ) ;
304
311
312
+ Ellipsoid . pack ( value . _ellipsoid , array , startingIndex ) ;
313
+ startingIndex += Ellipsoid . packedLength ;
314
+
305
315
VertexFormat . pack ( value . _vertexFormat , array , startingIndex ) ;
306
316
startingIndex += VertexFormat . packedLength ;
307
317
@@ -311,6 +321,7 @@ define([
311
321
return array ;
312
322
} ;
313
323
324
+ var scratchEllipsoid = Ellipsoid . clone ( Ellipsoid . UNIT_SPHERE ) ;
314
325
var scratchVertexFormat = new VertexFormat ( ) ;
315
326
var scratchOptions = {
316
327
polygonHierarchy : { }
@@ -334,6 +345,9 @@ define([
334
345
startingIndex = polygonHierarchy . startingIndex ;
335
346
delete polygonHierarchy . startingIndex ;
336
347
348
+ var ellipsoid = Ellipsoid . unpack ( array , startingIndex , scratchEllipsoid ) ;
349
+ startingIndex += Ellipsoid . packedLength ;
350
+
337
351
var vertexFormat = VertexFormat . unpack ( array , startingIndex , scratchVertexFormat ) ;
338
352
startingIndex += VertexFormat . packedLength ;
339
353
@@ -345,6 +359,7 @@ define([
345
359
}
346
360
347
361
result . _polygonHierarchy = polygonHierarchy ;
362
+ result . _ellipsoid = Ellipsoid . clone ( ellipsoid , result . _ellipsoid ) ;
348
363
result . _vertexFormat = VertexFormat . clone ( vertexFormat , result . _vertexFormat ) ;
349
364
result . _stRotation = stRotation ;
350
365
result . packedLength = packedLength ;
@@ -371,22 +386,33 @@ define([
371
386
var normal = scratchNormal ;
372
387
var tangent = scratchTangent ;
373
388
var bitangent = scratchBitangent ;
389
+ var axis1 = axis1Scratch ;
390
+ var axis2 = axis2Scratch ;
374
391
375
- var validGeometry = CoplanarPolygonGeometryLibrary . computeProjectTo2DArguments ( outerPositions , centerScratch , axis1Scratch , axis2Scratch ) ;
392
+ var validGeometry = CoplanarPolygonGeometryLibrary . computeProjectTo2DArguments ( outerPositions , centerScratch , axis1 , axis2 ) ;
376
393
if ( ! validGeometry ) {
377
394
return undefined ;
378
395
}
379
- var projectPoints = CoplanarPolygonGeometryLibrary . createProjectPointsTo2DFunction ( centerScratch , axis1Scratch , axis2Scratch ) ;
380
- var projectPoint = CoplanarPolygonGeometryLibrary . createProjectPointTo2DFunction ( centerScratch , axis1Scratch , axis2Scratch ) ;
381
396
382
- normal = Cartesian3 . cross ( axis1Scratch , axis2Scratch , normal ) ;
397
+ normal = Cartesian3 . cross ( axis1 , axis2 , normal ) ;
383
398
normal = Cartesian3 . normalize ( normal , normal ) ;
384
399
400
+ if ( ! Cartesian3 . equalsEpsilon ( centerScratch , Cartesian3 . ZERO , CesiumMath . EPSILON6 ) ) {
401
+ var surfaceNormal = polygonGeometry . _ellipsoid . geodeticSurfaceNormal ( centerScratch , surfaceNormalScratch ) ;
402
+ if ( Cartesian3 . dot ( normal , surfaceNormal ) < 0 ) {
403
+ normal = Cartesian3 . negate ( normal , normal ) ;
404
+ axis1 = Cartesian3 . negate ( axis1 , axis1 ) ;
405
+ }
406
+ }
407
+
408
+ var projectPoints = CoplanarPolygonGeometryLibrary . createProjectPointsTo2DFunction ( centerScratch , axis1 , axis2 ) ;
409
+ var projectPoint = CoplanarPolygonGeometryLibrary . createProjectPointTo2DFunction ( centerScratch , axis1 , axis2 ) ;
410
+
385
411
if ( vertexFormat . tangent ) {
386
- tangent = Cartesian3 . clone ( axis1Scratch , tangent ) ;
412
+ tangent = Cartesian3 . clone ( axis1 , tangent ) ;
387
413
}
388
414
if ( vertexFormat . bitangent ) {
389
- bitangent = Cartesian3 . clone ( axis2Scratch , bitangent ) ;
415
+ bitangent = Cartesian3 . clone ( axis2 , bitangent ) ;
390
416
}
391
417
392
418
var results = PolygonGeometryLibrary . polygonsFromHierarchy ( polygonHierarchy , projectPoints , false ) ;
0 commit comments