All files / engine/Source/Core BoxGeometry.js

98.28% Statements 517/526
78.72% Branches 37/47
85.71% Functions 6/7
98.28% Lines 517/526

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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