BoxGeometry-97fb4823.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910
  1. /**
  2. * @license
  3. * Cesium - https://github.com/CesiumGS/cesium
  4. * Version 1.95
  5. *
  6. * Copyright 2011-2022 Cesium Contributors
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *
  20. * Columbus View (Pat. Pend.)
  21. *
  22. * Portions licensed separately.
  23. * See https://github.com/CesiumGS/cesium/blob/main/LICENSE.md for full licensing details.
  24. */
  25. define(['exports', './Transforms-273eeb44', './Matrix2-9e1c22e2', './RuntimeError-4f8ec8a2', './ComponentDatatype-4eeb6d9b', './defaultValue-97284df2', './GeometryAttribute-9be2d2e5', './GeometryAttributes-734a3446', './GeometryOffsetAttribute-59b14f45', './VertexFormat-563ab2cc'], (function (exports, Transforms, Matrix2, RuntimeError, ComponentDatatype, defaultValue, GeometryAttribute, GeometryAttributes, GeometryOffsetAttribute, VertexFormat) { 'use strict';
  26. const diffScratch = new Matrix2.Cartesian3();
  27. /**
  28. * Describes a cube centered at the origin.
  29. *
  30. * @alias BoxGeometry
  31. * @constructor
  32. *
  33. * @param {Object} options Object with the following properties:
  34. * @param {Cartesian3} options.minimum The minimum x, y, and z coordinates of the box.
  35. * @param {Cartesian3} options.maximum The maximum x, y, and z coordinates of the box.
  36. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
  37. *
  38. * @see BoxGeometry.fromDimensions
  39. * @see BoxGeometry.createGeometry
  40. * @see Packable
  41. *
  42. * @demo {@link https://sandcastle.cesium.com/index.html?src=Box.html|Cesium Sandcastle Box Demo}
  43. *
  44. * @example
  45. * const box = new Cesium.BoxGeometry({
  46. * vertexFormat : Cesium.VertexFormat.POSITION_ONLY,
  47. * maximum : new Cesium.Cartesian3(250000.0, 250000.0, 250000.0),
  48. * minimum : new Cesium.Cartesian3(-250000.0, -250000.0, -250000.0)
  49. * });
  50. * const geometry = Cesium.BoxGeometry.createGeometry(box);
  51. */
  52. function BoxGeometry(options) {
  53. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  54. const min = options.minimum;
  55. const max = options.maximum;
  56. //>>includeStart('debug', pragmas.debug);
  57. RuntimeError.Check.typeOf.object("min", min);
  58. RuntimeError.Check.typeOf.object("max", max);
  59. if (
  60. defaultValue.defined(options.offsetAttribute) &&
  61. options.offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.TOP
  62. ) {
  63. throw new RuntimeError.DeveloperError(
  64. "GeometryOffsetAttribute.TOP is not a supported options.offsetAttribute for this geometry."
  65. );
  66. }
  67. //>>includeEnd('debug');
  68. const vertexFormat = defaultValue.defaultValue(options.vertexFormat, VertexFormat.VertexFormat.DEFAULT);
  69. this._minimum = Matrix2.Cartesian3.clone(min);
  70. this._maximum = Matrix2.Cartesian3.clone(max);
  71. this._vertexFormat = vertexFormat;
  72. this._offsetAttribute = options.offsetAttribute;
  73. this._workerName = "createBoxGeometry";
  74. }
  75. /**
  76. * Creates a cube centered at the origin given its dimensions.
  77. *
  78. * @param {Object} options Object with the following properties:
  79. * @param {Cartesian3} options.dimensions The width, depth, and height of the box stored in the x, y, and z coordinates of the <code>Cartesian3</code>, respectively.
  80. * @param {VertexFormat} [options.vertexFormat=VertexFormat.DEFAULT] The vertex attributes to be computed.
  81. * @returns {BoxGeometry}
  82. *
  83. * @exception {DeveloperError} All dimensions components must be greater than or equal to zero.
  84. *
  85. *
  86. * @example
  87. * const box = Cesium.BoxGeometry.fromDimensions({
  88. * vertexFormat : Cesium.VertexFormat.POSITION_ONLY,
  89. * dimensions : new Cesium.Cartesian3(500000.0, 500000.0, 500000.0)
  90. * });
  91. * const geometry = Cesium.BoxGeometry.createGeometry(box);
  92. *
  93. * @see BoxGeometry.createGeometry
  94. */
  95. BoxGeometry.fromDimensions = function (options) {
  96. options = defaultValue.defaultValue(options, defaultValue.defaultValue.EMPTY_OBJECT);
  97. const dimensions = options.dimensions;
  98. //>>includeStart('debug', pragmas.debug);
  99. RuntimeError.Check.typeOf.object("dimensions", dimensions);
  100. RuntimeError.Check.typeOf.number.greaterThanOrEquals("dimensions.x", dimensions.x, 0);
  101. RuntimeError.Check.typeOf.number.greaterThanOrEquals("dimensions.y", dimensions.y, 0);
  102. RuntimeError.Check.typeOf.number.greaterThanOrEquals("dimensions.z", dimensions.z, 0);
  103. //>>includeEnd('debug');
  104. const corner = Matrix2.Cartesian3.multiplyByScalar(dimensions, 0.5, new Matrix2.Cartesian3());
  105. return new BoxGeometry({
  106. minimum: Matrix2.Cartesian3.negate(corner, new Matrix2.Cartesian3()),
  107. maximum: corner,
  108. vertexFormat: options.vertexFormat,
  109. offsetAttribute: options.offsetAttribute,
  110. });
  111. };
  112. /**
  113. * Creates a cube from the dimensions of an AxisAlignedBoundingBox.
  114. *
  115. * @param {AxisAlignedBoundingBox} boundingBox A description of the AxisAlignedBoundingBox.
  116. * @returns {BoxGeometry}
  117. *
  118. *
  119. *
  120. * @example
  121. * const aabb = Cesium.AxisAlignedBoundingBox.fromPoints(Cesium.Cartesian3.fromDegreesArray([
  122. * -72.0, 40.0,
  123. * -70.0, 35.0,
  124. * -75.0, 30.0,
  125. * -70.0, 30.0,
  126. * -68.0, 40.0
  127. * ]));
  128. * const box = Cesium.BoxGeometry.fromAxisAlignedBoundingBox(aabb);
  129. *
  130. * @see BoxGeometry.createGeometry
  131. */
  132. BoxGeometry.fromAxisAlignedBoundingBox = function (boundingBox) {
  133. //>>includeStart('debug', pragmas.debug);
  134. RuntimeError.Check.typeOf.object("boundingBox", boundingBox);
  135. //>>includeEnd('debug');
  136. return new BoxGeometry({
  137. minimum: boundingBox.minimum,
  138. maximum: boundingBox.maximum,
  139. });
  140. };
  141. /**
  142. * The number of elements used to pack the object into an array.
  143. * @type {Number}
  144. */
  145. BoxGeometry.packedLength =
  146. 2 * Matrix2.Cartesian3.packedLength + VertexFormat.VertexFormat.packedLength + 1;
  147. /**
  148. * Stores the provided instance into the provided array.
  149. *
  150. * @param {BoxGeometry} value The value to pack.
  151. * @param {Number[]} array The array to pack into.
  152. * @param {Number} [startingIndex=0] The index into the array at which to start packing the elements.
  153. *
  154. * @returns {Number[]} The array that was packed into
  155. */
  156. BoxGeometry.pack = function (value, array, startingIndex) {
  157. //>>includeStart('debug', pragmas.debug);
  158. RuntimeError.Check.typeOf.object("value", value);
  159. RuntimeError.Check.defined("array", array);
  160. //>>includeEnd('debug');
  161. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  162. Matrix2.Cartesian3.pack(value._minimum, array, startingIndex);
  163. Matrix2.Cartesian3.pack(
  164. value._maximum,
  165. array,
  166. startingIndex + Matrix2.Cartesian3.packedLength
  167. );
  168. VertexFormat.VertexFormat.pack(
  169. value._vertexFormat,
  170. array,
  171. startingIndex + 2 * Matrix2.Cartesian3.packedLength
  172. );
  173. array[
  174. startingIndex + 2 * Matrix2.Cartesian3.packedLength + VertexFormat.VertexFormat.packedLength
  175. ] = defaultValue.defaultValue(value._offsetAttribute, -1);
  176. return array;
  177. };
  178. const scratchMin = new Matrix2.Cartesian3();
  179. const scratchMax = new Matrix2.Cartesian3();
  180. const scratchVertexFormat = new VertexFormat.VertexFormat();
  181. const scratchOptions = {
  182. minimum: scratchMin,
  183. maximum: scratchMax,
  184. vertexFormat: scratchVertexFormat,
  185. offsetAttribute: undefined,
  186. };
  187. /**
  188. * Retrieves an instance from a packed array.
  189. *
  190. * @param {Number[]} array The packed array.
  191. * @param {Number} [startingIndex=0] The starting index of the element to be unpacked.
  192. * @param {BoxGeometry} [result] The object into which to store the result.
  193. * @returns {BoxGeometry} The modified result parameter or a new BoxGeometry instance if one was not provided.
  194. */
  195. BoxGeometry.unpack = function (array, startingIndex, result) {
  196. //>>includeStart('debug', pragmas.debug);
  197. RuntimeError.Check.defined("array", array);
  198. //>>includeEnd('debug');
  199. startingIndex = defaultValue.defaultValue(startingIndex, 0);
  200. const min = Matrix2.Cartesian3.unpack(array, startingIndex, scratchMin);
  201. const max = Matrix2.Cartesian3.unpack(
  202. array,
  203. startingIndex + Matrix2.Cartesian3.packedLength,
  204. scratchMax
  205. );
  206. const vertexFormat = VertexFormat.VertexFormat.unpack(
  207. array,
  208. startingIndex + 2 * Matrix2.Cartesian3.packedLength,
  209. scratchVertexFormat
  210. );
  211. const offsetAttribute =
  212. array[
  213. startingIndex + 2 * Matrix2.Cartesian3.packedLength + VertexFormat.VertexFormat.packedLength
  214. ];
  215. if (!defaultValue.defined(result)) {
  216. scratchOptions.offsetAttribute =
  217. offsetAttribute === -1 ? undefined : offsetAttribute;
  218. return new BoxGeometry(scratchOptions);
  219. }
  220. result._minimum = Matrix2.Cartesian3.clone(min, result._minimum);
  221. result._maximum = Matrix2.Cartesian3.clone(max, result._maximum);
  222. result._vertexFormat = VertexFormat.VertexFormat.clone(vertexFormat, result._vertexFormat);
  223. result._offsetAttribute =
  224. offsetAttribute === -1 ? undefined : offsetAttribute;
  225. return result;
  226. };
  227. /**
  228. * Computes the geometric representation of a box, including its vertices, indices, and a bounding sphere.
  229. *
  230. * @param {BoxGeometry} boxGeometry A description of the box.
  231. * @returns {Geometry|undefined} The computed vertices and indices.
  232. */
  233. BoxGeometry.createGeometry = function (boxGeometry) {
  234. const min = boxGeometry._minimum;
  235. const max = boxGeometry._maximum;
  236. const vertexFormat = boxGeometry._vertexFormat;
  237. if (Matrix2.Cartesian3.equals(min, max)) {
  238. return;
  239. }
  240. const attributes = new GeometryAttributes.GeometryAttributes();
  241. let indices;
  242. let positions;
  243. if (
  244. vertexFormat.position &&
  245. (vertexFormat.st ||
  246. vertexFormat.normal ||
  247. vertexFormat.tangent ||
  248. vertexFormat.bitangent)
  249. ) {
  250. if (vertexFormat.position) {
  251. // 8 corner points. Duplicated 3 times each for each incident edge/face.
  252. positions = new Float64Array(6 * 4 * 3);
  253. // +z face
  254. positions[0] = min.x;
  255. positions[1] = min.y;
  256. positions[2] = max.z;
  257. positions[3] = max.x;
  258. positions[4] = min.y;
  259. positions[5] = max.z;
  260. positions[6] = max.x;
  261. positions[7] = max.y;
  262. positions[8] = max.z;
  263. positions[9] = min.x;
  264. positions[10] = max.y;
  265. positions[11] = max.z;
  266. // -z face
  267. positions[12] = min.x;
  268. positions[13] = min.y;
  269. positions[14] = min.z;
  270. positions[15] = max.x;
  271. positions[16] = min.y;
  272. positions[17] = min.z;
  273. positions[18] = max.x;
  274. positions[19] = max.y;
  275. positions[20] = min.z;
  276. positions[21] = min.x;
  277. positions[22] = max.y;
  278. positions[23] = min.z;
  279. // +x face
  280. positions[24] = max.x;
  281. positions[25] = min.y;
  282. positions[26] = min.z;
  283. positions[27] = max.x;
  284. positions[28] = max.y;
  285. positions[29] = min.z;
  286. positions[30] = max.x;
  287. positions[31] = max.y;
  288. positions[32] = max.z;
  289. positions[33] = max.x;
  290. positions[34] = min.y;
  291. positions[35] = max.z;
  292. // -x face
  293. positions[36] = min.x;
  294. positions[37] = min.y;
  295. positions[38] = min.z;
  296. positions[39] = min.x;
  297. positions[40] = max.y;
  298. positions[41] = min.z;
  299. positions[42] = min.x;
  300. positions[43] = max.y;
  301. positions[44] = max.z;
  302. positions[45] = min.x;
  303. positions[46] = min.y;
  304. positions[47] = max.z;
  305. // +y face
  306. positions[48] = min.x;
  307. positions[49] = max.y;
  308. positions[50] = min.z;
  309. positions[51] = max.x;
  310. positions[52] = max.y;
  311. positions[53] = min.z;
  312. positions[54] = max.x;
  313. positions[55] = max.y;
  314. positions[56] = max.z;
  315. positions[57] = min.x;
  316. positions[58] = max.y;
  317. positions[59] = max.z;
  318. // -y face
  319. positions[60] = min.x;
  320. positions[61] = min.y;
  321. positions[62] = min.z;
  322. positions[63] = max.x;
  323. positions[64] = min.y;
  324. positions[65] = min.z;
  325. positions[66] = max.x;
  326. positions[67] = min.y;
  327. positions[68] = max.z;
  328. positions[69] = min.x;
  329. positions[70] = min.y;
  330. positions[71] = max.z;
  331. attributes.position = new GeometryAttribute.GeometryAttribute({
  332. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  333. componentsPerAttribute: 3,
  334. values: positions,
  335. });
  336. }
  337. if (vertexFormat.normal) {
  338. const normals = new Float32Array(6 * 4 * 3);
  339. // +z face
  340. normals[0] = 0.0;
  341. normals[1] = 0.0;
  342. normals[2] = 1.0;
  343. normals[3] = 0.0;
  344. normals[4] = 0.0;
  345. normals[5] = 1.0;
  346. normals[6] = 0.0;
  347. normals[7] = 0.0;
  348. normals[8] = 1.0;
  349. normals[9] = 0.0;
  350. normals[10] = 0.0;
  351. normals[11] = 1.0;
  352. // -z face
  353. normals[12] = 0.0;
  354. normals[13] = 0.0;
  355. normals[14] = -1.0;
  356. normals[15] = 0.0;
  357. normals[16] = 0.0;
  358. normals[17] = -1.0;
  359. normals[18] = 0.0;
  360. normals[19] = 0.0;
  361. normals[20] = -1.0;
  362. normals[21] = 0.0;
  363. normals[22] = 0.0;
  364. normals[23] = -1.0;
  365. // +x face
  366. normals[24] = 1.0;
  367. normals[25] = 0.0;
  368. normals[26] = 0.0;
  369. normals[27] = 1.0;
  370. normals[28] = 0.0;
  371. normals[29] = 0.0;
  372. normals[30] = 1.0;
  373. normals[31] = 0.0;
  374. normals[32] = 0.0;
  375. normals[33] = 1.0;
  376. normals[34] = 0.0;
  377. normals[35] = 0.0;
  378. // -x face
  379. normals[36] = -1.0;
  380. normals[37] = 0.0;
  381. normals[38] = 0.0;
  382. normals[39] = -1.0;
  383. normals[40] = 0.0;
  384. normals[41] = 0.0;
  385. normals[42] = -1.0;
  386. normals[43] = 0.0;
  387. normals[44] = 0.0;
  388. normals[45] = -1.0;
  389. normals[46] = 0.0;
  390. normals[47] = 0.0;
  391. // +y face
  392. normals[48] = 0.0;
  393. normals[49] = 1.0;
  394. normals[50] = 0.0;
  395. normals[51] = 0.0;
  396. normals[52] = 1.0;
  397. normals[53] = 0.0;
  398. normals[54] = 0.0;
  399. normals[55] = 1.0;
  400. normals[56] = 0.0;
  401. normals[57] = 0.0;
  402. normals[58] = 1.0;
  403. normals[59] = 0.0;
  404. // -y face
  405. normals[60] = 0.0;
  406. normals[61] = -1.0;
  407. normals[62] = 0.0;
  408. normals[63] = 0.0;
  409. normals[64] = -1.0;
  410. normals[65] = 0.0;
  411. normals[66] = 0.0;
  412. normals[67] = -1.0;
  413. normals[68] = 0.0;
  414. normals[69] = 0.0;
  415. normals[70] = -1.0;
  416. normals[71] = 0.0;
  417. attributes.normal = new GeometryAttribute.GeometryAttribute({
  418. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  419. componentsPerAttribute: 3,
  420. values: normals,
  421. });
  422. }
  423. if (vertexFormat.st) {
  424. const texCoords = new Float32Array(6 * 4 * 2);
  425. // +z face
  426. texCoords[0] = 0.0;
  427. texCoords[1] = 0.0;
  428. texCoords[2] = 1.0;
  429. texCoords[3] = 0.0;
  430. texCoords[4] = 1.0;
  431. texCoords[5] = 1.0;
  432. texCoords[6] = 0.0;
  433. texCoords[7] = 1.0;
  434. // -z face
  435. texCoords[8] = 1.0;
  436. texCoords[9] = 0.0;
  437. texCoords[10] = 0.0;
  438. texCoords[11] = 0.0;
  439. texCoords[12] = 0.0;
  440. texCoords[13] = 1.0;
  441. texCoords[14] = 1.0;
  442. texCoords[15] = 1.0;
  443. //+x face
  444. texCoords[16] = 0.0;
  445. texCoords[17] = 0.0;
  446. texCoords[18] = 1.0;
  447. texCoords[19] = 0.0;
  448. texCoords[20] = 1.0;
  449. texCoords[21] = 1.0;
  450. texCoords[22] = 0.0;
  451. texCoords[23] = 1.0;
  452. // -x face
  453. texCoords[24] = 1.0;
  454. texCoords[25] = 0.0;
  455. texCoords[26] = 0.0;
  456. texCoords[27] = 0.0;
  457. texCoords[28] = 0.0;
  458. texCoords[29] = 1.0;
  459. texCoords[30] = 1.0;
  460. texCoords[31] = 1.0;
  461. // +y face
  462. texCoords[32] = 1.0;
  463. texCoords[33] = 0.0;
  464. texCoords[34] = 0.0;
  465. texCoords[35] = 0.0;
  466. texCoords[36] = 0.0;
  467. texCoords[37] = 1.0;
  468. texCoords[38] = 1.0;
  469. texCoords[39] = 1.0;
  470. // -y face
  471. texCoords[40] = 0.0;
  472. texCoords[41] = 0.0;
  473. texCoords[42] = 1.0;
  474. texCoords[43] = 0.0;
  475. texCoords[44] = 1.0;
  476. texCoords[45] = 1.0;
  477. texCoords[46] = 0.0;
  478. texCoords[47] = 1.0;
  479. attributes.st = new GeometryAttribute.GeometryAttribute({
  480. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  481. componentsPerAttribute: 2,
  482. values: texCoords,
  483. });
  484. }
  485. if (vertexFormat.tangent) {
  486. const tangents = new Float32Array(6 * 4 * 3);
  487. // +z face
  488. tangents[0] = 1.0;
  489. tangents[1] = 0.0;
  490. tangents[2] = 0.0;
  491. tangents[3] = 1.0;
  492. tangents[4] = 0.0;
  493. tangents[5] = 0.0;
  494. tangents[6] = 1.0;
  495. tangents[7] = 0.0;
  496. tangents[8] = 0.0;
  497. tangents[9] = 1.0;
  498. tangents[10] = 0.0;
  499. tangents[11] = 0.0;
  500. // -z face
  501. tangents[12] = -1.0;
  502. tangents[13] = 0.0;
  503. tangents[14] = 0.0;
  504. tangents[15] = -1.0;
  505. tangents[16] = 0.0;
  506. tangents[17] = 0.0;
  507. tangents[18] = -1.0;
  508. tangents[19] = 0.0;
  509. tangents[20] = 0.0;
  510. tangents[21] = -1.0;
  511. tangents[22] = 0.0;
  512. tangents[23] = 0.0;
  513. // +x face
  514. tangents[24] = 0.0;
  515. tangents[25] = 1.0;
  516. tangents[26] = 0.0;
  517. tangents[27] = 0.0;
  518. tangents[28] = 1.0;
  519. tangents[29] = 0.0;
  520. tangents[30] = 0.0;
  521. tangents[31] = 1.0;
  522. tangents[32] = 0.0;
  523. tangents[33] = 0.0;
  524. tangents[34] = 1.0;
  525. tangents[35] = 0.0;
  526. // -x face
  527. tangents[36] = 0.0;
  528. tangents[37] = -1.0;
  529. tangents[38] = 0.0;
  530. tangents[39] = 0.0;
  531. tangents[40] = -1.0;
  532. tangents[41] = 0.0;
  533. tangents[42] = 0.0;
  534. tangents[43] = -1.0;
  535. tangents[44] = 0.0;
  536. tangents[45] = 0.0;
  537. tangents[46] = -1.0;
  538. tangents[47] = 0.0;
  539. // +y face
  540. tangents[48] = -1.0;
  541. tangents[49] = 0.0;
  542. tangents[50] = 0.0;
  543. tangents[51] = -1.0;
  544. tangents[52] = 0.0;
  545. tangents[53] = 0.0;
  546. tangents[54] = -1.0;
  547. tangents[55] = 0.0;
  548. tangents[56] = 0.0;
  549. tangents[57] = -1.0;
  550. tangents[58] = 0.0;
  551. tangents[59] = 0.0;
  552. // -y face
  553. tangents[60] = 1.0;
  554. tangents[61] = 0.0;
  555. tangents[62] = 0.0;
  556. tangents[63] = 1.0;
  557. tangents[64] = 0.0;
  558. tangents[65] = 0.0;
  559. tangents[66] = 1.0;
  560. tangents[67] = 0.0;
  561. tangents[68] = 0.0;
  562. tangents[69] = 1.0;
  563. tangents[70] = 0.0;
  564. tangents[71] = 0.0;
  565. attributes.tangent = new GeometryAttribute.GeometryAttribute({
  566. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  567. componentsPerAttribute: 3,
  568. values: tangents,
  569. });
  570. }
  571. if (vertexFormat.bitangent) {
  572. const bitangents = new Float32Array(6 * 4 * 3);
  573. // +z face
  574. bitangents[0] = 0.0;
  575. bitangents[1] = 1.0;
  576. bitangents[2] = 0.0;
  577. bitangents[3] = 0.0;
  578. bitangents[4] = 1.0;
  579. bitangents[5] = 0.0;
  580. bitangents[6] = 0.0;
  581. bitangents[7] = 1.0;
  582. bitangents[8] = 0.0;
  583. bitangents[9] = 0.0;
  584. bitangents[10] = 1.0;
  585. bitangents[11] = 0.0;
  586. // -z face
  587. bitangents[12] = 0.0;
  588. bitangents[13] = 1.0;
  589. bitangents[14] = 0.0;
  590. bitangents[15] = 0.0;
  591. bitangents[16] = 1.0;
  592. bitangents[17] = 0.0;
  593. bitangents[18] = 0.0;
  594. bitangents[19] = 1.0;
  595. bitangents[20] = 0.0;
  596. bitangents[21] = 0.0;
  597. bitangents[22] = 1.0;
  598. bitangents[23] = 0.0;
  599. // +x face
  600. bitangents[24] = 0.0;
  601. bitangents[25] = 0.0;
  602. bitangents[26] = 1.0;
  603. bitangents[27] = 0.0;
  604. bitangents[28] = 0.0;
  605. bitangents[29] = 1.0;
  606. bitangents[30] = 0.0;
  607. bitangents[31] = 0.0;
  608. bitangents[32] = 1.0;
  609. bitangents[33] = 0.0;
  610. bitangents[34] = 0.0;
  611. bitangents[35] = 1.0;
  612. // -x face
  613. bitangents[36] = 0.0;
  614. bitangents[37] = 0.0;
  615. bitangents[38] = 1.0;
  616. bitangents[39] = 0.0;
  617. bitangents[40] = 0.0;
  618. bitangents[41] = 1.0;
  619. bitangents[42] = 0.0;
  620. bitangents[43] = 0.0;
  621. bitangents[44] = 1.0;
  622. bitangents[45] = 0.0;
  623. bitangents[46] = 0.0;
  624. bitangents[47] = 1.0;
  625. // +y face
  626. bitangents[48] = 0.0;
  627. bitangents[49] = 0.0;
  628. bitangents[50] = 1.0;
  629. bitangents[51] = 0.0;
  630. bitangents[52] = 0.0;
  631. bitangents[53] = 1.0;
  632. bitangents[54] = 0.0;
  633. bitangents[55] = 0.0;
  634. bitangents[56] = 1.0;
  635. bitangents[57] = 0.0;
  636. bitangents[58] = 0.0;
  637. bitangents[59] = 1.0;
  638. // -y face
  639. bitangents[60] = 0.0;
  640. bitangents[61] = 0.0;
  641. bitangents[62] = 1.0;
  642. bitangents[63] = 0.0;
  643. bitangents[64] = 0.0;
  644. bitangents[65] = 1.0;
  645. bitangents[66] = 0.0;
  646. bitangents[67] = 0.0;
  647. bitangents[68] = 1.0;
  648. bitangents[69] = 0.0;
  649. bitangents[70] = 0.0;
  650. bitangents[71] = 1.0;
  651. attributes.bitangent = new GeometryAttribute.GeometryAttribute({
  652. componentDatatype: ComponentDatatype.ComponentDatatype.FLOAT,
  653. componentsPerAttribute: 3,
  654. values: bitangents,
  655. });
  656. }
  657. // 12 triangles: 6 faces, 2 triangles each.
  658. indices = new Uint16Array(6 * 2 * 3);
  659. // +z face
  660. indices[0] = 0;
  661. indices[1] = 1;
  662. indices[2] = 2;
  663. indices[3] = 0;
  664. indices[4] = 2;
  665. indices[5] = 3;
  666. // -z face
  667. indices[6] = 4 + 2;
  668. indices[7] = 4 + 1;
  669. indices[8] = 4 + 0;
  670. indices[9] = 4 + 3;
  671. indices[10] = 4 + 2;
  672. indices[11] = 4 + 0;
  673. // +x face
  674. indices[12] = 8 + 0;
  675. indices[13] = 8 + 1;
  676. indices[14] = 8 + 2;
  677. indices[15] = 8 + 0;
  678. indices[16] = 8 + 2;
  679. indices[17] = 8 + 3;
  680. // -x face
  681. indices[18] = 12 + 2;
  682. indices[19] = 12 + 1;
  683. indices[20] = 12 + 0;
  684. indices[21] = 12 + 3;
  685. indices[22] = 12 + 2;
  686. indices[23] = 12 + 0;
  687. // +y face
  688. indices[24] = 16 + 2;
  689. indices[25] = 16 + 1;
  690. indices[26] = 16 + 0;
  691. indices[27] = 16 + 3;
  692. indices[28] = 16 + 2;
  693. indices[29] = 16 + 0;
  694. // -y face
  695. indices[30] = 20 + 0;
  696. indices[31] = 20 + 1;
  697. indices[32] = 20 + 2;
  698. indices[33] = 20 + 0;
  699. indices[34] = 20 + 2;
  700. indices[35] = 20 + 3;
  701. } else {
  702. // Positions only - no need to duplicate corner points
  703. positions = new Float64Array(8 * 3);
  704. positions[0] = min.x;
  705. positions[1] = min.y;
  706. positions[2] = min.z;
  707. positions[3] = max.x;
  708. positions[4] = min.y;
  709. positions[5] = min.z;
  710. positions[6] = max.x;
  711. positions[7] = max.y;
  712. positions[8] = min.z;
  713. positions[9] = min.x;
  714. positions[10] = max.y;
  715. positions[11] = min.z;
  716. positions[12] = min.x;
  717. positions[13] = min.y;
  718. positions[14] = max.z;
  719. positions[15] = max.x;
  720. positions[16] = min.y;
  721. positions[17] = max.z;
  722. positions[18] = max.x;
  723. positions[19] = max.y;
  724. positions[20] = max.z;
  725. positions[21] = min.x;
  726. positions[22] = max.y;
  727. positions[23] = max.z;
  728. attributes.position = new GeometryAttribute.GeometryAttribute({
  729. componentDatatype: ComponentDatatype.ComponentDatatype.DOUBLE,
  730. componentsPerAttribute: 3,
  731. values: positions,
  732. });
  733. // 12 triangles: 6 faces, 2 triangles each.
  734. indices = new Uint16Array(6 * 2 * 3);
  735. // plane z = corner.Z
  736. indices[0] = 4;
  737. indices[1] = 5;
  738. indices[2] = 6;
  739. indices[3] = 4;
  740. indices[4] = 6;
  741. indices[5] = 7;
  742. // plane z = -corner.Z
  743. indices[6] = 1;
  744. indices[7] = 0;
  745. indices[8] = 3;
  746. indices[9] = 1;
  747. indices[10] = 3;
  748. indices[11] = 2;
  749. // plane x = corner.X
  750. indices[12] = 1;
  751. indices[13] = 6;
  752. indices[14] = 5;
  753. indices[15] = 1;
  754. indices[16] = 2;
  755. indices[17] = 6;
  756. // plane y = corner.Y
  757. indices[18] = 2;
  758. indices[19] = 3;
  759. indices[20] = 7;
  760. indices[21] = 2;
  761. indices[22] = 7;
  762. indices[23] = 6;
  763. // plane x = -corner.X
  764. indices[24] = 3;
  765. indices[25] = 0;
  766. indices[26] = 4;
  767. indices[27] = 3;
  768. indices[28] = 4;
  769. indices[29] = 7;
  770. // plane y = -corner.Y
  771. indices[30] = 0;
  772. indices[31] = 1;
  773. indices[32] = 5;
  774. indices[33] = 0;
  775. indices[34] = 5;
  776. indices[35] = 4;
  777. }
  778. const diff = Matrix2.Cartesian3.subtract(max, min, diffScratch);
  779. const radius = Matrix2.Cartesian3.magnitude(diff) * 0.5;
  780. if (defaultValue.defined(boxGeometry._offsetAttribute)) {
  781. const length = positions.length;
  782. const offsetValue =
  783. boxGeometry._offsetAttribute === GeometryOffsetAttribute.GeometryOffsetAttribute.NONE ? 0 : 1;
  784. const applyOffset = new Uint8Array(length / 3).fill(offsetValue);
  785. attributes.applyOffset = new GeometryAttribute.GeometryAttribute({
  786. componentDatatype: ComponentDatatype.ComponentDatatype.UNSIGNED_BYTE,
  787. componentsPerAttribute: 1,
  788. values: applyOffset,
  789. });
  790. }
  791. return new GeometryAttribute.Geometry({
  792. attributes: attributes,
  793. indices: indices,
  794. primitiveType: GeometryAttribute.PrimitiveType.TRIANGLES,
  795. boundingSphere: new Transforms.BoundingSphere(Matrix2.Cartesian3.ZERO, radius),
  796. offsetAttribute: boxGeometry._offsetAttribute,
  797. });
  798. };
  799. let unitBoxGeometry;
  800. /**
  801. * Returns the geometric representation of a unit box, including its vertices, indices, and a bounding sphere.
  802. * @returns {Geometry} The computed vertices and indices.
  803. *
  804. * @private
  805. */
  806. BoxGeometry.getUnitBox = function () {
  807. if (!defaultValue.defined(unitBoxGeometry)) {
  808. unitBoxGeometry = BoxGeometry.createGeometry(
  809. BoxGeometry.fromDimensions({
  810. dimensions: new Matrix2.Cartesian3(1.0, 1.0, 1.0),
  811. vertexFormat: VertexFormat.VertexFormat.POSITION_ONLY,
  812. })
  813. );
  814. }
  815. return unitBoxGeometry;
  816. };
  817. exports.BoxGeometry = BoxGeometry;
  818. }));
  819. //# sourceMappingURL=BoxGeometry-97fb4823.js.map