Skip to content

Commit 016a0eb

Browse files
authored
Latest engine and support streaming sog (#353)
1 parent 09eb11e commit 016a0eb

File tree

3 files changed

+52
-26
lines changed

3 files changed

+52
-26
lines changed

package-lock.json

Lines changed: 4 additions & 4 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
@@ -42,7 +42,7 @@
4242
"eslint": "^9.37.0",
4343
"eslint-import-resolver-typescript": "^4.4.4",
4444
"globals": "^16.4.0",
45-
"playcanvas": "^2.12.3",
45+
"playcanvas": "^2.13.2",
4646
"qrious": "^4.0.2",
4747
"react": "^18.3.1",
4848
"react-dom": "^18.3.1",

src/viewer.ts

Lines changed: 47 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -929,14 +929,15 @@ class Viewer {
929929

930930
// update mesh stats
931931
this.assets.forEach((asset) => {
932-
if (asset.resource instanceof GSplatResourceBase) {
933-
const resource = asset.resource as GSplatResource;
934-
935-
meshCount++;
936-
materialCount++;
937-
primitiveCount += resource.gsplatData.numSplats;
938-
vertexCount += resource.gsplatData.numSplats * 4;
939-
meshVRAM += resource.gsplatData.numSplats * 64; // 16 * float32
932+
if (asset.type === 'gsplat') {
933+
const resource = asset.resource;
934+
935+
if (resource instanceof GSplatResource) {
936+
meshCount++;
937+
materialCount++;
938+
primitiveCount += resource.gsplatData.numSplats;
939+
vertexCount += resource.gsplatData.numSplats * 4;
940+
}
940941
} else {
941942
// ContainerResource type isn't picked up correctly for some reason
942943
const resource = asset.resource as any;
@@ -1653,15 +1654,19 @@ class Viewer {
16531654
// container/glb
16541655
entity = resource.instantiateRenderEntity();
16551656
} else {
1657+
const unified = ((asset.file as any)?.filename ?? '').endsWith('lod-meta.json');
1658+
16561659
// gaussian splat scene
16571660
entity = new Entity();
16581661
entity.setEulerAngles(0, 0, 180);
1659-
entity.addComponent('gsplat', { asset });
1662+
entity.addComponent('gsplat', { unified, asset });
16601663

16611664
// render frame if gaussian splat sorter updates)
1662-
entity.gsplat.instance.sorter.on('updated', () => {
1663-
this.renderNextFrame();
1664-
});
1665+
if (!unified) {
1666+
entity.gsplat.instance.sorter.on('updated', () => {
1667+
this.renderNextFrame();
1668+
});
1669+
}
16651670
}
16661671

16671672
this.entities.push(entity);
@@ -1826,17 +1831,38 @@ class Viewer {
18261831
}
18271832

18281833
private calcSceneBounds(result: BoundingBox, root: Entity | null = null) {
1829-
const meshInstances = root ? this.collectMeshInstances(root) : this.meshInstances;
1830-
if (meshInstances.length) {
1831-
Viewer.calcMeshBoundingBox(result, meshInstances);
1832-
} else {
1833-
root = root ?? this.sceneRoot;
1834-
if (root.children.length) {
1835-
Viewer.calcHierBoundingBox(result, root);
1836-
} else {
1837-
result.copy(defaultSceneBounds);
1834+
const entities = root ? [root] : this.entities;
1835+
1836+
let first = true;
1837+
1838+
const renderComponents = entities.map(e => e.findComponents('render') as RenderComponent[]).flat().map(rc => rc.meshInstances).flat();
1839+
if (renderComponents.length) {
1840+
for (let i = 0; i < renderComponents.length; ++i) {
1841+
if (first) {
1842+
result.copy(renderComponents[i].aabb);
1843+
first = false;
1844+
} else {
1845+
result.add(renderComponents[i].aabb);
1846+
}
18381847
}
18391848
}
1849+
1850+
const gsplatComponents = entities.map(e => e.findComponents('gsplat') as GSplatComponent[]).flat().filter(gc => !!gc.customAabb);
1851+
if (gsplatComponents.length) {
1852+
for (let i = 0; i < gsplatComponents.length; ++i) {
1853+
bbox.setFromTransformedAabb(gsplatComponents[i].customAabb, gsplatComponents[i].entity.getWorldTransform());
1854+
if (first) {
1855+
result.copy(bbox);
1856+
first = false;
1857+
} else {
1858+
result.add(bbox);
1859+
}
1860+
}
1861+
}
1862+
1863+
if (first) {
1864+
result.copy(defaultSceneBounds);
1865+
}
18401866
}
18411867

18421868
private resetWireframeMeshes() {

0 commit comments

Comments
 (0)