rapid-render 0.1.1 → 0.1.2-1.3

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/dist/math.d.ts CHANGED
@@ -1,15 +1,28 @@
1
- import { WebGLContext } from "./interface";
2
- type ArrayType = typeof Float32Array | typeof Uint16Array;
1
+ import { IMathObject, ITransformOptions, WebGLContext } from './interface';
2
+ /**
3
+ * @ignore
4
+ */
5
+ export declare enum ArrayType {
6
+ Float32 = 0,
7
+ Uint32 = 1,
8
+ Uint16 = 2
9
+ }
10
+ /**
11
+ * @ignore
12
+ */
3
13
  export declare class DynamicArrayBuffer {
4
14
  usedElemNum: number;
5
- protected typedArray: Float32Array | Uint16Array;
15
+ protected typedArray: Float32Array | Uint32Array | Uint16Array;
6
16
  private arrayType;
7
17
  protected maxElemNum: number;
8
18
  readonly bytePerElem: number;
9
19
  private arraybuffer;
10
- /** if typedArray is Float32Array*/
11
20
  private uint32?;
21
+ private float32?;
22
+ private uint16?;
12
23
  constructor(arrayType: ArrayType);
24
+ getArrayType(arrayType: ArrayType): Float32ArrayConstructor | Uint32ArrayConstructor | Uint16ArrayConstructor;
25
+ updateTypedArray(): void;
13
26
  clear(): void;
14
27
  /**
15
28
  * resize the array
@@ -18,12 +31,9 @@ export declare class DynamicArrayBuffer {
18
31
  */
19
32
  resize(size?: number): void;
20
33
  protected setMaxSize(size?: number): void;
21
- /**
22
- * push a new element
23
- * @param value
24
- */
25
- push(value: number): void;
26
- pushUint(value: number): void;
34
+ pushUint32(value: number): void;
35
+ pushFloat32(value: number): void;
36
+ pushUint16(value: number): void;
27
37
  /**
28
38
  * pop a element
29
39
  * @param num
@@ -35,12 +45,15 @@ export declare class DynamicArrayBuffer {
35
45
  * @param end
36
46
  * @returns
37
47
  */
38
- getArray(begin?: number, end?: number): Uint16Array | Float32Array;
48
+ getArray(begin?: number, end?: number): Uint32Array | Float32Array | Uint16Array;
39
49
  /**
40
50
  * length of the array
41
51
  */
42
52
  get length(): number;
43
53
  }
