Spaces:
Running
Running
Commit
•
4e1da8c
1
Parent(s):
c087f79
add skeleton library
Browse files- viewer/src/lib/{dataLoader.ts → data/dataLoader.ts} +0 -0
- viewer/src/lib/splat.js/cameras/PerspectiveCamera.ts +32 -0
- viewer/src/lib/splat.js/core/Camera.ts +8 -0
- viewer/src/lib/splat.js/core/Object3D.ts +12 -0
- viewer/src/lib/splat.js/core/Renderer.ts +6 -0
- viewer/src/lib/splat.js/core/Scene.ts +3 -0
- viewer/src/lib/splat.js/index.ts +8 -0
- viewer/src/lib/splat.js/math/Matrix4.ts +31 -0
- viewer/src/lib/splat.js/math/Quaternion.ts +22 -0
- viewer/src/lib/splat.js/math/Vector3.ts +19 -0
- viewer/src/lib/splat.js/renderers/WebGLRenderer.ts +9 -0
- viewer/src/routes/components/ModelsView.svelte +1 -1
- viewer/src/routes/components/ScenesView.svelte +1 -1
- viewer/src/routes/models/[slug]/+page.server.ts +1 -1
- viewer/src/routes/store.js +1 -1
- viewer/src/routes/viewer/[slug]/+page.server.ts +1 -1
- viewer/src/routes/viewer/[slug]/+page.svelte +3 -3
- viewer/src/routes/viewer/[slug]/BabylonViewer.ts +1 -1
- viewer/src/routes/viewer/[slug]/IViewer.ts +5 -1
- viewer/src/routes/viewer/[slug]/SplatViewer.ts +2 -1
- viewer/tsconfig.json +1 -0
viewer/src/lib/{dataLoader.ts → data/dataLoader.ts}
RENAMED
File without changes
|
viewer/src/lib/splat.js/cameras/PerspectiveCamera.ts
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Camera } from '../core/Camera';
|
2 |
+
import { Matrix4 } from '../math/Matrix4';
|
3 |
+
|
4 |
+
export class PerspectiveCamera extends Camera {
|
5 |
+
fx: number;
|
6 |
+
fy: number;
|
7 |
+
|
8 |
+
near: number;
|
9 |
+
far: number;
|
10 |
+
|
11 |
+
projectionMatrix: Matrix4;
|
12 |
+
|
13 |
+
constructor(fx: number = 1132, fy: number = 1132, near: number = 0.1, far: number = 100) {
|
14 |
+
super();
|
15 |
+
|
16 |
+
this.fx = fx;
|
17 |
+
this.fy = fy;
|
18 |
+
this.near = near;
|
19 |
+
this.far = far;
|
20 |
+
|
21 |
+
this.projectionMatrix = new Matrix4();
|
22 |
+
}
|
23 |
+
|
24 |
+
updateProjectionMatrix(width: number, height: number) : void {
|
25 |
+
this.projectionMatrix.set(
|
26 |
+
2 * this.fx / width, 0, 0, 0,
|
27 |
+
0, -2 * this.fy / height, 0, 0,
|
28 |
+
0, 0, this.far / (this.far - this.near), 1,
|
29 |
+
0, 0, -this.near * this.far / (this.far - this.near), 0
|
30 |
+
);
|
31 |
+
}
|
32 |
+
}
|
viewer/src/lib/splat.js/core/Camera.ts
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Object3D } from './Object3D';
|
2 |
+
import { Matrix4 } from '../math/Matrix4';
|
3 |
+
|
4 |
+
export class Camera extends Object3D {
|
5 |
+
constructor() {
|
6 |
+
super();
|
7 |
+
}
|
8 |
+
}
|
viewer/src/lib/splat.js/core/Object3D.ts
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Vector3 } from '../math/Vector3';
|
2 |
+
import { Quaternion } from '../math/Quaternion';
|
3 |
+
|
4 |
+
export class Object3D {
|
5 |
+
position: Vector3;
|
6 |
+
rotation: Quaternion;
|
7 |
+
|
8 |
+
constructor() {
|
9 |
+
this.position = new Vector3();
|
10 |
+
this.rotation = new Quaternion();
|
11 |
+
}
|
12 |
+
}
|
viewer/src/lib/splat.js/core/Renderer.ts
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import type { Scene } from './Scene';
|
2 |
+
import type { Camera } from './Camera';
|
3 |
+
|
4 |
+
export interface Renderer {
|
5 |
+
render(scene: Scene, camera: Camera): void;
|
6 |
+
}
|
viewer/src/lib/splat.js/core/Scene.ts
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
export class Scene {
|
2 |
+
|
3 |
+
}
|
viewer/src/lib/splat.js/index.ts
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export * from './core/Camera';
|
2 |
+
export * from './core/Renderer';
|
3 |
+
export * from './core/Scene';
|
4 |
+
|
5 |
+
export * from './renderers/WebGLRenderer';
|
6 |
+
|
7 |
+
export * from './math/Quaternion';
|
8 |
+
export * from './math/Vector3';
|
viewer/src/lib/splat.js/math/Matrix4.ts
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export class Matrix4 {
|
2 |
+
elements: number[];
|
3 |
+
|
4 |
+
constructor(n11: number = 1, n12: number = 0, n13: number = 0, n14: number = 0,
|
5 |
+
n21: number = 0, n22: number = 1, n23: number = 0, n24: number = 0,
|
6 |
+
n31: number = 0, n32: number = 0, n33: number = 1, n34: number = 0,
|
7 |
+
n41: number = 0, n42: number = 0, n43: number = 0, n44: number = 1) {
|
8 |
+
this.elements = new Array(16);
|
9 |
+
|
10 |
+
this.set(
|
11 |
+
n11, n12, n13, n14,
|
12 |
+
n21, n22, n23, n24,
|
13 |
+
n31, n32, n33, n34,
|
14 |
+
n41, n42, n43, n44
|
15 |
+
);
|
16 |
+
}
|
17 |
+
|
18 |
+
set(n11: number, n12: number, n13: number, n14: number,
|
19 |
+
n21: number, n22: number, n23: number, n24: number,
|
20 |
+
n31: number, n32: number, n33: number, n34: number,
|
21 |
+
n41: number, n42: number, n43: number, n44: number) : Matrix4 {
|
22 |
+
const e = this.elements;
|
23 |
+
|
24 |
+
e[0] = n11; e[4] = n12; e[8] = n13; e[12] = n14;
|
25 |
+
e[1] = n21; e[5] = n22; e[9] = n23; e[13] = n24;
|
26 |
+
e[2] = n31; e[6] = n32; e[10] = n33; e[14] = n34;
|
27 |
+
e[3] = n41; e[7] = n42; e[11] = n43; e[15] = n44;
|
28 |
+
|
29 |
+
return this;
|
30 |
+
}
|
31 |
+
}
|
viewer/src/lib/splat.js/math/Quaternion.ts
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export class Quaternion {
|
2 |
+
x: number;
|
3 |
+
y: number;
|
4 |
+
z: number;
|
5 |
+
w: number;
|
6 |
+
|
7 |
+
constructor(x: number = 0, y: number = 0, z: number = 0, w: number = 1) {
|
8 |
+
this.x = x;
|
9 |
+
this.y = y;
|
10 |
+
this.z = z;
|
11 |
+
this.w = w;
|
12 |
+
}
|
13 |
+
|
14 |
+
set(x: number, y: number, z: number, w: number) : Quaternion {
|
15 |
+
this.x = x;
|
16 |
+
this.y = y;
|
17 |
+
this.z = z;
|
18 |
+
this.w = w;
|
19 |
+
|
20 |
+
return this;
|
21 |
+
}
|
22 |
+
}
|
viewer/src/lib/splat.js/math/Vector3.ts
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
export 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 |
+
}
|
viewer/src/lib/splat.js/renderers/WebGLRenderer.ts
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import type { Scene } from '../core/Scene';
|
2 |
+
import type { Camera } from '../core/Camera';
|
3 |
+
import type { Renderer } from '../core/Renderer';
|
4 |
+
|
5 |
+
export class WebGLRenderer implements Renderer {
|
6 |
+
render(scene: Scene, camera: Camera): void {
|
7 |
+
|
8 |
+
}
|
9 |
+
}
|
viewer/src/routes/components/ModelsView.svelte
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<script lang="ts">
|
2 |
import { onMount } from "svelte";
|
3 |
-
import { getModels, getScenes } from "$lib/dataLoader";
|
4 |
import placeholderImage from "$lib/placeholder.png";
|
5 |
|
6 |
let models: any[] = [];
|
|
|
1 |
<script lang="ts">
|
2 |
import { onMount } from "svelte";
|
3 |
+
import { getModels, getScenes } from "$lib/data/dataLoader";
|
4 |
import placeholderImage from "$lib/placeholder.png";
|
5 |
|
6 |
let models: any[] = [];
|
viewer/src/routes/components/ScenesView.svelte
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<script lang="ts">
|
2 |
import { onMount } from "svelte";
|
3 |
-
import { getScenes } from "$lib/dataLoader";
|
4 |
import placeholderImage from "$lib/placeholder.png";
|
5 |
|
6 |
let scenes: any[] = [];
|
|
|
1 |
<script lang="ts">
|
2 |
import { onMount } from "svelte";
|
3 |
+
import { getScenes } from "$lib/data/dataLoader";
|
4 |
import placeholderImage from "$lib/placeholder.png";
|
5 |
|
6 |
let scenes: any[] = [];
|
viewer/src/routes/models/[slug]/+page.server.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import { getModels, getScenes } from "$lib/dataLoader";
|
2 |
|
3 |
export async function load({ params }) {
|
4 |
const models = await getModels();
|
|
|
1 |
+
import { getModels, getScenes } from "$lib/data/dataLoader";
|
2 |
|
3 |
export async function load({ params }) {
|
4 |
const models = await getModels();
|
viewer/src/routes/store.js
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
import { writable } from 'svelte/store';
|
2 |
|
3 |
-
export const activeTab = writable('Models');
|
|
|
1 |
import { writable } from 'svelte/store';
|
2 |
|
3 |
+
export const activeTab = writable('Models');
|
viewer/src/routes/viewer/[slug]/+page.server.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import { error } from "@sveltejs/kit";
|
2 |
-
import { getModels, getScenes } from "$lib/dataLoader";
|
3 |
|
4 |
export async function load({ params }) {
|
5 |
const models = await getModels();
|
|
|
1 |
import { error } from "@sveltejs/kit";
|
2 |
+
import { getModels, getScenes } from "$lib/data/dataLoader";
|
3 |
|
4 |
export async function load({ params }) {
|
5 |
const models = await getModels();
|
viewer/src/routes/viewer/[slug]/+page.svelte
CHANGED
@@ -41,7 +41,7 @@
|
|
41 |
console.error(`Unsupported scene type: ${data.scene.type}`);
|
42 |
}
|
43 |
handleMobileView();
|
44 |
-
await
|
45 |
window.addEventListener("resize", () => {
|
46 |
updateCanvasSize();
|
47 |
});
|
@@ -87,9 +87,9 @@
|
|
87 |
babylonViewer.setRenderMode(mode);
|
88 |
}
|
89 |
|
90 |
-
async function
|
91 |
overlay.style.display = "flex";
|
92 |
-
await viewer.
|
93 |
loadingBarFill.style.width = `${progress * 100}%`;
|
94 |
});
|
95 |
updateCanvasSize();
|
|
|
41 |
console.error(`Unsupported scene type: ${data.scene.type}`);
|
42 |
}
|
43 |
handleMobileView();
|
44 |
+
await loadScene(data.scene.url);
|
45 |
window.addEventListener("resize", () => {
|
46 |
updateCanvasSize();
|
47 |
});
|
|
|
87 |
babylonViewer.setRenderMode(mode);
|
88 |
}
|
89 |
|
90 |
+
async function loadScene(url: string) {
|
91 |
overlay.style.display = "flex";
|
92 |
+
await viewer.loadScene(url, (progress) => {
|
93 |
loadingBarFill.style.width = `${progress * 100}%`;
|
94 |
});
|
95 |
updateCanvasSize();
|
viewer/src/routes/viewer/[slug]/BabylonViewer.ts
CHANGED
@@ -41,7 +41,7 @@ export class BabylonViewer implements IViewer {
|
|
41 |
this.engine.resize();
|
42 |
}
|
43 |
|
44 |
-
async
|
45 |
// Load scene
|
46 |
await BABYLON.SceneLoader.AppendAsync("", url, this.scene, (event) => {
|
47 |
const progress = event.loaded / event.total;
|
|
|
41 |
this.engine.resize();
|
42 |
}
|
43 |
|
44 |
+
async loadScene(url: string, loadingBarCallback?: (progress: number) => void) {
|
45 |
// Load scene
|
46 |
await BABYLON.SceneLoader.AppendAsync("", url, this.scene, (event) => {
|
47 |
const progress = event.loaded / event.total;
|
viewer/src/routes/viewer/[slug]/IViewer.ts
CHANGED
@@ -1,6 +1,10 @@
|
|
1 |
export interface IViewer {
|
2 |
-
|
3 |
dispose(): void;
|
4 |
capture(): Promise<string | null>;
|
5 |
getStats(): { name: string, value: any }[];
|
|
|
|
|
|
|
|
|
6 |
}
|
|
|
1 |
export interface IViewer {
|
2 |
+
loadScene(url: string, loadingBarCallback?: (progress: number) => void): Promise<void>;
|
3 |
dispose(): void;
|
4 |
capture(): Promise<string | null>;
|
5 |
getStats(): { name: string, value: any }[];
|
6 |
+
}
|
7 |
+
|
8 |
+
export interface ISplatRenderer {
|
9 |
+
init(): void;
|
10 |
}
|
viewer/src/routes/viewer/[slug]/SplatViewer.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import type { IViewer } from "./IViewer";
|
|
|
2 |
|
3 |
class OrbitCamera {
|
4 |
position: number[];
|
@@ -789,7 +790,7 @@ export class SplatViewer implements IViewer {
|
|
789 |
return gl as WebGLRenderingContext;
|
790 |
}
|
791 |
|
792 |
-
async
|
793 |
const req = await fetch(url, {
|
794 |
mode: "cors",
|
795 |
credentials: "omit",
|
|
|
1 |
import type { IViewer } from "./IViewer";
|
2 |
+
import * as SPLAT from "$lib/splat.js";
|
3 |
|
4 |
class OrbitCamera {
|
5 |
position: number[];
|
|
|
790 |
return gl as WebGLRenderingContext;
|
791 |
}
|
792 |
|
793 |
+
async loadScene(url: string, loadingBarCallback?: (progress: number) => void) {
|
794 |
const req = await fetch(url, {
|
795 |
mode: "cors",
|
796 |
credentials: "omit",
|
viewer/tsconfig.json
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
{
|
2 |
"extends": "./.svelte-kit/tsconfig.json",
|
3 |
"compilerOptions": {
|
|
|
4 |
"allowJs": true,
|
5 |
"checkJs": true,
|
6 |
"esModuleInterop": true,
|
|
|
1 |
{
|
2 |
"extends": "./.svelte-kit/tsconfig.json",
|
3 |
"compilerOptions": {
|
4 |
+
"outDir": "build",
|
5 |
"allowJs": true,
|
6 |
"checkJs": true,
|
7 |
"esModuleInterop": true,
|