diff --git a/src/scene/gsplat/gsplat-sorter.js b/src/scene/gsplat/gsplat-sorter.js index 539a0012423..a4f15b5e413 100644 --- a/src/scene/gsplat/gsplat-sorter.js +++ b/src/scene/gsplat/gsplat-sorter.js @@ -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; @@ -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')) {