({
accumulator,
viewToWorld,
displayed = false,
}: {
accumulator?: OldSplatAccumulator;
viewToWorld: THREE.Matrix4;
displayed?: boolean;
})
| 563 | } |
| 564 | |
| 565 | private async sortUpdate({ |
| 566 | accumulator, |
| 567 | viewToWorld, |
| 568 | displayed = false, |
| 569 | }: { |
| 570 | accumulator?: OldSplatAccumulator; |
| 571 | viewToWorld: THREE.Matrix4; |
| 572 | displayed?: boolean; |
| 573 | }) { |
| 574 | if (this.sortingCheck) { |
| 575 | throw new Error("Only one sort at a time"); |
| 576 | } |
| 577 | this.sortingCheck = true; |
| 578 | |
| 579 | accumulator = accumulator ?? this.spark.active; |
| 580 | const { numSplats, maxSplats } = accumulator.splats; |
| 581 | let activeSplats = 0; |
| 582 | let ordering = this.orderingFreelist.alloc(maxSplats); |
| 583 | |
| 584 | if (this.stochastic) { |
| 585 | activeSplats = numSplats; |
| 586 | // Render all splats in order since the Z-buffer |
| 587 | // will handle ordering. |
| 588 | for (let i = 0; i < numSplats; ++i) { |
| 589 | ordering[i] = i; |
| 590 | } |
| 591 | } else if (numSplats > 0) { |
| 592 | const { |
| 593 | reader, |
| 594 | doubleSortReader, |
| 595 | sort32Reader, |
| 596 | dynoSortRadial, |
| 597 | dynoOrigin, |
| 598 | dynoDirection, |
| 599 | dynoDepthBias, |
| 600 | dynoSort360, |
| 601 | dynoSplats, |
| 602 | } = OldSparkViewpoint.makeSorter(); |
| 603 | const sort32 = this.sort32 ?? false; |
| 604 | let readback: Uint16Array | Uint32Array; |
| 605 | if (sort32) { |
| 606 | this.readback32 = reader.ensureBuffer(maxSplats, this.readback32); |
| 607 | readback = this.readback32; |
| 608 | } else { |
| 609 | const halfMaxSplats = Math.ceil(maxSplats / 2); |
| 610 | this.readback16 = reader.ensureBuffer(halfMaxSplats, this.readback16); |
| 611 | readback = this.readback16; |
| 612 | } |
| 613 | |
| 614 | const worldToOrigin = accumulator.toWorld.clone().invert(); |
| 615 | const viewToOrigin = viewToWorld.clone().premultiply(worldToOrigin); |
| 616 | |
| 617 | dynoSortRadial.value = this.sort360 ? true : this.sortRadial; |
| 618 | dynoOrigin.value.set(0, 0, 0).applyMatrix4(viewToOrigin); |
| 619 | dynoDirection.value |
| 620 | .set(0, 0, -1) |
| 621 | .applyMatrix4(viewToOrigin) |
| 622 | .sub(dynoOrigin.value) |
no test coverage detected