Bounding box helper function (#126)

* bounding box implementation

* set default bbox to center-based computation

* [bbox] clean up bbox and editor logic

* [bbox] add error handling and documentation
This commit is contained in:
Winnie Lin
2025-07-31 15:01:18 -07:00
committed by GitHub
parent 05ddd8375e
commit 0705207bdc
3 changed files with 73 additions and 1 deletions
+19 -1
View File
@@ -145,6 +145,7 @@
reversePointerDir: false,
reversePointerSlide: false,
backgroundColor: "#000000",
viewBoundingBox: false,
openFiles: () => {
fileInput.click();
},
@@ -340,7 +341,7 @@
async function loadFiles(splatFiles) {
if (guiOptions.resetOnLoad) {
const toRemove = frame.children.filter((child) => child instanceof SplatMesh);
const toRemove = frame.children.filter((child) => child instanceof SplatMesh || child instanceof THREE.Box3Helper);
for (const child of toRemove) {
frame.remove(child);
}
@@ -403,6 +404,7 @@
}
frame.add(splatMesh);
console.log(`Loaded ${fileName} with ${splatMesh.numSplats} splats`);
addBoundingBoxHelper(splatMesh);
const splatFolder = splatsFolder.addFolder(fileName).close();
splatFolder.add(splatMesh, "opacity", 0, 1, 0.01).name("Opacity").listen();
@@ -433,6 +435,14 @@
canvas.focus();
}
async function addBoundingBoxHelper(splatMesh) {
await splatMesh.initialized;
const box = splatMesh.getBoundingBox();
const boxHelper = new THREE.Box3Helper(box, 0x00ff00);
boxHelper.visible = guiOptions.viewBoundingBox;
frame.add(boxHelper);
}
secondGui.add(guiOptions, "resetOnLoad").name("Reset on load");
secondGui.add(guiOptions, "loadOffset", -2, 2, 0.01).name("Loading offset");
secondGui.add(guiOptions, "openFiles").name("Select Files");
@@ -502,6 +512,13 @@
const debugFolder = gui.addFolder("Debug").close();
const normalColor = dyno.dynoBool(false);
debugFolder.add(normalColor, "value").name("Normal color").onChange(() => updateFrameSplats());
debugFolder.add(guiOptions, "viewBoundingBox").name("View bounding boxes").onChange((viewBoundingBox) => {
frame.children.forEach((child) => {
if (child instanceof THREE.Box3Helper) {
child.visible = viewBoundingBox;
}
});
});
debugFolder.add(spark, "maxStdDev", 0.1, 3.0, 0.01).name("Max Gsplat stddev").listen();
debugFolder.add(spark, "falloff", 0, 1, 0.01).name("Gaussian falloff").listen();
@@ -688,6 +705,7 @@
}
const instructions = makeInstructions();
addBoundingBoxHelper(instructions);
frame.add(instructions);
// Load URLs from query parameters if any