reze-engine 0.68.8 → 0.68.9

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.
Files changed (59) hide show
  1. package/dist/engine.d.ts +2 -6
  2. package/dist/engine.d.ts.map +1 -1
  3. package/dist/engine.js +39 -41
  4. package/dist/graph/presets/pool_floor.d.ts +3 -0
  5. package/dist/graph/presets/pool_floor.d.ts.map +1 -0
  6. package/dist/graph/presets/pool_floor.js +42 -0
  7. package/dist/graph/presets/water.d.ts +3 -0
  8. package/dist/graph/presets/water.d.ts.map +1 -0
  9. package/dist/graph/presets/water.js +31 -0
  10. package/dist/graph/slots.d.ts.map +1 -1
  11. package/dist/graph/slots.js +5 -4
  12. package/dist/jelly-eyes.d.ts.map +1 -1
  13. package/dist/jelly-eyes.js +43 -17
  14. package/dist/physics/autofit.d.ts +147 -0
  15. package/dist/physics/autofit.d.ts.map +1 -0
  16. package/dist/physics/autofit.js +501 -0
  17. package/dist/shaders/agx-lut.d.ts +11 -0
  18. package/dist/shaders/agx-lut.d.ts.map +1 -0
  19. package/dist/shaders/agx-lut.js +29 -0
  20. package/dist/shaders/dfg_lut.d.ts +3 -0
  21. package/dist/shaders/dfg_lut.d.ts.map +1 -0
  22. package/dist/shaders/dfg_lut.js +129 -0
  23. package/dist/shaders/ltc_mag_lut.d.ts +3 -0
  24. package/dist/shaders/ltc_mag_lut.d.ts.map +1 -0
  25. package/dist/shaders/ltc_mag_lut.js +1033 -0
  26. package/dist/shaders/materials/common.d.ts +6 -0
  27. package/dist/shaders/materials/common.d.ts.map +1 -1
  28. package/dist/shaders/materials/common.js +67 -60
  29. package/dist/shaders/passes/depth-prepass.d.ts.map +1 -1
  30. package/dist/shaders/passes/depth-prepass.js +11 -3
  31. package/dist/shaders/passes/field-blit.d.ts +26 -0
  32. package/dist/shaders/passes/field-blit.d.ts.map +1 -0
  33. package/dist/shaders/passes/field-blit.js +65 -0
  34. package/dist/shaders/passes/ghosts.d.ts +22 -0
  35. package/dist/shaders/passes/ghosts.d.ts.map +1 -0
  36. package/dist/shaders/passes/ghosts.js +75 -0
  37. package/dist/shaders/passes/ground-noise.d.ts +7 -0
  38. package/dist/shaders/passes/ground-noise.d.ts.map +1 -0
  39. package/dist/shaders/passes/ground-noise.js +88 -0
  40. package/dist/shaders/passes/shadow.d.ts +1 -1
  41. package/dist/shaders/passes/shadow.d.ts.map +1 -1
  42. package/dist/shaders/passes/shadow.js +11 -3
  43. package/dist/shaders/passes/sim.d.ts +34 -0
  44. package/dist/shaders/passes/sim.d.ts.map +1 -0
  45. package/dist/shaders/passes/sim.js +169 -0
  46. package/dist/shaders/score-api.d.ts +10 -0
  47. package/dist/shaders/score-api.d.ts.map +1 -0
  48. package/dist/shaders/score-api.js +114 -0
  49. package/dist/shaders/shadow-api.d.ts +29 -0
  50. package/dist/shaders/shadow-api.d.ts.map +1 -0
  51. package/dist/shaders/shadow-api.js +112 -0
  52. package/package.json +1 -1
  53. package/src/engine.ts +39 -47
  54. package/src/graph/slots.ts +5 -4
  55. package/src/jelly-eyes.ts +41 -17
  56. package/src/shaders/materials/common.ts +68 -60
  57. package/src/shaders/passes/depth-prepass.ts +11 -3
  58. package/src/shaders/passes/shadow.ts +11 -3
  59. package/dist/_dbg-loader.mjs +0 -1100
