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

Splat updates #269

Merged
merged 6 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
24 changes: 18 additions & 6 deletions src/splat/splat-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,19 @@ class SplatData {
const sy = this.getProp('scale_1');
const sz = this.getProp('scale_2');

const opacity = this.getProp('opacity');

const splat = {
x: 0, y: 0, z: 0, rx: 0, ry: 0, rz: 0, rw: 0, sx: 0, sy: 0, sz: 0
};

// initialize aabb
result.center.set(x[0], y[0], z[0]);
result.halfExtents.set(0, 0, 0);
let first = true;

for (let i = 0; i < this.numSplats; ++i) {
if (opacity[i] === -1000) {
continue;
}

splat.x = x[i];
splat.y = y[i];
splat.z = z[i];
Expand All @@ -160,9 +164,16 @@ class SplatData {
splat.sy = Math.exp(sy[i]);
splat.sz = Math.exp(sz[i]);

calcSplatAabb(aabb2, splat);
result.add(aabb2);
if (first) {
first = false;
calcSplatAabb(result, splat);
} else {
calcSplatAabb(aabb2, splat);
result.add(aabb2);
}
}

return !first;
}

renderWireframeBounds(app: AppBase, worldMat: Mat4) {
Expand Down Expand Up @@ -215,14 +226,15 @@ class SplatData {
const x = this.getProp('x');
const y = this.getProp('y');
const z = this.getProp('z');
const opacity = this.getProp('opacity');

const sx = this.getProp('scale_0');
const sy = this.getProp('scale_1');
const sz = this.getProp('scale_2');

let sum = 0;
for (let i = 0; i < this.numSplats; ++i) {
const weight = 1.0 / (1.0 + Math.exp(Math.max(sx[i], sy[i], sz[i])));
const weight = opacity[i] / (1.0 + Math.exp(Math.max(sx[i], sy[i], sz[i])));
result.x += x[i] * weight;
result.y += y[i] * weight;
result.z += z[i] * weight;
Expand Down
12 changes: 12 additions & 0 deletions src/splat/splat-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ class SplatResource extends ContainerResource {
return result;
}

updateFocalPoint() {
this.splatData.calcFocalPoint(this.focalPoint);
}

updateAabb() {
this.splatData.calcAabb(this.customAabb);

this.instances.forEach((instance) => {
instance.entity.render.customAabb = this.customAabb;
});
}

getFocalPoint(): Vec3 {
const instance = this.instances[0];
return instance?.entity.getWorldTransform().transformPoint(this.focalPoint);
Expand Down