@soonspacejs/plugin-gs3d-loader 2.13.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.esm.js +14444 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/types.d.ts +46 -0
- package/env.d.ts +3 -0
- package/example/index.html +87 -0
- package/package.json +19 -0
- package/src/index.ts +96 -0
- package/src/types.ts +54 -0
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Group, Matrix4, Object3D } from 'three';
|
|
2
|
+
export declare enum SceneFormat {
|
|
3
|
+
'Splat' = 0,
|
|
4
|
+
'KSplat' = 1,
|
|
5
|
+
'Ply' = 2,
|
|
6
|
+
'Spz' = 3
|
|
7
|
+
}
|
|
8
|
+
export declare enum LoaderStatus {
|
|
9
|
+
'Downloading' = 0,
|
|
10
|
+
'Processing' = 1,
|
|
11
|
+
'Done' = 2
|
|
12
|
+
}
|
|
13
|
+
export interface option {
|
|
14
|
+
splatAlphaRemovalThreshold?: number;
|
|
15
|
+
position?: Array<number>;
|
|
16
|
+
rotation?: Array<number>;
|
|
17
|
+
scale?: Array<number>;
|
|
18
|
+
onProgress?: () => void;
|
|
19
|
+
}
|
|
20
|
+
export interface sceneOption {
|
|
21
|
+
path: string;
|
|
22
|
+
splatAlphaRemovalThreshold?: number;
|
|
23
|
+
position?: Array<number>;
|
|
24
|
+
rotation?: Array<number>;
|
|
25
|
+
scale?: Array<number>;
|
|
26
|
+
headers?: Headers;
|
|
27
|
+
format?: SceneFormat;
|
|
28
|
+
}
|
|
29
|
+
export interface DropInViewer extends Group {
|
|
30
|
+
viewer: any;
|
|
31
|
+
updateSplatMesh: () => void;
|
|
32
|
+
addSplatScene: (path: string, options?: option) => Promise<void>;
|
|
33
|
+
addSplatScenes: (sceneOptions: sceneOption[], showLoadingUI: boolean) => Promise<void>;
|
|
34
|
+
getSplatScene: (sceneIndex: number) => SplatScene;
|
|
35
|
+
removeSplatScene: (index: number) => Promise<void>;
|
|
36
|
+
removeSplatScenes: (indexes: number[]) => Promise<void>;
|
|
37
|
+
getSceneCount: () => number;
|
|
38
|
+
dispose: () => Promise<any>;
|
|
39
|
+
}
|
|
40
|
+
export interface SplatScene extends Object3D {
|
|
41
|
+
splatBuffer: Matrix4;
|
|
42
|
+
transform: Matrix4;
|
|
43
|
+
opacity: number;
|
|
44
|
+
copyTransformData: (otherScene: SplatScene) => void;
|
|
45
|
+
updateTransform: (dynamicMode: boolean) => void;
|
|
46
|
+
}
|
package/env.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>Document</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="view" style="width: 100vw; height: 100vh"></div>
|
|
10
|
+
<script type="importmap">
|
|
11
|
+
{
|
|
12
|
+
"imports": {
|
|
13
|
+
"soonspacejs": "../../../soonspacejs/dist/index.esm.js",
|
|
14
|
+
"three/": "/node_modules/three/",
|
|
15
|
+
"three": "/node_modules/three/build/three.module.js",
|
|
16
|
+
"three-mesh-bvh": "/node_modules/three-mesh-bvh/build/index.module.js",
|
|
17
|
+
"postprocessing": "/node_modules/postprocessing/build/index.js"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
</script>
|
|
21
|
+
<script type="module">
|
|
22
|
+
import SoonSpace from '../../../soonspacejs/dist/index.esm.js';
|
|
23
|
+
import GS3DLoaderPlugin from '../dist/index.esm.js';
|
|
24
|
+
import * as THREE from 'three'
|
|
25
|
+
|
|
26
|
+
const ssp = (window.ssp = new SoonSpace({
|
|
27
|
+
el: '#view',
|
|
28
|
+
options: {
|
|
29
|
+
showInfo: true,
|
|
30
|
+
showGrid: true,
|
|
31
|
+
},
|
|
32
|
+
events: {
|
|
33
|
+
selectPosition(position) {
|
|
34
|
+
// console.log(position);
|
|
35
|
+
},
|
|
36
|
+
modelClick(p) {
|
|
37
|
+
console.log(p);
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
const gs3dLoaderPlugin = ssp.registerPlugin(GS3DLoaderPlugin, 'GS3DLoader');
|
|
43
|
+
|
|
44
|
+
async function loadGS3D() {
|
|
45
|
+
debugger
|
|
46
|
+
const list = ['../assets/gs/dog.splat', '../assets/gs/scene.ply']
|
|
47
|
+
|
|
48
|
+
const [dogIndex, sceneIndex] = await Promise.allSettled([
|
|
49
|
+
gs3dLoaderPlugin.load('../assets/gs/dog.splat'),
|
|
50
|
+
gs3dLoaderPlugin.load('../assets/gs/scene.ply')
|
|
51
|
+
])
|
|
52
|
+
debugger
|
|
53
|
+
// const dogIndex = await gs3dLoaderPlugin.load('../assets/gs/dog.splat')
|
|
54
|
+
// const sceneIndex = await gs3dLoaderPlugin.load('../assets/gs/scene.ply')
|
|
55
|
+
|
|
56
|
+
const dogObject = gs3dLoaderPlugin.getSplatScene(dogIndex.value)
|
|
57
|
+
const sceneObject = gs3dLoaderPlugin.getSplatScene(sceneIndex.value)
|
|
58
|
+
|
|
59
|
+
ssp.addObject(gs3dLoaderPlugin.dropInViewer)
|
|
60
|
+
|
|
61
|
+
const _quat = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 0, 1), Math.PI);
|
|
62
|
+
|
|
63
|
+
// sceneObject.quaternion.copy(_quat);
|
|
64
|
+
sceneObject.rotation.set(0, 0, Math.PI)
|
|
65
|
+
|
|
66
|
+
dogObject.position.setY(0.2); // 机器狗底盘高度
|
|
67
|
+
_quat
|
|
68
|
+
.setFromAxisAngle(new THREE.Vector3(1, 0, 0), Math.PI)
|
|
69
|
+
.multiply(new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), -Math.PI / 5));
|
|
70
|
+
dogObject.quaternion.copy(_quat); // 旋转校正
|
|
71
|
+
dogObject.scale.setScalar(0.5); // 机器狗缩放
|
|
72
|
+
|
|
73
|
+
// const dog = await ssp.loadModel({
|
|
74
|
+
// id: 'dog',
|
|
75
|
+
// url: '../assets/glb/dog.glb',
|
|
76
|
+
// });
|
|
77
|
+
// console.log('scene', ssp)
|
|
78
|
+
console.log('sceneObject', sceneObject)
|
|
79
|
+
console.log('dogObject', dogObject)
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
loadGS3D()
|
|
84
|
+
|
|
85
|
+
</script>
|
|
86
|
+
</body>
|
|
87
|
+
</html>
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@soonspacejs/plugin-gs3d-loader",
|
|
3
|
+
"version": "2.13.6",
|
|
4
|
+
"description": "GS3D plugin for SoonSpace.js",
|
|
5
|
+
"main": "dist/index.esm.js",
|
|
6
|
+
"module": "dist/index.esm.js",
|
|
7
|
+
"unpkg": "dist/index.esm.js",
|
|
8
|
+
"typings": "dist/index.d.ts",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"soonspacejs",
|
|
11
|
+
"gs3dLoader"
|
|
12
|
+
],
|
|
13
|
+
"author": "xunwei",
|
|
14
|
+
"license": "UNLICENSED",
|
|
15
|
+
"gitHead": "31d61cfb34a7879b1cff3a955663415672ef2ef7",
|
|
16
|
+
"peerDependencies": {
|
|
17
|
+
"soonspacejs": "2.13.7"
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import * as GaussianSplats3D from '@mkkellogg/gaussian-splats-3d'
|
|
2
|
+
// import SoonSpace from 'soonspacejs'
|
|
3
|
+
import { sceneOption, DropInViewer, SplatScene, } from './types'
|
|
4
|
+
|
|
5
|
+
let index = 0
|
|
6
|
+
|
|
7
|
+
const loadingPromiseList: Promise<void>[] = []
|
|
8
|
+
|
|
9
|
+
class GS3DLoaderPlugin {
|
|
10
|
+
|
|
11
|
+
dropInViewer: DropInViewer
|
|
12
|
+
|
|
13
|
+
constructor () {
|
|
14
|
+
|
|
15
|
+
this.dropInViewer = this.createViewer()
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async load ( path: string ) {
|
|
20
|
+
|
|
21
|
+
const indexes = await this.loads( [ { path, } ] )
|
|
22
|
+
|
|
23
|
+
return indexes[ 0 ]
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async loads (
|
|
28
|
+
options: sceneOption[],
|
|
29
|
+
showLoadingUI?: boolean
|
|
30
|
+
// onProgress?: ( totalPercent: number, percentLabel: string, loaderStatus: LoaderStatus ) => void
|
|
31
|
+
) {
|
|
32
|
+
|
|
33
|
+
if ( loadingPromiseList.length ) {
|
|
34
|
+
|
|
35
|
+
await Promise.allSettled( loadingPromiseList )
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const loadingPromise = this.dropInViewer.addSplatScenes( options, showLoadingUI ?? false )
|
|
40
|
+
|
|
41
|
+
loadingPromiseList.push( loadingPromise )
|
|
42
|
+
|
|
43
|
+
await Promise.allSettled( loadingPromiseList )
|
|
44
|
+
|
|
45
|
+
const indexes: number[] = []
|
|
46
|
+
|
|
47
|
+
options.forEach( () => indexes.push( index++ ) )
|
|
48
|
+
|
|
49
|
+
return indexes
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
createViewer ( option?: Record<string, any> ) {
|
|
54
|
+
|
|
55
|
+
const dropInViewer = new GaussianSplats3D.DropInViewer(
|
|
56
|
+
{
|
|
57
|
+
// ignoreDevicePixelRatio: false,
|
|
58
|
+
sharedMemoryForWorkers: false,
|
|
59
|
+
gpuAcceleratedSort: false,
|
|
60
|
+
halfPrecisionCovariancesOnGPU: true,
|
|
61
|
+
// integerBasedSort: true,
|
|
62
|
+
dynamicScene: true,
|
|
63
|
+
...option,
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
) as DropInViewer
|
|
67
|
+
|
|
68
|
+
return dropInViewer
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getSplatScene ( sceneIndex: number ) {
|
|
73
|
+
|
|
74
|
+
return this.dropInViewer.getSplatScene( sceneIndex )
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
getSceneCount () {
|
|
79
|
+
|
|
80
|
+
return this.dropInViewer.getSceneCount()
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async dispose () {
|
|
85
|
+
|
|
86
|
+
if ( this.dropInViewer ) {
|
|
87
|
+
|
|
88
|
+
await this.dropInViewer.dispose()
|
|
89
|
+
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export default GS3DLoaderPlugin
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Group, Matrix4, Object3D, } from 'three'
|
|
2
|
+
|
|
3
|
+
export enum SceneFormat {
|
|
4
|
+
'Splat' = 0,
|
|
5
|
+
'KSplat' = 1,
|
|
6
|
+
'Ply' = 2,
|
|
7
|
+
'Spz' = 3
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export enum LoaderStatus {
|
|
11
|
+
'Downloading' = 0,
|
|
12
|
+
'Processing' = 1,
|
|
13
|
+
'Done' = 2
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface option {
|
|
17
|
+
splatAlphaRemovalThreshold?: number; // 0-255
|
|
18
|
+
position?: Array<number>;
|
|
19
|
+
rotation?: Array<number>;
|
|
20
|
+
scale?: Array<number>;
|
|
21
|
+
onProgress?: () => void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface sceneOption {
|
|
25
|
+
path: string;
|
|
26
|
+
splatAlphaRemovalThreshold?: number; // 0-255
|
|
27
|
+
position?: Array<number>;
|
|
28
|
+
rotation?: Array<number>;
|
|
29
|
+
scale?: Array<number>;
|
|
30
|
+
headers?: Headers;
|
|
31
|
+
format?: SceneFormat;
|
|
32
|
+
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface DropInViewer extends Group {
|
|
36
|
+
viewer: any;
|
|
37
|
+
updateSplatMesh: () => void;
|
|
38
|
+
addSplatScene: ( path: string, options?: option ) => Promise<void>;
|
|
39
|
+
addSplatScenes: ( sceneOptions: sceneOption[], showLoadingUI: boolean ) => Promise<void>;
|
|
40
|
+
getSplatScene: ( sceneIndex: number ) => SplatScene;
|
|
41
|
+
removeSplatScene: ( index: number ) => Promise<void>;
|
|
42
|
+
removeSplatScenes: ( indexes: number[] ) => Promise<void>;
|
|
43
|
+
getSceneCount: () => number;
|
|
44
|
+
dispose: () => Promise<any>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface SplatScene extends Object3D {
|
|
48
|
+
splatBuffer: Matrix4;
|
|
49
|
+
transform: Matrix4;
|
|
50
|
+
opacity: number;
|
|
51
|
+
|
|
52
|
+
copyTransformData: ( otherScene: SplatScene ) => void;
|
|
53
|
+
updateTransform: ( dynamicMode: boolean ) => void;
|
|
54
|
+
}
|