@fonsecabarreto/genesis-gl-core 0.1.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.
Files changed (62) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -0
  3. package/dist/Camera-DY_8gx3C.d.ts +45 -0
  4. package/dist/Core/classes/Material.d.ts +3 -0
  5. package/dist/Core/classes/Material.js +9 -0
  6. package/dist/Core/classes/Material.js.map +1 -0
  7. package/dist/Core/classes/Model.d.ts +5 -0
  8. package/dist/Core/classes/Model.js +7 -0
  9. package/dist/Core/classes/Model.js.map +1 -0
  10. package/dist/Core/classes/Renderer.d.ts +30 -0
  11. package/dist/Core/classes/Renderer.js +11 -0
  12. package/dist/Core/classes/Renderer.js.map +1 -0
  13. package/dist/Core/classes/Scene.d.ts +37 -0
  14. package/dist/Core/classes/Scene.js +7 -0
  15. package/dist/Core/classes/Scene.js.map +1 -0
  16. package/dist/Core/classes/Viewport.d.ts +37 -0
  17. package/dist/Core/classes/Viewport.js +7 -0
  18. package/dist/Core/classes/Viewport.js.map +1 -0
  19. package/dist/Core/domain/interfaces/Vectors.d.ts +4 -0
  20. package/dist/Core/domain/interfaces/Vectors.js +1 -0
  21. package/dist/Core/domain/interfaces/Vectors.js.map +1 -0
  22. package/dist/Core/index.d.ts +10 -0
  23. package/dist/Core/index.js +51 -0
  24. package/dist/Core/index.js.map +1 -0
  25. package/dist/Core/utils/get-overlap.d.ts +3 -0
  26. package/dist/Core/utils/get-overlap.js +11 -0
  27. package/dist/Core/utils/get-overlap.js.map +1 -0
  28. package/dist/Core/utils/load-glb.d.ts +101 -0
  29. package/dist/Core/utils/load-glb.js +697 -0
  30. package/dist/Core/utils/load-glb.js.map +1 -0
  31. package/dist/Core/utils/parse-obj.d.ts +10 -0
  32. package/dist/Core/utils/parse-obj.js +183 -0
  33. package/dist/Core/utils/parse-obj.js.map +1 -0
  34. package/dist/Editor/index.d.ts +364 -0
  35. package/dist/Editor/index.js +1737 -0
  36. package/dist/Editor/index.js.map +1 -0
  37. package/dist/Game/controls/KeyboardInput.d.ts +8 -0
  38. package/dist/Game/controls/KeyboardInput.js +7 -0
  39. package/dist/Game/controls/KeyboardInput.js.map +1 -0
  40. package/dist/Game/index.d.ts +45 -0
  41. package/dist/Game/index.js +353 -0
  42. package/dist/Game/index.js.map +1 -0
  43. package/dist/KeyboardControl-5w7Vm0J0.d.ts +18 -0
  44. package/dist/KeyboardInput-DTsfj3tE.d.ts +166 -0
  45. package/dist/Material-BGLkldxv.d.ts +74 -0
  46. package/dist/Model-CQvDXd-b.d.ts +302 -0
  47. package/dist/WebGLCore-DR7ZHJB0.d.ts +22 -0
  48. package/dist/chunk-3ULETMWF.js +144 -0
  49. package/dist/chunk-3ULETMWF.js.map +1 -0
  50. package/dist/chunk-5TAAXI6S.js +330 -0
  51. package/dist/chunk-5TAAXI6S.js.map +1 -0
  52. package/dist/chunk-6LS6AO5H.js +296 -0
  53. package/dist/chunk-6LS6AO5H.js.map +1 -0
  54. package/dist/chunk-JK2HEZAT.js +317 -0
  55. package/dist/chunk-JK2HEZAT.js.map +1 -0
  56. package/dist/chunk-P7QOKDLY.js +57 -0
  57. package/dist/chunk-P7QOKDLY.js.map +1 -0
  58. package/dist/chunk-QCQVJCSR.js +968 -0
  59. package/dist/chunk-QCQVJCSR.js.map +1 -0
  60. package/dist/chunk-SUNYSY45.js +81 -0
  61. package/dist/chunk-SUNYSY45.js.map +1 -0
  62. package/package.json +83 -0
