@soonspacejs/plugin-gs3d-loader 2.13.8 → 2.13.9
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/dist/index.d.ts +3 -7
- package/dist/index.esm.js +1 -1
- package/dist/types.d.ts +6 -4
- package/example/gs/dog.splat +0 -0
- package/example/gs/scene.ply +0 -0
- package/example/index.html +68 -73
- package/package.json +3 -3
- package/src/index.ts +30 -49
- package/src/types.ts +6 -5
package/dist/types.d.ts
CHANGED
|
@@ -10,14 +10,16 @@ export declare enum LoaderStatus {
|
|
|
10
10
|
'Processing' = 1,
|
|
11
11
|
'Done' = 2
|
|
12
12
|
}
|
|
13
|
-
export interface
|
|
13
|
+
export interface SceneOption {
|
|
14
14
|
splatAlphaRemovalThreshold?: number;
|
|
15
15
|
position?: Array<number>;
|
|
16
16
|
rotation?: Array<number>;
|
|
17
17
|
scale?: Array<number>;
|
|
18
|
+
showLoadingUI?: boolean;
|
|
19
|
+
headers?: Headers;
|
|
18
20
|
onProgress?: () => void;
|
|
19
21
|
}
|
|
20
|
-
export interface
|
|
22
|
+
export interface ScenesOption {
|
|
21
23
|
path: string;
|
|
22
24
|
splatAlphaRemovalThreshold?: number;
|
|
23
25
|
position?: Array<number>;
|
|
@@ -29,8 +31,8 @@ export interface sceneOption {
|
|
|
29
31
|
export interface DropInViewer extends Group {
|
|
30
32
|
viewer: any;
|
|
31
33
|
updateSplatMesh: () => void;
|
|
32
|
-
addSplatScene: (path: string, options?:
|
|
33
|
-
addSplatScenes: (sceneOptions:
|
|
34
|
+
addSplatScene: (path: string, options?: SceneOption) => Promise<void>;
|
|
35
|
+
addSplatScenes: (sceneOptions: ScenesOption[], showLoadingUI: boolean) => Promise<void>;
|
|
34
36
|
getSplatScene: (sceneIndex: number) => SplatScene;
|
|
35
37
|
removeSplatScene: (index: number) => Promise<void>;
|
|
36
38
|
removeSplatScenes: (indexes: number[]) => Promise<void>;
|
|
Binary file
|
|
Binary file
|
package/example/index.html
CHANGED
|
@@ -1,87 +1,82 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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"
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>Document</title>
|
|
7
|
+
<style>
|
|
8
|
+
* {
|
|
9
|
+
margin: 0;
|
|
18
10
|
}
|
|
19
|
-
|
|
20
|
-
</
|
|
21
|
-
<
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
</style>
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<div id="view" style="width: 100vw; height: 100vh"></div>
|
|
15
|
+
<script type="importmap">
|
|
16
|
+
{
|
|
17
|
+
"imports": {
|
|
18
|
+
"soonspacejs": "../../../soonspacejs/dist/index.esm.js",
|
|
19
|
+
"three/": "/node_modules/three/",
|
|
20
|
+
"three": "/node_modules/three/build/three.module.js",
|
|
21
|
+
"three-mesh-bvh": "/node_modules/three-mesh-bvh/build/index.module.js",
|
|
22
|
+
"postprocessing": "/node_modules/postprocessing/build/index.js"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
</script>
|
|
26
|
+
<script type="module">
|
|
27
|
+
import SoonSpace from '../../../soonspacejs/dist/index.esm.js';
|
|
28
|
+
import GS3DLoaderPlugin from '../dist/index.esm.js';
|
|
29
|
+
import * as THREE from 'three';
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
},
|
|
32
|
-
events: {
|
|
33
|
-
selectPosition(position) {
|
|
34
|
-
// console.log(position);
|
|
31
|
+
const ssp = (window.ssp = new SoonSpace({
|
|
32
|
+
el: '#view',
|
|
33
|
+
options: {
|
|
34
|
+
showInfo: true,
|
|
35
|
+
showGrid: true,
|
|
35
36
|
},
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
events: {
|
|
38
|
+
selectPosition(position) {
|
|
39
|
+
// console.log(position);
|
|
40
|
+
},
|
|
41
|
+
modelClick(p) {
|
|
42
|
+
console.log(p);
|
|
43
|
+
},
|
|
38
44
|
},
|
|
39
|
-
}
|
|
40
|
-
}));
|
|
41
|
-
|
|
42
|
-
const gs3dLoaderPlugin = ssp.registerPlugin(GS3DLoaderPlugin, 'GS3DLoader');
|
|
45
|
+
}));
|
|
43
46
|
|
|
44
|
-
|
|
45
|
-
debugger
|
|
46
|
-
const list = ['../assets/gs/dog.splat', '../assets/gs/scene.ply']
|
|
47
|
+
const gs3dLoaderPlugin = ssp.registerPlugin(GS3DLoaderPlugin, 'GS3DLoader');
|
|
47
48
|
|
|
48
|
-
|
|
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')
|
|
49
|
+
async function loadGS3D() {
|
|
55
50
|
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
// debugger
|
|
52
|
+
const dogViewer = await gs3dLoaderPlugin.load('./gs/dog.splat');
|
|
53
|
+
const sceneViewer = await gs3dLoaderPlugin.load('./gs/scene.ply');
|
|
54
|
+
|
|
55
|
+
const dogObject = dogViewer.getSplatScene(0);
|
|
56
|
+
const sceneObject = sceneViewer.getSplatScene(0);
|
|
58
57
|
|
|
59
|
-
|
|
58
|
+
ssp.addObject(dogViewer);
|
|
59
|
+
// ssp.addObject(sceneViewer);
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
// sceneObject.quaternion.copy(_quat);
|
|
64
|
-
sceneObject.rotation.set(0, 0, Math.PI)
|
|
61
|
+
const _quat = new THREE.Quaternion();
|
|
65
62
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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)
|
|
63
|
+
dogObject.position.setY(0.2); // 机器狗底盘高度
|
|
64
|
+
_quat
|
|
65
|
+
.setFromAxisAngle(new THREE.Vector3(1, 0, 0), Math.PI)
|
|
66
|
+
.multiply(new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), -Math.PI / 5));
|
|
67
|
+
dogObject.quaternion.copy(_quat); // 旋转校正
|
|
68
|
+
dogObject.scale.setScalar(0.5); // 机器狗缩放
|
|
80
69
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
70
|
+
// const dog = await ssp.loadModel({
|
|
71
|
+
// id: 'dog',
|
|
72
|
+
// url: '../assets/glb/dog.glb',
|
|
73
|
+
// });
|
|
74
|
+
// console.log('scene', ssp)
|
|
75
|
+
console.log('sceneObject', sceneObject);
|
|
76
|
+
console.log('dogObject', dogObject);
|
|
77
|
+
}
|
|
84
78
|
|
|
85
|
-
|
|
86
|
-
</
|
|
87
|
-
</
|
|
79
|
+
loadGS3D();
|
|
80
|
+
</script>
|
|
81
|
+
</body>
|
|
82
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soonspacejs/plugin-gs3d-loader",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.9",
|
|
4
4
|
"description": "GS3D plugin for SoonSpace.js",
|
|
5
5
|
"main": "dist/index.esm.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
],
|
|
13
13
|
"author": "xunwei",
|
|
14
14
|
"license": "UNLICENSED",
|
|
15
|
-
"gitHead": "
|
|
15
|
+
"gitHead": "a5596909f48bd136905b85f239e13690f9f2c66e",
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"soonspacejs": "2.13.
|
|
17
|
+
"soonspacejs": "2.13.9"
|
|
18
18
|
}
|
|
19
19
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,52 +1,56 @@
|
|
|
1
1
|
import * as GaussianSplats3D from '@mkkellogg/gaussian-splats-3d'
|
|
2
|
-
|
|
3
|
-
import {
|
|
2
|
+
import { ScenesOption, DropInViewer, SceneOption, } from './types'
|
|
3
|
+
import { Quaternion, Vector3, } from 'three'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const loadingPromiseList: Promise<void>[] = []
|
|
5
|
+
const _quat = new Quaternion().setFromAxisAngle( new Vector3( 0, 0, 1 ), Math.PI )
|
|
8
6
|
|
|
9
7
|
class GS3DLoaderPlugin {
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
constructor () {
|
|
9
|
+
constructor () {}
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
async load (
|
|
12
|
+
path: string,
|
|
13
|
+
option: SceneOption = {},
|
|
14
|
+
viewer?: DropInViewer
|
|
15
|
+
) {
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
if ( !viewer ) viewer = this.createViewer()
|
|
18
|
+
|
|
19
|
+
await viewer.addSplatScene( path, {
|
|
20
|
+
showLoadingUI: false,
|
|
21
|
+
...option,
|
|
22
|
+
} )
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
const scene = viewer.getSplatScene( 0 )
|
|
20
25
|
|
|
21
|
-
|
|
26
|
+
if ( scene ) scene.quaternion.copy( _quat )
|
|
22
27
|
|
|
23
|
-
return
|
|
28
|
+
return viewer
|
|
24
29
|
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
async loads (
|
|
28
|
-
options:
|
|
29
|
-
|
|
33
|
+
options: ScenesOption[],
|
|
34
|
+
viewer?: DropInViewer,
|
|
35
|
+
showLoadingUI = false
|
|
30
36
|
// onProgress?: ( totalPercent: number, percentLabel: string, loaderStatus: LoaderStatus ) => void
|
|
31
37
|
) {
|
|
32
38
|
|
|
33
|
-
if (
|
|
39
|
+
if ( !viewer ) viewer = this.createViewer()
|
|
34
40
|
|
|
35
|
-
|
|
41
|
+
await viewer.addSplatScenes( options, showLoadingUI )
|
|
36
42
|
|
|
37
|
-
|
|
43
|
+
const count = viewer.getSceneCount()
|
|
38
44
|
|
|
39
|
-
|
|
45
|
+
for ( let i = 0; i < count; i++ ) {
|
|
40
46
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
await Promise.allSettled( loadingPromiseList )
|
|
47
|
+
const scene = ( viewer as DropInViewer ).getSplatScene( i )
|
|
44
48
|
|
|
45
|
-
|
|
49
|
+
if ( scene ) scene.quaternion.copy( _quat )
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return viewer
|
|
50
54
|
|
|
51
55
|
}
|
|
52
56
|
|
|
@@ -61,7 +65,6 @@ class GS3DLoaderPlugin {
|
|
|
61
65
|
// integerBasedSort: true,
|
|
62
66
|
dynamicScene: true,
|
|
63
67
|
...option,
|
|
64
|
-
|
|
65
68
|
}
|
|
66
69
|
) as DropInViewer
|
|
67
70
|
|
|
@@ -69,28 +72,6 @@ class GS3DLoaderPlugin {
|
|
|
69
72
|
|
|
70
73
|
}
|
|
71
74
|
|
|
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
75
|
}
|
|
95
76
|
|
|
96
77
|
export default GS3DLoaderPlugin
|
package/src/types.ts
CHANGED
|
@@ -13,15 +13,17 @@ export enum LoaderStatus {
|
|
|
13
13
|
'Done' = 2
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export interface
|
|
16
|
+
export interface SceneOption {
|
|
17
17
|
splatAlphaRemovalThreshold?: number; // 0-255
|
|
18
18
|
position?: Array<number>;
|
|
19
19
|
rotation?: Array<number>;
|
|
20
20
|
scale?: Array<number>;
|
|
21
|
+
showLoadingUI?: boolean;
|
|
22
|
+
headers?: Headers;
|
|
21
23
|
onProgress?: () => void;
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
export interface
|
|
26
|
+
export interface ScenesOption {
|
|
25
27
|
path: string;
|
|
26
28
|
splatAlphaRemovalThreshold?: number; // 0-255
|
|
27
29
|
position?: Array<number>;
|
|
@@ -29,14 +31,13 @@ export interface sceneOption {
|
|
|
29
31
|
scale?: Array<number>;
|
|
30
32
|
headers?: Headers;
|
|
31
33
|
format?: SceneFormat;
|
|
32
|
-
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
export interface DropInViewer extends Group {
|
|
36
37
|
viewer: any;
|
|
37
38
|
updateSplatMesh: () => void;
|
|
38
|
-
addSplatScene: ( path: string, options?:
|
|
39
|
-
addSplatScenes: ( sceneOptions:
|
|
39
|
+
addSplatScene: ( path: string, options?: SceneOption ) => Promise<void>;
|
|
40
|
+
addSplatScenes: ( sceneOptions: ScenesOption[], showLoadingUI: boolean ) => Promise<void>;
|
|
40
41
|
getSplatScene: ( sceneIndex: number ) => SplatScene;
|
|
41
42
|
removeSplatScene: ( index: number ) => Promise<void>;
|
|
42
43
|
removeSplatScenes: ( indexes: number[] ) => Promise<void>;
|