Skip to content

Commit 408943e

Browse files
authored
Merge pull request #384 from mkkellogg/dev
Release v0.4.6 - Minor updates
2 parents f6f4ade + 000adcc commit 408943e

File tree

12 files changed

+66
-45
lines changed

12 files changed

+66
-45
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ Advanced `Viewer` parameters
334334
| `renderMode` | Controls when the viewer renders the scene. Valid values are defined in the `RenderMode` enum: `Always`, `OnChange`, and `Never`. Defaults to `Always`.
335335
| `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.
336336
| `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
337+
| `kernel2DSize` | A constant added to the size of the 2D screen-space gaussian kernel used in rendering splats. Default value is 0.3.
337338
| `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.
338339
| `logLevel` | Verbosity of the console logging. Defaults to `GaussianSplats3D.LogLevel.None`.
339340
| `sphericalHarmonicsDegree` | Degree of spherical harmonics to utilize in rendering splats (assuming the data is present in the splat scene). Valid values are 0, 1, or 2. Default value is 0.
@@ -361,7 +362,8 @@ GaussianSplats3D.PlyLoader.loadFromURL('<path to .ply or .splat file>',
361362
minimumAlpha,
362363
compressionLevel,
363364
optimizeSplatData,
364-
sphericalHarmonicsDegree)
365+
sphericalHarmonicsDegree,
366+
headers)
365367
.then((splatBuffer) => {
366368
GaussianSplats3D.KSplatLoader.downloadFile(splatBuffer, 'converted_file.ksplat');
367369
});

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "git",
55
"url": "https://github.com/mkkellogg/GaussianSplats3D"
66
},
7-
"version": "0.4.5",
7+
"version": "0.4.6",
88
"description": "Three.js-based 3D Gaussian splat viewer",
99
"module": "build/gaussian-splats-3d.module.js",
1010
"main": "build/gaussian-splats-3d.umd.cjs",

src/DropInViewer.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export class DropInViewer extends THREE.Group {
1313
options.selfDrivenMode = false;
1414
options.useBuiltInControls = false;
1515
options.rootElement = null;
16-
options.ignoreDevicePixelRatio = false;
1716
options.dropInMode = true;
1817
options.camera = undefined;
1918
options.renderer = undefined;

src/Util.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ export const rgbaArrayToInteger = function(arr, offset) {
5454
return arr[offset] + (arr[offset + 1] << 8) + (arr[offset + 2] << 16) + (arr[offset + 3] << 24);
5555
};
5656

57-
export const fetchWithProgress = function(path, onProgress, saveChunks = true) {
57+
export const fetchWithProgress = function(path, onProgress, saveChunks = true, headers) {
5858

5959
const abortController = new AbortController();
6060
const signal = abortController.signal;
@@ -65,7 +65,9 @@ export const fetchWithProgress = function(path, onProgress, saveChunks = true) {
6565
};
6666

6767
return new AbortablePromise((resolve, reject) => {
68-
fetch(path, { signal })
68+
const fetchOptions = { signal };
69+
if (headers) fetchOptions.headers = headers;
70+
fetch(path, fetchOptions)
6971
.then(async (data) => {
7072
// Handle error conditions where data is still returned
7173
if (!data.ok) {

src/Viewer.js

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class Viewer {
7272
// Tells the viewer to pretend the device pixel ratio is 1, which can boost performance on devices where it is larger,
7373
// at a small cost to visual quality
7474
this.ignoreDevicePixelRatio = options.ignoreDevicePixelRatio || false;
75-
this.devicePixelRatio = this.ignoreDevicePixelRatio ? 1 : window.devicePixelRatio;
75+
this.devicePixelRatio = this.ignoreDevicePixelRatio ? 1 : (window.devicePixelRatio || 1);
7676

7777
// Tells the viewer to use 16-bit floating point values when storing splat covariance data in textures, instead of 32-bit
7878
this.halfPrecisionCovariancesOnGPU = options.halfPrecisionCovariancesOnGPU || false;
@@ -117,6 +117,9 @@ export class Viewer {
117117
// https://github.com/graphdeco-inria/gaussian-splatting/issues/294#issuecomment-1772688093
118118
this.antialiased = options.antialiased || false;
119119

120+
// This constant is added to the projected 2D screen-space splat scales
121+
this.kernel2DSize = (options.kernel2DSize === undefined) ? 0.3 : options.kernel2DSize;
122+
120123
this.webXRMode = options.webXRMode || WebXRMode.None;
121124
if (this.webXRMode !== WebXRMode.None) {
122125
this.gpuAcceleratedSort = false;
@@ -286,7 +289,7 @@ export class Viewer {
286289
this.splatMesh = new SplatMesh(this.splatRenderMode, this.dynamicScene, this.enableOptionalEffects,
287290
this.halfPrecisionCovariancesOnGPU, this.devicePixelRatio, this.gpuAcceleratedSort,
288291
this.integerBasedSort, this.antialiased, this.maxScreenSpaceSplatSize, this.logLevel,
289-
this.sphericalHarmonicsDegree, this.sceneFadeInRateMultiplier);
292+
this.sphericalHarmonicsDegree, this.sceneFadeInRateMultiplier, this.kernel2DSize);
290293
this.splatMesh.frustumCulled = false;
291294
if (this.onSplatMeshChangedCallback) this.onSplatMeshChangedCallback();
292295
}
@@ -303,7 +306,7 @@ export class Viewer {
303306
this.rootElement.style.position = 'absolute';
304307
document.body.appendChild(this.rootElement);
305308
} else {
306-
this.rootElement = this.renderer.domElement.parentElement || document.body;
309+
this.rootElement = this.renderer.domElement || document.body;
307310
}
308311
}
309312

@@ -725,6 +728,7 @@ export class Viewer {
725728
*
726729
* onProgress: Function to be called as file data are received, or other processing occurs
727730
*
731+
* headers: Optional HTTP headers to be sent along with splat requests
728732
* }
729733
* @return {AbortablePromise}
730734
*/
@@ -819,7 +823,8 @@ export class Viewer {
819823

820824
const loadFunc = progressiveLoad ? this.downloadAndBuildSingleSplatSceneProgressiveLoad.bind(this) :
821825
this.downloadAndBuildSingleSplatSceneStandardLoad.bind(this);
822-
return loadFunc(path, format, options.splatAlphaRemovalThreshold, buildSection.bind(this), onProgress, hideLoadingUI.bind(this));
826+
return loadFunc(path, format, options.splatAlphaRemovalThreshold, buildSection.bind(this),
827+
onProgress, hideLoadingUI.bind(this), options.headers);
823828
}
824829

825830
/**
@@ -832,12 +837,13 @@ export class Viewer {
832837
* @param {function} buildFunc Function to build the viewer's splat mesh with the downloaded splat buffer
833838
* @param {function} onProgress Function to be called as file data are received, or other processing occurs
834839
* @param {function} onException Function to be called when exception occurs
840+
* @param {object} headers Optional HTTP headers to pass to use for downloading splat scene
835841
* @return {AbortablePromise}
836842
*/
837-
downloadAndBuildSingleSplatSceneStandardLoad(path, format, splatAlphaRemovalThreshold, buildFunc, onProgress, onException) {
843+
downloadAndBuildSingleSplatSceneStandardLoad(path, format, splatAlphaRemovalThreshold, buildFunc, onProgress, onException, headers) {
838844

839-
const downloadPromise = this.downloadSplatSceneToSplatBuffer(path, splatAlphaRemovalThreshold,
840-
onProgress, false, undefined, format);
845+
const downloadPromise = this.downloadSplatSceneToSplatBuffer(path, splatAlphaRemovalThreshold, onProgress, false,
846+
undefined, format, headers);
841847
const downloadAndBuildPromise = abortablePromiseWithExtractedComponents(downloadPromise.abortHandler);
842848

843849
downloadPromise.then((splatBuffer) => {
@@ -871,10 +877,11 @@ export class Viewer {
871877
* @param {function} buildFunc Function to rebuild the viewer's splat mesh after a new splat buffer section is downloaded
872878
* @param {function} onDownloadProgress Function to be called as file data are received
873879
* @param {function} onDownloadException Function to be called when exception occurs at any point during the full download
880+
* @param {object} headers Optional HTTP headers to pass to use for downloading splat scene
874881
* @return {AbortablePromise}
875882
*/
876883
downloadAndBuildSingleSplatSceneProgressiveLoad(path, format, splatAlphaRemovalThreshold, buildFunc,
877-
onDownloadProgress, onDownloadException) {
884+
onDownloadProgress, onDownloadException, headers) {
878885
let progressiveLoadedSectionBuildCount = 0;
879886
let progressiveLoadedSectionBuilding = false;
880887
const queuedProgressiveLoadSectionBuilds = [];
@@ -917,7 +924,7 @@ export class Viewer {
917924
};
918925

919926
const splatSceneDownloadPromise = this.downloadSplatSceneToSplatBuffer(path, splatAlphaRemovalThreshold, onDownloadProgress, true,
920-
onProgressiveLoadSectionProgress, format);
927+
onProgressiveLoadSectionProgress, format, headers);
921928

922929
const progressiveLoadFirstSectionBuildPromise = abortablePromiseWithExtractedComponents(splatSceneDownloadPromise.abortHandler);
923930
const splatSceneDownloadAndBuildPromise = abortablePromiseWithExtractedComponents();
@@ -953,6 +960,11 @@ export class Viewer {
953960
* rotation (Array<number>): Rotation of the scene represented as a quaternion, defaults to [0, 0, 0, 1]
954961
*
955962
* scale (Array<number>): Scene's scale, defaults to [1, 1, 1]
963+
*
964+
* headers: Optional HTTP headers to be sent along with splat requests
965+
*
966+
* format (SceneFormat) Optional, the format of the scene data (.ply, .ksplat, .splat). If not present, the
967+
* file extension in 'path' will be used to determine the format (if it is present)
956968
* }
957969
* @param {boolean} showLoadingUI Display a loading spinner while the scene is loading, defaults to true
958970
* @param {function} onProgress Function to be called as file data are received
@@ -998,7 +1010,8 @@ export class Viewer {
9981010
const options = sceneOptions[i];
9991011
const format = (options.format !== undefined && options.format !== null) ? options.format : sceneFormatFromPath(options.path);
10001012
const baseDownloadPromise = this.downloadSplatSceneToSplatBuffer(options.path, options.splatAlphaRemovalThreshold,
1001-
onLoadProgress.bind(this, i), false, undefined, format);
1013+
onLoadProgress.bind(this, i), false, undefined,
1014+
format, options.headers);
10021015
baseDownloadPromises.push(baseDownloadPromise);
10031016
nativeDownloadPromises.push(baseDownloadPromise.promise);
10041017
}
@@ -1044,23 +1057,22 @@ export class Viewer {
10441057
* @param {boolean} progressiveBuild Construct file sections into splat buffers as they are downloaded
10451058
* @param {function} onSectionBuilt Function to be called when new section is added to the file
10461059
* @param {string} format File format of the scene
1060+
* @param {object} headers Optional HTTP headers to pass to use for downloading splat scene
10471061
* @return {AbortablePromise}
10481062
*/
10491063
downloadSplatSceneToSplatBuffer(path, splatAlphaRemovalThreshold = 1, onProgress = undefined,
1050-
progressiveBuild = false, onSectionBuilt = undefined, format) {
1064+
progressiveBuild = false, onSectionBuilt = undefined, format, headers) {
10511065

10521066
const optimizeSplatData = progressiveBuild ? false : this.optimizeSplatData;
10531067
try {
10541068
if (format === SceneFormat.Splat) {
1055-
return SplatLoader.loadFromURL(path, onProgress, progressiveBuild,
1056-
onSectionBuilt, splatAlphaRemovalThreshold,
1057-
this.inMemoryCompressionLevel, optimizeSplatData);
1069+
return SplatLoader.loadFromURL(path, onProgress, progressiveBuild, onSectionBuilt, splatAlphaRemovalThreshold,
1070+
this.inMemoryCompressionLevel, optimizeSplatData, headers);
10581071
} else if (format === SceneFormat.KSplat) {
1059-
return KSplatLoader.loadFromURL(path, onProgress, progressiveBuild, onSectionBuilt);
1072+
return KSplatLoader.loadFromURL(path, onProgress, progressiveBuild, onSectionBuilt, headers);
10601073
} else if (format === SceneFormat.Ply) {
1061-
return PlyLoader.loadFromURL(path, onProgress, progressiveBuild, onSectionBuilt,
1062-
splatAlphaRemovalThreshold, this.inMemoryCompressionLevel,
1063-
optimizeSplatData, this.sphericalHarmonicsDegree);
1074+
return PlyLoader.loadFromURL(path, onProgress, progressiveBuild, onSectionBuilt, splatAlphaRemovalThreshold,
1075+
this.inMemoryCompressionLevel, optimizeSplatData, this.sphericalHarmonicsDegree, headers);
10641076
}
10651077
} catch (e) {
10661078
if (e instanceof DirectLoadError) {
@@ -1870,7 +1882,7 @@ export class Viewer {
18701882
mvpMatrix.copy(this.camera.matrixWorld).invert();
18711883
const mvpCamera = this.perspectiveCamera || this.camera;
18721884
mvpMatrix.premultiply(mvpCamera.projectionMatrix);
1873-
mvpMatrix.multiply(this.splatMesh.matrixWorld);
1885+
if (!this.splatMesh.dynamicMode) mvpMatrix.multiply(this.splatMesh.matrixWorld);
18741886

18751887
let gpuAcceleratedSortPromise = Promise.resolve(true);
18761888
if (this.gpuAcceleratedSort && (queuedSorts.length <= 1 || queuedSorts.length % 2 === 0)) {
@@ -1979,7 +1991,7 @@ export class Viewer {
19791991

19801992
if (splatTree) {
19811993
baseModelView.copy(this.camera.matrixWorld).invert();
1982-
baseModelView.multiply(this.splatMesh.matrixWorld);
1994+
if (!this.splatMesh.dynamicMode) baseModelView.multiply(this.splatMesh.matrixWorld);
19831995

19841996
let nodeRenderCount = 0;
19851997
let splatRenderCount = 0;

src/loaders/ksplat/KSplatLoader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class KSplatLoader {
1919
}
2020
};
2121

22-
static loadFromURL(fileName, externalOnProgress, loadDirectoToSplatBuffer, onSectionBuilt) {
22+
static loadFromURL(fileName, externalOnProgress, loadDirectoToSplatBuffer, onSectionBuilt, headers) {
2323
let directLoadBuffer;
2424
let directLoadSplatBuffer;
2525

@@ -196,7 +196,7 @@ export class KSplatLoader {
196196
}
197197
};
198198

199-
return fetchWithProgress(fileName, localOnProgress, !loadDirectoToSplatBuffer).then((fullBuffer) => {
199+
return fetchWithProgress(fileName, localOnProgress, !loadDirectoToSplatBuffer, headers).then((fullBuffer) => {
200200
if (externalOnProgress) externalOnProgress(0, '0%', LoaderStatus.Processing);
201201
const loadPromise = loadDirectoToSplatBuffer ? directLoadPromise.promise : KSplatLoader.loadFromFileData(fullBuffer);
202202
return loadPromise.then((splatBuffer) => {

src/loaders/ply/PlyLoader.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ function finalize(splatData, optimizeSplatData, minimumAlpha, compressionLevel,
4343

4444
export class PlyLoader {
4545

46-
static loadFromURL(fileName, onProgress, loadDirectoToSplatBuffer, onProgressiveLoadSectionProgress, minimumAlpha, compressionLevel,
47-
optimizeSplatData = true, outSphericalHarmonicsDegree = 0, sectionSize, sceneCenter, blockSize, bucketSize) {
46+
static loadFromURL(fileName, onProgress, loadDirectoToSplatBuffer, onProgressiveLoadSectionProgress,
47+
minimumAlpha, compressionLevel, optimizeSplatData = true, outSphericalHarmonicsDegree = 0,
48+
headers, sectionSize, sceneCenter, blockSize, bucketSize) {
4849

4950
let internalLoadType = loadDirectoToSplatBuffer ? InternalLoadType.DirectToSplatBuffer : InternalLoadType.DirectToSplatArray;
5051
if (optimizeSplatData) internalLoadType = InternalLoadType.DirectToSplatArray;
@@ -256,7 +257,7 @@ export class PlyLoader {
256257
};
257258

258259
if (onProgress) onProgress(0, '0%', LoaderStatus.Downloading);
259-
return fetchWithProgress(fileName, localOnProgress, false).then(() => {
260+
return fetchWithProgress(fileName, localOnProgress, false, headers).then(() => {
260261
if (onProgress) onProgress(0, '0%', LoaderStatus.Processing);
261262
return loadPromise.promise.then((splatData) => {
262263
if (onProgress) onProgress(100, '100%', LoaderStatus.Done);

src/loaders/splat/SplatLoader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function finalize(splatData, optimizeSplatData, minimumAlpha, compressionLevel,
2323
export class SplatLoader {
2424

2525
static loadFromURL(fileName, onProgress, loadDirectoToSplatBuffer, onProgressiveLoadSectionProgress, minimumAlpha, compressionLevel,
26-
optimizeSplatData = true, sectionSize, sceneCenter, blockSize, bucketSize) {
26+
optimizeSplatData = true, headers, sectionSize, sceneCenter, blockSize, bucketSize) {
2727

2828
let internalLoadType = loadDirectoToSplatBuffer ? InternalLoadType.DirectToSplatBuffer : InternalLoadType.DirectToSplatArray;
2929
if (optimizeSplatData) internalLoadType = InternalLoadType.DirectToSplatArray;
@@ -149,7 +149,7 @@ export class SplatLoader {
149149
};
150150

151151
if (onProgress) onProgress(0, '0%', LoaderStatus.Downloading);
152-
return fetchWithProgress(fileName, localOnProgress, false).then(() => {
152+
return fetchWithProgress(fileName, localOnProgress, false, headers).then(() => {
153153
if (onProgress) onProgress(0, '0%', LoaderStatus.Processing);
154154
return loadPromise.promise.then((splatData) => {
155155
if (onProgress) onProgress(100, '100%', LoaderStatus.Done);

src/splatmesh/SplatMaterial.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export class SplatMaterial {
140140
if (dynamicMode) {
141141
vertexShaderSource += `
142142
mat4 transform = transforms[sceneIndex];
143-
mat4 transformModelViewMatrix = modelViewMatrix * transform;
143+
mat4 transformModelViewMatrix = viewMatrix * transform;
144144
`;
145145
} else {
146146
vertexShaderSource += `mat4 transformModelViewMatrix = modelViewMatrix;`;

0 commit comments

Comments
 (0)