Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle NaNs in GSplat data #7243

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading