reze-engine 0.2.19 → 0.3.0
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 +67 -66
- package/dist/bezier-interpolate.d.ts +15 -0
- package/dist/bezier-interpolate.d.ts.map +1 -0
- package/dist/bezier-interpolate.js +40 -0
- package/dist/engine.d.ts +7 -9
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +252 -143
- package/dist/ik-solver.d.ts +26 -0
- package/dist/ik-solver.d.ts.map +1 -0
- package/dist/ik-solver.js +372 -0
- package/dist/math.d.ts +1 -0
- package/dist/math.d.ts.map +1 -1
- package/dist/math.js +8 -0
- package/dist/model.d.ts +46 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +201 -3
- package/dist/pmx-loader.d.ts.map +1 -1
- package/dist/pmx-loader.js +57 -36
- package/dist/vmd-loader.d.ts +11 -1
- package/dist/vmd-loader.d.ts.map +1 -1
- package/dist/vmd-loader.js +91 -15
- package/package.json +1 -1
- package/src/bezier-interpolate.ts +47 -0
- package/src/camera.ts +358 -358
- package/src/engine.ts +275 -164
- package/src/ik-solver.ts +488 -0
- package/src/math.ts +555 -546
- package/src/model.ts +284 -3
- package/src/physics.ts +752 -752
- package/src/pmx-loader.ts +1173 -1145
- package/src/vmd-loader.ts +276 -179
package/README.md
CHANGED
|
@@ -1,66 +1,67 @@
|
|
|
1
|
-
# Reze Engine
|
|
2
|
-
|
|
3
|
-
A lightweight engine built with WebGPU and TypeScript for real-time 3D anime character MMD model rendering.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- Physics
|
|
8
|
-
- Alpha blending
|
|
9
|
-
- Post alpha eye rendering
|
|
10
|
-
- Rim lighting
|
|
11
|
-
- Bloom
|
|
12
|
-
- Outlines
|
|
13
|
-
- MSAA 4x anti-aliasing
|
|
14
|
-
- GPU-accelerated skinning
|
|
15
|
-
- Bone and morph api
|
|
16
|
-
- VMD animation
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
await engine.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
- **[
|
|
60
|
-
- **[
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
1
|
+
# Reze Engine
|
|
2
|
+
|
|
3
|
+
A lightweight engine built with WebGPU and TypeScript for real-time 3D anime character MMD model rendering.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Physics
|
|
8
|
+
- Alpha blending
|
|
9
|
+
- Post alpha eye rendering
|
|
10
|
+
- Rim lighting
|
|
11
|
+
- Bloom
|
|
12
|
+
- Outlines
|
|
13
|
+
- MSAA 4x anti-aliasing
|
|
14
|
+
- GPU-accelerated skinning
|
|
15
|
+
- Bone and morph api
|
|
16
|
+
- VMD animation
|
|
17
|
+
- Ik solver
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
export default function Scene() {
|
|
23
|
+
const canvasRef = useRef < HTMLCanvasElement > null
|
|
24
|
+
const engineRef = useRef < Engine > null
|
|
25
|
+
|
|
26
|
+
const initEngine = useCallback(async () => {
|
|
27
|
+
if (canvasRef.current) {
|
|
28
|
+
try {
|
|
29
|
+
const engine = new Engine(canvasRef.current)
|
|
30
|
+
engineRef.current = engine
|
|
31
|
+
await engine.init()
|
|
32
|
+
await engine.loadModel("/models/塞尔凯特/塞尔凯特.pmx")
|
|
33
|
+
|
|
34
|
+
engine.runRenderLoop(() => {})
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.error(error)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}, [])
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
void (async () => {
|
|
43
|
+
initEngine()
|
|
44
|
+
})()
|
|
45
|
+
|
|
46
|
+
return () => {
|
|
47
|
+
if (engineRef.current) {
|
|
48
|
+
engineRef.current.dispose()
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}, [initEngine])
|
|
52
|
+
|
|
53
|
+
return <canvas ref={canvasRef} className="w-full h-full" />
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Projects Using This Engine
|
|
58
|
+
|
|
59
|
+
- **[MiKaPo](https://mikapo.vercel.app)** - Online real-time motion capture for MMD using webcam and MediaPipe
|
|
60
|
+
- **[Popo](https://popo.love)** - Fine-tuned LLM that generates MMD poses from natural language descriptions
|
|
61
|
+
- **[MPL](https://mmd-mpl.vercel.app)** - Semantic motion programming language for scripting MMD animations with intuitive syntax
|
|
62
|
+
|
|
63
|
+
## Tutorial
|
|
64
|
+
|
|
65
|
+
Learn WebGPU from scratch by building an anime character renderer in incremental steps. The tutorial covers the complete rendering pipeline from a simple triangle to fully textured, skeletal-animated characters.
|
|
66
|
+
|
|
67
|
+
[How to Render an Anime Character with WebGPU](https://reze.one/tutorial)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bezier interpolation for VMD animations
|
|
3
|
+
* Based on the reference implementation from babylon-mmd
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Bezier interpolation function
|
|
7
|
+
* @param x1 First control point X (0-127, normalized to 0-1)
|
|
8
|
+
* @param x2 Second control point X (0-127, normalized to 0-1)
|
|
9
|
+
* @param y1 First control point Y (0-127, normalized to 0-1)
|
|
10
|
+
* @param y2 Second control point Y (0-127, normalized to 0-1)
|
|
11
|
+
* @param t Interpolation parameter (0-1)
|
|
12
|
+
* @returns Interpolated value (0-1)
|
|
13
|
+
*/
|
|
14
|
+
export declare function bezierInterpolate(x1: number, x2: number, y1: number, y2: number, t: number): number;
|
|
15
|
+
//# sourceMappingURL=bezier-interpolate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bezier-interpolate.d.ts","sourceRoot":"","sources":["../src/bezier-interpolate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAgCnG"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bezier interpolation for VMD animations
|
|
3
|
+
* Based on the reference implementation from babylon-mmd
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Bezier interpolation function
|
|
7
|
+
* @param x1 First control point X (0-127, normalized to 0-1)
|
|
8
|
+
* @param x2 Second control point X (0-127, normalized to 0-1)
|
|
9
|
+
* @param y1 First control point Y (0-127, normalized to 0-1)
|
|
10
|
+
* @param y2 Second control point Y (0-127, normalized to 0-1)
|
|
11
|
+
* @param t Interpolation parameter (0-1)
|
|
12
|
+
* @returns Interpolated value (0-1)
|
|
13
|
+
*/
|
|
14
|
+
export function bezierInterpolate(x1, x2, y1, y2, t) {
|
|
15
|
+
// Clamp t to [0, 1]
|
|
16
|
+
t = Math.max(0, Math.min(1, t));
|
|
17
|
+
// Binary search for the t value that gives us the desired x
|
|
18
|
+
// We're solving for t in the Bezier curve: x(t) = 3*(1-t)^2*t*x1 + 3*(1-t)*t^2*x2 + t^3
|
|
19
|
+
let start = 0;
|
|
20
|
+
let end = 1;
|
|
21
|
+
let mid = 0.5;
|
|
22
|
+
// Iterate until we find the t value that gives us the desired x
|
|
23
|
+
for (let i = 0; i < 15; i++) {
|
|
24
|
+
// Evaluate Bezier curve at mid point
|
|
25
|
+
const x = 3 * (1 - mid) * (1 - mid) * mid * x1 + 3 * (1 - mid) * mid * mid * x2 + mid * mid * mid;
|
|
26
|
+
if (Math.abs(x - t) < 0.0001) {
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
if (x < t) {
|
|
30
|
+
start = mid;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
end = mid;
|
|
34
|
+
}
|
|
35
|
+
mid = (start + end) / 2;
|
|
36
|
+
}
|
|
37
|
+
// Now evaluate the y value at this t
|
|
38
|
+
const y = 3 * (1 - mid) * (1 - mid) * mid * y1 + 3 * (1 - mid) * mid * mid * y2 + mid * mid * mid;
|
|
39
|
+
return y;
|
|
40
|
+
}
|
package/dist/engine.d.ts
CHANGED
|
@@ -54,7 +54,6 @@ export declare class Engine {
|
|
|
54
54
|
private static readonly DEFAULT_RIM_LIGHT_INTENSITY;
|
|
55
55
|
private static readonly DEFAULT_CAMERA_DISTANCE;
|
|
56
56
|
private static readonly DEFAULT_CAMERA_TARGET;
|
|
57
|
-
private static readonly HAIR_OVER_EYES_ALPHA;
|
|
58
57
|
private static readonly TRANSPARENCY_EPSILON;
|
|
59
58
|
private static readonly STATS_FPS_UPDATE_INTERVAL_MS;
|
|
60
59
|
private static readonly STATS_FRAME_TIME_ROUNDING;
|
|
@@ -105,8 +104,10 @@ export declare class Engine {
|
|
|
105
104
|
private animationTimeouts;
|
|
106
105
|
private hasAnimation;
|
|
107
106
|
private playingAnimation;
|
|
108
|
-
private
|
|
109
|
-
private
|
|
107
|
+
private animationStartTime;
|
|
108
|
+
private animationDuration;
|
|
109
|
+
private boneTracks;
|
|
110
|
+
private morphTracks;
|
|
110
111
|
constructor(canvas: HTMLCanvasElement, options?: EngineOptions);
|
|
111
112
|
init(): Promise<void>;
|
|
112
113
|
private createPipelines;
|
|
@@ -119,19 +120,16 @@ export declare class Engine {
|
|
|
119
120
|
private setupLighting;
|
|
120
121
|
private setAmbientColor;
|
|
121
122
|
loadAnimation(url: string): Promise<void>;
|
|
122
|
-
playAnimation(
|
|
123
|
-
breathBones?: string[] | Record<string, number>;
|
|
124
|
-
breathDuration?: number;
|
|
125
|
-
}): void;
|
|
123
|
+
playAnimation(): void;
|
|
126
124
|
stopAnimation(): void;
|
|
127
|
-
private
|
|
128
|
-
private startBreathing;
|
|
125
|
+
private animate;
|
|
129
126
|
getStats(): EngineStats;
|
|
130
127
|
runRenderLoop(callback?: () => void): void;
|
|
131
128
|
stopRenderLoop(): void;
|
|
132
129
|
dispose(): void;
|
|
133
130
|
loadModel(path: string): Promise<void>;
|
|
134
131
|
rotateBones(bones: string[], rotations: Quat[], durationMs?: number): void;
|
|
132
|
+
moveBones(bones: string[], relativeTranslations: Vec3[], durationMs?: number): void;
|
|
135
133
|
setMorphWeight(name: string, weight: number, durationMs?: number): void;
|
|
136
134
|
private updateVertexBuffer;
|
|
137
135
|
private setupModelBuffers;
|
package/dist/engine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAEA,OAAO,EAAQ,IAAI,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAMzC,MAAM,MAAM,aAAa,GAAG;IAC1B,YAAY,CAAC,EAAE,IAAI,CAAA;IACnB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB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