@benjos/create-boilerplate 1.4.0 → 1.5.0
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.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/template-react/package-lock.json +3 -18
- package/template-react/package.json +1 -1
- package/template-vanilla/eslint.config.js +5 -11
- package/template-vanilla/index.html +18 -20
- package/template-vanilla/package-lock.json +3 -13
- package/template-vanilla/package.json +1 -1
- package/template-vanilla/src/experiences/Experience.ts +10 -5
- package/template-vanilla/src/experiences/cameras/threes/DebugThreeCameraController.ts +3 -3
- package/template-vanilla/src/experiences/cameras/threes/LoaderThreeCameraController.ts +2 -2
- package/template-vanilla/src/experiences/cameras/threes/bases/ThreeCameraControllerBase.ts +2 -2
- package/template-vanilla/src/experiences/commands/InitCommand.ts +4 -4
- package/template-vanilla/src/experiences/constants/experiences/DebugGuiTitle.ts +6 -0
- package/template-vanilla/src/experiences/constants/experiences/ViewId.ts +2 -1
- package/template-vanilla/src/experiences/engines/threes/MainThree.ts +6 -91
- package/template-vanilla/src/experiences/engines/threes/app/LoaderThreeApp.ts +49 -0
- package/template-vanilla/src/experiences/engines/threes/app/MainThreeApp.ts +109 -0
- package/template-vanilla/src/experiences/engines/threes/{bases/ThreeBase.ts → app/bases/ThreeAppBase.ts} +49 -11
- package/template-vanilla/src/experiences/managers/DebugManager.ts +13 -2
- package/template-vanilla/src/experiences/managers/LoaderManager.ts +97 -7
- package/template-vanilla/src/experiences/managers/threes/ThreeRaycasterManager.ts +2 -2
- package/template-vanilla/src/experiences/materials/threes/loaders/LoaderMaterial.ts +4 -4
- package/template-vanilla/src/experiences/renderers/threes/LoaderRenderer.ts +2 -2
- package/template-vanilla/src/experiences/renderers/threes/Renderer.ts +2 -1
- package/template-vanilla/src/experiences/shaders/threes/loaders/LoaderFragmentShader.glsl +2 -0
- package/template-vanilla/src/experiences/styles/commons/main.scss +5 -30
- package/template-vanilla/src/experiences/styles/style.scss +1 -1
- package/template-vanilla/src/experiences/styles/views/loader.scss +1 -4
- package/template-vanilla/src/experiences/types/global.d.ts +2 -2
- package/template-vanilla/src/experiences/views/htmls/bases/HTMLViewBase.ts +0 -3
- package/template-vanilla/src/experiences/views/htmls/loaders/LoaderHTMLView.ts +7 -8
- package/template-vanilla/src/experiences/views/threes/bases/ThreeViewBase.ts +29 -6
- package/template-vanilla/src/experiences/views/threes/loaders/LoaderThreeView.ts +9 -19
- package/template-vanilla/src/experiences/views/threes/loaders/components/{ThreeTemplateLoader.ts → TemplateLoaderThreeActor.ts} +6 -12
- package/template-vanilla/src/experiences/views/threes/worlds/World2ThreeView.ts +35 -0
- package/template-vanilla/src/experiences/views/threes/worlds/WorldThreeView.ts +12 -20
- package/template-vanilla/src/experiences/views/threes/worlds/components/Environment.ts +25 -9
- package/template-vanilla/src/experiences/views/threes/worlds/components/actors/TemplateFont.ts +2 -8
- package/template-vanilla/src/experiences/views/threes/worlds/components/actors/TemplateMesh.ts +4 -6
- package/template-vanilla/src/experiences/views/threes/worlds/components/actors/TemplateMesh2.ts +71 -0
- package/template-vanilla/src/experiences/views/threes/worlds/components/actors/TemplateModel.ts +9 -3
- package/template-vanilla/src/experiences/views/threes/worlds/components/actors/bases/ThreeActorBase.ts +44 -0
- package/template-vanilla/src/experiences/views/threes/worlds/components/actors/bases/{AnimatedModelBase.ts → ThreeAnimatedModelBase.ts} +3 -3
- package/template-vanilla/src/experiences/views/threes/worlds/components/actors/bases/{ModelBase.ts → ThreeModelBase.ts} +2 -16
- package/template-vanilla/tsconfig.json +3 -8
- package/template-vanilla/src/experiences/engines/threes/LoaderThree.ts +0 -39
- package/template-vanilla/src/experiences/views/threes/worlds/components/actors/bases/ActorBase.ts +0 -13
|
@@ -9,9 +9,9 @@ export default class LoaderHTMLView extends HTMLViewBase {
|
|
|
9
9
|
|
|
10
10
|
constructor() {
|
|
11
11
|
super();
|
|
12
|
-
LoaderManager.onBeginLoad.add(this._onBeginLoad);
|
|
13
12
|
LoaderManager.onProgress.add(this._onProgress);
|
|
14
|
-
LoaderManager.
|
|
13
|
+
LoaderManager.onShow.add(this._onShow);
|
|
14
|
+
LoaderManager.onHide.add(this._onHide);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
protected override _getElement(): void {
|
|
@@ -21,20 +21,19 @@ export default class LoaderHTMLView extends HTMLViewBase {
|
|
|
21
21
|
this._loadingBar = this._htmlElement.querySelector('.loading-bar')!;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
private readonly
|
|
24
|
+
private readonly _onShow = (): void => {
|
|
25
25
|
this._loadingNumber.textContent = '0';
|
|
26
26
|
this._loadingBar.style.transform = '';
|
|
27
27
|
this._loadingBar.classList.remove('ended');
|
|
28
28
|
this.show();
|
|
29
29
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this._loadingBar.style.transform = `translateY(-50%) scaleX(${progress / 100})`;
|
|
30
|
+
private readonly _onProgress = (): void => {
|
|
31
|
+
const progress = LoaderManager.progress * 100;
|
|
32
|
+
this._loadingBar.style.transform = `translateY(-50%) scaleX(${LoaderManager.progress})`;
|
|
34
33
|
this._loadingNumber.textContent = Math.round(progress).toString();
|
|
35
34
|
};
|
|
36
35
|
|
|
37
|
-
private readonly
|
|
36
|
+
private readonly _onHide = (): void => {
|
|
38
37
|
this._loadingNumber.textContent = '100';
|
|
39
38
|
this._loadingBar.style.transform = '';
|
|
40
39
|
this._loadingBar.classList.add('ended');
|
|
@@ -1,26 +1,49 @@
|
|
|
1
1
|
import { Object3D } from 'three';
|
|
2
|
-
import
|
|
2
|
+
import { ViewId } from '../../../constants/experiences/ViewId';
|
|
3
|
+
import ThreeActorBase from '../worlds/components/actors/bases/ThreeActorBase';
|
|
3
4
|
|
|
4
5
|
export default abstract class ThreeViewBase extends Object3D {
|
|
5
|
-
|
|
6
|
+
private readonly _id: ViewId;
|
|
7
|
+
protected readonly _actors: ThreeActorBase[];
|
|
8
|
+
private _areActorsGenerated = false;
|
|
6
9
|
|
|
7
|
-
constructor() {
|
|
10
|
+
constructor(id: ViewId) {
|
|
8
11
|
super();
|
|
9
|
-
|
|
12
|
+
this._id = id;
|
|
10
13
|
this._actors = [];
|
|
11
14
|
}
|
|
12
15
|
|
|
13
|
-
|
|
16
|
+
public declareAssets(): void {
|
|
14
17
|
//
|
|
15
18
|
}
|
|
16
19
|
|
|
20
|
+
public init(): void {
|
|
21
|
+
if (!this._areActorsGenerated) this._generateActors();
|
|
22
|
+
this.reset();
|
|
23
|
+
for (const actor of this._actors) actor.init();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public reset(): void {
|
|
27
|
+
for (const actor of this._actors) actor.reset();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
protected _generateActors(): void {
|
|
31
|
+
this._areActorsGenerated = true;
|
|
32
|
+
}
|
|
33
|
+
|
|
17
34
|
public dispose(): void {
|
|
18
35
|
for (const actor of this._actors) {
|
|
19
36
|
actor.dispose();
|
|
20
37
|
}
|
|
21
38
|
}
|
|
22
39
|
|
|
23
|
-
public update(
|
|
40
|
+
public update(_dt: number): void {
|
|
24
41
|
//
|
|
25
42
|
}
|
|
43
|
+
|
|
44
|
+
//#region Getters
|
|
45
|
+
//
|
|
46
|
+
public get viewId(): ViewId { return this._id; }
|
|
47
|
+
//
|
|
48
|
+
//#endregion
|
|
26
49
|
}
|
|
@@ -1,38 +1,28 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ViewId } from '../../../constants/experiences/ViewId';
|
|
2
2
|
import ThreeViewBase from '../bases/ThreeViewBase';
|
|
3
|
-
import
|
|
3
|
+
import TemplateLoaderThreeActor from './components/TemplateLoaderThreeActor';
|
|
4
4
|
|
|
5
5
|
export default class LoaderThreeView extends ThreeViewBase {
|
|
6
|
-
declare private _threeLoader:
|
|
6
|
+
declare private _threeLoader: TemplateLoaderThreeActor;
|
|
7
7
|
|
|
8
8
|
constructor() {
|
|
9
|
-
super();
|
|
9
|
+
super(ViewId.THREE_LOADER);
|
|
10
10
|
this._generateActors();
|
|
11
|
-
LoaderManager.onBeginLoad.add(this._onBeginLoad);
|
|
12
|
-
LoaderManager.onFinishLoad.add(this._onFinishLoad);
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
protected override _generateActors(): void {
|
|
16
14
|
super._generateActors();
|
|
17
|
-
this._threeLoader = new
|
|
15
|
+
this._threeLoader = new TemplateLoaderThreeActor();
|
|
18
16
|
this._actors.push(this._threeLoader);
|
|
19
17
|
|
|
20
18
|
for (const actor of this._actors) this.add(actor);
|
|
21
19
|
}
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
this._threeLoader.material.show();
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
protected _hide(): void {
|
|
28
|
-
this._threeLoader.material.hide();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
private readonly _onBeginLoad = (): void => {
|
|
32
|
-
this._show();
|
|
21
|
+
public readonly show = (): Promise<void> => {
|
|
22
|
+
return this._threeLoader.material.show();
|
|
33
23
|
};
|
|
34
24
|
|
|
35
|
-
|
|
36
|
-
this.
|
|
25
|
+
public readonly hide = (): Promise<void> => {
|
|
26
|
+
return this._threeLoader.material.hide();
|
|
37
27
|
};
|
|
38
28
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Mesh, PlaneGeometry } from 'three';
|
|
2
2
|
import LoaderMaterial from '../../../../materials/threes/loaders/LoaderMaterial';
|
|
3
|
-
import
|
|
3
|
+
import ThreeActorBase from '../../worlds/components/actors/bases/ThreeActorBase';
|
|
4
4
|
|
|
5
|
-
export default class
|
|
5
|
+
export default class TemplateLoaderThreeActor extends ThreeActorBase {
|
|
6
6
|
private static readonly _DEFAULT_SIZE_WIDTH: number = 2;
|
|
7
7
|
private static readonly _DEFAULT_SIZE_HEIGHT: number = 2;
|
|
8
8
|
private static readonly _DEFAULT_SEGMENTS_WIDTH: number = 1;
|
|
@@ -24,10 +24,10 @@ export default class ThreeTemplateLoader extends ActorBase {
|
|
|
24
24
|
|
|
25
25
|
private _generateGeometry(): void {
|
|
26
26
|
this._geometry = new PlaneGeometry(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
TemplateLoaderThreeActor._DEFAULT_SIZE_WIDTH,
|
|
28
|
+
TemplateLoaderThreeActor._DEFAULT_SIZE_HEIGHT,
|
|
29
|
+
TemplateLoaderThreeActor._DEFAULT_SEGMENTS_WIDTH,
|
|
30
|
+
TemplateLoaderThreeActor._DEFAULT_SEGMENTS_HEIGHT
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -39,12 +39,6 @@ export default class ThreeTemplateLoader extends ActorBase {
|
|
|
39
39
|
this._mesh = new Mesh(this._geometry, this._material);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
public override dispose(): void {
|
|
43
|
-
super.dispose();
|
|
44
|
-
this._geometry.dispose();
|
|
45
|
-
this._material.dispose();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
42
|
//#region Getters
|
|
49
43
|
//
|
|
50
44
|
public get material(): LoaderMaterial {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DebugGuiTitle } from '../../../constants/experiences/DebugGuiTitle';
|
|
2
|
+
import { ViewId } from '../../../constants/experiences/ViewId';
|
|
3
|
+
import MainThreeApp from '../../../engines/threes/app/MainThreeApp';
|
|
4
|
+
import DebugManager from '../../../managers/DebugManager';
|
|
5
|
+
import ThreeViewBase from '../bases/ThreeViewBase';
|
|
6
|
+
import Environment from './components/Environment';
|
|
7
|
+
import TemplateFont from './components/actors/TemplateFont';
|
|
8
|
+
import TemplateMesh2 from './components/actors/TemplateMesh2';
|
|
9
|
+
import TemplateModel from './components/actors/TemplateModel';
|
|
10
|
+
|
|
11
|
+
export default class World2ThreeView extends ThreeViewBase {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(ViewId.THREE_VIEW_WORLD_2);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
protected override _generateActors(): void {
|
|
17
|
+
super._generateActors();
|
|
18
|
+
|
|
19
|
+
if (DebugManager.isActive) {
|
|
20
|
+
const viewsDebug = DebugManager.getGuiFolder(DebugGuiTitle.THREE_VIEWS)
|
|
21
|
+
viewsDebug.add({ switchToWorld2ThreeView: () => MainThreeApp.setCurrentView(ViewId.THREE_VIEW_WORLD_2) }, 'switchToWorld2ThreeView').name('SWITCH WORLD_2_VIEW');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
this._actors.push(new Environment());
|
|
25
|
+
this._actors.push(new TemplateMesh2());
|
|
26
|
+
this._actors.push(new TemplateModel());
|
|
27
|
+
this._actors.push(new TemplateFont());
|
|
28
|
+
|
|
29
|
+
for (const actor of this._actors) this.add(actor);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public override update(dt: number): void {
|
|
33
|
+
for (const actor of this._actors) actor.update(dt);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { DebugGuiTitle } from '../../../constants/experiences/DebugGuiTitle';
|
|
2
|
+
import { ViewId } from '../../../constants/experiences/ViewId';
|
|
3
|
+
import MainThreeApp from '../../../engines/threes/app/MainThreeApp';
|
|
4
|
+
import DebugManager from '../../../managers/DebugManager';
|
|
2
5
|
import ThreeViewBase from '../bases/ThreeViewBase';
|
|
3
6
|
import Environment from './components/Environment';
|
|
4
7
|
import TemplateFont from './components/actors/TemplateFont';
|
|
@@ -6,27 +9,19 @@ import TemplateMesh from './components/actors/TemplateMesh';
|
|
|
6
9
|
import TemplateModel from './components/actors/TemplateModel';
|
|
7
10
|
|
|
8
11
|
export default class WorldThreeView extends ThreeViewBase {
|
|
9
|
-
declare private _environment: Environment;
|
|
10
|
-
|
|
11
12
|
constructor() {
|
|
12
|
-
super();
|
|
13
|
-
LoaderManager.onFinishLoad.add(this._onFinishLoad);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
private readonly _onFinishLoad = (): void => {
|
|
17
|
-
this._generateEnvironment();
|
|
18
|
-
this._generateActors();
|
|
19
|
-
LoaderManager.onFinishLoad.remove(this._onFinishLoad);
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
private _generateEnvironment(): void {
|
|
23
|
-
this._environment = new Environment();
|
|
24
|
-
|
|
25
|
-
this.add(this._environment);
|
|
13
|
+
super(ViewId.THREE_VIEW_WORLD_1);
|
|
26
14
|
}
|
|
27
15
|
|
|
28
16
|
protected override _generateActors(): void {
|
|
29
17
|
super._generateActors();
|
|
18
|
+
|
|
19
|
+
if (DebugManager.isActive) {
|
|
20
|
+
const viewsDebug = DebugManager.getGuiFolder(DebugGuiTitle.THREE_VIEWS)
|
|
21
|
+
viewsDebug.add({ switchToWorldThreeView: () => MainThreeApp.setCurrentView(ViewId.THREE_VIEW_WORLD_1) }, 'switchToWorldThreeView').name('SWITCH WORLD_1_VIEW');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
this._actors.push(new Environment());
|
|
30
25
|
this._actors.push(new TemplateMesh());
|
|
31
26
|
this._actors.push(new TemplateModel());
|
|
32
27
|
this._actors.push(new TemplateFont());
|
|
@@ -35,9 +30,6 @@ export default class WorldThreeView extends ThreeViewBase {
|
|
|
35
30
|
}
|
|
36
31
|
|
|
37
32
|
public override update(dt: number): void {
|
|
38
|
-
if (!this._environment) return;
|
|
39
|
-
|
|
40
|
-
this._environment.update(dt);
|
|
41
33
|
for (const actor of this._actors) actor.update(dt);
|
|
42
34
|
}
|
|
43
35
|
}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
import { DataTexture, DirectionalLight,
|
|
1
|
+
import { DataTexture, DirectionalLight, Vector3 } from 'three';
|
|
2
2
|
import { AssetId } from '../../../../constants/experiences/AssetId';
|
|
3
|
-
import
|
|
3
|
+
import { DebugGuiTitle } from '../../../../constants/experiences/DebugGuiTitle';
|
|
4
|
+
import MainThreeApp from '../../../../engines/threes/app/MainThreeApp';
|
|
4
5
|
import DebugManager from '../../../../managers/DebugManager';
|
|
5
6
|
import ThreeAssetsManager from '../../../../managers/threes/ThreeAssetsManager';
|
|
7
|
+
import ThreeActorBase from './actors/bases/ThreeActorBase';
|
|
6
8
|
|
|
7
9
|
interface EnvironmentMap {
|
|
8
10
|
intensity?: number;
|
|
9
11
|
texture?: DataTexture;
|
|
10
12
|
}
|
|
11
13
|
|
|
12
|
-
export default class Environment extends
|
|
14
|
+
export default class Environment extends ThreeActorBase {
|
|
13
15
|
private static readonly _DEFAULT_ENVIRONMENT_MAP_INTENSITY: number = 1;
|
|
14
16
|
private static readonly _DEFAULT_SUN_LIGHT_COLOR: number = 0xffffff;
|
|
15
17
|
private static readonly _DEFAULT_SUN_LIGHT_INTENSITY: number = 10;
|
|
@@ -28,19 +30,32 @@ export default class Environment extends Object3D {
|
|
|
28
30
|
this._generateSunLight();
|
|
29
31
|
}
|
|
30
32
|
|
|
33
|
+
public init(): void {
|
|
34
|
+
this.reset();
|
|
35
|
+
if (this._environmentMap) {
|
|
36
|
+
MainThreeApp.scene.environment = this._environmentMap.texture!;
|
|
37
|
+
MainThreeApp.scene.environmentIntensity = this._environmentMap.intensity!;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public reset(): void {
|
|
42
|
+
//
|
|
43
|
+
}
|
|
44
|
+
|
|
31
45
|
private _generateEnvironmentMap = (): void => {
|
|
32
46
|
this._environmentMap = {};
|
|
33
47
|
this._environmentMap.intensity = Environment._DEFAULT_ENVIRONMENT_MAP_INTENSITY;
|
|
34
48
|
this._environmentMap.texture = ThreeAssetsManager.getHDR(AssetId.THREE_HDR_TEMPLATE);
|
|
35
49
|
this._environmentMap.texture.needsUpdate = true;
|
|
36
50
|
|
|
37
|
-
|
|
38
|
-
|
|
51
|
+
MainThreeApp.scene.environment = this._environmentMap.texture;
|
|
52
|
+
MainThreeApp.scene.environmentIntensity = this._environmentMap.intensity!;
|
|
39
53
|
|
|
40
54
|
if (DebugManager.isActive) {
|
|
41
|
-
const
|
|
55
|
+
const viewsDebug = DebugManager.getGuiFolder(DebugGuiTitle.THREE_VIEWS)
|
|
56
|
+
const environmentFolder = viewsDebug.addFolder('Environment');
|
|
42
57
|
environmentFolder.add(this._environmentMap, 'intensity', 0, 10, 0.01).onChange(() => {
|
|
43
|
-
|
|
58
|
+
MainThreeApp.scene.environmentIntensity = this._environmentMap.intensity!;
|
|
44
59
|
});
|
|
45
60
|
}
|
|
46
61
|
};
|
|
@@ -61,7 +76,8 @@ export default class Environment extends Object3D {
|
|
|
61
76
|
this.add(this._sunLight);
|
|
62
77
|
|
|
63
78
|
if (DebugManager.isActive) {
|
|
64
|
-
const
|
|
79
|
+
const viewsDebug = DebugManager.getGuiFolder(DebugGuiTitle.THREE_VIEWS)
|
|
80
|
+
const sunLightFolder = viewsDebug.addFolder('Sun Light');
|
|
65
81
|
sunLightFolder.add(this._sunLight, 'intensity', 0, 10, 0.01).name('intensity');
|
|
66
82
|
sunLightFolder.add(this._sunLight.position, 'x', -5, 5, 0.01).name('positionX');
|
|
67
83
|
sunLightFolder.add(this._sunLight.position, 'y', -5, 5, 0.01).name('positionY');
|
|
@@ -69,5 +85,5 @@ export default class Environment extends Object3D {
|
|
|
69
85
|
}
|
|
70
86
|
}
|
|
71
87
|
|
|
72
|
-
public update(_dt: number): void {}
|
|
88
|
+
public update(_dt: number): void { }
|
|
73
89
|
}
|
package/template-vanilla/src/experiences/views/threes/worlds/components/actors/TemplateFont.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { Mesh, MeshStandardMaterial, type MeshStandardMaterialParameters } from
|
|
|
2
2
|
import { TextGeometry, type TextGeometryParameters } from 'three/examples/jsm/Addons.js';
|
|
3
3
|
import { AssetId } from '../../../../../constants/experiences/AssetId';
|
|
4
4
|
import ThreeAssetsManager from '../../../../../managers/threes/ThreeAssetsManager';
|
|
5
|
-
import
|
|
5
|
+
import ThreeActorBase from './bases/ThreeActorBase';
|
|
6
6
|
|
|
7
|
-
export default class TemplateFont extends
|
|
7
|
+
export default class TemplateFont extends ThreeActorBase {
|
|
8
8
|
private static readonly _DEFAULT_TEXT: string = 'Hello boilerplate!';
|
|
9
9
|
private static readonly _DEFAULT_TEXT_OPTION: TextGeometryParameters = {
|
|
10
10
|
font: null!,
|
|
@@ -55,10 +55,4 @@ export default class TemplateFont extends ActorBase {
|
|
|
55
55
|
|
|
56
56
|
this.add(this._mesh);
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
public override dispose(): void {
|
|
60
|
-
super.dispose();
|
|
61
|
-
this._geometry.dispose();
|
|
62
|
-
this._material.dispose();
|
|
63
|
-
}
|
|
64
58
|
}
|
package/template-vanilla/src/experiences/views/threes/worlds/components/actors/TemplateMesh.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Mesh, MeshStandardMaterial, RepeatWrapping, SphereGeometry, type MeshStandardMaterialParameters } from 'three';
|
|
2
2
|
import { AssetId } from '../../../../../constants/experiences/AssetId';
|
|
3
3
|
import ThreeAssetsManager from '../../../../../managers/threes/ThreeAssetsManager';
|
|
4
|
-
import
|
|
4
|
+
import ThreeActorBase from './bases/ThreeActorBase';
|
|
5
5
|
|
|
6
|
-
export default class TemplateMesh extends
|
|
6
|
+
export default class TemplateMesh extends ThreeActorBase {
|
|
7
7
|
private static readonly _DEFAULT_GEOMETRY_RADIUS = 1;
|
|
8
8
|
private static readonly _DEFAULT_GEOMETRY_WIDTH_SEGMENTS = 64;
|
|
9
9
|
private static readonly _DEFAULT_GEOMETRY_HEIGHT_SEGMENTS = 64;
|
|
@@ -54,10 +54,8 @@ export default class TemplateMesh extends ActorBase {
|
|
|
54
54
|
this.add(this._mesh);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
public override
|
|
58
|
-
|
|
59
|
-
this._geometry.dispose();
|
|
60
|
-
this._material.dispose();
|
|
57
|
+
public override reset(): void {
|
|
58
|
+
this._mesh.rotation.y = 0;
|
|
61
59
|
}
|
|
62
60
|
|
|
63
61
|
public update(dt: number): void {
|
package/template-vanilla/src/experiences/views/threes/worlds/components/actors/TemplateMesh2.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { BoxGeometry, Mesh, MeshStandardMaterial, RepeatWrapping, type MeshStandardMaterialParameters } from 'three';
|
|
2
|
+
import { AssetId } from '../../../../../constants/experiences/AssetId';
|
|
3
|
+
import ThreeAssetsManager from '../../../../../managers/threes/ThreeAssetsManager';
|
|
4
|
+
import ThreeActorBase from './bases/ThreeActorBase';
|
|
5
|
+
|
|
6
|
+
export default class TemplateMesh2 extends ThreeActorBase {
|
|
7
|
+
private static readonly _DEFAULT_GEOMETRY_WIDTH = 2;
|
|
8
|
+
private static readonly _DEFAULT_GEOMETRY_HEIGHT = 2;
|
|
9
|
+
private static readonly _DEFAULT_GEOMETRY_DEPTH = 2;
|
|
10
|
+
private static readonly _DEFAULT_GEOMETRY_WIDTH_SEGMENTS = 1;
|
|
11
|
+
private static readonly _DEFAULT_GEOMETRY_HEIGHT_SEGMENTS = 1;
|
|
12
|
+
private static readonly _DEFAULT_GEOMETRY_DEPTH_SEGMENTS = 1;
|
|
13
|
+
private static readonly _DEFAULT_MATERIAL_REPEAT = 1.5;
|
|
14
|
+
private static readonly _DEFAULT_MATERIAL_OPTIONS: MeshStandardMaterialParameters = {
|
|
15
|
+
color: 0xffffff,
|
|
16
|
+
metalness: 0.7,
|
|
17
|
+
roughness: 0.2,
|
|
18
|
+
envMapIntensity: 0,
|
|
19
|
+
};
|
|
20
|
+
private static readonly _MESH_ROTATION_Y = 0.25;
|
|
21
|
+
|
|
22
|
+
declare private _geometry: BoxGeometry;
|
|
23
|
+
declare private _material: MeshStandardMaterial;
|
|
24
|
+
declare private _mesh: Mesh;
|
|
25
|
+
|
|
26
|
+
constructor() {
|
|
27
|
+
super();
|
|
28
|
+
|
|
29
|
+
this._generateGeometry();
|
|
30
|
+
this._generateMaterial();
|
|
31
|
+
this._generateMesh();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private _generateGeometry(): void {
|
|
35
|
+
this._geometry = new BoxGeometry(
|
|
36
|
+
TemplateMesh2._DEFAULT_GEOMETRY_WIDTH,
|
|
37
|
+
TemplateMesh2._DEFAULT_GEOMETRY_HEIGHT,
|
|
38
|
+
TemplateMesh2._DEFAULT_GEOMETRY_DEPTH,
|
|
39
|
+
TemplateMesh2._DEFAULT_GEOMETRY_WIDTH_SEGMENTS,
|
|
40
|
+
TemplateMesh2._DEFAULT_GEOMETRY_HEIGHT_SEGMENTS,
|
|
41
|
+
TemplateMesh2._DEFAULT_GEOMETRY_DEPTH_SEGMENTS
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private _generateMaterial(): void {
|
|
46
|
+
const normalMat = ThreeAssetsManager.getTexture(AssetId.THREE_TEXTURE_TEMPLATE);
|
|
47
|
+
normalMat.repeat.set(TemplateMesh2._DEFAULT_MATERIAL_REPEAT, TemplateMesh2._DEFAULT_MATERIAL_REPEAT);
|
|
48
|
+
normalMat.wrapS = normalMat.wrapT = RepeatWrapping;
|
|
49
|
+
|
|
50
|
+
this._material = new MeshStandardMaterial({
|
|
51
|
+
...TemplateMesh2._DEFAULT_MATERIAL_OPTIONS,
|
|
52
|
+
normalMap: normalMat,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private _generateMesh(): void {
|
|
57
|
+
this._mesh = new Mesh(this._geometry, this._material);
|
|
58
|
+
this._mesh.castShadow = true;
|
|
59
|
+
this._mesh.receiveShadow = true;
|
|
60
|
+
this.add(this._mesh);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public override reset(): void {
|
|
64
|
+
this._mesh.rotation.y = 0;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public update(dt: number): void {
|
|
68
|
+
super.update(dt);
|
|
69
|
+
this._mesh.rotation.y += dt * TemplateMesh2._MESH_ROTATION_Y;
|
|
70
|
+
}
|
|
71
|
+
}
|
package/template-vanilla/src/experiences/views/threes/worlds/components/actors/TemplateModel.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Vector3 } from 'three';
|
|
2
2
|
import { AssetId } from '../../../../../constants/experiences/AssetId';
|
|
3
|
+
import { DebugGuiTitle } from '../../../../../constants/experiences/DebugGuiTitle';
|
|
3
4
|
import DebugManager from '../../../../../managers/DebugManager';
|
|
4
|
-
import
|
|
5
|
+
import ThreeModelBase from './bases/ThreeModelBase';
|
|
5
6
|
|
|
6
|
-
export default class TemplateModel extends
|
|
7
|
+
export default class TemplateModel extends ThreeModelBase {
|
|
7
8
|
private static readonly _DEFAULT_POSITION: Vector3 = new Vector3(0, 1, 0);
|
|
8
9
|
private static readonly _ROTATION_Y = 0.25;
|
|
9
10
|
|
|
@@ -15,11 +16,16 @@ export default class TemplateModel extends ModelBase {
|
|
|
15
16
|
this.position.copy(TemplateModel._DEFAULT_POSITION);
|
|
16
17
|
|
|
17
18
|
if (DebugManager.isActive) {
|
|
18
|
-
const
|
|
19
|
+
const viewsDebug = DebugManager.getGuiFolder(DebugGuiTitle.THREE_VIEWS)
|
|
20
|
+
const templateModelFolder = viewsDebug.addFolder('Template Model');
|
|
19
21
|
templateModelFolder.add(this.position, 'y', -1, 1, 0.01);
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
public override reset(): void {
|
|
26
|
+
this.rotation.y = 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
23
29
|
public update(dt: number): void {
|
|
24
30
|
super.update(dt);
|
|
25
31
|
this.rotation.y += dt * TemplateModel._ROTATION_Y;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { BufferGeometry, Material, Mesh, Object3D, Texture } from 'three';
|
|
2
|
+
|
|
3
|
+
export default abstract class ThreeActorBase extends Object3D {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
public init(): void {
|
|
9
|
+
this.reset();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public reset(): void {
|
|
13
|
+
//
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public dispose(): void {
|
|
17
|
+
const geometries = new Set<BufferGeometry>();
|
|
18
|
+
const materials = new Set<Material>();
|
|
19
|
+
const textures = new Set<Texture>();
|
|
20
|
+
|
|
21
|
+
this.traverse((child) => {
|
|
22
|
+
if (child instanceof Mesh) {
|
|
23
|
+
if (child.geometry instanceof BufferGeometry) geometries.add(child.geometry as BufferGeometry);
|
|
24
|
+
|
|
25
|
+
const mats = Array.isArray(child.material) ? child.material : [child.material];
|
|
26
|
+
mats.forEach((mat) => {
|
|
27
|
+
if (mat instanceof Material) {
|
|
28
|
+
materials.add(mat);
|
|
29
|
+
|
|
30
|
+
Object.values(mat).forEach((value) => {
|
|
31
|
+
if (value instanceof Texture) textures.add(value);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
textures.forEach((tex) => tex.dispose());
|
|
39
|
+
materials.forEach((mat) => mat.dispose());
|
|
40
|
+
geometries.forEach((geo) => geo.dispose());
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public update(_dt: number): void { }
|
|
44
|
+
}
|
|
@@ -2,9 +2,9 @@ import { AnimationAction, AnimationMixer } from 'three';
|
|
|
2
2
|
import type { AnimationId } from '../../../../../../constants/experiences/AnimationId';
|
|
3
3
|
import type { AssetId } from '../../../../../../constants/experiences/AssetId';
|
|
4
4
|
import ThreeAssetsManager from '../../../../../../managers/threes/ThreeAssetsManager';
|
|
5
|
-
import
|
|
5
|
+
import ThreeModelBase, { type ModelBaseParams } from './ThreeModelBase';
|
|
6
6
|
|
|
7
|
-
export default abstract class
|
|
7
|
+
export default abstract class ThreeAnimatedModelBase extends ThreeModelBase {
|
|
8
8
|
private static readonly _DEFAULT_ANIMATION_FADE_DURATION: number = 1;
|
|
9
9
|
|
|
10
10
|
declare private _mixer: AnimationMixer;
|
|
@@ -35,7 +35,7 @@ export default abstract class AnimatedModelBase extends ModelBase {
|
|
|
35
35
|
|
|
36
36
|
protected _playAnimation = (
|
|
37
37
|
animationId: AnimationId,
|
|
38
|
-
fadeDuration: number =
|
|
38
|
+
fadeDuration: number = ThreeAnimatedModelBase._DEFAULT_ANIMATION_FADE_DURATION
|
|
39
39
|
): void => {
|
|
40
40
|
if (!this._actions) return;
|
|
41
41
|
const newAction = this._getAnimationAction(animationId);
|
|
@@ -3,7 +3,7 @@ import { SkeletonUtils } from 'three/examples/jsm/Addons.js';
|
|
|
3
3
|
import type { AssetId } from '../../../../../../constants/experiences/AssetId';
|
|
4
4
|
import type { Object3DId } from '../../../../../../constants/experiences/Object3dId';
|
|
5
5
|
import ThreeAssetsManager from '../../../../../../managers/threes/ThreeAssetsManager';
|
|
6
|
-
import
|
|
6
|
+
import ThreeActorBase from './ThreeActorBase';
|
|
7
7
|
|
|
8
8
|
export interface ModelBaseParams {
|
|
9
9
|
object3DId?: Object3DId;
|
|
@@ -11,7 +11,7 @@ export interface ModelBaseParams {
|
|
|
11
11
|
receiveShadow?: boolean;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export default abstract class
|
|
14
|
+
export default abstract class ThreeModelBase extends ThreeActorBase {
|
|
15
15
|
protected _assetId: AssetId;
|
|
16
16
|
protected _parameters: ModelBaseParams;
|
|
17
17
|
declare protected _model: Group | Object3D | Mesh;
|
|
@@ -42,20 +42,6 @@ export default abstract class ModelBase extends ActorBase {
|
|
|
42
42
|
this.add(this._model);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
public override dispose(): void {
|
|
46
|
-
super.dispose();
|
|
47
|
-
this._model.traverse((child) => {
|
|
48
|
-
if (child instanceof Mesh) {
|
|
49
|
-
child.geometry.dispose();
|
|
50
|
-
if (Array.isArray(child.material)) {
|
|
51
|
-
child.material.forEach((material) => material.dispose());
|
|
52
|
-
} else {
|
|
53
|
-
child.material.dispose();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
45
|
public update(dt: number): void {
|
|
60
46
|
super.update(dt);
|
|
61
47
|
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { DomUtils } from '@benjos/cookware';
|
|
2
|
-
import { Scene } from 'three';
|
|
3
|
-
import LoaderThreeCameraController from '../../cameras/threes/LoaderThreeCameraController';
|
|
4
|
-
import { CameraId } from '../../constants/experiences/CameraId';
|
|
5
|
-
import ThreeCameraControllerManager from '../../managers/threes/ThreeCameraControllerManager';
|
|
6
|
-
import LoaderRenderer from '../../renderers/threes/LoaderRenderer';
|
|
7
|
-
import LoaderThreeView from '../../views/threes/loaders/LoaderThreeView';
|
|
8
|
-
import ThreeBase from './bases/ThreeBase';
|
|
9
|
-
|
|
10
|
-
class LoaderThree extends ThreeBase {
|
|
11
|
-
constructor() {
|
|
12
|
-
super(DomUtils.GetLoader());
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
protected override _generateScenes(): void {
|
|
16
|
-
this._scene = new Scene();
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
protected override _generateCameras(): void {
|
|
20
|
-
ThreeCameraControllerManager.add(new LoaderThreeCameraController());
|
|
21
|
-
this._cameraController = ThreeCameraControllerManager.get(CameraId.THREE_LOADER);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
protected override _generateRenderers(): void {
|
|
25
|
-
this._renderer = new LoaderRenderer(
|
|
26
|
-
this._scene,
|
|
27
|
-
ThreeCameraControllerManager.get(CameraId.THREE_LOADER).camera
|
|
28
|
-
);
|
|
29
|
-
this._domElementContainer.appendChild(this._renderer.domElement);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
protected override _generateViews(): void {
|
|
33
|
-
const loaderThreeView = new LoaderThreeView();
|
|
34
|
-
this._views.push(loaderThreeView);
|
|
35
|
-
this._setCurrentView(loaderThreeView);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export default new LoaderThree();
|