Spaces:
Running
Running
Commit
·
537f2af
1
Parent(s):
95af024
use gsplat package
Browse files- viewer/bun.lockb +0 -0
- viewer/package.json +2 -1
- viewer/src/lib/splat.js/cameras/Camera.ts +0 -45
- viewer/src/lib/splat.js/controls/OrbitControls.ts +0 -147
- viewer/src/lib/splat.js/core/Object3D.ts +0 -14
- viewer/src/lib/splat.js/core/Scene.ts +0 -22
- viewer/src/lib/splat.js/index.ts +0 -10
- viewer/src/lib/splat.js/loaders/Loader.ts +0 -34
- viewer/src/lib/splat.js/math/Matrix3.ts +0 -82
- viewer/src/lib/splat.js/math/Matrix4.ts +0 -69
- viewer/src/lib/splat.js/math/Quaternion.ts +0 -73
- viewer/src/lib/splat.js/math/Vector3.ts +0 -98
- viewer/src/lib/splat.js/renderers/Renderer.ts +0 -9
- viewer/src/lib/splat.js/renderers/WebGLRenderer.ts +0 -225
- viewer/src/lib/splat.js/renderers/webgl/shaders/frag.glsl.ts +0 -13
- viewer/src/lib/splat.js/renderers/webgl/shaders/vertex.glsl.ts +0 -75
- viewer/src/lib/splat.js/renderers/webgl/utils/worker.ts +0 -254
- viewer/src/routes/viewer/[slug]/SplatViewer.ts +2 -2
viewer/bun.lockb
CHANGED
Binary files a/viewer/bun.lockb and b/viewer/bun.lockb differ
|
|
viewer/package.json
CHANGED
@@ -23,6 +23,7 @@
|
|
23 |
"type": "module",
|
24 |
"dependencies": {
|
25 |
"@babylonjs/core": "^6.23.0",
|
26 |
-
"@babylonjs/loaders": "^6.23.0"
|
|
|
27 |
}
|
28 |
}
|
|
|
23 |
"type": "module",
|
24 |
"dependencies": {
|
25 |
"@babylonjs/core": "^6.23.0",
|
26 |
+
"@babylonjs/loaders": "^6.23.0",
|
27 |
+
"gsplat": "^0.1.0"
|
28 |
}
|
29 |
}
|
viewer/src/lib/splat.js/cameras/Camera.ts
DELETED
@@ -1,45 +0,0 @@
|
|
1 |
-
import { Object3D } from "../core/Object3D";
|
2 |
-
import { Matrix3 } from "../math/Matrix3";
|
3 |
-
import { Matrix4 } from "../math/Matrix4";
|
4 |
-
import { Vector3 } from "../math/Vector3";
|
5 |
-
|
6 |
-
class Camera extends Object3D {
|
7 |
-
fx: number;
|
8 |
-
fy: number;
|
9 |
-
|
10 |
-
near: number;
|
11 |
-
far: number;
|
12 |
-
|
13 |
-
projectionMatrix: Matrix4;
|
14 |
-
|
15 |
-
constructor(
|
16 |
-
position: Vector3 = new Vector3(0, 0, -5),
|
17 |
-
rotation: Matrix3 = new Matrix3(),
|
18 |
-
fx: number = 1132,
|
19 |
-
fy: number = 1132,
|
20 |
-
near: number = 0.1,
|
21 |
-
far: number = 100
|
22 |
-
) {
|
23 |
-
super();
|
24 |
-
|
25 |
-
this.position = position;
|
26 |
-
this.rotation = rotation;
|
27 |
-
this.fx = fx;
|
28 |
-
this.fy = fy;
|
29 |
-
this.near = near;
|
30 |
-
this.far = far;
|
31 |
-
this.projectionMatrix = new Matrix4();
|
32 |
-
}
|
33 |
-
|
34 |
-
updateProjectionMatrix(width: number, height: number): void {
|
35 |
-
// prettier-ignore
|
36 |
-
this.projectionMatrix.set(
|
37 |
-
2 * this.fx / width, 0, 0, 0,
|
38 |
-
0, -2 * this.fy / height, 0, 0,
|
39 |
-
0, 0, this.far / (this.far - this.near), 1,
|
40 |
-
0, 0, -(this.far * this.near) / (this.far - this.near), 0
|
41 |
-
);
|
42 |
-
}
|
43 |
-
}
|
44 |
-
|
45 |
-
export { Camera };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
viewer/src/lib/splat.js/controls/OrbitControls.ts
DELETED
@@ -1,147 +0,0 @@
|
|
1 |
-
import type { Camera } from "../cameras/Camera";
|
2 |
-
import { Matrix3 } from "../math/Matrix3";
|
3 |
-
import { Vector3 } from "../math/Vector3";
|
4 |
-
|
5 |
-
class OrbitControls {
|
6 |
-
minBeta: number = (5 * Math.PI) / 180;
|
7 |
-
maxBeta: number = (85 * Math.PI) / 180;
|
8 |
-
minZoom: number = 0.1;
|
9 |
-
maxZoom: number = 30;
|
10 |
-
orbitSpeed: number = 1;
|
11 |
-
panSpeed: number = 1;
|
12 |
-
zoomSpeed: number = 1;
|
13 |
-
dampening: number = 0.3;
|
14 |
-
|
15 |
-
update: () => void;
|
16 |
-
dispose: () => void;
|
17 |
-
|
18 |
-
constructor(camera: Camera, domElement: HTMLElement) {
|
19 |
-
let target = new Vector3();
|
20 |
-
let alpha = 0;
|
21 |
-
let beta = 0;
|
22 |
-
let radius = 5;
|
23 |
-
|
24 |
-
let desiredTarget = target.clone();
|
25 |
-
let desiredAlpha = alpha;
|
26 |
-
let desiredBeta = beta;
|
27 |
-
let desiredRadius = radius;
|
28 |
-
|
29 |
-
let dragging = false;
|
30 |
-
let panning = false;
|
31 |
-
let lastX = 0;
|
32 |
-
let lastY = 0;
|
33 |
-
|
34 |
-
const computeZoomNorm = () => {
|
35 |
-
return 0.1 + (0.9 * (desiredRadius - this.minZoom)) / (this.maxZoom - this.minZoom);
|
36 |
-
};
|
37 |
-
|
38 |
-
const onPointerDown = (e: PointerEvent) => {
|
39 |
-
preventDefault(e);
|
40 |
-
|
41 |
-
dragging = true;
|
42 |
-
if (e.pointerType === "touch") {
|
43 |
-
panning = e.pointerId === 2;
|
44 |
-
} else {
|
45 |
-
panning = e.button === 2;
|
46 |
-
}
|
47 |
-
lastX = e.clientX;
|
48 |
-
lastY = e.clientY;
|
49 |
-
window.addEventListener("pointerup", onPointerUp);
|
50 |
-
window.addEventListener("pointercancel", onPointerUp);
|
51 |
-
};
|
52 |
-
|
53 |
-
const onPointerUp = (e: PointerEvent) => {
|
54 |
-
preventDefault(e);
|
55 |
-
|
56 |
-
dragging = false;
|
57 |
-
panning = false;
|
58 |
-
window.removeEventListener("pointerup", onPointerUp);
|
59 |
-
window.removeEventListener("pointercancel", onPointerUp);
|
60 |
-
};
|
61 |
-
|
62 |
-
const onPointerMove = (e: PointerEvent) => {
|
63 |
-
preventDefault(e);
|
64 |
-
|
65 |
-
if (!dragging) return;
|
66 |
-
|
67 |
-
const dx = e.clientX - lastX;
|
68 |
-
const dy = e.clientY - lastY;
|
69 |
-
const zoomNorm = computeZoomNorm();
|
70 |
-
|
71 |
-
if (panning) {
|
72 |
-
const panX = -dx * this.panSpeed * 0.01 * zoomNorm;
|
73 |
-
const panY = -dy * this.panSpeed * 0.01 * zoomNorm;
|
74 |
-
const R = camera.rotation.buffer;
|
75 |
-
const right = new Vector3(R[0], R[3], R[6]);
|
76 |
-
const up = new Vector3(R[1], R[4], R[7]);
|
77 |
-
desiredTarget.add(right.multiply(panX));
|
78 |
-
desiredTarget.add(up.multiply(panY));
|
79 |
-
} else {
|
80 |
-
desiredAlpha -= dx * this.orbitSpeed * 0.005;
|
81 |
-
desiredBeta += dy * this.orbitSpeed * 0.005;
|
82 |
-
desiredBeta = Math.min(Math.max(desiredBeta, this.minBeta), this.maxBeta);
|
83 |
-
}
|
84 |
-
|
85 |
-
lastX = e.clientX;
|
86 |
-
lastY = e.clientY;
|
87 |
-
};
|
88 |
-
|
89 |
-
const onWheel = (e: WheelEvent) => {
|
90 |
-
preventDefault(e);
|
91 |
-
|
92 |
-
const zoomNorm = computeZoomNorm();
|
93 |
-
desiredRadius += e.deltaY * this.zoomSpeed * 0.02 * zoomNorm;
|
94 |
-
desiredRadius = Math.min(Math.max(desiredRadius, this.minZoom), this.maxZoom);
|
95 |
-
};
|
96 |
-
|
97 |
-
const lerp = (a: number, b: number, t: number) => {
|
98 |
-
return (1 - t) * a + t * b;
|
99 |
-
};
|
100 |
-
|
101 |
-
this.update = () => {
|
102 |
-
alpha = lerp(alpha, desiredAlpha, this.dampening);
|
103 |
-
beta = lerp(beta, desiredBeta, this.dampening);
|
104 |
-
radius = lerp(radius, desiredRadius, this.dampening);
|
105 |
-
target = target.lerp(desiredTarget, this.dampening);
|
106 |
-
|
107 |
-
const x = target.x + radius * Math.sin(alpha) * Math.cos(beta);
|
108 |
-
const y = target.y - radius * Math.sin(beta);
|
109 |
-
const z = target.z - radius * Math.cos(alpha) * Math.cos(beta);
|
110 |
-
camera.position.set(x, y, z);
|
111 |
-
|
112 |
-
const direction = target.clone().subtract(camera.position).normalize();
|
113 |
-
const rx = Math.asin(-direction.y);
|
114 |
-
const ry = Math.atan2(direction.x, direction.z);
|
115 |
-
camera.rotation = Matrix3.RotationFromEuler(new Vector3(rx, ry, 0));
|
116 |
-
};
|
117 |
-
|
118 |
-
const preventDefault = (e: Event) => {
|
119 |
-
e.preventDefault();
|
120 |
-
e.stopPropagation();
|
121 |
-
};
|
122 |
-
|
123 |
-
this.dispose = () => {
|
124 |
-
domElement.removeEventListener("dragenter", preventDefault);
|
125 |
-
domElement.removeEventListener("dragover", preventDefault);
|
126 |
-
domElement.removeEventListener("dragleave", preventDefault);
|
127 |
-
domElement.removeEventListener("contextmenu", preventDefault);
|
128 |
-
|
129 |
-
domElement.removeEventListener("pointerdown", onPointerDown);
|
130 |
-
domElement.removeEventListener("pointermove", onPointerMove);
|
131 |
-
domElement.removeEventListener("wheel", onWheel);
|
132 |
-
};
|
133 |
-
|
134 |
-
domElement.addEventListener("dragenter", preventDefault);
|
135 |
-
domElement.addEventListener("dragover", preventDefault);
|
136 |
-
domElement.addEventListener("dragleave", preventDefault);
|
137 |
-
domElement.addEventListener("contextmenu", preventDefault);
|
138 |
-
|
139 |
-
domElement.addEventListener("pointerdown", onPointerDown);
|
140 |
-
domElement.addEventListener("pointermove", onPointerMove);
|
141 |
-
domElement.addEventListener("wheel", onWheel);
|
142 |
-
|
143 |
-
this.update();
|
144 |
-
}
|
145 |
-
}
|
146 |
-
|
147 |
-
export { OrbitControls };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
viewer/src/lib/splat.js/core/Object3D.ts
DELETED
@@ -1,14 +0,0 @@
|
|
1 |
-
import { Vector3 } from "../math/Vector3";
|
2 |
-
import { Matrix3 } from "../math/Matrix3";
|
3 |
-
|
4 |
-
class Object3D {
|
5 |
-
position: Vector3;
|
6 |
-
rotation: Matrix3;
|
7 |
-
|
8 |
-
constructor() {
|
9 |
-
this.position = new Vector3();
|
10 |
-
this.rotation = new Matrix3();
|
11 |
-
}
|
12 |
-
}
|
13 |
-
|
14 |
-
export { Object3D };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
viewer/src/lib/splat.js/core/Scene.ts
DELETED
@@ -1,22 +0,0 @@
|
|
1 |
-
import { Object3D } from "./Object3D";
|
2 |
-
|
3 |
-
class Scene extends Object3D {
|
4 |
-
data: Uint8Array;
|
5 |
-
vertexCount: number;
|
6 |
-
|
7 |
-
constructor() {
|
8 |
-
super();
|
9 |
-
|
10 |
-
this.data = new Uint8Array(0);
|
11 |
-
this.vertexCount = 0;
|
12 |
-
}
|
13 |
-
|
14 |
-
setData(data: Uint8Array): void {
|
15 |
-
this.data = data;
|
16 |
-
|
17 |
-
const rowLength = 3 * 4 + 3 * 4 + 4 + 4;
|
18 |
-
this.vertexCount = data.length / rowLength;
|
19 |
-
}
|
20 |
-
}
|
21 |
-
|
22 |
-
export { Scene };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
viewer/src/lib/splat.js/index.ts
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
export { Camera } from "./cameras/Camera";
|
2 |
-
export { Renderer } from "./renderers/Renderer";
|
3 |
-
export { Scene } from "./core/Scene";
|
4 |
-
export { Loader } from "./loaders/Loader";
|
5 |
-
export { WebGLRenderer } from "./renderers/WebGLRenderer";
|
6 |
-
export { OrbitControls } from "./controls/OrbitControls";
|
7 |
-
export { Quaternion } from "./math/Quaternion";
|
8 |
-
export { Vector3 } from "./math/Vector3";
|
9 |
-
export { Matrix4 } from "./math/Matrix4";
|
10 |
-
export { Matrix3 } from "./math/Matrix3";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
viewer/src/lib/splat.js/loaders/Loader.ts
DELETED
@@ -1,34 +0,0 @@
|
|
1 |
-
import type { Scene } from "../core/Scene";
|
2 |
-
|
3 |
-
class Loader {
|
4 |
-
static async LoadAsync(url: string, scene: Scene, onProgress?: (progress: number) => void): Promise<void> {
|
5 |
-
const req = await fetch(url, {
|
6 |
-
mode: "cors",
|
7 |
-
credentials: "omit",
|
8 |
-
});
|
9 |
-
|
10 |
-
if (req.status != 200) {
|
11 |
-
throw new Error(req.status + " Unable to load " + req.url);
|
12 |
-
}
|
13 |
-
|
14 |
-
const reader = req.body!.getReader();
|
15 |
-
const contentLength = parseInt(req.headers.get("content-length") as string);
|
16 |
-
const data = new Uint8Array(contentLength);
|
17 |
-
|
18 |
-
let bytesRead = 0;
|
19 |
-
|
20 |
-
while (true) {
|
21 |
-
const { done, value } = await reader.read();
|
22 |
-
if (done) break;
|
23 |
-
|
24 |
-
data.set(value, bytesRead);
|
25 |
-
bytesRead += value.length;
|
26 |
-
|
27 |
-
onProgress?.(bytesRead / contentLength);
|
28 |
-
}
|
29 |
-
|
30 |
-
scene.setData(data);
|
31 |
-
}
|
32 |
-
}
|
33 |
-
|
34 |
-
export { Loader };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
viewer/src/lib/splat.js/math/Matrix3.ts
DELETED
@@ -1,82 +0,0 @@
|
|
1 |
-
import type { Vector3 } from "./Vector3";
|
2 |
-
|
3 |
-
class Matrix3 {
|
4 |
-
buffer: number[];
|
5 |
-
|
6 |
-
// prettier-ignore
|
7 |
-
constructor(n11: number = 1, n12: number = 0, n13: number = 0,
|
8 |
-
n21: number = 0, n22: number = 1, n23: number = 0,
|
9 |
-
n31: number = 0, n32: number = 0, n33: number = 1) {
|
10 |
-
this.buffer = new Array(9);
|
11 |
-
|
12 |
-
this.set(
|
13 |
-
n11, n12, n13,
|
14 |
-
n21, n22, n23,
|
15 |
-
n31, n32, n33
|
16 |
-
);
|
17 |
-
}
|
18 |
-
|
19 |
-
// prettier-ignore
|
20 |
-
set(n11: number, n12: number, n13: number,
|
21 |
-
n21: number, n22: number, n23: number,
|
22 |
-
n31: number, n32: number, n33: number): Matrix3 {
|
23 |
-
const e = this.buffer;
|
24 |
-
|
25 |
-
e[0] = n11; e[1] = n12; e[2] = n13;
|
26 |
-
e[3] = n21; e[4] = n22; e[5] = n23;
|
27 |
-
e[6] = n31; e[7] = n32; e[8] = n33;
|
28 |
-
|
29 |
-
return this;
|
30 |
-
}
|
31 |
-
|
32 |
-
multiply(m: Matrix3): Matrix3 {
|
33 |
-
const a = this.buffer;
|
34 |
-
const b = m.buffer;
|
35 |
-
return new Matrix3(
|
36 |
-
b[0] * a[0] + b[1] * a[3] + b[2] * a[6],
|
37 |
-
b[0] * a[1] + b[1] * a[4] + b[2] * a[7],
|
38 |
-
b[0] * a[2] + b[1] * a[5] + b[2] * a[8],
|
39 |
-
b[3] * a[0] + b[4] * a[3] + b[5] * a[6],
|
40 |
-
b[3] * a[1] + b[4] * a[4] + b[5] * a[7],
|
41 |
-
b[3] * a[2] + b[4] * a[5] + b[5] * a[8],
|
42 |
-
b[6] * a[0] + b[7] * a[3] + b[8] * a[6],
|
43 |
-
b[6] * a[1] + b[7] * a[4] + b[8] * a[7],
|
44 |
-
b[6] * a[2] + b[7] * a[5] + b[8] * a[8]
|
45 |
-
);
|
46 |
-
}
|
47 |
-
|
48 |
-
clone(): Matrix3 {
|
49 |
-
const e = this.buffer;
|
50 |
-
// prettier-ignore
|
51 |
-
return new Matrix3(
|
52 |
-
e[0], e[1], e[2],
|
53 |
-
e[3], e[4], e[5],
|
54 |
-
e[6], e[7], e[8]
|
55 |
-
);
|
56 |
-
}
|
57 |
-
|
58 |
-
static RotationFromEuler(m: Vector3): Matrix3 {
|
59 |
-
const cx = Math.cos(m.x);
|
60 |
-
const sx = Math.sin(m.x);
|
61 |
-
const cy = Math.cos(m.y);
|
62 |
-
const sy = Math.sin(m.y);
|
63 |
-
const cz = Math.cos(m.z);
|
64 |
-
const sz = Math.sin(m.z);
|
65 |
-
|
66 |
-
const rotationMatrix = [
|
67 |
-
cy * cz + sy * sx * sz,
|
68 |
-
-cy * sz + sy * sx * cz,
|
69 |
-
sy * cx,
|
70 |
-
cx * sz,
|
71 |
-
cx * cz,
|
72 |
-
-sx,
|
73 |
-
-sy * cz + cy * sx * sz,
|
74 |
-
sy * sz + cy * sx * cz,
|
75 |
-
cy * cx,
|
76 |
-
];
|
77 |
-
|
78 |
-
return new Matrix3(...rotationMatrix);
|
79 |
-
}
|
80 |
-
}
|
81 |
-
|
82 |
-
export { Matrix3 };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
viewer/src/lib/splat.js/math/Matrix4.ts
DELETED
@@ -1,69 +0,0 @@
|
|
1 |
-
class Matrix4 {
|
2 |
-
buffer: number[];
|
3 |
-
|
4 |
-
// prettier-ignore
|
5 |
-
constructor(n11: number = 1, n12: number = 0, n13: number = 0, n14: number = 0,
|
6 |
-
n21: number = 0, n22: number = 1, n23: number = 0, n24: number = 0,
|
7 |
-
n31: number = 0, n32: number = 0, n33: number = 1, n34: number = 0,
|
8 |
-
n41: number = 0, n42: number = 0, n43: number = 0, n44: number = 1) {
|
9 |
-
this.buffer = new Array(16);
|
10 |
-
|
11 |
-
this.set(
|
12 |
-
n11, n12, n13, n14,
|
13 |
-
n21, n22, n23, n24,
|
14 |
-
n31, n32, n33, n34,
|
15 |
-
n41, n42, n43, n44
|
16 |
-
);
|
17 |
-
}
|
18 |
-
|
19 |
-
// prettier-ignore
|
20 |
-
set(n11: number, n12: number, n13: number, n14: number,
|
21 |
-
n21: number, n22: number, n23: number, n24: number,
|
22 |
-
n31: number, n32: number, n33: number, n34: number,
|
23 |
-
n41: number, n42: number, n43: number, n44: number) : Matrix4 {
|
24 |
-
const e = this.buffer;
|
25 |
-
|
26 |
-
e[0] = n11; e[1] = n12; e[2] = n13; e[3] = n14;
|
27 |
-
e[4] = n21; e[5] = n22; e[6] = n23; e[7] = n24;
|
28 |
-
e[8] = n31; e[9] = n32; e[10] = n33; e[11] = n34;
|
29 |
-
e[12] = n41; e[13] = n42; e[14] = n43; e[15] = n44;
|
30 |
-
|
31 |
-
return this;
|
32 |
-
}
|
33 |
-
|
34 |
-
multiply(m: Matrix4): Matrix4 {
|
35 |
-
const a = this.buffer;
|
36 |
-
const b = m.buffer;
|
37 |
-
return new Matrix4(
|
38 |
-
b[0] * a[0] + b[1] * a[4] + b[2] * a[8] + b[3] * a[12],
|
39 |
-
b[0] * a[1] + b[1] * a[5] + b[2] * a[9] + b[3] * a[13],
|
40 |
-
b[0] * a[2] + b[1] * a[6] + b[2] * a[10] + b[3] * a[14],
|
41 |
-
b[0] * a[3] + b[1] * a[7] + b[2] * a[11] + b[3] * a[15],
|
42 |
-
b[4] * a[0] + b[5] * a[4] + b[6] * a[8] + b[7] * a[12],
|
43 |
-
b[4] * a[1] + b[5] * a[5] + b[6] * a[9] + b[7] * a[13],
|
44 |
-
b[4] * a[2] + b[5] * a[6] + b[6] * a[10] + b[7] * a[14],
|
45 |
-
b[4] * a[3] + b[5] * a[7] + b[6] * a[11] + b[7] * a[15],
|
46 |
-
b[8] * a[0] + b[9] * a[4] + b[10] * a[8] + b[11] * a[12],
|
47 |
-
b[8] * a[1] + b[9] * a[5] + b[10] * a[9] + b[11] * a[13],
|
48 |
-
b[8] * a[2] + b[9] * a[6] + b[10] * a[10] + b[11] * a[14],
|
49 |
-
b[8] * a[3] + b[9] * a[7] + b[10] * a[11] + b[11] * a[15],
|
50 |
-
b[12] * a[0] + b[13] * a[4] + b[14] * a[8] + b[15] * a[12],
|
51 |
-
b[12] * a[1] + b[13] * a[5] + b[14] * a[9] + b[15] * a[13],
|
52 |
-
b[12] * a[2] + b[13] * a[6] + b[14] * a[10] + b[15] * a[14],
|
53 |
-
b[12] * a[3] + b[13] * a[7] + b[14] * a[11] + b[15] * a[15]
|
54 |
-
);
|
55 |
-
}
|
56 |
-
|
57 |
-
clone(): Matrix4 {
|
58 |
-
const e = this.buffer;
|
59 |
-
// prettier-ignore
|
60 |
-
return new Matrix4(
|
61 |
-
e[0], e[1], e[2], e[3],
|
62 |
-
e[4], e[5], e[6], e[7],
|
63 |
-
e[8], e[9], e[10], e[11],
|
64 |
-
e[12], e[13], e[14], e[15]
|
65 |
-
);
|
66 |
-
}
|
67 |
-
}
|
68 |
-
|
69 |
-
export { Matrix4 };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
viewer/src/lib/splat.js/math/Quaternion.ts
DELETED
@@ -1,73 +0,0 @@
|
|
1 |
-
import { Matrix3 } from "./Matrix3";
|
2 |
-
import type { Vector3 } from "./Vector3";
|
3 |
-
|
4 |
-
class Quaternion {
|
5 |
-
x: number;
|
6 |
-
y: number;
|
7 |
-
z: number;
|
8 |
-
w: number;
|
9 |
-
|
10 |
-
constructor(x: number = 0, y: number = 0, z: number = 0, w: number = 1) {
|
11 |
-
this.x = x;
|
12 |
-
this.y = y;
|
13 |
-
this.z = z;
|
14 |
-
this.w = w;
|
15 |
-
}
|
16 |
-
|
17 |
-
set(x: number, y: number, z: number, w: number): Quaternion {
|
18 |
-
this.x = x;
|
19 |
-
this.y = y;
|
20 |
-
this.z = z;
|
21 |
-
this.w = w;
|
22 |
-
|
23 |
-
return this;
|
24 |
-
}
|
25 |
-
|
26 |
-
flat(): number[] {
|
27 |
-
return [this.x, this.y, this.z, this.w];
|
28 |
-
}
|
29 |
-
|
30 |
-
clone(): Quaternion {
|
31 |
-
return new Quaternion(this.x, this.y, this.z, this.w);
|
32 |
-
}
|
33 |
-
|
34 |
-
toRotationMatrix(): Matrix3 {
|
35 |
-
const xx = this.x * this.x;
|
36 |
-
const xy = this.x * this.y;
|
37 |
-
const xz = this.x * this.z;
|
38 |
-
const xw = this.x * this.w;
|
39 |
-
const yy = this.y * this.y;
|
40 |
-
const yz = this.y * this.z;
|
41 |
-
const yw = this.y * this.w;
|
42 |
-
const zz = this.z * this.z;
|
43 |
-
const zw = this.z * this.w;
|
44 |
-
|
45 |
-
const m = new Matrix3();
|
46 |
-
// prettier-ignore
|
47 |
-
m.set(
|
48 |
-
1 - 2 * (yy + zz), 2 * (xy - zw), 2 * (xz + yw),
|
49 |
-
2 * (xy + zw), 1 - 2 * (xx + zz), 2 * (yz - xw),
|
50 |
-
2 * (xz - yw), 2 * (yz + xw), 1 - 2 * (xx + yy)
|
51 |
-
)
|
52 |
-
|
53 |
-
return m;
|
54 |
-
}
|
55 |
-
|
56 |
-
static FromEuler(m: Vector3) {
|
57 |
-
const cy = Math.cos(m.y / 2);
|
58 |
-
const sy = Math.sin(m.y / 2);
|
59 |
-
const cp = Math.cos(m.x / 2);
|
60 |
-
const sp = Math.sin(m.x / 2);
|
61 |
-
const cr = Math.cos(m.z / 2);
|
62 |
-
const sr = Math.sin(m.z / 2);
|
63 |
-
|
64 |
-
const w = cy * cp * cr + sy * sp * sr;
|
65 |
-
const x = cy * cp * sr - sy * sp * cr;
|
66 |
-
const y = sy * cp * sr + cy * sp * cr;
|
67 |
-
const z = sy * cp * cr - cy * sp * sr;
|
68 |
-
|
69 |
-
return new Quaternion(x, y, z, w);
|
70 |
-
}
|
71 |
-
}
|
72 |
-
|
73 |
-
export { Quaternion };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
viewer/src/lib/splat.js/math/Vector3.ts
DELETED
@@ -1,98 +0,0 @@
|
|
1 |
-
class Vector3 {
|
2 |
-
x: number;
|
3 |
-
y: number;
|
4 |
-
z: number;
|
5 |
-
|
6 |
-
constructor(x: number = 0, y: number = 0, z: number = 0) {
|
7 |
-
this.x = x;
|
8 |
-
this.y = y;
|
9 |
-
this.z = z;
|
10 |
-
}
|
11 |
-
|
12 |
-
set(x: number, y: number, z: number): Vector3 {
|
13 |
-
this.x = x;
|
14 |
-
this.y = y;
|
15 |
-
this.z = z;
|
16 |
-
|
17 |
-
return this;
|
18 |
-
}
|
19 |
-
|
20 |
-
add(v: Vector3): Vector3;
|
21 |
-
add(v: number): Vector3;
|
22 |
-
add(v: Vector3 | number): Vector3 {
|
23 |
-
if (typeof v === "number") {
|
24 |
-
this.x += v;
|
25 |
-
this.y += v;
|
26 |
-
this.z += v;
|
27 |
-
} else {
|
28 |
-
this.x += v.x;
|
29 |
-
this.y += v.y;
|
30 |
-
this.z += v.z;
|
31 |
-
}
|
32 |
-
|
33 |
-
return this;
|
34 |
-
}
|
35 |
-
|
36 |
-
subtract(v: Vector3): Vector3;
|
37 |
-
subtract(v: number): Vector3;
|
38 |
-
subtract(v: Vector3 | number): Vector3 {
|
39 |
-
if (typeof v === "number") {
|
40 |
-
this.x -= v;
|
41 |
-
this.y -= v;
|
42 |
-
this.z -= v;
|
43 |
-
} else {
|
44 |
-
this.x -= v.x;
|
45 |
-
this.y -= v.y;
|
46 |
-
this.z -= v.z;
|
47 |
-
}
|
48 |
-
|
49 |
-
return this;
|
50 |
-
}
|
51 |
-
|
52 |
-
multiply(v: Vector3): Vector3;
|
53 |
-
multiply(v: number): Vector3;
|
54 |
-
multiply(v: Vector3 | number): Vector3 {
|
55 |
-
if (typeof v === "number") {
|
56 |
-
this.x *= v;
|
57 |
-
this.y *= v;
|
58 |
-
this.z *= v;
|
59 |
-
} else {
|
60 |
-
this.x *= v.x;
|
61 |
-
this.y *= v.y;
|
62 |
-
this.z *= v.z;
|
63 |
-
}
|
64 |
-
|
65 |
-
return this;
|
66 |
-
}
|
67 |
-
|
68 |
-
lerp(v: Vector3, t: number): Vector3 {
|
69 |
-
this.x += (v.x - this.x) * t;
|
70 |
-
this.y += (v.y - this.y) * t;
|
71 |
-
this.z += (v.z - this.z) * t;
|
72 |
-
|
73 |
-
return this;
|
74 |
-
}
|
75 |
-
|
76 |
-
length(): number {
|
77 |
-
return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
|
78 |
-
}
|
79 |
-
|
80 |
-
normalize(): Vector3 {
|
81 |
-
const length = this.length();
|
82 |
-
this.x /= length;
|
83 |
-
this.y /= length;
|
84 |
-
this.z /= length;
|
85 |
-
|
86 |
-
return this;
|
87 |
-
}
|
88 |
-
|
89 |
-
flat(): number[] {
|
90 |
-
return [this.x, this.y, this.z];
|
91 |
-
}
|
92 |
-
|
93 |
-
clone(): Vector3 {
|
94 |
-
return new Vector3(this.x, this.y, this.z);
|
95 |
-
}
|
96 |
-
}
|
97 |
-
|
98 |
-
export { Vector3 };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
viewer/src/lib/splat.js/renderers/Renderer.ts
DELETED
@@ -1,9 +0,0 @@
|
|
1 |
-
import type { Camera } from "../cameras/Camera";
|
2 |
-
import type { Scene } from "../core/Scene";
|
3 |
-
|
4 |
-
class Renderer {
|
5 |
-
render(scene: Scene, camera: Camera): void {}
|
6 |
-
dispose(): void {}
|
7 |
-
}
|
8 |
-
|
9 |
-
export { Renderer };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
viewer/src/lib/splat.js/renderers/WebGLRenderer.ts
DELETED
@@ -1,225 +0,0 @@
|
|
1 |
-
import type { Camera } from "../cameras/Camera";
|
2 |
-
import type { Scene } from "../core/Scene";
|
3 |
-
import type { Renderer } from "./Renderer";
|
4 |
-
|
5 |
-
import { createWorker } from "./webgl/utils/worker";
|
6 |
-
|
7 |
-
import { vertex } from "./webgl/shaders/vertex.glsl";
|
8 |
-
import { frag } from "./webgl/shaders/frag.glsl";
|
9 |
-
import { Matrix4 } from "../math/Matrix4";
|
10 |
-
|
11 |
-
export class WebGLRenderer implements Renderer {
|
12 |
-
render: (scene: Scene, camera: Camera) => void;
|
13 |
-
dispose: () => void;
|
14 |
-
|
15 |
-
constructor(canvas: HTMLCanvasElement) {
|
16 |
-
const gl = (canvas.getContext("webgl") || canvas.getContext("experimental-webgl")) as WebGLRenderingContext;
|
17 |
-
const ext = gl.getExtension("ANGLE_instanced_arrays") as ANGLE_instanced_arrays;
|
18 |
-
|
19 |
-
let activeScene: Scene;
|
20 |
-
let activeCamera: Camera;
|
21 |
-
|
22 |
-
let worker: Worker;
|
23 |
-
let vertexCount = 0;
|
24 |
-
|
25 |
-
let vertexShader: WebGLShader;
|
26 |
-
let fragmentShader: WebGLShader;
|
27 |
-
let program: WebGLProgram;
|
28 |
-
|
29 |
-
let u_projection: WebGLUniformLocation;
|
30 |
-
let u_viewport: WebGLUniformLocation;
|
31 |
-
let u_focal: WebGLUniformLocation;
|
32 |
-
let u_view: WebGLUniformLocation;
|
33 |
-
|
34 |
-
let positionAttribute: number;
|
35 |
-
let centerAttribute: number;
|
36 |
-
let colorAttribute: number;
|
37 |
-
let covAAttribute: number;
|
38 |
-
let covBAttribute: number;
|
39 |
-
|
40 |
-
let vertexBuffer: WebGLBuffer;
|
41 |
-
let centerBuffer: WebGLBuffer;
|
42 |
-
let colorBuffer: WebGLBuffer;
|
43 |
-
let covABuffer: WebGLBuffer;
|
44 |
-
let covBBuffer: WebGLBuffer;
|
45 |
-
|
46 |
-
let initialized = false;
|
47 |
-
|
48 |
-
const getViewMatrix = (camera: Camera) => {
|
49 |
-
const R = camera.rotation.buffer;
|
50 |
-
const t = camera.position.flat();
|
51 |
-
const camToWorld = [
|
52 |
-
[R[0], R[1], R[2], 0],
|
53 |
-
[R[3], R[4], R[5], 0],
|
54 |
-
[R[6], R[7], R[8], 0],
|
55 |
-
[
|
56 |
-
-t[0] * R[0] - t[1] * R[3] - t[2] * R[6],
|
57 |
-
-t[0] * R[1] - t[1] * R[4] - t[2] * R[7],
|
58 |
-
-t[0] * R[2] - t[1] * R[5] - t[2] * R[8],
|
59 |
-
1,
|
60 |
-
],
|
61 |
-
].flat();
|
62 |
-
return new Matrix4(...camToWorld);
|
63 |
-
};
|
64 |
-
|
65 |
-
const initWebGL = () => {
|
66 |
-
worker = new Worker(
|
67 |
-
URL.createObjectURL(
|
68 |
-
new Blob(["(", createWorker.toString(), ")(self)"], { type: "application/javascript" })
|
69 |
-
)
|
70 |
-
);
|
71 |
-
|
72 |
-
canvas.width = innerWidth;
|
73 |
-
canvas.height = innerHeight;
|
74 |
-
|
75 |
-
gl.viewport(0, 0, canvas.width, canvas.height);
|
76 |
-
activeCamera.updateProjectionMatrix(canvas.width, canvas.height);
|
77 |
-
|
78 |
-
vertexShader = gl.createShader(gl.VERTEX_SHADER) as WebGLShader;
|
79 |
-
gl.shaderSource(vertexShader, vertex);
|
80 |
-
gl.compileShader(vertexShader);
|
81 |
-
if (!gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS)) {
|
82 |
-
console.error(gl.getShaderInfoLog(vertexShader));
|
83 |
-
}
|
84 |
-
|
85 |
-
fragmentShader = gl.createShader(gl.FRAGMENT_SHADER) as WebGLShader;
|
86 |
-
gl.shaderSource(fragmentShader, frag);
|
87 |
-
gl.compileShader(fragmentShader);
|
88 |
-
if (!gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS)) {
|
89 |
-
console.error(gl.getShaderInfoLog(fragmentShader));
|
90 |
-
}
|
91 |
-
|
92 |
-
program = gl.createProgram() as WebGLProgram;
|
93 |
-
gl.attachShader(program, vertexShader);
|
94 |
-
gl.attachShader(program, fragmentShader);
|
95 |
-
gl.linkProgram(program);
|
96 |
-
gl.useProgram(program);
|
97 |
-
if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {
|
98 |
-
console.error(gl.getProgramInfoLog(program));
|
99 |
-
}
|
100 |
-
|
101 |
-
gl.disable(gl.DEPTH_TEST);
|
102 |
-
gl.enable(gl.BLEND);
|
103 |
-
gl.blendFuncSeparate(gl.ONE_MINUS_DST_ALPHA, gl.ONE, gl.ONE_MINUS_DST_ALPHA, gl.ONE);
|
104 |
-
gl.blendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD);
|
105 |
-
|
106 |
-
const viewMatrix = getViewMatrix(activeCamera);
|
107 |
-
|
108 |
-
u_projection = gl.getUniformLocation(program, "projection") as WebGLUniformLocation;
|
109 |
-
gl.uniformMatrix4fv(u_projection, false, activeCamera.projectionMatrix.buffer);
|
110 |
-
|
111 |
-
u_viewport = gl.getUniformLocation(program, "viewport") as WebGLUniformLocation;
|
112 |
-
gl.uniform2fv(u_viewport, new Float32Array([canvas.width, canvas.height]));
|
113 |
-
|
114 |
-
u_focal = gl.getUniformLocation(program, "focal") as WebGLUniformLocation;
|
115 |
-
gl.uniform2fv(u_focal, new Float32Array([activeCamera.fx, activeCamera.fy]));
|
116 |
-
|
117 |
-
u_view = gl.getUniformLocation(program, "view") as WebGLUniformLocation;
|
118 |
-
gl.uniformMatrix4fv(u_view, false, viewMatrix.buffer);
|
119 |
-
|
120 |
-
const triangleVertices = new Float32Array([-2, -2, 2, -2, 2, 2, -2, 2]);
|
121 |
-
vertexBuffer = gl.createBuffer() as WebGLBuffer;
|
122 |
-
gl.bindBuffer(gl.ARRAY_BUFFER, vertexBuffer);
|
123 |
-
gl.bufferData(gl.ARRAY_BUFFER, triangleVertices, gl.STATIC_DRAW);
|
124 |
-
|
125 |
-
positionAttribute = gl.getAttribLocation(program, "position");
|
126 |
-
gl.enableVertexAttribArray(positionAttribute);
|
127 |
-
gl.vertexAttribPointer(positionAttribute, 2, gl.FLOAT, false, 0, 0);
|
128 |
-
|
129 |
-
centerBuffer = gl.createBuffer() as WebGLBuffer;
|
130 |
-
centerAttribute = gl.getAttribLocation(program, "center");
|
131 |
-
gl.enableVertexAttribArray(centerAttribute);
|
132 |
-
gl.bindBuffer(gl.ARRAY_BUFFER, centerBuffer);
|
133 |
-
gl.vertexAttribPointer(centerAttribute, 3, gl.FLOAT, false, 0, 0);
|
134 |
-
ext.vertexAttribDivisorANGLE(centerAttribute, 1);
|
135 |
-
|
136 |
-
colorBuffer = gl.createBuffer() as WebGLBuffer;
|
137 |
-
colorAttribute = gl.getAttribLocation(program, "color");
|
138 |
-
gl.enableVertexAttribArray(colorAttribute);
|
139 |
-
gl.bindBuffer(gl.ARRAY_BUFFER, colorBuffer);
|
140 |
-
gl.vertexAttribPointer(colorAttribute, 4, gl.FLOAT, false, 0, 0);
|
141 |
-
ext.vertexAttribDivisorANGLE(colorAttribute, 1);
|
142 |
-
|
143 |
-
covABuffer = gl.createBuffer() as WebGLBuffer;
|
144 |
-
covAAttribute = gl.getAttribLocation(program, "covA");
|
145 |
-
gl.enableVertexAttribArray(covAAttribute);
|
146 |
-
gl.bindBuffer(gl.ARRAY_BUFFER, covABuffer);
|
147 |
-
gl.vertexAttribPointer(covAAttribute, 3, gl.FLOAT, false, 0, 0);
|
148 |
-
ext.vertexAttribDivisorANGLE(covAAttribute, 1);
|
149 |
-
|
150 |
-
covBBuffer = gl.createBuffer() as WebGLBuffer;
|
151 |
-
covBAttribute = gl.getAttribLocation(program, "covB");
|
152 |
-
gl.enableVertexAttribArray(covBAttribute);
|
153 |
-
gl.bindBuffer(gl.ARRAY_BUFFER, covBBuffer);
|
154 |
-
gl.vertexAttribPointer(covBAttribute, 3, gl.FLOAT, false, 0, 0);
|
155 |
-
ext.vertexAttribDivisorANGLE(covBAttribute, 1);
|
156 |
-
|
157 |
-
worker.onmessage = (e) => {
|
158 |
-
if (e.data.center) {
|
159 |
-
let { covA, covB, center, color } = e.data;
|
160 |
-
vertexCount = center.length / 3;
|
161 |
-
|
162 |
-
gl.bindBuffer(gl.ARRAY_BUFFER, centerBuffer);
|
163 |
-
gl.bufferData(gl.ARRAY_BUFFER, center, gl.DYNAMIC_DRAW);
|
164 |
-
|
165 |
-
gl.bindBuffer(gl.ARRAY_BUFFER, colorBuffer);
|
166 |
-
gl.bufferData(gl.ARRAY_BUFFER, color, gl.DYNAMIC_DRAW);
|
167 |
-
|
168 |
-
gl.bindBuffer(gl.ARRAY_BUFFER, covABuffer);
|
169 |
-
gl.bufferData(gl.ARRAY_BUFFER, covA, gl.DYNAMIC_DRAW);
|
170 |
-
|
171 |
-
gl.bindBuffer(gl.ARRAY_BUFFER, covBBuffer);
|
172 |
-
gl.bufferData(gl.ARRAY_BUFFER, covB, gl.DYNAMIC_DRAW);
|
173 |
-
}
|
174 |
-
};
|
175 |
-
|
176 |
-
worker.postMessage({
|
177 |
-
buffer: activeScene.data.buffer,
|
178 |
-
vertexCount: activeScene.vertexCount,
|
179 |
-
});
|
180 |
-
|
181 |
-
initialized = true;
|
182 |
-
};
|
183 |
-
|
184 |
-
this.render = (scene: Scene, camera: Camera) => {
|
185 |
-
if (scene !== activeScene || camera !== activeCamera) {
|
186 |
-
if (initialized) {
|
187 |
-
this.dispose();
|
188 |
-
}
|
189 |
-
|
190 |
-
activeScene = scene;
|
191 |
-
activeCamera = camera;
|
192 |
-
|
193 |
-
initWebGL();
|
194 |
-
}
|
195 |
-
|
196 |
-
activeCamera.updateProjectionMatrix(canvas.width, canvas.height);
|
197 |
-
const viewMatrix = getViewMatrix(activeCamera);
|
198 |
-
const viewProj = activeCamera.projectionMatrix.multiply(viewMatrix);
|
199 |
-
worker.postMessage({ view: viewProj.buffer });
|
200 |
-
|
201 |
-
if (vertexCount > 0) {
|
202 |
-
gl.uniformMatrix4fv(u_view, false, viewMatrix.buffer);
|
203 |
-
ext.drawArraysInstancedANGLE(gl.TRIANGLE_FAN, 0, 4, vertexCount);
|
204 |
-
} else {
|
205 |
-
gl.clear(gl.COLOR_BUFFER_BIT);
|
206 |
-
}
|
207 |
-
};
|
208 |
-
|
209 |
-
this.dispose = () => {
|
210 |
-
gl.deleteShader(vertexShader);
|
211 |
-
gl.deleteShader(fragmentShader);
|
212 |
-
gl.deleteProgram(program);
|
213 |
-
|
214 |
-
gl.deleteBuffer(vertexBuffer);
|
215 |
-
gl.deleteBuffer(centerBuffer);
|
216 |
-
gl.deleteBuffer(colorBuffer);
|
217 |
-
gl.deleteBuffer(covABuffer);
|
218 |
-
gl.deleteBuffer(covBBuffer);
|
219 |
-
|
220 |
-
worker.terminate();
|
221 |
-
|
222 |
-
initialized = false;
|
223 |
-
};
|
224 |
-
}
|
225 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
viewer/src/lib/splat.js/renderers/webgl/shaders/frag.glsl.ts
DELETED
@@ -1,13 +0,0 @@
|
|
1 |
-
export const frag = /* glsl */ `
|
2 |
-
precision mediump float;
|
3 |
-
|
4 |
-
varying vec4 vColor;
|
5 |
-
varying vec2 vPosition;
|
6 |
-
|
7 |
-
void main () {
|
8 |
-
float A = -dot(vPosition, vPosition);
|
9 |
-
if (A < -4.0) discard;
|
10 |
-
float B = exp(A) * vColor.a;
|
11 |
-
gl_FragColor = vec4(B * vColor.rgb, B);
|
12 |
-
}
|
13 |
-
`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
viewer/src/lib/splat.js/renderers/webgl/shaders/vertex.glsl.ts
DELETED
@@ -1,75 +0,0 @@
|
|
1 |
-
export const vertex = /* glsl */ `
|
2 |
-
precision mediump float;
|
3 |
-
attribute vec2 position;
|
4 |
-
|
5 |
-
attribute vec4 color;
|
6 |
-
attribute vec3 center;
|
7 |
-
attribute vec3 covA;
|
8 |
-
attribute vec3 covB;
|
9 |
-
|
10 |
-
uniform mat4 projection, view;
|
11 |
-
uniform vec2 focal;
|
12 |
-
uniform vec2 viewport;
|
13 |
-
|
14 |
-
varying vec4 vColor;
|
15 |
-
varying vec2 vPosition;
|
16 |
-
|
17 |
-
mat3 transpose(mat3 m) {
|
18 |
-
return mat3(
|
19 |
-
m[0][0], m[1][0], m[2][0],
|
20 |
-
m[0][1], m[1][1], m[2][1],
|
21 |
-
m[0][2], m[1][2], m[2][2]
|
22 |
-
);
|
23 |
-
}
|
24 |
-
|
25 |
-
void main () {
|
26 |
-
vec4 camspace = view * vec4(center, 1);
|
27 |
-
vec4 pos2d = projection * camspace;
|
28 |
-
|
29 |
-
float bounds = 1.2 * pos2d.w;
|
30 |
-
if (pos2d.z < -pos2d.w || pos2d.x < -bounds || pos2d.x > bounds
|
31 |
-
|| pos2d.y < -bounds || pos2d.y > bounds) {
|
32 |
-
gl_Position = vec4(0.0, 0.0, 2.0, 1.0);
|
33 |
-
return;
|
34 |
-
}
|
35 |
-
|
36 |
-
mat3 Vrk = mat3(
|
37 |
-
covA.x, covA.y, covA.z,
|
38 |
-
covA.y, covB.x, covB.y,
|
39 |
-
covA.z, covB.y, covB.z
|
40 |
-
);
|
41 |
-
|
42 |
-
mat3 J = mat3(
|
43 |
-
focal.x / camspace.z, 0., -(focal.x * camspace.x) / (camspace.z * camspace.z),
|
44 |
-
0., -focal.y / camspace.z, (focal.y * camspace.y) / (camspace.z * camspace.z),
|
45 |
-
0., 0., 0.
|
46 |
-
);
|
47 |
-
|
48 |
-
mat3 W = transpose(mat3(view));
|
49 |
-
mat3 T = W * J;
|
50 |
-
mat3 cov = transpose(T) * Vrk * T;
|
51 |
-
|
52 |
-
vec2 vCenter = vec2(pos2d) / pos2d.w;
|
53 |
-
|
54 |
-
float diagonal1 = cov[0][0] + 0.3;
|
55 |
-
float offDiagonal = cov[0][1];
|
56 |
-
float diagonal2 = cov[1][1] + 0.3;
|
57 |
-
|
58 |
-
float mid = 0.5 * (diagonal1 + diagonal2);
|
59 |
-
float radius = length(vec2((diagonal1 - diagonal2) / 2.0, offDiagonal));
|
60 |
-
float lambda1 = mid + radius;
|
61 |
-
float lambda2 = max(mid - radius, 0.1);
|
62 |
-
vec2 diagonalVector = normalize(vec2(offDiagonal, lambda1 - diagonal1));
|
63 |
-
vec2 v1 = min(sqrt(2.0 * lambda1), 1024.0) * diagonalVector;
|
64 |
-
vec2 v2 = min(sqrt(2.0 * lambda2), 1024.0) * vec2(diagonalVector.y, -diagonalVector.x);
|
65 |
-
|
66 |
-
vColor = color;
|
67 |
-
vPosition = position;
|
68 |
-
|
69 |
-
gl_Position = vec4(
|
70 |
-
vCenter
|
71 |
-
+ position.x * v1 / viewport * 2.0
|
72 |
-
+ position.y * v2 / viewport * 2.0, 0.0, 1.0
|
73 |
-
);
|
74 |
-
}
|
75 |
-
`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
viewer/src/lib/splat.js/renderers/webgl/utils/worker.ts
DELETED
@@ -1,254 +0,0 @@
|
|
1 |
-
export function createWorker(self: Worker) {
|
2 |
-
let buffer: ArrayBuffer;
|
3 |
-
let vertexCount = 0;
|
4 |
-
let viewProj: Float32Array;
|
5 |
-
// 6*4 + 4 + 4 = 8*4
|
6 |
-
// XYZ - Position (Float32)
|
7 |
-
// XYZ - Scale (Float32)
|
8 |
-
// RGBA - colors (uint8)
|
9 |
-
// IJKL - quaternion/rot (uint8)
|
10 |
-
const rowLength = 3 * 4 + 3 * 4 + 4 + 4;
|
11 |
-
let depthIndex = new Uint32Array();
|
12 |
-
|
13 |
-
function processPlyBuffer(inputBuffer: ArrayBuffer) {
|
14 |
-
const ubuf = new Uint8Array(inputBuffer);
|
15 |
-
// 10KB ought to be enough for a header...
|
16 |
-
const header = new TextDecoder().decode(ubuf.slice(0, 1024 * 10));
|
17 |
-
const header_end = "end_header\n";
|
18 |
-
const header_end_index = header.indexOf(header_end);
|
19 |
-
if (header_end_index < 0) throw new Error("Unable to read .ply file header");
|
20 |
-
const vertexCount = parseInt(/element vertex (\d+)\n/.exec(header)![1]);
|
21 |
-
console.log("Vertex Count", vertexCount);
|
22 |
-
let row_offset: number = 0;
|
23 |
-
let offsets: { [key: string]: number } = {};
|
24 |
-
let types: { [key: string]: string } = {};
|
25 |
-
const TYPE_MAP: { [key: string]: string } = {
|
26 |
-
double: "getFloat64",
|
27 |
-
int: "getInt32",
|
28 |
-
uint: "getUint32",
|
29 |
-
float: "getFloat32",
|
30 |
-
short: "getInt16",
|
31 |
-
ushort: "getUint16",
|
32 |
-
uchar: "getUint8",
|
33 |
-
};
|
34 |
-
for (let prop of header
|
35 |
-
.slice(0, header_end_index)
|
36 |
-
.split("\n")
|
37 |
-
.filter((k) => k.startsWith("property "))) {
|
38 |
-
const [_p, type, name] = prop.split(" ");
|
39 |
-
const arrayType = TYPE_MAP[type] || "getInt8";
|
40 |
-
types[name] = arrayType;
|
41 |
-
offsets[name] = row_offset;
|
42 |
-
row_offset += parseInt(arrayType.replace(/[^\d]/g, "")) / 8;
|
43 |
-
}
|
44 |
-
|
45 |
-
let dataView = new DataView(inputBuffer, header_end_index + header_end.length);
|
46 |
-
let row: number = 0;
|
47 |
-
const attrs: any = new Proxy(
|
48 |
-
{},
|
49 |
-
{
|
50 |
-
get(_target, prop: string) {
|
51 |
-
if (!types[prop]) throw new Error(prop + " not found");
|
52 |
-
const type = types[prop] as keyof DataView;
|
53 |
-
const dataViewMethod = dataView[type] as any;
|
54 |
-
return dataViewMethod(row * row_offset + offsets[prop], true);
|
55 |
-
},
|
56 |
-
}
|
57 |
-
);
|
58 |
-
|
59 |
-
// 6*4 + 4 + 4 = 8*4
|
60 |
-
// XYZ - Position (Float32)
|
61 |
-
// XYZ - Scale (Float32)
|
62 |
-
// RGBA - colors (uint8)
|
63 |
-
// IJKL - quaternion/rot (uint8)
|
64 |
-
const rowLength = 3 * 4 + 3 * 4 + 4 + 4;
|
65 |
-
const buffer = new ArrayBuffer(rowLength * vertexCount);
|
66 |
-
|
67 |
-
for (let j = 0; j < vertexCount; j++) {
|
68 |
-
row = j;
|
69 |
-
|
70 |
-
const position = new Float32Array(buffer, j * rowLength, 3);
|
71 |
-
const scales = new Float32Array(buffer, j * rowLength + 4 * 3, 3);
|
72 |
-
const rgba = new Uint8ClampedArray(buffer, j * rowLength + 4 * 3 + 4 * 3, 4);
|
73 |
-
const rot = new Uint8ClampedArray(buffer, j * rowLength + 4 * 3 + 4 * 3 + 4, 4);
|
74 |
-
|
75 |
-
if (types["scale_0"]) {
|
76 |
-
const qlen = Math.sqrt(attrs.rot_0 ** 2 + attrs.rot_1 ** 2 + attrs.rot_2 ** 2 + attrs.rot_3 ** 2);
|
77 |
-
|
78 |
-
rot[0] = (attrs.rot_0 / qlen) * 128 + 128;
|
79 |
-
rot[1] = (attrs.rot_1 / qlen) * 128 + 128;
|
80 |
-
rot[2] = (attrs.rot_2 / qlen) * 128 + 128;
|
81 |
-
rot[3] = (attrs.rot_3 / qlen) * 128 + 128;
|
82 |
-
|
83 |
-
scales[0] = Math.exp(attrs.scale_0);
|
84 |
-
scales[1] = Math.exp(attrs.scale_1);
|
85 |
-
scales[2] = Math.exp(attrs.scale_2);
|
86 |
-
} else {
|
87 |
-
scales[0] = 0.01;
|
88 |
-
scales[1] = 0.01;
|
89 |
-
scales[2] = 0.01;
|
90 |
-
|
91 |
-
rot[0] = 255;
|
92 |
-
rot[1] = 0;
|
93 |
-
rot[2] = 0;
|
94 |
-
rot[3] = 0;
|
95 |
-
}
|
96 |
-
|
97 |
-
position[0] = attrs.x;
|
98 |
-
position[1] = attrs.y;
|
99 |
-
position[2] = attrs.z;
|
100 |
-
|
101 |
-
if (types["f_dc_0"]) {
|
102 |
-
const SH_C0 = 0.28209479177387814;
|
103 |
-
rgba[0] = (0.5 + SH_C0 * attrs.f_dc_0) * 255;
|
104 |
-
rgba[1] = (0.5 + SH_C0 * attrs.f_dc_1) * 255;
|
105 |
-
rgba[2] = (0.5 + SH_C0 * attrs.f_dc_2) * 255;
|
106 |
-
} else {
|
107 |
-
rgba[0] = attrs.red;
|
108 |
-
rgba[1] = attrs.green;
|
109 |
-
rgba[2] = attrs.blue;
|
110 |
-
}
|
111 |
-
if (types["opacity"]) {
|
112 |
-
rgba[3] = (1 / (1 + Math.exp(-attrs.opacity))) * 255;
|
113 |
-
} else {
|
114 |
-
rgba[3] = 255;
|
115 |
-
}
|
116 |
-
}
|
117 |
-
return buffer;
|
118 |
-
}
|
119 |
-
|
120 |
-
const runSort = (viewProj: Float32Array) => {
|
121 |
-
if (!buffer) return;
|
122 |
-
|
123 |
-
const f_buffer = new Float32Array(buffer);
|
124 |
-
const u_buffer = new Uint8Array(buffer);
|
125 |
-
|
126 |
-
const covA = new Float32Array(3 * vertexCount);
|
127 |
-
const covB = new Float32Array(3 * vertexCount);
|
128 |
-
|
129 |
-
const center = new Float32Array(3 * vertexCount);
|
130 |
-
const color = new Float32Array(4 * vertexCount);
|
131 |
-
|
132 |
-
let maxDepth = -Infinity;
|
133 |
-
let minDepth = Infinity;
|
134 |
-
let sizeList = new Int32Array(vertexCount);
|
135 |
-
for (let i = 0; i < vertexCount; i++) {
|
136 |
-
let depth =
|
137 |
-
((viewProj[2] * f_buffer[8 * i + 0] +
|
138 |
-
viewProj[6] * f_buffer[8 * i + 1] +
|
139 |
-
viewProj[10] * f_buffer[8 * i + 2]) *
|
140 |
-
4096) |
|
141 |
-
0;
|
142 |
-
sizeList[i] = depth;
|
143 |
-
if (depth > maxDepth) maxDepth = depth;
|
144 |
-
if (depth < minDepth) minDepth = depth;
|
145 |
-
}
|
146 |
-
|
147 |
-
// This is a 16 bit single-pass counting sort
|
148 |
-
let depthInv = (256 * 256) / (maxDepth - minDepth);
|
149 |
-
let counts0 = new Uint32Array(256 * 256);
|
150 |
-
for (let i = 0; i < vertexCount; i++) {
|
151 |
-
sizeList[i] = ((sizeList[i] - minDepth) * depthInv) | 0;
|
152 |
-
counts0[sizeList[i]]++;
|
153 |
-
}
|
154 |
-
let starts0 = new Uint32Array(256 * 256);
|
155 |
-
for (let i = 1; i < 256 * 256; i++) starts0[i] = starts0[i - 1] + counts0[i - 1];
|
156 |
-
depthIndex = new Uint32Array(vertexCount);
|
157 |
-
for (let i = 0; i < vertexCount; i++) depthIndex[starts0[sizeList[i]]++] = i;
|
158 |
-
|
159 |
-
for (let j = 0; j < vertexCount; j++) {
|
160 |
-
const i = depthIndex[j];
|
161 |
-
|
162 |
-
center[3 * j + 0] = f_buffer[8 * i + 0];
|
163 |
-
center[3 * j + 1] = f_buffer[8 * i + 1];
|
164 |
-
center[3 * j + 2] = f_buffer[8 * i + 2];
|
165 |
-
|
166 |
-
color[4 * j + 0] = u_buffer[32 * i + 24 + 0] / 255;
|
167 |
-
color[4 * j + 1] = u_buffer[32 * i + 24 + 1] / 255;
|
168 |
-
color[4 * j + 2] = u_buffer[32 * i + 24 + 2] / 255;
|
169 |
-
color[4 * j + 3] = u_buffer[32 * i + 24 + 3] / 255;
|
170 |
-
|
171 |
-
let scale = [f_buffer[8 * i + 3 + 0], f_buffer[8 * i + 3 + 1], f_buffer[8 * i + 3 + 2]];
|
172 |
-
let rot = [
|
173 |
-
(u_buffer[32 * i + 28 + 0] - 128) / 128,
|
174 |
-
(u_buffer[32 * i + 28 + 1] - 128) / 128,
|
175 |
-
(u_buffer[32 * i + 28 + 2] - 128) / 128,
|
176 |
-
(u_buffer[32 * i + 28 + 3] - 128) / 128,
|
177 |
-
];
|
178 |
-
|
179 |
-
const R = [
|
180 |
-
1.0 - 2.0 * (rot[2] * rot[2] + rot[3] * rot[3]),
|
181 |
-
2.0 * (rot[1] * rot[2] + rot[0] * rot[3]),
|
182 |
-
2.0 * (rot[1] * rot[3] - rot[0] * rot[2]),
|
183 |
-
|
184 |
-
2.0 * (rot[1] * rot[2] - rot[0] * rot[3]),
|
185 |
-
1.0 - 2.0 * (rot[1] * rot[1] + rot[3] * rot[3]),
|
186 |
-
2.0 * (rot[2] * rot[3] + rot[0] * rot[1]),
|
187 |
-
|
188 |
-
2.0 * (rot[1] * rot[3] + rot[0] * rot[2]),
|
189 |
-
2.0 * (rot[2] * rot[3] - rot[0] * rot[1]),
|
190 |
-
1.0 - 2.0 * (rot[1] * rot[1] + rot[2] * rot[2]),
|
191 |
-
];
|
192 |
-
|
193 |
-
// Compute the matrix product of S and R (M = S * R)
|
194 |
-
const M = [
|
195 |
-
scale[0] * R[0],
|
196 |
-
scale[0] * R[1],
|
197 |
-
scale[0] * R[2],
|
198 |
-
scale[1] * R[3],
|
199 |
-
scale[1] * R[4],
|
200 |
-
scale[1] * R[5],
|
201 |
-
scale[2] * R[6],
|
202 |
-
scale[2] * R[7],
|
203 |
-
scale[2] * R[8],
|
204 |
-
];
|
205 |
-
|
206 |
-
covA[3 * j + 0] = M[0] * M[0] + M[3] * M[3] + M[6] * M[6];
|
207 |
-
covA[3 * j + 1] = M[0] * M[1] + M[3] * M[4] + M[6] * M[7];
|
208 |
-
covA[3 * j + 2] = M[0] * M[2] + M[3] * M[5] + M[6] * M[8];
|
209 |
-
covB[3 * j + 0] = M[1] * M[1] + M[4] * M[4] + M[7] * M[7];
|
210 |
-
covB[3 * j + 1] = M[1] * M[2] + M[4] * M[5] + M[7] * M[8];
|
211 |
-
covB[3 * j + 2] = M[2] * M[2] + M[5] * M[5] + M[8] * M[8];
|
212 |
-
}
|
213 |
-
|
214 |
-
self.postMessage({ covA, center, color, covB, viewProj }, [
|
215 |
-
covA.buffer,
|
216 |
-
center.buffer,
|
217 |
-
color.buffer,
|
218 |
-
covB.buffer,
|
219 |
-
]);
|
220 |
-
};
|
221 |
-
|
222 |
-
const throttledSort = () => {
|
223 |
-
if (!sortRunning) {
|
224 |
-
sortRunning = true;
|
225 |
-
let lastView = viewProj;
|
226 |
-
runSort(lastView);
|
227 |
-
setTimeout(() => {
|
228 |
-
sortRunning = false;
|
229 |
-
if (lastView !== viewProj) {
|
230 |
-
throttledSort();
|
231 |
-
}
|
232 |
-
}, 0);
|
233 |
-
}
|
234 |
-
};
|
235 |
-
|
236 |
-
let sortRunning: boolean = false;
|
237 |
-
self.onmessage = (e) => {
|
238 |
-
if (e.data.ply) {
|
239 |
-
vertexCount = 0;
|
240 |
-
runSort(viewProj);
|
241 |
-
buffer = processPlyBuffer(e.data.ply);
|
242 |
-
vertexCount = Math.floor(buffer.byteLength / rowLength);
|
243 |
-
postMessage({ buffer: buffer });
|
244 |
-
} else if (e.data.buffer) {
|
245 |
-
buffer = e.data.buffer;
|
246 |
-
vertexCount = e.data.vertexCount;
|
247 |
-
} else if (e.data.vertexCount) {
|
248 |
-
vertexCount = e.data.vertexCount;
|
249 |
-
} else if (e.data.view) {
|
250 |
-
viewProj = e.data.view;
|
251 |
-
throttledSort();
|
252 |
-
}
|
253 |
-
};
|
254 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
viewer/src/routes/viewer/[slug]/SplatViewer.ts
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
import type { IViewer } from "./IViewer";
|
2 |
-
import * as SPLAT from "
|
3 |
|
4 |
export class SplatViewer implements IViewer {
|
5 |
canvas: HTMLCanvasElement;
|
6 |
|
7 |
-
renderer: SPLAT.
|
8 |
scene: SPLAT.Scene;
|
9 |
camera: SPLAT.Camera;
|
10 |
controls: SPLAT.OrbitControls;
|
|
|
1 |
import type { IViewer } from "./IViewer";
|
2 |
+
import * as SPLAT from "gsplat";
|
3 |
|
4 |
export class SplatViewer implements IViewer {
|
5 |
canvas: HTMLCanvasElement;
|
6 |
|
7 |
+
renderer: SPLAT.WebGLRenderer;
|
8 |
scene: SPLAT.Scene;
|
9 |
camera: SPLAT.Camera;
|
10 |
controls: SPLAT.OrbitControls;
|