reze-engine 0.68.28 → 0.68.31

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/src/index.ts CHANGED
@@ -131,6 +131,7 @@ export type {
131
131
  BlendEntry,
132
132
  BoneKeyframe,
133
133
  IkKeyframe,
134
+ VisibilityKeyframe,
134
135
  MorphKeyframe,
135
136
  BoneInterpolation,
136
137
  ControlPoint,
package/src/jelly-eyes.ts CHANGED
@@ -31,6 +31,9 @@ export interface JellyEyeOptions {
31
31
  /** The idle taps: a ripple every 4–8 s while nothing else moves them.
32
32
  * Default true; false leaves only what her blinks and motion set off. */
33
33
  idle?: boolean
34
+ /** Whether her head's motion knocks them: a turn, a bob, a step. Default
35
+ * true; false leaves only her blinks and the idle taps. */
36
+ motion?: boolean
34
37
  }
35
38
 
36
39
  // The closing morphs, by the names MMD, VRoid and the usual converters give
@@ -254,6 +257,7 @@ const newState = (): EyeState => ({
254
257
  export class JellyEyes {
255
258
  strength: number
256
259
  idle: boolean
260
+ motion: boolean
257
261
  // Scene time stepped so far, and the idle taps: how many, and when the next.
258
262
  private clock = 0
259
263
  private taps = 0
@@ -282,6 +286,7 @@ export class JellyEyes {
282
286
  constructor(model: Model, options: JellyEyeOptions) {
283
287
  this.strength = clampStrength(options.strength)
284
288
  this.idle = options.idle ?? true
289
+ this.motion = options.motion ?? true
285
290
  const bones = model.getSkeleton().bones
286
291
  const index = (name: string) => bones.findIndex((b) => b.name === name)
287
292
  const both = index("両目")
@@ -354,7 +359,8 @@ export class JellyEyes {
354
359
  // Only her motion — the head turning and moving (the inertia) — and her
355
360
  // blinks do.
356
361
  look(head, null, s.look)
357
- const knock = seek ? 0 : Math.max(this.tapKnock, Math.tanh(Math.hypot(...this.offset(s, e)) / PULSE_REF))
362
+ const moved = this.motion ? Math.tanh(Math.hypot(...this.offset(s, e)) / PULSE_REF) : 0
363
+ const knock = seek ? 0 : Math.max(this.tapKnock, moved)
358
364
  const squashTarget = MOTION_SQUASH * knock
359
365
  if (seek) {
360
366
  // Landing on a pose is no blink: the spring rests where it lands.
package/src/model.ts CHANGED
@@ -337,12 +337,25 @@ export class Model {
337
337
  return this._scale
338
338
  }
339
339
 
340
- /** Whether this model renders. Hidden models skip the main, shadow, and pick passes;
341
- * physics keeps running so they resume consistently. */
340
+ /** Whether the HOST shows this model — what setVisible last said. A playing
341
+ * motion can hide her on top of this (see `drawn`), and never writes here,
342
+ * so the host's own switch reads back exactly as it set it. */
342
343
  get visible(): boolean {
343
344
  return this._visible
344
345
  }
345
346
 
347
+ /** Whether this model renders this frame: the host shows her and the motion
348
+ * has not hidden her. Hidden models skip the main, shadow and pick passes;
349
+ * physics keeps running so they resume consistently. */
350
+ get drawn(): boolean {
351
+ return this._visible && !this.motionHidden
352
+ }
353
+
354
+ /** Whether the playing motion has her hidden right now (VMD's 表示 flag). */
355
+ get hiddenByMotion(): boolean {
356
+ return this.motionHidden
357
+ }
358
+
346
359
  setPosition(position: Vec3): void {
347
360
  this._position.set(position)
348
361
  this.rootMatrixDirty = true
@@ -459,6 +472,8 @@ export class Model {
459
472
  private _rotation: Quat = Quat.identity()
460
473
  private _scale: number = 1
461
474
  private _visible: boolean = true
475
+ /** The playing clip's display flag at the current frame — see `drawn`. */
476
+ private motionHidden = false
462
477
  private rootMatrixValues: Float32Array = new Float32Array([1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1])
463
478
  private rootMatrixDirty: boolean = false
464
479
  private rootIsIdentity: boolean = true
@@ -2041,6 +2056,11 @@ export class Model {
2041
2056
  }
2042
2057
  for (const track of ikTracks.values()) track.sort((a, b) => a.frame - b.frame)
2043
2058
  clip.ikTracks = ikTracks
2059
+ // The same records carry the model's 表示 flag. Kept only when some
2060
+ // record hides her: a motion that never does plays exactly as before.
2061
+ if (ikFrames.some((r) => !r.visible)) {
2062
+ clip.visibility = ikFrames.map((r) => ({ frame: r.frame, visible: r.visible }))
2063
+ }
2044
2064
  }
2045
2065
  this.animationState.loadAnimation(name, clip)
2046
2066
  })
@@ -2317,6 +2337,8 @@ export class Model {
2317
2337
  this.crossfade = null
2318
2338
  this.oneShot = null
2319
2339
  this.animationState.clear()
2340
+ // No clip, no motion to hide her: a cleared clip must not leave her gone.
2341
+ this.motionHidden = false
2320
2342
  }
2321
2343
 
2322
2344
  // Seek by absolute timeline seconds, not frame index.
@@ -2376,6 +2398,7 @@ export class Model {
2376
2398
  /** Step the IK state to `frame`. VMD IK keys are steps: a state holds until
2377
2399
  * the next one changes it, so this is a lookup, not an interpolation. */
2378
2400
  private applyIkFromClip(clip: AnimationClip, frame: number): void {
2401
+ this.applyVisibilityFromClip(clip, frame)
2379
2402
  if (!clip.ikTracks || clip.ikTracks.size === 0) {
2380
2403
  if (this.ikDisabled.size > 0) this.ikDisabled.clear()
2381
2404
  return
@@ -2390,6 +2413,15 @@ export class Model {
2390
2413
  }
2391
2414
  }
2392
2415
 
2416
+ /** Step the motion's display flag to `frame`. Before its first key she is
2417
+ * shown — MMD's own reading of a motion that starts hidden later. */
2418
+ private applyVisibilityFromClip(clip: AnimationClip, frame: number): void {
2419
+ const keys = clip.visibility
2420
+ let shown = true
2421
+ if (keys) for (let i = 0; i < keys.length && keys[i].frame <= frame; i++) shown = keys[i].visible
2422
+ this.motionHidden = !shown
2423
+ }
2424
+
2393
2425
  /** Sample one bone track at `frame` into outRot + outVmdTrans. The translation is
2394
2426
  * VMD-space (bind-relative), NOT yet converted to bone-local — callers convert with
2395
2427
  * convertVMDTranslationToLocal once they know the final rotation. The cursor cache
@@ -2871,6 +2903,7 @@ export class Model {
2871
2903
  this.applyCrossfade(deltaTime)
2872
2904
  } else {
2873
2905
  const clip = this.animationState.getCurrentClip()
2906
+ if (clip === null) this.motionHidden = false
2874
2907
  if (clip !== null) {
2875
2908
  this.applyPoseFromClip(clip, this.animationState.getCurrentFrame())
2876
2909
  if (evWatch !== null && evWatch === this.animationState.getCurrentAnimation()) {
@@ -191,18 +191,6 @@ struct VertexOutput {
191
191
  // At rest skinMats are identity so restPos == worldPos, which is why existing noise-
192
192
  // scale constants stay valid without retuning.
193
193
  @location(3) restPos: vec3f,
194
- /**
195
- * This TRIANGLE's dissolve threshold.
196
- *
197
- * FLAT, so every fragment of a face shares the provoking vertex's value and
198
- * the face goes as a unit — the mesh comes apart in triangles that light and
199
- * leave in turn, rather than in a scatter that crosses them. Computed in the
200
- * vertex stage from the bind-pose attribute, which is what lets the depth
201
- * prepass, the shadow map and the outline hull reach the same number for the
202
- * same face: one function, one input, one provoking vertex, one answer. They
203
- * must agree — a pass that disagrees punches holes through her.
204
- */
205
- @location(4) @interpolate(flat) faceT: f32,
206
194
  /** The scene fog's two amounts, computed PER VERTEX as the game does — see
207
195
  * Engine.setSceneFog — and interpolated across the face. */
208
196
  @location(5) fog: vec2f,
@@ -484,7 +472,6 @@ const COMMON_VS_WGSL = /* wgsl */ `
484
472
  output.uv = uv;
485
473
  output.worldPos = skinnedPos.xyz;
486
474
  output.restPos = position;
487
- output.faceT = rz_dissolve_threshold(position);
488
475
  let viewZ = (camera.view * vec4f(skinnedPos.xyz, 1.0)).z;
489
476
  output.fog = vec2f(
490
477
  _rzFogAmount(viewZ, skinnedPos.y, light.fog[0], light.fog[1]),
@@ -69,9 +69,6 @@ struct VSOut {
69
69
  // The bind-pose position, carried for one reason: the dissolve test below has
70
70
  // to be the SAME test the colour pass runs, and that one is in object space.
71
71
  @location(1) restPos: vec3f,
72
- /** The triangle's own threshold, flat — see the material VertexOutput. This
73
- * pass must throw away exactly the faces the colour pass does. */
74
- @location(2) @interpolate(flat) faceT: f32,
75
72
  };
76
73
 
77
74
  @vertex fn vs(
@@ -94,7 +91,6 @@ struct VSOut {
94
91
  o.position = camera.projection * camera.view * vec4f(skinned.xyz, 1.0);
95
92
  o.uv = uv;
96
93
  o.restPos = position;
97
- o.faceT = rz_dissolve_threshold(position);
98
94
  return o;
99
95
  }
100
96
 
@@ -121,7 +117,7 @@ override CUTOFF: f32 = 0.5;
121
117
  // the colour pass throws away would punch holes that occlude the floor behind
122
118
  // her: you would see sky through her, which is the failure this line exists
123
119
  // to prevent.
124
- if (material.dissolve < 0.9995 && in.faceT > material.dissolve) { discard; }
120
+ if (material.dissolve < 0.9995 && rz_dissolve_threshold(in.restPos) > material.dissolve) { discard; }
125
121
  var out: PrepassOut;
126
122
  out.color = vec4f(0.0);
127
123
  out.mask = vec4f(0.0);
@@ -104,9 +104,6 @@ struct VertexOutput {
104
104
  * the depth prepass measure against, so all three agree about which flakes
105
105
  * are gone. */
106
106
  @location(1) restPos: vec3f,
107
- /** The triangle's own threshold, flat — see the material VertexOutput. The
108
- * hull traces the body's faces, so it has to lose the same ones. */
109
- @location(2) @interpolate(flat) faceT: f32,
110
107
  /** How much of a pixel-wide line this one really is (1 = all of it): a line
111
108
  * held at the minimum width fades by what it was short. */
112
109
  @location(3) coverage: f32,
@@ -246,7 +243,6 @@ fn safe_normal2(v: vec2f) -> vec2f {
246
243
  output.position = vec4f(clipPos.xy + ndc * w, clipPos.z, clipPos.w);
247
244
  output.uv = uv;
248
245
  output.restPos = position;
249
- output.faceT = rz_dissolve_threshold(position);
250
246
  return output;
251
247
  }
252
248
 
@@ -272,7 +268,7 @@ ${sceneFsOutWgsl({ name: "FSOut", aux: "mask" })}
272
268
  // The same test the colour pass and the depth prepass run, against the same
273
269
  // bind-pose position — three passes, one rule, or they disagree about which
274
270
  // pieces are still there.
275
- if (material.dissolve < 0.9995 && input.faceT > material.dissolve) { discard; }
271
+ if (material.dissolve < 0.9995 && rz_dissolve_threshold(input.restPos) > material.dissolve) { discard; }
276
272
  let tex = textureSample(diffuseTexture, edgeSampler, input.uv);
277
273
  let texA = tex.a;
278
274
  if (texA < 0.05) {
@@ -36,11 +36,9 @@ ${JELLY_VERTEX_WGSL}
36
36
  struct VSOut {
37
37
  @builtin(position) position: vec4f,
38
38
  @location(0) uv: vec2f,
39
- /** Bind-pose position, for the dissolve test — object space, as everywhere. */
39
+ /** Bind-pose position, for the dissolve test — object space, as everywhere.
40
+ * A flake that is gone must stop casting. */
40
41
  @location(1) restPos: vec3f,
41
- /** The triangle's own threshold, flat — see the material VertexOutput. A
42
- * face that is gone must stop casting, and stop as a whole face. */
43
- @location(2) @interpolate(flat) faceT: f32,
44
42
  };
45
43
 
46
44
  @vertex fn vs(@location(0) position: vec3f, @location(1) normal: vec3f, @location(2) uv: vec2f,
@@ -56,7 +54,6 @@ struct VSOut {
56
54
  out.position = lp.viewProj * vec4f(sp.xyz, 1.0);
57
55
  out.uv = uv;
58
56
  out.restPos = position;
59
- out.faceT = rz_dissolve_threshold(position);
60
57
  return out;
61
58
  }
62
59
 
@@ -66,6 +63,6 @@ struct VSOut {
66
63
  // The dissolve, run as the colour pass runs it. A flake that is gone stops
67
64
  // casting: without this she leaves a whole shadow standing on the floor while
68
65
  // her body is in the air.
69
- if (material.dissolve < 0.9995 && in.faceT > material.dissolve) { discard; }
66
+ if (material.dissolve < 0.9995 && rz_dissolve_threshold(in.restPos) > material.dissolve) { discard; }
70
67
  }
71
68
  `
package/src/vmd-writer.ts CHANGED
@@ -94,6 +94,17 @@ export class VMDWriter {
94
94
  else ikByFrame.set(key.frame, [{ boneName, enabled: key.enabled }])
95
95
  }
96
96
  }
97
+ // The model's display flag rides in the same records. A moment it changes
98
+ // with no IK switch beside it still needs a record of its own, and every
99
+ // record states the flag as it stands then — one written as "shown" would
100
+ // bring her back mid-hide on the way in.
101
+ const visibility = wantBones ? clip.visibility : undefined
102
+ if (visibility) for (const key of visibility) if (!ikByFrame.has(key.frame)) ikByFrame.set(key.frame, [])
103
+ const shownAt = (frame: number): boolean => {
104
+ let shown = true
105
+ if (visibility) for (let i = 0; i < visibility.length && visibility[i].frame <= frame; i++) shown = visibility[i].visible
106
+ return shown
107
+ }
97
108
  const ikFrames = [...ikByFrame.entries()].sort((a, b) => a[0] - b[0])
98
109
  let ikSize = 0
99
110
  for (const [, states] of ikFrames) ikSize += 4 + 1 + 4 + states.length * (IK_NAME_SIZE + 1)
@@ -188,7 +199,7 @@ export class VMDWriter {
188
199
  for (const [frame, states] of ikFrames) {
189
200
  view.setUint32(offset, frame, true)
190
201
  offset += 4
191
- view.setUint8(offset, 1) // model visible
202
+ view.setUint8(offset, shownAt(frame) ? 1 : 0) // model visible
192
203
  offset += 1
193
204
  view.setUint32(offset, states.length, true)
194
205
  offset += 4