BoxGeometry-7eb1af60.js 26 KB

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