reze-engine 0.43.0 → 0.50.1

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 (140) hide show
  1. package/README.md +53 -429
  2. package/dist/animation.d.ts +26 -0
  3. package/dist/animation.d.ts.map +1 -1
  4. package/dist/animation.js +42 -0
  5. package/dist/camera.d.ts +3 -0
  6. package/dist/camera.d.ts.map +1 -1
  7. package/dist/camera.js +33 -8
  8. package/dist/engine.d.ts +841 -53
  9. package/dist/engine.d.ts.map +1 -1
  10. package/dist/engine.js +3498 -451
  11. package/dist/graph/registry.d.ts +2 -2
  12. package/dist/graph/registry.d.ts.map +1 -1
  13. package/dist/graph/registry.js +1 -1
  14. package/dist/graph/slots.d.ts +0 -1
  15. package/dist/graph/slots.d.ts.map +1 -1
  16. package/dist/graph/slots.js +37 -9
  17. package/dist/hdr.d.ts +18 -0
  18. package/dist/hdr.d.ts.map +1 -0
  19. package/dist/hdr.js +162 -0
  20. package/dist/ibl.d.ts +19 -0
  21. package/dist/ibl.d.ts.map +1 -0
  22. package/dist/ibl.js +113 -0
  23. package/dist/ik-solver.d.ts +2 -1
  24. package/dist/ik-solver.d.ts.map +1 -1
  25. package/dist/index.d.ts +5 -1
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +10 -0
  28. package/dist/math.d.ts +20 -1
  29. package/dist/math.d.ts.map +1 -1
  30. package/dist/math.js +23 -16
  31. package/dist/midi-loader.d.ts +10 -0
  32. package/dist/midi-loader.d.ts.map +1 -0
  33. package/dist/midi-loader.js +247 -0
  34. package/dist/model.d.ts +19 -14
  35. package/dist/model.d.ts.map +1 -1
  36. package/dist/model.js +31 -2
  37. package/dist/param-track.d.ts +48 -0
  38. package/dist/param-track.d.ts.map +1 -0
  39. package/dist/param-track.js +80 -0
  40. package/dist/physics/types.d.ts.map +1 -1
  41. package/dist/physics/types.js +3 -0
  42. package/dist/reflection.d.ts +27 -0
  43. package/dist/reflection.d.ts.map +1 -0
  44. package/dist/reflection.js +93 -0
  45. package/dist/shaders/anchor-table.d.ts +56 -0
  46. package/dist/shaders/anchor-table.d.ts.map +1 -0
  47. package/dist/shaders/anchor-table.js +128 -0
  48. package/dist/shaders/cast-api.d.ts +2 -0
  49. package/dist/shaders/cast-api.d.ts.map +1 -0
  50. package/dist/shaders/cast-api.js +121 -0
  51. package/dist/shaders/cast-layout.d.ts +21 -0
  52. package/dist/shaders/cast-layout.d.ts.map +1 -0
  53. package/dist/shaders/cast-layout.js +20 -0
  54. package/dist/shaders/lights.d.ts +79 -0
  55. package/dist/shaders/lights.d.ts.map +1 -0
  56. package/dist/shaders/lights.js +269 -0
  57. package/dist/shaders/lyrics-api.d.ts +39 -0
  58. package/dist/shaders/lyrics-api.d.ts.map +1 -0
  59. package/dist/shaders/lyrics-api.js +187 -0
  60. package/dist/shaders/materials/common.d.ts +2 -4
  61. package/dist/shaders/materials/common.d.ts.map +1 -1
  62. package/dist/shaders/materials/common.js +87 -35
  63. package/dist/shaders/midi-api.d.ts +10 -0
  64. package/dist/shaders/midi-api.d.ts.map +1 -0
  65. package/dist/shaders/midi-api.js +114 -0
  66. package/dist/shaders/passes/composite.d.ts +28 -22
  67. package/dist/shaders/passes/composite.d.ts.map +1 -1
  68. package/dist/shaders/passes/composite.js +165 -138
  69. package/dist/shaders/passes/cull.d.ts +2 -0
  70. package/dist/shaders/passes/cull.d.ts.map +1 -0
  71. package/dist/shaders/passes/cull.js +138 -0
  72. package/dist/shaders/passes/field-blit.d.ts +26 -0
  73. package/dist/shaders/passes/field-blit.d.ts.map +1 -0
  74. package/dist/shaders/passes/field-blit.js +65 -0
  75. package/dist/shaders/passes/grid.d.ts +31 -0
  76. package/dist/shaders/passes/grid.d.ts.map +1 -0
  77. package/dist/shaders/passes/grid.js +169 -0
  78. package/dist/shaders/passes/ground.d.ts +13 -1
  79. package/dist/shaders/passes/ground.d.ts.map +1 -1
  80. package/dist/shaders/passes/ground.js +170 -25
  81. package/dist/shaders/passes/hosted-api.d.ts +57 -0
  82. package/dist/shaders/passes/hosted-api.d.ts.map +1 -0
  83. package/dist/shaders/passes/hosted-api.js +166 -0
  84. package/dist/shaders/passes/id-debug.d.ts +28 -0
  85. package/dist/shaders/passes/id-debug.d.ts.map +1 -0
  86. package/dist/shaders/passes/id-debug.js +74 -0
  87. package/dist/shaders/passes/particles.d.ts +10 -2
  88. package/dist/shaders/passes/particles.d.ts.map +1 -1
  89. package/dist/shaders/passes/particles.js +37 -109
  90. package/dist/shaders/passes/scene-contract.d.ts +128 -0
  91. package/dist/shaders/passes/scene-contract.d.ts.map +1 -0
  92. package/dist/shaders/passes/scene-contract.js +207 -0
  93. package/dist/shaders/passes/sim.d.ts +34 -0
  94. package/dist/shaders/passes/sim.d.ts.map +1 -0
  95. package/dist/shaders/passes/sim.js +169 -0
  96. package/dist/shaders/passes/trails.d.ts +14 -2
  97. package/dist/shaders/passes/trails.d.ts.map +1 -1
  98. package/dist/shaders/passes/trails.js +55 -90
  99. package/dist/shaders/score-api.d.ts +10 -0
  100. package/dist/shaders/score-api.d.ts.map +1 -0
  101. package/dist/shaders/score-api.js +114 -0
  102. package/dist/shadow-cascades.d.ts +45 -0
  103. package/dist/shadow-cascades.d.ts.map +1 -0
  104. package/dist/shadow-cascades.js +70 -0
  105. package/dist/vmd-loader.d.ts +3 -2
  106. package/dist/vmd-loader.d.ts.map +1 -1
  107. package/package.json +1 -1
  108. package/src/animation.ts +41 -0
  109. package/src/camera.ts +31 -8
  110. package/src/engine.ts +4015 -556
  111. package/src/graph/registry.ts +2 -2
  112. package/src/graph/slots.ts +37 -9
  113. package/src/hdr.ts +156 -0
  114. package/src/ibl.ts +115 -0
  115. package/src/ik-solver.ts +1 -1
  116. package/src/index.ts +12 -0
  117. package/src/math.ts +23 -17
  118. package/src/midi-loader.ts +246 -0
  119. package/src/model.ts +34 -4
  120. package/src/param-track.ts +83 -0
  121. package/src/physics/types.ts +4 -1
  122. package/src/reflection.ts +94 -0
  123. package/src/shaders/anchor-table.ts +147 -0
  124. package/src/shaders/cast-api.ts +123 -0
  125. package/src/shaders/cast-layout.ts +20 -0
  126. package/src/shaders/lights.ts +280 -0
  127. package/src/shaders/lyrics-api.ts +202 -0
  128. package/src/shaders/materials/common.ts +89 -35
  129. package/src/shaders/midi-api.ts +116 -0
  130. package/src/shaders/passes/composite.ts +182 -139
  131. package/src/shaders/passes/cull.ts +139 -0
  132. package/src/shaders/passes/grid.ts +178 -0
  133. package/src/shaders/passes/ground.ts +172 -25
  134. package/src/shaders/passes/hosted-api.ts +171 -0
  135. package/src/shaders/passes/id-debug.ts +75 -0
  136. package/src/shaders/passes/particles.ts +54 -112
  137. package/src/shaders/passes/scene-contract.ts +266 -0
  138. package/src/shaders/passes/trails.ts +77 -93
  139. package/src/shadow-cascades.ts +97 -0
  140. package/src/vmd-loader.ts +2 -2
