BoxGeometry-652222c8.js 33 KB

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