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