@@ -78,23 +78,23 @@ const HL_SCALE_MIN = 0.85;
78
78
  const HL_SCALE_MAX = 1.2;
79
79
  // The roll: while a closing expression holds, the iris turns about its eye
80
80
  // bone's X axis (左目/右目, the eyeball's centre), rolling down with the lid —
81
- // the angle at weight 1, and simultaneous expressions add. And it comes
82
- // forward a little (iris radii) with the expression and with the spring, so
83
- // the roll does not sink it into the white. The MME rolls with the lid
84
- // exactly, which the lid hides; here the roll follows on a spring of the same
85
- // pace and decay as the blink's, so as the eye opens the iris swings up past
86
- // rest and wobbles back, where it can be seen.
81
+ // the angle at weight 1, and simultaneous expressions add. It comes forward
82
+ // only with the spring (iris radii): pushed with the expression as well, a
83
+ // shut eye's iris came through a lid set close in front of it (白里黑子). The MME rolls with the lid
84
+ // exactly, which the lid hides; here the roll follows on a spring twice the
85
+ // blink's pace with its decay, so as the eye opens the iris swings up past rest
86
+ // and wobbles back, where it can be seen. At the blink's own pace it trailed
87
+ // the opening lid and swung a third of an iris past centre: a jump.
87
88
  const ROLL = {
88
89
  まばたき: -15, blink: -15, Blink: -15, eye_close: -15, Fcl_EYE_Close: -15, はぅ: -15, 笑い: -5,
89
90
  ウィンク: -5, ウィンク: -5, wink: -5, Wink: -5, ウィンク2: -15, ウィンク2: -15, blink_L: -15, Fcl_EYE_Close_L: -15,
90
91
  ウィンク右: -5, ウィンク右: -5, wink_R: -5, Wink_R: -5, ウィンク2右: -15, ウィンク2右: -15, blink_R: -15, Fcl_EYE_Close_R: -15,
91
92
  };
92
- const ROLL_HZ = SPRING_HZ;
93
- const ROLL_ZETA = Math.LN2 / HALF_LIFE / (2 * Math.PI * SPRING_HZ);
94
- // How much of the spring's swing about the expression angle shows: the whole
95
- // of it carried the iris up most of its radius after a blink.
96
- const ROLL_SWING = 0.4;
97
- const PUSH_EXPRESSION = 0.15;
93
+ const ROLL_HZ = 6;
94
+ const ROLL_ZETA = Math.LN2 / HALF_LIFE / (2 * Math.PI * ROLL_HZ);
95
+ // How much of the spring's swing about the expression angle shows: a
96
+ // twenty-fifth of an iris radius past centre after a blink.
97
+ const ROLL_SWING = 0.25;
98
98
  const PUSH_ELASTIC = 0.04;
99
99
  // A highlight sheet by name, for rigs that keep it on its own material.
100
100
  const HIGHLIGHT = /ハイライト|ハイライト|高光|highlight|hilight|(^|[^a-z])hl([^a-z]|$)/i;
