@soonspacejs/plugin-gs3d-loader 2.13.8 → 2.13.10

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/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 option {
13
+ export interface SceneOption {
14
14
  splatAlphaRemovalThreshold?: number;
15
15
  position?: Array<number>;
16
16
  rotation?: Array<number>;
17
17
  scale?: Array<number>;
18
- onProgress?: () => void;
18
+ showLoadingUI?: boolean;
19
+ headers?: Headers;
20
+ onProgress?: (percentComplete: number, percentCompleteLabel: string, loaderStatus: LoaderStatus) => void;
19
21
  }
20
- export interface sceneOption {
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?: option) => Promise<void>;
33
- addSplatScenes: (sceneOptions: sceneOption[], showLoadingUI: boolean) => Promise<void>;
34
+ addSplatScene: (path: string, options?: SceneOption) => Promise<void>;
35
+ addSplatScenes: (sceneOptions: ScenesOption[], showLoadingUI: boolean, onProgress?: (percentComplete: number, percentCompleteLabel: string, loaderStatus: LoaderStatus) => void) => 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
@@ -1,87 +1,82 @@
1
1
  <!DOCTYPE html>
2
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"
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
- </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'
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
- 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);
31
+ const ssp = (window.ssp = new SoonSpace({
32
+ el: '#view',
33
+ options: {
34
+ showInfo: true,
35
+ showGrid: true,
35
36
  },
36
- modelClick(p) {
37
- console.log(p);
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
- async function loadGS3D() {
45
- debugger
46
- const list = ['../assets/gs/dog.splat', '../assets/gs/scene.ply']
47
+ const gs3dLoaderPlugin = ssp.registerPlugin(GS3DLoaderPlugin, 'GS3DLoader');
47
48
 
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')
49
+ async function loadGS3D() {
55
50
 
56
- const dogObject = gs3dLoaderPlugin.getSplatScene(dogIndex.value)
57
- const sceneObject = gs3dLoaderPlugin.getSplatScene(sceneIndex.value)
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
- ssp.addObject(gs3dLoaderPlugin.dropInViewer)
58
+ ssp.addObject(dogViewer);
59
+ // ssp.addObject(sceneViewer);
60
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)
61
+ const _quat = new THREE.Quaternion();
65
62
 
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)
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
- loadGS3D()
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
- </script>
86
- </body>
87
- </html>
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.8",
3
+ "version": "2.13.10",
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": "d6b6f55e087ba0621e8bb404fc63c99fd4389660",
15
+ "gitHead": "6bca3b98477ef9c2fa0ba5f67d461561896bb0ff",
16
16
  "peerDependencies": {
17
- "soonspacejs": "2.13.8"
17
+ "soonspacejs": "2.13.10"
18
18
  }
19
19
  }
package/src/index.ts CHANGED
@@ -1,52 +1,63 @@
1
1
  import * as GaussianSplats3D from '@mkkellogg/gaussian-splats-3d'
2
- // import SoonSpace from 'soonspacejs'
3
- import { sceneOption, DropInViewer, SplatScene, } from './types'
2
+ import { ScenesOption, DropInViewer, SceneOption, LoaderStatus, } from './types'
3
+ import { Quaternion, Vector3, } from 'three'
4
+ import SoonSpace from 'soonspacejs/types/index'
4
5
 
5
- let index = 0
6
-
7
- const loadingPromiseList: Promise<void>[] = []
6
+ const _quat = new Quaternion().setFromAxisAngle( new Vector3( 0, 0, 1 ), Math.PI )
8
7
 
9
8
  class GS3DLoaderPlugin {
10
9
 
11
- dropInViewer: DropInViewer
10
+ ssp?: SoonSpace
12
11
 
13
- constructor () {
12
+ constructor ( ssp?: SoonSpace ) {
14
13
 
15
- this.dropInViewer = this.createViewer()
14
+ this.ssp = ssp
16
15
 
17
16
  }
18
17
 
19
- async load ( path: string ) {
18
+ async load (
19
+ path: string,
20
+ option: SceneOption = {},
21
+ viewer?: DropInViewer
22
+ ) {
23
+
24
+ if ( !viewer ) viewer = this.createViewer()
20
25
 
21
- const indexes = await this.loads( [ { path, } ] )
26
+ await viewer.addSplatScene( path, {
27
+ showLoadingUI: false,
28
+ ...option,
29
+ } )
22
30
 
23
- return indexes[ 0 ]
31
+ const scene = viewer.getSplatScene( 0 )
32
+
33
+ if ( scene ) scene.quaternion.copy( _quat )
34
+
35
+ return viewer
24
36
 
25
37
  }
26
38
 
27
39
  async loads (
28
- options: sceneOption[],
29
- showLoadingUI?: boolean
30
- // onProgress?: ( totalPercent: number, percentLabel: string, loaderStatus: LoaderStatus ) => void
40
+ options: ScenesOption[],
41
+ viewer?: DropInViewer,
42
+ showLoadingUI = false,
43
+ onProgress?: ( totalPercent: number, percentLabel: string, loaderStatus: LoaderStatus ) => void
31
44
  ) {
32
45
 
33
- if ( loadingPromiseList.length ) {
46
+ if ( !viewer ) viewer = this.createViewer()
34
47
 
35
- await Promise.allSettled( loadingPromiseList )
48
+ await viewer.addSplatScenes( options, showLoadingUI, onProgress )
36
49
 
37
- }
50
+ const count = viewer.getSceneCount()
38
51
 
39
- const loadingPromise = this.dropInViewer.addSplatScenes( options, showLoadingUI ?? false )
52
+ for ( let i = 0; i < count; i++ ) {
40
53
 
41
- loadingPromiseList.push( loadingPromise )
42
-
43
- await Promise.allSettled( loadingPromiseList )
54
+ const scene = ( viewer as DropInViewer ).getSplatScene( i )
44
55
 
45
- const indexes: number[] = []
56
+ if ( scene ) scene.quaternion.copy( _quat )
46
57
 
47
- options.forEach( () => indexes.push( index++ ) )
48
-
49
- return indexes
58
+ }
59
+
60
+ return viewer
50
61
 
51
62
  }
52
63
 
@@ -61,7 +72,6 @@ class GS3DLoaderPlugin {
61
72
  // integerBasedSort: true,
62
73
  dynamicScene: true,
63
74
  ...option,
64
-
65
75
  }
66
76
  ) as DropInViewer
67
77
 
@@ -69,28 +79,6 @@ class GS3DLoaderPlugin {
69
79
 
70
80
  }
71
81
 
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
82
  }
95
83
 
96
84
  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 option {
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
- onProgress?: () => void;
21
+ showLoadingUI?: boolean;
22
+ headers?: Headers;
23
+ onProgress?: ( percentComplete: number, percentCompleteLabel: string, loaderStatus: LoaderStatus ) => void;
22
24
  }
23
25
 
24
- export interface sceneOption {
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?: option ) => Promise<void>;
39
- addSplatScenes: ( sceneOptions: sceneOption[], showLoadingUI: boolean ) => Promise<void>;
39
+ addSplatScene: ( path: string, options?: SceneOption ) => Promise<void>;
40
+ addSplatScenes: ( sceneOptions: ScenesOption[], showLoadingUI: boolean, onProgress?: ( percentComplete: number, percentCompleteLabel: string, loaderStatus: LoaderStatus ) => void ) => Promise<void>;
40
41
  getSplatScene: ( sceneIndex: number ) => SplatScene;
41
42
  removeSplatScene: ( index: number ) => Promise<void>;
42
43
  removeSplatScenes: ( indexes: number[] ) => Promise<void>;