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/src/model.ts
CHANGED
|
@@ -52,6 +52,70 @@ const smooth01 = (a: number, b: number, x: number): number => {
|
|
|
52
52
|
const rangeMap = (v: number, inMax: number, out: number): number =>
|
|
53
53
|
(Math.min(Math.abs(v), inMax) / inMax) * out * Math.sign(v)
|
|
54
54
|
|
|
55
|
+
// ─── Auto blink (see Model.setAutoBlink) ───
|
|
56
|
+
/** Morphs that close both eyes, in order of preference. */
|
|
57
|
+
const BLINK_BOTH = ["まばたき", "blink", "Blink", "eye_close", "Fcl_EYE_Close"]
|
|
58
|
+
/** Left and right pairs, for a model without one. ウィンク2 is the plain
|
|
59
|
+
* closed eye; ウィンク often comes with a smile, so it is the last resort. */
|
|
60
|
+
const BLINK_PAIRS: [string, string][] = [
|
|
61
|
+
["ウィンク2", "ウィンク2右"],
|
|
62
|
+
["ウィンク2", "ウィンク2右"],
|
|
63
|
+
["blink_L", "blink_R"],
|
|
64
|
+
["Fcl_EYE_Close_L", "Fcl_EYE_Close_R"],
|
|
65
|
+
["ウィンク", "ウィンク右"],
|
|
66
|
+
["ウィンク", "ウィンク右"],
|
|
67
|
+
["wink", "wink_R"],
|
|
68
|
+
["Wink", "Wink_R"],
|
|
69
|
+
]
|
|
70
|
+
/** A blink's shape at speed 1, seconds — about 0.33 s in all, the 6–8 frames
|
|
71
|
+
* an anime blink runs at 24 fps. Measured blinks close in 75–100 ms, rest shut
|
|
72
|
+
* 10–50 ms and open about twice as slowly, quick at first and then settling
|
|
73
|
+
* (the lid lifts against the orbit's pull), so the close is short and the
|
|
74
|
+
* open long with a tail. A symmetric ease reads mechanical. */
|
|
75
|
+
const BLINK_CLOSE = 0.09
|
|
76
|
+
const BLINK_HOLD = 0.04
|
|
77
|
+
const BLINK_OPEN = 0.2
|
|
78
|
+
/** How often a blink is doubled, and how soon the second follows (at speed 1). */
|
|
79
|
+
const BLINK_DOUBLE = 0.15
|
|
80
|
+
const BLINK_DOUBLE_GAP = 0.4
|
|
81
|
+
|
|
82
|
+
/** What setAutoBlink asks for. */
|
|
83
|
+
export interface AutoBlinkOptions {
|
|
84
|
+
/** The average gap between blinks, seconds; each gap is drawn from half to
|
|
85
|
+
* one and a half times it. 1–10, default 4. */
|
|
86
|
+
interval?: number
|
|
87
|
+
/** How fast one blink is: 2 takes half as long. 0.5–2, default 1. */
|
|
88
|
+
speed?: number
|
|
89
|
+
/** Whether a blink is now and then followed straight by a second. Default true. */
|
|
90
|
+
double?: boolean
|
|
91
|
+
}
|
|
92
|
+
/** A fixed value in 0..1 for an integer — the same sequence every take. */
|
|
93
|
+
const blinkHash = (n: number): number => {
|
|
94
|
+
let h = Math.imul(n ^ 0x9e3779b9, 0x85ebca6b)
|
|
95
|
+
h = Math.imul(h ^ (h >>> 13), 0xc2b2ae35)
|
|
96
|
+
h ^= h >>> 16
|
|
97
|
+
return (h >>> 0) / 4294967296
|
|
98
|
+
}
|
|
99
|
+
const blinkGap = (n: number, interval: number): number => interval * (0.5 + blinkHash(n))
|
|
100
|
+
/** How shut the eyes are t seconds into a blink at speed 1. The close is a
|
|
101
|
+
* quick smooth drop; the open leaves fast and settles slowly (a cubic ease-out,
|
|
102
|
+
* most of the lift in the first third and the rest a long approach to open). */
|
|
103
|
+
const blinkCurve = (t: number): number => {
|
|
104
|
+
if (t < 0) return 0
|
|
105
|
+
if (t < BLINK_CLOSE) {
|
|
106
|
+
const x = t / BLINK_CLOSE
|
|
107
|
+
return x * x * (3 - 2 * x)
|
|
108
|
+
}
|
|
109
|
+
t -= BLINK_CLOSE
|
|
110
|
+
if (t < BLINK_HOLD) return 1
|
|
111
|
+
t -= BLINK_HOLD
|
|
112
|
+
if (t < BLINK_OPEN) {
|
|
113
|
+
const x = 1 - t / BLINK_OPEN
|
|
114
|
+
return x * x * x
|
|
115
|
+
}
|
|
116
|
+
return 0
|
|
117
|
+
}
|
|
118
|
+
|
|
55
119
|
/** What setEyeTracking asks for. */
|
|
56
120
|
export interface EyeTrackingOptions {
|
|
57
121
|
/** 0..1 — how much of the solved gaze replaces the motion's own. Default 1. */
|
|
@@ -1278,6 +1342,132 @@ export class Model {
|
|
|
1278
1342
|
return this.eyeTracking !== null
|
|
1279
1343
|
}
|
|
1280
1344
|
|
|
1345
|
+
// ─── Auto blink ──────────────────────────────────────────────────────
|
|
1346
|
+
/** The closing morphs auto blink drives (one for both eyes, or a left and
|
|
1347
|
+
* right pair), or null while it is off. */
|
|
1348
|
+
private autoBlink: {
|
|
1349
|
+
morphs: number[]
|
|
1350
|
+
/** Each morph's weight without the blink: what the motion or the host set,
|
|
1351
|
+
* handed back when the blink goes off. */
|
|
1352
|
+
base: number[]
|
|
1353
|
+
/** What the blink last wrote, to tell a fresh write from our own. */
|
|
1354
|
+
written: number[]
|
|
1355
|
+
clock: number
|
|
1356
|
+
/** When the current blink started, and the next. */
|
|
1357
|
+
start: number
|
|
1358
|
+
next: number
|
|
1359
|
+
count: number
|
|
1360
|
+
/** Whether the current blink is the first of a double. */
|
|
1361
|
+
double: boolean
|
|
1362
|
+
options: Required<AutoBlinkOptions>
|
|
1363
|
+
} | null = null
|
|
1364
|
+
|
|
1365
|
+
/**
|
|
1366
|
+
* Auto blink: she blinks every few seconds on her own, as eyes do — a
|
|
1367
|
+
* natural irregular gap around `interval`, now and then a double blink.
|
|
1368
|
+
*
|
|
1369
|
+
* A MORPH, on the model's own closing morph (まばたき, or a left and right
|
|
1370
|
+
* wink pair when there is none). It OWNS that morph while on, as eye
|
|
1371
|
+
* tracking owns the eye bones: a morph motion's own まばたき keys are
|
|
1372
|
+
* replaced, and handed back when it goes off. Its other expressions (a
|
|
1373
|
+
* smile, a wince) play as keyed. Steps on the scene clock (the delta
|
|
1374
|
+
* update() is handed, every frame, playing or paused) through a fixed
|
|
1375
|
+
* sequence of gaps.
|
|
1376
|
+
*
|
|
1377
|
+
* Null hands the morph back. Returns false for a model with no closing morph.
|
|
1378
|
+
*/
|
|
1379
|
+
setAutoBlink(options: AutoBlinkOptions | null): boolean {
|
|
1380
|
+
if (!options) {
|
|
1381
|
+
const b = this.autoBlink
|
|
1382
|
+
if (b) {
|
|
1383
|
+
b.morphs.forEach((m, i) => (this.runtimeMorph.weights[m] = b.base[i]))
|
|
1384
|
+
this.morphsDirty = true
|
|
1385
|
+
}
|
|
1386
|
+
this.autoBlink = null
|
|
1387
|
+
return true
|
|
1388
|
+
}
|
|
1389
|
+
const opts: Required<AutoBlinkOptions> = {
|
|
1390
|
+
interval: Math.min(10, Math.max(1, options.interval ?? 4)),
|
|
1391
|
+
speed: Math.min(2, Math.max(0.5, options.speed ?? 1)),
|
|
1392
|
+
double: options.double ?? true,
|
|
1393
|
+
}
|
|
1394
|
+
if (this.autoBlink) {
|
|
1395
|
+
// A new interval takes from the next gap on; the current one stands.
|
|
1396
|
+
this.autoBlink.options = opts
|
|
1397
|
+
return true
|
|
1398
|
+
}
|
|
1399
|
+
const morphs = this.blinkMorphs()
|
|
1400
|
+
if (!morphs) return false
|
|
1401
|
+
const weights = this.runtimeMorph.weights
|
|
1402
|
+
this.autoBlink = {
|
|
1403
|
+
morphs,
|
|
1404
|
+
base: morphs.map((m) => weights[m]),
|
|
1405
|
+
written: morphs.map((m) => weights[m]),
|
|
1406
|
+
clock: 0,
|
|
1407
|
+
start: -1,
|
|
1408
|
+
next: blinkGap(0, opts.interval),
|
|
1409
|
+
count: 0,
|
|
1410
|
+
double: false,
|
|
1411
|
+
options: opts,
|
|
1412
|
+
}
|
|
1413
|
+
return true
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
getAutoBlink(): Required<AutoBlinkOptions> | null {
|
|
1417
|
+
return this.autoBlink ? { ...this.autoBlink.options } : null
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
/** The morphs that close both eyes, by the names MMD, VRoid and the usual
|
|
1421
|
+
* converters give them. A smile or a wince closes them too and is no blink. */
|
|
1422
|
+
private blinkMorphs(): number[] | null {
|
|
1423
|
+
const ni = this.runtimeMorph.nameIndex
|
|
1424
|
+
for (const n of BLINK_BOTH) if (ni[n] !== undefined) return [ni[n]]
|
|
1425
|
+
for (const [l, r] of BLINK_PAIRS) if (ni[l] !== undefined && ni[r] !== undefined) return [ni[l], ni[r]]
|
|
1426
|
+
return null
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
/** One frame of auto blink, after the pose sources set the morphs and before
|
|
1430
|
+
* they are applied. True when it moved a weight. */
|
|
1431
|
+
private stepAutoBlink(dt: number): boolean {
|
|
1432
|
+
const b = this.autoBlink!
|
|
1433
|
+
const { interval, speed, double } = b.options
|
|
1434
|
+
const weights = this.runtimeMorph.weights
|
|
1435
|
+
// A weight that is not what we wrote was set afresh this frame.
|
|
1436
|
+
for (let i = 0; i < b.morphs.length; i++) {
|
|
1437
|
+
const w = weights[b.morphs[i]]
|
|
1438
|
+
if (w !== b.written[i]) b.base[i] = w
|
|
1439
|
+
}
|
|
1440
|
+
if (dt > 0) b.clock += dt
|
|
1441
|
+
// A seek back (or a scrub to the start) begins the sequence again.
|
|
1442
|
+
if (dt < 0) {
|
|
1443
|
+
b.clock = 0
|
|
1444
|
+
b.start = -1
|
|
1445
|
+
b.count = 0
|
|
1446
|
+
b.double = false
|
|
1447
|
+
b.next = blinkGap(0, interval)
|
|
1448
|
+
}
|
|
1449
|
+
// A loop, so a long jump forward lands on the blink it is in, not on each one passed.
|
|
1450
|
+
while (b.clock >= b.next) {
|
|
1451
|
+
b.start = b.next
|
|
1452
|
+
b.count++
|
|
1453
|
+
// Now and then a second blink follows straight after the first — never a third.
|
|
1454
|
+
b.double = double && !b.double && blinkHash(b.count * 7 + 3) < BLINK_DOUBLE
|
|
1455
|
+
b.next = b.start + (b.double ? BLINK_DOUBLE_GAP / speed : blinkGap(b.count, interval))
|
|
1456
|
+
}
|
|
1457
|
+
const w = blinkCurve((b.clock - b.start) * speed)
|
|
1458
|
+
let changed = false
|
|
1459
|
+
for (let i = 0; i < b.morphs.length; i++) {
|
|
1460
|
+
if (weights[b.morphs[i]] !== w) {
|
|
1461
|
+
weights[b.morphs[i]] = w
|
|
1462
|
+
changed = true
|
|
1463
|
+
}
|
|
1464
|
+
// Read back: the weights are float32, and a float64 kept here never
|
|
1465
|
+
// compares equal, so our own write passed for the motion's next frame.
|
|
1466
|
+
b.written[i] = weights[b.morphs[i]]
|
|
1467
|
+
}
|
|
1468
|
+
return changed
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1281
1471
|
/**
|
|
1282
1472
|
* Where she looks: a unit direction in model space, or null for a model
|
|
1283
1473
|
* without eye bones. See RzSubject.gaze.
|
|
@@ -2960,6 +3150,9 @@ export class Model {
|
|
|
2960
3150
|
Quat.multiplyInto(r, offset, r)
|
|
2961
3151
|
}
|
|
2962
3152
|
|
|
3153
|
+
// The blink over whatever the motion and the host set this frame.
|
|
3154
|
+
if (this.autoBlink !== null && this.stepAutoBlink(deltaTime)) this.morphsDirty = true
|
|
3155
|
+
|
|
2963
3156
|
// Apply morphs if tweens changed morphs or animation changed morphs
|
|
2964
3157
|
const verticesChanged = this.morphsDirty || tweensChangedMorphs
|
|
2965
3158
|
if (this.morphsDirty || tweensChangedMorphs) {
|