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

Add option to show splat bounding box #165

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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
});
Comment on lines +83 to +96
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason that you're not using LabelGroup: https://api.playcanvas.com/classes/PCUI.LabelGroup.html

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep the best of reasons - I didn't know of its existence. :) I will consider using this for future updates (though in some cases it's easier to start from a css-blank-sheet rather than wrestle pcui styling).


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
Loading