@benjos/create-boilerplate 1.3.5 → 1.4.1
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 +1 -1
- package/template-react/package-lock.json +2 -2
- package/template-react/package.json +1 -1
- package/template-react/src/App.css +21 -21
- package/template-react/src/App.tsx +5 -9
- package/template-react/src/index.css +42 -42
- package/template-react/src/main.tsx +8 -8
- package/template-vanilla/index.html +23 -14
- package/template-vanilla/package-lock.json +8 -6
- package/template-vanilla/package.json +2 -2
- package/template-vanilla/src/experiences/Experience.ts +11 -11
- package/template-vanilla/src/experiences/cameras/threes/DebugThreeCameraController.ts +13 -18
- package/template-vanilla/src/experiences/cameras/threes/LoaderThreeCameraController.ts +7 -10
- package/template-vanilla/src/experiences/cameras/threes/MainThreeCameraController.ts +6 -10
- package/template-vanilla/src/experiences/cameras/threes/bases/ThreeCameraControllerBase.ts +20 -39
- package/template-vanilla/src/experiences/commands/InitCommand.ts +30 -33
- package/template-vanilla/src/experiences/engines/htmls/MainHTML.ts +10 -7
- package/template-vanilla/src/experiences/engines/threes/MainThree.ts +8 -168
- package/template-vanilla/src/experiences/engines/threes/app/LoaderThreeApp.ts +39 -0
- package/template-vanilla/src/experiences/engines/threes/app/MainThreeApp.ts +96 -0
- package/template-vanilla/src/experiences/engines/threes/app/bases/ThreeAppBase.ts +92 -0
- package/template-vanilla/src/experiences/managers/DebugManager.ts +31 -33
- package/template-vanilla/src/experiences/managers/LoaderManager.ts +53 -45
- package/template-vanilla/src/experiences/managers/threes/ThreeAssetsManager.ts +94 -109
- package/template-vanilla/src/experiences/managers/threes/ThreeCameraControllerManager.ts +22 -19
- package/template-vanilla/src/experiences/managers/threes/ThreeRaycasterManager.ts +12 -14
- package/template-vanilla/src/experiences/materials/threes/loaders/LoaderMaterial.ts +0 -4
- package/template-vanilla/src/experiences/renderers/threes/LoaderRenderer.ts +0 -4
- package/template-vanilla/src/experiences/renderers/threes/Renderer.ts +5 -9
- package/template-vanilla/src/experiences/renderers/threes/bases/WebGLRendererBase.ts +3 -3
- package/template-vanilla/src/experiences/styles/commons/main.scss +6 -6
- package/template-vanilla/src/experiences/styles/style.scss +1 -1
- package/template-vanilla/src/experiences/styles/views/loader.scss +7 -6
- package/template-vanilla/src/experiences/types/cameraTypes.ts +37 -0
- package/template-vanilla/src/experiences/types/global.d.ts +2 -2
- package/template-vanilla/src/experiences/types/shaders.d.ts +4 -0
- package/template-vanilla/src/experiences/views/htmls/bases/HTMLViewBase.ts +13 -33
- package/template-vanilla/src/experiences/views/htmls/loaders/LoaderHTMLView.ts +27 -18
- package/template-vanilla/src/experiences/views/threes/bases/ThreeViewBase.ts +26 -18
- package/template-vanilla/src/experiences/views/threes/loaders/LoaderThreeView.ts +11 -15
- package/template-vanilla/src/experiences/views/threes/loaders/components/ThreeTemplateLoader.ts +15 -12
- package/template-vanilla/src/experiences/views/threes/worlds/WorldThreeView.ts +9 -17
- package/template-vanilla/src/experiences/views/threes/worlds/components/Environment.ts +14 -18
- package/template-vanilla/src/experiences/views/threes/worlds/components/actors/TemplateFont.ts +11 -9
- package/template-vanilla/src/experiences/views/threes/worlds/components/actors/TemplateMesh.ts +11 -9
- package/template-vanilla/src/experiences/views/threes/worlds/components/actors/TemplateModel.ts +2 -6
- package/template-vanilla/src/experiences/views/threes/worlds/components/actors/bases/ActorBase.ts +13 -1
- package/template-vanilla/src/experiences/views/threes/worlds/components/actors/bases/AnimatedModelBase.ts +5 -9
- package/template-vanilla/src/experiences/views/threes/worlds/components/actors/bases/ModelBase.ts +18 -4
- package/template-vanilla/src/main.ts +1 -1
- package/template-vanilla/tsconfig.json +17 -0
- package/template-vanilla/src/experiences/constants/experiences/CameraType.ts +0 -6
- package/template-vanilla/src/experiences/managers/KeyboardManager.ts +0 -65
- package/template-vanilla/src/experiences/managers/MouseManager.ts +0 -100
- package/template-vanilla/src/experiences/managers/ResizeManager.ts +0 -53
- package/template-vanilla/src/experiences/managers/TickerManager.ts +0 -86
- package/template-vanilla/src/experiences/proxies/ViewProxy.ts +0 -45
- package/template-vanilla/src/experiences/views/bases/ViewBase.ts +0 -36
- package/template-vanilla/src/experiences/views/htmls/loaders/components/HTMLTemplateLoader.ts +0 -57
- /package/template-vanilla/src/experiences/{constants/experiences/AssetType.ts → types/assetTypes.ts} +0 -0
|
@@ -1,79 +1,87 @@
|
|
|
1
1
|
import { Action } from '@benjos/cookware';
|
|
2
2
|
import ThreeAssetsManager from './threes/ThreeAssetsManager';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
private
|
|
6
|
-
private
|
|
4
|
+
class LoaderManager {
|
|
5
|
+
private _totalSize = 0;
|
|
6
|
+
private _loadedSize = 0;
|
|
7
7
|
|
|
8
|
-
public
|
|
9
|
-
public
|
|
10
|
-
public
|
|
8
|
+
public readonly onBeginLoad = new Action();
|
|
9
|
+
public readonly onProgress = new Action();
|
|
10
|
+
public readonly onFinishLoad = new Action();
|
|
11
11
|
|
|
12
|
-
public
|
|
13
|
-
|
|
12
|
+
public init(): void {
|
|
13
|
+
this._addCallbacks();
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
private
|
|
17
|
-
|
|
18
|
-
ThreeAssetsManager.
|
|
19
|
-
ThreeAssetsManager.
|
|
16
|
+
private _addCallbacks(): void {
|
|
17
|
+
this._removeCallbacks();
|
|
18
|
+
ThreeAssetsManager.onLoad.add(this._onLoad);
|
|
19
|
+
ThreeAssetsManager.onProgress.add(this._onProgress);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
private
|
|
23
|
-
ThreeAssetsManager.
|
|
24
|
-
ThreeAssetsManager.
|
|
22
|
+
private _removeCallbacks(): void {
|
|
23
|
+
ThreeAssetsManager.onLoad.remove(this._onLoad);
|
|
24
|
+
ThreeAssetsManager.onProgress.remove(this._onProgress);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
27
|
+
private _beginLoad = (): void => {
|
|
28
|
+
ThreeAssetsManager.beginLoad();
|
|
29
|
+
this.onBeginLoad.execute();
|
|
30
|
+
};
|
|
31
31
|
|
|
32
|
-
private
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
private _finishLoad = (): void => {
|
|
33
|
+
ThreeAssetsManager.finishLoad();
|
|
34
|
+
this.onFinishLoad.execute();
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
|
|
37
|
+
public loadAllAssets(): void {
|
|
38
|
+
if (this._checkIsFinished()) return;
|
|
39
|
+
this._beginLoad();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private _onLoad = (): void => {
|
|
43
|
+
this._refreshSizes();
|
|
44
|
+
if (this._checkIsFinished()) this._finishLoad();
|
|
40
45
|
};
|
|
41
46
|
|
|
42
|
-
private
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
private _checkIsFinished = (): boolean => {
|
|
48
|
+
if (!ThreeAssetsManager.isLoaded) return false;
|
|
49
|
+
return true;
|
|
45
50
|
};
|
|
46
51
|
|
|
47
|
-
private
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
private _onProgress = (): void => {
|
|
53
|
+
this._refreshSizes();
|
|
54
|
+
this.onProgress.execute();
|
|
50
55
|
};
|
|
51
56
|
|
|
52
|
-
private
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
private _refreshSizes = (): void => {
|
|
58
|
+
this._refreshTotalSize();
|
|
59
|
+
this._refreshLoadedSize();
|
|
55
60
|
};
|
|
56
61
|
|
|
57
|
-
private
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
private _refreshTotalSize = (): void => {
|
|
63
|
+
this._totalSize = 0;
|
|
64
|
+
this._totalSize += ThreeAssetsManager.totalSize;
|
|
60
65
|
};
|
|
61
66
|
|
|
62
|
-
private
|
|
63
|
-
|
|
67
|
+
private _refreshLoadedSize = (): void => {
|
|
68
|
+
this._loadedSize = 0;
|
|
69
|
+
this._loadedSize += ThreeAssetsManager.loadedSize;
|
|
64
70
|
};
|
|
65
71
|
|
|
66
72
|
//#region Getters
|
|
67
73
|
//
|
|
68
|
-
public
|
|
69
|
-
return
|
|
74
|
+
public get isLoaded(): boolean {
|
|
75
|
+
return this._checkIsFinished();
|
|
70
76
|
}
|
|
71
|
-
public
|
|
72
|
-
return
|
|
77
|
+
public get totalSize(): number {
|
|
78
|
+
return this._totalSize;
|
|
73
79
|
}
|
|
74
|
-
public
|
|
75
|
-
return
|
|
80
|
+
public get loadedSize(): number {
|
|
81
|
+
return this._loadedSize;
|
|
76
82
|
}
|
|
77
83
|
//
|
|
78
84
|
//#endregion
|
|
79
85
|
}
|
|
86
|
+
|
|
87
|
+
export default new LoaderManager();
|
|
@@ -12,21 +12,20 @@ import {
|
|
|
12
12
|
} from 'three';
|
|
13
13
|
import { DRACOLoader, Font, FontLoader, GLTFLoader, HDRLoader, type GLTF } from 'three/examples/jsm/Addons.js';
|
|
14
14
|
import type { AssetId } from '../../constants/experiences/AssetId';
|
|
15
|
-
import { AssetType } from '../../
|
|
16
|
-
import LoaderManager from '../LoaderManager';
|
|
15
|
+
import { AssetType } from '../../types/assetTypes';
|
|
17
16
|
|
|
18
|
-
export interface
|
|
17
|
+
export interface ThreeAssetToLoad {
|
|
19
18
|
id: AssetId;
|
|
20
19
|
type: AssetType;
|
|
21
20
|
path: string;
|
|
22
|
-
option?:
|
|
21
|
+
option?: ThreeAssetOption;
|
|
23
22
|
loadedSize: number;
|
|
24
23
|
totalSize: number;
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
export interface
|
|
26
|
+
export interface ThreeAssetOption {}
|
|
28
27
|
|
|
29
|
-
export interface
|
|
28
|
+
export interface ThreeTextureOption extends ThreeAssetOption {
|
|
30
29
|
colorSpace?: ColorSpace;
|
|
31
30
|
wrapping?: Wrapping;
|
|
32
31
|
repeatX?: number;
|
|
@@ -35,34 +34,16 @@ export interface IThreeTextureOption extends IThreeAssetOption {
|
|
|
35
34
|
centerY?: number;
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
export interface
|
|
37
|
+
export interface ThreeHDROption extends ThreeAssetOption {
|
|
39
38
|
mapping?: Mapping;
|
|
40
39
|
colorSpace?: ColorSpace;
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
export interface
|
|
42
|
+
export interface ThreeModelOption extends ThreeAssetOption {}
|
|
44
43
|
|
|
45
|
-
export interface
|
|
44
|
+
export interface ThreeFontOption extends ThreeAssetOption {}
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
private static readonly _Assets: Map<string, Texture | DataTexture | GLTF | Font> = new Map<
|
|
49
|
-
string,
|
|
50
|
-
Texture | GLTF | Font
|
|
51
|
-
>();
|
|
52
|
-
private static readonly _ToLoadList: IThreeAssetToLoad[] = [];
|
|
53
|
-
private static _ExpectedAssetsCount = 0;
|
|
54
|
-
|
|
55
|
-
private static readonly _TextureLoader = new TextureLoader();
|
|
56
|
-
private static readonly _HDRLoader = new HDRLoader();
|
|
57
|
-
private static readonly _GltfLoader = new GLTFLoader();
|
|
58
|
-
private static readonly _DracoLoader = new DRACOLoader();
|
|
59
|
-
private static readonly _FontLoader = new FontLoader();
|
|
60
|
-
|
|
61
|
-
public static readonly OnLoad = new Action();
|
|
62
|
-
public static readonly OnProgress = new Action();
|
|
63
|
-
|
|
64
|
-
//#region Constants
|
|
65
|
-
//
|
|
46
|
+
class ThreeAssetsManager {
|
|
66
47
|
private static readonly _DRACO_LOADER_PATH: string = 'loaders/draco/';
|
|
67
48
|
private static readonly _DEFAULT_TEXTURE_OPTION_COLOR_SPACE: ColorSpace = LinearSRGBColorSpace;
|
|
68
49
|
private static readonly _DEFAULT_TEXTURE_OPTION_WRAPPING: Wrapping = RepeatWrapping;
|
|
@@ -75,28 +56,30 @@ export default class ThreeAssetsManager {
|
|
|
75
56
|
private static readonly _DEFAULT_LOADED_SIZE: number = 0;
|
|
76
57
|
private static readonly _DEFAULT_TOTAL_SIZE: number = -1;
|
|
77
58
|
private static readonly _DEFAULT_TEXTURE_TOTAL_SIZE: number = 1;
|
|
78
|
-
//
|
|
79
|
-
//#endregion
|
|
80
59
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
60
|
+
private readonly _assets: Map<string, Texture | DataTexture | GLTF | Font> = new Map<
|
|
61
|
+
string,
|
|
62
|
+
Texture | GLTF | Font
|
|
63
|
+
>();
|
|
64
|
+
private readonly _toLoadList: ThreeAssetToLoad[] = [];
|
|
65
|
+
private _expectedAssetsCount = 0;
|
|
86
66
|
|
|
87
|
-
private
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
67
|
+
private readonly _textureLoader = new TextureLoader();
|
|
68
|
+
private readonly _hdrLoader = new HDRLoader();
|
|
69
|
+
private readonly _gltfLoader = new GLTFLoader();
|
|
70
|
+
private readonly _dracoLoader = new DRACOLoader();
|
|
71
|
+
private readonly _fontLoader = new FontLoader();
|
|
92
72
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
73
|
+
public readonly onLoad = new Action();
|
|
74
|
+
public readonly onProgress = new Action();
|
|
75
|
+
|
|
76
|
+
public init(): void {
|
|
77
|
+
this._dracoLoader.setDecoderPath(AssetUtils.GetPath(ThreeAssetsManager._DRACO_LOADER_PATH));
|
|
78
|
+
this._gltfLoader.setDRACOLoader(this._dracoLoader);
|
|
96
79
|
}
|
|
97
80
|
|
|
98
|
-
public
|
|
99
|
-
|
|
81
|
+
public addTexture(id: AssetId, path: string, textureOption?: ThreeTextureOption): void {
|
|
82
|
+
this._toLoadList.push({
|
|
100
83
|
id,
|
|
101
84
|
type: AssetType.TEXTURE,
|
|
102
85
|
path,
|
|
@@ -104,11 +87,11 @@ export default class ThreeAssetsManager {
|
|
|
104
87
|
loadedSize: ThreeAssetsManager._DEFAULT_LOADED_SIZE,
|
|
105
88
|
totalSize: ThreeAssetsManager._DEFAULT_TEXTURE_TOTAL_SIZE,
|
|
106
89
|
});
|
|
107
|
-
|
|
90
|
+
this._expectedAssetsCount++;
|
|
108
91
|
}
|
|
109
92
|
|
|
110
|
-
public
|
|
111
|
-
|
|
93
|
+
public addHDR(id: AssetId, path: string, hdrOption?: ThreeHDROption): void {
|
|
94
|
+
this._toLoadList.push({
|
|
112
95
|
id,
|
|
113
96
|
type: AssetType.HDR,
|
|
114
97
|
path,
|
|
@@ -116,11 +99,11 @@ export default class ThreeAssetsManager {
|
|
|
116
99
|
loadedSize: ThreeAssetsManager._DEFAULT_LOADED_SIZE,
|
|
117
100
|
totalSize: ThreeAssetsManager._DEFAULT_TOTAL_SIZE,
|
|
118
101
|
});
|
|
119
|
-
|
|
102
|
+
this._expectedAssetsCount++;
|
|
120
103
|
}
|
|
121
104
|
|
|
122
|
-
public
|
|
123
|
-
|
|
105
|
+
public addModel(id: AssetId, path: string, modelOption?: ThreeModelOption): void {
|
|
106
|
+
this._toLoadList.push({
|
|
124
107
|
id,
|
|
125
108
|
type: AssetType.MODEL,
|
|
126
109
|
path,
|
|
@@ -128,11 +111,11 @@ export default class ThreeAssetsManager {
|
|
|
128
111
|
loadedSize: ThreeAssetsManager._DEFAULT_LOADED_SIZE,
|
|
129
112
|
totalSize: ThreeAssetsManager._DEFAULT_TOTAL_SIZE,
|
|
130
113
|
});
|
|
131
|
-
|
|
114
|
+
this._expectedAssetsCount++;
|
|
132
115
|
}
|
|
133
116
|
|
|
134
|
-
public
|
|
135
|
-
|
|
117
|
+
public addFont(id: AssetId, path: string, fontOption?: ThreeFontOption): void {
|
|
118
|
+
this._toLoadList.push({
|
|
136
119
|
id,
|
|
137
120
|
type: AssetType.FONT,
|
|
138
121
|
path,
|
|
@@ -140,29 +123,29 @@ export default class ThreeAssetsManager {
|
|
|
140
123
|
loadedSize: ThreeAssetsManager._DEFAULT_LOADED_SIZE,
|
|
141
124
|
totalSize: ThreeAssetsManager._DEFAULT_TOTAL_SIZE,
|
|
142
125
|
});
|
|
143
|
-
|
|
126
|
+
this._expectedAssetsCount++;
|
|
144
127
|
}
|
|
145
128
|
|
|
146
|
-
|
|
147
|
-
if (
|
|
148
|
-
|
|
129
|
+
public beginLoad(): void {
|
|
130
|
+
if (this._toLoadList.length === 0) {
|
|
131
|
+
this.onLoad.execute();
|
|
149
132
|
return;
|
|
150
133
|
}
|
|
151
|
-
for (const asset of
|
|
152
|
-
if (asset.type === AssetType.TEXTURE)
|
|
153
|
-
else if (asset.type === AssetType.HDR)
|
|
154
|
-
else if (asset.type === AssetType.MODEL)
|
|
155
|
-
else if (asset.type === AssetType.FONT)
|
|
134
|
+
for (const asset of this._toLoadList) {
|
|
135
|
+
if (asset.type === AssetType.TEXTURE) this._loadTexture(asset);
|
|
136
|
+
else if (asset.type === AssetType.HDR) this._loadHDR(asset);
|
|
137
|
+
else if (asset.type === AssetType.MODEL) this._loadModel(asset);
|
|
138
|
+
else if (asset.type === AssetType.FONT) this._loadFont(asset);
|
|
156
139
|
}
|
|
157
|
-
}
|
|
140
|
+
}
|
|
158
141
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
}
|
|
142
|
+
public finishLoad(): void {
|
|
143
|
+
this._toLoadList.length = 0;
|
|
144
|
+
}
|
|
162
145
|
|
|
163
|
-
private
|
|
164
|
-
const option = asset.option as
|
|
165
|
-
|
|
146
|
+
private _loadTexture(asset: ThreeAssetToLoad): void {
|
|
147
|
+
const option = asset.option as ThreeTextureOption | undefined;
|
|
148
|
+
this._textureLoader.load(
|
|
166
149
|
asset.path,
|
|
167
150
|
(texture) => {
|
|
168
151
|
texture.colorSpace = option?.colorSpace ?? ThreeAssetsManager._DEFAULT_TEXTURE_OPTION_COLOR_SPACE;
|
|
@@ -176,99 +159,99 @@ export default class ThreeAssetsManager {
|
|
|
176
159
|
option?.centerY ?? ThreeAssetsManager._DEFAULT_TEXTURE_OPTION_CENTER_Y
|
|
177
160
|
);
|
|
178
161
|
asset.loadedSize = asset.totalSize;
|
|
179
|
-
|
|
162
|
+
this._onLoad(asset.id, texture);
|
|
180
163
|
},
|
|
181
|
-
(event: ProgressEvent) =>
|
|
182
|
-
() =>
|
|
164
|
+
(event: ProgressEvent) => this._onProgress(asset, event),
|
|
165
|
+
() => this._onError(AssetType.TEXTURE, asset.id, asset.path)
|
|
183
166
|
);
|
|
184
167
|
}
|
|
185
168
|
|
|
186
|
-
private
|
|
187
|
-
const option = asset.option as
|
|
188
|
-
|
|
169
|
+
private _loadHDR(asset: ThreeAssetToLoad): void {
|
|
170
|
+
const option = asset.option as ThreeHDROption | undefined;
|
|
171
|
+
this._hdrLoader.load(
|
|
189
172
|
asset.path,
|
|
190
173
|
(dataTexture) => {
|
|
191
174
|
dataTexture.mapping = option?.mapping ?? ThreeAssetsManager._DEFAULT_HDR_MAPPING;
|
|
192
175
|
dataTexture.colorSpace = option?.colorSpace ?? ThreeAssetsManager._DEFAULT_HDR_COLOR_SPACE;
|
|
193
|
-
|
|
176
|
+
this._onLoad(asset.id, dataTexture);
|
|
194
177
|
},
|
|
195
|
-
(event: ProgressEvent) =>
|
|
196
|
-
() =>
|
|
178
|
+
(event: ProgressEvent) => this._onProgress(asset, event),
|
|
179
|
+
() => this._onError(AssetType.HDR, asset.id, asset.path)
|
|
197
180
|
);
|
|
198
181
|
}
|
|
199
182
|
|
|
200
|
-
private
|
|
201
|
-
|
|
183
|
+
private _loadModel(asset: ThreeAssetToLoad): void {
|
|
184
|
+
this._gltfLoader.load(
|
|
202
185
|
asset.path,
|
|
203
|
-
(model) =>
|
|
204
|
-
(event: ProgressEvent) =>
|
|
205
|
-
() =>
|
|
186
|
+
(model) => this._onLoad(asset.id, model),
|
|
187
|
+
(event: ProgressEvent) => this._onProgress(asset, event),
|
|
188
|
+
() => this._onError(AssetType.MODEL, asset.id, asset.path)
|
|
206
189
|
);
|
|
207
190
|
}
|
|
208
191
|
|
|
209
|
-
private
|
|
210
|
-
|
|
192
|
+
private _loadFont(asset: ThreeAssetToLoad): void {
|
|
193
|
+
this._fontLoader.load(
|
|
211
194
|
asset.path,
|
|
212
|
-
(font) =>
|
|
213
|
-
(event: ProgressEvent) =>
|
|
214
|
-
() =>
|
|
195
|
+
(font) => this._onLoad(asset.id, font),
|
|
196
|
+
(event: ProgressEvent) => this._onProgress(asset, event),
|
|
197
|
+
() => this._onError(AssetType.FONT, asset.id, asset.path)
|
|
215
198
|
);
|
|
216
199
|
}
|
|
217
200
|
|
|
218
|
-
private
|
|
219
|
-
|
|
220
|
-
|
|
201
|
+
private _onLoad(id: AssetId, asset: Texture | GLTF | Font): void {
|
|
202
|
+
this._assets.set(id, asset);
|
|
203
|
+
this.onLoad.execute();
|
|
221
204
|
}
|
|
222
205
|
|
|
223
|
-
private
|
|
206
|
+
private _onProgress(asset: ThreeAssetToLoad, event: ProgressEvent): void {
|
|
224
207
|
if (asset.totalSize === ThreeAssetsManager._DEFAULT_TOTAL_SIZE) asset.totalSize = event.total;
|
|
225
208
|
asset.loadedSize = event.loaded;
|
|
226
|
-
|
|
209
|
+
this.onProgress.execute();
|
|
227
210
|
}
|
|
228
211
|
|
|
229
|
-
private
|
|
212
|
+
private _onError(type: AssetType, id: AssetId, path: string): void {
|
|
230
213
|
throw new Error(`ThreeAssetsManager: Failed to load ${type} with id '${id}' from path '${path}'`);
|
|
231
214
|
}
|
|
232
215
|
|
|
233
|
-
public
|
|
234
|
-
const asset =
|
|
216
|
+
public getTexture(id: AssetId): Texture {
|
|
217
|
+
const asset = this._assets.get(id);
|
|
235
218
|
if (!asset) throw new Error(`Texture with id '${id}' not found!`);
|
|
236
219
|
return asset as Texture;
|
|
237
220
|
}
|
|
238
221
|
|
|
239
|
-
public
|
|
240
|
-
const asset =
|
|
222
|
+
public getHDR(id: AssetId): DataTexture {
|
|
223
|
+
const asset = this._assets.get(id);
|
|
241
224
|
if (!asset) throw new Error(`HDR with id '${id}' not found!`);
|
|
242
225
|
return asset as DataTexture;
|
|
243
226
|
}
|
|
244
227
|
|
|
245
|
-
public
|
|
246
|
-
const asset =
|
|
228
|
+
public getModel(id: AssetId): GLTF {
|
|
229
|
+
const asset = this._assets.get(id);
|
|
247
230
|
if (!asset) throw new Error(`Model with id '${id}' not found!`);
|
|
248
231
|
return asset as GLTF;
|
|
249
232
|
}
|
|
250
233
|
|
|
251
|
-
public
|
|
252
|
-
const asset =
|
|
234
|
+
public getFont(id: AssetId): Font {
|
|
235
|
+
const asset = this._assets.get(id);
|
|
253
236
|
if (!asset) throw new Error(`Font with id '${id}' not found!`);
|
|
254
237
|
return asset as Font;
|
|
255
238
|
}
|
|
256
239
|
|
|
257
240
|
//#region Getters
|
|
258
241
|
//
|
|
259
|
-
public
|
|
260
|
-
return
|
|
242
|
+
public get isLoaded(): boolean {
|
|
243
|
+
return this._assets.size === this._expectedAssetsCount;
|
|
261
244
|
}
|
|
262
|
-
public
|
|
245
|
+
public get totalSize(): number {
|
|
263
246
|
let totalSize = 0;
|
|
264
|
-
for (const asset of
|
|
247
|
+
for (const asset of this._toLoadList) {
|
|
265
248
|
totalSize += asset.totalSize;
|
|
266
249
|
}
|
|
267
250
|
return totalSize;
|
|
268
251
|
}
|
|
269
|
-
public
|
|
252
|
+
public get loadedSize(): number {
|
|
270
253
|
let loadedSize = 0;
|
|
271
|
-
for (const asset of
|
|
254
|
+
for (const asset of this._toLoadList) {
|
|
272
255
|
loadedSize += asset.loadedSize;
|
|
273
256
|
}
|
|
274
257
|
return loadedSize;
|
|
@@ -276,3 +259,5 @@ export default class ThreeAssetsManager {
|
|
|
276
259
|
//
|
|
277
260
|
//#endregion
|
|
278
261
|
}
|
|
262
|
+
|
|
263
|
+
export default new ThreeAssetsManager();
|
|
@@ -2,42 +2,45 @@ import { Action } from '@benjos/cookware';
|
|
|
2
2
|
import type ThreeCameraControllerBase from '../../cameras/threes/bases/ThreeCameraControllerBase';
|
|
3
3
|
import type { CameraId } from '../../constants/experiences/CameraId';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
private
|
|
7
|
-
private
|
|
5
|
+
class ThreeCameraControllerManager {
|
|
6
|
+
declare private _threeCameraControllers: Map<CameraId, ThreeCameraControllerBase>;
|
|
7
|
+
declare private _activeThreeCameraController: ThreeCameraControllerBase;
|
|
8
8
|
|
|
9
|
-
public
|
|
9
|
+
public readonly onActiveThreeCameraControllerChange = new Action();
|
|
10
10
|
|
|
11
|
-
public
|
|
12
|
-
|
|
11
|
+
public init(): void {
|
|
12
|
+
this._threeCameraControllers = new Map();
|
|
13
|
+
this._threeCameraControllers.clear();
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
public
|
|
16
|
-
|
|
17
|
-
if (isActive)
|
|
16
|
+
public add(threeCameraController: ThreeCameraControllerBase, isActive = false): void {
|
|
17
|
+
this._threeCameraControllers.set(threeCameraController.cameraId, threeCameraController);
|
|
18
|
+
if (isActive) this.setActiveCamera(threeCameraController.cameraId);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
public
|
|
21
|
-
const threeCameraController =
|
|
21
|
+
public get(cameraId: CameraId): ThreeCameraControllerBase {
|
|
22
|
+
const threeCameraController = this._threeCameraControllers.get(cameraId);
|
|
22
23
|
if (!threeCameraController) {
|
|
23
24
|
throw new Error(`CameraControllerManager: No camera found with id ${cameraId}`);
|
|
24
25
|
}
|
|
25
26
|
return threeCameraController;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
public
|
|
29
|
-
const threeCameraController =
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
public setActiveCamera(cameraId: CameraId): void {
|
|
30
|
+
const threeCameraController = this.get(cameraId);
|
|
31
|
+
this._activeThreeCameraController?.disable();
|
|
32
|
+
this._activeThreeCameraController = threeCameraController;
|
|
33
|
+
this._activeThreeCameraController.enable();
|
|
34
|
+
this.onActiveThreeCameraControllerChange.execute();
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
//#region Getters
|
|
37
38
|
//
|
|
38
|
-
public
|
|
39
|
-
return
|
|
39
|
+
public get activeThreeCameraController(): ThreeCameraControllerBase {
|
|
40
|
+
return this._activeThreeCameraController;
|
|
40
41
|
}
|
|
41
42
|
//
|
|
42
43
|
//#endregion
|
|
43
44
|
}
|
|
45
|
+
|
|
46
|
+
export default new ThreeCameraControllerManager();
|
|
@@ -1,23 +1,21 @@
|
|
|
1
|
+
import { DomPointerManager } from '@benjos/cookware';
|
|
1
2
|
import { Object3D, Raycaster, Vector2, type Intersection, type Object3DEventMap } from 'three';
|
|
2
|
-
import
|
|
3
|
-
import MouseManager from '../MouseManager';
|
|
3
|
+
import MainThreeApp from '../../engines/threes/app/MainThreeApp';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
private
|
|
5
|
+
class ThreeRaycasterManager {
|
|
6
|
+
private readonly _raycaster = new Raycaster();
|
|
7
|
+
private readonly _pointerPosition = new Vector2();
|
|
7
8
|
|
|
8
|
-
public
|
|
9
|
+
public init(): void {
|
|
9
10
|
//
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
public
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
ThreeRaycasterManager._Raycaster.setFromCamera(
|
|
17
|
-
new Vector2(MouseManager.CentralX, MouseManager.CentralY),
|
|
18
|
-
MainThree.CameraController.camera
|
|
19
|
-
);
|
|
20
|
-
const intersects = ThreeRaycasterManager._Raycaster.intersectObjects(objects, recursive);
|
|
13
|
+
public castFromCameraToPointer(objects: Object3D[], recursive = true): Intersection<Object3D<Object3DEventMap>>[] {
|
|
14
|
+
this._pointerPosition.set(DomPointerManager.ndcX, DomPointerManager.ndcY);
|
|
15
|
+
this._raycaster.setFromCamera(this._pointerPosition, MainThreeApp.cameraController.camera);
|
|
16
|
+
const intersects = this._raycaster.intersectObjects(objects, recursive);
|
|
21
17
|
return intersects;
|
|
22
18
|
}
|
|
23
19
|
}
|
|
20
|
+
|
|
21
|
+
export default new ThreeRaycasterManager();
|
|
@@ -4,16 +4,12 @@ import LoaderFragmentShader from '../../../shaders/threes/loaders/LoaderFragment
|
|
|
4
4
|
import LoaderVertexShader from '../../../shaders/threes/loaders/LoaderVertexShader.glsl';
|
|
5
5
|
|
|
6
6
|
export default class LoaderMaterial extends ShaderMaterial {
|
|
7
|
-
//#region Constants
|
|
8
|
-
//
|
|
9
7
|
private static readonly _DEFAULT_UNIFORMS_ALPHA: number = 1;
|
|
10
8
|
private static readonly _DEFAULT_UNIFORMS_COLOR: number = 0x3f79f3;
|
|
11
9
|
private static readonly _GSAP_DURATION_FADE_IN: number = 0.5;
|
|
12
10
|
private static readonly _GSAP_EASE_FADE_IN: string = 'power2.out';
|
|
13
11
|
private static readonly _GSAP_DURATION_FADE_OUT: number = 1.5;
|
|
14
12
|
private static readonly _GSAP_EASE_FADE_OUT: string = 'power2.in';
|
|
15
|
-
//
|
|
16
|
-
//#endregion
|
|
17
13
|
|
|
18
14
|
constructor() {
|
|
19
15
|
super({
|
|
@@ -2,15 +2,11 @@ import { Camera, LinearSRGBColorSpace, NoToneMapping, Scene, type WebGLRendererP
|
|
|
2
2
|
import WebGLRendererBase from './bases/WebGLRendererBase';
|
|
3
3
|
|
|
4
4
|
export default class LoaderRenderer extends WebGLRendererBase {
|
|
5
|
-
//#region Constants
|
|
6
|
-
//
|
|
7
5
|
private static readonly _DEFAULT_TONE_MAPPING = NoToneMapping;
|
|
8
6
|
private static readonly _DEFAULT_OUTPUT_COLOR_SPACE = LinearSRGBColorSpace;
|
|
9
7
|
private static readonly _DEFAULT_TONE_MAPPING_EXPOSURE = 1;
|
|
10
8
|
private static readonly _DEFAULT_CLEAR_COLOR = 0x000000;
|
|
11
9
|
private static readonly _DEFAULT_CLEAR_ALPHA = 0;
|
|
12
|
-
//
|
|
13
|
-
//#endregion
|
|
14
10
|
|
|
15
11
|
constructor(scene: Scene, camera: Camera, parameters: WebGLRendererParameters = {}) {
|
|
16
12
|
super(scene, camera, parameters);
|