Skip to content

Commit

Permalink
Handle NaNs in GSplat data (#7243)
Browse files Browse the repository at this point in the history
  • Loading branch information
slimbuck authored Dec 30, 2024
1 parent b8f4cc5 commit 456f872
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions src/scene/gsplat/gsplat-sorter.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ function SortWorker() {
const y = centers[istride + 1] - py;
const z = centers[istride + 2] - pz;
const d = x * dx + y * dy + z * dz;
if (isNaN(d)) {
continue;
}
const sortKey = Math.floor((d - minDist) * divider);

distances[i] = sortKey;
Expand Down Expand Up @@ -160,24 +163,36 @@ function SortWorker() {
centers = new Float32Array(message.data.centers);

// calculate bounds
boundMin.x = boundMax.x = centers[0];
boundMin.y = boundMax.y = centers[1];
boundMin.z = boundMax.z = centers[2];

let initialized = false;
const numVertices = centers.length / 3;
for (let i = 1; i < numVertices; ++i) {
for (let i = 0; i < numVertices; ++i) {
const x = centers[i * 3 + 0];
const y = centers[i * 3 + 1];
const z = centers[i * 3 + 2];

boundMin.x = Math.min(boundMin.x, x);
boundMin.y = Math.min(boundMin.y, y);
boundMin.z = Math.min(boundMin.z, z);
if (isNaN(x) || isNaN(y) || isNaN(z)) {
continue;
}

if (!initialized) {
initialized = true;
boundMin.x = boundMax.x = x;
boundMin.y = boundMax.y = y;
boundMin.z = boundMax.z = z;
} else {
boundMin.x = Math.min(boundMin.x, x);
boundMax.x = Math.max(boundMax.x, x);
boundMin.y = Math.min(boundMin.y, y);
boundMax.y = Math.max(boundMax.y, y);
boundMin.z = Math.min(boundMin.z, z);
boundMax.z = Math.max(boundMax.z, z);
}
}

boundMax.x = Math.max(boundMax.x, x);
boundMax.y = Math.max(boundMax.y, y);
boundMax.z = Math.max(boundMax.z, z);
if (!initialized) {
boundMin.x = boundMax.x = boundMin.y = boundMax.y = boundMin.z = boundMax.z = 0;
}

forceUpdate = true;
}
if (message.data.hasOwnProperty('mapping')) {
Expand Down

0 comments on commit 456f872

Please sign in to comment.