@@ -200,10 +200,23 @@ export class JellyEyes {
200
200
  const l = index("左目");
201
201
  const r = index("右目");
202
202
  this.headBone = index("頭");
203
- const names = model.getMorphing().morphs.map((m) => m.name);
204
- const find = (list) => list.map((n) => names.indexOf(n)).filter((i) => i >= 0);
203
+ const all = model.getMorphing().morphs;
204
+ const names = all.map((m) => m.name);
205
+ // The weights read are resolved, so a group whose every target is named
206
+ // (Reze's まばたき is ウィンク2 + ウィンク2右) arrives through its
207
+ // leaves; counted as well, a blink rolled the iris twice as far.
208
+ const known = new Set([...BOTH, ...LEFT, ...RIGHT]);
209
+ const resolved = (i) => {
210
+ const refs = all[i].groupReferences;
211
+ return !!refs?.length && refs.every((r) => known.has(names[r.morphIndex]));
212
+ };
213
+ const morphIndex = (n) => {
214
+ const i = names.indexOf(n);
215
+ return i >= 0 && !resolved(i) ? i : -1;
216
+ };
217
+ const find = (list) => list.map(morphIndex).filter((i) => i >= 0);
205
218
  this.morphs = [find(BOTH), find(LEFT), find(RIGHT)];
206
- const rolls = (list) => list.map((n) => ({ morph: names.indexOf(n), deg: ROLL[n] ?? 0 })).filter((r) => r.morph >= 0 && r.deg !== 0);
219
+ const rolls = (list) => list.map((n) => ({ morph: morphIndex(n), deg: ROLL[n] ?? 0 })).filter((r) => r.morph >= 0 && r.deg !== 0);
207
220
  this.rolls = [rolls([...BOTH, ...LEFT]), rolls([...BOTH, ...RIGHT])];
208
221
  this.rest = findIrises(model, l, r, both);
209
222
  // The bone that carries each iris, which may be under the eye bone.
@@ -335,7 +348,7 @@ export class JellyEyes {
335
348
  const pivot = rest.pivot;
336
349
  o.set(pivot ? [pivot[0], pivot[1], pivot[2], (this.roll[e] + (s.roll - this.roll[e]) * ROLL_SWING) * DEG * g] : [0, 0, 0, 0], 80 + e * 4);
337
350
  const hs = (k) => Math.max(HL_SCALE_MIN, Math.min(HL_SCALE_MAX, 1 + x * HL_SCALE[k] * g));
338
- o.set([hs(0), hs(1), (s.closure * PUSH_EXPRESSION + Math.min(Math.abs(x), SPRING_LIMIT) * PUSH_ELASTIC) * r * g, 0], 88 + e * 4);
351
+ o.set([hs(0), hs(1), Math.min(Math.abs(x), SPRING_LIMIT) * PUSH_ELASTIC * r * g, 0], 88 + e * 4);
339
352
  }
340
353
  }
341
354
  /** Where the iris sits off rest, in iris radii (right, up): the lag through
@@ -460,6 +473,11 @@ function blink(s, dt) {
460
473
  * As draw ids (1-based over the materials that draw, as the engine numbers
461
474
  * MaterialUniforms.materialId), at most two. A rig whose highlight is painted
462
475
  * into the iris has none, and only the iris moves.
476
+ *
477
+ * A layer drawn on vertices an earlier layer already uses is a copy of that
478
+ * layer (白里黑子's ☆ and ❤ are star and heart irises on the iris's own
479
+ * vertices), so it moves with it. Slid as a highlight, a copy of the dome sits
480
+ * in front of the iris on one half, flipping sides with the tremble.
463
481
  */
