rapid-render 0.1.11 → 0.1.13

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 CHANGED
@@ -9,17 +9,23 @@ A highly efficient ([stress-test](https://nightre.github.io/Rapid.js/docs/exampl
9
9
 
10
10
  ## Features
11
11
 
12
- * **Fast Rendering**
13
- * **TileMap** - YSort, isometric
14
- * **Graphics Drawing**
15
- * **Text Rendering**
16
- * **Line Drawing** - line texture
17
- * **Custom Shaders**
18
- * **Mask**
19
- * **Frame Buffer Object**
20
-
21
- > [!WARNING]
22
- > This project is a work in progress! Expect bugs, report issues, and feel free to contribute.
12
+ * **Fast Rendering**
13
+ * **TileMap** - YSort, isometric 🗺️
14
+ * **Light Shadow** 💡
15
+ * **Particle** 🎆
16
+ * **Camera** 🎥
17
+ * **Graphics Drawing** ✏️
18
+ * **Text Rendering** 📝
19
+ * **Line Drawing** - line texture 〰️
20
+ * **Custom Shaders** 🎨
21
+ * **Mask** 🎭
22
+ * **Frame Buffer Object** 🖼️
23
+
24
+ ## Performance Testing
25
+
26
+ 32x32 Texture Sprites 60FPS
27
+
28
+ * `Intel® Iris® Xe Graphics` : 42K sprites
23
29
 
24
30
  ## Install
25
31
 
@@ -59,7 +65,7 @@ For more examples and detailed documentation, visit our [website](https://nightr
59
65
 
60
66
  ## Roadmap
61
67
 
62
- * Light System 🚧 (In Progress)
68
+ * 9-slice 🚧 (In Progress)
63
69
  * Nodejs Support
64
70
 
65
71
  ## Contributing
@@ -69,4 +75,6 @@ Issues and PRs are welcome!
69
75
  ## Screen shot
70
76
 
71
77
  ![1](./screenshot/1.gif)
72
- ![2](./screenshot/2.gif)
78
+ ![2](./screenshot/2.gif)
79
+ ![3](./screenshot/3.png)
80
+ ![4](./screenshot/4.png)
package/dist/index.d.ts CHANGED
@@ -1,11 +1,13 @@
1
- import Rapid from "./render";
2
- import GLShader from "./webgl/glshader";
3
- import { Text } from "./texture";
4
- import { TileMapRender, TileSet } from "./tilemap";
5
- import { Uniform } from "./webgl/uniform";
6
- import { spriteAttributes, graphicAttributes } from "./regions/attributes";
7
- export { Text, Rapid, GLShader, TileMapRender, TileSet, Uniform, graphicAttributes, spriteAttributes, };
8
- export * from "./math";
9
- export * from "./interface";
10
- export * from "./texture";
11
- export * from "./render";
1
+ import Rapid from "./render";
2
+ import GLShader from "./webgl/glshader";
3
+ import { Text } from "./texture";
4
+ import { TileMapRender, TileSet } from "./tilemap";
5
+ import { Uniform } from "./webgl/uniform";
6
+ import { spriteAttributes, graphicAttributes } from "./regions/attributes";
7
+ import { ParticleEmitter } from "./particle";
8
+ export { Text, Rapid, GLShader, TileMapRender, TileSet, Uniform, ParticleEmitter, graphicAttributes, spriteAttributes, };
9
+ export * from "./math";
10
+ export * from "./interface";
11
+ export * from "./texture";
12
+ export * from "./render";
13
+ export * from "./particle";
@@ -1,165 +1,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 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 interface IParticleEmitterOptions extends ITransformOptions, IShaderRenderOptions {
159
- texture: Texture | Texture[] | [Texture, number][];
160
- }
161
- export declare enum BlendMode {
162
- Additive = "additive",
163
- Subtractive = "subtractive",
164
- Mix = "mix"
165
- }
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
+ };
package/dist/light.d.ts CHANGED
@@ -1,5 +1,7 @@
1
- import Rapid from "./render";
2
- export declare class LightManager {
3
- render: Rapid;
4
- constructor(render: Rapid);
5
- }
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
+ }