@tomorrowevening/hermes 0.0.120 → 0.0.121
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/hermes.cjs.js +16 -16
- package/dist/hermes.es.js +604 -518
- package/package.json +4 -4
- package/src/webworkers/LoadWorker.ts +161 -0
- package/types/index.d.ts +2 -0
- package/types/utils/three.d.ts +7 -1
- package/types/webworkers/LoadWorker.d.ts +1 -0
- package/types/webworkers/ProxyManager.d.ts +45 -0
- package/types/webworkers/types.d.ts +21 -0
package/package.json
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
"module": "./dist/hermes.esm.js",
|
8
8
|
"types": "./types/index.d.ts",
|
9
9
|
"type": "module",
|
10
|
-
"version": "0.0.
|
10
|
+
"version": "0.0.121",
|
11
11
|
"homepage": "https://github.com/tomorrowevening/hermes#readme",
|
12
12
|
"bugs": {
|
13
13
|
"url": "https://github.com/tomorrowevening/hermes/issues"
|
@@ -22,7 +22,8 @@
|
|
22
22
|
"dist/hermes.es.js",
|
23
23
|
"dist/hermes.cjs.js",
|
24
24
|
"dist/style.css",
|
25
|
-
"types/**/*.d.ts"
|
25
|
+
"types/**/*.d.ts",
|
26
|
+
"src/webworkers/LoadWorker.ts"
|
26
27
|
],
|
27
28
|
"exports": {
|
28
29
|
".": {
|
@@ -30,8 +31,7 @@
|
|
30
31
|
"require": "./dist/hermes.cjs.js",
|
31
32
|
"types": "./types/index.d.ts"
|
32
33
|
},
|
33
|
-
"./dist/style.css": "./dist/style.css"
|
34
|
-
"./server/index.mjs": "./server/index.mjs"
|
34
|
+
"./dist/style.css": "./dist/style.css"
|
35
35
|
},
|
36
36
|
"repository": {
|
37
37
|
"type": "git",
|
@@ -0,0 +1,161 @@
|
|
1
|
+
import { Group, Object3DEventMap } from 'three';
|
2
|
+
import { FBXLoader } from 'three/examples/jsm/Addons.js';
|
3
|
+
import { DRACOLoader } from 'three/examples/jsm/loaders/DRACOLoader.js';
|
4
|
+
import { GLTF, GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js';
|
5
|
+
import { Assets, File, ModelLite } from './types';
|
6
|
+
|
7
|
+
let loadedAssets = 0;
|
8
|
+
let assetList: File[] = [];
|
9
|
+
|
10
|
+
const assets: Assets = {
|
11
|
+
audio: {},
|
12
|
+
blob: {},
|
13
|
+
buffer: {},
|
14
|
+
images: {},
|
15
|
+
json: {},
|
16
|
+
models: {},
|
17
|
+
video: {},
|
18
|
+
};
|
19
|
+
|
20
|
+
// Loaders
|
21
|
+
|
22
|
+
const draco = new DRACOLoader();
|
23
|
+
draco.setDecoderPath('/libs/draco/');
|
24
|
+
draco.preload();
|
25
|
+
|
26
|
+
const fbxLoader = new FBXLoader();
|
27
|
+
|
28
|
+
const gltfLoader = new GLTFLoader();
|
29
|
+
gltfLoader.setDRACOLoader(draco);
|
30
|
+
|
31
|
+
// Load functions
|
32
|
+
|
33
|
+
async function loadArrayBuffer(url: string): Promise<ArrayBuffer> {
|
34
|
+
const response = await fetch(url);
|
35
|
+
return await response.arrayBuffer();
|
36
|
+
}
|
37
|
+
|
38
|
+
async function loadBlob(url: string): Promise<Blob> {
|
39
|
+
const response = await fetch(url);
|
40
|
+
return await response.blob();
|
41
|
+
}
|
42
|
+
|
43
|
+
async function loadFBX(url: string): Promise<ModelLite> {
|
44
|
+
return new Promise((resolve) => {
|
45
|
+
fbxLoader.loadAsync(url)
|
46
|
+
.then((value: Group<Object3DEventMap>) => {
|
47
|
+
resolve({
|
48
|
+
animations: value.animations.map(animation => animation.toJSON(animation)),
|
49
|
+
scene: value.toJSON(),
|
50
|
+
});
|
51
|
+
})
|
52
|
+
.catch((reason: any) => {
|
53
|
+
console.log('FBX Error:');
|
54
|
+
console.log(reason);
|
55
|
+
});
|
56
|
+
});
|
57
|
+
}
|
58
|
+
|
59
|
+
async function loadGLTF(url: string): Promise<ModelLite> {
|
60
|
+
return new Promise((resolve) => {
|
61
|
+
gltfLoader.loadAsync(url)
|
62
|
+
.then((value: GLTF) => {
|
63
|
+
resolve({
|
64
|
+
animations: value.animations.map(animation => animation.toJSON(animation)),
|
65
|
+
cameras: value.cameras.map(camera => camera.toJSON()),
|
66
|
+
scene: value.scene.toJSON(),
|
67
|
+
});
|
68
|
+
})
|
69
|
+
.catch((reason: any) => {
|
70
|
+
console.log('GLTF Error:');
|
71
|
+
console.log(reason);
|
72
|
+
});
|
73
|
+
});
|
74
|
+
}
|
75
|
+
|
76
|
+
async function loadImage(url: string): Promise<ImageBitmap> {
|
77
|
+
const blob = await loadBlob(url);
|
78
|
+
return await createImageBitmap(blob);
|
79
|
+
}
|
80
|
+
|
81
|
+
async function loadJSON(url: string): Promise<any> {
|
82
|
+
const response = await fetch(url);
|
83
|
+
return response.json();
|
84
|
+
}
|
85
|
+
|
86
|
+
// Load calls
|
87
|
+
|
88
|
+
function loadStart() {
|
89
|
+
assetList.forEach((item: File) => {
|
90
|
+
switch (item.type) {
|
91
|
+
case 'audio':
|
92
|
+
loadArrayBuffer(item.file).then((value: ArrayBuffer) => {
|
93
|
+
assets.audio[item.name] = value;
|
94
|
+
onLoad();
|
95
|
+
});
|
96
|
+
break;
|
97
|
+
case 'blob':
|
98
|
+
loadBlob(item.file).then((value: Blob) => {
|
99
|
+
assets.blob[item.name] = value;
|
100
|
+
onLoad();
|
101
|
+
});
|
102
|
+
break;
|
103
|
+
case 'buffer':
|
104
|
+
loadArrayBuffer(item.file).then((value: ArrayBuffer) => {
|
105
|
+
assets.buffer[item.name] = value;
|
106
|
+
onLoad();
|
107
|
+
});
|
108
|
+
break;
|
109
|
+
case 'fbx':
|
110
|
+
loadFBX(item.file).then((value: ModelLite) => {
|
111
|
+
assets.models[item.name] = value;
|
112
|
+
onLoad();
|
113
|
+
});
|
114
|
+
break;
|
115
|
+
case 'gltf':
|
116
|
+
loadGLTF(item.file).then((value: ModelLite) => {
|
117
|
+
assets.models[item.name] = value;
|
118
|
+
onLoad();
|
119
|
+
});
|
120
|
+
break;
|
121
|
+
case 'image':
|
122
|
+
loadImage(item.file).then((value: ImageBitmap) => {
|
123
|
+
assets.images[item.name] = value;
|
124
|
+
onLoad();
|
125
|
+
});
|
126
|
+
break;
|
127
|
+
case 'json':
|
128
|
+
loadJSON(item.file).then((value: any) => {
|
129
|
+
assets.json[item.name] = value;
|
130
|
+
onLoad();
|
131
|
+
});
|
132
|
+
break;
|
133
|
+
case 'video':
|
134
|
+
loadBlob(item.file).then((value: Blob) => {
|
135
|
+
assets.video[item.name] = value;
|
136
|
+
onLoad();
|
137
|
+
});
|
138
|
+
break;
|
139
|
+
}
|
140
|
+
});
|
141
|
+
}
|
142
|
+
|
143
|
+
function onLoad() {
|
144
|
+
loadedAssets++;
|
145
|
+
if (loadedAssets >= assetList.length) loadComplete();
|
146
|
+
}
|
147
|
+
|
148
|
+
function loadComplete() {
|
149
|
+
self.postMessage({ type: 'loadComplete', data: assets });
|
150
|
+
}
|
151
|
+
|
152
|
+
// Worker
|
153
|
+
|
154
|
+
self.onmessage = (event: MessageEvent) => {
|
155
|
+
switch (event.data.type) {
|
156
|
+
case 'loadStart':
|
157
|
+
assetList = event.data.data;
|
158
|
+
loadStart();
|
159
|
+
break;
|
160
|
+
}
|
161
|
+
};
|
package/types/index.d.ts
CHANGED
@@ -3,6 +3,8 @@ export * from './editor/utils';
|
|
3
3
|
export * from './utils/detectSettings';
|
4
4
|
export * from './utils/math';
|
5
5
|
export * from './utils/three';
|
6
|
+
export * from './webworkers/types';
|
7
|
+
export * from './webworkers/ProxyManager';
|
6
8
|
export { default as Application } from './core/Application';
|
7
9
|
export { debugDispatcher, ToolEvents } from './editor/global';
|
8
10
|
export { default as BaseRemote } from './core/remote/BaseRemote';
|
package/types/utils/three.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
import { Material, Object3D, Texture, WebGLRenderer } from 'three';
|
1
|
+
import { AnimationMixer, Material, Object3D, Texture, WebGLRenderer } from 'three';
|
2
|
+
import { ModelLite } from '../webworkers/types';
|
2
3
|
export declare const disposeTexture: (texture?: Texture) => void;
|
3
4
|
export declare const disposeMaterial: (material?: Material | Material[]) => void;
|
4
5
|
export declare const dispose: (object: Object3D) => void;
|
@@ -19,3 +20,8 @@ export declare class ExportTexture {
|
|
19
20
|
static renderToBlob(texture: Texture): string;
|
20
21
|
private static renderToCanvas;
|
21
22
|
}
|
23
|
+
export declare function parseModelLite(model: ModelLite): {
|
24
|
+
model: Object3D<import("three").Object3DEventMap>;
|
25
|
+
mixer: AnimationMixer;
|
26
|
+
cameras: Object3D<import("three").Object3DEventMap>[];
|
27
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import { EventDispatcher } from 'three';
|
2
|
+
interface SizeData {
|
3
|
+
left: number;
|
4
|
+
top: number;
|
5
|
+
width: number;
|
6
|
+
height: number;
|
7
|
+
}
|
8
|
+
interface EventData extends SizeData {
|
9
|
+
type: string;
|
10
|
+
id?: number;
|
11
|
+
data?: any;
|
12
|
+
preventDefault?: () => void;
|
13
|
+
stopPropagation?: () => void;
|
14
|
+
}
|
15
|
+
export declare class ElementProxyReceiver extends EventDispatcher {
|
16
|
+
style: Record<string, any>;
|
17
|
+
left: number;
|
18
|
+
top: number;
|
19
|
+
width: number;
|
20
|
+
height: number;
|
21
|
+
ownerDocument: any;
|
22
|
+
get clientWidth(): number;
|
23
|
+
set clientWidth(value: number);
|
24
|
+
get clientHeight(): number;
|
25
|
+
set clientHeight(value: number);
|
26
|
+
setPointerCapture(): void;
|
27
|
+
releasePointerCapture(): void;
|
28
|
+
getBoundingClientRect(): DOMRect;
|
29
|
+
handleEvent(data: EventData): void;
|
30
|
+
focus(): void;
|
31
|
+
getRootNode(): any;
|
32
|
+
}
|
33
|
+
export declare class ProxyManager {
|
34
|
+
targets: Record<number, ElementProxyReceiver>;
|
35
|
+
constructor();
|
36
|
+
makeProxy(data: {
|
37
|
+
id: number;
|
38
|
+
}): void;
|
39
|
+
getProxy(id: number): ElementProxyReceiver;
|
40
|
+
handleEvent(data: {
|
41
|
+
id: number;
|
42
|
+
data: EventData;
|
43
|
+
}): void;
|
44
|
+
}
|
45
|
+
export {};
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { AnimationClip, Object3DJSON } from 'three';
|
2
|
+
export type FileType = 'audio' | 'blob' | 'buffer' | 'fbx' | 'gltf' | 'image' | 'json' | 'video';
|
3
|
+
export type File = {
|
4
|
+
name: string;
|
5
|
+
file: string;
|
6
|
+
type: FileType;
|
7
|
+
};
|
8
|
+
export type Assets = {
|
9
|
+
audio: any;
|
10
|
+
blob: any;
|
11
|
+
buffer: any;
|
12
|
+
images: any;
|
13
|
+
json: any;
|
14
|
+
models: any;
|
15
|
+
video: any;
|
16
|
+
};
|
17
|
+
export type ModelLite = {
|
18
|
+
animations: AnimationClip[];
|
19
|
+
cameras?: Object3DJSON[];
|
20
|
+
scene: Object3DJSON;
|
21
|
+
};
|