package/dist/animation.js CHANGED
@@ -1,5 +1,23 @@
1
1
  export const FPS = 30;
2
2
  // Priority-aware playback: higher priority preempts, otherwise latest request is queued.
3
+ /**
4
+ * Morphs the OLD tracks drove that the new ones do not name.
5
+ *
6
+ * Nothing in the pose pass resets a morph weight — it writes only the morphs
7
+ * its clip names — so a morph left behind by a replaced track keeps its last
8
+ * value for the rest of the session. These are the ones a caller has to zero,
9
+ * or the old face stays frozen underneath the new one, which reads exactly
10
+ * like the new file having had no effect at all.
11
+ */
12
+ export function retiredMorphs(prev, next) {
13
+ if (!prev)
14
+ return [];
15
+ const out = [];
16
+ for (const name of prev.morphTracks.keys())
17
+ if (!next.has(name))
18
+ out.push(name);
19
+ return out;
20
+ }
3
21
  export class AnimationState {
4
22
  constructor() {
5
23
  this.animations = new Map();
@@ -23,6 +41,30 @@ export class AnimationState {
23
41
  frameCount: clip.frameCount,
24
42
  });
25
43
  }
44
+ /**
45
+ * Replace a clip's morph tracks wholesale, leaving its bones alone.
46
+ *
47
+ * MMD authors ship expressions as their own file (表情モーション) beside the
48
+ * body motion, and when they do it is AUTHORITATIVE: whatever morphs the body
49
+ * motion carried are the ones the morph pass was made to replace. So
50
+ * this overwrites rather than merges per-morph — a half-overridden face is
51
+ * nobody's intent. With no expression file loaded, the motion's own morphs
52
+ * play untouched, because nothing calls this.
53
+ *
54
+ * The clip is created if it does not exist yet, so the two files may arrive
55
+ * in either order, and frameCount grows to cover the longer of the two — an
56
+ * morph track running past the body motion is common and must not be
57
+ * truncated to it.
58
+ */
59
+ setMorphTracks(name, morphTracks, frameCount) {
60
+ const clip = this.animations.get(name);
61
+ this.animations.set(name, {
62
+ boneTracks: clip?.boneTracks ?? new Map(),
63
+ morphTracks,
64
+ ikTracks: clip?.ikTracks,
65
+ frameCount: Math.max(clip?.frameCount ?? 0, frameCount),
66
+ });
67
+ }
26
68
  removeAnimation(name) {
27
69
  this.animations.delete(name);
28
70
  if (this.currentAnimationName === name) {
package/dist/camera.d.ts CHANGED
@@ -13,6 +13,9 @@ export declare class Camera {
13
13
  * closer than any real framing — and buys 10× precision at character range. */
14
14
  near: number;
15
15
  far: number;
16
+ /** Set once by the engine, from whether it got a float depth format. Decides
17
+ * both the near-plane floor and which way round the projection maps z. */
18
+ reversedZ: boolean;
16
19
  private canvas;
17
20
  private inputLocked;
18
21
  private isDragging;
@@ -1 +1 @@
1
- {"version":3,"file":"camera.d.ts","sourceRoot":"","sources":["../src/camera.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAQ,IAAI,EAAE,MAAM,QAAQ,CAAA;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAA;AAWpD,qBAAa,MAAM;IACjB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,IAAI,CAAA;IACZ,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAI;IAClB;;;oFAGgF;IAChF,IAAI,EAAE,MAAM,CAAM;IAClB,GAAG,EAAE,MAAM,CAAU;IAGrB,OAAO,CAA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,MAAM,EAAE,OAAO;IAS9B,OAAO,CAAC,WAAW;IAOnB,OAAO,CAAC,WAAW;IAsBnB,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,OAAO;IAYf,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,YAAY;IA8BpB,OAAO,CAAC,WAAW;IAuFnB,OAAO,CAAC,UAAU;CA+BnB"}
package/dist/camera.js CHANGED
@@ -2,11 +2,25 @@ import { Mat4, Quat, Vec3 } from "./math";
2
2
  /** Far cap / zoom limit; large enough for wide shots without clipping distant ground */
3
3
  const FAR_CAP = 8000;
4
4
  const FAR_MIN = 200;
5
- /** The character-framing value the cloth z-fighting fix settled on — never go below it. */
6
- const NEAR_MIN = 0.5;
7
- /** ~40cm in MMD units. Past this the near plane would start clipping geometry a
8
- * user has deliberately pushed the camera up against. */
9
- const NEAR_MAX = 5;
5
+ /**
6
+ * Near-plane floor and cap, in two sets, because what a near plane costs depends
7
+ * entirely on the depth buffer underneath it.
8
+ *
9
+ * The single set that used to live here was written against a projection that
10
+ * silently doubled it (see Mat4.perspectiveInto), so the real clip was at 1.0 and
11
+ * 10 rather than the 0.5 and 5 stated. UNORM keeps exactly that behaviour, now
12
+ * said out loud: identical precision, identical z-fighting margin on coplanar
13
+ * cloth, no change to any scene that renders correctly today.
14
+ *
15
+ * REVERSED gets the floor the content actually wants. Float depth read backwards
16
+ * holds roughly constant RELATIVE precision across the range, so pulling the near
17
+ * plane in by twenty times costs almost nothing — and a 4 mm near plane is closer
18
+ * than any camera VMD will ever push.
19
+ */
20
+ const NEAR_MIN_UNORM = 1.0;
21
+ const NEAR_MAX_UNORM = 10;
22
+ const NEAR_MIN_REVERSED = 0.05;
23
+ const NEAR_MAX_REVERSED = 5;
10
24
  export class Camera {
11
25
  constructor(alpha, beta, radius, target, fov = Math.PI / 4) {
12
26
  this.aspect = 1;
@@ -14,8 +28,11 @@ export class Camera {
14
28
  * nearly all of it within a hand's reach and coplanar cloth/body layers z-fought
15
29
  * (white crack flashes, worse the further the camera). 0.5 MMD units ≈ 4 cm —
16
30
  * closer than any real framing — and buys 10× precision at character range. */
17
- this.near = 0.5;
31
+ this.near = NEAR_MIN_UNORM;
18
32
  this.far = FAR_CAP;
33
+ /** Set once by the engine, from whether it got a float depth format. Decides
34
+ * both the near-plane floor and which way round the projection maps z. */
35
+ this.reversedZ = false;
19
36
  // Input state
20
37
  this.canvas = null;
21
38
  this.inputLocked = false;
@@ -228,12 +245,20 @@ export class Camera {
228
245
  * user is deliberately close to.
229
246
  */
230
247
  updateNearFromRadius() {
231
- this.near = Math.min(NEAR_MAX, Math.max(NEAR_MIN, this.radius / 50));
248
+ const lo = this.reversedZ ? NEAR_MIN_REVERSED : NEAR_MIN_UNORM;
249
+ const hi = this.reversedZ ? NEAR_MAX_REVERSED : NEAR_MAX_UNORM;
250
+ this.near = Math.min(hi, Math.max(lo, this.radius / 50));
232
251
  }
233
252
  getProjectionMatrix() {
234
253
  this.updateFarFromRadius();
235
254
  this.updateNearFromRadius();
236
- Mat4.perspectiveInto(this._projMat.values, this.fov, this.aspect, this.near, this.far);
255
+ // Reversed-Z is the same matrix with near and far handed over the other way
256
+ // round — near → 1, far → 0. One projection function, and the reversal is a
257
+ // property of the depth buffer rather than a second matrix to keep in step.
258
+ if (this.reversedZ)
259
+ Mat4.perspectiveInto(this._projMat.values, this.fov, this.aspect, this.far, this.near);
260
+ else
261
+ Mat4.perspectiveInto(this._projMat.values, this.fov, this.aspect, this.near, this.far);
237
262
  return this._projMat;
238
263
  }
239
264
  attachControl(canvas) {