rapid-render 0.1.1 → 0.1.3
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 +71 -81
- package/dist/depth.d.ts +8 -0
- package/dist/index.d.ts +4 -3
- package/dist/interface.d.ts +90 -29
- package/dist/line.d.ts +8 -1
- package/dist/log.d.ts +2 -0
- package/dist/math.d.ts +218 -44
- package/dist/particle.d.ts +14 -0
- 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 +7 -20
- package/dist/regions/region.d.ts +13 -5
- package/dist/regions/sprite_region.d.ts +3 -26
- package/dist/render.d.ts +101 -37
- package/dist/texture.d.ts +30 -2
- package/dist/tilemap.d.ts +97 -0
- 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,26 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="./screenshot/logo.png" alt="Rapid.js Logo" width="100" style="image-rendering: pixelated;">
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
<a href="https://nightre.github.io/Rapid.js/docs/index.html"><h1 align="center">Rapid.js</h1></a>
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
A highly efficient ([stress-test](./docs/examples.html)) and lightweight WebGL-based 2D rendering engine focused on rendering capabilities. Rapid.js provides a simple and intuitive API for developers to quickly build high-performance 2D
|
|
8
|
+
games, while staying completely independent from your game's architecture and logic.
|
|
6
9
|
|
|
7
|
-
[stress test demo](https://nightre.github.io/Rapid.js/demo/) ( [source code](./demo/index.js) )
|
|
8
10
|
|
|
9
|
-
[
|
|
11
|
+
### [Website](https://nightre.github.io/Rapid.js/docs/index.html)
|
|
10
12
|
|
|
11
|
-
[
|
|
13
|
+
#### [Document](https://nightre.github.io/Rapid.js/docs/docs.html)
|
|
12
14
|
|
|
15
|
+
#### [API Docs](https://nightre.github.io/Rapid.js/docs/api/index.html)
|
|
13
16
|
|
|
17
|
+
#### [Examples](https://nightre.github.io/Rapid.js/demo/)
|
|
14
18
|
|
|
15
19
|
# Features
|
|
16
|
-
|
|
17
|
-
* **
|
|
20
|
+
|
|
21
|
+
* **Fast Rendering**
|
|
22
|
+
* **TileMap** - YSort, isometric
|
|
18
23
|
* **Graphics Drawing**
|
|
19
|
-
* **Matrix Stack**
|
|
20
24
|
* **Text Rendering**
|
|
21
25
|
* **Line Drawing**
|
|
22
26
|
* **Custom Shaders**
|
|
23
|
-
* **
|
|
27
|
+
* **Mask**
|
|
28
|
+
|
|
29
|
+
> [!WARNING]
|
|
30
|
+
> This project is under active development! Please expect bugs, report any issues you find, and contributions are welcome.
|
|
31
|
+
|
|
24
32
|
|
|
25
33
|
# Install
|
|
26
34
|
|
|
@@ -40,87 +48,69 @@ Or use unpkg
|
|
|
40
48
|
import { Rapid } from "rapid-render"
|
|
41
49
|
```
|
|
42
50
|
|
|
43
|
-
#
|
|
51
|
+
# Usage
|
|
44
52
|
|
|
45
|
-
|
|
46
|
-
let rapid = new Rapid({
|
|
47
|
-
canvas: document.getElementById("game"),
|
|
48
|
-
backgroundColor: Color.fromHex("FFFFFF")
|
|
49
|
-
});
|
|
53
|
+
Rapid.js is a focused WebGL-based 2D rendering engine that provides rendering capabilities only. It does not include any game architecture, state management, physics, or other game-related systems - it's purely a rendering engine. This intentional design choice means you have complete freedom to structure your game however you want.
|
|
50
54
|
|
|
51
|
-
|
|
52
|
-
const cat = await rapid.textures.textureFromUrl("./cat.png");
|
|
53
|
-
// R G B A
|
|
54
|
-
const color = new Color(255, 255, 255, 255); // Or use Color.fromHex
|
|
55
|
+
Here's a simple example showing how to use Rapid.js to create a bouncing box:
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
rapid.startRender();
|
|
57
|
+
First, create a canvas element in your HTML:
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
// Call after rendering
|
|
62
|
-
rapid.endRender();
|
|
63
|
-
|
|
64
|
-
// Set canvas size
|
|
65
|
-
rapid.resize(100, 100);
|
|
59
|
+
```html
|
|
60
|
+
<canvas id="gameCanvas" width="500" height="500"></canvas>
|
|
66
61
|
```
|
|
67
62
|
|
|
68
|
-
|
|
63
|
+
Then, add the following JavaScript code:
|
|
69
64
|
|
|
70
65
|
```js
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
rapid
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
rapid.
|
|
66
|
+
import { Rapid, Color, Vec2 } from "rapid-render"
|
|
67
|
+
|
|
68
|
+
// Initialize Rapid
|
|
69
|
+
const rapid = new Rapid({
|
|
70
|
+
canvas: document.getElementById("gameCanvas"),
|
|
71
|
+
backgroundColor: Color.fromHex("E6F0FF")
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
// Position and velocity
|
|
75
|
+
let position = new Vec2(100, 100)
|
|
76
|
+
let velocity = new Vec2(2, 2)
|
|
77
|
+
|
|
78
|
+
function gameLoop() {
|
|
79
|
+
// Update position
|
|
80
|
+
position.x += velocity.x
|
|
81
|
+
position.y += velocity.y
|
|
82
|
+
|
|
83
|
+
// Simple collision with boundaries
|
|
84
|
+
if (position.x < 0 || position.x > 400) velocity.x *= -1
|
|
85
|
+
if (position.y < 0 || position.y > 400) velocity.y *= -1
|
|
86
|
+
|
|
87
|
+
// Render using the recommended render callback method
|
|
88
|
+
rapid.render(() => {
|
|
89
|
+
rapid.renderRect({
|
|
90
|
+
offset: position,
|
|
91
|
+
width: 50,
|
|
92
|
+
height: 50,
|
|
93
|
+
color: Color.Red
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
// rapid.startRender();
|
|
97
|
+
// ...
|
|
98
|
+
// rapid.endRender();
|
|
99
|
+
requestAnimationFrame(gameLoop);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
gameLoop()
|
|
94
103
|
```
|
|
95
104
|
|
|
96
|
-
|
|
105
|
+
This will create a red square that bounces around the canvas, demonstrating basic animation and collision detection.
|
|
97
106
|
|
|
98
|
-
|
|
107
|
+
Note: All rendering operations must be performed within a render context, either:
|
|
108
|
+
- Inside a `rapid.render(() => { ... })` callback (Recommended), or
|
|
109
|
+
- Between `rapid.startRender()` and `rapid.endRender()` calls
|
|
99
110
|
|
|
100
|
-
|
|
101
|
-
const vertexShaderSource = `...`
|
|
102
|
-
const fragmentShaderSource = `...`
|
|
103
|
-
|
|
104
|
-
const customShader = new GLShader(rapid, vertexShaderSource, fragmentShaderSource)
|
|
105
|
-
rapid.startRender()
|
|
106
|
-
|
|
107
|
-
rapid.renderSprite(plane, 100, 100, {
|
|
108
|
-
shader: customShader, // shader
|
|
109
|
-
uniforms: {
|
|
110
|
-
// Set custom uniform (You can set mat3, vec2, and so on here)
|
|
111
|
-
uCustomUniform: Number(costumUniformValue)
|
|
112
|
-
// uVec2Uniform: [0,2] // recognized as vec2
|
|
113
|
-
// uMat3Uniform: [
|
|
114
|
-
// [0,0,0],
|
|
115
|
-
// [0,0,0],
|
|
116
|
-
// [0,0,0],
|
|
117
|
-
// ]
|
|
118
|
-
// recognized as mat3
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
rapid.endRender()
|
|
123
|
-
```
|
|
124
|
-
# Screen Shot
|
|
111
|
+
# Road Map
|
|
125
112
|
|
|
126
|
-
|
|
113
|
+
* Frame Buffer Object (allows rendering to a texture instead of screen) [Under development]
|
|
114
|
+
* Light system
|
|
115
|
+
* Line Texture
|
|
116
|
+
* Particle system
|
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,12 +1,26 @@
|
|
|
1
1
|
import { Color, Vec2 } from "./math";
|
|
2
|
+
import { Texture } from "./texture";
|
|
3
|
+
import { TileSet } from "./tilemap";
|
|
2
4
|
import GLShader from "./webgl/glshader";
|
|
5
|
+
import { Uniform } from "./webgl/uniform";
|
|
6
|
+
/**
|
|
7
|
+
* @ignore
|
|
8
|
+
*/
|
|
3
9
|
export type WebGLContext = WebGL2RenderingContext | WebGLRenderingContext;
|
|
4
|
-
|
|
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 {
|
|
5
19
|
canvas: HTMLCanvasElement;
|
|
6
|
-
pixelDensity?: number;
|
|
7
20
|
width?: number;
|
|
8
21
|
height?: number;
|
|
9
22
|
backgroundColor?: Color;
|
|
23
|
+
antialias?: boolean;
|
|
10
24
|
}
|
|
11
25
|
export interface IAttribute {
|
|
12
26
|
name: string;
|
|
@@ -16,16 +30,33 @@ export interface IAttribute {
|
|
|
16
30
|
stride: number;
|
|
17
31
|
offset?: number;
|
|
18
32
|
}
|
|
19
|
-
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 {
|
|
20
51
|
color?: Color;
|
|
21
|
-
|
|
22
|
-
|
|
52
|
+
texture?: Texture;
|
|
53
|
+
offset?: Vec2;
|
|
23
54
|
}
|
|
24
55
|
export interface ITextOptions {
|
|
25
56
|
/**
|
|
26
57
|
* The text string to be rendered.
|
|
27
58
|
*/
|
|
28
|
-
text
|
|
59
|
+
text?: string;
|
|
29
60
|
/**
|
|
30
61
|
* The font size for the text.
|
|
31
62
|
* Default is 16.
|
|
@@ -53,36 +84,66 @@ export interface ITextOptions {
|
|
|
53
84
|
* Default is 'top'.
|
|
54
85
|
*/
|
|
55
86
|
textBaseline?: CanvasTextBaseline;
|
|
56
|
-
/**
|
|
57
|
-
* Whether to apply antialiasing to the texture.
|
|
58
|
-
* Default is `false`.
|
|
59
|
-
*/
|
|
60
|
-
antialias?: boolean;
|
|
61
|
-
}
|
|
62
|
-
export declare enum JoinTyps {
|
|
63
|
-
BEVEL = 0,
|
|
64
|
-
ROUND = 1,
|
|
65
|
-
MITER = 2
|
|
66
|
-
}
|
|
67
|
-
export declare enum CapTyps {
|
|
68
|
-
BUTT = 0,
|
|
69
|
-
ROUND = 1,
|
|
70
|
-
SQUARE = 2
|
|
71
87
|
}
|
|
72
88
|
export interface ILineOptions {
|
|
73
|
-
cap?: CapTyps;
|
|
74
|
-
join?: JoinTyps;
|
|
75
89
|
width?: number;
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
export interface IRenderLineOptions extends ILineOptions {
|
|
90
|
+
closed?: boolean;
|
|
79
91
|
points: Vec2[];
|
|
92
|
+
roundCap?: boolean;
|
|
80
93
|
color?: Color;
|
|
81
94
|
}
|
|
82
|
-
export interface
|
|
95
|
+
export interface IRenderLineOptions extends ILineOptions, ITransform {
|
|
96
|
+
}
|
|
97
|
+
export interface IGraphicOptions extends ITransform, IShader {
|
|
83
98
|
points: Vec2[];
|
|
84
|
-
color?: Color;
|
|
99
|
+
color?: Color | Color[];
|
|
85
100
|
drawType?: number;
|
|
101
|
+
uv?: Vec2[];
|
|
102
|
+
texture?: Texture;
|
|
103
|
+
}
|
|
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;
|
|
86
111
|
}
|
|
87
|
-
export
|
|
112
|
+
export declare enum MaskType {
|
|
113
|
+
Include = "normal",
|
|
114
|
+
Exclude = "inverse"
|
|
115
|
+
}
|
|
116
|
+
export type UniformType = Record<string, number | Array<any> | boolean | Texture>;
|
|
88
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