Skip to content

Commit 92ee4db

Browse files
authored
Ignore infinities when calculating bound (#484)
1 parent 0ed0dfa commit 92ee4db

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

src/asset-loader.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class AssetLoader {
177177
url: loadRequest.url,
178178
filename: loadRequest.filename
179179
});
180-
asset.resource = new GSplatResource(this.app, gsplatData, []);
180+
asset.resource = new GSplatResource(this.app.graphicsDevice, gsplatData, []);
181181
resolve(new Splat(asset));
182182
})
183183
.catch((err) => {

src/data-processor.ts

+17-11
Original file line numberDiff line numberDiff line change
@@ -379,17 +379,23 @@ class DataProcessor {
379379

380380
// resolve mins/maxs
381381
const { minData, maxData } = resources;
382-
v1.set(minData[0], minData[1], minData[2]);
383-
v2.set(maxData[0], maxData[1], maxData[2]);
384-
385-
for (let i = 1; i < transformA.width; i++) {
386-
v1.x = Math.min(v1.x, minData[i * 4]);
387-
v1.y = Math.min(v1.y, minData[i * 4 + 1]);
388-
v1.z = Math.min(v1.z, minData[i * 4 + 2]);
389-
390-
v2.x = Math.max(v2.x, maxData[i * 4]);
391-
v2.y = Math.max(v2.y, maxData[i * 4 + 1]);
392-
v2.z = Math.max(v2.z, maxData[i * 4 + 2]);
382+
v1.set(Infinity, Infinity, Infinity);
383+
v2.set(-Infinity, -Infinity, -Infinity);
384+
385+
for (let i = 0; i < transformA.width; i++) {
386+
const a = minData[i * 4];
387+
const b = minData[i * 4 + 1];
388+
const c = minData[i * 4 + 2];
389+
if (isFinite(a)) v1.x = Math.min(v1.x, a);
390+
if (isFinite(b)) v1.y = Math.min(v1.y, b);
391+
if (isFinite(c)) v1.z = Math.min(v1.z, c);
392+
393+
const d = maxData[i * 4];
394+
const e = maxData[i * 4 + 1];
395+
const f = maxData[i * 4 + 2];
396+
if (isFinite(d)) v2.x = Math.max(v2.x, d);
397+
if (isFinite(e)) v2.y = Math.max(v2.y, e);
398+
if (isFinite(f)) v2.z = Math.max(v2.z, f);
393399
}
394400

395401
boundingBox.setMinMax(v1, v2);

src/shaders/bound-shader.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ const fragmentShader = /* glsl */ `
1616
// calculate min and max for a single column of splats
1717
void main(void) {
1818
19-
vec3 boundMin = vec3(100000.0);
20-
vec3 boundMax = vec3(-100000.0);
19+
vec3 boundMin = vec3(1e6);
20+
vec3 boundMax = vec3(-1e6);
2121
2222
for (int id = 0; id < splat_params.y; id++) {
2323
// calculate splatUV
@@ -54,8 +54,8 @@ const fragmentShader = /* glsl */ `
5454
center = vec4(center, 1.0) * t;
5555
}
5656
57-
boundMin = min(boundMin, center);
58-
boundMax = max(boundMax, center);
57+
boundMin = min(boundMin, mix(center, boundMin, isinf(center)));
58+
boundMax = max(boundMax, mix(center, boundMax, isinf(center)));
5959
}
6060
6161
pcFragColor0 = vec4(boundMin, 0.0);

src/splat.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class Splat extends Element {
141141

142142
// pack spherical harmonic data
143143
const createTexture = (name: string, format: number) => {
144-
return new Texture(splatResource.app.graphicsDevice, {
144+
return new Texture(splatResource.device, {
145145
name: name,
146146
width: width,
147147
height: height,
@@ -159,7 +159,7 @@ class Splat extends Element {
159159
this.transformTexture = createTexture('splatTransform', PIXELFORMAT_R16U);
160160

161161
// create the transform palette
162-
this.transformPalette = new TransformPalette(splatResource.app.graphicsDevice);
162+
this.transformPalette = new TransformPalette(splatResource.device);
163163

164164
// blend mode for splats
165165
const blendState = new BlendState(true, BLENDEQUATION_ADD, BLENDMODE_ONE, BLENDMODE_ONE_MINUS_SRC_ALPHA);

0 commit comments

Comments
 (0)