@fonsecabarreto/genesis-gl-core 0.1.0 → 0.1.2
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/README.md +19 -2
- package/dist/{Camera-DY_8gx3C.d.ts → Camera-CJVYy9fH.d.ts} +13 -2
- package/dist/Core/classes/Material.d.ts +1 -1
- package/dist/Core/classes/Material.js +1 -1
- package/dist/Core/classes/Model.d.ts +3 -3
- package/dist/Core/classes/Model.js +1 -1
- package/dist/Core/classes/Renderer.d.ts +11 -5
- package/dist/Core/classes/Renderer.js +4 -4
- package/dist/Core/classes/Scene.d.ts +2 -2
- package/dist/Core/classes/Viewport.d.ts +1 -1
- package/dist/Core/classes/Viewport.js +1 -1
- package/dist/Core/index.d.ts +4 -4
- package/dist/Core/index.js +4 -4
- package/dist/Core/utils/load-glb.d.ts +3 -3
- package/dist/Core/utils/load-glb.js +4 -4
- package/dist/Core/utils/parse-obj.d.ts +2 -2
- package/dist/Core/utils/parse-obj.js +4 -4
- package/dist/Editor/index.d.ts +126 -15
- package/dist/Editor/index.js +471 -74
- package/dist/Editor/index.js.map +1 -1
- package/dist/Game/controls/KeyboardInput.d.ts +4 -4
- package/dist/Game/index.d.ts +308 -7
- package/dist/Game/index.js +470 -24
- package/dist/Game/index.js.map +1 -1
- package/dist/{KeyboardInput-DTsfj3tE.d.ts → KeyboardInput-1xOAabI0.d.ts} +95 -14
- package/dist/{Material-BGLkldxv.d.ts → Material-DhwSRbP2.d.ts} +8 -0
- package/dist/{Model-CQvDXd-b.d.ts → Model-BBZHnUp1.d.ts} +24 -8
- package/dist/{chunk-6LS6AO5H.js → chunk-L66K4AZU.js} +36 -30
- package/dist/chunk-L66K4AZU.js.map +1 -0
- package/dist/{chunk-JK2HEZAT.js → chunk-QOAQVTAB.js} +26 -22
- package/dist/chunk-QOAQVTAB.js.map +1 -0
- package/dist/{chunk-5TAAXI6S.js → chunk-XMW2MS66.js} +39 -16
- package/dist/chunk-XMW2MS66.js.map +1 -0
- package/dist/{chunk-QCQVJCSR.js → chunk-ZCJ3MJZD.js} +103 -67
- package/dist/chunk-ZCJ3MJZD.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-5TAAXI6S.js.map +0 -1
- package/dist/chunk-6LS6AO5H.js.map +0 -1
- package/dist/chunk-JK2HEZAT.js.map +0 -1
- package/dist/chunk-QCQVJCSR.js.map +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import '../../Camera-
|
|
1
|
+
import '../../Camera-CJVYy9fH.js';
|
|
2
2
|
import '../../KeyboardControl-5w7Vm0J0.js';
|
|
3
|
-
export { K as KeyboardInput } from '../../KeyboardInput-
|
|
3
|
+
export { K as KeyboardInput } from '../../KeyboardInput-1xOAabI0.js';
|
|
4
4
|
import 'gl-matrix';
|
|
5
5
|
import '../../Core/domain/interfaces/Vectors.js';
|
|
6
|
-
import '../../Model-
|
|
6
|
+
import '../../Model-BBZHnUp1.js';
|
|
7
7
|
import '../../WebGLCore-DR7ZHJB0.js';
|
|
8
|
-
import '../../Material-
|
|
8
|
+
import '../../Material-DhwSRbP2.js';
|
package/dist/Game/index.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import '../
|
|
1
|
+
import { P as PhysicsBody } from '../KeyboardInput-1xOAabI0.js';
|
|
2
|
+
export { A as AnimationController, a as AnimationState, b as AnimationTransition, C as Character, K as KeyboardInput, T as TransitionCondition } from '../KeyboardInput-1xOAabI0.js';
|
|
3
|
+
import { g as Mesh, i as Model, S as Skeleton } from '../Model-BBZHnUp1.js';
|
|
4
|
+
import { b as Material } from '../Material-DhwSRbP2.js';
|
|
5
|
+
import { Vector3 } from '../Core/domain/interfaces/Vectors.js';
|
|
6
|
+
import { W as WebGLCore } from '../WebGLCore-DR7ZHJB0.js';
|
|
7
|
+
import { Scene } from '../Core/classes/Scene.js';
|
|
8
|
+
import { Viewport } from '../Core/classes/Viewport.js';
|
|
9
|
+
import { Renderer } from '../Core/classes/Renderer.js';
|
|
10
|
+
import '../Camera-CJVYy9fH.js';
|
|
5
11
|
import 'gl-matrix';
|
|
6
|
-
import '../Core/domain/interfaces/Vectors.js';
|
|
7
12
|
import '../KeyboardControl-5w7Vm0J0.js';
|
|
8
|
-
import '../WebGLCore-DR7ZHJB0.js';
|
|
9
13
|
|
|
10
14
|
declare class Arm extends Mesh {
|
|
11
15
|
private swingPhase;
|
|
@@ -42,4 +46,301 @@ declare class Leg extends Mesh {
|
|
|
42
46
|
animate(moving: boolean, deltaTime: number): number;
|
|
43
47
|
}
|
|
44
48
|
|
|
45
|
-
|
|
49
|
+
/**
|
|
50
|
+
* Actor — a static, non-physics scene entity.
|
|
51
|
+
*
|
|
52
|
+
* Sits directly on top of {@link Model} and represents any object that is
|
|
53
|
+
* placed in the world but **does not move** (environment props, decorations,
|
|
54
|
+
* landmarks, triggers, etc.).
|
|
55
|
+
*
|
|
56
|
+
* Use {@link InteractiveActor} when the object should react to collisions
|
|
57
|
+
* and participate in the physics simulation loop.
|
|
58
|
+
*
|
|
59
|
+
* ## Layer contract
|
|
60
|
+
* ```
|
|
61
|
+
* Model → transform, AABB, render, skeletal animation
|
|
62
|
+
* └─ Actor → static scene entity (no physics)
|
|
63
|
+
* └─ PhysicsBody → + velocity, gravity, ground detection, friction
|
|
64
|
+
* └─ Character → + input, animation FSM, jump/roll, stamina
|
|
65
|
+
* └─ InteractiveActor → + bounce, rolling friction, impulse exchange
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* ## Usage
|
|
69
|
+
* ```ts
|
|
70
|
+
* const prop = new Actor(myModel.meshes, [10, 0, 5], [1, 1, 1], 'lamp_post');
|
|
71
|
+
* prop.collidable = false; // decorative — skip collision
|
|
72
|
+
* scene.add('lamp_0', prop);
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
declare class Actor extends Model {
|
|
76
|
+
constructor(meshes: Mesh[], translation?: Vector3, scale?: Vector3, name?: string, skeleton?: Skeleton | null);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* InteractiveActor — a physics-simulated scene object.
|
|
81
|
+
*
|
|
82
|
+
* Extends {@link PhysicsBody} with:
|
|
83
|
+
* - Bounce behaviour via {@link restitution}.
|
|
84
|
+
* - Horizontal friction via the inherited {@link surfaceFriction}.
|
|
85
|
+
* - An override of {@link resolveYCollision} that applies a bounce impulse.
|
|
86
|
+
* - An override of {@link update} that integrates velocity and applies friction.
|
|
87
|
+
*
|
|
88
|
+
* The constructor accepts any set of {@link Mesh}es so any model can behave
|
|
89
|
+
* as a physics-interactive object. Use the static factory {@link sphere} when
|
|
90
|
+
* you specifically want a procedural sphere shape.
|
|
91
|
+
*
|
|
92
|
+
* ## Usage — custom mesh
|
|
93
|
+
* ```ts
|
|
94
|
+
* const actor = new InteractiveActor(myModel.meshes, [0, 5, 0], 'crate');
|
|
95
|
+
* actor.restitution = 0.2;
|
|
96
|
+
* game.addPhysicsObject('crate_1', actor);
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* ## Usage — sphere shorthand
|
|
100
|
+
* ```ts
|
|
101
|
+
* const ball = InteractiveActor.sphere(webglCore, mat, 0.5, [0, 5, 0]);
|
|
102
|
+
* game.addPhysicsObject('ball_1', ball);
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
declare class InteractiveActor extends PhysicsBody {
|
|
106
|
+
/**
|
|
107
|
+
* Minimum impact speed (|vy|) required to trigger a visible bounce.
|
|
108
|
+
* Below this threshold the actor comes to rest instead of micro-bouncing.
|
|
109
|
+
* Default: `0.05`.
|
|
110
|
+
*/
|
|
111
|
+
minBounceSpeed: number;
|
|
112
|
+
constructor(meshes: Mesh[], position?: Vector3, name?: string);
|
|
113
|
+
/**
|
|
114
|
+
* Create an {@link InteractiveActor} with a procedurally generated sphere
|
|
115
|
+
* mesh — convenience shorthand for the common "physics ball" use case.
|
|
116
|
+
*
|
|
117
|
+
* @param webglCore WebGL context used to build the mesh buffers.
|
|
118
|
+
* @param material Material applied to the sphere.
|
|
119
|
+
* @param radius Sphere radius in world units. Default `0.5`.
|
|
120
|
+
* @param position Initial world position. Default origin.
|
|
121
|
+
* @param latBands Latitude subdivisions. Default `16`.
|
|
122
|
+
* @param lonBands Longitude subdivisions. Default `16`.
|
|
123
|
+
*/
|
|
124
|
+
static sphere(webglCore: WebGLCore, material: Material, radius?: number, position?: Vector3, latBands?: number, lonBands?: number): InteractiveActor;
|
|
125
|
+
/**
|
|
126
|
+
* Apply a bounce impulse instead of zeroing Y velocity.
|
|
127
|
+
* The collision system passes the velocity captured just before impact so
|
|
128
|
+
* the correct outgoing speed can be computed from {@link restitution}.
|
|
129
|
+
*/
|
|
130
|
+
resolveYCollision(impactVy: number): void;
|
|
131
|
+
/**
|
|
132
|
+
* Advance one physics tick: integrate velocity, apply friction, zero
|
|
133
|
+
* sub-threshold components so the actor eventually comes to rest.
|
|
134
|
+
*/
|
|
135
|
+
update(deltaTime: number): void;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* GameLoopRunner
|
|
140
|
+
*
|
|
141
|
+
* Encapsulates a fixed-timestep game loop built on `requestAnimationFrame`.
|
|
142
|
+
*
|
|
143
|
+
* Responsibilities:
|
|
144
|
+
* - Accumulate real elapsed time and fire a fixed-update callback at a
|
|
145
|
+
* constant rate (e.g. 60 Hz physics / logic ticks).
|
|
146
|
+
* - Fire a variable-rate render callback once per animation frame.
|
|
147
|
+
* - Expose start / stop / dispose controls.
|
|
148
|
+
*
|
|
149
|
+
* Design note: this class has no knowledge of scene, renderer, or any game
|
|
150
|
+
* object — it is a pure scheduling primitive consumed by `GameApplication`.
|
|
151
|
+
*/
|
|
152
|
+
declare class GameLoopRunner {
|
|
153
|
+
readonly targetFPS: number;
|
|
154
|
+
/** Number of milliseconds between each fixed-update tick. */
|
|
155
|
+
private readonly stepMs;
|
|
156
|
+
private rafHandle;
|
|
157
|
+
private lastTime;
|
|
158
|
+
private accumulated;
|
|
159
|
+
private fixedUpdateFn;
|
|
160
|
+
private renderFn;
|
|
161
|
+
/**
|
|
162
|
+
* @param targetFPS Number of fixed-update ticks per second. Defaults to 60.
|
|
163
|
+
*/
|
|
164
|
+
constructor(targetFPS?: number);
|
|
165
|
+
/**
|
|
166
|
+
* Begin the loop.
|
|
167
|
+
*
|
|
168
|
+
* @param fixedUpdate Called at the fixed timestep rate with `dt` in seconds.
|
|
169
|
+
* @param render Called once per animation frame (variable rate).
|
|
170
|
+
*/
|
|
171
|
+
start(fixedUpdate: (dt: number) => void, render: () => void): void;
|
|
172
|
+
/** Pause the loop without discarding callbacks. Resume with `resume()`. */
|
|
173
|
+
pause(): void;
|
|
174
|
+
/** Resume a paused loop. */
|
|
175
|
+
resume(): void;
|
|
176
|
+
/** Stop the loop and release all callbacks. */
|
|
177
|
+
stop(): void;
|
|
178
|
+
get isRunning(): boolean;
|
|
179
|
+
/** Arrow function to preserve `this` across rAF callbacks. */
|
|
180
|
+
private readonly tick;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Bootstrap configuration passed to `GameApplication`.
|
|
185
|
+
*
|
|
186
|
+
* All fields except `canvasId` are optional and fall back to sensible defaults.
|
|
187
|
+
*/
|
|
188
|
+
interface GameApplicationConfig {
|
|
189
|
+
/** ID of the `<canvas>` element that WebGL will render into. */
|
|
190
|
+
canvasId: string;
|
|
191
|
+
/** Logical render width in pixels. Default: `1280`. */
|
|
192
|
+
viewportWidth?: number;
|
|
193
|
+
/** Logical render height in pixels. Default: `720`. */
|
|
194
|
+
viewportHeight?: number;
|
|
195
|
+
/**
|
|
196
|
+
* Number of fixed-update ticks per second.
|
|
197
|
+
* Physics, input and game-logic run at this rate. Default: `60`.
|
|
198
|
+
*/
|
|
199
|
+
targetFPS?: number;
|
|
200
|
+
}
|
|
201
|
+
type ResolvedConfig = Required<GameApplicationConfig>;
|
|
202
|
+
/**
|
|
203
|
+
* GameApplication — abstract base class for GenesisGL games.
|
|
204
|
+
*
|
|
205
|
+
* ## Design: Template Method pattern
|
|
206
|
+
*
|
|
207
|
+
* This class provides the **invariant algorithm skeleton** for a GenesisGL
|
|
208
|
+
* application. Subclasses supply the variant behaviour by overriding the
|
|
209
|
+
* hook methods listed below.
|
|
210
|
+
*
|
|
211
|
+
* ### Lifecycle
|
|
212
|
+
*
|
|
213
|
+
* ```
|
|
214
|
+
* start()
|
|
215
|
+
* ├── onLoadResources() ← abstract — load models, textures, data
|
|
216
|
+
* ├── createScene() ← virtual — build and configure the Scene
|
|
217
|
+
* ├── createViewport() ← virtual — build and configure the Viewport
|
|
218
|
+
* ├── createRenderer() ← virtual — build and configure the Renderer
|
|
219
|
+
* ├── onInit() ← abstract — place entities, wire input, etc.
|
|
220
|
+
* └── loop (per frame)
|
|
221
|
+
* ├── [N×] onUpdate(dt) ← abstract — physics / logic fixed tick
|
|
222
|
+
* ├── onBeforeRender() ← virtual — pre-render hook (e.g. HUD)
|
|
223
|
+
* ├── renderer.render() ← sealed
|
|
224
|
+
* └── onAfterRender() ← virtual — post-render hook
|
|
225
|
+
*
|
|
226
|
+
* stop()
|
|
227
|
+
* └── onDispose() ← virtual — release custom resources
|
|
228
|
+
* ```
|
|
229
|
+
*
|
|
230
|
+
* ### Minimal subclass
|
|
231
|
+
*
|
|
232
|
+
* ```ts
|
|
233
|
+
* class MyGame extends GameApplication {
|
|
234
|
+
* protected async onLoadResources() { ... }
|
|
235
|
+
* protected async onInit() { ... }
|
|
236
|
+
* protected onUpdate(dt: number) { ... }
|
|
237
|
+
* }
|
|
238
|
+
*
|
|
239
|
+
* const game = new MyGame({ canvasId: 'glcanvas' });
|
|
240
|
+
* await game.start();
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
declare abstract class GameApplication {
|
|
244
|
+
protected readonly webglCore: WebGLCore;
|
|
245
|
+
protected readonly config: ResolvedConfig;
|
|
246
|
+
/**
|
|
247
|
+
* The active scene. Populated during construction via `createScene()`
|
|
248
|
+
* so subclasses may reference it as early as `onLoadResources()`.
|
|
249
|
+
*/
|
|
250
|
+
protected readonly scene: Scene;
|
|
251
|
+
/**
|
|
252
|
+
* Set during `start()`, after `onLoadResources()` returns.
|
|
253
|
+
* Use in `onInit()` and lifecycle hooks.
|
|
254
|
+
*/
|
|
255
|
+
viewport: Viewport | null;
|
|
256
|
+
/**
|
|
257
|
+
* Set during `start()`, after `viewport` is initialised.
|
|
258
|
+
* `null` before `start()` resolves — safe to check from external code.
|
|
259
|
+
*/
|
|
260
|
+
renderer: Renderer | null;
|
|
261
|
+
private readonly loopRunner;
|
|
262
|
+
private _started;
|
|
263
|
+
constructor(config: GameApplicationConfig);
|
|
264
|
+
/**
|
|
265
|
+
* Execute the full startup sequence and begin the game loop.
|
|
266
|
+
*
|
|
267
|
+
* The sequence is **sealed** — extend behaviour through the protected hooks,
|
|
268
|
+
* not by overriding `start()`.
|
|
269
|
+
*/
|
|
270
|
+
start(): Promise<void>;
|
|
271
|
+
/**
|
|
272
|
+
* Pause the game loop without discarding state.
|
|
273
|
+
* Call `resume()` to continue.
|
|
274
|
+
*/
|
|
275
|
+
pause(): void;
|
|
276
|
+
/** Resume a paused game loop. */
|
|
277
|
+
resume(): void;
|
|
278
|
+
/**
|
|
279
|
+
* Stop the game loop permanently and invoke `onDispose()`.
|
|
280
|
+
* After calling `stop()` the instance should be discarded.
|
|
281
|
+
*/
|
|
282
|
+
stop(): void;
|
|
283
|
+
get isRunning(): boolean;
|
|
284
|
+
/**
|
|
285
|
+
* Load all external assets required by the game (models, textures, data).
|
|
286
|
+
*
|
|
287
|
+
* Called **before** `viewport`, `renderer`, or any scene entities are
|
|
288
|
+
* created, so it is safe to fire async fetch/XHR calls here.
|
|
289
|
+
*/
|
|
290
|
+
protected abstract onLoadResources(): Promise<void>;
|
|
291
|
+
/**
|
|
292
|
+
* Place entities into the scene, configure input handlers, set up stores, etc.
|
|
293
|
+
*
|
|
294
|
+
* Called once, after `viewport` and `renderer` have been initialised and
|
|
295
|
+
* `onLoadResources()` has resolved.
|
|
296
|
+
*/
|
|
297
|
+
protected abstract onInit(): Promise<void> | void;
|
|
298
|
+
/**
|
|
299
|
+
* Game-logic / physics update.
|
|
300
|
+
*
|
|
301
|
+
* Called at the fixed timestep rate defined by `config.targetFPS`.
|
|
302
|
+
*
|
|
303
|
+
* @param dt Fixed delta-time in **seconds** (e.g. `1/60 ≈ 0.0167`).
|
|
304
|
+
*/
|
|
305
|
+
protected abstract onUpdate(dt: number): void;
|
|
306
|
+
/**
|
|
307
|
+
* Factory for the `Scene`. Override to customise lights or initial state.
|
|
308
|
+
* Default: `Scene.withDefaultLights(webglCore)`.
|
|
309
|
+
*/
|
|
310
|
+
protected createScene(): Scene;
|
|
311
|
+
/**
|
|
312
|
+
* Factory for the `Viewport`. Override to customise camera settings or
|
|
313
|
+
* attach extra resize behaviour.
|
|
314
|
+
* Default: constructed from `config.canvasId`, `viewportWidth`, `viewportHeight`.
|
|
315
|
+
*/
|
|
316
|
+
protected createViewport(): Viewport;
|
|
317
|
+
/**
|
|
318
|
+
* Factory for the `Renderer`. Override to enable debug mode or swap
|
|
319
|
+
* the renderer implementation.
|
|
320
|
+
* Default: `new Renderer(webglCore, viewport)`.
|
|
321
|
+
*/
|
|
322
|
+
protected createRenderer(): Renderer;
|
|
323
|
+
/**
|
|
324
|
+
* Called every animation frame **before** `renderer.render(scene)`.
|
|
325
|
+
*
|
|
326
|
+
* Suitable for: updating HUD overlays, syncing camera state, or any
|
|
327
|
+
* visual concern that must run at display rate rather than the fixed tick.
|
|
328
|
+
*/
|
|
329
|
+
protected onBeforeRender(): void;
|
|
330
|
+
/**
|
|
331
|
+
* Called every animation frame **after** `renderer.render(scene)`.
|
|
332
|
+
*
|
|
333
|
+
* Suitable for: post-process passes, 2D canvas overlays, analytics.
|
|
334
|
+
*/
|
|
335
|
+
protected onAfterRender(): void;
|
|
336
|
+
/**
|
|
337
|
+
* Called by `stop()` to release any custom resources held by the subclass
|
|
338
|
+
* (event listeners, WebSocket connections, audio contexts, etc.).
|
|
339
|
+
*
|
|
340
|
+
* The base `Scene` and engine objects are **not** auto-disposed here;
|
|
341
|
+
* call `scene.dispose()` explicitly if needed.
|
|
342
|
+
*/
|
|
343
|
+
protected onDispose(): void;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
export { Actor, Arm, GameApplication, type GameApplicationConfig, GameLoopRunner, Head, InteractiveActor, Leg, PhysicsBody };
|