Skip to content

Commit

Permalink
Update splat sorting (#323)
Browse files Browse the repository at this point in the history
  • Loading branch information
slimbuck authored Dec 10, 2024
1 parent 2cf7c7f commit 5b8f6a9
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/splat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
Mat4,
Quat,
Texture,
Vec3
Vec3,
MeshInstance
} from 'playcanvas';

import { Element, ElementType } from './element';
Expand Down Expand Up @@ -88,6 +89,24 @@ class Splat extends Element {

const instance = this.entity.gsplat.instance;

// use custom render order distance calculation for splats
instance.meshInstance.calculateSortDistance = (meshInstance: MeshInstance, pos: Vec3, dir: Vec3) => {
const bound = this.localBound;
const mat = this.entity.getWorldTransform();
let maxDist;
for (let i = 0; i < 8; ++i) {
vec.x = bound.center.x + bound.halfExtents.x * (i & 1 ? 1 : -1);
vec.y = bound.center.y + bound.halfExtents.y * (i & 2 ? 1 : -1);
vec.z = bound.center.z + bound.halfExtents.z * (i & 4 ? 1 : -1);
mat.transformPoint(vec, vec);
const dist = vec.sub(pos).dot(dir);
if (i === 0 || dist > maxDist) {
maxDist = dist;
}
}
return maxDist;
};

// added per-splat state channel
// bit 1: selected
// bit 2: deleted
Expand Down

0 comments on commit 5b8f6a9

Please sign in to comment.