Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 34 additions & 16 deletions src/scene/gsplat-unified/gsplat-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ class GSplatManager {
/** @type {number} */
sortedVersion = 0;

/** @type {number} */
framesTillFullUpdate = 0;

/** @type {Vec3} */
lastCameraPos = new Vec3(Infinity, Infinity, Infinity);

Expand Down Expand Up @@ -353,27 +356,42 @@ class GSplatManager {

update() {

// process any pending / prefetch resource completions and collect LOD updates
let anyInstanceNeedsLodUpdate = false;
for (const [, inst] of this.octreeInstances) {

const isDirty = inst.update(this.scene);
this.layerPlacementsDirty ||= isDirty;
let fullUpdate = false;
this.framesTillFullUpdate--;
if (this.framesTillFullUpdate <= 0) {
this.framesTillFullUpdate = 10;

const instNeeds = inst.consumeNeedsLodUpdate();
anyInstanceNeedsLodUpdate ||= instNeeds;
// if sorter can keep up
if (this.sorter.jobsInFlight < 3) {
fullUpdate = true;
}
}

// check if any octree instances have moved enough to require LOD update
let anyInstanceNeedsLodUpdate = false;
let anyOctreeMoved = false;
const threshold = this.scene.gsplat.lodUpdateDistance;
for (const [, inst] of this.octreeInstances) {
const moved = inst.testMoved(threshold);
anyOctreeMoved ||= moved;
}
let cameraMovedOrRotated = false;
if (fullUpdate) {

// process any pending / prefetch resource completions and collect LOD updates
for (const [, inst] of this.octreeInstances) {

const isDirty = inst.update(this.scene);
this.layerPlacementsDirty ||= isDirty;

const instNeeds = inst.consumeNeedsLodUpdate();
anyInstanceNeedsLodUpdate ||= instNeeds;
}

// check if camera has moved/rotated enough to require LOD update
const cameraMovedOrRotated = this.testCameraMoved();
// check if any octree instances have moved enough to require LOD update
const threshold = this.scene.gsplat.lodUpdateDistance;
for (const [, inst] of this.octreeInstances) {
const moved = inst.testMoved(threshold);
anyOctreeMoved ||= moved;
}

// check if camera has moved/rotated enough to require LOD update
cameraMovedOrRotated = this.testCameraMoved();
}

// if parameters are dirty, rebuild world state
if (this.scene.gsplat.dirty) {
Expand Down