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 | 527x 527x 527x 5x 5x 5x 2x 2x 527x 477x 516x 514x 50x 640x 640x 640x 640x 640x 640x 871095x 527x 527x 569x 569x 492x 77x 74x 74x 528x 528x 528x 528x 528x 528x 528x 528x 528x 528x 525x 525x 528x 43x 1x 527x 527x 475x 512x 510x 527x 527x 527x 527x 527x 578x 578x 578x 527x 1701x 553x 553x 553x 553x 527x 553x 553x 51x 178x 48x 578x 574x 527x 527x 527x 527x 578x 578x 527x 527x 156x 156x 102x 102x 102x 102x 54x 54x 54x 156x 156x 165x 165x 165x 108x 57x 57x 2x 2x 57x 57x 52x 52x 52x 52x 52x 1x 1x 528x 528x 528x 528x 528x 527x 524x 524x 52x 527x 2x 2x 527x 527x 527x 569x 569x 569x 492x 492x 492x 2x 569x 569x 569x 74x 74x 74x 527x 2x 2x 2x 3x 3x 3x 3x 3x 3x 18x 7x 7x 2x 1x 2x 2x 2x 2x 2x 2x 2x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 18x 7x 7x 4x 4x 3x 3x 7x 7x 7x 7x 7x 7x 7x 7x 7x 3x 3x 3x 2x 2x 2x 2x 1x 2x 2x 2x 2x 2x 2x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 7x 7x 7x 7x 7x 7x 7x 390x 7x 3x 3x 2x 2x 2x 72x 3x 2x 114x 114x 114x 114x 114x 128x 128x 128x 128x 128x 114x 114x 1x 114x 114x 114x 128x 114x 1x 228x 228x 228x 228x 256x 124x 256x 256x 228x 1x 1x 114x | import BoundingSphere from "../Core/BoundingSphere.js";
import ComponentDatatype from "../Core/ComponentDatatype.js";
import defined from "../Core/defined.js";
import DeveloperError from "../Core/DeveloperError.js";
import Ellipsoid from "../Core/Ellipsoid.js";
import GeographicProjection from "../Core/GeographicProjection.js";
import Geometry from "../Core/Geometry.js";
import GeometryAttribute from "../Core/GeometryAttribute.js";
import GeometryAttributes from "../Core/GeometryAttributes.js";
import GeometryPipeline from "../Core/GeometryPipeline.js";
import IndexDatatype from "../Core/IndexDatatype.js";
import Matrix4 from "../Core/Matrix4.js";
import OffsetGeometryInstanceAttribute from "../Core/OffsetGeometryInstanceAttribute.js";
import WebMercatorProjection from "../Core/WebMercatorProjection.js";
function transformToWorldCoordinates(
instances,
primitiveModelMatrix,
scene3DOnly,
) {
let toWorld = !scene3DOnly;
const length = instances.length;
let i;
if (!toWorld && length > 1) {
const modelMatrix = instances[0].modelMatrix;
for (i = 1; i < length; ++i) {
if (!Matrix4.equals(modelMatrix, instances[i].modelMatrix)) {
toWorld = true;
break;
}
}
}
if (toWorld) {
for (i = 0; i < length; ++i) {
if (defined(instances[i].geometry)) {
GeometryPipeline.transformToWorldCoordinates(instances[i]);
}
}
} else {
// Leave geometry in local coordinate system; auto update model-matrix.
Matrix4.multiplyTransformation(
primitiveModelMatrix,
instances[0].modelMatrix,
primitiveModelMatrix,
);
}
}
function addGeometryBatchId(geometry, batchId) {
const attributes = geometry.attributes;
const positionAttr = attributes.position;
const numberOfComponents =
positionAttr.values.length / positionAttr.componentsPerAttribute;
attributes.batchId = new GeometryAttribute({
componentDatatype: ComponentDatatype.FLOAT,
componentsPerAttribute: 1,
values: new Float32Array(numberOfComponents),
});
const values = attributes.batchId.values;
for (let j = 0; j < numberOfComponents; ++j) {
values[j] = batchId;
}
}
function addBatchIds(instances) {
const length = instances.length;
for (let i = 0; i < length; ++i) {
const instance = instances[i];
if (defined(instance.geometry)) {
addGeometryBatchId(instance.geometry, i);
} else if (
defined(instance.westHemisphereGeometry) &&
defined(instance.eastHemisphereGeometry)
) {
addGeometryBatchId(instance.westHemisphereGeometry, i);
addGeometryBatchId(instance.eastHemisphereGeometry, i);
}
}
}
function geometryPipeline(parameters) {
const instances = parameters.instances;
const projection = parameters.projection;
const uintIndexSupport = parameters.elementIndexUintSupported;
const scene3DOnly = parameters.scene3DOnly;
const vertexCacheOptimize = parameters.vertexCacheOptimize;
const compressVertices = parameters.compressVertices;
const modelMatrix = parameters.modelMatrix;
let i;
let geometry;
let primitiveType;
let length = instances.length;
for (i = 0; i < length; ++i) {
if (defined(instances[i].geometry)) {
primitiveType = instances[i].geometry.primitiveType;
break;
}
}
//>>includeStart('debug', pragmas.debug);
for (i = 1; i < length; ++i) {
if (
defined(instances[i].geometry) &&
instances[i].geometry.primitiveType !== primitiveType
) {
throw new DeveloperError(
"All instance geometries must have the same primitiveType.",
);
}
}
//>>includeEnd('debug');
// Unify to world coordinates before combining.
transformToWorldCoordinates(instances, modelMatrix, scene3DOnly);
// Clip to IDL
if (!scene3DOnly) {
for (i = 0; i < length; ++i) {
if (defined(instances[i].geometry)) {
GeometryPipeline.splitLongitude(instances[i]);
}
}
}
addBatchIds(instances);
// Optimize for vertex shader caches
Iif (vertexCacheOptimize) {
for (i = 0; i < length; ++i) {
const instance = instances[i];
if (defined(instance.geometry)) {
GeometryPipeline.reorderForPostVertexCache(instance.geometry);
GeometryPipeline.reorderForPreVertexCache(instance.geometry);
} else if (
defined(instance.westHemisphereGeometry) &&
defined(instance.eastHemisphereGeometry)
) {
GeometryPipeline.reorderForPostVertexCache(
instance.westHemisphereGeometry,
);
GeometryPipeline.reorderForPreVertexCache(
instance.westHemisphereGeometry,
);
GeometryPipeline.reorderForPostVertexCache(
instance.eastHemisphereGeometry,
);
GeometryPipeline.reorderForPreVertexCache(
instance.eastHemisphereGeometry,
);
}
}
}
// Combine into single geometry for better rendering performance.
let geometries = GeometryPipeline.combineInstances(instances);
length = geometries.length;
for (i = 0; i < length; ++i) {
geometry = geometries[i];
// Split positions for GPU RTE
const attributes = geometry.attributes;
if (!scene3DOnly) {
for (const name in attributes) {
if (
attributes.hasOwnProperty(name) &&
attributes[name].componentDatatype === ComponentDatatype.DOUBLE
) {
const name3D = `${name}3D`;
const name2D = `${name}2D`;
// Compute 2D positions
GeometryPipeline.projectTo2D(
geometry,
name,
name3D,
name2D,
projection,
);
if (defined(geometry.boundingSphere) && name === "position") {
geometry.boundingSphereCV = BoundingSphere.fromVertices(
geometry.attributes.position2D.values,
);
}
GeometryPipeline.encodeAttribute(
geometry,
name3D,
`${name3D}High`,
`${name3D}Low`,
);
GeometryPipeline.encodeAttribute(
geometry,
name2D,
`${name2D}High`,
`${name2D}Low`,
);
}
}
} else {
for (const name in attributes) {
if (
attributes.hasOwnProperty(name) &&
attributes[name].componentDatatype === ComponentDatatype.DOUBLE
) {
GeometryPipeline.encodeAttribute(
geometry,
name,
`${name}3DHigh`,
`${name}3DLow`,
);
}
}
}
// oct encode and pack normals, compress texture coordinates
if (compressVertices) {
GeometryPipeline.compressVertices(geometry);
}
}
Eif (!uintIndexSupport) {
// Break into multiple geometries to fit within unsigned short indices if needed
let splitGeometries = [];
length = geometries.length;
for (i = 0; i < length; ++i) {
geometry = geometries[i];
splitGeometries = splitGeometries.concat(
GeometryPipeline.fitToUnsignedShortIndices(geometry),
);
}
geometries = splitGeometries;
}
return geometries;
}
function createPickOffsets(instances, geometryName, geometries, pickOffsets) {
let offset;
let indexCount;
let geometryIndex;
const offsetIndex = pickOffsets.length - 1;
if (offsetIndex >= 0) {
const pickOffset = pickOffsets[offsetIndex];
offset = pickOffset.offset + pickOffset.count;
geometryIndex = pickOffset.index;
indexCount = geometries[geometryIndex].indices.length;
} else {
offset = 0;
geometryIndex = 0;
indexCount = geometries[geometryIndex].indices.length;
}
const length = instances.length;
for (let i = 0; i < length; ++i) {
const instance = instances[i];
const geometry = instance[geometryName];
if (!defined(geometry)) {
continue;
}
const count = geometry.indices.length;
if (offset + count > indexCount) {
offset = 0;
indexCount = geometries[++geometryIndex].indices.length;
}
pickOffsets.push({
index: geometryIndex,
offset: offset,
count: count,
});
offset += count;
}
}
function createInstancePickOffsets(instances, geometries) {
const pickOffsets = [];
createPickOffsets(instances, "geometry", geometries, pickOffsets);
createPickOffsets(
instances,
"westHemisphereGeometry",
geometries,
pickOffsets,
);
createPickOffsets(
instances,
"eastHemisphereGeometry",
geometries,
pickOffsets,
);
return pickOffsets;
}
/**
* @private
*/
const PrimitivePipeline = {};
/**
* @private
*/
PrimitivePipeline.combineGeometry = function (parameters) {
let geometries;
let attributeLocations;
const instances = parameters.instances;
const length = instances.length;
let pickOffsets;
let offsetInstanceExtend;
let hasOffset = false;
Eif (length > 0) {
geometries = geometryPipeline(parameters);
if (geometries.length > 0) {
attributeLocations = GeometryPipeline.createAttributeLocations(
geometries[0],
);
if (parameters.createPickOffsets) {
pickOffsets = createInstancePickOffsets(instances, geometries);
}
}
if (
defined(instances[0].attributes) &&
defined(instances[0].attributes.offset)
) {
offsetInstanceExtend = new Array(length);
hasOffset = true;
}
}
const boundingSpheres = new Array(length);
const boundingSpheresCV = new Array(length);
for (let i = 0; i < length; ++i) {
const instance = instances[i];
const geometry = instance.geometry;
if (defined(geometry)) {
boundingSpheres[i] = geometry.boundingSphere;
boundingSpheresCV[i] = geometry.boundingSphereCV;
if (hasOffset) {
offsetInstanceExtend[i] = instance.geometry.offsetAttribute;
}
}
const eastHemisphereGeometry = instance.eastHemisphereGeometry;
const westHemisphereGeometry = instance.westHemisphereGeometry;
if (defined(eastHemisphereGeometry) && defined(westHemisphereGeometry)) {
Eif (
defined(eastHemisphereGeometry.boundingSphere) &&
defined(westHemisphereGeometry.boundingSphere)
) {
boundingSpheres[i] = BoundingSphere.union(
eastHemisphereGeometry.boundingSphere,
westHemisphereGeometry.boundingSphere,
);
}
Iif (
defined(eastHemisphereGeometry.boundingSphereCV) &&
defined(westHemisphereGeometry.boundingSphereCV)
) {
boundingSpheresCV[i] = BoundingSphere.union(
eastHemisphereGeometry.boundingSphereCV,
westHemisphereGeometry.boundingSphereCV,
);
}
}
}
return {
geometries: geometries,
modelMatrix: parameters.modelMatrix,
attributeLocations: attributeLocations,
pickOffsets: pickOffsets,
offsetInstanceExtend: offsetInstanceExtend,
boundingSpheres: boundingSpheres,
boundingSpheresCV: boundingSpheresCV,
};
};
function transferGeometry(geometry, transferableObjects) {
const attributes = geometry.attributes;
for (const name in attributes) {
if (attributes.hasOwnProperty(name)) {
const attribute = attributes[name];
if (defined(attribute) && defined(attribute.values)) {
transferableObjects.push(attribute.values.buffer);
}
}
}
if (defined(geometry.indices)) {
transferableObjects.push(geometry.indices.buffer);
}
}
function transferGeometries(geometries, transferableObjects) {
const length = geometries.length;
for (let i = 0; i < length; ++i) {
transferGeometry(geometries[i], transferableObjects);
}
}
// This function was created by simplifying packCreateGeometryResults into a count-only operation.
function countCreateGeometryResults(items) {
let count = 1;
const length = items.length;
for (let i = 0; i < length; i++) {
const geometry = items[i];
++count;
Iif (!defined(geometry)) {
continue;
}
const attributes = geometry.attributes;
count +=
7 +
2 * BoundingSphere.packedLength +
(defined(geometry.indices) ? geometry.indices.length : 0);
for (const property in attributes) {
if (
attributes.hasOwnProperty(property) &&
defined(attributes[property])
) {
const attribute = attributes[property];
count += 5 + attribute.values.length;
}
}
}
return count;
}
/**
* @private
*/
PrimitivePipeline.packCreateGeometryResults = function (
items,
transferableObjects,
) {
const packedData = new Float64Array(countCreateGeometryResults(items));
const stringTable = [];
const stringHash = {};
const length = items.length;
let count = 0;
packedData[count++] = length;
for (let i = 0; i < length; i++) {
const geometry = items[i];
const validGeometry = defined(geometry);
packedData[count++] = validGeometry ? 1.0 : 0.0;
Iif (!validGeometry) {
continue;
}
packedData[count++] = geometry.primitiveType;
packedData[count++] = geometry.geometryType;
packedData[count++] = geometry.offsetAttribute ?? -1;
const validBoundingSphere = defined(geometry.boundingSphere) ? 1.0 : 0.0;
packedData[count++] = validBoundingSphere;
Eif (validBoundingSphere) {
BoundingSphere.pack(geometry.boundingSphere, packedData, count);
}
count += BoundingSphere.packedLength;
const validBoundingSphereCV = defined(geometry.boundingSphereCV)
? 1.0
: 0.0;
packedData[count++] = validBoundingSphereCV;
Iif (validBoundingSphereCV) {
BoundingSphere.pack(geometry.boundingSphereCV, packedData, count);
}
count += BoundingSphere.packedLength;
const attributes = geometry.attributes;
const attributesToWrite = [];
for (const property in attributes) {
if (
attributes.hasOwnProperty(property) &&
defined(attributes[property])
) {
attributesToWrite.push(property);
if (!defined(stringHash[property])) {
stringHash[property] = stringTable.length;
stringTable.push(property);
}
}
}
packedData[count++] = attributesToWrite.length;
for (let q = 0; q < attributesToWrite.length; q++) {
const name = attributesToWrite[q];
const attribute = attributes[name];
packedData[count++] = stringHash[name];
packedData[count++] = attribute.componentDatatype;
packedData[count++] = attribute.componentsPerAttribute;
packedData[count++] = attribute.normalize ? 1 : 0;
packedData[count++] = attribute.values.length;
packedData.set(attribute.values, count);
count += attribute.values.length;
}
const indicesLength = defined(geometry.indices)
? geometry.indices.length
: 0;
packedData[count++] = indicesLength;
if (indicesLength > 0) {
packedData.set(geometry.indices, count);
count += indicesLength;
}
}
transferableObjects.push(packedData.buffer);
return {
stringTable: stringTable,
packedData: packedData,
};
};
/**
* @private
*/
PrimitivePipeline.unpackCreateGeometryResults = function (
createGeometryResult,
) {
const stringTable = createGeometryResult.stringTable;
const packedGeometry = createGeometryResult.packedData;
let i;
const result = new Array(packedGeometry[0]);
let resultIndex = 0;
let packedGeometryIndex = 1;
while (packedGeometryIndex < packedGeometry.length) {
const valid = packedGeometry[packedGeometryIndex++] === 1.0;
Iif (!valid) {
result[resultIndex++] = undefined;
continue;
}
const primitiveType = packedGeometry[packedGeometryIndex++];
const geometryType = packedGeometry[packedGeometryIndex++];
let offsetAttribute = packedGeometry[packedGeometryIndex++];
Eif (offsetAttribute === -1) {
offsetAttribute = undefined;
}
let boundingSphere;
let boundingSphereCV;
const validBoundingSphere = packedGeometry[packedGeometryIndex++] === 1.0;
Eif (validBoundingSphere) {
boundingSphere = BoundingSphere.unpack(
packedGeometry,
packedGeometryIndex,
);
}
packedGeometryIndex += BoundingSphere.packedLength;
const validBoundingSphereCV = packedGeometry[packedGeometryIndex++] === 1.0;
Iif (validBoundingSphereCV) {
boundingSphereCV = BoundingSphere.unpack(
packedGeometry,
packedGeometryIndex,
);
}
packedGeometryIndex += BoundingSphere.packedLength;
let length;
let values;
let componentsPerAttribute;
const attributes = new GeometryAttributes();
const numAttributes = packedGeometry[packedGeometryIndex++];
for (i = 0; i < numAttributes; i++) {
const name = stringTable[packedGeometry[packedGeometryIndex++]];
const componentDatatype = packedGeometry[packedGeometryIndex++];
componentsPerAttribute = packedGeometry[packedGeometryIndex++];
const normalize = packedGeometry[packedGeometryIndex++] !== 0;
length = packedGeometry[packedGeometryIndex++];
values = ComponentDatatype.createTypedArray(componentDatatype, length);
for (let valuesIndex = 0; valuesIndex < length; valuesIndex++) {
values[valuesIndex] = packedGeometry[packedGeometryIndex++];
}
attributes[name] = new GeometryAttribute({
componentDatatype: componentDatatype,
componentsPerAttribute: componentsPerAttribute,
normalize: normalize,
values: values,
});
}
let indices;
length = packedGeometry[packedGeometryIndex++];
if (length > 0) {
const numberOfVertices = values.length / componentsPerAttribute;
indices = IndexDatatype.createTypedArray(numberOfVertices, length);
for (i = 0; i < length; i++) {
indices[i] = packedGeometry[packedGeometryIndex++];
}
}
result[resultIndex++] = new Geometry({
primitiveType: primitiveType,
geometryType: geometryType,
boundingSphere: boundingSphere,
boundingSphereCV: boundingSphereCV,
indices: indices,
attributes: attributes,
offsetAttribute: offsetAttribute,
});
}
return result;
};
function packInstancesForCombine(instances, transferableObjects) {
const length = instances.length;
const packedData = new Float64Array(1 + length * 19);
let count = 0;
packedData[count++] = length;
for (let i = 0; i < length; i++) {
const instance = instances[i];
Matrix4.pack(instance.modelMatrix, packedData, count);
count += Matrix4.packedLength;
Iif (defined(instance.attributes) && defined(instance.attributes.offset)) {
const values = instance.attributes.offset.value;
packedData[count] = values[0];
packedData[count + 1] = values[1];
packedData[count + 2] = values[2];
}
count += 3;
}
transferableObjects.push(packedData.buffer);
return packedData;
}
function unpackInstancesForCombine(data) {
const packedInstances = data;
const result = new Array(packedInstances[0]);
let count = 0;
let i = 1;
while (i < packedInstances.length) {
const modelMatrix = Matrix4.unpack(packedInstances, i);
let attributes;
i += Matrix4.packedLength;
if (defined(packedInstances[i])) {
attributes = {
offset: new OffsetGeometryInstanceAttribute(
packedInstances[i],
packedInstances[i + 1],
packedInstances[i + 2],
),
};
}
i += 3;
result[count++] = {
modelMatrix: modelMatrix,
attributes: attributes,
};
}
return result;
}
/**
* @private
*/
PrimitivePipeline.packCombineGeometryParameters = function (
parameters,
transferableObjects,
) {
const createGeometryResults = parameters.createGeometryResults;
const length = createGeometryResults.length;
for (let i = 0; i < length; i++) {
transferableObjects.push(createGeometryResults[i].packedData.buffer);
}
return {
createGeometryResults: parameters.createGeometryResults,
packedInstances: packInstancesForCombine(
parameters.instances,
transferableObjects,
),
ellipsoid: parameters.ellipsoid,
isGeographic: parameters.projection instanceof GeographicProjection,
elementIndexUintSupported: parameters.elementIndexUintSupported,
scene3DOnly: parameters.scene3DOnly,
vertexCacheOptimize: parameters.vertexCacheOptimize,
compressVertices: parameters.compressVertices,
modelMatrix: parameters.modelMatrix,
createPickOffsets: parameters.createPickOffsets,
};
};
/**
* @private
*/
PrimitivePipeline.unpackCombineGeometryParameters = function (
packedParameters,
) {
const instances = unpackInstancesForCombine(packedParameters.packedInstances);
const createGeometryResults = packedParameters.createGeometryResults;
const length = createGeometryResults.length;
let instanceIndex = 0;
for (let resultIndex = 0; resultIndex < length; resultIndex++) {
const geometries = PrimitivePipeline.unpackCreateGeometryResults(
createGeometryResults[resultIndex],
);
const geometriesLength = geometries.length;
for (
let geometryIndex = 0;
geometryIndex < geometriesLength;
geometryIndex++
) {
const geometry = geometries[geometryIndex];
const instance = instances[instanceIndex];
instance.geometry = geometry;
++instanceIndex;
}
}
const ellipsoid = Ellipsoid.clone(packedParameters.ellipsoid);
const projection = packedParameters.isGeographic
? new GeographicProjection(ellipsoid)
: new WebMercatorProjection(ellipsoid);
return {
instances: instances,
ellipsoid: ellipsoid,
projection: projection,
elementIndexUintSupported: packedParameters.elementIndexUintSupported,
scene3DOnly: packedParameters.scene3DOnly,
vertexCacheOptimize: packedParameters.vertexCacheOptimize,
compressVertices: packedParameters.compressVertices,
modelMatrix: Matrix4.clone(packedParameters.modelMatrix),
createPickOffsets: packedParameters.createPickOffsets,
};
};
function packBoundingSpheres(boundingSpheres) {
const length = boundingSpheres.length;
const bufferLength = 1 + (BoundingSphere.packedLength + 1) * length;
const buffer = new Float32Array(bufferLength);
let bufferIndex = 0;
buffer[bufferIndex++] = length;
for (let i = 0; i < length; ++i) {
const bs = boundingSpheres[i];
if (!defined(bs)) {
buffer[bufferIndex++] = 0.0;
} else {
buffer[bufferIndex++] = 1.0;
BoundingSphere.pack(boundingSpheres[i], buffer, bufferIndex);
}
bufferIndex += BoundingSphere.packedLength;
}
return buffer;
}
function unpackBoundingSpheres(buffer) {
const result = new Array(buffer[0]);
let count = 0;
let i = 1;
while (i < buffer.length) {
if (buffer[i++] === 1.0) {
result[count] = BoundingSphere.unpack(buffer, i);
}
++count;
i += BoundingSphere.packedLength;
}
return result;
}
/**
* @private
*/
PrimitivePipeline.packCombineGeometryResults = function (
results,
transferableObjects,
) {
if (defined(results.geometries)) {
transferGeometries(results.geometries, transferableObjects);
}
const packedBoundingSpheres = packBoundingSpheres(results.boundingSpheres);
const packedBoundingSpheresCV = packBoundingSpheres(
results.boundingSpheresCV,
);
transferableObjects.push(
packedBoundingSpheres.buffer,
packedBoundingSpheresCV.buffer,
);
return {
geometries: results.geometries,
attributeLocations: results.attributeLocations,
modelMatrix: results.modelMatrix,
pickOffsets: results.pickOffsets,
offsetInstanceExtend: results.offsetInstanceExtend,
boundingSpheres: packedBoundingSpheres,
boundingSpheresCV: packedBoundingSpheresCV,
};
};
/**
* @private
*/
PrimitivePipeline.unpackCombineGeometryResults = function (packedResult) {
return {
geometries: packedResult.geometries,
attributeLocations: packedResult.attributeLocations,
modelMatrix: packedResult.modelMatrix,
pickOffsets: packedResult.pickOffsets,
offsetInstanceExtend: packedResult.offsetInstanceExtend,
boundingSpheres: unpackBoundingSpheres(packedResult.boundingSpheres),
boundingSpheresCV: unpackBoundingSpheres(packedResult.boundingSpheresCV),
};
};
export default PrimitivePipeline;
|