Skip to content

Commit

Permalink
Add option to show splat bounding box (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
slimbuck authored Aug 14, 2024
1 parent 6d42b44 commit e86f604
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "supersplat",
"version": "1.0.0",
"version": "1.1.0",
"author": "PlayCanvas<support@playcanvas.com>",
"homepage": "https://playcanvas.com/supersplat/editor",
"description": "3D Gaussian Splat Editor",
Expand Down
2 changes: 1 addition & 1 deletion src/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ class Camera extends Element {

const device = this.scene.graphicsDevice as WebglGraphicsDevice;
const events = this.scene.events;
const alpha = events.invoke('camera.debug') && events.invoke('camera.mode') === 'rings' ? 0.0 : 0.2;
const alpha = events.invoke('camera.mode') === 'rings' ? 0.0 : 0.2;

// hide non-selected elements
const splats = this.scene.getElementsByType(ElementType.splat);
Expand Down
33 changes: 31 additions & 2 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ const registerEditorEvents = (events: Events, editHistory: EditHistory, scene: S
scene.forceRender = true;
});

events.on('camera.bound', () => {
scene.forceRender = true;
});

// grid.visible

const setGridVisible = (visible: boolean) => {
if (visible !== scene.grid.visible) {
scene.grid.visible = visible;
Expand All @@ -99,12 +105,35 @@ const registerEditorEvents = (events: Events, editHistory: EditHistory, scene: S
return scene.grid.visible;
});

events.on('grid.setVisible', (visible: boolean) => {
setGridVisible(visible);
});

events.on('grid.toggleVisible', () => {
setGridVisible(!scene.grid.visible);
});

events.on('grid.setVisible', (visible: boolean) => {
setGridVisible(visible);
// camera.bound

let bound = true;

const setBoundVisible = (visible: boolean) => {
if (visible !== bound) {
bound = visible;
events.fire('camera.bound', bound);
}
};

events.function('camera.bound', () => {
return bound;
});

events.on('camera.setBound', (value: boolean) => {
setBoundVisible(value);
});

events.on('camera.toggleBound', () => {
setBoundVisible(!events.invoke('camera.bound'));
});

events.on('camera.focus', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/splat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ class Splat extends Element {
const material = this.entity.gsplat.instance.material;
material.setParameter('ringSize', (selected && cameraMode === 'rings' && splatSize > 0) ? 0.04 : 0);

if (this.visible && selected) {
if (this.visible && selected && events.invoke('camera.bound')) {
// render splat centers
if (cameraMode === 'centers' && splatSize > 0) {
this.splatDebug.splatSize = splatSize;
Expand Down
31 changes: 31 additions & 0 deletions src/ui/view-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,30 @@ class ViewPanel extends Container {
showGridRow.append(showGridLabel);
showGridRow.append(showGridToggle);

// show bound

const showBoundRow = new Container({
class: 'view-panel-row'
});

const showBoundLabel = new Label({
text: 'Show Bound',
class: 'view-panel-row-label'
});

const showBoundToggle = new BooleanInput({
type: 'toggle',
class: 'view-panel-row-toggle',
value: true
});

showBoundRow.append(showBoundLabel);
showBoundRow.append(showBoundToggle);

this.append(header);
this.append(splatSizeRow);
this.append(showGridRow);
this.append(showBoundRow);

// handle panel visibility

Expand Down Expand Up @@ -124,6 +145,16 @@ class ViewPanel extends Container {
showGridToggle.on('change', () => {
events.fire('grid.setVisible', showGridToggle.value);
});

// show bound

events.on('camera.bound', (visible: boolean) => {
showBoundToggle.value = visible;
});

showBoundToggle.on('change', () => {
events.fire('camera.setBound', showBoundToggle.value);
});
}
}

Expand Down

0 comments on commit e86f604

Please sign in to comment.