@benjos/create-boilerplate 1.4.1 → 1.5.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.
Files changed (46) hide show
  1. package/README.md +6 -5
  2. package/dist/index.js +2 -2
  3. package/dist/index.js.map +1 -1
  4. package/package.json +1 -1
  5. package/template-react/package-lock.json +3 -18
  6. package/template-react/package.json +1 -1
  7. package/template-vanilla/eslint.config.js +5 -11
  8. package/template-vanilla/index.html +18 -20
  9. package/template-vanilla/package-lock.json +3 -13
  10. package/template-vanilla/package.json +1 -1
  11. package/template-vanilla/readme.md +12 -9
  12. package/template-vanilla/src/experiences/Experience.ts +10 -3
  13. package/template-vanilla/src/experiences/commands/InitCommand.ts +4 -4
  14. package/template-vanilla/src/experiences/constants/experiences/DebugGuiTitle.ts +6 -0
  15. package/template-vanilla/src/experiences/constants/experiences/ViewId.ts +2 -1
  16. package/template-vanilla/src/experiences/engines/threes/MainThree.ts +2 -2
  17. package/template-vanilla/src/experiences/engines/threes/app/LoaderThreeApp.ts +13 -3
  18. package/template-vanilla/src/experiences/engines/threes/app/MainThreeApp.ts +18 -5
  19. package/template-vanilla/src/experiences/engines/threes/app/bases/ThreeAppBase.ts +43 -7
  20. package/template-vanilla/src/experiences/managers/DebugManager.ts +11 -0
  21. package/template-vanilla/src/experiences/managers/LoaderManager.ts +97 -7
  22. package/template-vanilla/src/experiences/materials/threes/loaders/LoaderMaterial.ts +4 -4
  23. package/template-vanilla/src/experiences/renderers/threes/LoaderRenderer.ts +2 -2
  24. package/template-vanilla/src/experiences/renderers/threes/Renderer.ts +2 -1
  25. package/template-vanilla/src/experiences/shaders/threes/loaders/LoaderFragmentShader.glsl +2 -0
  26. package/template-vanilla/src/experiences/styles/commons/main.scss +5 -30
  27. package/template-vanilla/src/experiences/styles/style.scss +1 -1
  28. package/template-vanilla/src/experiences/styles/views/loader.scss +1 -4
  29. package/template-vanilla/src/experiences/types/global.d.ts +1 -2
  30. package/template-vanilla/src/experiences/views/htmls/bases/HTMLViewBase.ts +0 -3
  31. package/template-vanilla/src/experiences/views/htmls/loaders/LoaderHTMLView.ts +7 -8
  32. package/template-vanilla/src/experiences/views/threes/bases/ThreeViewBase.ts +20 -6
  33. package/template-vanilla/src/experiences/views/threes/loaders/LoaderThreeView.ts +9 -19
  34. package/template-vanilla/src/experiences/views/threes/loaders/components/{ThreeTemplateLoader.ts → TemplateLoaderThreeActor.ts} +6 -12
  35. package/template-vanilla/src/experiences/views/threes/worlds/World2ThreeView.ts +35 -0
  36. package/template-vanilla/src/experiences/views/threes/worlds/WorldThreeView.ts +12 -20
  37. package/template-vanilla/src/experiences/views/threes/worlds/components/Environment.ts +20 -4
  38. package/template-vanilla/src/experiences/views/threes/worlds/components/actors/TemplateFont.ts +2 -8
  39. package/template-vanilla/src/experiences/views/threes/worlds/components/actors/TemplateMesh.ts +4 -6
  40. package/template-vanilla/src/experiences/views/threes/worlds/components/actors/TemplateMesh2.ts +71 -0
  41. package/template-vanilla/src/experiences/views/threes/worlds/components/actors/TemplateModel.ts +9 -3
  42. package/template-vanilla/src/experiences/views/threes/worlds/components/actors/bases/ThreeActorBase.ts +44 -0
  43. package/template-vanilla/src/experiences/views/threes/worlds/components/actors/bases/{AnimatedModelBase.ts → ThreeAnimatedModelBase.ts} +3 -3
  44. package/template-vanilla/src/experiences/views/threes/worlds/components/actors/bases/{ModelBase.ts → ThreeModelBase.ts} +2 -16
  45. package/template-vanilla/tsconfig.json +3 -8
  46. package/template-vanilla/src/experiences/views/threes/worlds/components/actors/bases/ActorBase.ts +0 -21
@@ -1,4 +1,7 @@
1
- import LoaderManager from '../../../managers/LoaderManager';
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, Object3D, Vector3 } from 'three';
1
+ import { DataTexture, DirectionalLight, Vector3 } from 'three';
2
2
  import { AssetId } from '../../../../constants/experiences/AssetId';
3
+ import { DebugGuiTitle } from '../../../../constants/experiences/DebugGuiTitle';
3
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 Object3D {
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,6 +30,18 @@ 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;
@@ -38,7 +52,8 @@ export default class Environment extends Object3D {
38
52
  MainThreeApp.scene.environmentIntensity = this._environmentMap.intensity!;
39
53
 
40
54
  if (DebugManager.isActive) {
41
- const environmentFolder = DebugManager.gui.addFolder('Environment');
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
  });
@@ -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 sunLightFolder = DebugManager.gui.addFolder('Sun Light');
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');
@@ -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 ActorBase from './bases/ActorBase';
5
+ import ThreeActorBase from './bases/ThreeActorBase';
6
6
 
7
- export default class TemplateFont extends ActorBase {
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
  }
@@ -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 ActorBase from './bases/ActorBase';
4
+ import ThreeActorBase from './bases/ThreeActorBase';
5
5
 
6
- export default class TemplateMesh extends ActorBase {
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 dispose(): void {
58
- super.dispose();
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 {
@@ -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
+ }
@@ -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 ModelBase from './bases/ModelBase';
5
+ import ThreeModelBase from './bases/ThreeModelBase';
5
6
 
6
- export default class TemplateModel extends ModelBase {
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 templateModelFolder = DebugManager.gui.addFolder('Template Model');
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 ModelBase, { type ModelBaseParams } from './ModelBase';
5
+ import ThreeModelBase, { type ModelBaseParams } from './ThreeModelBase';
6
6
 
7
- export default abstract class AnimatedModelBase extends ModelBase {
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 = AnimatedModelBase._DEFAULT_ANIMATION_FADE_DURATION
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 ActorBase from './ActorBase';
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 ModelBase extends ActorBase {
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
  }
@@ -4,14 +4,9 @@
4
4
  "module": "ESNext",
5
5
  "moduleResolution": "Node",
6
6
  "strict": true,
7
- "lib": [
8
- "DOM",
9
- "ES2020"
10
- ],
7
+ "lib": ["DOM", "ES2020"],
11
8
  "skipLibCheck": true,
12
9
  "noEmit": true
13
10
  },
14
- "include": [
15
- "src"
16
- ]
17
- }
11
+ "include": ["src"]
12
+ }
@@ -1,21 +0,0 @@
1
- import { Object3D } from 'three';
2
-
3
- export default abstract class ActorBase 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
- //
18
- }
19
-
20
- public update(_dt: number): void { }
21
- }