@benjos/create-boilerplate 1.0.0 → 1.0.3

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.
Files changed (94) hide show
  1. package/README.md +16 -21
  2. package/dist/index.js +16 -15
  3. package/dist/index.js.map +1 -1
  4. package/package.json +2 -2
  5. package/template-vanilla/.prettierignore +6 -0
  6. package/template-vanilla/.prettierrc +10 -0
  7. package/template-vanilla/assets_source/.gitkeep +0 -0
  8. package/template-vanilla/docs/PUBLISHING.md +30 -0
  9. package/template-vanilla/eslint.config.js +126 -0
  10. package/template-vanilla/index.html +17 -0
  11. package/template-vanilla/package-lock.json +3743 -0
  12. package/template-vanilla/package.json +38 -0
  13. package/template-vanilla/public/assets/fonts/LICENSE +13 -0
  14. package/template-vanilla/public/assets/fonts/template.typeface.json +1 -0
  15. package/template-vanilla/public/assets/hdrs/template.hdr +0 -0
  16. package/template-vanilla/public/assets/icons/benjosLogoBlack.svg +5 -0
  17. package/template-vanilla/public/assets/loaders/draco/README.md +32 -0
  18. package/template-vanilla/public/assets/loaders/draco/draco_decoder.js +34 -0
  19. package/template-vanilla/public/assets/loaders/draco/draco_decoder.wasm +0 -0
  20. package/template-vanilla/public/assets/loaders/draco/draco_encoder.js +33 -0
  21. package/template-vanilla/public/assets/loaders/draco/draco_wasm_wrapper.js +117 -0
  22. package/template-vanilla/public/assets/loaders/draco/gltf/draco_decoder.js +33 -0
  23. package/template-vanilla/public/assets/loaders/draco/gltf/draco_decoder.wasm +0 -0
  24. package/template-vanilla/public/assets/loaders/draco/gltf/draco_encoder.js +33 -0
  25. package/template-vanilla/public/assets/loaders/draco/gltf/draco_wasm_wrapper.js +116 -0
  26. package/template-vanilla/public/assets/models/template.glb +0 -0
  27. package/template-vanilla/public/assets/textures/template.jpg +0 -0
  28. package/template-vanilla/readme.md +49 -0
  29. package/template-vanilla/src/experiences/Experience.ts +15 -0
  30. package/template-vanilla/src/experiences/cameras/threes/DebugThreeCameraController.ts +60 -0
  31. package/template-vanilla/src/experiences/cameras/threes/LoaderThreeCameraController.ts +28 -0
  32. package/template-vanilla/src/experiences/cameras/threes/MainThreeCameraController.ts +28 -0
  33. package/template-vanilla/src/experiences/cameras/threes/bases/ThreeCameraControllerBase.ts +109 -0
  34. package/template-vanilla/src/experiences/commands/InitCommand.ts +48 -0
  35. package/template-vanilla/src/experiences/constants/doms/DomEvent.ts +100 -0
  36. package/template-vanilla/src/experiences/constants/doms/KeyboardConstant.ts +250 -0
  37. package/template-vanilla/src/experiences/constants/experiences/AnimationId.ts +3 -0
  38. package/template-vanilla/src/experiences/constants/experiences/AssetId.ts +8 -0
  39. package/template-vanilla/src/experiences/constants/experiences/AssetType.ts +8 -0
  40. package/template-vanilla/src/experiences/constants/experiences/CameraId.ts +7 -0
  41. package/template-vanilla/src/experiences/constants/experiences/CameraType.ts +6 -0
  42. package/template-vanilla/src/experiences/constants/experiences/Object3dId.ts +3 -0
  43. package/template-vanilla/src/experiences/constants/experiences/ViewId.ts +15 -0
  44. package/template-vanilla/src/experiences/engines/htmls/MainHTML.ts +13 -0
  45. package/template-vanilla/src/experiences/engines/threes/MainThree.ts +171 -0
  46. package/template-vanilla/src/experiences/managers/DebugManager.ts +78 -0
  47. package/template-vanilla/src/experiences/managers/KeyboardManager.ts +65 -0
  48. package/template-vanilla/src/experiences/managers/LoaderManager.ts +79 -0
  49. package/template-vanilla/src/experiences/managers/MouseManager.ts +100 -0
  50. package/template-vanilla/src/experiences/managers/ResizeManager.ts +53 -0
  51. package/template-vanilla/src/experiences/managers/TickerManager.ts +86 -0
  52. package/template-vanilla/src/experiences/managers/threes/ThreeAssetsManager.ts +279 -0
  53. package/template-vanilla/src/experiences/managers/threes/ThreeCameraControllerManager.ts +43 -0
  54. package/template-vanilla/src/experiences/managers/threes/ThreeRaycasterManager.ts +23 -0
  55. package/template-vanilla/src/experiences/materials/threes/loaders/LoaderMaterial.ts +48 -0
  56. package/template-vanilla/src/experiences/proxies/ViewProxy.ts +30 -0
  57. package/template-vanilla/src/experiences/proxies/bases/PoolProxyBase.ts +61 -0
  58. package/template-vanilla/src/experiences/renderers/threes/LoaderRenderer.ts +22 -0
  59. package/template-vanilla/src/experiences/renderers/threes/Renderer.ts +74 -0
  60. package/template-vanilla/src/experiences/renderers/threes/bases/WebGLRendererBase.ts +29 -0
  61. package/template-vanilla/src/experiences/shaders/threes/loaders/LoaderFragmentShader.glsl +6 -0
  62. package/template-vanilla/src/experiences/shaders/threes/loaders/LoaderVertexShader.glsl +3 -0
  63. package/template-vanilla/src/experiences/styles/abstracts/_import.scss +5 -0
  64. package/template-vanilla/src/experiences/styles/abstracts/functions.scss +3 -0
  65. package/template-vanilla/src/experiences/styles/abstracts/mixins.scss +0 -0
  66. package/template-vanilla/src/experiences/styles/abstracts/variables.scss +7 -0
  67. package/template-vanilla/src/experiences/styles/commons/fonts.scss +10 -0
  68. package/template-vanilla/src/experiences/styles/commons/main.scss +84 -0
  69. package/template-vanilla/src/experiences/styles/commons/texts.scss +1 -0
  70. package/template-vanilla/src/experiences/styles/style.scss +7 -0
  71. package/template-vanilla/src/experiences/styles/views/loader.scss +72 -0
  72. package/template-vanilla/src/experiences/tools/Action.ts +23 -0
  73. package/template-vanilla/src/experiences/tools/Point.ts +56 -0
  74. package/template-vanilla/src/experiences/types/global.d.ts +9 -0
  75. package/template-vanilla/src/experiences/utils/AssetUtils.ts +6 -0
  76. package/template-vanilla/src/experiences/utils/DomUtils.ts +28 -0
  77. package/template-vanilla/src/experiences/views/bases/ViewBase.ts +25 -0
  78. package/template-vanilla/src/experiences/views/htmls/bases/HTMLViewBase.ts +41 -0
  79. package/template-vanilla/src/experiences/views/htmls/loaders/LoaderHTMLView.ts +34 -0
  80. package/template-vanilla/src/experiences/views/htmls/loaders/components/HTMLTemplateLoader.ts +57 -0
  81. package/template-vanilla/src/experiences/views/threes/bases/ThreeViewBase.ts +26 -0
  82. package/template-vanilla/src/experiences/views/threes/loaders/LoaderThreeView.ts +41 -0
  83. package/template-vanilla/src/experiences/views/threes/loaders/components/ThreeTemplateLoader.ts +52 -0
  84. package/template-vanilla/src/experiences/views/threes/worlds/WorldThreeView.ts +51 -0
  85. package/template-vanilla/src/experiences/views/threes/worlds/components/Environment.ts +77 -0
  86. package/template-vanilla/src/experiences/views/threes/worlds/components/actors/TemplateFont.ts +62 -0
  87. package/template-vanilla/src/experiences/views/threes/worlds/components/actors/TemplateMesh.ts +65 -0
  88. package/template-vanilla/src/experiences/views/threes/worlds/components/actors/TemplateModel.ts +31 -0
  89. package/template-vanilla/src/experiences/views/threes/worlds/components/actors/bases/ActorBase.ts +9 -0
  90. package/template-vanilla/src/experiences/views/threes/worlds/components/actors/bases/AnimatedModelBase.ts +67 -0
  91. package/template-vanilla/src/experiences/views/threes/worlds/components/actors/bases/ModelBase.ts +48 -0
  92. package/template-vanilla/src/main.ts +3 -0
  93. package/template-vanilla/tsconfig.json +24 -0
  94. package/template-vanilla/vite.config.ts +15 -0
