Skip to content

Commit

Permalink
Customize console logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mkkellogg committed Apr 22, 2024
1 parent b520c3f commit 89297bb
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 17 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ const viewer = new GaussianSplats3D.Viewer({
'renderMode': GaussianSplats3D.RenderMode.OnChange,
'sceneRevealMode': GaussianSplats3D.SceneRevealMode.Instant,
'antialiased': false,
'focalAdjustment': 1.0
'focalAdjustment': 1.0,
'logLevel': GaussianSplats3D.LogLevel.None
});
viewer.addSplatScene('<path to .ply, .ksplat, or .splat file>')
.then(() => {
Expand Down Expand Up @@ -305,6 +306,7 @@ Advanced `Viewer` parameters
| `sceneRevealMode` | Controls the fade-in effect used when the scene is loaded. Valid values are defined in the `SceneRevealMode` enum: `Default`, `Gradual`, and `Instant`. `Default` results in a nice, slow fade-in effect for progressively loaded scenes, and a fast fade-in for non progressively loaded scenes. `Gradual` will force a slow fade-in for all scenes. `Instant` will force all loaded scene data to be immediately visible.
| `antialiased` | When true, will perform additional steps during rendering to address artifacts caused by the rendering of gaussians at substantially different resolutions than that at which they were rendered during training. This will only work correctly for models that were trained using a process that utilizes this compensation calculation. For more details: https://github.com/nerfstudio-project/gsplat/pull/117, https://github.com/graphdeco-inria/gaussian-splatting/issues/294#issuecomment-1772688093
| `focalAdjustment` | Hacky, non-scientific parameter for tweaking focal length related calculations. For scenes with very small gaussians & small details, increasing this value can help improve visual quality. Default value is 1.0.
| `logLevel` | Verbosity of the console logging. Defaults to `GaussianSplats3D.LogLevel.None`.
<br>

### Creating KSPLAT files
Expand Down
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,7 @@
currentCameraLookAtArray = component[1];
document.getElementById('cameraLookAt').value = currentCameraLookAtArray;
} else if (varName == "aa") {
currentAntialiased = component[1];
currentAntialiased = component[1] === 'true' ? true : false;
document.getElementById('antialiased').checked = currentAntialiased;
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/LogLevel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const LogLevel = {
None: 0,
Error: 1,
Warning: 2,
Info: 3,
Debug: 4
};
19 changes: 12 additions & 7 deletions src/SplatMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { WebGLCapabilities } from './three-shim/WebGLCapabilities.js';
import { uintEncodedFloat, rgbaArrayToInteger } from './Util.js';
import { Constants } from './Constants.js';
import { SceneRevealMode } from './SceneRevealMode.js';
import { LogLevel } from './LogLevel.js';

const dummyGeometry = new THREE.BufferGeometry();
const dummyMaterial = new THREE.MeshBasicMaterial();
Expand All @@ -30,7 +31,7 @@ export class SplatMesh extends THREE.Mesh {

constructor(dynamicMode = true, halfPrecisionCovariancesOnGPU = false, devicePixelRatio = 1,
enableDistancesComputationOnGPU = true, integerBasedDistancesComputation = false,
antialiased = false, maxScreenSpaceSplatSize = 2048) {
antialiased = false, maxScreenSpaceSplatSize = 2048, logLevel = LogLevel.None) {
super(dummyGeometry, dummyMaterial);
// Reference to a Three.js renderer
this.renderer = undefined;
Expand All @@ -55,6 +56,8 @@ export class SplatMesh extends THREE.Mesh {
this.antialiased = antialiased;
// Specify the maximum clip space splat size, can help deal with large splats that get too unwieldy
this.maxScreenSpaceSplatSize = maxScreenSpaceSplatSize;
// The verbosity of console logging
this.logLevel = logLevel;
// The individual splat scenes stored in this splat mesh, each containing their own transform
this.scenes = [];
// Special octree tailored to SplatMesh instances
Expand Down Expand Up @@ -601,7 +604,7 @@ export class SplatMesh extends THREE.Mesh {
}, onSplatTreeIndexesUpload, onSplatTreeConstruction)
.then(() => {
const buildTime = performance.now() - buildStartTime;
console.log('SplatTree build: ' + buildTime + ' ms');
if (this.logLevel >= LogLevel.Info) console.log('SplatTree build: ' + buildTime + ' ms');
if (this.disposed) {
resolve();
} else {
Expand All @@ -623,11 +626,13 @@ export class SplatMesh extends THREE.Mesh {
leavesWithVertices++;
}
});
console.log(`SplatTree leaves: ${this.splatTree.countLeaves()}`);
console.log(`SplatTree leaves with splats:${leavesWithVertices}`);
avgSplatCount = avgSplatCount / nodeCount;
console.log(`Avg splat count per node: ${avgSplatCount}`);
console.log(`Total splat count: ${this.getSplatCount()}`);
if (this.logLevel >= LogLevel.Info) {
console.log(`SplatTree leaves: ${this.splatTree.countLeaves()}`);
console.log(`SplatTree leaves with splats:${leavesWithVertices}`);
avgSplatCount = avgSplatCount / nodeCount;
console.log(`Avg splat count per node: ${avgSplatCount}`);
console.log(`Total splat count: ${this.getSplatCount()}`);
}
resolve();
}
});
Expand Down
23 changes: 15 additions & 8 deletions src/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ARButton } from './webxr/ARButton.js';
import { delayedExecute } from './Util.js';
import { LoaderStatus } from './loaders/LoaderStatus.js';
import { RenderMode } from './RenderMode.js';
import { LogLevel } from './LogLevel.js';
import { SceneRevealMode } from './SceneRevealMode.js';

const THREE_CAMERA_FOV = 50;
Expand Down Expand Up @@ -137,6 +138,9 @@ export class Viewer {
// Specify the maximum screen-space splat size, can help deal with large splats that get too unwieldy
this.maxScreenSpaceSplatSize = options.maxScreenSpaceSplatSize || 2048;

// The verbosity of console logging
this.logLevel = options.logLevel || LogLevel.None;

this.createSplatMesh();

this.controls = null;
Expand Down Expand Up @@ -211,7 +215,8 @@ export class Viewer {

createSplatMesh() {
this.splatMesh = new SplatMesh(this.dynamicScene, this.halfPrecisionCovariancesOnGPU, this.devicePixelRatio,
this.gpuAcceleratedSort, this.integerBasedSort, this.antialiased, this.maxScreenSpaceSplatSize);
this.gpuAcceleratedSort, this.integerBasedSort, this.antialiased,
this.maxScreenSpaceSplatSize, this.logLevel);
this.splatMesh.frustumCulled = false;
}

Expand Down Expand Up @@ -1121,7 +1126,7 @@ export class Viewer {
} else if (e.data.sortCanceled) {
this.sortRunning = false;
} else if (e.data.sortSetupPhase1Complete) {
console.log('Sorting web worker WASM setup complete.');
if (this.logLevel >= LogLevel.Info) console.log('Sorting web worker WASM setup complete.');
if (this.sharedMemoryForWorkers) {
this.sortWorkerSortedIndexes = new Uint32Array(e.data.sortedIndexesBuffer,
e.data.sortedIndexesOffset, maxSplatCount);
Expand All @@ -1140,12 +1145,14 @@ export class Viewer {
for (let i = 0; i < splatCount; i++) this.sortWorkerIndexesToSort[i] = i;
this.sortWorker.maxSplatCount = maxSplatCount;

console.log('Sorting web worker ready.');
const splatDataTextures = this.splatMesh.getSplatDataTextures();
const covariancesTextureSize = splatDataTextures.covariances.size;
const centersColorsTextureSize = splatDataTextures.centerColors.size;
console.log('Covariances texture size: ' + covariancesTextureSize.x + ' x ' + covariancesTextureSize.y);
console.log('Centers/colors texture size: ' + centersColorsTextureSize.x + ' x ' + centersColorsTextureSize.y);
if (this.logLevel >= LogLevel.Info) {
console.log('Sorting web worker ready.');
const splatDataTextures = this.splatMesh.getSplatDataTextures();
const covariancesTextureSize = splatDataTextures.covariances.size;
const centersColorsTextureSize = splatDataTextures.centerColors.size;
console.log('Covariances texture size: ' + covariancesTextureSize.x + ' x ' + covariancesTextureSize.y);
console.log('Centers/colors texture size: ' + centersColorsTextureSize.x + ' x ' + centersColorsTextureSize.y);
}

resolve();
}
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { AbortablePromise } from './AbortablePromise.js';
import { SceneFormat } from './loaders/SceneFormat.js';
import { WebXRMode } from './webxr/WebXRMode.js';
import { RenderMode } from './RenderMode.js';
import { LogLevel } from './LogLevel.js';
import { SceneRevealMode } from './SceneRevealMode.js';

export {
Expand All @@ -35,5 +36,6 @@ export {
SceneFormat,
WebXRMode,
RenderMode,
LogLevel,
SceneRevealMode
};

0 comments on commit 89297bb

Please sign in to comment.