@guinetik/gcanvas 1.0.0 → 1.0.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/demos/coordinates.html +698 -0
- package/demos/cube3d.html +23 -0
- package/demos/demos.css +17 -3
- package/demos/dino.html +42 -0
- package/demos/fluid-simple.html +22 -0
- package/demos/fluid.html +37 -0
- package/demos/gameobjects.html +626 -0
- package/demos/index.html +19 -7
- package/demos/js/blob.js +18 -5
- package/demos/js/coordinates.js +840 -0
- package/demos/js/cube3d.js +789 -0
- package/demos/js/dino.js +1420 -0
- package/demos/js/fluid-simple.js +253 -0
- package/demos/js/fluid.js +527 -0
- package/demos/js/gameobjects.js +176 -0
- package/demos/js/plane3d.js +256 -0
- package/demos/js/platformer.js +1579 -0
- package/demos/js/sphere3d.js +229 -0
- package/demos/js/sprite.js +473 -0
- package/demos/js/tde/accretiondisk.js +65 -12
- package/demos/js/tde/blackholescene.js +2 -2
- package/demos/js/tde/config.js +2 -2
- package/demos/js/tde/index.js +152 -27
- package/demos/js/tde/lensedstarfield.js +32 -25
- package/demos/js/tde/tdestar.js +78 -98
- package/demos/js/tde/tidalstream.js +24 -8
- package/demos/plane3d.html +24 -0
- package/demos/platformer.html +43 -0
- package/demos/sphere3d.html +24 -0
- package/demos/sprite.html +18 -0
- package/docs/README.md +230 -222
- package/docs/api/FluidSystem.md +173 -0
- package/docs/concepts/architecture-overview.md +204 -204
- package/docs/concepts/coordinate-system.md +384 -0
- package/docs/concepts/rendering-pipeline.md +279 -279
- package/docs/concepts/shapes-vs-gameobjects.md +187 -0
- package/docs/concepts/two-layer-architecture.md +229 -229
- package/docs/fluid-dynamics.md +99 -0
- package/docs/getting-started/first-game.md +354 -354
- package/docs/getting-started/installation.md +175 -157
- package/docs/modules/collision/README.md +2 -2
- package/docs/modules/fluent/README.md +6 -6
- package/docs/modules/game/README.md +303 -303
- package/docs/modules/isometric-camera.md +2 -2
- package/docs/modules/isometric.md +1 -1
- package/docs/modules/painter/README.md +328 -328
- package/docs/modules/particle/README.md +3 -3
- package/docs/modules/shapes/README.md +221 -221
- package/docs/modules/shapes/base/euclidian.md +123 -123
- package/docs/modules/shapes/base/shape.md +262 -262
- package/docs/modules/shapes/base/transformable.md +243 -243
- package/docs/modules/state/README.md +2 -2
- package/docs/modules/util/README.md +1 -1
- package/docs/modules/util/camera3d.md +3 -3
- package/docs/modules/util/scene3d.md +1 -1
- package/package.json +3 -1
- package/readme.md +19 -5
- package/src/collision/collision.js +75 -0
- package/src/game/game.js +11 -5
- package/src/game/index.js +2 -1
- package/src/game/objects/index.js +3 -0
- package/src/game/objects/platformer-scene.js +411 -0
- package/src/game/objects/scene.js +14 -0
- package/src/game/objects/sprite.js +529 -0
- package/src/game/pipeline.js +20 -16
- package/src/game/systems/FluidSystem.js +835 -0
- package/src/game/systems/index.js +11 -0
- package/src/game/ui/button.js +39 -18
- package/src/game/ui/cursor.js +14 -0
- package/src/game/ui/fps.js +12 -4
- package/src/game/ui/index.js +2 -0
- package/src/game/ui/stepper.js +549 -0
- package/src/game/ui/theme.js +123 -0
- package/src/game/ui/togglebutton.js +9 -3
- package/src/game/ui/tooltip.js +11 -4
- package/src/io/input.js +75 -45
- package/src/io/mouse.js +44 -19
- package/src/io/touch.js +35 -12
- package/src/math/fluid.js +507 -0
- package/src/math/index.js +2 -0
- package/src/mixins/anchor.js +17 -7
- package/src/motion/tweenetik.js +16 -0
- package/src/shapes/cube3d.js +599 -0
- package/src/shapes/index.js +3 -0
- package/src/shapes/plane3d.js +687 -0
- package/src/shapes/sphere3d.js +75 -6
- package/src/util/camera2d.js +315 -0
- package/src/util/camera3d.js +218 -12
- package/src/util/index.js +1 -0
- package/src/webgl/shaders/plane-shaders.js +332 -0
- package/src/webgl/shaders/sphere-shaders.js +4 -2
- package/types/fluent.d.ts +361 -0
- package/types/game.d.ts +303 -0
- package/types/index.d.ts +144 -5
- package/types/math.d.ts +361 -0
- package/types/motion.d.ts +271 -0
- package/types/particle.d.ts +373 -0
- package/types/shapes.d.ts +107 -9
- package/types/util.d.ts +353 -0
- package/types/webgl.d.ts +109 -0
- package/disk_example.png +0 -0
- package/tde.png +0 -0
package/types/shapes.d.ts
CHANGED
|
@@ -713,21 +713,56 @@ export class PatternRectangle extends Rectangle {
|
|
|
713
713
|
|
|
714
714
|
/** Options for ImageShape */
|
|
715
715
|
export interface ImageShapeOptions extends ShapeOptions {
|
|
716
|
-
/**
|
|
717
|
-
|
|
718
|
-
/**
|
|
719
|
-
|
|
716
|
+
/** Anchor point for positioning (e.g., "center", "top-left") */
|
|
717
|
+
anchor?: string;
|
|
718
|
+
/** Enable image smoothing (default: true) */
|
|
719
|
+
smoothing?: boolean;
|
|
720
720
|
}
|
|
721
721
|
|
|
722
|
+
/** Type for bitmap sources that ImageShape accepts */
|
|
723
|
+
export type BitmapSource = HTMLImageElement | HTMLCanvasElement | ImageBitmap | HTMLVideoElement | ImageData;
|
|
724
|
+
|
|
722
725
|
/**
|
|
723
|
-
* Image shape.
|
|
726
|
+
* Image shape for rendering arbitrary pixel buffers.
|
|
727
|
+
* Supports HTMLImageElement, HTMLCanvasElement, ImageBitmap, HTMLVideoElement, and ImageData.
|
|
728
|
+
*
|
|
729
|
+
* @example
|
|
730
|
+
* const data = Painter.img.getImageData(0, 0, 320, 200);
|
|
731
|
+
* const shape = new ImageShape(data, { x: 100, y: 50, anchor: "center" });
|
|
732
|
+
* scene.add(shape);
|
|
724
733
|
*/
|
|
725
734
|
export class ImageShape extends Shape {
|
|
726
|
-
|
|
735
|
+
/**
|
|
736
|
+
* Create an ImageShape.
|
|
737
|
+
* @param bitmap - Image source (HTMLImageElement, HTMLCanvasElement, ImageBitmap, HTMLVideoElement, or ImageData)
|
|
738
|
+
* @param options - Shape options including anchor and smoothing
|
|
739
|
+
*/
|
|
740
|
+
constructor(bitmap: BitmapSource | null, options?: ImageShapeOptions);
|
|
741
|
+
|
|
742
|
+
/** The internal bitmap */
|
|
743
|
+
get bitmap(): BitmapSource | null;
|
|
744
|
+
set bitmap(v: BitmapSource | null);
|
|
745
|
+
|
|
746
|
+
/** Anchor position (e.g., "center", "top-left") */
|
|
747
|
+
anchor: string;
|
|
727
748
|
|
|
728
|
-
/**
|
|
729
|
-
|
|
730
|
-
|
|
749
|
+
/** Whether image smoothing is enabled */
|
|
750
|
+
smoothing: boolean;
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* Update the canvas buffer for ImageData sources.
|
|
754
|
+
* @param bitmap - ImageData to buffer
|
|
755
|
+
*/
|
|
756
|
+
buffer(bitmap: ImageData): void;
|
|
757
|
+
|
|
758
|
+
/** Reset the image to an empty state */
|
|
759
|
+
reset(): void;
|
|
760
|
+
|
|
761
|
+
/**
|
|
762
|
+
* Set the anchor point.
|
|
763
|
+
* @param anchor - Anchor position string
|
|
764
|
+
*/
|
|
765
|
+
setAnchor(anchor: string): void;
|
|
731
766
|
}
|
|
732
767
|
|
|
733
768
|
// ==========================================================================
|
|
@@ -801,6 +836,69 @@ export class Sphere extends Shape {
|
|
|
801
836
|
constructor(radius: number, options?: ShapeOptions);
|
|
802
837
|
}
|
|
803
838
|
|
|
839
|
+
/** Options for Sphere3D */
|
|
840
|
+
export interface Sphere3DOptions extends ShapeOptions {
|
|
841
|
+
/** Sphere radius */
|
|
842
|
+
radius?: number;
|
|
843
|
+
/** Number of latitude segments */
|
|
844
|
+
latSegments?: number;
|
|
845
|
+
/** Number of longitude segments */
|
|
846
|
+
lonSegments?: number;
|
|
847
|
+
/** Base color */
|
|
848
|
+
color?: string;
|
|
849
|
+
/** Light direction [x, y, z] */
|
|
850
|
+
lightDirection?: [number, number, number];
|
|
851
|
+
/** Ambient light intensity (0-1) */
|
|
852
|
+
ambientLight?: number;
|
|
853
|
+
/** Whether to use glow effect */
|
|
854
|
+
glow?: boolean;
|
|
855
|
+
/** Glow color */
|
|
856
|
+
glowColor?: string;
|
|
857
|
+
/** Glow intensity */
|
|
858
|
+
glowIntensity?: number;
|
|
859
|
+
/** Whether to use wireframe */
|
|
860
|
+
wireframe?: boolean;
|
|
861
|
+
/** Wireframe color */
|
|
862
|
+
wireframeColor?: string;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
/**
|
|
866
|
+
* 3D sphere with Camera3D projection support.
|
|
867
|
+
* Renders a proper 3D sphere with lighting and optional effects.
|
|
868
|
+
*
|
|
869
|
+
* @example
|
|
870
|
+
* const sphere = new Sphere3D({
|
|
871
|
+
* x: 0, y: 0, z: 0,
|
|
872
|
+
* radius: 100,
|
|
873
|
+
* color: '#ff6600',
|
|
874
|
+
* glow: true
|
|
875
|
+
* });
|
|
876
|
+
*/
|
|
877
|
+
export class Sphere3D extends Shape {
|
|
878
|
+
/** Sphere radius */
|
|
879
|
+
radius: number;
|
|
880
|
+
/** Z position in 3D space */
|
|
881
|
+
z: number;
|
|
882
|
+
/** Camera3D instance for projection */
|
|
883
|
+
camera: any;
|
|
884
|
+
|
|
885
|
+
constructor(options?: Sphere3DOptions);
|
|
886
|
+
|
|
887
|
+
/**
|
|
888
|
+
* Set the camera for 3D projection.
|
|
889
|
+
* @param camera - Camera3D instance
|
|
890
|
+
*/
|
|
891
|
+
setCamera(camera: any): Sphere3D;
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
* Set position in 3D space.
|
|
895
|
+
* @param x - X position
|
|
896
|
+
* @param y - Y position
|
|
897
|
+
* @param z - Z position
|
|
898
|
+
*/
|
|
899
|
+
setPosition(x: number, y: number, z: number): Sphere3D;
|
|
900
|
+
}
|
|
901
|
+
|
|
804
902
|
// ==========================================================================
|
|
805
903
|
// Text Shapes
|
|
806
904
|
// ==========================================================================
|
package/types/util.d.ts
CHANGED
|
@@ -251,3 +251,356 @@ export function gridLayout(
|
|
|
251
251
|
items: LayoutItem[],
|
|
252
252
|
options?: GridLayoutOptions
|
|
253
253
|
): LayoutResult;
|
|
254
|
+
|
|
255
|
+
// ==========================================================================
|
|
256
|
+
// Camera3D
|
|
257
|
+
// ==========================================================================
|
|
258
|
+
|
|
259
|
+
/** Options for Camera3D */
|
|
260
|
+
export interface Camera3DOptions {
|
|
261
|
+
/** Initial X rotation (tilt up/down) in radians */
|
|
262
|
+
rotationX?: number;
|
|
263
|
+
/** Initial Y rotation (spin left/right) in radians */
|
|
264
|
+
rotationY?: number;
|
|
265
|
+
/** Initial Z rotation (roll) in radians */
|
|
266
|
+
rotationZ?: number;
|
|
267
|
+
/** Initial X position in world space */
|
|
268
|
+
x?: number;
|
|
269
|
+
/** Initial Y position in world space */
|
|
270
|
+
y?: number;
|
|
271
|
+
/** Initial Z position in world space */
|
|
272
|
+
z?: number;
|
|
273
|
+
/** Perspective distance (higher = less distortion, default: 800) */
|
|
274
|
+
perspective?: number;
|
|
275
|
+
/** Mouse drag sensitivity (default: 0.005) */
|
|
276
|
+
sensitivity?: number;
|
|
277
|
+
/** Minimum X rotation limit (default: -1.5) */
|
|
278
|
+
minRotationX?: number;
|
|
279
|
+
/** Maximum X rotation limit (default: 1.5) */
|
|
280
|
+
maxRotationX?: number;
|
|
281
|
+
/** Whether to clamp X rotation (default: true) */
|
|
282
|
+
clampX?: boolean;
|
|
283
|
+
/** Enable auto-rotation (default: false) */
|
|
284
|
+
autoRotate?: boolean;
|
|
285
|
+
/** Auto-rotation speed in radians per second (default: 0.5) */
|
|
286
|
+
autoRotateSpeed?: number;
|
|
287
|
+
/** Auto-rotation axis: 'x', 'y', or 'z' */
|
|
288
|
+
autoRotateAxis?: 'x' | 'y' | 'z';
|
|
289
|
+
/** Enable inertia/momentum (default: false) */
|
|
290
|
+
inertia?: boolean;
|
|
291
|
+
/** Velocity decay per frame (default: 0.92) */
|
|
292
|
+
friction?: number;
|
|
293
|
+
/** Multiplier for initial throw velocity (default: 1.0) */
|
|
294
|
+
velocityScale?: number;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** Projected point result */
|
|
298
|
+
export interface ProjectedPoint {
|
|
299
|
+
/** Screen X coordinate */
|
|
300
|
+
x: number;
|
|
301
|
+
/** Screen Y coordinate */
|
|
302
|
+
y: number;
|
|
303
|
+
/** Depth (for sorting) */
|
|
304
|
+
z: number;
|
|
305
|
+
/** Scale factor (for size adjustment) */
|
|
306
|
+
scale: number;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** Mouse control options */
|
|
310
|
+
export interface MouseControlOptions {
|
|
311
|
+
/** Invert horizontal rotation */
|
|
312
|
+
invertX?: boolean;
|
|
313
|
+
/** Invert vertical rotation */
|
|
314
|
+
invertY?: boolean;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** Follow options */
|
|
318
|
+
export interface FollowOptions {
|
|
319
|
+
/** X offset from target */
|
|
320
|
+
offsetX?: number;
|
|
321
|
+
/** Y offset from target */
|
|
322
|
+
offsetY?: number;
|
|
323
|
+
/** Z offset from target */
|
|
324
|
+
offsetZ?: number;
|
|
325
|
+
/** Auto-orient to look at lookAtTarget */
|
|
326
|
+
lookAt?: boolean;
|
|
327
|
+
/** Point to look at (default: origin) */
|
|
328
|
+
lookAtTarget?: { x: number; y: number; z: number } | null;
|
|
329
|
+
/** Interpolation speed (0-1, higher = snappier, default: 0.1) */
|
|
330
|
+
lerp?: number;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
/** MoveTo animation options */
|
|
334
|
+
export interface MoveToOptions {
|
|
335
|
+
/** Target X rotation */
|
|
336
|
+
rotationX?: number;
|
|
337
|
+
/** Target Y rotation */
|
|
338
|
+
rotationY?: number;
|
|
339
|
+
/** Interpolation speed (0-1, default: 0.05) */
|
|
340
|
+
lerp?: number;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Camera3D - Pseudo-3D projection and mouse-controlled rotation.
|
|
345
|
+
* Provides 3D to 2D projection with perspective, rotation controls,
|
|
346
|
+
* and interactive mouse/touch rotation for 2D canvas applications.
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* const camera = new Camera3D({
|
|
350
|
+
* rotationX: 0.3,
|
|
351
|
+
* rotationY: -0.4,
|
|
352
|
+
* perspective: 800,
|
|
353
|
+
* inertia: true,
|
|
354
|
+
* friction: 0.92
|
|
355
|
+
* });
|
|
356
|
+
* camera.enableMouseControl(canvas);
|
|
357
|
+
*
|
|
358
|
+
* // In render loop
|
|
359
|
+
* const { x, y, scale, z } = camera.project(x3d, y3d, z3d);
|
|
360
|
+
*/
|
|
361
|
+
export class Camera3D {
|
|
362
|
+
/** X rotation in radians */
|
|
363
|
+
rotationX: number;
|
|
364
|
+
/** Y rotation in radians */
|
|
365
|
+
rotationY: number;
|
|
366
|
+
/** Z rotation in radians */
|
|
367
|
+
rotationZ: number;
|
|
368
|
+
/** X position in world space */
|
|
369
|
+
x: number;
|
|
370
|
+
/** Y position in world space */
|
|
371
|
+
y: number;
|
|
372
|
+
/** Z position in world space */
|
|
373
|
+
z: number;
|
|
374
|
+
/** Perspective distance */
|
|
375
|
+
perspective: number;
|
|
376
|
+
/** Mouse drag sensitivity */
|
|
377
|
+
sensitivity: number;
|
|
378
|
+
/** Minimum X rotation */
|
|
379
|
+
minRotationX: number;
|
|
380
|
+
/** Maximum X rotation */
|
|
381
|
+
maxRotationX: number;
|
|
382
|
+
/** Whether X rotation is clamped */
|
|
383
|
+
clampX: boolean;
|
|
384
|
+
/** Auto-rotation enabled */
|
|
385
|
+
autoRotate: boolean;
|
|
386
|
+
/** Auto-rotation speed */
|
|
387
|
+
autoRotateSpeed: number;
|
|
388
|
+
/** Auto-rotation axis */
|
|
389
|
+
autoRotateAxis: 'x' | 'y' | 'z';
|
|
390
|
+
/** Inertia enabled */
|
|
391
|
+
inertia: boolean;
|
|
392
|
+
/** Friction for inertia */
|
|
393
|
+
friction: number;
|
|
394
|
+
/** Velocity scale for throws */
|
|
395
|
+
velocityScale: number;
|
|
396
|
+
|
|
397
|
+
constructor(options?: Camera3DOptions);
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Project a 3D point to 2D screen coordinates.
|
|
401
|
+
* @param x - X coordinate in 3D space
|
|
402
|
+
* @param y - Y coordinate in 3D space
|
|
403
|
+
* @param z - Z coordinate in 3D space
|
|
404
|
+
*/
|
|
405
|
+
project(x: number, y: number, z: number): ProjectedPoint;
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Project multiple points at once.
|
|
409
|
+
* @param points - Array of 3D points
|
|
410
|
+
*/
|
|
411
|
+
projectAll(points: Array<{ x: number; y: number; z: number }>): ProjectedPoint[];
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Update camera for auto-rotation, inertia, and follow mode.
|
|
415
|
+
* @param dt - Delta time in seconds
|
|
416
|
+
*/
|
|
417
|
+
update(dt: number): void;
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Enable mouse/touch drag rotation on a canvas.
|
|
421
|
+
* @param canvas - Canvas element to attach controls to
|
|
422
|
+
* @param options - Control options
|
|
423
|
+
*/
|
|
424
|
+
enableMouseControl(canvas: HTMLCanvasElement, options?: MouseControlOptions): Camera3D;
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Disable mouse/touch controls.
|
|
428
|
+
*/
|
|
429
|
+
disableMouseControl(): Camera3D;
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Reset rotation and position to initial values.
|
|
433
|
+
*/
|
|
434
|
+
reset(): Camera3D;
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Stop any inertia motion immediately.
|
|
438
|
+
*/
|
|
439
|
+
stopInertia(): Camera3D;
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Set camera position in world space.
|
|
443
|
+
* @param x - X position
|
|
444
|
+
* @param y - Y position
|
|
445
|
+
* @param z - Z position
|
|
446
|
+
*/
|
|
447
|
+
setPosition(x: number, y: number, z: number): Camera3D;
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Animate camera to a new position.
|
|
451
|
+
* @param x - Target X position
|
|
452
|
+
* @param y - Target Y position
|
|
453
|
+
* @param z - Target Z position
|
|
454
|
+
* @param options - Animation options
|
|
455
|
+
*/
|
|
456
|
+
moveTo(x: number, y: number, z: number, options?: MoveToOptions): Camera3D;
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Follow a target object.
|
|
460
|
+
* @param target - Object with x, y, z properties
|
|
461
|
+
* @param options - Follow options
|
|
462
|
+
*/
|
|
463
|
+
follow(target: { x?: number; y?: number; z?: number }, options?: FollowOptions): Camera3D;
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Stop following target.
|
|
467
|
+
* @param resetPosition - Animate back to initial position
|
|
468
|
+
*/
|
|
469
|
+
unfollow(resetPosition?: boolean): Camera3D;
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Check if camera is following a target.
|
|
473
|
+
*/
|
|
474
|
+
isFollowing(): boolean;
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Set rotation angles.
|
|
478
|
+
* @param x - X rotation in radians
|
|
479
|
+
* @param y - Y rotation in radians
|
|
480
|
+
* @param z - Z rotation in radians (optional)
|
|
481
|
+
*/
|
|
482
|
+
setRotation(x: number, y: number, z?: number): Camera3D;
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Add to current rotation.
|
|
486
|
+
* @param dx - Delta X rotation
|
|
487
|
+
* @param dy - Delta Y rotation
|
|
488
|
+
* @param dz - Delta Z rotation (optional)
|
|
489
|
+
*/
|
|
490
|
+
rotate(dx: number, dy: number, dz?: number): Camera3D;
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Check if currently being dragged by user.
|
|
494
|
+
*/
|
|
495
|
+
isDragging(): boolean;
|
|
496
|
+
|
|
497
|
+
/**
|
|
498
|
+
* Look at a specific point.
|
|
499
|
+
* @param x - Target X in world space
|
|
500
|
+
* @param y - Target Y in world space
|
|
501
|
+
* @param z - Target Z in world space
|
|
502
|
+
*/
|
|
503
|
+
lookAt(x: number, y: number, z: number): Camera3D;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// ==========================================================================
|
|
507
|
+
// IsometricCamera
|
|
508
|
+
// ==========================================================================
|
|
509
|
+
|
|
510
|
+
/** Options for IsometricCamera */
|
|
511
|
+
export interface IsometricCameraOptions {
|
|
512
|
+
/** Tile width in pixels (default: 64) */
|
|
513
|
+
tileWidth?: number;
|
|
514
|
+
/** Tile height in pixels (default: 32) */
|
|
515
|
+
tileHeight?: number;
|
|
516
|
+
/** Camera X offset */
|
|
517
|
+
offsetX?: number;
|
|
518
|
+
/** Camera Y offset */
|
|
519
|
+
offsetY?: number;
|
|
520
|
+
/** Camera zoom level (default: 1) */
|
|
521
|
+
zoom?: number;
|
|
522
|
+
/** Rotation angle (0, 90, 180, 270 degrees) */
|
|
523
|
+
rotation?: 0 | 90 | 180 | 270;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Isometric camera for 2.5D grid-based projections.
|
|
528
|
+
* Converts between grid coordinates and screen positions.
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
* const camera = new IsometricCamera({
|
|
532
|
+
* tileWidth: 64,
|
|
533
|
+
* tileHeight: 32,
|
|
534
|
+
* offsetX: 400,
|
|
535
|
+
* offsetY: 100
|
|
536
|
+
* });
|
|
537
|
+
*
|
|
538
|
+
* const screen = camera.gridToScreen(5, 3);
|
|
539
|
+
* const grid = camera.screenToGrid(mouseX, mouseY);
|
|
540
|
+
*/
|
|
541
|
+
export class IsometricCamera {
|
|
542
|
+
/** Tile width in pixels */
|
|
543
|
+
tileWidth: number;
|
|
544
|
+
/** Tile height in pixels */
|
|
545
|
+
tileHeight: number;
|
|
546
|
+
/** Camera X offset */
|
|
547
|
+
offsetX: number;
|
|
548
|
+
/** Camera Y offset */
|
|
549
|
+
offsetY: number;
|
|
550
|
+
/** Camera zoom level */
|
|
551
|
+
zoom: number;
|
|
552
|
+
/** Camera rotation (0, 90, 180, 270) */
|
|
553
|
+
rotation: 0 | 90 | 180 | 270;
|
|
554
|
+
|
|
555
|
+
constructor(options?: IsometricCameraOptions);
|
|
556
|
+
|
|
557
|
+
/**
|
|
558
|
+
* Convert grid coordinates to screen position.
|
|
559
|
+
* @param gridX - Grid X coordinate
|
|
560
|
+
* @param gridY - Grid Y coordinate
|
|
561
|
+
* @param height - Optional height offset
|
|
562
|
+
*/
|
|
563
|
+
gridToScreen(gridX: number, gridY: number, height?: number): { x: number; y: number };
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* Convert screen position to grid coordinates.
|
|
567
|
+
* @param screenX - Screen X coordinate
|
|
568
|
+
* @param screenY - Screen Y coordinate
|
|
569
|
+
*/
|
|
570
|
+
screenToGrid(screenX: number, screenY: number): { x: number; y: number };
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Rotate camera by 90 degrees.
|
|
574
|
+
* @param clockwise - Rotate clockwise (default: true)
|
|
575
|
+
*/
|
|
576
|
+
rotate90(clockwise?: boolean): void;
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Set camera offset.
|
|
580
|
+
* @param x - X offset
|
|
581
|
+
* @param y - Y offset
|
|
582
|
+
*/
|
|
583
|
+
setOffset(x: number, y: number): void;
|
|
584
|
+
|
|
585
|
+
/**
|
|
586
|
+
* Set zoom level.
|
|
587
|
+
* @param zoom - Zoom multiplier
|
|
588
|
+
*/
|
|
589
|
+
setZoom(zoom: number): void;
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Pan camera by delta.
|
|
593
|
+
* @param dx - X delta
|
|
594
|
+
* @param dy - Y delta
|
|
595
|
+
*/
|
|
596
|
+
pan(dx: number, dy: number): void;
|
|
597
|
+
|
|
598
|
+
/**
|
|
599
|
+
* Center camera on grid position.
|
|
600
|
+
* @param gridX - Grid X coordinate
|
|
601
|
+
* @param gridY - Grid Y coordinate
|
|
602
|
+
* @param screenWidth - Screen width
|
|
603
|
+
* @param screenHeight - Screen height
|
|
604
|
+
*/
|
|
605
|
+
centerOn(gridX: number, gridY: number, screenWidth: number, screenHeight: number): void;
|
|
606
|
+
}
|
package/types/webgl.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GCanvas WebGL Module
|
|
3
|
+
* Optional WebGL rendering capabilities for enhanced visual effects.
|
|
4
|
+
* @module webgl
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
// ==========================================================================
|
|
8
|
+
// WebGL Renderer
|
|
9
|
+
// ==========================================================================
|
|
10
|
+
|
|
11
|
+
/** WebGL renderer options */
|
|
12
|
+
export interface WebGLRendererOptions {
|
|
13
|
+
/** Canvas element */
|
|
14
|
+
canvas: HTMLCanvasElement;
|
|
15
|
+
/** Whether to preserve drawing buffer */
|
|
16
|
+
preserveDrawingBuffer?: boolean;
|
|
17
|
+
/** Enable antialiasing */
|
|
18
|
+
antialias?: boolean;
|
|
19
|
+
/** Enable alpha blending */
|
|
20
|
+
alpha?: boolean;
|
|
21
|
+
/** Enable depth testing */
|
|
22
|
+
depth?: boolean;
|
|
23
|
+
/** Enable stencil buffer */
|
|
24
|
+
stencil?: boolean;
|
|
25
|
+
/** Premultiplied alpha */
|
|
26
|
+
premultipliedAlpha?: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* WebGL renderer for enhanced visual effects.
|
|
31
|
+
* Provides shader-based rendering for complex effects.
|
|
32
|
+
*/
|
|
33
|
+
export class WebGLRenderer {
|
|
34
|
+
/** WebGL rendering context */
|
|
35
|
+
readonly gl: WebGLRenderingContext | WebGL2RenderingContext;
|
|
36
|
+
/** Canvas element */
|
|
37
|
+
readonly canvas: HTMLCanvasElement;
|
|
38
|
+
/** Whether WebGL is available */
|
|
39
|
+
readonly isAvailable: boolean;
|
|
40
|
+
|
|
41
|
+
constructor(options: WebGLRendererOptions);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Create and compile a shader program.
|
|
45
|
+
* @param vertexSource - Vertex shader GLSL source
|
|
46
|
+
* @param fragmentSource - Fragment shader GLSL source
|
|
47
|
+
* @returns Compiled shader program
|
|
48
|
+
*/
|
|
49
|
+
createProgram(vertexSource: string, fragmentSource: string): WebGLProgram;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Set uniform value.
|
|
53
|
+
* @param program - Shader program
|
|
54
|
+
* @param name - Uniform name
|
|
55
|
+
* @param value - Uniform value
|
|
56
|
+
*/
|
|
57
|
+
setUniform(program: WebGLProgram, name: string, value: number | number[] | Float32Array): void;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Create a texture from an image or canvas.
|
|
61
|
+
* @param source - Image or canvas source
|
|
62
|
+
* @returns WebGL texture
|
|
63
|
+
*/
|
|
64
|
+
createTexture(source: HTMLImageElement | HTMLCanvasElement | ImageData): WebGLTexture;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Render a full-screen quad with a shader.
|
|
68
|
+
* @param program - Shader program to use
|
|
69
|
+
*/
|
|
70
|
+
renderFullscreenQuad(program: WebGLProgram): void;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Clear the canvas.
|
|
74
|
+
* @param r - Red (0-1)
|
|
75
|
+
* @param g - Green (0-1)
|
|
76
|
+
* @param b - Blue (0-1)
|
|
77
|
+
* @param a - Alpha (0-1)
|
|
78
|
+
*/
|
|
79
|
+
clear(r?: number, g?: number, b?: number, a?: number): void;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Resize the renderer to match canvas size.
|
|
83
|
+
*/
|
|
84
|
+
resize(): void;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Dispose of WebGL resources.
|
|
88
|
+
*/
|
|
89
|
+
dispose(): void;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ==========================================================================
|
|
93
|
+
// Shader Collections
|
|
94
|
+
// ==========================================================================
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Pre-built shaders for 3D sphere rendering.
|
|
98
|
+
*/
|
|
99
|
+
export namespace SPHERE_SHADERS {
|
|
100
|
+
/** Basic sphere vertex shader */
|
|
101
|
+
const vertex: string;
|
|
102
|
+
/** Basic sphere fragment shader with lighting */
|
|
103
|
+
const fragment: string;
|
|
104
|
+
/** Glow effect fragment shader */
|
|
105
|
+
const glowFragment: string;
|
|
106
|
+
/** Atmosphere effect fragment shader */
|
|
107
|
+
const atmosphereFragment: string;
|
|
108
|
+
}
|
|
109
|
+
|
package/disk_example.png
DELETED
|
Binary file
|
package/tde.png
DELETED
|
Binary file
|