Skip to content

Commit

Permalink
Render compressed GS data (#6371)
Browse files Browse the repository at this point in the history
  • Loading branch information
slimbuck committed May 20, 2024
1 parent 56d4ded commit d09fa8c
Show file tree
Hide file tree
Showing 9 changed files with 982 additions and 367 deletions.
37 changes: 4 additions & 33 deletions src/framework/parsers/gsplat-resource.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BoundingBox } from '../../core/shape/bounding-box.js';
import { Entity } from '../entity.js';
import { GSplatInstance } from '../../scene/gsplat/gsplat-instance.js';
import { GSplat } from '../../scene/gsplat/gsplat.js';
import { GSplatCompressed } from '../../scene/gsplat/gsplat-compressed.js';

/**
* The resource for the gsplat asset type.
Expand All @@ -22,7 +22,7 @@ class GSplatResource {
splatData;

/**
* @type {GSplat | null}
* @type {GSplat | GSplatCompressed | null}
* @ignore
*/
splat = null;
Expand All @@ -34,7 +34,7 @@ class GSplatResource {
*/
constructor(device, splatData) {
this.device = device;
this.splatData = splatData.isCompressed ? splatData.decompress() : splatData;
this.splatData = splatData;
}

destroy() {
Expand All @@ -46,37 +46,8 @@ class GSplatResource {

createSplat() {
if (!this.splat) {

const splatData = this.splatData;

const aabb = new BoundingBox();
this.splatData.calcAabb(aabb);

const splat = new GSplat(this.device, splatData.numSplats, aabb);
this.splat = splat;

// texture data
splat.updateColorData(splatData.getProp('f_dc_0'), splatData.getProp('f_dc_1'), splatData.getProp('f_dc_2'), splatData.getProp('opacity'));
splat.updateTransformData(
splatData.getProp('x'), splatData.getProp('y'), splatData.getProp('z'),
splatData.getProp('rot_0'), splatData.getProp('rot_1'), splatData.getProp('rot_2'), splatData.getProp('rot_3'),
splatData.getProp('scale_0'), splatData.getProp('scale_1'), splatData.getProp('scale_2')
);

// centers - constant buffer that is sent to the worker
const x = splatData.getProp('x');
const y = splatData.getProp('y');
const z = splatData.getProp('z');

const centers = new Float32Array(this.splatData.numSplats * 3);
for (let i = 0; i < this.splatData.numSplats; ++i) {
centers[i * 3 + 0] = x[i];
centers[i * 3 + 1] = y[i];
centers[i * 3 + 2] = z[i];
}
splat.centers = centers;
this.splat = this.splatData.isCompressed ? new GSplatCompressed(this.device, this.splatData) : new GSplat(this.device, this.splatData);
}

return this.splat;
}

Expand Down
10 changes: 9 additions & 1 deletion src/framework/parsers/ply.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,19 @@ class PlyParser {
} else {
readPly(response.body.getReader(), asset.data.elementFilter ?? defaultElementFilter)
.then((response) => {
// construct the GSplatData object
const gsplatData = new GSplatData(response, {
performZScale: asset.data.performZScale,
reorder: asset.data.reorder
});
callback(null, new GSplatResource(this.device, gsplatData));

// construct the resource
const resource = new GSplatResource(
this.device,
gsplatData.isCompressed && asset.data.decompress ? gsplatData.decompress() : gsplatData
);

callback(null, resource);
})
.catch((err) => {
callback(err, null);
Expand Down

0 comments on commit d09fa8c

Please sign in to comment.