From e86f604275e8e43d5044dc32370e0760cc46e056 Mon Sep 17 00:00:00 2001 From: Donovan Hutchence Date: Wed, 14 Aug 2024 16:29:53 +0100 Subject: [PATCH] Add option to show splat bounding box (#165) --- package-lock.json | 4 ++-- package.json | 2 +- src/camera.ts | 2 +- src/editor.ts | 33 +++++++++++++++++++++++++++++++-- src/splat.ts | 2 +- src/ui/view-panel.ts | 31 +++++++++++++++++++++++++++++++ 6 files changed, 67 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index c64e269..5c46413 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "supersplat", - "version": "1.0.0", + "version": "1.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "supersplat", - "version": "1.0.0", + "version": "1.1.0", "license": "MIT", "devDependencies": { "@playcanvas/eslint-config": "^1.7.4", diff --git a/package.json b/package.json index cdf7e43..64f50aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "supersplat", - "version": "1.0.0", + "version": "1.1.0", "author": "PlayCanvas", "homepage": "https://playcanvas.com/supersplat/editor", "description": "3D Gaussian Splat Editor", diff --git a/src/camera.ts b/src/camera.ts index 7ddef6c..c4147cb 100644 --- a/src/camera.ts +++ b/src/camera.ts @@ -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); diff --git a/src/editor.ts b/src/editor.ts index ab82558..c8517dd 100644 --- a/src/editor.ts +++ b/src/editor.ts @@ -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; @@ -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', () => { diff --git a/src/splat.ts b/src/splat.ts index dc8b5f7..95fd66c 100644 --- a/src/splat.ts +++ b/src/splat.ts @@ -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; diff --git a/src/ui/view-panel.ts b/src/ui/view-panel.ts index 621e988..05319f0 100644 --- a/src/ui/view-panel.ts +++ b/src/ui/view-panel.ts @@ -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 @@ -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); + }); } }