464
482
  function findHighlights(model, rest) {
465
483
  const materials = model.getMaterials?.() ?? [];
@@ -468,6 +486,7 @@ function findHighlights(model, rest) {
468
486
  if (!materials.length || !indices.length || !iris.size)
469
487
  return [];
470
488
  const layers = [];
489
+ const used = new Set();
471
490
  let start = 0;
472
491
  let id = 0;
473
492
  for (const m of materials) {
@@ -476,17 +495,24 @@ function findHighlights(model, rest) {
476
495
  continue;
477
496
  id++;
478
497
  let minX = Infinity, maxX = -Infinity, minY = Infinity, maxY = -Infinity;
498
+ let copy = true;
499
+ const mine = [];
479
500
  for (let k = start; k < start + count; k++) {
480
501
  const v = indices[k];
481
502
  if (!iris.has(v))
482
503
  continue;
504
+ if (!used.has(v))
505
+ copy = false;
506
+ mine.push(v);
483
507
  minX = Math.min(minX, positions[v * 3]);
484
508
  maxX = Math.max(maxX, positions[v * 3]);
485
509
  minY = Math.min(minY, positions[v * 3 + 1]);
486
510
  maxY = Math.max(maxY, positions[v * 3 + 1]);
487
511
  }
488
512
  start += count;
489
- if (minX <= maxX)
513
+ for (const v of mine)
514
+ used.add(v);
515
+ if (minX <= maxX && !copy)
490
516
  layers.push({ id, name: m.name, minX, maxX, minY, maxY });
491
517
  }
492
518
  const out = [];
@@ -0,0 +1,147 @@
1
+ import { type Rigidbody } from "./types";
2
+ import type { Skinning } from "../model";
3
+ /**
4
+ * Supplementary colliders fitted to the mesh a PMX rigid body fails to cover.
5
+ *
6
+ * PMX body proxies are bodies of revolution — 下半身 is a capsule lying
7
+ * transversely across the hips, so its cross-section is a circle. A pelvis seen
8
+ * from the side is not a circle, and across every rig measured the butt sits
9
+ * 0.18–0.71 units OUTSIDE that capsule while the front is flush or inside. That
10
+ * gap is where a skirt goes through a character: the cloth is resting correctly
11
+ * on the collider it was given, and the collider stops half a unit short of the
12
+ * skin.
13
+ *
14
+ * A rest offset cannot close it (see RigidBodyStore.restOffset) — it is one
15
+ * scalar on a radially symmetric shape, and the error is asymmetric. Measured
16
+ * on 托特's run cycle, the offset that clears the butt is 0.5, which is simply
17
+ * the size of the missing geometry, and at that value the skirt stands off the
18
+ * front and hips by the same 0.5.
19
+ *
20
+ * So fit the missing piece instead: take each bone-following body's own skinned
21
+ * vertices, find the ones that escape its shape in a concentrated lobe, and fit
22
+ * a capsule to that lobe. That is the fix riggers apply by hand, derived from
23
+ * the mesh rather than guessed.
24
+ *
25
+ * Measured on 托特's run cycle, counting butt vertices swallowed by a cloth
26
+ * body: 32.4 per frame with nothing, 30.9 with a 0.02 rest offset, 12.4 with
27
+ * this pass, 10.4 with both.
28
+ */
29
+ export interface AutoFitOptions {
30
+ /** A vertex counts as protruding past this much (model units). Below it the
31
+ * mesh is within authoring tolerance of the proxy and needs no help. */
32
+ minProtrusion?: number;
33
+ /**
34
+ * Ignore vertices further out than this multiple of the source shape's
35
+ * RADIUS (its smallest characteristic dimension).
36
+ *
37
+ * A coarse first cut at keeping hair and loose clothing out — anything
38
+ * standing further off the proxy than the proxy is wide is not skin. The
39
+ * discriminator that actually does the work is minConcentration.
40
+ */
41
+ maxProtrusionRatio?: number;
42
+ /** Fewer protruding vertices than this and it is a spike, not a region. */
43
+ minVertices?: number;
44
+ /**
45
+ * Per-axis quantile the fitted lobe's extent is clipped to, each end. A
46
+ * handful of stray vertices (a weight-painting slip, a seam) would otherwise
47
+ * stretch the capsule far past the surface everyone can see.
48
+ */
49
+ quantile?: number;
50
+ /** Skip the fit unless the capsule actually reaches this far past what is
51
+ * already covered — otherwise it adds solver rows for nothing. */
52
+ minGain?: number;
53
+ /** How tightly the kept lobe's outward directions must agree, 0–1. A loose
54
+ * sanity check; the real discriminator is minConcentration. */
55
+ minDirectionality?: number;
56
+ /** Vertices outside the dominant lobe, by this cosine, are not part of the
57
+ * feature being fitted. */
58
+ lobeCos?: number;
59
+ /**
60
+ * How much deeper the fitted lobe must be than protrusion typically is on
61
+ * this body, averaged over the vertices that protrude at all.
62
+ *
63
+ * This is the guard that separates "the proxy is missing a lobe" from "the
64
+ * proxy is not a proxy for this mesh at all". A pelvis escapes its capsule by
65
+ * 0.53 at the back and 0.14 at the front, so the back lobe stands well clear
66
+ * of the average. Hair escapes the skull by a similar depth in every
67
+ * direction, so its deepest lobe is no deeper than typical and the ratio sits
68
+ * near 1. See the note at the meanProtrusion computation for what this
69
+ * deliberately refuses to fit.
70
+ *
71
+ * Without it the pass fits the hairstyle — measured on 托特, 頭 reports
72
+ * 3653 of 4669 vertices outside its capsule, and the fitted shape was a crate
73
+ * around the whole head. No threshold on depth or vertex count tells those
74
+ * two cases apart; concentration does.
75
+ */
76
+ minConcentration?: number;
77
+ /**
78
+ * How many capsules may be fitted to one body, each against what the previous
79
+ * ones already cover.
80
+ *
81
+ * One capsule inscribed in a lobe does not fill it — on 托特's butt a single
82
+ * fit removed 58% of the clipping and left the rest at the edges the capsule
83
+ * could not reach. Each further pass re-measures protrusion against the
84
+ * original shape UNION everything fitted so far, so it lands on whatever is
85
+ * still exposed instead of re-fitting the same bulge.
86
+ */
87
+ maxShapesPerBody?: number;
88
+ /**
89
+ * Quantile of the lobe's perpendicular spread used as the capsule radius.
90
+ *
91
+ * The clip-versus-float dial, and the one to reach for if a result looks
92
+ * wrong. Lower hugs the body: less standoff in idle, more clipping left. 1.0
93
+ * encloses the lobe entirely, which is what produced a visibly hovering
94
+ * skirt on 托特.
95
+ */
96
+ radiusQuantile?: number;
97
+ /**
98
+ * Fit only the deepest part of each lobe: points at least this fraction of
99
+ * the lobe's own maximum protrusion.
100
+ *
101
+ * A lobe tapers to nothing at its edges, and a capsule sized to span the
102
+ * whole thing has to be fat enough to reach the edges too. Fitting the deep
103
+ * core keeps each capsule small and lets a later pass handle the shallows
104
+ * with its own, which is both tighter and closer to what the surface is
105
+ * actually doing.
106
+ */
107
+ lobeDepthFraction?: number;
108
+ }
109
+ /** What the pass decided for one source body — surfaced so a rig can be
110
+ * inspected rather than silently rebuilt underneath its author. */
111
+ export interface AutoFitResult {
112
+ /** Index of the body in the input array that this supplements. */
113
+ sourceIndex: number;
114
+ sourceName: string;
115
+ /** Vertices dominated by that body's bone, and how many were outside it. */
116
+ vertexCount: number;
117
+ protrudingCount: number;
118
+ /** Furthest any kept vertex sat outside the source shape. */
119
+ maxProtrusion: number;
120
+ /** How far the fitted capsule reaches past what was already covered. */
121
+ gain: number;
122
+ /** Length of the kept lobe's mean outward direction, 0–1. */
123
+ directionality: number;
124
+ /** Lobe depth over the body's average protrusion. See minConcentration. */
125
+ concentration: number;
126
+ /**
127
+ * Furthest the capsule's newly exposed surface sits from the skin it was
128
+ * fitted to — the amount cloth resting on it will stand off the body at the
129
+ * worst point, and the number to watch if a result looks puffy. Only the part
130
+ * reaching outside the source shape is measured; the rest is buried.
131
+ */
132
+ overshoot: number;
133
+ body: Rigidbody;
134
+ }
135
+ /**
136
+ * Fit supplementary colliders for every bone-following body whose own mesh
137
+ * escapes it.
138
+ *
139
+ * `vertices` is the model's interleaved vertex buffer (stride 8, position
140
+ * first) and `skinning` its joints/weights — both in PMX bind pose, the same
141
+ * space as `shapePosition` / `shapeRotation`, so nothing has to be skinned.
142
+ *
143
+ * Returns one entry per body it chose to supplement; the caller appends
144
+ * `.body` to the rigid body list before constructing RezePhysics.
145
+ */
146
+ export declare function fitSupplementaryColliders(rigidbodies: Rigidbody[], vertices: Float32Array, skinning: Skinning, options?: AutoFitOptions): AutoFitResult[];
147
+ //# sourceMappingURL=autofit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autofit.d.ts","sourceRoot":"","sources":["../../src/physics/autofit.ts"],"names":[],"mappings":"AACA,OAAO,EAAiC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