rapid-render 0.1.13 → 0.1.15

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.
@@ -1,312 +1,325 @@
1
- import { Color, Vec2 } from "./math";
2
- import { Texture } from "./texture";
3
- import { TileSet } from "./tilemap";
4
- import GLShader from "./webgl/glshader";
5
- import { Uniform } from "./webgl/uniform";
6
- /**
7
- * @ignore
8
- */
9
- export type WebGLContext = WebGL2RenderingContext | WebGLRenderingContext;
10
- /**
11
- * @ignore
12
- */
13
- export interface IMathStruct<T> {
14
- clone(obj: T): T;
15
- copy(obj: T): void;
16
- equal(obj: T): boolean;
17
- }
18
- export interface IRapidOptions {
19
- canvas: HTMLCanvasElement;
20
- width?: number;
21
- height?: number;
22
- backgroundColor?: Color;
23
- antialias?: boolean;
24
- }
25
- export interface IAttribute {
26
- name: string;
27
- size: number;
28
- type: number;
29
- normalized?: boolean;
30
- stride: number;
31
- offset?: number;
32
- }
33
- export interface ITransformOptions {
34
- position?: Vec2;
35
- scale?: Vec2 | number;
36
- rotation?: number;
37
- offset?: Vec2;
38
- x?: number;
39
- y?: number;
40
- offsetX?: number;
41
- offsetY?: number;
42
- origin?: Vec2 | number;
43
- restoreTransform?: boolean;
44
- saveTransform?: boolean;
45
- afterSave?(): unknown;
46
- beforRestore?(): unknown;
47
- }
48
- export interface ISpriteRenderOptions extends ITransformOptions, IShaderRenderOptions {
49
- color?: Color;
50
- texture?: Texture;
51
- offset?: Vec2;
52
- flipX?: boolean;
53
- flipY?: boolean;
54
- }
55
- export interface ITextTextureOptions {
56
- /**
57
- * The text string to be rendered.
58
- */
59
- text?: string;
60
- /**
61
- * The font size for the text.
62
- * Default is 16.
63
- */
64
- fontSize?: number;
65
- /**
66
- * The font family for the text.
67
- * Default is 'Arial'.
68
- */
69
- fontFamily?: string;
70
- /**
71
- * The color of the text.
72
- * Default is '#000000' (black).
73
- */
74
- color?: string;
75
- /**
76
- * The alignment of the text.
77
- * Possible values: 'left', 'right', 'center', 'start', 'end'.
78
- * Default is 'left'.
79
- */
80
- textAlign?: CanvasTextAlign;
81
- /**
82
- * The baseline of the text.
83
- * Possible values: 'top', 'hanging', 'middle', 'alphabetic', 'ideographic', 'bottom'.
84
- * Default is 'top'.
85
- */
86
- textBaseline?: CanvasTextBaseline;
87
- }
88
- export interface ILineRenderOptions extends IGraphicRenderOptions {
89
- width?: number;
90
- closed?: boolean;
91
- roundCap?: boolean;
92
- textureMode?: LineTextureMode;
93
- }
94
- export declare enum LineTextureMode {
95
- STRETCH = "stretch",
96
- REPEAT = "repeat"
97
- }
98
- export declare enum TextureWrapMode {
99
- REPEAT = "repeat",
100
- CLAMP = "clamp",
101
- MIRROR = "mirror"
102
- }
103
- export interface IRenderLineOptions extends ILineRenderOptions, ITransformOptions {
104
- }
105
- export interface IGraphicRenderOptions extends ITransformOptions, IShaderRenderOptions {
106
- points: Vec2[];
107
- color?: Color | Color[];
108
- drawType?: number;
109
- uv?: Vec2[];
110
- texture?: Texture;
111
- }
112
- export interface ICircleRenderOptions extends IGraphicRenderOptions {
113
- radius: number;
114
- segments?: number;
115
- }
116
- export interface IRectRenderOptions extends IGraphicRenderOptions {
117
- width: number;
118
- height: number;
119
- }
120
- export declare enum MaskType {
121
- Include = "normal",
122
- Exclude = "inverse"
123
- }
124
- export type UniformType = Record<string, number | Array<any> | boolean | Texture>;
125
- export type Images = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas;
126
- export interface IRegisterTileOptions extends ISpriteRenderOptions {
127
- texture: Texture;
128
- offsetX?: number;
129
- offsetY?: number;
130
- ySortOffset?: number;
131
- }
132
- export interface YSortCallback {
133
- ySort: number;
134
- render?: () => void;
135
- renderSprite?: ISpriteRenderOptions;
136
- }
137
- export interface ILayerRenderOptions extends ITransformOptions {
138
- error?: number | Vec2;
139
- errorX?: number;
140
- errorY?: number;
141
- ySortCallback?: Array<YSortCallback>;
142
- shape?: TilemapShape;
143
- tileSet: TileSet;
144
- eachTile?: (tileId: string | number, mapX: number, mapY: number) => ISpriteRenderOptions | undefined | void;
145
- }
146
- export interface IShaderRenderOptions {
147
- shader?: GLShader;
148
- uniforms?: Uniform;
149
- }
150
- export declare enum TilemapShape {
151
- SQUARE = "square",
152
- ISOMETRIC = "isometric"
153
- }
154
- export declare enum ShaderType {
155
- SPRITE = "sprite",
156
- GRAPHIC = "graphic"
157
- }
158
- export declare enum BlendMode {
159
- Additive = "additive",
160
- Subtractive = "subtractive",
161
- Mix = "mix"
162
- }
163
- /**
164
- * Interface for light rendering options
165
- */
166
- export interface ILightRenderOptions {
167
- /** Position of the light source */
168
- lightSource: Vec2;
169
- /** Array of vertex arrays for occlusion objects, each occlusion object is defined by a set of vertices */
170
- occlusion: Vec2[][];
171
- /** Base projection length that controls shadow length */
172
- baseProjectionLength?: number;
173
- /** Type of mask to apply */
174
- type?: MaskType;
175
- }
176
- export interface ICameraOptions extends ITransformOptions {
177
- }
178
- /**
179
- * Defines particle emitter shape types
180
- */
181
- export declare enum ParticleShape {
182
- /**
183
- * Point emitter, emits particles from a single point
184
- */
185
- POINT = "point",
186
- /**
187
- * Circle emitter, emits particles randomly from a circular area
188
- */
189
- CIRCLE = "circle",
190
- /**
191
- * Rectangle emitter, emits particles randomly from a rectangular area
192
- */
193
- RECT = "rect"
194
- }
195
- /**
196
- * Defines particle attribute animation
197
- * @template T Attribute type, can be number, vector or color
198
- */
199
- export interface ParticleAttribute<T extends number | Vec2 | Color> {
200
- /**
201
- * Damping coefficient, controls attribute decay rate over time
202
- */
203
- damping?: number;
204
- /**
205
- * Initial attribute value
206
- */
207
- start: T;
208
- /**
209
- * Final attribute value, uses initial value if not specified
210
- */
211
- end?: T;
212
- /**
213
- * Attribute change rate, automatically calculated from start and end if not specified
214
- */
215
- delta?: T;
216
- }
217
- /**
218
- * Particle system configuration options
219
- */
220
- export interface IParticleOptions extends ITransformOptions, IShaderRenderOptions {
221
- /**
222
- * Particle texture, can be a single texture, array of textures, or weighted texture array
223
- */
224
- texture: Texture | Texture[] | [Texture, number][];
225
- /**
226
- * Particle emission rate (particles per second)
227
- */
228
- emitRate?: number;
229
- /**
230
- * Emission time interval in seconds
231
- */
232
- emitTime?: number;
233
- /**
234
- * Maximum number of particles limit
235
- */
236
- maxParticles?: number;
237
- /**
238
- * Particle lifetime in seconds, can be fixed value or range
239
- */
240
- life?: number | [number, number];
241
- /**
242
- * Particle animation properties collection
243
- */
244
- animation: {
245
- /**
246
- * Velocity vector, controls particle movement direction and speed
247
- */
248
- velocity?: ParticleAttribute<Vec2>;
249
- /**
250
- * Acceleration vector, controls particle velocity changes
251
- */
252
- acceleration?: ParticleAttribute<Vec2>;
253
- /**
254
- * Speed scalar, used in combination with rotation direction
255
- */
256
- speed?: ParticleAttribute<number>;
257
- /**
258
- * Scale factor, controls particle size
259
- */
260
- scale?: ParticleAttribute<number>;
261
- /**
262
- * Rotation angle (in radians)
263
- */
264
- rotation?: ParticleAttribute<number>;
265
- /**
266
- * Color and transparency
267
- */
268
- color?: ParticleAttribute<Color>;
269
- };
270
- /**
271
- * Emitter shape
272
- */
273
- emitShape?: ParticleShape;
274
- /**
275
- * Circular emitter radius
276
- */
277
- emitRadius?: number;
278
- /**
279
- * Rectangular emitter dimensions
280
- */
281
- emitRect?: {
282
- width: number;
283
- height: number;
284
- };
285
- /**
286
- * Whether to use local coordinate system, true means particles are relative to emitter position,
287
- * false means using global coordinates
288
- */
289
- localSpace?: boolean;
290
- }
291
- /**
292
- * Particle attribute data types
293
- */
294
- export type ParticleAttributeTypes = number | Vec2 | Color;
295
- /**
296
- * Particle attribute runtime data
297
- * @template T Attribute type
298
- */
299
- export type ParticleAttributeData<T extends ParticleAttributeTypes> = {
300
- /**
301
- * Attribute change rate per second
302
- */
303
- delta?: T;
304
- /**
305
- * Current attribute value
306
- */
307
- value: T;
308
- /**
309
- * Damping coefficient
310
- */
311
- damping?: number;
312
- };
1
+ import { Color, Vec2 } from "./math";
2
+ import { Texture } from "./texture";
3
+ import { TileSet } from "./tilemap";
4
+ import GLShader from "./webgl/glshader";
5
+ import { Uniform } from "./webgl/uniform";
6
+ /**
7
+ * @ignore
8
+ */
9
+ export type WebGLContext = WebGL2RenderingContext | WebGLRenderingContext;
10
+ /**
11
+ * @ignore
12
+ */
13
+ export interface IMathStruct<T> {
14
+ clone(obj: T): T;
15
+ copy(obj: T): void;
16
+ equal(obj: T): boolean;
17
+ }
18
+ export declare enum ScaleRadio {
19
+ KEEP = "keep",
20
+ KEEP_H = "keep_h",
21
+ KEEP_W = "keep_w",
22
+ IGNORE = "ignore",
23
+ EXPAND = "expand"
24
+ }
25
+ export interface IRapidOptions {
26
+ canvas: HTMLCanvasElement;
27
+ width?: number;
28
+ height?: number;
29
+ backgroundColor?: Color;
30
+ antialias?: boolean;
31
+ devicePixelRatio?: number;
32
+ scaleEnable?: boolean;
33
+ scaleRadio?: ScaleRadio;
34
+ }
35
+ export interface IAttribute {
36
+ name: string;
37
+ size: number;
38
+ type: number;
39
+ normalized?: boolean;
40
+ stride: number;
41
+ offset?: number;
42
+ }
43
+ export interface ITransformOptions {
44
+ position?: Vec2;
45
+ scale?: Vec2 | number;
46
+ rotation?: number;
47
+ offset?: Vec2;
48
+ x?: number;
49
+ y?: number;
50
+ offsetX?: number;
51
+ offsetY?: number;
52
+ origin?: Vec2 | number;
53
+ restoreTransform?: boolean;
54
+ saveTransform?: boolean;
55
+ afterSave?(): unknown;
56
+ beforRestore?(): unknown;
57
+ }
58
+ export interface ISpriteRenderOptions extends ITransformOptions, IShaderRenderOptions {
59
+ color?: Color;
60
+ texture?: Texture;
61
+ offset?: Vec2;
62
+ flipX?: boolean;
63
+ flipY?: boolean;
64
+ }
65
+ export interface ITextTextureOptions {
66
+ /**
67
+ * The text string to be rendered.
68
+ */
69
+ text?: string;
70
+ /**
71
+ * The font size for the text.
72
+ * Default is 16.
73
+ */
74
+ fontSize?: number;
75
+ /**
76
+ * The font family for the text.
77
+ * Default is 'Arial'.
78
+ */
79
+ fontFamily?: string;
80
+ /**
81
+ * The color of the text.
82
+ * Default is '#000000' (black).
83
+ */
84
+ color?: string;
85
+ /**
86
+ * The alignment of the text.
87
+ * Possible values: 'left', 'right', 'center', 'start', 'end'.
88
+ * Default is 'left'.
89
+ */
90
+ textAlign?: CanvasTextAlign;
91
+ /**
92
+ * The baseline of the text.
93
+ * Possible values: 'top', 'hanging', 'middle', 'alphabetic', 'ideographic', 'bottom'.
94
+ * Default is 'top'.
95
+ */
96
+ textBaseline?: CanvasTextBaseline;
97
+ }
98
+ export interface ILineStyleOptions extends IGraphicRenderOptions {
99
+ width?: number;
100
+ closed?: boolean;
101
+ roundCap?: boolean;
102
+ textureMode?: LineTextureMode;
103
+ points: Vec2[];
104
+ }
105
+ export declare enum LineTextureMode {
106
+ STRETCH = "stretch",
107
+ REPEAT = "repeat"
108
+ }
109
+ export declare enum TextureWrapMode {
110
+ REPEAT = "repeat",
111
+ CLAMP = "clamp",
112
+ MIRROR = "mirror"
113
+ }
114
+ export interface IRenderLineOptions extends ILineStyleOptions, ITransformOptions {
115
+ }
116
+ export interface IGraphicRenderOptions extends ITransformOptions, IShaderRenderOptions {
117
+ color?: Color | Color[];
118
+ drawType?: number;
119
+ uv?: Vec2[];
120
+ texture?: Texture;
121
+ }
122
+ export interface IPolygonGraphicRenderOptions extends IGraphicRenderOptions {
123
+ points: Vec2[];
124
+ }
125
+ export interface ICircleRenderOptions extends IGraphicRenderOptions {
126
+ radius: number;
127
+ segments?: number;
128
+ }
129
+ export interface IRectRenderOptions extends IGraphicRenderOptions {
130
+ width: number;
131
+ height: number;
132
+ }
133
+ export declare enum MaskType {
134
+ Include = "normal",
135
+ Exclude = "inverse"
136
+ }
137
+ export type UniformType = Record<string, number | Array<any> | boolean | Texture>;
138
+ export type Images = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas;
139
+ export interface IRegisterTileOptions extends ISpriteRenderOptions {
140
+ texture: Texture;
141
+ offsetX?: number;
142
+ offsetY?: number;
143
+ ySortOffset?: number;
144
+ }
145
+ export interface YSortCallback {
146
+ ySort: number;
147
+ render?: () => void;
148
+ renderSprite?: ISpriteRenderOptions;
149
+ }
150
+ export interface ILayerRenderOptions extends ITransformOptions {
151
+ error?: number | Vec2;
152
+ errorX?: number;
153
+ errorY?: number;
154
+ ySortCallback?: Array<YSortCallback>;
155
+ shape?: TilemapShape;
156
+ tileSet: TileSet;
157
+ eachTile?: (tileId: string | number, mapX: number, mapY: number) => ISpriteRenderOptions | undefined | void;
158
+ }
159
+ export interface IShaderRenderOptions {
160
+ shader?: GLShader;
161
+ uniforms?: Uniform;
162
+ }
163
+ export declare enum TilemapShape {
164
+ SQUARE = "square",
165
+ ISOMETRIC = "isometric"
166
+ }
167
+ export declare enum ShaderType {
168
+ SPRITE = "sprite",
169
+ GRAPHIC = "graphic"
170
+ }
171
+ export declare enum BlendMode {
172
+ Additive = "additive",
173
+ Subtractive = "subtractive",
174
+ Mix = "mix"
175
+ }
176
+ /**
177
+ * Interface for light rendering options
178
+ */
179
+ export interface ILightRenderOptions {
180
+ /** Position of the light source */
181
+ lightSource: Vec2;
182
+ /** Array of vertex arrays for occlusion objects, each occlusion object is defined by a set of vertices */
183
+ occlusion: Vec2[][];
184
+ /** Base projection length that controls shadow length */
185
+ baseProjectionLength?: number;
186
+ /** Type of mask to apply */
187
+ type?: MaskType;
188
+ }
189
+ export interface ICameraOptions extends ITransformOptions {
190
+ }
191
+ /**
192
+ * Defines particle emitter shape types
193
+ */
194
+ export declare enum ParticleShape {
195
+ /**
196
+ * Point emitter, emits particles from a single point
197
+ */
198
+ POINT = "point",
199
+ /**
200
+ * Circle emitter, emits particles randomly from a circular area
201
+ */
202
+ CIRCLE = "circle",
203
+ /**
204
+ * Rectangle emitter, emits particles randomly from a rectangular area
205
+ */
206
+ RECT = "rect"
207
+ }
208
+ /**
209
+ * Defines particle attribute animation
210
+ * @template T Attribute type, can be number, vector or color
211
+ */
212
+ export interface ParticleAttribute<T extends number | Vec2 | Color> {
213
+ /**
214
+ * Damping coefficient, controls attribute decay rate over time
215
+ */
216
+ damping?: number;
217
+ /**
218
+ * Initial attribute value
219
+ */
220
+ start: T;
221
+ /**
222
+ * Final attribute value, uses initial value if not specified
223
+ */
224
+ end?: T;
225
+ /**
226
+ * Attribute change rate, automatically calculated from start and end if not specified
227
+ */
228
+ delta?: T;
229
+ }
230
+ /**
231
+ * Particle system configuration options
232
+ */
233
+ export interface IParticleOptions extends ITransformOptions, IShaderRenderOptions {
234
+ /**
235
+ * Particle texture, can be a single texture, array of textures, or weighted texture array
236
+ */
237
+ texture: Texture | Texture[] | [Texture, number][];
238
+ /**
239
+ * Particle emission rate (particles per second)
240
+ */
241
+ emitRate?: number;
242
+ /**
243
+ * Emission time interval in seconds
244
+ */
245
+ emitTime?: number;
246
+ /**
247
+ * Maximum number of particles limit
248
+ */
249
+ maxParticles?: number;
250
+ /**
251
+ * Particle lifetime in seconds, can be fixed value or range
252
+ */
253
+ life?: number | [number, number];
254
+ /**
255
+ * Particle animation properties collection
256
+ */
257
+ animation: {
258
+ /**
259
+ * Velocity vector, controls particle movement direction and speed
260
+ */
261
+ velocity?: ParticleAttribute<Vec2>;
262
+ /**
263
+ * Acceleration vector, controls particle velocity changes
264
+ */
265
+ acceleration?: ParticleAttribute<Vec2>;
266
+ /**
267
+ * Speed scalar, used in combination with rotation direction
268
+ */
269
+ speed?: ParticleAttribute<number>;
270
+ /**
271
+ * Scale factor, controls particle size
272
+ */
273
+ scale?: ParticleAttribute<number>;
274
+ /**
275
+ * Rotation angle (in radians)
276
+ */
277
+ rotation?: ParticleAttribute<number>;
278
+ /**
279
+ * Color and transparency
280
+ */
281
+ color?: ParticleAttribute<Color>;
282
+ };
283
+ /**
284
+ * Emitter shape
285
+ */
286
+ emitShape?: ParticleShape;
287
+ /**
288
+ * Circular emitter radius
289
+ */
290
+ emitRadius?: number;
291
+ /**
292
+ * Rectangular emitter dimensions
293
+ */
294
+ emitRect?: {
295
+ width: number;
296
+ height: number;
297
+ };
298
+ /**
299
+ * Whether to use local coordinate system, true means particles are relative to emitter position,
300
+ * false means using global coordinates
301
+ */
302
+ localSpace?: boolean;
303
+ }
304
+ /**
305
+ * Particle attribute data types
306
+ */
307
+ export type ParticleAttributeTypes = number | Vec2 | Color;
308
+ /**
309
+ * Particle attribute runtime data
310
+ * @template T Attribute type
311
+ */
312
+ export type ParticleAttributeData<T extends ParticleAttributeTypes> = {
313
+ /**
314
+ * Attribute change rate per second
315
+ */
316
+ delta?: T;
317
+ /**
318
+ * Current attribute value
319
+ */
320
+ value: T;
321
+ /**
322
+ * Damping coefficient
323
+ */
324
+ damping?: number;
325
+ };
package/dist/light.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { Vec2 } from "./math";
2
- import Rapid from "./render";
3
- export declare class LightManager {
4
- render: Rapid;
5
- constructor(render: Rapid);
6
- createLightShadowMaskPolygon(occlusion: Vec2[][], lightSource: Vec2, baseProjectionLength?: number): Vec2[][];
7
- }
1
+ import { Vec2 } from "./math";
2
+ import Rapid from "./render";
3
+ export declare class LightManager {
4
+ render: Rapid;
5
+ constructor(render: Rapid);
6
+ createLightShadowMaskPolygon(occlusion: Vec2[][], lightSource: Vec2, baseProjectionLength?: number): Vec2[][];
7
+ }