rapid-render 0.1.2 → 0.1.4
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 +36 -100
- package/dist/depth.d.ts +8 -0
- package/dist/index.d.ts +4 -3
- package/dist/interface.d.ts +83 -34
- package/dist/line.d.ts +8 -1
- package/dist/log.d.ts +2 -0
- package/dist/math.d.ts +218 -44
- package/dist/rapid.global.js +1 -1
- package/dist/rapid.js +2453 -1
- package/dist/rapid.umd.cjs +1 -1
- package/dist/regions/attributes.d.ts +44 -0
- package/dist/regions/graphic_region.d.ts +5 -25
- package/dist/regions/region.d.ts +12 -5
- package/dist/regions/sprite_region.d.ts +2 -26
- package/dist/render.d.ts +91 -49
- package/dist/texture.d.ts +30 -2
- package/dist/tilemap.d.ts +92 -19
- package/dist/utils.d.ts +1 -0
- package/dist/webgl/glshader.d.ts +14 -4
- package/dist/webgl/uniform.d.ts +13 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,128 +1,64 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Rapid.js
|
|
2
2
|
|
|
3
|
-
A highly efficient and lightweight WebGL
|
|
3
|
+
A highly efficient [stress-test](https://nightre.github.io/Rapid.js/docs/examples.htm) and lightweight WebGL-based 2D rendering engine focused on rendering capabilities.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
### [Website](https://nightre.github.io/Rapid.js/docs/index.html)
|
|
6
6
|
|
|
7
|
-
[
|
|
7
|
+
#### [Document](https://nightre.github.io/Rapid.js/docs/docs.html) | [API Docs](https://nightre.github.io/Rapid.js/docs/api/index.html) | [Examples](https://nightre.github.io/Rapid.js/docs/examples.html)
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## Features
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
[mask demo](https://nightre.github.io/Rapid.js/demo/mask.html) ( [source code](./demo/mask.js) )
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
# Features
|
|
17
|
-
* **Fast Rendering**: Render 10,000 sprites at 60fps
|
|
18
|
-
* **Multi-Texture Support**: Batch rendering using GPU's maximum texture units
|
|
11
|
+
* **Fast Rendering**
|
|
12
|
+
* **TileMap** - YSort, isometric
|
|
19
13
|
* **Graphics Drawing**
|
|
20
|
-
* **Matrix Stack**
|
|
21
14
|
* **Text Rendering**
|
|
22
15
|
* **Line Drawing**
|
|
23
16
|
* **Custom Shaders**
|
|
24
|
-
* **Texture Clipping**
|
|
25
17
|
* **Mask**
|
|
26
18
|
|
|
27
|
-
|
|
19
|
+
## Install
|
|
28
20
|
|
|
29
|
-
```
|
|
21
|
+
```bash
|
|
30
22
|
npm i rapid-render
|
|
31
23
|
```
|
|
32
24
|
|
|
33
|
-
Or
|
|
25
|
+
Or via CDN:
|
|
34
26
|
|
|
35
27
|
```html
|
|
36
28
|
<script src="https://unpkg.com/rapid-render/dist/rapid.umd.cjs"></script>
|
|
37
29
|
```
|
|
38
30
|
|
|
39
|
-
|
|
31
|
+
## Quick Start
|
|
40
32
|
|
|
41
33
|
```js
|
|
42
|
-
import { Rapid } from "rapid-render"
|
|
34
|
+
import { Rapid, Color, Vec2 } from "rapid-render"
|
|
35
|
+
|
|
36
|
+
// Initialize
|
|
37
|
+
const rapid = new Rapid({
|
|
38
|
+
canvas: document.getElementById("gameCanvas"),
|
|
39
|
+
backgroundColor: Color.fromHex("E6F0FF")
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
// Render example
|
|
43
|
+
rapid.render(() => {
|
|
44
|
+
rapid.renderRect({
|
|
45
|
+
offset: new Vec2(100, 100),
|
|
46
|
+
width: 50,
|
|
47
|
+
height: 50,
|
|
48
|
+
color: Color.Red
|
|
49
|
+
})
|
|
50
|
+
})
|
|
43
51
|
```
|
|
44
52
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
```js
|
|
48
|
-
let rapid = new Rapid({
|
|
49
|
-
canvas: document.getElementById("game"),
|
|
50
|
-
backgroundColor: Color.fromHex("FFFFFF")
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
// Create texture
|
|
54
|
-
const cat = await rapid.textures.textureFromUrl("./cat.png");
|
|
55
|
-
// R G B A
|
|
56
|
-
const color = new Color(255, 255, 255, 255); // Or use Color.fromHex
|
|
57
|
-
|
|
58
|
-
// Call before rendering
|
|
59
|
-
rapid.startRender();
|
|
60
|
-
|
|
61
|
-
// Render here...
|
|
53
|
+
For more examples and detailed documentation, visit our [website](https://nightre.github.io/Rapid.js/docs/index.html).
|
|
62
54
|
|
|
63
|
-
|
|
64
|
-
rapid.endRender();
|
|
55
|
+
## Roadmap
|
|
65
56
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
# Render
|
|
57
|
+
* Frame Buffer Object (FBO)
|
|
58
|
+
* Light System
|
|
59
|
+
* Line Texture
|
|
60
|
+
* Particle System
|
|
71
61
|
|
|
72
|
-
|
|
73
|
-
const text = rapid.textures.createText({ text: "Hello!", fontSize: 30 })
|
|
74
|
-
|
|
75
|
-
rapid.save() // Save state
|
|
76
|
-
rapid.matrixStack.translate(0,0)
|
|
77
|
-
rapid.matrixStack.scale(1)
|
|
78
|
-
rapid.matrixStack.rotate(0)
|
|
79
|
-
|
|
80
|
-
// Render Sprit
|
|
81
|
-
rapid.renderSprite(cat, 0, 0, color) // or rapid.renderSprite(cat, 0, 0, { color })
|
|
82
|
-
|
|
83
|
-
// Rendr Graphic
|
|
84
|
-
const path = Vec2.FormArray([[0, 0], [100, 0], [100, 100]])
|
|
85
|
-
rapid.renderGraphic(0,0,{points:path, color:green})
|
|
86
|
-
// or
|
|
87
|
-
// rapid.startGraphicDraw()
|
|
88
|
-
// rapid.addGraphicVertex(0, 0, color)
|
|
89
|
-
// rapid.endGraphicDraw()
|
|
90
|
-
|
|
91
|
-
// Render Text
|
|
92
|
-
rapid.renderSprite(text, 200, 0)
|
|
93
|
-
text.setText("time:" + Math.round(time))
|
|
94
|
-
|
|
95
|
-
rapid.restore() // back to the previous saved state
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
# Custom Shader
|
|
99
|
-
|
|
100
|
-
View demo and watch detailed shader code [custom shader demo](https://nightre.github.io/Rapid.js/demo/custom-shader.html) ( [source code](./demo/custom-shader.js) )
|
|
101
|
-
|
|
102
|
-
```js
|
|
103
|
-
const vertexShaderSource = `...`
|
|
104
|
-
const fragmentShaderSource = `...`
|
|
105
|
-
|
|
106
|
-
const customShader = new GLShader(rapid, vertexShaderSource, fragmentShaderSource)
|
|
107
|
-
rapid.startRender()
|
|
108
|
-
|
|
109
|
-
rapid.renderSprite(plane, 100, 100, {
|
|
110
|
-
shader: customShader, // shader
|
|
111
|
-
uniforms: {
|
|
112
|
-
// Set custom uniform (You can set mat3, vec2, and so on here)
|
|
113
|
-
uCustomUniform: Number(costumUniformValue)
|
|
114
|
-
// uVec2Uniform: [0,2] // recognized as vec2
|
|
115
|
-
// uMat3Uniform: [
|
|
116
|
-
// [0,0,0],
|
|
117
|
-
// [0,0,0],
|
|
118
|
-
// [0,0,0],
|
|
119
|
-
// ]
|
|
120
|
-
// recognized as mat3
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
rapid.endRender()
|
|
125
|
-
```
|
|
126
|
-
# Screen Shot
|
|
62
|
+
## Contributing
|
|
127
63
|
|
|
128
|
-
!
|
|
64
|
+
Issues and PRs are welcome!
|
package/dist/depth.d.ts
ADDED
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { graphicAttributes } from "./regions/graphic_region";
|
|
2
|
-
import { spriteAttributes } from "./regions/sprite_region";
|
|
3
1
|
import Rapid from "./render";
|
|
4
2
|
import GLShader from "./webgl/glshader";
|
|
5
3
|
import { Text } from "./texture";
|
|
6
|
-
|
|
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, };
|
|
7
8
|
export * from "./math";
|
|
8
9
|
export * from "./interface";
|
|
9
10
|
export * from "./texture";
|
package/dist/interface.d.ts
CHANGED
|
@@ -1,13 +1,26 @@
|
|
|
1
1
|
import { Color, Vec2 } from "./math";
|
|
2
2
|
import { Texture } from "./texture";
|
|
3
|
+
import { TileSet } from "./tilemap";
|
|
3
4
|
import GLShader from "./webgl/glshader";
|
|
5
|
+
import { Uniform } from "./webgl/uniform";
|
|
6
|
+
/**
|
|
7
|
+
* @ignore
|
|
8
|
+
*/
|
|
4
9
|
export type WebGLContext = WebGL2RenderingContext | WebGLRenderingContext;
|
|
5
|
-
|
|
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 {
|
|
6
19
|
canvas: HTMLCanvasElement;
|
|
7
|
-
pixelDensity?: number;
|
|
8
20
|
width?: number;
|
|
9
21
|
height?: number;
|
|
10
22
|
backgroundColor?: Color;
|
|
23
|
+
antialias?: boolean;
|
|
11
24
|
}
|
|
12
25
|
export interface IAttribute {
|
|
13
26
|
name: string;
|
|
@@ -17,16 +30,33 @@ export interface IAttribute {
|
|
|
17
30
|
stride: number;
|
|
18
31
|
offset?: number;
|
|
19
32
|
}
|
|
20
|
-
export interface
|
|
33
|
+
export interface ITransform {
|
|
34
|
+
position?: Vec2;
|
|
35
|
+
scale?: Vec2 | number;
|
|
36
|
+
rotation?: number;
|
|
37
|
+
flipX?: boolean;
|
|
38
|
+
flipY?: boolean;
|
|
39
|
+
offset?: Vec2;
|
|
40
|
+
x?: number;
|
|
41
|
+
y?: number;
|
|
42
|
+
offsetX?: number;
|
|
43
|
+
offsetY?: number;
|
|
44
|
+
origin?: Vec2 | number;
|
|
45
|
+
restoreTransform?: boolean;
|
|
46
|
+
saveTransform?: boolean;
|
|
47
|
+
afterSave?(): unknown;
|
|
48
|
+
beforRestore?(): unknown;
|
|
49
|
+
}
|
|
50
|
+
export interface IRenderSpriteOptions extends ITransform, IShader {
|
|
21
51
|
color?: Color;
|
|
22
|
-
|
|
23
|
-
|
|
52
|
+
texture?: Texture;
|
|
53
|
+
offset?: Vec2;
|
|
24
54
|
}
|
|
25
55
|
export interface ITextOptions {
|
|
26
56
|
/**
|
|
27
57
|
* The text string to be rendered.
|
|
28
58
|
*/
|
|
29
|
-
text
|
|
59
|
+
text?: string;
|
|
30
60
|
/**
|
|
31
61
|
* The font size for the text.
|
|
32
62
|
* Default is 16.
|
|
@@ -54,47 +84,66 @@ export interface ITextOptions {
|
|
|
54
84
|
* Default is 'top'.
|
|
55
85
|
*/
|
|
56
86
|
textBaseline?: CanvasTextBaseline;
|
|
57
|
-
/**
|
|
58
|
-
* Whether to apply antialiasing to the texture.
|
|
59
|
-
* Default is `false`.
|
|
60
|
-
*/
|
|
61
|
-
antialias?: boolean;
|
|
62
|
-
}
|
|
63
|
-
export declare enum JoinTyps {
|
|
64
|
-
BEVEL = 0,
|
|
65
|
-
ROUND = 1,
|
|
66
|
-
MITER = 2
|
|
67
|
-
}
|
|
68
|
-
export declare enum CapTyps {
|
|
69
|
-
BUTT = 0,
|
|
70
|
-
ROUND = 1,
|
|
71
|
-
SQUARE = 2
|
|
72
87
|
}
|
|
73
88
|
export interface ILineOptions {
|
|
74
|
-
cap?: CapTyps;
|
|
75
|
-
join?: JoinTyps;
|
|
76
89
|
width?: number;
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
export interface IRenderLineOptions extends ILineOptions {
|
|
90
|
+
closed?: boolean;
|
|
80
91
|
points: Vec2[];
|
|
92
|
+
roundCap?: boolean;
|
|
81
93
|
color?: Color;
|
|
82
94
|
}
|
|
83
|
-
export interface
|
|
95
|
+
export interface IRenderLineOptions extends ILineOptions, ITransform {
|
|
96
|
+
}
|
|
97
|
+
export interface IGraphicOptions extends ITransform, IShader {
|
|
84
98
|
points: Vec2[];
|
|
85
99
|
color?: Color | Color[];
|
|
86
100
|
drawType?: number;
|
|
87
101
|
uv?: Vec2[];
|
|
88
102
|
texture?: Texture;
|
|
89
|
-
shader?: GLShader;
|
|
90
103
|
}
|
|
91
|
-
export
|
|
92
|
-
|
|
93
|
-
|
|
104
|
+
export interface ICircleOptions extends IGraphicOptions {
|
|
105
|
+
radius: number;
|
|
106
|
+
segments?: number;
|
|
107
|
+
}
|
|
108
|
+
export interface IRectOptions extends IGraphicOptions {
|
|
109
|
+
width: number;
|
|
110
|
+
height: number;
|
|
94
111
|
}
|
|
95
112
|
export declare enum MaskType {
|
|
96
|
-
|
|
97
|
-
|
|
113
|
+
Include = "normal",
|
|
114
|
+
Exclude = "inverse"
|
|
98
115
|
}
|
|
99
|
-
export type UniformType = Record<string, number | Array<any> | boolean>;
|
|
116
|
+
export type UniformType = Record<string, number | Array<any> | boolean | Texture>;
|
|
100
117
|
export type Images = ImageBitmap | ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement | OffscreenCanvas;
|
|
118
|
+
export interface IRegisterTileOptions extends IRenderSpriteOptions {
|
|
119
|
+
texture: Texture;
|
|
120
|
+
offsetX?: number;
|
|
121
|
+
offsetY?: number;
|
|
122
|
+
ySortOffset?: number;
|
|
123
|
+
}
|
|
124
|
+
export interface YSortCallback {
|
|
125
|
+
ySort: number;
|
|
126
|
+
render?: () => void;
|
|
127
|
+
renderSprite?: IRenderSpriteOptions;
|
|
128
|
+
}
|
|
129
|
+
export interface ILayerRender extends ITransform {
|
|
130
|
+
error?: number | Vec2;
|
|
131
|
+
errorX?: number;
|
|
132
|
+
errorY?: number;
|
|
133
|
+
ySortCallback?: Array<YSortCallback>;
|
|
134
|
+
shape?: TilemapShape;
|
|
135
|
+
tileSet: TileSet;
|
|
136
|
+
eachTile?: (tileId: string | number, mapX: number, mapY: number) => IRenderSpriteOptions | undefined | void;
|
|
137
|
+
}
|
|
138
|
+
export interface IShader {
|
|
139
|
+
shader?: GLShader;
|
|
140
|
+
uniforms?: Uniform;
|
|
141
|
+
}
|
|
142
|
+
export declare enum TilemapShape {
|
|
143
|
+
SQUARE = "square",
|
|
144
|
+
ISOMETRIC = "isometric"
|
|
145
|
+
}
|
|
146
|
+
export declare enum ShaderType {
|
|
147
|
+
SPRITE = "sprite",
|
|
148
|
+
GRAPHIC = "graphic"
|
|
149
|
+
}
|
package/dist/line.d.ts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import { ILineOptions } from "./interface";
|
|
2
2
|
import { Vec2 } from "./math";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @ignore
|
|
5
|
+
*/
|
|
6
|
+
export declare const getLineNormal: (points: Vec2[], closed?: boolean) => {
|
|
7
|
+
normal: Vec2;
|
|
8
|
+
miters: number;
|
|
9
|
+
}[];
|
|
10
|
+
export declare const getLineGeometry: (options: ILineOptions) => Vec2[];
|
package/dist/log.d.ts
ADDED