54
+ /**
55
+ * @ignore
56
+ */
44
57
  export declare class WebglBufferArray extends DynamicArrayBuffer {
45
58
  buffer: WebGLBuffer;
46
59
  gl: WebGLContext;
@@ -50,8 +63,11 @@ export declare class WebglBufferArray extends DynamicArrayBuffer {
50
63
  * webglbuffer 中的大小
51
64
  */
52
65
  private webglBufferSize;
53
- constructor(gl: WebGLContext, arrayType: ArrayType, type?: number);
54
- push(value: number): void;
66
+ readonly usage: number;
67
+ constructor(gl: WebGLContext, arrayType: ArrayType, type?: number, usage?: number);
68
+ pushFloat32(value: number): void;
69
+ pushUint32(value: number): void;
70
+ pushUint16(value: number): void;
55
71
  /**
56
72
  * bind buffer to gpu
57
73
  */
@@ -80,7 +96,7 @@ export declare class MatrixStack extends DynamicArrayBuffer {
80
96
  * @param x - The amount to translate horizontally.
81
97
  * @param y - The amount to translate vertically.
82
98
  */
83
- translate(x: number | Vec2, y: number): void;
99
+ translate(x: number | Vec2, y?: number): void;
84
100
  /**
85
101
  * Rotates the current matrix by the specified angle.
86
102
  * @param angle - The angle, in radians, to rotate the matrix by.
@@ -96,7 +112,7 @@ export declare class MatrixStack extends DynamicArrayBuffer {
96
112
  * Transforms a point by applying the current matrix stack.
97
113
  * @returns The transformed point as an array `[newX, newY]`.
98
114
  */
99
- apply(x: number | Vec2, y: number): Vec2 | number[];
115
+ apply(x: number | Vec2, y?: number): Vec2 | number[];
100
116
  /**
101
117
  * Obtain the inverse matrix of the current matrix
102
118
  * @returns inverse matrix
@@ -112,7 +128,63 @@ export declare class MatrixStack extends DynamicArrayBuffer {
112
128
  * @param array
113
129
  */
114
130
  setTransform(array: Float32Array | number[]): void;
131
+ /**
132
+ * Get the global position in world space
133
+ * @returns The current matrix position in world space
134
+ */
135
+ getGlobalPosition(): Vec2;
136
+ /**
137
+ * Set the global position in world space
138
+ * @param x - x coordinate or Vec2 object
139
+ * @param y - y coordinate (ignored if first parameter is Vec2)
140
+ */
141
+ setGlobalPosition(x: number | Vec2, y?: number): void;
142
+ /**
143
+ * Get the global rotation angle
144
+ * @returns The current matrix rotation angle in radians
145
+ */
146
+ getGlobalRotation(): number;
147
+ /**
148
+ * Set the global rotation angle
149
+ * @param angle - rotation angle in radians
150
+ */
151
+ setGlobalRotation(angle: number): void;
152
+ /**
153
+ * Get the global scale
154
+ * @returns The current matrix scale values
155
+ */
156
+ getGlobalScale(): Vec2;
157
+ /**
158
+ * Set the global scale
159
+ * @param x - x scale or Vec2 object
160
+ * @param y - y scale (ignored if first parameter is Vec2)
161
+ */
162
+ setGlobalScale(x: number | Vec2, y?: number): void;
163
+ globalToLocal(global: Vec2): Vec2;
164
+ localToGlobal(local: Vec2): Vec2;
165
+ /**
166
+ * Convert the current matrix to a CSS transform string
167
+ * @returns CSS transform string representation of the matrix
168
+ */
169
+ toCSSTransform(): string;
170
+ /**
171
+ * Reset the current matrix to identity matrix
172
+ */
173
+ identity(): void;
174
+ /**
175
+ * Apply the transform to the current matrix
176
+ * @param transform - The transform to apply
177
+ * @returns offset position
178
+ */
179
+ applyTransform(transform: ITransformOptions, width?: number, height?: number): {
180
+ offsetX: number;
181
+ offsetY: number;
182
+ };
183
+ applyTransformAfter(transform: ITransformOptions): void;
115
184
  }
185
+ /**
186
+ * @ignore
187
+ */
116
188
  export declare class WebglElementBufferArray extends WebglBufferArray {
117
189
  constructor(gl: WebGLContext, elemVertPerObj: number, vertexPerObject: number, maxBatch: number);
118
190
  protected addObject(_vertex?: number): void;
@@ -120,7 +192,7 @@ export declare class WebglElementBufferArray extends WebglBufferArray {
120
192
  /**
121
193
  * Represents a color with red, green, blue, and alpha (transparency) components.
122
194
  */
123
- export declare class Color {
195
+ export declare class Color implements IMathObject<Color> {
124
196
  private _r;
125
197
  private _g;
126
198
  private _b;
@@ -133,7 +205,7 @@ export declare class Color {
133
205
  * @param b - The blue component (0-255).
134
206
  * @param a - The alpha component (0-255).
135
207
  */
136
- constructor(r: number, g: number, b: number, a: number);
208
+ constructor(r: number, g: number, b: number, a?: number);
137
209
  /**
138
210
  * Gets the red component.
139
211
  */
@@ -188,12 +260,23 @@ export declare class Color {
188
260
  * @param color - The color to copy from.
189
261
  */
190
262
  copy(color: Color): void;
263
+ /**
264
+ * Clone the current color
265
+ * @returns A new `Color` instance with the same RGBA values.
266
+ */
267
+ clone(): Color;
268
+ /**
269
+ * Converts the color to a hexadecimal string representation (e.g., '#RRGGBBAA').
270
+ * @param includeAlpha - Whether to include the alpha channel in the hex string.
271
+ * @returns The hexadecimal string representation of the color.
272
+ */
273
+ toHexString(includeAlpha?: boolean): string;
191
274
  /**
192
275
  * Checks if the current color is equal to another color.
193
276
  * @param color - The color to compare with.
194
277
  * @returns True if the colors are equal, otherwise false.
195
278
  */
196
- equals(color: Color): boolean;
279
+ equal(color: Color): boolean;
197
280
  /**
198
281
  * Creates a Color instance from a hexadecimal color string.
199
282
  * @param hexString - The hexadecimal color string, e.g., '#RRGGBB' or '#RRGGBBAA'.
@@ -212,25 +295,102 @@ export declare class Color {
212
295
  * @returns A new Color instance with the result of the subtraction.
213
296
  */
214
297
  subtract(color: Color): Color;
298
+ divide(color: Color | number): Color;
299
+ multiply(color: Color | number): Color;
300
+ clamp(): void;
301
+ static Red: Color;
302
+ static Green: Color;
303
+ static Blue: Color;
304
+ static Yellow: Color;
305
+ static Purple: Color;
306
+ static Orange: Color;
307
+ static Pink: Color;
308
+ static Gray: Color;
309
+ static Brown: Color;
310
+ static Cyan: Color;
311
+ static Magenta: Color;
312
+ static Lime: Color;
313
+ static White: Color;
314
+ static Black: Color;
315
+ static TRANSPARENT: Color;
215
316
  }
216
317
  /**
217
318
  * Represents a 2D vector with x and y components.
218
319
  */
219
- export declare class Vec2 {
320
+ export declare class Vec2 implements IMathObject<Vec2> {
220
321
  x: number;
221
322
  y: number;
323
+ static ZERO: Vec2;
324
+ static ONE: Vec2;
325
+ static UP: Vec2;
326
+ static DOWN: Vec2;
327
+ static LEFT: Vec2;
328
+ static RIGHT: Vec2;
222
329
  /**
223
330
  * Creates an instance of Vec2.
224
331
  * @param x - The x coordinate (default is 0).
225
332
  * @param y - The y coordinate (default is 0).
226
333
  */
227
334
  constructor(x?: number, y?: number);
335
+ set(x: number | number[], y?: number): this;
228
336
  /**
229
- * Multiplies the vector by a scalar.
230
- * @param f - The scalar value to multiply by.
231
- * @returns The current instance with updated values.
337
+ * Adds another vector to this vector.
338
+ * @param v - The vector to add.
339
+ * @returns A new Vec2 instance with the result of the addition.
340
+ */
341
+ add(v: Vec2): Vec2;
342
+ /**
343
+ * Subtracts another vector from this vector.
344
+ * @param v - The vector to subtract.
345
+ * @returns A new Vec2 instance with the result of the subtraction.
346
+ */
347
+ subtract(v: Vec2): Vec2;
348
+ /**
349
+ * Multiplies the vector by a scalar or another vector.
350
+ * @param f - The scalar value or vector to multiply by.
351
+ * @returns A new Vec2 instance with the result of the multiplication.
352
+ */
353
+ multiply(f: number | Vec2): Vec2;
354
+ /**
355
+ * Divides the vector by a scalar or another vector.
356
+ * @param f - The scalar value or vector to divide by.
357
+ * @returns A new Vec2 instance with the result of the division.
232
358
  */
233
- scalarMult(f: number): this;
359
+ divide(f: number | Vec2): Vec2;
360
+ /**
361
+ * Calculates the dot product of this vector with another vector.
362
+ * @param v - The other vector.
363
+ * @returns The dot product result.
364
+ */
365
+ dot(v: Vec2): number;
366
+ /**
367
+ * Calculates the cross product of this vector with another vector.
368
+ * @param v - The other vector.
369
+ * @returns The cross product result.
370
+ */
371
+ cross(v: Vec2): number;
372
+ /**
373
+ * Calculates the distance to another point.
374
+ * @param v - The other point.
375
+ * @returns The distance between the two points.
376
+ */
377
+ distanceTo(v: Vec2): number;
378
+ /**
379
+ * Clones the vector.
380
+ * @returns A new Vec2 instance with the same x and y values.
381
+ */
382
+ clone(): Vec2;
383
+ /**
384
+ * Copy the vector
385
+ * @param vec - The vector to copy.
386
+ */
387
+ copy(vec: Vec2): void;
388
+ /**
389
+ * Check if the vector is equal to another vector.
390
+ * @param vec - The vector to compare with.
391
+ * @returns True if the vectors are equal, otherwise false.
392
+ */
393
+ equal(vec: Vec2): boolean;
234
394
  /**
235
395
  * Rotates the vector 90 degrees counterclockwise.
236
396
  * @returns The current instance with updated values.
@@ -257,38 +417,112 @@ export declare class Vec2 {
257
417
  */
258
418
  angle(): number;
259
419
  /**
260
- * Computes the angle between two vectors.
261
- * @param p0 - The starting vector.
262
- * @param p1 - The ending vector.
263
- * @returns The angle between the two vectors in radians.
420
+ * Calculates the middle point between the current vector and another vector.
421
+ * @param other - The other vector.
422
+ * @returns A new vector representing the middle point between the current vector and the other vector.
423
+ */
424
+ middle(other: Vec2): Vec2;
425
+ /**
426
+ * Returns a new vector with the absolute values of the components.
427
+ * @returns A new vector with absolute values.
264
428
  */
265
- static Angle(p0: Vec2, p1: Vec2): number;
429
+ abs(): Vec2;
266
430
  /**
267
- * Adds two vectors together.
268
- * @param p0 - The first vector.
269
- * @param p1 - The second vector.
270
- * @returns A new vector representing the sum of p0 and p1.
431
+ * Returns a new vector with floored components.
432
+ * @returns A new vector with components rounded down to the nearest integer.
271
433
  */
272
- static Add(p0: Vec2, p1: Vec2): Vec2;
434
+ floor(): Vec2;
273
435
  /**
274
- * Subtracts one vector from another.
275
- * @param p1 - The vector to subtract from.
276
- * @param p0 - The vector to subtract.
277
- * @returns A new vector representing the difference between p1 and p0.
436
+ * Returns a new vector with ceiled components.
437
+ * @returns A new vector with components rounded up to the nearest integer.
278
438
  */
279
- static Sub(p1: Vec2, p0: Vec2): Vec2;
439
+ ceil(): Vec2;
280
440
  /**
281
- * Finds the midpoint between two vectors.
282
- * @param p0 - The first vector.
283
- * @param p1 - The second vector.
284
- * @returns A new vector representing the midpoint between p0 and p1.
441
+ * Snaps the vector components to the nearest increment.
442
+ * @param increment - The increment to snap to.
443
+ * @returns A new vector with components snapped to the nearest increment.
285
444
  */
286
- static Middle(p0: Vec2, p1: Vec2): Vec2;
445
+ snap(increment: number): Vec2;
446
+ /**
447
+ * Converts the vector to a string representation.
448
+ * @returns A string containing the vector's x and y coordinates.
449
+ */
450
+ stringify(): string;
287
451
  /**
288
452
  * Converts an array of coordinate pairs into an array of Vec2 instances.
289
453
  * @param array - An array of [x, y] coordinate pairs.
290
454
  * @returns An array of Vec2 instances.
291
455
  */
292
- static FormArray(array: number[][]): Vec2[];
456
+ static FromArray(array: number[][]): Vec2[];
457
+ static fromAngle(angle: number): Vec2;
458
+ /**
459
+ * Calculates the angle between two vectors.
460
+ * @param v - The other vector.
461
+ * @returns The angle between the two vectors in radians.
462
+ */
463
+ angleBetween(v: Vec2): number;
464
+ lerp(target: Vec2, factor: number): Vec2;
465
+ }
466
+ /**
467
+ * Provides utility methods for mathematical conversions.
468
+ */
469
+ export declare class MathUtils {
470
+ /**
471
+ * Converts degrees to radians.
472
+ * @param degrees - The angle in degrees.
473
+ * @returns The equivalent angle in radians.
474
+ */
475
+ static deg2rad(degrees: number): number;
476
+ /**
477
+ * Converts radians to degrees.
478
+ * @param rad - The angle in radians.
479
+ * @returns The equivalent angle in degrees.
480
+ */
481
+ static rad2deg(rad: number): number;
482
+ /**
483
+ * Normalizes an angle in degrees to be within the range of 0 to 360 degrees.
484
+ * @param degrees - The angle in degrees to be normalized.
485
+ * @returns The normalized angle in degrees.
486
+ */
487
+ static normalizeDegrees(degrees: number): number;
488
+ }
489
+ export declare class Random {
490
+ /**
491
+ * 生成指定范围内的随机浮点数
492
+ * @param min - 最小值
493
+ * @param max - 最大值
494
+ * @returns 随机浮点数
495
+ */
496
+ static float(min: number, max: number): number;
497
+ /**
498
+ * 生成指定范围内的随机整数
499
+ * @param min - 最小值
500
+ * @param max - 最大值
501
+ * @returns 随机整数
502
+ */
503
+ static int(min: number, max: number): number;
504
+ /**
505
+ * 生成随机角度(0-360度)
506
+ * @returns 随机角度(弧度)
507
+ */
508
+ static angle(): number;
509
+ /**
510
+ * 生成指定范围内的随机向量
511
+ * @param minX - 最小X值
512
+ * @param maxX - 最大X值
513
+ * @param minY - 最小Y值
514
+ * @param maxY - 最大Y值
515
+ * @returns 随机向量
516
+ */
517
+ static vector(minX: number, maxX: number, minY: number, maxY: number): Vec2;
518
+ /**
519
+ * 生成具有随机方向和指定长度的向量
520
+ * @param length - 向量长度
521
+ * @returns 随机方向向量
522
+ */
523
+ static direction(length: number): Vec2;
524
+ static randomColor(minColor: Color, maxColor: Color): Color;
525
+ static pick(array: any[]): any;
526
+ static pickWeight(array: [any, number][]): any;
527
+ static scalarOrRange<T extends number | Vec2 | Color>(range?: T | [T, T], defaultValue?: T): T;
293
528
  }
294
- export {};
@@ -0,0 +1,76 @@
1
+ import { IParticleOptions, ITransformOptions } from './interface';
2
+ import { Entity, Game } from './game';
3
+ /**
4
+ * Particle emitter for creating and managing particle systems
5
+ */
6
+ export declare class ParticleEmitter extends Entity {
7
+ private particles;
8
+ private options;
9
+ private emitting;
10
+ private emitTimer;
11
+ private emitRate;
12
+ private emitTime;
13
+ private emitTimeCounter;
14
+ localSpace: boolean;
15
+ /**
16
+ * Creates a new particle emitter
17
+ * @param rapid - The Rapid renderer instance
18
+ * @param options - Emitter configuration options
19
+ */
20
+ constructor(game: Game, options: IParticleOptions);
21
+ /**
22
+ * Gets the transform options
23
+ */
24
+ getTransform(): ITransformOptions;
25
+ /**
26
+ * Sets particle emission rate.
27
+ * In continuous mode (`emitTime`=0), this is particles per second.
28
+ * In burst mode (`emitTime`>0), this is particles per burst.
29
+ * @param rate - The emission rate.
30
+ */
31
+ setEmitRate(rate: number): void;
32
+ /**
33
+ * Sets time interval between emissions. Set to 0 for continuous emission.
34
+ * @param time - Time interval in seconds
35
+ */
36
+ setEmitTime(time: number): void;
37
+ /**
38
+ * Starts emitting particles
39
+ */
40
+ start(): void;
41
+ /**
42
+ * Stops emitting new particles but allows existing ones to complete their lifecycle
43
+ */
44
+ stop(): void;
45
+ /**
46
+ * Clears all particles and resets the emitter
47
+ */
48
+ clear(): void;
49
+ /**
50
+ * Emits a specified number of particles immediately.
51
+ * @param count - Number of particles to emit
52
+ */
53
+ emit(count: number): void;
54
+ /**
55
+ * Updates particle emitter state
56
+ * @param deltaTime - Time in seconds since last update
57
+ */
58
+ onUpdate(deltaTime: number): void;
59
+ /**
60
+ * Renders all particles
61
+ */
62
+ onRender(): void;
63
+ /**
64
+ * Gets current particle count
65
+ */
66
+ getParticleCount(): number;
67
+ /**
68
+ * Checks if the particle emitter is active (has particles or is emitting)
69
+ */
70
+ isActive(): boolean;
71
+ /**
72
+ * Triggers a single burst of particles, regardless of whether the emitter is running.
73
+ * The number of particles is determined by `emitRate`.
74
+ */
75
+ oneShot(): void;
76
+ }