rapid-render 1.0.16 → 1.0.18
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 +17 -9
- package/dist/extensions/light.d.ts +34 -0
- package/dist/{particle.d.ts → extensions/particle.d.ts} +6 -6
- package/dist/index.d.ts +4 -9
- package/dist/matrix-engine.d.ts +3 -1
- package/dist/rapid-render.js +1064 -956
- package/dist/rapid-render.umd.cjs +84 -51
- package/dist/region/atlasSpriteRegion.d.ts +0 -2
- package/dist/region/graphicRegion.d.ts +1 -0
- package/dist/region/particleRegion.d.ts +1 -1
- package/dist/region/region.d.ts +2 -0
- package/dist/region/spriteRegion.d.ts +0 -2
- package/dist/render.d.ts +3 -5
- package/dist/texture-filter-mode.d.ts +5 -0
- package/dist/texture.d.ts +2 -2
- package/dist/utils.d.ts +1 -0
- package/dist/webgl/glshader.d.ts +6 -3
- package/dist/webgl/utils.d.ts +4 -3
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
<p align="center">
|
|
6
6
|
<a href="https://www.npmjs.com/package/rapid-render"><img src="https://img.shields.io/npm/v/rapid-render?logo=npm&label=npm" alt="npm version"></a>
|
|
7
|
-
<a href="https://www.npmjs.com/package/rapid-render"><img src="https://img.shields.io/badge/gzipped
|
|
7
|
+
<a href="https://www.npmjs.com/package/rapid-render"><img src="https://img.shields.io/badge/gzipped-22.5%20kB-5C7CFA" alt="gzipped size"></a>
|
|
8
8
|
<a href="https://github.com/Nightre/Rapid.js/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/rapid-render" alt="license"></a>
|
|
9
9
|
<img src="https://img.shields.io/badge/TypeScript-strict-3178C6?logo=typescript&logoColor=white" alt="TypeScript strict">
|
|
10
10
|
</p>
|
|
@@ -27,12 +27,18 @@
|
|
|
27
27
|
|
|
28
28
|
## What is Rapid?
|
|
29
29
|
|
|
30
|
-
Rapid is a focused WebGL 2D rendering engine for games and visual tools.
|
|
30
|
+
Rapid is a focused WebGL 2D rendering engine for games and visual tools.
|
|
31
31
|
|
|
32
|
-
If you
|
|
32
|
+
If you want Pixi-level rendering without letting your renderer dictate how your game is organized, Rapid.js is for you!
|
|
33
|
+
|
|
34
|
+
## Full 2D Toolkit
|
|
35
|
+
|
|
36
|
+
Particles, Light & Shadow, Custom Shaders, Lines, Masks, Render textures, Sprites, Custom Geometry, Filters and more. all from one focused WebGL renderer. Yet it is only **22.5 kB gzipped**.
|
|
33
37
|
|
|
34
38
|
## Architecture Recipes
|
|
35
39
|
|
|
40
|
+
Rapid.js handles only the rendering layer, leaving your game architecture entirely in your hands.
|
|
41
|
+
|
|
36
42
|
Rapid.js is frame-stateless, making it easy to build games with different architectures. Below are minimal, working implementations of several popular architectures built on Rapid.js, each in **around 100 lines** of JavaScript.
|
|
37
43
|
|
|
38
44
|
- **Architecture recipes**
|
|
@@ -56,7 +62,7 @@ Or via the unpkg CDN
|
|
|
56
62
|
## Quick Start
|
|
57
63
|
|
|
58
64
|
```ts
|
|
59
|
-
import { Rapid
|
|
65
|
+
import { Rapid } from "rapid-render";
|
|
60
66
|
|
|
61
67
|
const canvas = document.querySelector("canvas")!;
|
|
62
68
|
const rapid = new Rapid({canvas});
|
|
@@ -73,7 +79,7 @@ rapid.flush();
|
|
|
73
79
|
|
|
74
80
|
## Render a scene
|
|
75
81
|
|
|
76
|
-
`rapid.matrixStack` brings the familiar, intuitive `save()` and `restore()` flow from Canvas 2D into high-performance WebGL
|
|
82
|
+
`rapid.matrixStack` brings the familiar, intuitive `save()` and `restore()` flow from Canvas 2D into high-performance WebGL. It reuses typed-array-backed matrix storage and avoids per-transform matrix allocation.
|
|
77
83
|
|
|
78
84
|
```ts
|
|
79
85
|
// root
|
|
@@ -95,8 +101,10 @@ stack.save();
|
|
|
95
101
|
// 3.enemies
|
|
96
102
|
stack.save();
|
|
97
103
|
for (let i = 0; i < 2; i++) {
|
|
98
|
-
stack.
|
|
99
|
-
|
|
104
|
+
stack.save();
|
|
105
|
+
stack.translate(enemyX[i], enemyY[i]);
|
|
106
|
+
rapid.drawSprite(enemies[i]); // enemy
|
|
107
|
+
stack.restore();
|
|
100
108
|
}
|
|
101
109
|
stack.restore(); // 3.enemies
|
|
102
110
|
stack.restore(); // 2.world
|
|
@@ -107,7 +115,7 @@ rapid.drawSprite(ui);
|
|
|
107
115
|
|
|
108
116
|
## Reuse and Update Matrix Subtrees
|
|
109
117
|
|
|
110
|
-
Use `customMatrix` to render with any matrix in the hierarchy(even after its stack scope has been popped)
|
|
118
|
+
Use `customMatrix` to render with any matrix in the hierarchy (even after its stack scope has been popped).
|
|
111
119
|
|
|
112
120
|
When you modify a node's local matrix, call `updateMatrixSubtree()` to automatically recalculate that node and all affected descendant world matrices, without rebuilding the entire matrix hierarchy.
|
|
113
121
|
|
|
@@ -144,7 +152,7 @@ rapid.drawSprite({
|
|
|
144
152
|
rapid.flush();
|
|
145
153
|
```
|
|
146
154
|
|
|
147
|
-
With this flexible matrix stack, you can build your own architecture with minimal friction. It doesn't care how you organize your game logic.
|
|
155
|
+
With this flexible matrix stack, you can build your own architecture with minimal friction. It doesn't care how you organize your game logic. You can use ECS, scene graphs, components, or any hybrid approach you prefer.
|
|
148
156
|
|
|
149
157
|
For more information about matrix transformations, see the [Transformations](https://nightre.github.io/Rapid.js/docs.html#transformations).
|
|
150
158
|
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Rapid } from '../render';
|
|
2
|
+
import { CustomGlShader, UniformValue } from '../webgl/glshader';
|
|
3
|
+
import { Vec2 } from '../math';
|
|
4
|
+
import { RenderTexture, Texture } from '../texture';
|
|
5
|
+
import { Color } from '../color';
|
|
6
|
+
import { MatrixSaveState } from '../matrix-engine';
|
|
7
|
+
import { Region } from '../region/region';
|
|
8
|
+
export declare const MAX_LIGHTS = 8;
|
|
9
|
+
export declare class LightShader extends CustomGlShader {
|
|
10
|
+
constructor(rapid: Rapid, vs?: string, fs?: string, usedTextureUnitNum?: number, uniforms?: Record<string, UniformValue>);
|
|
11
|
+
getGLShader(region: Region, key: string, baseVS: string, baseFS: string): import('..').GLShader | null;
|
|
12
|
+
}
|
|
13
|
+
export type LightMatrix = number | MatrixSaveState;
|
|
14
|
+
export interface ILight {
|
|
15
|
+
lightMatrix: LightMatrix | LightMatrix[];
|
|
16
|
+
normalMap: Texture;
|
|
17
|
+
lightTexture: Texture[] | Texture;
|
|
18
|
+
metallic?: number;
|
|
19
|
+
roughness?: number;
|
|
20
|
+
color?: Color | Color[];
|
|
21
|
+
ambientColor?: Color;
|
|
22
|
+
lightHeight?: number | number[];
|
|
23
|
+
customShader?: LightShader;
|
|
24
|
+
normalScaleY?: number;
|
|
25
|
+
normalScaleX?: number;
|
|
26
|
+
}
|
|
27
|
+
export declare class Light {
|
|
28
|
+
shader: CustomGlShader;
|
|
29
|
+
rapid: Rapid;
|
|
30
|
+
rt: RenderTexture;
|
|
31
|
+
constructor(rapid: Rapid);
|
|
32
|
+
lightShadow(texture: Texture, lightMatrix: LightMatrix, points: Array<Vec2>): RenderTexture | undefined;
|
|
33
|
+
setupLight(option: ILight): CustomGlShader;
|
|
34
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Color } from '
|
|
2
|
-
import { Vec2 } from '
|
|
3
|
-
import { Rapid } from '
|
|
4
|
-
import { Texture } from '
|
|
5
|
-
import { DynamicArrayBuffer } from '
|
|
6
|
-
import { CustomGlShader } from '
|
|
1
|
+
import { Color } from '../color';
|
|
2
|
+
import { Vec2 } from '../math';
|
|
3
|
+
import { Rapid } from '../render';
|
|
4
|
+
import { Texture } from '../texture';
|
|
5
|
+
import { DynamicArrayBuffer } from '../buffer';
|
|
6
|
+
import { CustomGlShader } from '../webgl/glshader';
|
|
7
7
|
/**
|
|
8
8
|
* Describes an animated attribute: it transitions from `start` to `end`
|
|
9
9
|
* over the particle's lifetime, optionally with a per-second damping factor.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
export * from './buffer';
|
|
2
1
|
export * from './color';
|
|
3
|
-
export * from './matrix-engine';
|
|
4
2
|
export * from './render';
|
|
5
|
-
export * from './draw';
|
|
6
3
|
export * from './texture';
|
|
7
4
|
export * from './webgl/glshader';
|
|
8
|
-
export * from './region/region';
|
|
9
|
-
export * from './region/spriteRegion';
|
|
10
|
-
export * from './region/particleRegion';
|
|
11
|
-
export * from './region/graphicRegion';
|
|
12
5
|
export * from './math';
|
|
13
|
-
export * from './particle';
|
|
14
|
-
export
|
|
6
|
+
export * from './extensions/particle';
|
|
7
|
+
export * from './extensions/light';
|
|
8
|
+
export * from './line';
|
|
9
|
+
export * from './draw';
|
package/dist/matrix-engine.d.ts
CHANGED