@@ -0,0 +1,364 @@
1
+ import { Vector3 } from '../Core/domain/interfaces/Vectors.js';
2
+
3
+ /** Plain, JSON-serialisable description of a material preset. */
4
+ interface MaterialSpec {
5
+ /** Unique identifier (crypto.randomUUID). */
6
+ id: string;
7
+ /** Human-readable name shown in the UI. */
8
+ name: string;
9
+ /** RGBA albedo / base colour [0–1]. */
10
+ albedoColor: [number, number, number, number];
11
+ /** RGB diffuse colour [0–1]. */
12
+ diffuse: [number, number, number];
13
+ /** RGB ambient colour [0–1]. */
14
+ ambientColor: [number, number, number];
15
+ /** RGB specular colour [0–1]. */
16
+ specular: [number, number, number];
17
+ /** Phong shininess exponent. */
18
+ shininess: number;
19
+ /** Opacity (d / Tr). */
20
+ dissolve: number;
21
+ /** Skip lighting calculations and render with raw albedo. */
22
+ unlit: boolean;
23
+ /** Render both front and back faces. */
24
+ doubleSided: boolean;
25
+ /** Optional public path to a texture image (relative to /public). */
26
+ texturePath?: string;
27
+ /** When true the texture wraps with GL_REPEAT instead of CLAMP_TO_EDGE. */
28
+ textureRepeat?: boolean;
29
+ /** Physics friction coefficient [0–1]. Defaults to 0.75 when omitted. */
30
+ friction?: number;
31
+ }
32
+ /** Create a spec with sensible defaults. */
33
+ declare function createDefaultSpec(name?: string): MaterialSpec;
34
+
35
+ type StoreListener$1 = (specs: MaterialSpec[]) => void;
36
+ interface MaterialStoreOptions {
37
+ /**
38
+ * URL / public-folder path to a JSON file that seeds the store on {@link MaterialStore.init}.
39
+ * Example: `'data/materials.json'`
40
+ *
41
+ * The file is fetched once with `fetch()` during init. If the fetch succeeds its
42
+ * contents supersede anything already in `localStorage`.
43
+ */
44
+ filePath?: string;
45
+ }
46
+ /**
47
+ * Manages a collection of {@link MaterialSpec} presets.
48
+ *
49
+ * - Automatically persists to `localStorage` on every change (synchronous).
50
+ * - Call {@link init} once at startup to seed from a configurable JSON file.
51
+ * - Supports exporting / importing the whole collection as a `.json` file.
52
+ */
53
+ declare class MaterialStore {
54
+ private specs;
55
+ private listeners;
56
+ private readonly filePath;
57
+ constructor(options?: MaterialStoreOptions);
58
+ /**
59
+ * Asynchronously loads materials from the configured {@link MaterialStoreOptions.filePath}.
60
+ * Call this once during app / resource initialisation (e.g. inside `loadResources`).
61
+ *
62
+ * The file data is merged on top of any localStorage data; conflicting IDs are
63
+ * overwritten by the file version.
64
+ */
65
+ init(): Promise<void>;
66
+ getAll(): MaterialSpec[];
67
+ get(id: string): MaterialSpec | undefined;
68
+ /** Add a brand-new spec and return it. */
69
+ create(name?: string): MaterialSpec;
70
+ /** Replace an existing spec (matched by id). */
71
+ update(spec: MaterialSpec): void;
72
+ /** Deep-clone a spec under a new id. */
73
+ duplicate(id: string): MaterialSpec | undefined;
74
+ delete(id: string): void;
75
+ /**
76
+ * Write the full collection to the server's `materials.json` via the
77
+ * `PUT /api/materials` endpoint provided by the Vite dev plugin.
78
+ * Silently no-ops if no `filePath` was configured.
79
+ */
80
+ syncToServer(): Promise<boolean>;
81
+ private persist;
82
+ private loadFromStorage;
83
+ /** Download the full collection as a `.json` file (defaults to the configured filePath name). */
84
+ exportToFile(filename?: string): Promise<void>;
85
+ /**
86
+ * Open a file-picker, parse the JSON, and merge imported specs.
87
+ * Existing specs with the same id are overwritten.
88
+ */
89
+ importFromFile(): Promise<void>;
90
+ subscribe(fn: StoreListener$1): () => void;
91
+ private emit;
92
+ }
93
+
94
+ /** JSON-serialisable description of a single item placed in the scene. */
95
+ interface SceneItemSpec {
96
+ /** Unique identifier (crypto.randomUUID). */
97
+ id: string;
98
+ /** Human-readable label shown in the editor. */
99
+ name: string;
100
+ /**
101
+ * Key used to look up the base model in the DI / resource container.
102
+ * The model must have been loaded during resource initialisation.
103
+ */
104
+ resourceKey: string;
105
+ translation: Vector3;
106
+ rotation: Vector3;
107
+ scale: Vector3;
108
+ /**
109
+ * Custom AABB override relative to translation:
110
+ * `[offsetX, offsetY, offsetZ, width, height, depth]`.
111
+ * When `null` or omitted the model's auto-computed bbox is used.
112
+ */
113
+ bounds?: [number, number, number, number, number, number] | null;
114
+ /** Whether this item participates in collision detection. Defaults to `true`. */
115
+ collider?: boolean;
116
+ /**
117
+ * Optional material name (from `materials.json`) to override the model's
118
+ * default material. Applied to all meshes in the model at placement time.
119
+ */
120
+ materialKey?: string | null;
121
+ }
122
+ /** Top-level scene definition stored in `scene.json`. */
123
+ interface SceneSpec {
124
+ /** World position where the player spawns. */
125
+ playerSpawn: Vector3;
126
+ /** All placed models in the scene. */
127
+ items: SceneItemSpec[];
128
+ }
129
+ /** Create a new scene item with sensible defaults. */
130
+ declare function createDefaultSceneItem(name?: string, resourceKey?: string): SceneItemSpec;
131
+ /** Create an empty scene. */
132
+ declare function createDefaultScene(): SceneSpec;
133
+
134
+ type StoreListener = (spec: SceneSpec) => void;
135
+ interface SceneStoreOptions {
136
+ /**
137
+ * URL / public-folder path to a JSON file that seeds the store on {@link SceneStore.init}.
138
+ * Example: `'data/scene.json'`
139
+ */
140
+ filePath?: string;
141
+ }
142
+ /**
143
+ * Manages the current scene definition ({@link SceneSpec}).
144
+ *
145
+ * Follows the same patterns as `MaterialStore`:
146
+ * - Persists to `localStorage` on every change.
147
+ * - Call {@link init} once at startup to load from a JSON file.
148
+ * - Syncs back to the server via a PUT endpoint (Vite dev plugin).
149
+ */
150
+ declare class SceneStore {
151
+ private scene;
152
+ private listeners;
153
+ private readonly filePath;
154
+ constructor(options?: SceneStoreOptions);
155
+ init(): Promise<void>;
156
+ get(): SceneSpec;
157
+ getItems(): SceneItemSpec[];
158
+ getItem(id: string): SceneItemSpec | undefined;
159
+ getPlayerSpawn(): [number, number, number];
160
+ setPlayerSpawn(x: number, y: number, z: number): void;
161
+ addItem(item: SceneItemSpec): void;
162
+ updateItem(item: SceneItemSpec): void;
163
+ deleteItem(id: string): void;
164
+ /** Replace the entire scene definition. */
165
+ setScene(spec: SceneSpec): void;
166
+ syncToServer(): Promise<boolean>;
167
+ private persist;
168
+ private loadFromStorage;
169
+ exportToFile(filename?: string): Promise<void>;
170
+ importFromFile(): Promise<void>;
171
+ subscribe(fn: StoreListener): () => void;
172
+ private emit;
173
+ }
174
+
175
+ interface EditorTab {
176
+ id: string;
177
+ /** Label shown on the tab button. */
178
+ label: string;
179
+ /** Called once to populate the tab's content container. */
180
+ buildContent: (container: HTMLElement) => void;
181
+ /** Called each time the tab becomes the active, visible tab. */
182
+ onActivate?: () => void;
183
+ /** Called each time the tab is hidden (tab switch or sidebar hide). */
184
+ onDeactivate?: () => void;
185
+ /** Optional cleanup called when the sidebar is unmounted. */
186
+ destroy?: () => void;
187
+ }
188
+ /**
189
+ * Fixed right-side editor sidebar.
190
+ *
191
+ * - Hosts a tab strip so new features can be added via {@link addTab}.
192
+ * - First tab is the Material Editor (colour preview swatches + full form).
193
+ * - Every store mutation auto-syncs to `materials.json` via the Vite dev plugin.
194
+ * - "🔄 Reload Game" triggers `location.reload()` to pick up JSON changes.
195
+ */
196
+ declare class EditorSidebar {
197
+ private readonly store;
198
+ private root;
199
+ private tabBar;
200
+ private contentArea;
201
+ private tabs;
202
+ private activeTabId;
203
+ private listEl;
204
+ private formEl;
205
+ private selectedId;
206
+ private unsubMaterials?;
207
+ private _sidebarWidth;
208
+ private _dragging;
209
+ private _layoutMode;
210
+ private _layoutBtn;
211
+ private constructor();
212
+ static mount(store: MaterialStore): EditorSidebar;
213
+ show(): void;
214
+ hide(): void;
215
+ toggle(): void;
216
+ get isVisible(): boolean;
217
+ /** Register an extra tab. */
218
+ addTab(tab: EditorTab): void;
219
+ unmount(): void;
220
+ private build;
221
+ private toggleLayout;
222
+ private applyLayout;
223
+ private renderTabBar;
224
+ /** Activate a tab by id. Safe to call from outside (e.g. TopBar button). */
225
+ activateTab(id: string): void;
226
+ private buildMaterialsContent;
227
+ private refreshList;
228
+ private select;
229
+ private buildForm;
230
+ private onNew;
231
+ private onDuplicate;
232
+ private onDelete;
233
+ private mkBtn;
234
+ }
235
+
236
+ /** Entry from models.json */
237
+ interface ModelRegistryEntry {
238
+ key: string;
239
+ name: string;
240
+ type: string;
241
+ path?: string;
242
+ description?: string;
243
+ }
244
+ interface SceneSectionOptions {
245
+ /** URL to the models registry JSON file. */
246
+ modelsFile?: string;
247
+ /** Returns the list of material names currently available. */
248
+ getMaterialNames?: () => string[];
249
+ /** Renderer reference — used to toggle hitbox debug visualisation. */
250
+ renderer?: {
251
+ debug: boolean;
252
+ };
253
+ }
254
+ /**
255
+ * Scene Editor — rendered as a tab inside the {@link EditorSidebar}.
256
+ *
257
+ * Lets the user:
258
+ * – View / edit player spawn position.
259
+ * – View / edit every scene item (translation, rotation, scale, bounds, collider).
260
+ * – Add, duplicate, and delete items.
261
+ * – Reload the game to apply changes.
262
+ */
263
+ declare class SceneSection {
264
+ private readonly store;
265
+ private root;
266
+ private listEl;
267
+ private selectedId;
268
+ private formEl;
269
+ private unsub?;
270
+ private modelRegistry;
271
+ private readonly getMaterialNames;
272
+ private readonly modelsFile;
273
+ private readonly renderer;
274
+ private hitboxCheck;
275
+ private constructor();
276
+ static create(store: SceneStore, options?: SceneSectionOptions): SceneSection;
277
+ asTab(): EditorTab;
278
+ private onActivate;
279
+ private onDeactivate;
280
+ private buildContent;
281
+ private refreshList;
282
+ private refreshForm;
283
+ private buildSpawnForm;
284
+ private buildItemForm;
285
+ private onAdd;
286
+ private onDuplicate;
287
+ private onDelete;
288
+ private vec3Row;
289
+ private textRow;
290
+ private selectRow;
291
+ private checkRow;
292
+ private mkBtn;
293
+ }
294
+
295
+ /** Minimal sidebar interface used by TopBar for tab-aware buttons. */
296
+ interface ISidebar {
297
+ show(): void;
298
+ toggle(): void;
299
+ activateTab(id: string): void;
300
+ readonly isVisible: boolean;
301
+ }
302
+ /**
303
+ * Slim top bar pinned at the top of the viewport.
304
+ * Houses engine tool buttons (e.g. Material Editor toggle).
305
+ */
306
+ declare class TopBar {
307
+ private root;
308
+ private constructor();
309
+ static mount(materialPanel: ISidebar): TopBar;
310
+ unmount(): void;
311
+ private build;
312
+ /** Add the Models tab button after the game has started. */
313
+ addModelsButton(sidebar: ISidebar): void;
314
+ /** Add the Scene tab button after the game has started. */
315
+ addSceneButton(sidebar: ISidebar): void;
316
+ private mkToggleBtn;
317
+ private mkPanelToggleBtn;
318
+ }
319
+
320
+ /** Minimal interface: only the debug flag we need. */
321
+ interface IRenderer {
322
+ debug: boolean;
323
+ }
324
+ /** Bounding box as stored on Model. */
325
+ interface AABB {
326
+ min: [number, number, number];
327
+ max: [number, number, number];
328
+ }
329
+ /** Minimal model shape required by the inspector. */
330
+ interface IModel {
331
+ translation: [number, number, number];
332
+ rotation: [number, number, number];
333
+ scale: [number, number, number];
334
+ boundingBox: AABB;
335
+ }
336
+ /** Minimal scene interface: just the keyed entry list. */
337
+ interface IScene {
338
+ getEntries(): [string, IModel][];
339
+ }
340
+ /**
341
+ * Model Inspector — rendered as a tab inside the {@link EditorSidebar}.
342
+ *
343
+ * Lifecycle:
344
+ * – `buildContent(container)` builds the DOM once when the tab is activated.
345
+ * – `onActivate()` enables `renderer.debug` and starts a 200 ms refresh loop.
346
+ * – `onDeactivate()` disables `renderer.debug` and stops the refresh loop.
347
+ * – `asTab()` returns an {@link EditorTab} descriptor ready for `sidebar.addTab()`.
348
+ */
349
+ declare class ModelsSection {
350
+ private readonly renderer;
351
+ private readonly scene;
352
+ private listEl;
353
+ private hitboxCheck;
354
+ private intervalId;
355
+ private constructor();
356
+ static create(renderer: IRenderer, scene: IScene): ModelsSection;
357
+ asTab(): EditorTab;
358
+ private start;
359
+ private stop;
360
+ private buildContent;
361
+ private refresh;
362
+ }
363
+
364
+ export { EditorSidebar, type EditorTab, type MaterialSpec, MaterialStore, type MaterialStoreOptions, type ModelRegistryEntry, ModelsSection, type SceneItemSpec, SceneSection, type SceneSectionOptions, type SceneSpec, SceneStore, type SceneStoreOptions, TopBar, createDefaultScene, createDefaultSceneItem, createDefaultSpec };