Skip to content

Commit 1e6664d

Browse files
authored
Speed up sogs centers calc (#7669)
1 parent b4c3e25 commit 1e6664d

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

src/scene/gsplat/gsplat-sogs-data.js

+31-8
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,39 @@ class GSplatSogsData {
177177
}
178178

179179
getCenters(result) {
180-
const p = new Vec3();
181-
const iter = this.createIter(p);
180+
const { meta, means_l, means_u, numSplats } = this;
181+
const { means } = meta;
182+
const means_u_data = new Uint32Array(means_u._levels[0].buffer);
183+
const means_l_data = new Uint32Array(means_l._levels[0].buffer);
182184
const order = this.orderTexture?._levels[0];
183185

184-
for (let i = 0; i < this.numSplats; i++) {
185-
iter.read(order ? order[i] : i);
186-
187-
result[i * 3 + 0] = p.x;
188-
result[i * 3 + 1] = p.y;
189-
result[i * 3 + 2] = p.z;
186+
const mx = means.mins[0] / 65535;
187+
const my = means.mins[1] / 65535;
188+
const mz = means.mins[2] / 65535;
189+
const Mx = means.maxs[0] / 65535;
190+
const My = means.maxs[1] / 65535;
191+
const Mz = means.maxs[2] / 65535;
192+
193+
for (let i = 0; i < numSplats; i++) {
194+
const idx = order ? order[i] : i;
195+
196+
const means_u = means_u_data[idx];
197+
const means_l = means_l_data[idx];
198+
199+
const wx = ((means_u << 8) & 0xff00) | (means_l & 0xff);
200+
const wy = (means_u & 0xff00) | ((means_l >>> 8) & 0xff);
201+
const wz = ((means_u >>> 8) & 0xff00) | ((means_l >>> 16) & 0xff);
202+
203+
const nx = mx * (65535 - wx) + Mx * wx;
204+
const ny = my * (65535 - wy) + My * wy;
205+
const nz = mz * (65535 - wz) + Mz * wz;
206+
207+
const ax = nx < 0 ? -nx : nx;
208+
const ay = ny < 0 ? -ny : ny;
209+
const az = nz < 0 ? -nz : nz;
210+
result[i * 3] = (nx < 0 ? -1 : 1) * (Math.exp(ax) - 1);
211+
result[i * 3 + 1] = (ny < 0 ? -1 : 1) * (Math.exp(ay) - 1);
212+
result[i * 3 + 2] = (nz < 0 ? -1 : 1) * (Math.exp(az) - 1);
190213
}
191214
}
192215

0 commit comments

Comments
 (0)