@@ -0,0 +1,25 @@
1
+ import type { ViewId } from '../../constants/experiences/ViewId';
2
+
3
+ export default class ViewBase {
4
+ private readonly _id: ViewId;
5
+
6
+ constructor(id: ViewId) {
7
+ this._id = id;
8
+ }
9
+
10
+ protected _show(): void {
11
+ //
12
+ }
13
+
14
+ protected _hide(): void {
15
+ //
16
+ }
17
+
18
+ //#region Getters
19
+ //
20
+ public get id(): ViewId {
21
+ return this._id;
22
+ }
23
+ //
24
+ //#endregion
25
+ }
@@ -0,0 +1,41 @@
1
+ import { DomEvent } from '../../../constants/doms/DomEvent';
2
+ import type { ViewId } from '../../../constants/experiences/ViewId';
3
+ import DomUtils from '../../../utils/DomUtils';
4
+ import ViewBase from '../../bases/ViewBase';
5
+
6
+ export default abstract class HTMLViewBase extends ViewBase {
7
+ private readonly _parentElement: HTMLElement;
8
+ protected readonly _htmlContainer: HTMLDivElement;
9
+
10
+ constructor(id: ViewId, parentElement: HTMLElement = DomUtils.GetApp()) {
11
+ super(id);
12
+ this._parentElement = parentElement;
13
+ this._htmlContainer = document.createElement('div');
14
+ this._htmlContainer.classList.add('view-html-container');
15
+
16
+ this._htmlContainer.addEventListener(DomEvent.ANIMATION_END, this._onAnimationEnd);
17
+ }
18
+
19
+ protected override _show(): void {
20
+ super._show();
21
+ this._parentElement.appendChild(this._htmlContainer);
22
+ this._htmlContainer.classList.remove('hide');
23
+ requestAnimationFrame(this._onShow);
24
+ }
25
+
26
+ private readonly _onShow = (): void => {
27
+ this._htmlContainer.classList.add('show');
28
+ };
29
+
30
+ protected override _hide(): void {
31
+ super._hide();
32
+ this._htmlContainer.classList.remove('show');
33
+ this._htmlContainer.classList.add('hide');
34
+ }
35
+
36
+ private readonly _onAnimationEnd = (event: AnimationEvent): void => {
37
+ if (event.animationName === 'hideView') {
38
+ this._parentElement.removeChild(this._htmlContainer);
39
+ }
40
+ };
41
+ }
@@ -0,0 +1,34 @@
1
+ import { ViewId } from '../../../constants/experiences/ViewId';
2
+ import LoaderManager from '../../../managers/LoaderManager';
3
+ import DomUtils from '../../../utils/DomUtils';
4
+ import HTMLViewBase from '../bases/HTMLViewBase';
5
+ import HTMLTemplateLoader from './components/HTMLTemplateLoader';
6
+
7
+ export default class LoaderHTMLView extends HTMLViewBase {
8
+ declare private _htmlLoader: HTMLTemplateLoader;
9
+
10
+ constructor(id: ViewId) {
11
+ super(id, DomUtils.GetLoader());
12
+
13
+ this._generateLoader();
14
+
15
+ LoaderManager.OnBeginLoad.add(this._onBeginLoad);
16
+ LoaderManager.OnFinishLoad.add(this._onFinishLoad);
17
+ }
18
+
19
+ private _generateLoader(): void {
20
+ this._htmlLoader = new HTMLTemplateLoader();
21
+ this._htmlContainer.appendChild(this._htmlLoader.htmlElement);
22
+ DomUtils.GetLoader().appendChild(this._htmlContainer);
23
+ }
24
+
25
+ private readonly _onBeginLoad = (): void => {
26
+ this._show();
27
+ this._htmlLoader.show();
28
+ };
29
+
30
+ private readonly _onFinishLoad = (): void => {
31
+ this._htmlLoader.hide();
32
+ this._hide();
33
+ };
34
+ }
@@ -0,0 +1,57 @@
1
+ import LoaderManager from '../../../../managers/LoaderManager';
2
+
3
+ export default class HTMLTemplateLoader {
4
+ declare private _htmlElement: HTMLDivElement;
5
+ declare private _loadingBar: HTMLDivElement;
6
+ declare private _loadingProgress: HTMLDivElement;
7
+ declare private _loadingNumber: HTMLSpanElement;
8
+
9
+ constructor() {
10
+ this._generateElement();
11
+
12
+ LoaderManager.OnProgress.add(this._onProgress);
13
+ }
14
+
15
+ private _generateElement(): void {
16
+ const wrapper = document.createElement('div');
17
+ wrapper.innerHTML = `
18
+ <div id="loading-screen" class="loading-screen">
19
+ <div class="loading-progress">
20
+ <span class="loading-number">0</span><span>%</span>
21
+ </div>
22
+ <div class="loading-bar"></div>
23
+ </div>
24
+ `.trim();
25
+
26
+ this._htmlElement = wrapper.querySelector('#loading-screen')!;
27
+ this._loadingProgress = this._htmlElement.querySelector('.loading-progress')!;
28
+ this._loadingNumber = this._loadingProgress.querySelector('.loading-number')!;
29
+ this._loadingBar = this._htmlElement.querySelector('.loading-bar')!;
30
+ }
31
+
32
+ private readonly _onProgress = (): void => {
33
+ const progress = (LoaderManager.LoadedSize / LoaderManager.TotalSize) * 100;
34
+ this._loadingBar.style.transform = `translateY(-50%) scaleX(${progress / 100})`;
35
+ this._loadingNumber.textContent = Math.round(progress).toString();
36
+ };
37
+
38
+ public show(): void {
39
+ this._loadingNumber.textContent = '0';
40
+ this._loadingBar.style.transform = '';
41
+ this._loadingBar.classList.remove('ended');
42
+ }
43
+
44
+ public hide(): void {
45
+ this._loadingNumber.textContent = '100';
46
+ this._loadingBar.style.transform = '';
47
+ this._loadingBar.classList.add('ended');
48
+ }
49
+
50
+ //#region
51
+ //
52
+ public get htmlElement(): HTMLDivElement {
53
+ return this._htmlElement;
54
+ }
55
+ //
56
+ //#endregion
57
+ }
@@ -0,0 +1,26 @@
1
+ import { Object3D, Scene } from 'three';
2
+ import type { ViewId } from '../../../constants/experiences/ViewId';
3
+ import MainThree from '../../../engines/threes/MainThree';
4
+ import ViewBase from '../../bases/ViewBase';
5
+
6
+ export default abstract class ThreeViewBase extends ViewBase {
7
+ protected _scene: Scene;
8
+ protected _container: Object3D;
9
+
10
+ constructor(id: ViewId, scene: Scene = MainThree.Scene) {
11
+ super(id);
12
+
13
+ this._scene = scene;
14
+ this._container = new Object3D();
15
+ }
16
+
17
+ protected override _show(): void {
18
+ super._show();
19
+ this._scene.add(this._container);
20
+ }
21
+
22
+ protected override _hide(): void {
23
+ super._hide();
24
+ this._scene.remove(this._container);
25
+ }
26
+ }
@@ -0,0 +1,41 @@
1
+ import { ViewId } from '../../../constants/experiences/ViewId';
2
+ import MainThree from '../../../engines/threes/MainThree';
3
+ import LoaderManager from '../../../managers/LoaderManager';
4
+ import ThreeViewBase from '../bases/ThreeViewBase';
5
+ import ThreeTemplateLoader from './components/ThreeTemplateLoader';
6
+
7
+ export default class LoaderThreeView extends ThreeViewBase {
8
+ declare private _threeLoader: ThreeTemplateLoader;
9
+
10
+ constructor(id: ViewId) {
11
+ super(id, MainThree.LoaderScene);
12
+
13
+ this._generateLoader();
14
+
15
+ LoaderManager.OnBeginLoad.add(this._onBeginLoad);
16
+ LoaderManager.OnFinishLoad.add(this._onFinishLoad);
17
+ }
18
+
19
+ private _generateLoader(): void {
20
+ this._threeLoader = new ThreeTemplateLoader();
21
+
22
+ this._container.add(this._threeLoader);
23
+ this._scene.add(this._container);
24
+ }
25
+
26
+ protected override _show(): void {
27
+ this._threeLoader.material.show();
28
+ }
29
+
30
+ protected override _hide(): void {
31
+ this._threeLoader.material.hide();
32
+ }
33
+
34
+ private readonly _onBeginLoad = (): void => {
35
+ this._show();
36
+ };
37
+
38
+ private readonly _onFinishLoad = (): void => {
39
+ this._hide();
40
+ };
41
+ }
@@ -0,0 +1,52 @@
1
+ import { Mesh, Object3D, PlaneGeometry } from 'three';
2
+ import LoaderMaterial from '../../../../materials/threes/loaders/LoaderMaterial';
3
+
4
+ export default class ThreeTemplateLoader extends Object3D {
5
+ declare private _geometry: PlaneGeometry;
6
+ declare private _material: LoaderMaterial;
7
+ declare private _loader: Mesh;
8
+
9
+ //#region Constants
10
+ //
11
+ private static readonly _DEFAULT_SIZE_WIDTH: number = 2;
12
+ private static readonly _DEFAULT_SIZE_HEIGHT: number = 2;
13
+ private static readonly _DEFAULT_SEGMENTS_WIDTH: number = 1;
14
+ private static readonly _DEFAULT_SEGMENTS_HEIGHT: number = 1;
15
+ //
16
+ //#endregion
17
+
18
+ constructor() {
19
+ super();
20
+
21
+ this._generateGeometry();
22
+ this._generateMaterial();
23
+ this._generateMesh();
24
+
25
+ this.add(this._loader);
26
+ }
27
+
28
+ private _generateGeometry(): void {
29
+ this._geometry = new PlaneGeometry(
30
+ ThreeTemplateLoader._DEFAULT_SIZE_WIDTH,
31
+ ThreeTemplateLoader._DEFAULT_SIZE_HEIGHT,
32
+ ThreeTemplateLoader._DEFAULT_SEGMENTS_WIDTH,
33
+ ThreeTemplateLoader._DEFAULT_SEGMENTS_HEIGHT
34
+ );
35
+ }
36
+
37
+ private _generateMaterial(): void {
38
+ this._material = new LoaderMaterial();
39
+ }
40
+
41
+ private _generateMesh(): void {
42
+ this._loader = new Mesh(this._geometry, this._material);
43
+ }
44
+
45
+ //#region Getters
46
+ //
47
+ public get material(): LoaderMaterial {
48
+ return this._material;
49
+ }
50
+ //
51
+ //#endregion
52
+ }
@@ -0,0 +1,51 @@
1
+ import { ViewId } from '../../../constants/experiences/ViewId';
2
+ import LoaderManager from '../../../managers/LoaderManager';
3
+ import ThreeViewBase from '../bases/ThreeViewBase';
4
+ import Environment from './components/Environment';
5
+ import TemplateFont from './components/actors/TemplateFont';
6
+ import TemplateMesh from './components/actors/TemplateMesh';
7
+ import TemplateModel from './components/actors/TemplateModel';
8
+ import type ActorBase from './components/actors/bases/ActorBase';
9
+
10
+ export default class WorldThreeView extends ThreeViewBase {
11
+ declare private _environment: Environment;
12
+ private readonly _actors: ActorBase[];
13
+
14
+ constructor(id: ViewId) {
15
+ super(id);
16
+
17
+ this._actors = [];
18
+
19
+ LoaderManager.OnFinishLoad.add(this._onFinishLoad);
20
+ }
21
+
22
+ private readonly _onFinishLoad = (): void => {
23
+ this._generateEnvironment();
24
+ this._generateActors();
25
+
26
+ this._show();
27
+ };
28
+
29
+ private _generateEnvironment(): void {
30
+ if (this._environment) return;
31
+ this._environment = new Environment();
32
+
33
+ this._container.add(this._environment);
34
+ }
35
+
36
+ private _generateActors(): void {
37
+ if (this._actors.length > 0) return;
38
+ this._actors.push(new TemplateMesh());
39
+ this._actors.push(new TemplateModel());
40
+ this._actors.push(new TemplateFont());
41
+
42
+ for (const actor of this._actors) this._container.add(actor);
43
+ }
44
+
45
+ public update(dt: number): void {
46
+ if (!this._environment) return;
47
+
48
+ this._environment.update(dt);
49
+ for (const actor of this._actors) actor.update(dt);
50
+ }
51
+ }
@@ -0,0 +1,77 @@
1
+ import { DataTexture, DirectionalLight, Object3D, Vector3 } from 'three';
2
+ import { AssetId } from '../../../../constants/experiences/AssetId';
3
+ import MainThree from '../../../../engines/threes/MainThree';
4
+ import DebugManager from '../../../../managers/DebugManager';
5
+ import ThreeAssetsManager from '../../../../managers/threes/ThreeAssetsManager';
6
+
7
+ interface IEnvironmentMap {
8
+ intensity?: number;
9
+ texture?: DataTexture;
10
+ }
11
+
12
+ export default class Environment extends Object3D {
13
+ declare private _environmentMap: IEnvironmentMap;
14
+ declare private _sunLight: DirectionalLight;
15
+
16
+ //#region Constants
17
+ //
18
+ private static readonly _DEFAULT_ENVIRONMENT_MAP_INTENSITY: number = 1;
19
+ private static readonly _DEFAULT_SUN_LIGHT_COLOR: number = 0xffffff;
20
+ private static readonly _DEFAULT_SUN_LIGHT_INTENSITY: number = 10;
21
+ private static readonly _DEFAULT_SUN_SHADOW_CAMERA_FAR: number = 15;
22
+ private static readonly _DEFAULT_SUN_SHADOW_MAP_SIZE: number = 1024;
23
+ private static readonly _DEFAULT_SUN_SHADOW_NORMAL_BIAS: number = 0.05;
24
+ private static readonly _DEFAULT_SUN_POSITION: Vector3 = new Vector3(0, 2, 1);
25
+ //
26
+ //#endregion
27
+
28
+ constructor() {
29
+ super();
30
+
31
+ this._generateEnvironmentMap();
32
+ this._generateSunLight();
33
+ }
34
+
35
+ private _generateEnvironmentMap = (): void => {
36
+ this._environmentMap = {};
37
+ this._environmentMap.intensity = Environment._DEFAULT_ENVIRONMENT_MAP_INTENSITY;
38
+ this._environmentMap.texture = ThreeAssetsManager.GetHDR(AssetId.THREE_HDR_TEMPLATE);
39
+ this._environmentMap.texture.needsUpdate = true;
40
+
41
+ MainThree.Scene.environment = this._environmentMap.texture;
42
+ MainThree.Scene.environmentIntensity = this._environmentMap.intensity!;
43
+
44
+ if (DebugManager.IsActive) {
45
+ const environmentFolder = DebugManager.Gui.addFolder('Environment');
46
+ environmentFolder.add(this._environmentMap, 'intensity', 0, 10, 0.01).onChange(() => {
47
+ MainThree.Scene.environmentIntensity = this._environmentMap.intensity!;
48
+ });
49
+ }
50
+ };
51
+
52
+ private _generateSunLight(): void {
53
+ this._sunLight = new DirectionalLight(
54
+ Environment._DEFAULT_SUN_LIGHT_COLOR,
55
+ Environment._DEFAULT_SUN_LIGHT_INTENSITY
56
+ );
57
+ this._sunLight.castShadow = true;
58
+ this._sunLight.shadow.camera.far = Environment._DEFAULT_SUN_SHADOW_CAMERA_FAR;
59
+ this._sunLight.shadow.mapSize.set(
60
+ Environment._DEFAULT_SUN_SHADOW_MAP_SIZE,
61
+ Environment._DEFAULT_SUN_SHADOW_MAP_SIZE
62
+ );
63
+ this._sunLight.shadow.normalBias = Environment._DEFAULT_SUN_SHADOW_NORMAL_BIAS;
64
+ this._sunLight.position.copy(Environment._DEFAULT_SUN_POSITION);
65
+ this.add(this._sunLight);
66
+
67
+ if (DebugManager.IsActive) {
68
+ const sunLightFolder = DebugManager.Gui.addFolder('Sun Light');
69
+ sunLightFolder.add(this._sunLight, 'intensity', 0, 10, 0.01).name('intensity');
70
+ sunLightFolder.add(this._sunLight.position, 'x', -5, 5, 0.01).name('positionX');
71
+ sunLightFolder.add(this._sunLight.position, 'y', -5, 5, 0.01).name('positionY');
72
+ sunLightFolder.add(this._sunLight.position, 'z', -5, 5, 0.01).name('positionZ');
73
+ }
74
+ }
75
+
76
+ public update(_dt: number): void {}
77
+ }
@@ -0,0 +1,62 @@
1
+ import { Mesh, MeshStandardMaterial, type MeshStandardMaterialParameters } from 'three';
2
+ import { TextGeometry, type TextGeometryParameters } from 'three/examples/jsm/Addons.js';
3
+ import { AssetId } from '../../../../../constants/experiences/AssetId';
4
+ import ThreeAssetsManager from '../../../../../managers/threes/ThreeAssetsManager';
5
+ import ActorBase from './bases/ActorBase';
6
+
7
+ export default class TemplateFont extends ActorBase {
8
+ declare private _geometry: TextGeometry;
9
+ declare private _material: MeshStandardMaterial;
10
+ declare private _mesh: Mesh;
11
+
12
+ //#region Constants
13
+ //
14
+ private static readonly _DEFAULT_TEXT: string = 'Hello boilerplate!';
15
+ private static readonly _DEFAULT_TEXT_OPTION: TextGeometryParameters = {
16
+ font: null!,
17
+ size: 0.25,
18
+ depth: 0.01,
19
+ curveSegments: 5,
20
+ bevelEnabled: true,
21
+ bevelThickness: 0.03,
22
+ bevelSize: 0.02,
23
+ bevelOffset: 0,
24
+ bevelSegments: 4,
25
+ };
26
+ private static readonly _DEFAULT_MATERIAL_OPTION: MeshStandardMaterialParameters = {
27
+ color: 0xffffff,
28
+ metalness: 0.7,
29
+ roughness: 0.2,
30
+ envMapIntensity: 0,
31
+ };
32
+ private static readonly _DEFAULT_MESH_POSITION_Y = 3;
33
+ //
34
+ //#endregion
35
+
36
+ constructor() {
37
+ super();
38
+
39
+ this._generateGeometry();
40
+ this._generateMaterial();
41
+ this._generateMesh();
42
+ }
43
+
44
+ private _generateGeometry(): void {
45
+ this._geometry = new TextGeometry(TemplateFont._DEFAULT_TEXT, {
46
+ ...TemplateFont._DEFAULT_TEXT_OPTION,
47
+ font: ThreeAssetsManager.GetFont(AssetId.THREE_FONT_TEMPLATE),
48
+ });
49
+ this._geometry.center();
50
+ }
51
+
52
+ private _generateMaterial(): void {
53
+ this._material = new MeshStandardMaterial(TemplateFont._DEFAULT_MATERIAL_OPTION);
54
+ }
55
+
56
+ private _generateMesh(): void {
57
+ this._mesh = new Mesh(this._geometry, this._material);
58
+ this._mesh.position.y = TemplateFont._DEFAULT_MESH_POSITION_Y;
59
+
60
+ this.add(this._mesh);
61
+ }
62
+ }
@@ -0,0 +1,65 @@
1
+ import { Mesh, MeshStandardMaterial, RepeatWrapping, SphereGeometry, type MeshStandardMaterialParameters } from 'three';
2
+ import { AssetId } from '../../../../../constants/experiences/AssetId';
3
+ import ThreeAssetsManager from '../../../../../managers/threes/ThreeAssetsManager';
4
+ import ActorBase from './bases/ActorBase';
5
+
6
+ export default class TemplateMesh extends ActorBase {
7
+ declare private _geometry: SphereGeometry;
8
+ declare private _material: MeshStandardMaterial;
9
+ declare private _mesh: Mesh;
10
+
11
+ //#region Constants
12
+ //
13
+ private static readonly _DEFAULT_GEOMETRY_RADIUS = 1;
14
+ private static readonly _DEFAULT_GEOMETRY_WIDTH_SEGMENTS = 64;
15
+ private static readonly _DEFAULT_GEOMETRY_HEIGHT_SEGMENTS = 64;
16
+ private static readonly _DEFAULT_MATERIAL_REPEAT = 1.5;
17
+ private static readonly _DEFAULT_MATERIAL_OPTIONS: MeshStandardMaterialParameters = {
18
+ color: 0xffffff,
19
+ metalness: 0.7,
20
+ roughness: 0.2,
21
+ envMapIntensity: 0,
22
+ };
23
+ private static readonly _MESH_ROTATION_Y = 0.25;
24
+ //
25
+ //#endregion
26
+
27
+ constructor() {
28
+ super();
29
+
30
+ this._generateGeometry();
31
+ this._generateMaterial();
32
+ this._generateMesh();
33
+ }
34
+
35
+ private _generateGeometry(): void {
36
+ this._geometry = new SphereGeometry(
37
+ TemplateMesh._DEFAULT_GEOMETRY_RADIUS,
38
+ TemplateMesh._DEFAULT_GEOMETRY_WIDTH_SEGMENTS,
39
+ TemplateMesh._DEFAULT_GEOMETRY_HEIGHT_SEGMENTS
40
+ );
41
+ }
42
+
43
+ private _generateMaterial(): void {
44
+ const normalMat = ThreeAssetsManager.GetTexture(AssetId.THREE_TEXTURE_TEMPLATE);
45
+ normalMat.repeat.set(TemplateMesh._DEFAULT_MATERIAL_REPEAT, TemplateMesh._DEFAULT_MATERIAL_REPEAT);
46
+ normalMat.wrapS = normalMat.wrapT = RepeatWrapping;
47
+
48
+ this._material = new MeshStandardMaterial({
49
+ ...TemplateMesh._DEFAULT_MATERIAL_OPTIONS,
50
+ normalMap: normalMat,
51
+ });
52
+ }
53
+
54
+ private _generateMesh(): void {
55
+ this._mesh = new Mesh(this._geometry, this._material);
56
+ this._mesh.castShadow = true;
57
+ this._mesh.receiveShadow = true;
58
+ this.add(this._mesh);
59
+ }
60
+
61
+ public update(dt: number): void {
62
+ super.update(dt);
63
+ this._mesh.rotation.y += dt * TemplateMesh._MESH_ROTATION_Y;
64
+ }
65
+ }
@@ -0,0 +1,31 @@
1
+ import { Vector3 } from 'three';
2
+ import { AssetId } from '../../../../../constants/experiences/AssetId';
3
+ import DebugManager from '../../../../../managers/DebugManager';
4
+ import ModelBase from './bases/ModelBase';
5
+
6
+ export default class TemplateModel extends ModelBase {
7
+ //#region Constants
8
+ //
9
+ private static readonly _DEFAULT_POSITION: Vector3 = new Vector3(0, 1, 0);
10
+ private static readonly _ROTATION_Y = 0.25;
11
+ //
12
+ //#endregion
13
+
14
+ constructor() {
15
+ super(AssetId.THREE_GLTF_TEMPLATE, {
16
+ castShadow: true,
17
+ receiveShadow: true,
18
+ });
19
+ this.position.copy(TemplateModel._DEFAULT_POSITION);
20
+
21
+ if (DebugManager.IsActive) {
22
+ const templateModelFolder = DebugManager.Gui.addFolder('Template Model');
23
+ templateModelFolder.add(this.position, 'y', -1, 1, 0.01);
24
+ }
25
+ }
26
+
27
+ public update(dt: number): void {
28
+ super.update(dt);
29
+ this.rotation.y += dt * TemplateModel._ROTATION_Y;
30
+ }
31
+ }
@@ -0,0 +1,9 @@
1
+ import { Object3D } from 'three';
2
+
3
+ export default abstract class ActorBase extends Object3D {
4
+ constructor() {
5
+ super();
6
+ }
7
+
8
+ public update(_dt: number): void {}
9
+ }
@@ -0,0 +1,67 @@
1
+ import { AnimationAction, AnimationMixer } from 'three';
2
+ import type { AnimationId } from '../../../../../../constants/experiences/AnimationId';
3
+ import type { AssetId } from '../../../../../../constants/experiences/AssetId';
4
+ import ThreeAssetsManager from '../../../../../../managers/threes/ThreeAssetsManager';
5
+ import ModelBase, { type IModelBaseParams } from './ModelBase';
6
+
7
+ export default abstract class AnimatedModelBase extends ModelBase {
8
+ declare private _mixer: AnimationMixer;
9
+ declare private _actions: AnimationAction[];
10
+ declare private _currentAction: AnimationAction | null;
11
+
12
+ //#region Constants
13
+ //
14
+ private static readonly _DEFAULT_ANIMATION_FADE_DURATION: number = 1;
15
+ //
16
+ //#endregion
17
+
18
+ constructor(assetId: AssetId, params: IModelBaseParams = {}) {
19
+ super(assetId, params);
20
+
21
+ this._generateAnimations();
22
+ }
23
+
24
+ protected _generateAnimations(): void {
25
+ const animations = ThreeAssetsManager.GetModel(this._assetId).animations;
26
+ this._mixer = new AnimationMixer(this._model);
27
+ this._actions = [];
28
+ this._currentAction = null;
29
+
30
+ for (const clip of animations) {
31
+ const action = this._mixer.clipAction(clip);
32
+ this._addAnimationAction(action);
33
+ }
34
+ }
35
+
36
+ private _addAnimationAction(action: AnimationAction): void {
37
+ this._actions.push(action);
38
+ }
39
+
40
+ protected _playAnimation = (
41
+ animationId: AnimationId,
42
+ fadeDuration: number = AnimatedModelBase._DEFAULT_ANIMATION_FADE_DURATION
43
+ ): void => {
44
+ if (!this._actions) return;
45
+ const newAction = this._getAnimationAction(animationId);
46
+ const oldAction = this._currentAction ?? null;
47
+
48
+ newAction.reset();
49
+ newAction.play();
50
+ if (oldAction) newAction.crossFadeFrom(oldAction, fadeDuration);
51
+ this._currentAction = newAction;
52
+ };
53
+
54
+ private _getAnimationAction = (animationId: AnimationId): AnimationAction => {
55
+ for (const action of this._actions) {
56
+ if (action.getClip().name === animationId) {
57
+ return action;
58
+ }
59
+ }
60
+ throw new Error(`Animation action not found for animationId: ${animationId}`);
61
+ };
62
+
63
+ public update(dt: number): void {
64
+ super.update(dt);
65
+ if (this._mixer) this._mixer.update(dt);
66
+ }
67
+ }