Skip to content

Commit

Permalink
refactor: app structure reorder + assets optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
Neosoulink committed Jan 2, 2024
1 parent 0f008e0 commit 4ad631e
Show file tree
Hide file tree
Showing 83 changed files with 458 additions and 688 deletions.
14 changes: 9 additions & 5 deletions nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import glslify from "vite-plugin-glslify";
export default defineNuxtConfig({
devtools: { enabled: true },
alias: {
"@exp-factories/*": "../src/experiences/factories/*",
"@exp-errors/*": "../src/experiences/errors/*",
"@exp-pages/*": "../src/experiences/pages/*",
"@interfaces/*": "../src/interfaces/*",
"@constants/*": "../src/constants/*",
"~blueprints/*": "../src/blueprints/*",
"~config": "../src/config",
"~config/*": "../src/config/*",
"~experiences/*": "../src/experiences/*",
"~errors": "../src/errors",
"~errors/*": "../src/errors/*",
"~common/*": "../src/common/*",
"~static": "../src/static",
"~static/*": "../src/static/*",
},
app: {
head: {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/models/scene_1/model.glb
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/models/scene_1/tree_baked_texture.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/models/scene_2/baked_texture.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
Binary file added src/assets/models/scene_3/baked_texture.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/models/scene_3/model.glb
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
Binary file added src/assets/textures/cloudAlphaMap.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/textures/rocksAlphaMap.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { EventEmitter } from "events";
// BLUEPRINTS
import type { ExperienceBlueprint } from "./experience.blueprint";

// INTERFACES
import type { ExperienceBase } from "~/interfaces/experienceBase";
// MODELS
import type { Experience } from "~/common/experiences/experience.model";

/** Represent a class that depend on {@link ExperienceBlueprint}. */
export abstract class ExperienceBasedBlueprint
extends EventEmitter
implements ExperienceBase
implements Experience
{
protected abstract readonly _experience: ExperienceBlueprint;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import QuickThree from "quick-threejs";

// INTERFACES
import type { ExperienceBase } from "@/interfaces/experienceBase";
// MODELS
import type {
Experience,
ExperienceConstructorProps,
} from "~/common/experiences/experience.model";

export interface ExperienceProps {
/** String dom element reference of the canvas. */
domElementRef?: string;
/* Start the project in debug mode */
debug?: boolean;
/** Event triggered when the scene is constructed. */
onConstruct?: () => unknown;
/** Event triggered when the scene is destructed. */
onDestruct?: () => unknown;
}

export abstract class ExperienceBlueprint implements ExperienceBase {
export abstract class ExperienceBlueprint implements Experience {
/**
* Self class reference. Used for *singleton* pattern.
*
Expand All @@ -26,7 +18,7 @@ export abstract class ExperienceBlueprint implements ExperienceBase {
/** [`quick-threejs`](https://www.npmjs.com/package/quick-threejs) instance. */
readonly app!: QuickThree;
/** To make the singleton logic, refer to the {@link ExperienceBlueprint._self `#_self`} declaration */
constructor(_?: ExperienceProps | ExperienceBlueprint) {
constructor(_?: ExperienceConstructorProps | ExperienceBlueprint) {
if (!(_ instanceof ExperienceBlueprint) && _) {
this.app = new QuickThree(
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ import type { GLTF } from "three/examples/jsm/loaders/GLTFLoader";
import { ExperienceBasedBlueprint } from "./experience-based.blueprint";

// EXPERIENCES
import { HomeExperience } from "~/experiences/core/home";
import { HomeExperience } from "~/experiences/home";

// MODELS
import { CONSTRUCTED, DESTRUCTED, LOADED } from "~/common/event.model";
import { WRONG_PARAM } from "~/common/error.model";
// STATIC
import { errors, events } from "~/static";

// ERRORS
import { ErrorFactory } from "../errors/error.factory";
import { ErrorFactory } from "~/errors";

// INTERFACES
// MODELS
import type {
Materials,
ModelChildrenMaterials,
} from "~/interfaces/experienceWorld";
} from "~/common/experiences/experience-world.model";

// TODO: Link with the names of assets in the `app.loader` assets names
export interface SceneBlueprintProps {
Expand Down Expand Up @@ -50,7 +49,7 @@ export abstract class SceneComponentBlueprint extends ExperienceBasedBlueprint {

this._childrenMaterials = _.childrenMaterials;

this._experience.loader?.on(LOADED, () => {
this._experience.loader?.on(events.LOADED, () => {
const _MODEL = this._experience.app.resources.items[_.modelName] as
| GLTF
| undefined;
Expand Down Expand Up @@ -108,7 +107,7 @@ export abstract class SceneComponentBlueprint extends ExperienceBasedBlueprint {

if (!this.modelScene)
throw new ErrorFactory(
new Error("No model scene founded", { cause: WRONG_PARAM })
new Error("No model scene founded", { cause: errors.WRONG_PARAM })
);

if (typeof callback === "function") callback();
Expand All @@ -118,13 +117,13 @@ export abstract class SceneComponentBlueprint extends ExperienceBasedBlueprint {
...this._getAvailableMaterials(),
};
this._initModelMaterials();
this.emit(CONSTRUCTED);
this.emit(events.CONSTRUCTED);
}

public destruct() {
this.modelScene?.clear();
this.modelScene?.removeFromParent();
this.emit(DESTRUCTED);
this.emit(events.DESTRUCTED);
}

public intro(): void {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CatmullRomCurve3, Material, Vector3 } from "three";
import { Material } from "three";

export type MaterialName = string;

Expand All @@ -9,9 +9,3 @@ export interface Materials {
export interface ModelChildrenMaterials {
[childName: string]: MaterialName;
}

export interface SceneConfig {
position: Vector3;
center: Vector3;
cameraPath: CatmullRomCurve3;
}
17 changes: 17 additions & 0 deletions src/common/experiences/experience.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/** Represent the base structure of all experience classes in the application. */
export interface Experience {
construct: (callback?: () => unknown) => unknown;
destruct: (callback?: () => unknown) => unknown;
update?: (callback?: () => unknown) => unknown;
}

export interface ExperienceConstructorProps {
/** String dom element reference of the canvas. */
domElementRef?: string;
/* Start the project in debug mode */
debug?: boolean;
/** Event triggered when the scene is constructed. */
onConstruct?: () => unknown;
/** Event triggered when the scene is destructed. */
onDestruct?: () => unknown;
}
File renamed without changes.
2 changes: 1 addition & 1 deletion src/experiences/config/index.ts → src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CommonConfig } from "./common.config";

export class Config extends CommonConfig {
protected static _supportsPassive = false;
private static _supportsPassive = false;

static set supportsPassive(val: boolean) {
Config._supportsPassive = !!val;
Expand Down
1 change: 0 additions & 1 deletion src/constants/UI.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UnknownError } from "./unknown-error";
import { UnknownError } from "./unknown.error";

export class ErrorFactory {
constructor(_: any) {
Expand Down
File renamed without changes.
109 changes: 0 additions & 109 deletions src/experiences/core/home/ui.ts

This file was deleted.

Loading

0 comments on commit 4ad631e

Please sign in to comment.