@soonspacejs/plugin-gs3d-loader 2.14.0 → 2.14.2
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/package.json +3 -3
- package/example/gs/dog.splat +0 -0
- package/example/gs/scene.ply +0 -0
- package/example/index.html +0 -82
- package/src/index.ts +0 -84
- package/src/types.ts +0 -55
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soonspacejs/plugin-gs3d-loader",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.2",
|
|
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": "00bbf1c9241f4466abe494c009c99a316ccfc24a",
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"soonspacejs": "2.14.
|
|
17
|
+
"soonspacejs": "2.14.2"
|
|
18
18
|
}
|
|
19
19
|
}
|
package/example/gs/dog.splat
DELETED
|
Binary file
|
package/example/gs/scene.ply
DELETED
|
Binary file
|
package/example/index.html
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
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
|
-
<style>
|
|
8
|
-
* {
|
|
9
|
-
margin: 0;
|
|
10
|
-
}
|
|
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';
|
|
30
|
-
|
|
31
|
-
const ssp = (window.ssp = new SoonSpace({
|
|
32
|
-
el: '#view',
|
|
33
|
-
options: {
|
|
34
|
-
showInfo: true,
|
|
35
|
-
showGrid: true,
|
|
36
|
-
},
|
|
37
|
-
events: {
|
|
38
|
-
selectPosition(position) {
|
|
39
|
-
// console.log(position);
|
|
40
|
-
},
|
|
41
|
-
modelClick(p) {
|
|
42
|
-
console.log(p);
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
}));
|
|
46
|
-
|
|
47
|
-
const gs3dLoaderPlugin = ssp.registerPlugin(GS3DLoaderPlugin, 'GS3DLoader');
|
|
48
|
-
|
|
49
|
-
async function loadGS3D() {
|
|
50
|
-
|
|
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);
|
|
57
|
-
|
|
58
|
-
ssp.addObject(dogViewer);
|
|
59
|
-
// ssp.addObject(sceneViewer);
|
|
60
|
-
|
|
61
|
-
const _quat = new THREE.Quaternion();
|
|
62
|
-
|
|
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); // 机器狗缩放
|
|
69
|
-
|
|
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
|
-
}
|
|
78
|
-
|
|
79
|
-
loadGS3D();
|
|
80
|
-
</script>
|
|
81
|
-
</body>
|
|
82
|
-
</html>
|
package/src/index.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import * as GaussianSplats3D from '@mkkellogg/gaussian-splats-3d'
|
|
2
|
-
import { ScenesOption, DropInViewer, SceneOption, LoaderStatus, } from './types'
|
|
3
|
-
import { Quaternion, Vector3, } from 'three'
|
|
4
|
-
import SoonSpace from 'soonspacejs'
|
|
5
|
-
|
|
6
|
-
const _quat = new Quaternion().setFromAxisAngle( new Vector3( 0, 0, 1 ), Math.PI )
|
|
7
|
-
|
|
8
|
-
class GS3DLoaderPlugin {
|
|
9
|
-
|
|
10
|
-
ssp?: SoonSpace
|
|
11
|
-
|
|
12
|
-
constructor ( ssp?: SoonSpace ) {
|
|
13
|
-
|
|
14
|
-
this.ssp = ssp
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async load (
|
|
19
|
-
path: string,
|
|
20
|
-
option: SceneOption = {},
|
|
21
|
-
viewer?: DropInViewer
|
|
22
|
-
) {
|
|
23
|
-
|
|
24
|
-
if ( !viewer ) viewer = this.createViewer()
|
|
25
|
-
|
|
26
|
-
await viewer.addSplatScene( path, {
|
|
27
|
-
showLoadingUI: false,
|
|
28
|
-
...option,
|
|
29
|
-
} )
|
|
30
|
-
|
|
31
|
-
const scene = viewer.getSplatScene( 0 )
|
|
32
|
-
|
|
33
|
-
if ( scene ) scene.quaternion.copy( _quat )
|
|
34
|
-
|
|
35
|
-
return viewer
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async loads (
|
|
40
|
-
options: ScenesOption[],
|
|
41
|
-
viewer?: DropInViewer,
|
|
42
|
-
showLoadingUI = false,
|
|
43
|
-
onProgress?: ( totalPercent: number, percentLabel: string, loaderStatus: LoaderStatus ) => void
|
|
44
|
-
) {
|
|
45
|
-
|
|
46
|
-
if ( !viewer ) viewer = this.createViewer()
|
|
47
|
-
|
|
48
|
-
await viewer.addSplatScenes( options, showLoadingUI, onProgress )
|
|
49
|
-
|
|
50
|
-
const count = viewer.getSceneCount()
|
|
51
|
-
|
|
52
|
-
for ( let i = 0; i < count; i++ ) {
|
|
53
|
-
|
|
54
|
-
const scene = ( viewer as DropInViewer ).getSplatScene( i )
|
|
55
|
-
|
|
56
|
-
if ( scene ) scene.quaternion.copy( _quat )
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return viewer
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
createViewer ( option?: Record<string, any> ) {
|
|
65
|
-
|
|
66
|
-
const dropInViewer = new GaussianSplats3D.DropInViewer(
|
|
67
|
-
{
|
|
68
|
-
// ignoreDevicePixelRatio: false,
|
|
69
|
-
sharedMemoryForWorkers: false,
|
|
70
|
-
gpuAcceleratedSort: false,
|
|
71
|
-
halfPrecisionCovariancesOnGPU: true,
|
|
72
|
-
// integerBasedSort: true,
|
|
73
|
-
dynamicScene: true,
|
|
74
|
-
...option,
|
|
75
|
-
}
|
|
76
|
-
) as DropInViewer
|
|
77
|
-
|
|
78
|
-
return dropInViewer
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export default GS3DLoaderPlugin
|
package/src/types.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
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 SceneOption {
|
|
17
|
-
splatAlphaRemovalThreshold?: number; // 0-255
|
|
18
|
-
position?: Array<number>;
|
|
19
|
-
rotation?: Array<number>;
|
|
20
|
-
scale?: Array<number>;
|
|
21
|
-
showLoadingUI?: boolean;
|
|
22
|
-
headers?: Headers;
|
|
23
|
-
onProgress?: ( percentComplete: number, percentCompleteLabel: string, loaderStatus: LoaderStatus ) => void;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface ScenesOption {
|
|
27
|
-
path: string;
|
|
28
|
-
splatAlphaRemovalThreshold?: number; // 0-255
|
|
29
|
-
position?: Array<number>;
|
|
30
|
-
rotation?: Array<number>;
|
|
31
|
-
scale?: Array<number>;
|
|
32
|
-
headers?: Headers;
|
|
33
|
-
format?: SceneFormat;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface DropInViewer extends Group {
|
|
37
|
-
viewer: any;
|
|
38
|
-
updateSplatMesh: () => 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>;
|
|
41
|
-
getSplatScene: ( sceneIndex: number ) => SplatScene;
|
|
42
|
-
removeSplatScene: ( index: number ) => Promise<void>;
|
|
43
|
-
removeSplatScenes: ( indexes: number[] ) => Promise<void>;
|
|
44
|
-
getSceneCount: () => number;
|
|
45
|
-
dispose: () => Promise<any>;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface SplatScene extends Object3D {
|
|
49
|
-
splatBuffer: Matrix4;
|
|
50
|
-
transform: Matrix4;
|
|
51
|
-
opacity: number;
|
|
52
|
-
|
|
53
|
-
copyTransformData: ( otherScene: SplatScene ) => void;
|
|
54
|
-
updateTransform: ( dynamicMode: boolean ) => void;
|
|
55
|
-
}
|