createCoplanarPolygonGeometry.js 21 KB

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