reze-engine 0.69.8 → 0.70.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/dist/_dbg-loader.mjs +1100 -0
- package/dist/camera-mount.d.ts +57 -0
- package/dist/camera-mount.d.ts.map +1 -0
- package/dist/camera-mount.js +249 -0
- package/dist/camera.d.ts +11 -0
- package/dist/camera.d.ts.map +1 -1
- package/dist/camera.js +31 -7
- package/dist/engine.d.ts +130 -2
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +476 -12
- package/dist/graph/compile.js +1 -1
- package/dist/graph/registry.d.ts.map +1 -1
- package/dist/graph/registry.js +19 -2
- package/dist/graph/slots.js +117 -117
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/model.d.ts +35 -0
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +170 -0
- package/dist/shaders/materials/common.d.ts +11 -1
- package/dist/shaders/materials/common.d.ts.map +1 -1
- package/dist/shaders/materials/common.js +571 -548
- package/dist/shaders/passes/cull.d.ts +1 -1
- package/dist/shaders/passes/cull.d.ts.map +1 -1
- package/dist/shaders/passes/cull.js +4 -1
- package/dist/shaders/passes/motion-blur.d.ts +35 -0
- package/dist/shaders/passes/motion-blur.d.ts.map +1 -0
- package/dist/shaders/passes/motion-blur.js +166 -0
- package/dist/shaders/passes/particles.d.ts.map +1 -1
- package/dist/shaders/passes/particles.js +13 -2
- package/dist/shaders/passes/shadow.d.ts +1 -1
- package/dist/shaders/passes/shadow.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/camera-mount.ts +281 -0
- package/src/camera.ts +27 -4
- package/src/engine.ts +21741 -21249
- package/src/graph/compile.ts +1 -1
- package/src/graph/registry.ts +20 -3
- package/src/graph/slots.ts +304 -304
- package/src/index.ts +4 -1
- package/src/model.ts +193 -0
- package/src/shaders/materials/common.ts +706 -682
- package/src/shaders/passes/cull.ts +4 -1
- package/src/shaders/passes/motion-blur.ts +171 -0
- package/src/shaders/passes/particles.ts +14 -2
package/dist/model.js
CHANGED
|
@@ -33,6 +33,60 @@ const smooth01 = (a, b, x) => {
|
|
|
33
33
|
/** VRM's range map: `inMax` degrees of target offset onto `out` degrees of eye,
|
|
34
34
|
* linearly — a look-at that never saturates. */
|
|
35
35
|
const rangeMap = (v, inMax, out) => (Math.min(Math.abs(v), inMax) / inMax) * out * Math.sign(v);
|
|
36
|
+
// ─── Auto blink (see Model.setAutoBlink) ───
|
|
37
|
+
/** Morphs that close both eyes, in order of preference. */
|
|
38
|
+
const BLINK_BOTH = ["まばたき", "blink", "Blink", "eye_close", "Fcl_EYE_Close"];
|
|
39
|
+
/** Left and right pairs, for a model without one. ウィンク2 is the plain
|
|
40
|
+
* closed eye; ウィンク often comes with a smile, so it is the last resort. */
|
|
41
|
+
const BLINK_PAIRS = [
|
|
42
|
+
["ウィンク2", "ウィンク2右"],
|
|
43
|
+
["ウィンク2", "ウィンク2右"],
|
|
44
|
+
["blink_L", "blink_R"],
|
|
45
|
+
["Fcl_EYE_Close_L", "Fcl_EYE_Close_R"],
|
|
46
|
+
["ウィンク", "ウィンク右"],
|
|
47
|
+
["ウィンク", "ウィンク右"],
|
|
48
|
+
["wink", "wink_R"],
|
|
49
|
+
["Wink", "Wink_R"],
|
|
50
|
+
];
|
|
51
|
+
/** A blink's shape at speed 1, seconds — about 0.33 s in all, the 6–8 frames
|
|
52
|
+
* an anime blink runs at 24 fps. Measured blinks close in 75–100 ms, rest shut
|
|
53
|
+
* 10–50 ms and open about twice as slowly, quick at first and then settling
|
|
54
|
+
* (the lid lifts against the orbit's pull), so the close is short and the
|
|
55
|
+
* open long with a tail. A symmetric ease reads mechanical. */
|
|
56
|
+
const BLINK_CLOSE = 0.09;
|
|
57
|
+
const BLINK_HOLD = 0.04;
|
|
58
|
+
const BLINK_OPEN = 0.2;
|
|
59
|
+
/** How often a blink is doubled, and how soon the second follows (at speed 1). */
|
|
60
|
+
const BLINK_DOUBLE = 0.15;
|
|
61
|
+
const BLINK_DOUBLE_GAP = 0.4;
|
|
62
|
+
/** A fixed value in 0..1 for an integer — the same sequence every take. */
|
|
63
|
+
const blinkHash = (n) => {
|
|
64
|
+
let h = Math.imul(n ^ 0x9e3779b9, 0x85ebca6b);
|
|
65
|
+
h = Math.imul(h ^ (h >>> 13), 0xc2b2ae35);
|
|
66
|
+
h ^= h >>> 16;
|
|
67
|
+
return (h >>> 0) / 4294967296;
|
|
68
|
+
};
|
|
69
|
+
const blinkGap = (n, interval) => interval * (0.5 + blinkHash(n));
|
|
70
|
+
/** How shut the eyes are t seconds into a blink at speed 1. The close is a
|
|
71
|
+
* quick smooth drop; the open leaves fast and settles slowly (a cubic ease-out,
|
|
72
|
+
* most of the lift in the first third and the rest a long approach to open). */
|
|
73
|
+
const blinkCurve = (t) => {
|
|
74
|
+
if (t < 0)
|
|
75
|
+
return 0;
|
|
76
|
+
if (t < BLINK_CLOSE) {
|
|
77
|
+
const x = t / BLINK_CLOSE;
|
|
78
|
+
return x * x * (3 - 2 * x);
|
|
79
|
+
}
|
|
80
|
+
t -= BLINK_CLOSE;
|
|
81
|
+
if (t < BLINK_HOLD)
|
|
82
|
+
return 1;
|
|
83
|
+
t -= BLINK_HOLD;
|
|
84
|
+
if (t < BLINK_OPEN) {
|
|
85
|
+
const x = 1 - t / BLINK_OPEN;
|
|
86
|
+
return x * x * x;
|
|
87
|
+
}
|
|
88
|
+
return 0;
|
|
89
|
+
};
|
|
36
90
|
// Scratch for the post-physics append recovery — see applyPhysicsAppend.
|
|
37
91
|
const _appendBasisX = new Vec3(0, 0, 0);
|
|
38
92
|
const _appendBasisY = new Vec3(0, 0, 0);
|
|
@@ -273,6 +327,10 @@ export class Model {
|
|
|
273
327
|
/** Set when the eyes are handed back, so the next update starts them from
|
|
274
328
|
* rest before the pose sources run — see update(). */
|
|
275
329
|
this.eyesReleased = false;
|
|
330
|
+
// ─── Auto blink ──────────────────────────────────────────────────────
|
|
331
|
+
/** The closing morphs auto blink drives (one for both eyes, or a left and
|
|
332
|
+
* right pair), or null while it is off. */
|
|
333
|
+
this.autoBlink = null;
|
|
276
334
|
/**
|
|
277
335
|
* IK bones whose chains are switched OFF at the current frame.
|
|
278
336
|
*
|
|
@@ -894,6 +952,115 @@ export class Model {
|
|
|
894
952
|
hasEyeTracking() {
|
|
895
953
|
return this.eyeTracking !== null;
|
|
896
954
|
}
|
|
955
|
+
/**
|
|
956
|
+
* Auto blink: she blinks every few seconds on her own, as eyes do — a
|
|
957
|
+
* natural irregular gap around `interval`, now and then a double blink.
|
|
958
|
+
*
|
|
959
|
+
* A MORPH, on the model's own closing morph (まばたき, or a left and right
|
|
960
|
+
* wink pair when there is none). It OWNS that morph while on, as eye
|
|
961
|
+
* tracking owns the eye bones: a morph motion's own まばたき keys are
|
|
962
|
+
* replaced, and handed back when it goes off. Its other expressions (a
|
|
963
|
+
* smile, a wince) play as keyed. Steps on the scene clock (the delta
|
|
964
|
+
* update() is handed, every frame, playing or paused) through a fixed
|
|
965
|
+
* sequence of gaps.
|
|
966
|
+
*
|
|
967
|
+
* Null hands the morph back. Returns false for a model with no closing morph.
|
|
968
|
+
*/
|
|
969
|
+
setAutoBlink(options) {
|
|
970
|
+
if (!options) {
|
|
971
|
+
const b = this.autoBlink;
|
|
972
|
+
if (b) {
|
|
973
|
+
b.morphs.forEach((m, i) => (this.runtimeMorph.weights[m] = b.base[i]));
|
|
974
|
+
this.morphsDirty = true;
|
|
975
|
+
}
|
|
976
|
+
this.autoBlink = null;
|
|
977
|
+
return true;
|
|
978
|
+
}
|
|
979
|
+
const opts = {
|
|
980
|
+
interval: Math.min(10, Math.max(1, options.interval ?? 4)),
|
|
981
|
+
speed: Math.min(2, Math.max(0.5, options.speed ?? 1)),
|
|
982
|
+
double: options.double ?? true,
|
|
983
|
+
};
|
|
984
|
+
if (this.autoBlink) {
|
|
985
|
+
// A new interval takes from the next gap on; the current one stands.
|
|
986
|
+
this.autoBlink.options = opts;
|
|
987
|
+
return true;
|
|
988
|
+
}
|
|
989
|
+
const morphs = this.blinkMorphs();
|
|
990
|
+
if (!morphs)
|
|
991
|
+
return false;
|
|
992
|
+
const weights = this.runtimeMorph.weights;
|
|
993
|
+
this.autoBlink = {
|
|
994
|
+
morphs,
|
|
995
|
+
base: morphs.map((m) => weights[m]),
|
|
996
|
+
written: morphs.map((m) => weights[m]),
|
|
997
|
+
clock: 0,
|
|
998
|
+
start: -1,
|
|
999
|
+
next: blinkGap(0, opts.interval),
|
|
1000
|
+
count: 0,
|
|
1001
|
+
double: false,
|
|
1002
|
+
options: opts,
|
|
1003
|
+
};
|
|
1004
|
+
return true;
|
|
1005
|
+
}
|
|
1006
|
+
getAutoBlink() {
|
|
1007
|
+
return this.autoBlink ? { ...this.autoBlink.options } : null;
|
|
1008
|
+
}
|
|
1009
|
+
/** The morphs that close both eyes, by the names MMD, VRoid and the usual
|
|
1010
|
+
* converters give them. A smile or a wince closes them too and is no blink. */
|
|
1011
|
+
blinkMorphs() {
|
|
1012
|
+
const ni = this.runtimeMorph.nameIndex;
|
|
1013
|
+
for (const n of BLINK_BOTH)
|
|
1014
|
+
if (ni[n] !== undefined)
|
|
1015
|
+
return [ni[n]];
|
|
1016
|
+
for (const [l, r] of BLINK_PAIRS)
|
|
1017
|
+
if (ni[l] !== undefined && ni[r] !== undefined)
|
|
1018
|
+
return [ni[l], ni[r]];
|
|
1019
|
+
return null;
|
|
1020
|
+
}
|
|
1021
|
+
/** One frame of auto blink, after the pose sources set the morphs and before
|
|
1022
|
+
* they are applied. True when it moved a weight. */
|
|
1023
|
+
stepAutoBlink(dt) {
|
|
1024
|
+
const b = this.autoBlink;
|
|
1025
|
+
const { interval, speed, double } = b.options;
|
|
1026
|
+
const weights = this.runtimeMorph.weights;
|
|
1027
|
+
// A weight that is not what we wrote was set afresh this frame.
|
|
1028
|
+
for (let i = 0; i < b.morphs.length; i++) {
|
|
1029
|
+
const w = weights[b.morphs[i]];
|
|
1030
|
+
if (w !== b.written[i])
|
|
1031
|
+
b.base[i] = w;
|
|
1032
|
+
}
|
|
1033
|
+
if (dt > 0)
|
|
1034
|
+
b.clock += dt;
|
|
1035
|
+
// A seek back (or a scrub to the start) begins the sequence again.
|
|
1036
|
+
if (dt < 0) {
|
|
1037
|
+
b.clock = 0;
|
|
1038
|
+
b.start = -1;
|
|
1039
|
+
b.count = 0;
|
|
1040
|
+
b.double = false;
|
|
1041
|
+
b.next = blinkGap(0, interval);
|
|
1042
|
+
}
|
|
1043
|
+
// A loop, so a long jump forward lands on the blink it is in, not on each one passed.
|
|
1044
|
+
while (b.clock >= b.next) {
|
|
1045
|
+
b.start = b.next;
|
|
1046
|
+
b.count++;
|
|
1047
|
+
// Now and then a second blink follows straight after the first — never a third.
|
|
1048
|
+
b.double = double && !b.double && blinkHash(b.count * 7 + 3) < BLINK_DOUBLE;
|
|
1049
|
+
b.next = b.start + (b.double ? BLINK_DOUBLE_GAP / speed : blinkGap(b.count, interval));
|
|
1050
|
+
}
|
|
1051
|
+
const w = blinkCurve((b.clock - b.start) * speed);
|
|
1052
|
+
let changed = false;
|
|
1053
|
+
for (let i = 0; i < b.morphs.length; i++) {
|
|
1054
|
+
if (weights[b.morphs[i]] !== w) {
|
|
1055
|
+
weights[b.morphs[i]] = w;
|
|
1056
|
+
changed = true;
|
|
1057
|
+
}
|
|
1058
|
+
// Read back: the weights are float32, and a float64 kept here never
|
|
1059
|
+
// compares equal, so our own write passed for the motion's next frame.
|
|
1060
|
+
b.written[i] = weights[b.morphs[i]];
|
|
1061
|
+
}
|
|
1062
|
+
return changed;
|
|
1063
|
+
}
|
|
897
1064
|
/**
|
|
898
1065
|
* Where she looks: a unit direction in model space, or null for a model
|
|
899
1066
|
* without eye bones. See RzSubject.gaze.
|
|
@@ -2521,6 +2688,9 @@ export class Model {
|
|
|
2521
2688
|
const r = this.runtimeSkeleton.localRotations[idx];
|
|
2522
2689
|
Quat.multiplyInto(r, offset, r);
|
|
2523
2690
|
}
|
|
2691
|
+
// The blink over whatever the motion and the host set this frame.
|
|
2692
|
+
if (this.autoBlink !== null && this.stepAutoBlink(deltaTime))
|
|
2693
|
+
this.morphsDirty = true;
|
|
2524
2694
|
// Apply morphs if tweens changed morphs or animation changed morphs
|
|
2525
2695
|
const verticesChanged = this.morphsDirty || tweensChangedMorphs;
|
|
2526
2696
|
if (this.morphsDirty || tweensChangedMorphs) {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
export declare const JELLY_VERTEX_WGSL = "\nfn _rzJellyTurn(q: vec2f, a: f32) -> vec2f {\n let c = cos(a);\n let s = sin(a);\n return vec2f(c * q.x - s * q.y, s * q.x + c * q.y);\n}\n\n/**\n * Where the jelly puts an iris vertex. The iris is the part of the eye the eye\n * bones carry, so it is moved as a whole, in bind space before skinning:\n * scaled about its centre (the CPU composes the blink's spring, the lid's\n * press and her motion's knock into one scale), turned and drifted a hair on\n * the spring, brought forward a hair, and rolled about the eye bone with a\n * closing expression \u2014 inside the white, which stays where it is. A highlight\n * layer (this draw's material is one of jelly[1].w's) takes the iris's move,\n * then its own scale, turn and tremble, before the roll. Vertices take it by their weight on the eye bones\n * (jelly[2].w, jelly[3].w), so nothing else on the face moves.\n */\nfn rzJellyVertex(p: vec3f, joints: vec4<u32>, nw: vec4f) -> vec3f {\n let j = objectLight.jelly;\n let ids = u32(j[1].w);\n let mid = u32(material.materialId);\n let hl = mid > 0u && (mid == (ids & 4095u) || mid == (ids >> 12u));\n var out = p;\n for (var e = 0u; e < 2u; e++) {\n let bone = j[2u + e].w;\n if (bone < 0.0) { continue; }\n let b = u32(bone);\n let w = dot(nw, select(vec4f(0.0), vec4f(1.0), joints == vec4<u32>(b)));\n if (w <= 0.0) { continue; }\n let c = j[e].xyz;\n // A rig that carries both eyes on one bone: each vertex follows its own side.\n if (j[2].w == j[3].w && e == 0u && distance(p.xy, j[1].xy) < distance(p.xy, j[0].xy)) { continue; }\n if (j[2].w == j[3].w && e == 1u && distance(p.xy, j[0].xy) <= distance(p.xy, j[1].xy)) { continue; }\n let t = j[4u + e];\n let m = j[6u + e];\n let h = j[10u + e];\n var q = _rzJellyTurn((p.xy - c.xy) * t.xy, t.z) + m.xy;\n // Forward is \u2212Z (MMD faces \u2212Z).\n var push = h.z;\n if (hl) {\n // Sliding over the iris's dome on its own, a highlight sheet a hair in\n // front of it would sink into it where the dome bulges more and the two\n // fight for depth; so it comes forward by as far as it slid \u2014 a slope of\n // one, steeper than the dome anywhere it draws.\n let before = q;\n q = _rzJellyTurn(q * h.xy, t.w) + m.zw;\n push += length(q - before);\n }\n var moved = vec3f(c.xy + q, p.z - push);\n let roll = j[8u + e];\n if (roll.w != 0.0) {\n let d = moved - roll.xyz;\n let rd = _rzJellyTurn(d.yz, roll.w);\n moved = roll.xyz + vec3f(d.x, rd.x, rd.y);\n }\n out = mix(p, moved, w);\n }\n return out;\n}\n";
|
|
7
7
|
/** A model's ObjectLight as WGSL declares it (see the layout below). One copy
|
|
8
8
|
* for every pass that binds it, so their layouts cannot drift. */
|
|
9
|
-
export declare const OBJECT_LIGHT_STRUCT_WGSL = "struct ObjectLight { layers: vec4u, ambient: vec4f, sh: array<vec4f, 9>, fill: vec4f, jelly: array<vec4f, 12>, bloom: vec4f, xray: array<vec4f, 4>, xrayMask: array<vec4u, 16> }";
|
|
9
|
+
export declare const OBJECT_LIGHT_STRUCT_WGSL = "struct ObjectLight { layers: vec4u, ambient: vec4f, sh: array<vec4f, 9>, fill: vec4f, jelly: array<vec4f, 12>, bloom: vec4f, xray: array<vec4f, 4>, xrayMask: array<vec4u, 16>, matLayers: array<vec4u, 128> }";
|
|
10
10
|
/**
|
|
11
11
|
* The see-through window (#xray): a rectangle on the frame, in pixels —
|
|
12
12
|
* xray[0] is (left, top, right, bottom), xray[3].x is 1 while a window is open
|
|
@@ -16,6 +16,16 @@ export declare const OBJECT_LIGHT_STRUCT_WGSL = "struct ObjectLight { layers: ve
|
|
|
16
16
|
* behind it. Declared after the pass's own `objectLight` binding.
|
|
17
17
|
*/
|
|
18
18
|
export declare const XRAY_WGSL = "\nfn rz_xray_inside(fp: vec4f) -> bool {\n if (objectLight.xray[3].x < 0.5) { return false; }\n let r = objectLight.xray[0];\n return fp.x >= r.x && fp.y >= r.y && fp.x <= r.z && fp.y <= r.w;\n}\nfn rz_xray_cut(fp: vec4f, materialId: f32) -> bool {\n let i = u32(materialId);\n if (i >= 512u) { return false; }\n let word = objectLight.xrayMask[i / 128u][(i / 32u) % 4u];\n if (((word >> (i % 32u)) & 1u) == 0u) { return false; }\n return rz_xray_inside(fp);\n}\n";
|
|
19
|
+
/**
|
|
20
|
+
* The rendering layers this draw is on: its material's own where the model
|
|
21
|
+
* gives it some (objectLight.matLayers, by the 1-based materialId, up to 511),
|
|
22
|
+
* else the model's. A game lights its renderers one by one — URP hands each
|
|
23
|
+
* object its own few lamps — and a converted stage is one model of many such
|
|
24
|
+
* renderers, so the bits a light is tested against have to be able to differ
|
|
25
|
+
* from material to material. Zero, which every model leaves there, is "the
|
|
26
|
+
* model's". Declared after the pass's own `objectLight` and `material` bindings.
|
|
27
|
+
*/
|
|
28
|
+
export declare const DRAW_LAYERS_WGSL = "\nfn rzDrawLayers() -> u32 {\n let i = u32(material.materialId);\n if (i >= 512u) { return objectLight.layers.x; }\n let own = objectLight.matLayers[i / 4u][i % 4u];\n return select(objectLight.layers.x, own, own != 0u);\n}\n";
|
|
19
29
|
export declare const COMMON_BINDINGS_WGSL: string;
|
|
20
30
|
export declare function commonFsOutWgsl(): string;
|
|
21
31
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/shaders/materials/common.ts"],"names":[],"mappings":"AA4BA;;;;uBAIuB;AACvB,eAAO,MAAM,iBAAiB,8iFA4D7B,CAAA;AAED;mEACmE;AACnE,eAAO,MAAM,wBAAwB,
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/shaders/materials/common.ts"],"names":[],"mappings":"AA4BA;;;;uBAIuB;AACvB,eAAO,MAAM,iBAAiB,8iFA4D7B,CAAA;AAED;mEACmE;AACnE,eAAO,MAAM,wBAAwB,mNAC6K,CAAA;AAElN;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS,4dAarB,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,0OAO5B,CAAA;AAED,eAAO,MAAM,oBAAoB,QAwQhC,CAAC;AA2JF,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAGD;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,aAAa,orMAgHzB,CAAA;AAQD,eAAO,MAAM,4BAA4B,QAC0I,CAAA"}
|