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/dist/render.d.ts CHANGED
@@ -1,237 +1,248 @@
1
- import { ICircleRenderOptions, IGraphicRenderOptions, ILayerRenderOptions, IRapidOptions, IRectRenderOptions, IRenderLineOptions, ISpriteRenderOptions, ShaderType as ShaderType, MaskType, WebGLContext, BlendMode } from "./interface";
2
- import { LightManager } from "./light";
3
- import { Color, MatrixStack, Vec2 } from "./math";
4
- import RenderRegion from "./regions/region";
5
- import { FrameBufferObject, Texture, TextureCache } from "./texture";
6
- import { TileMapRender, TileSet } from "./tilemap";
7
- import GLShader from "./webgl/glshader";
8
- /**
9
- * The `Rapid` class provides a WebGL-based rendering engine.
10
- */
11
- declare class Rapid {
12
- gl: WebGLContext;
13
- canvas: HTMLCanvasElement;
14
- projection: Float32Array;
15
- projectionDirty: boolean;
16
- matrixStack: MatrixStack;
17
- textures: TextureCache;
18
- tileMap: TileMapRender;
19
- light: LightManager;
20
- width: number;
21
- height: number;
22
- backgroundColor: Color;
23
- readonly devicePixelRatio: number;
24
- readonly maxTextureUnits: number;
25
- private readonly defaultColor;
26
- private currentRegion?;
27
- private currentRegionName?;
28
- private regions;
29
- private currentMaskType;
30
- private currentTransform;
31
- private currentFBO;
32
- /**
33
- * Constructs a new `Rapid` instance with the given options.
34
- * @param options - Options for initializing the `Rapid` instance.
35
- */
36
- constructor(options: IRapidOptions);
37
- /**
38
- * Render a tile map layer.
39
- * @param data - The map data to render.
40
- * @param options - The options for rendering the tile map layer.
41
- */
42
- renderTileMapLayer(data: (number | string)[][], options: ILayerRenderOptions | TileSet): void;
43
- /**
44
- * Initializes WebGL context settings.
45
- * @param gl - The WebGL context.
46
- */
47
- private initWebgl;
48
- /**
49
- * @ignore
50
- */
51
- clearTextureUnit(): void;
52
- /**
53
- * Registers built-in regions such as sprite and graphic regions.
54
- */
55
- private registerBuildInRegion;
56
- /**
57
- * Registers a custom render region with a specified name.
58
- * @param name - The name of the region.
59
- * @param regionClass - The class of the region to register.
60
- */
61
- registerRegion(name: string, regionClass: typeof RenderRegion): void;
62
- private quitCurrentRegion;
63
- /**
64
- * Sets the current render region by name and optionally a custom shader.
65
- * @param regionName - The name of the region to set as current.
66
- * @param customShader - An optional custom shader to use with the region.
67
- * @param hasUnifrom - have costum unifrom
68
- */
69
- setRegion(regionName: string, customShader?: GLShader): void;
70
- /**
71
- * Saves the current matrix state to the stack.
72
- */
73
- save(): void;
74
- /**
75
- * Restores the matrix state from the stack.
76
- */
77
- restore(): void;
78
- /**
79
- * Executes a callback function within a saved and restored matrix state scope.
80
- * @param cb - The callback function to execute within the saved and restored matrix state scope.
81
- */
82
- withTransform(cb: () => void): void;
83
- /**
84
- * Starts the rendering process, resetting the matrix stack and clearing the current region.
85
- * @param clear - Whether to clear the matrix stack. Defaults to true.
86
- */
87
- startRender(clear?: boolean): void;
88
- /**
89
- * Ends the rendering process by rendering the current region.
90
- */
91
- endRender(): void;
92
- /**
93
- * Render
94
- * @param cb - The function to render.
95
- */
96
- render(cb: () => void): void;
97
- /**
98
- * Renders a sprite with the specified options.
99
- *
100
- * @param options - The rendering options for the sprite, including texture, position, color, and shader.
101
- */
102
- renderSprite(options: ISpriteRenderOptions): void;
103
- /**
104
- * Renders a texture directly without additional options.
105
- * This is a convenience method that calls renderSprite with just the texture.
106
- *
107
- * @param texture - The texture to render at the current transformation position.
108
- */
109
- renderTexture(texture: Texture): void;
110
- /**
111
- * Renders a line with the specified options.
112
- *
113
- * @param options - The options for rendering the line, including points, color, width, and join/cap types.
114
- */
115
- renderLine(options: IRenderLineOptions): void;
116
- /**
117
- * Renders graphics based on the provided options.
118
- *
119
- * @param options - The options for rendering the graphic, including points, color, texture, and draw type.
120
- */
121
- renderGraphic(options: IGraphicRenderOptions): void;
122
- /**
123
- * Starts the graphic drawing process.
124
- *
125
- * @param options - The options for the graphic drawing, including shader, texture, and draw type.
126
- */
127
- startGraphicDraw(options: IGraphicRenderOptions): void;
128
- /**
129
- * Adds a vertex to the current graphic being drawn.
130
- *
131
- * @param offsetX - The X coordinate of the vertex.
132
- * @param offsetY - The Y coordinate of the vertex.
133
- * @param uv - The texture UV coordinates for the vertex.
134
- * @param color - The color of the vertex. Defaults to the renderer's default color.
135
- */
136
- addGraphicVertex(offsetX: number, offsetY: number, uv: Vec2, color?: Color): void;
137
- /**
138
- * Completes the graphic drawing process and renders the result.
139
- */
140
- endGraphicDraw(): void;
141
- private startDraw;
142
- private afterDraw;
143
- /**
144
- * Renders a rectangle with the specified options.
145
- *
146
- * @param options - The options for rendering the rectangle, including width, height, position, and color.
147
- */
148
- renderRect(options: IRectRenderOptions): void;
149
- /**
150
- * Renders a circle with the specified options.
151
- *
152
- * @param options - The options for rendering the circle, including radius, position, color, and segment count.
153
- */
154
- renderCircle(options: ICircleRenderOptions): void;
155
- /**
156
- * Resizes the canvas and updates the viewport and projection matrix.
157
- * @param width - The new width of the canvas.
158
- * @param height - The new height of the canvas.
159
- */
160
- resize(logicalWidth: number, logicalHeight: number): void;
161
- private resizeWebglSize;
162
- private updateProjection;
163
- /**
164
- * Clears the canvas with the background color.
165
- * @param bgColor - The background color to clear the canvas with.
166
- */
167
- clear(bgColor?: Color): void;
168
- /**
169
- * Creates an orthogonal projection matrix.
170
- * @param left - The left bound of the projection.
171
- * @param right - The right bound of the projection.
172
- * @param bottom - The bottom bound of the projection.
173
- * @param top - The top bound of the projection.
174
- * @returns The orthogonal projection matrix as a `Float32Array`.
175
- */
176
- private createOrthMatrix;
177
- /**
178
- * Draw a mask. Automatically calls startDrawMask.
179
- * @param type - The type of mask to draw.
180
- * @param cb - The callback function to execute.
181
- */
182
- drawMask(type: MaskType | undefined, cb: () => void): void;
183
- /**
184
- * Start drawing a mask using the stencil buffer.
185
- * This method configures the WebGL context to begin defining a mask area.
186
- */
187
- startDrawMask(type?: MaskType): void;
188
- /**
189
- * End the mask drawing process.
190
- * This method configures the WebGL context to use the defined mask for subsequent rendering.
191
- */
192
- endDrawMask(): void;
193
- /**
194
- * Set the mask type for rendering
195
- * @param type - The mask type to apply
196
- * @param start - Whether this is the start of mask drawing
197
- */
198
- private setMaskType;
199
- /**
200
- * Clear the current mask by clearing the stencil buffer.
201
- * This effectively removes any previously defined mask.
202
- */
203
- clearMask(): void;
204
- /**
205
- * Creates a custom shader.
206
- * @param vs - Vertex shader code.
207
- * @param fs - Fragment shader code.
208
- * @param type - Shader type.
209
- * @returns The created shader object.
210
- */
211
- createCostumShader(vs: string, fs: string, type: ShaderType, textureUnitNum?: number): GLShader;
212
- /**
213
- * Starts rendering to a Frame Buffer Object (FBO)
214
- * Sets up the FBO for rendering by binding it, adjusting viewport size and projection
215
- * @param fbo - The Frame Buffer Object to render to
216
- */
217
- startFBO(fbo: FrameBufferObject): void;
218
- /**
219
- * Ends rendering to a Frame Buffer Object
220
- * Restores the default framebuffer and original viewport settings
221
- * @param fbo - The Frame Buffer Object to unbind
222
- */
223
- endFBO(): void;
224
- /**
225
- * Convenience method to render to a Frame Buffer Object
226
- * Handles starting and ending the FBO rendering automatically
227
- * @param fbo - The Frame Buffer Object to render to
228
- * @param cb - Callback function containing render commands to execute on the FBO
229
- */
230
- drawToFBO(fbo: FrameBufferObject, cb: () => void): void;
231
- /**
232
- * Set the blend mode for rendering
233
- * @param mode - The blend mode to apply
234
- */
235
- setBlendMode(mode: BlendMode): void;
236
- }
237
- export default Rapid;
1
+ import { ICircleRenderOptions, IGraphicRenderOptions, ILayerRenderOptions, IRapidOptions, IRectRenderOptions, IRenderLineOptions, ISpriteRenderOptions, ShaderType as ShaderType, MaskType, WebGLContext, BlendMode, ILightRenderOptions, IParticleOptions, ICameraOptions } from "./interface";
2
+ import { LightManager } from "./light";
3
+ import { Color, MatrixStack, Vec2 } from "./math";
4
+ import RenderRegion from "./regions/region";
5
+ import { FrameBufferObject, Texture, TextureCache } from "./texture";
6
+ import { TileMapRender, TileSet } from "./tilemap";
7
+ import GLShader from "./webgl/glshader";
8
+ import { ParticleEmitter } from "./particle";
9
+ /**
10
+ * The `Rapid` class provides a WebGL-based rendering engine.
11
+ */
12
+ declare class Rapid {
13
+ gl: WebGLContext;
14
+ canvas: HTMLCanvasElement;
15
+ projection: Float32Array;
16
+ projectionDirty: boolean;
17
+ matrixStack: MatrixStack;
18
+ textures: TextureCache;
19
+ tileMap: TileMapRender;
20
+ light: LightManager;
21
+ width: number;
22
+ height: number;
23
+ backgroundColor: Color;
24
+ readonly devicePixelRatio: number;
25
+ readonly maxTextureUnits: number;
26
+ private readonly defaultColor;
27
+ private currentRegion?;
28
+ private currentRegionName?;
29
+ private regions;
30
+ private currentMaskType;
31
+ private currentTransform;
32
+ private currentFBO;
33
+ private lastTime;
34
+ /**
35
+ * Constructs a new `Rapid` instance with the given options.
36
+ * @param options - Options for initializing the `Rapid` instance.
37
+ */
38
+ constructor(options: IRapidOptions);
39
+ /**
40
+ * Render a tile map layer.
41
+ * @param data - The map data to render.
42
+ * @param options - The options for rendering the tile map layer.
43
+ */
44
+ renderTileMapLayer(data: (number | string)[][], options: ILayerRenderOptions | TileSet): void;
45
+ /**
46
+ * Initializes WebGL context settings.
47
+ * @param gl - The WebGL context.
48
+ */
49
+ private initWebgl;
50
+ /**
51
+ * @ignore
52
+ */
53
+ clearTextureUnit(): void;
54
+ /**
55
+ * Registers built-in regions such as sprite and graphic regions.
56
+ */
57
+ private registerBuildInRegion;
58
+ /**
59
+ * Registers a custom render region with a specified name.
60
+ * @param name - The name of the region.
61
+ * @param regionClass - The class of the region to register.
62
+ */
63
+ registerRegion(name: string, regionClass: typeof RenderRegion): void;
64
+ private quitCurrentRegion;
65
+ /**
66
+ * Sets the current render region by name and optionally a custom shader.
67
+ * @param regionName - The name of the region to set as current.
68
+ * @param customShader - An optional custom shader to use with the region.
69
+ * @param hasUnifrom - have costum unifrom
70
+ */
71
+ setRegion(regionName: string, customShader?: GLShader): void;
72
+ /**
73
+ * Saves the current matrix state to the stack.
74
+ */
75
+ save(): void;
76
+ /**
77
+ * Restores the matrix state from the stack.
78
+ */
79
+ restore(): void;
80
+ /**
81
+ * Executes a callback function within a saved and restored matrix state scope.
82
+ * @param cb - The callback function to execute within the saved and restored matrix state scope.
83
+ */
84
+ withTransform(cb: () => void): void;
85
+ /**
86
+ * Starts the rendering process, resetting the matrix stack and clearing the current region.
87
+ * @param clear - Whether to clear the matrix stack. Defaults to true.
88
+ */
89
+ startRender(clear?: boolean): number;
90
+ /**
91
+ * Ends the rendering process by rendering the current region.
92
+ */
93
+ endRender(): void;
94
+ /**
95
+ * Render
96
+ * @param cb - The function to render.
97
+ */
98
+ render(cb: (dt: number) => void): void;
99
+ renderCamera(options: ICameraOptions): void;
100
+ /**
101
+ * Renders a sprite with the specified options.
102
+ *
103
+ * @param options - The rendering options for the sprite, including texture, position, color, and shader.
104
+ */
105
+ renderSprite(options: ISpriteRenderOptions): void;
106
+ renderParticles(particleEmitter: ParticleEmitter): void;
107
+ /**
108
+ * Renders a texture directly without additional options.
109
+ * This is a convenience method that calls renderSprite with just the texture.
110
+ *
111
+ * @param texture - The texture to render at the current transformation position.
112
+ */
113
+ renderTexture(texture: Texture): void;
114
+ /**
115
+ * Renders a line with the specified options.
116
+ *
117
+ * @param options - The options for rendering the line, including points, color, width, and join/cap types.
118
+ */
119
+ renderLine(options: IRenderLineOptions): void;
120
+ /**
121
+ * Renders graphics based on the provided options.
122
+ *
123
+ * @param options - The options for rendering the graphic, including points, color, texture, and draw type.
124
+ */
125
+ renderGraphic(options: IGraphicRenderOptions): void;
126
+ /**
127
+ * Starts the graphic drawing process.
128
+ *
129
+ * @param options - The options for the graphic drawing, including shader, texture, and draw type.
130
+ */
131
+ startGraphicDraw(options: IGraphicRenderOptions): void;
132
+ /**
133
+ * Adds a vertex to the current graphic being drawn.
134
+ *
135
+ * @param offsetX - The X coordinate of the vertex.
136
+ * @param offsetY - The Y coordinate of the vertex.
137
+ * @param uv - The texture UV coordinates for the vertex.
138
+ * @param color - The color of the vertex. Defaults to the renderer's default color.
139
+ */
140
+ addGraphicVertex(offsetX: number, offsetY: number, uv: Vec2, color?: Color): void;
141
+ /**
142
+ * Completes the graphic drawing process and renders the result.
143
+ */
144
+ endGraphicDraw(): void;
145
+ private startDraw;
146
+ private afterDraw;
147
+ /**
148
+ * Renders a rectangle with the specified options.
149
+ *
150
+ * @param options - The options for rendering the rectangle, including width, height, position, and color.
151
+ */
152
+ renderRect(options: IRectRenderOptions): void;
153
+ /**
154
+ * Renders a circle with the specified options.
155
+ *
156
+ * @param options - The options for rendering the circle, including radius, position, color, and segment count.
157
+ */
158
+ renderCircle(options: ICircleRenderOptions): void;
159
+ /**
160
+ * Resizes the canvas and updates the viewport and projection matrix.
161
+ * @param width - The new width of the canvas.
162
+ * @param height - The new height of the canvas.
163
+ */
164
+ resize(logicalWidth: number, logicalHeight: number): void;
165
+ private resizeWebglSize;
166
+ private updateProjection;
167
+ /**
168
+ * Clears the canvas with the background color.
169
+ * @param bgColor - The background color to clear the canvas with.
170
+ */
171
+ clear(bgColor?: Color): void;
172
+ /**
173
+ * Creates an orthogonal projection matrix.
174
+ * @param left - The left bound of the projection.
175
+ * @param right - The right bound of the projection.
176
+ * @param bottom - The bottom bound of the projection.
177
+ * @param top - The top bound of the projection.
178
+ * @returns The orthogonal projection matrix as a `Float32Array`.
179
+ */
180
+ private createOrthMatrix;
181
+ /**
182
+ * Draw a mask. Automatically calls startDrawMask.
183
+ * @param type - The type of mask to draw.
184
+ * @param cb - The callback function to execute.
185
+ */
186
+ drawMask(type: MaskType | undefined, cb: () => void): void;
187
+ /**
188
+ * Start drawing a mask using the stencil buffer.
189
+ * This method configures the WebGL context to begin defining a mask area.
190
+ */
191
+ startDrawMask(type?: MaskType): void;
192
+ /**
193
+ * End the mask drawing process.
194
+ * This method configures the WebGL context to use the defined mask for subsequent rendering.
195
+ */
196
+ endDrawMask(): void;
197
+ /**
198
+ * Set the mask type for rendering
199
+ * @param type - The mask type to apply
200
+ * @param start - Whether this is the start of mask drawing
201
+ */
202
+ private setMaskType;
203
+ /**
204
+ * Clear the current mask by clearing the stencil buffer.
205
+ * This effectively removes any previously defined mask.
206
+ */
207
+ clearMask(): void;
208
+ /**
209
+ * Creates a custom shader.
210
+ * @param vs - Vertex shader code.
211
+ * @param fs - Fragment shader code.
212
+ * @param type - Shader type.
213
+ * @returns The created shader object.
214
+ */
215
+ createCostumShader(vs: string, fs: string, type: ShaderType, textureUnitNum?: number): GLShader;
216
+ /**
217
+ * Starts rendering to a Frame Buffer Object (FBO)
218
+ * Sets up the FBO for rendering by binding it, adjusting viewport size and projection
219
+ * @param fbo - The Frame Buffer Object to render to
220
+ */
221
+ startFBO(fbo: FrameBufferObject): void;
222
+ /**
223
+ * Ends rendering to a Frame Buffer Object
224
+ * Restores the default framebuffer and original viewport settings
225
+ * @param fbo - The Frame Buffer Object to unbind
226
+ */
227
+ endFBO(): void;
228
+ /**
229
+ * Convenience method to render to a Frame Buffer Object
230
+ * Handles starting and ending the FBO rendering automatically
231
+ * @param fbo - The Frame Buffer Object to render to
232
+ * @param cb - Callback function containing render commands to execute on the FBO
233
+ */
234
+ drawToFBO(fbo: FrameBufferObject, cb: () => void): void;
235
+ /**
236
+ * Set the blend mode for rendering
237
+ * @param mode - The blend mode to apply
238
+ */
239
+ setBlendMode(mode: BlendMode): void;
240
+ /**
241
+ * Render light shadow
242
+ * @param occlusion - The occlusion polygon
243
+ * @param lightSource - The light source position
244
+ */
245
+ drawLightShadowMask(options: ILightRenderOptions): void;
246
+ createParticleEmitter(options: IParticleOptions): ParticleEmitter;
247
+ }
248
+ export default Rapid;
package/dist/utils.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const getSize: (obj: any) => number;
1
+ export declare const isPlainObject: (obj: any) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rapid-render",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -21,15 +21,18 @@
21
21
  "docs": "typedoc"
22
22
  },
23
23
  "devDependencies": {
24
+ "express": "^4.18.2",
24
25
  "rollup": "^4.12.0",
25
26
  "rollup-plugin-dts": "^6.1.0",
26
27
  "rollup-plugin-string": "^3.0.0",
27
28
  "rollup-plugin-terser": "^7.0.2",
28
29
  "rollup-plugin-typescript2": "^0.36.0",
29
30
  "tslib": "^2.6.2",
30
- "typedoc": "^0.26.6",
31
- "typescript": "^5.3.3",
32
- "express": "^4.18.2",
33
- "typedoc-theme-category-nav": "^0.0.3"
31
+ "typedoc-theme-category-nav": "^0.0.3",
32
+ "typescript": "^5.3.3"
33
+ },
34
+ "dependencies": {
35
+ "concurrently": "^9.1.2",
36
+ "typedoc": "^0.28.3"
34
37
  }
35
- }
38
+ }