createCoplanarPolygonGeometry.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. define(['./arrayRemoveDuplicates-d2061e85', './BoundingRectangle-995f0079', './Transforms-bc45e707', './Matrix2-e1298525', './Matrix3-41c58dde', './Check-6ede7e26', './ComponentDatatype-cf1fa08e', './CoplanarPolygonGeometryLibrary-d7d972d6', './defaultValue-fe22d8c0', './GeometryAttribute-a466e9c7', './GeometryAttributes-ad136444', './GeometryInstance-34d9e21e', './GeometryPipeline-dcf79306', './IndexDatatype-2643aa47', './Math-0a2ac845', './PolygonGeometryLibrary-59126025', './PolygonPipeline-1fe328c0', './VertexFormat-030f11ff', './combine-d9581036', './RuntimeError-ef395448', './WebGLConstants-0b1ce7ba', './OrientedBoundingBox-2dd47921', './EllipsoidTangentPlane-46d4d9c2', './AxisAlignedBoundingBox-31fadcf0', './IntersectionTests-88c49b2e', './Plane-4c3d403b', './AttributeCompression-f9f6c717', './EncodedCartesian3-57415c8a', './ArcType-2d9abbbc', './EllipsoidRhumbLine-ef872433'], (function (arrayRemoveDuplicates, BoundingRectangle, Transforms, Matrix2, Matrix3, Check, ComponentDatatype, CoplanarPolygonGeometryLibrary, defaultValue, GeometryAttribute, GeometryAttributes, GeometryInstance, GeometryPipeline, IndexDatatype, Math, PolygonGeometryLibrary, PolygonPipeline, VertexFormat, combine, RuntimeError, WebGLConstants, OrientedBoundingBox, EllipsoidTangentPlane, AxisAlignedBoundingBox, IntersectionTests, Plane, AttributeCompression, EncodedCartesian3, ArcType, EllipsoidRhumbLine) { 'use strict';
  2. const scratchPosition = new Matrix3.Cartesian3();
  3. const scratchBR = new BoundingRectangle.BoundingRectangle();
  4. const stScratch = new Matrix2.Cartesian2();
  5. const textureCoordinatesOrigin = new Matrix2.Cartesian2();
  6. const scratchNormal = new Matrix3.Cartesian3();
  7. const scratchTangent = new Matrix3.Cartesian3();
  8. const scratchBitangent = new Matrix3.Cartesian3();
  9. const centerScratch = new Matrix3.Cartesian3();
  10. const axis1Scratch = new Matrix3.Cartesian3();
  11. const axis2Scratch = new Matrix3.Cartesian3();
  12. const quaternionScratch = new Transforms.Quaternion();
  13. const textureMatrixScratch = new Matrix3.Matrix3();
  14. const tangentRotationScratch = new Matrix3.Matrix3();
  15. const surfaceNormalScratch = new Matrix3.Cartesian3();
  16. function createGeometryFromPolygon(
  17. polygon,
  18. vertexFormat,
  19. boundingRectangle,
  20. stRotation,
  21. hardcodedTextureCoordinates,
  22. projectPointTo2D,
  23. normal,
  24. tangent,
  25. bitangent
  26. ) {
  27. const positions = polygon.positions;
  28. let indices = PolygonPipeline.PolygonPipeline.triangulate(polygon.positions2D, polygon.holes);
  29. /* If polygon is completely unrenderable, just use the first three vertices */
  30. if (indices.length < 3) {
  31. indices = [0, 1, 2];
  32. }
  33. const newIndices = IndexDatatype.IndexDatatype.createTypedArray(
  34. positions.length,
  35. indices.length
  36. );
  37. newIndices.set(indices);
  38. let textureMatrix = textureMatrixScratch;
  39. if (stRotation !== 0.0) {
  40. let rotation = Transforms.Quaternion.fromAxisAngle(
  41. normal,
  42. stRotation,
  43. quaternionScratch
  44. );
  45. textureMatrix = Matrix3.Matrix3.fromQuaternion(rotation, textureMatrix);
  46. if (vertexFormat.tangent || vertexFormat.bitangent) {
  47. rotation = Transforms.Quaternion.fromAxisAngle(
  48. normal,
  49. -stRotation,
  50. quaternionScratch
  51. );
  52. const tangentRotation = Matrix3.Matrix3.fromQuaternion(
  53. rotation,
  54. tangentRotationScratch
  55. );
  56. tangent = Matrix3.Cartesian3.normalize(
  57. Matrix3.Matrix3.multiplyByVector(tangentRotation, tangent, tangent),
  58. tangent
  59. );
  60. if (vertexFormat.bitangent) {
  61. bitangent = Matrix3.Cartesian3.normalize(
  62. Matrix3.Cartesian3.cross(normal, tangent, bitangent),
  63. bitangent
  64. );
  65. }
  66. }
  67. } else {
  68. textureMatrix = Matrix3.Matrix3.clone(Matrix3.Matrix3.IDENTITY, textureMatrix);
  69. }
  70. const stOrigin = textureCoordinatesOrigin;
  71. if (vertexFormat.st) {
  72. stOrigin.x = boundingRectangle.x;
  73. stOrigin.y = boundingRectangle.y;
  74. }
  75. const length = positions.length;
  76. const size = length * 3;
  77. const flatPositions = new Float64Array(size);
  78. const normals = vertexFormat.normal ? new Float32Array(size) : undefined;
  79. const tangents = vertexFormat.tangent ? new Float32Array(size) : undefined;
  80. const bitangents = vertexFormat.bitangent
  81. ? new Float32Array(size)
  82. : undefined;
  83. const textureCoordinates = vertexFormat.st
  84. ? new Float32Array(length * 2)
  85. : undefined;
  86. let positionIndex = 0;
  87. let normalIndex = 0;
  88. let bitangentIndex = 0;
  89. let tangentIndex = 0;
  90. let stIndex = 0;
  91. for (let i = 0; i < length; i++) {
  92. const position = positions[i];
  93. flatPositions[positionIndex++] = position.x;
  94. flatPositions[positionIndex++] = position.y;
  95. flatPositions[positionIndex++] = position.z;
  96. if (vertexFormat.st) {
  97. if (
  98. defaultValue.defined(hardcodedTextureCoordinates) &&
  99. hardcodedTextureCoordinates.positions.length === length
  100. ) {
  101. textureCoordinates[stIndex++] =
  102. hardcodedTextureCoordinates.positions[i].x;
  103. textureCoordinates[stIndex++] =
  104. hardcodedTextureCoordinates.positions[i].y;
  105. } else {
  106. const p = Matrix3.Matrix3.multiplyByVector(
  107. textureMatrix,
  108. position,
  109. scratchPosition
  110. );
  111. const st = projectPointTo2D(p, stScratch);
  112. Matrix2.Cartesian2.subtract(st, stOrigin, st);
  113. const stx = Math.CesiumMath.clamp(st.x / boundingRectangle.width, 0, 1);
  114. const sty = Math.CesiumMath.clamp(st.y / boundingRectangle.height, 0, 1);
  115. textureCoordinates[stIndex++] = stx;
  116. textureCoordinates[stIndex++] = sty;
  117. }
  118. }
  119. if (vertexFormat.normal) {
  120. normals[normalIndex++] = normal.x;
  121. normals[normalIndex++] = normal.y;
  122. normals[normalIndex++] = normal.z;
  123. }
  124. if (vertexFormat.tangent) {
  125. tangents[tangentIndex++] = tangent.x;
  126. tangents[tangentIndex++] = tangent.y;
  127. tangents[tangentIndex++] = tangent.z;
  128. }
  129. if (vertexFormat.bitangent) {
  130. bitangents[bitangentIndex++] = bitangent.x;
  131. bitangents[bitangentIndex++] = bitangent.y;
  132. bitangents[bitangentIndex++] = bitangent.z;
  133. }
  134. }
  135. const attributes = new GeometryAttributes.GeometryAttributes();
  136. if (vertexFormat.position) {
  137. attributes.position = new GeometryAttribute.GeometryAttribute({
  138. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  139. componentsPerAttribute: 3,
  140. values: flatPositions,
  141. });
  142. }
  143. if (vertexFormat.normal) {
  144. attributes.normal = new GeometryAttribute.GeometryAttribute({
  145. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  146. componentsPerAttribute: 3,
  147. values: normals,
  148. });
  149. }
  150. if (vertexFormat.tangent) {
  151. attributes.tangent = new GeometryAttribute.GeometryAttribute({
  152. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  153. componentsPerAttribute: 3,
  154. values: tangents,
  155. });
  156. }
  157. if (vertexFormat.bitangent) {
  158. attributes.bitangent = new GeometryAttribute.GeometryAttribute({
  159. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  160. componentsPerAttribute: 3,
  161. values: bitangents,
  162. });
  163. }
  164. if (vertexFormat.st) {
  165. attributes.st = new GeometryAttribute.GeometryAttribute({
  166. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  167. componentsPerAttribute: 2,
  168. values: textureCoordinates,
  169. });
  170. }
  171. return new GeometryAttribute.Geometry({
  172. attributes: attributes,
  173. indices: newIndices,
  174. primitiveType: GeometryAttribute.PrimitiveType.TRIANGLES,
  175. });
  176. }
  177. /**
  178. * A description of a polygon composed of arbitrary coplanar positions.
  179. *
  180. * @alias CoplanarPolygonGeometry
  181. * @constructor
  182. *
  183. * @param {object} options Object with the following properties:
  184. * @param {PolygonHierarchy} options.polygonHierarchy A polygon hierarchy that can include holes.
  185. * @param {number} [options.stRotation=0.0] The rotation of the texture coordinates, in radians. A positive rotation is counter-clockwise.
  186. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
  187. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.
  188. * @param {PolygonHierarchy} [options.textureCoordinates] Texture coordinates as a {@link PolygonHierarchy} of {@link Cartesian2} points.
  189. *
  190. * @example
  191. * const polygonGeometry = new Cesium.CoplanarPolygonGeometry({
  192. * polygonHierarchy: new Cesium.PolygonHierarchy(
  193. * Cesium.Cartesian3.fromDegreesArrayHeights([
  194. * -90.0, 30.0, 0.0,
  195. * -90.0, 30.0, 300000.0,
  196. * -80.0, 30.0, 300000.0,
  197. * -80.0, 30.0, 0.0
  198. * ]))
  199. * });
  200. *
  201. */
  202. function CoplanarPolygonGeometry(options) {
  203. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  204. const polygonHierarchy = options.polygonHierarchy;
  205. const textureCoordinates = options.textureCoordinates;
  206. //>>includeStart('debug', pragmas.debug);
  207. Check.Check.defined("options.polygonHierarchy", polygonHierarchy);
  208. //>>includeEnd('debug');
  209. const vertexFormat = defaultValue.defaultValue(options.vertexFormat, VertexFormat.VertexFormat.DEFAULT);
  210. this._vertexFormat = VertexFormat.VertexFormat.clone(vertexFormat);
  211. this._polygonHierarchy = polygonHierarchy;
  212. this._stRotation = defaultValue.defaultValue(options.stRotation, 0.0);
  213. this._ellipsoid = Matrix3.Ellipsoid.clone(
  214. defaultValue.defaultValue(options.ellipsoid, Matrix3.Ellipsoid.WGS84)
  215. );
  216. this._workerName = "createCoplanarPolygonGeometry";
  217. this._textureCoordinates = textureCoordinates;
  218. /**
  219. * The number of elements used to pack the object into an array.
  220. * @type {number}
  221. */
  222. this.packedLength =
  223. PolygonGeometryLibrary.PolygonGeometryLibrary.computeHierarchyPackedLength(
  224. polygonHierarchy,
  225. Matrix3.Cartesian3
  226. ) +
  227. VertexFormat.VertexFormat.packedLength +
  228. Matrix3.Ellipsoid.packedLength +
  229. (defaultValue.defined(textureCoordinates)
  230. ? PolygonGeometryLibrary.PolygonGeometryLibrary.computeHierarchyPackedLength(
  231. textureCoordinates,
  232. Matrix2.Cartesian2
  233. )
  234. : 1) +
  235. 2;
  236. }
  237. /**
  238. * A description of a coplanar polygon from an array of positions.
  239. *
  240. * @param {object} options Object with the following properties:
  241. * @param {Cartesian3[]} options.positions An array of positions that defined the corner points of the polygon.
  242. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
  243. * @param {number} [options.stRotation=0.0] The rotation of the texture coordinates, in radians. A positive rotation is counter-clockwise.
  244. * @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84] The ellipsoid to be used as a reference.
  245. * @param {PolygonHierarchy} [options.textureCoordinates] Texture coordinates as a {@link PolygonHierarchy} of {@link Cartesian2} points.
  246. * @returns {CoplanarPolygonGeometry}
  247. *
  248. * @example
  249. * // create a polygon from points
  250. * const polygon = Cesium.CoplanarPolygonGeometry.fromPositions({
  251. * positions : Cesium.Cartesian3.fromDegreesArray([
  252. * -72.0, 40.0,
  253. * -70.0, 35.0,
  254. * -75.0, 30.0,
  255. * -70.0, 30.0,
  256. * -68.0, 40.0
  257. * ])
  258. * });
  259. * const geometry = Cesium.PolygonGeometry.createGeometry(polygon);
  260. *
  261. * @see PolygonGeometry#createGeometry
  262. */
  263. CoplanarPolygonGeometry.fromPositions = function (options) {
  264. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  265. //>>includeStart('debug', pragmas.debug);
  266. Check.Check.defined("options.positions", options.positions);
  267. //>>includeEnd('debug');
  268. const newOptions = {
  269. polygonHierarchy: {
  270. positions: options.positions,
  271. },
  272. vertexFormat: options.vertexFormat,
  273. stRotation: options.stRotation,
  274. ellipsoid: options.ellipsoid,
  275. textureCoordinates: options.textureCoordinates,
  276. };
  277. return new CoplanarPolygonGeometry(newOptions);
  278. };
  279. /**
  280. * Stores the provided instance into the provided array.
  281. *
  282. * @param {CoplanarPolygonGeometry} value The value to pack.
  283. * @param {number[]} array The array to pack into.
  284. * @param {number} [startingIndex=0] The index into the array at which to start packing the elements.
  285. *
  286. * @returns {number[]} The array that was packed into
  287. */
  288. CoplanarPolygonGeometry.pack = function (value, array, startingIndex) {
  289. //>>includeStart('debug', pragmas.debug);
  290. Check.Check.typeOf.object("value", value);
  291. Check.Check.defined("array", array);
  292. //>>includeEnd('debug');
  293. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  294. startingIndex = PolygonGeometryLibrary.PolygonGeometryLibrary.packPolygonHierarchy(
  295. value._polygonHierarchy,
  296. array,
  297. startingIndex,
  298. Matrix3.Cartesian3
  299. );
  300. Matrix3.Ellipsoid.pack(value._ellipsoid, array, startingIndex);
  301. startingIndex += Matrix3.Ellipsoid.packedLength;
  302. VertexFormat.VertexFormat.pack(value._vertexFormat, array, startingIndex);
  303. startingIndex += VertexFormat.VertexFormat.packedLength;
  304. array[startingIndex++] = value._stRotation;
  305. if (defaultValue.defined(value._textureCoordinates)) {
  306. startingIndex = PolygonGeometryLibrary.PolygonGeometryLibrary.packPolygonHierarchy(
  307. value._textureCoordinates,
  308. array,
  309. startingIndex,
  310. Matrix2.Cartesian2
  311. );
  312. } else {
  313. array[startingIndex++] = -1.0;
  314. }
  315. array[startingIndex++] = value.packedLength;
  316. return array;
  317. };
  318. const scratchEllipsoid = Matrix3.Ellipsoid.clone(Matrix3.Ellipsoid.UNIT_SPHERE);
  319. const scratchVertexFormat = new VertexFormat.VertexFormat();
  320. const scratchOptions = {
  321. polygonHierarchy: {},
  322. };
  323. /**
  324. * Retrieves an instance from a packed array.
  325. *
  326. * @param {number[]} array The packed array.
  327. * @param {number} [startingIndex=0] The starting index of the element to be unpacked.
  328. * @param {CoplanarPolygonGeometry} [result] The object into which to store the result.
  329. * @returns {CoplanarPolygonGeometry} The modified result parameter or a new CoplanarPolygonGeometry instance if one was not provided.
  330. */
  331. CoplanarPolygonGeometry.unpack = function (array, startingIndex, result) {
  332. //>>includeStart('debug', pragmas.debug);
  333. Check.Check.defined("array", array);
  334. //>>includeEnd('debug');
  335. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  336. const polygonHierarchy = PolygonGeometryLibrary.PolygonGeometryLibrary.unpackPolygonHierarchy(
  337. array,
  338. startingIndex,
  339. Matrix3.Cartesian3
  340. );
  341. startingIndex = polygonHierarchy.startingIndex;
  342. delete polygonHierarchy.startingIndex;
  343. const ellipsoid = Matrix3.Ellipsoid.unpack(array, startingIndex, scratchEllipsoid);
  344. startingIndex += Matrix3.Ellipsoid.packedLength;
  345. const vertexFormat = VertexFormat.VertexFormat.unpack(
  346. array,
  347. startingIndex,
  348. scratchVertexFormat
  349. );
  350. startingIndex += VertexFormat.VertexFormat.packedLength;
  351. const stRotation = array[startingIndex++];
  352. const textureCoordinates =
  353. array[startingIndex] === -1.0
  354. ? undefined
  355. : PolygonGeometryLibrary.PolygonGeometryLibrary.unpackPolygonHierarchy(
  356. array,
  357. startingIndex,
  358. Matrix2.Cartesian2
  359. );
  360. if (defaultValue.defined(textureCoordinates)) {
  361. startingIndex = textureCoordinates.startingIndex;
  362. delete textureCoordinates.startingIndex;
  363. } else {
  364. startingIndex++;
  365. }
  366. const packedLength = array[startingIndex++];
  367. if (!defaultValue.defined(result)) {
  368. result = new CoplanarPolygonGeometry(scratchOptions);
  369. }
  370. result._polygonHierarchy = polygonHierarchy;
  371. result._ellipsoid = Matrix3.Ellipsoid.clone(ellipsoid, result._ellipsoid);
  372. result._vertexFormat = VertexFormat.VertexFormat.clone(vertexFormat, result._vertexFormat);
  373. result._stRotation = stRotation;
  374. result._textureCoordinates = textureCoordinates;
  375. result.packedLength = packedLength;
  376. return result;
  377. };
  378. /**
  379. * Computes the geometric representation of an arbitrary coplanar polygon, including its vertices, indices, and a bounding sphere.
  380. *
  381. * @param {CoplanarPolygonGeometry} polygonGeometry A description of the polygon.
  382. * @returns {Geometry|undefined} The computed vertices and indices.
  383. */
  384. CoplanarPolygonGeometry.createGeometry = function (polygonGeometry) {
  385. const vertexFormat = polygonGeometry._vertexFormat;
  386. const polygonHierarchy = polygonGeometry._polygonHierarchy;
  387. const stRotation = polygonGeometry._stRotation;
  388. const textureCoordinates = polygonGeometry._textureCoordinates;
  389. const hasTextureCoordinates = defaultValue.defined(textureCoordinates);
  390. let outerPositions = polygonHierarchy.positions;
  391. outerPositions = arrayRemoveDuplicates.arrayRemoveDuplicates(
  392. outerPositions,
  393. Matrix3.Cartesian3.equalsEpsilon,
  394. true
  395. );
  396. if (outerPositions.length < 3) {
  397. return;
  398. }
  399. let normal = scratchNormal;
  400. let tangent = scratchTangent;
  401. let bitangent = scratchBitangent;
  402. let axis1 = axis1Scratch;
  403. const axis2 = axis2Scratch;
  404. const validGeometry = CoplanarPolygonGeometryLibrary.CoplanarPolygonGeometryLibrary.computeProjectTo2DArguments(
  405. outerPositions,
  406. centerScratch,
  407. axis1,
  408. axis2
  409. );
  410. if (!validGeometry) {
  411. return undefined;
  412. }
  413. normal = Matrix3.Cartesian3.cross(axis1, axis2, normal);
  414. normal = Matrix3.Cartesian3.normalize(normal, normal);
  415. if (
  416. !Matrix3.Cartesian3.equalsEpsilon(
  417. centerScratch,
  418. Matrix3.Cartesian3.ZERO,
  419. Math.CesiumMath.EPSILON6
  420. )
  421. ) {
  422. const surfaceNormal = polygonGeometry._ellipsoid.geodeticSurfaceNormal(
  423. centerScratch,
  424. surfaceNormalScratch
  425. );
  426. if (Matrix3.Cartesian3.dot(normal, surfaceNormal) < 0) {
  427. normal = Matrix3.Cartesian3.negate(normal, normal);
  428. axis1 = Matrix3.Cartesian3.negate(axis1, axis1);
  429. }
  430. }
  431. const projectPoints = CoplanarPolygonGeometryLibrary.CoplanarPolygonGeometryLibrary.createProjectPointsTo2DFunction(
  432. centerScratch,
  433. axis1,
  434. axis2
  435. );
  436. const projectPoint = CoplanarPolygonGeometryLibrary.CoplanarPolygonGeometryLibrary.createProjectPointTo2DFunction(
  437. centerScratch,
  438. axis1,
  439. axis2
  440. );
  441. if (vertexFormat.tangent) {
  442. tangent = Matrix3.Cartesian3.clone(axis1, tangent);
  443. }
  444. if (vertexFormat.bitangent) {
  445. bitangent = Matrix3.Cartesian3.clone(axis2, bitangent);
  446. }
  447. const results = PolygonGeometryLibrary.PolygonGeometryLibrary.polygonsFromHierarchy(
  448. polygonHierarchy,
  449. hasTextureCoordinates,
  450. projectPoints,
  451. false
  452. );
  453. const hierarchy = results.hierarchy;
  454. const polygons = results.polygons;
  455. const dummyFunction = function (identity) {
  456. return identity;
  457. };
  458. const textureCoordinatePolygons = hasTextureCoordinates
  459. ? PolygonGeometryLibrary.PolygonGeometryLibrary.polygonsFromHierarchy(
  460. textureCoordinates,
  461. true,
  462. dummyFunction,
  463. false
  464. ).polygons
  465. : undefined;
  466. if (hierarchy.length === 0) {
  467. return;
  468. }
  469. outerPositions = hierarchy[0].outerRing;
  470. const boundingSphere = Transforms.BoundingSphere.fromPoints(outerPositions);
  471. const boundingRectangle = PolygonGeometryLibrary.PolygonGeometryLibrary.computeBoundingRectangle(
  472. normal,
  473. projectPoint,
  474. outerPositions,
  475. stRotation,
  476. scratchBR
  477. );
  478. const geometries = [];
  479. for (let i = 0; i < polygons.length; i++) {
  480. const geometryInstance = new GeometryInstance.GeometryInstance({
  481. geometry: createGeometryFromPolygon(
  482. polygons[i],
  483. vertexFormat,
  484. boundingRectangle,
  485. stRotation,
  486. hasTextureCoordinates ? textureCoordinatePolygons[i] : undefined,
  487. projectPoint,
  488. normal,
  489. tangent,
  490. bitangent
  491. ),
  492. });
  493. geometries.push(geometryInstance);
  494. }
  495. const geometry = GeometryPipeline.GeometryPipeline.combineInstances(geometries)[0];
  496. geometry.attributes.position.values = new Float64Array(
  497. geometry.attributes.position.values
  498. );
  499. geometry.indices = IndexDatatype.IndexDatatype.createTypedArray(
  500. geometry.attributes.position.values.length / 3,
  501. geometry.indices
  502. );
  503. const attributes = geometry.attributes;
  504. if (!vertexFormat.position) {
  505. delete attributes.position;
  506. }
  507. return new GeometryAttribute.Geometry({
  508. attributes: attributes,
  509. indices: geometry.indices,
  510. primitiveType: geometry.primitiveType,
  511. boundingSphere: boundingSphere,
  512. });
  513. };
  514. function createCoplanarPolygonGeometry(polygonGeometry, offset) {
  515. if (defaultValue.defined(offset)) {
  516. polygonGeometry = CoplanarPolygonGeometry.unpack(polygonGeometry, offset);
  517. }
  518. return CoplanarPolygonGeometry.createGeometry(polygonGeometry);
  519. }
  520. return createCoplanarPolygonGeometry;
  521. }));