reze-engine 0.16.1 → 0.16.3

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 (88) hide show
  1. package/README.md +139 -284
  2. package/dist/engine.d.ts.map +1 -1
  3. package/dist/engine.js +5 -5
  4. package/dist/model.d.ts +4 -1
  5. package/dist/model.d.ts.map +1 -1
  6. package/dist/model.js +14 -1
  7. package/dist/physics/body.d.ts +1 -0
  8. package/dist/physics/body.d.ts.map +1 -1
  9. package/dist/physics/body.js +2 -0
  10. package/dist/physics/constraint.d.ts +8 -1
  11. package/dist/physics/constraint.d.ts.map +1 -1
  12. package/dist/physics/constraint.js +13 -1
  13. package/dist/physics/physics.d.ts +15 -1
  14. package/dist/physics/physics.d.ts.map +1 -1
  15. package/dist/physics/physics.js +413 -48
  16. package/dist/physics/solver.d.ts.map +1 -1
  17. package/dist/physics/solver.js +223 -39
  18. package/dist/physics/types.d.ts +2 -1
  19. package/dist/physics/types.d.ts.map +1 -1
  20. package/dist/physics/types.js +5 -0
  21. package/dist/physics/world.d.ts +3 -0
  22. package/dist/physics/world.d.ts.map +1 -1
  23. package/dist/physics/world.js +31 -4
  24. package/dist/physics-debug.d.ts +30 -0
  25. package/dist/physics-debug.d.ts.map +1 -0
  26. package/dist/physics-debug.js +526 -0
  27. package/dist/pmx-loader.d.ts +2 -0
  28. package/dist/pmx-loader.d.ts.map +1 -1
  29. package/dist/pmx-loader.js +37 -20
  30. package/dist/shaders/materials/body.d.ts +1 -1
  31. package/dist/shaders/materials/body.d.ts.map +1 -1
  32. package/dist/shaders/materials/body.js +90 -85
  33. package/dist/shaders/materials/cloth_rough.d.ts +1 -1
  34. package/dist/shaders/materials/cloth_rough.d.ts.map +1 -1
  35. package/dist/shaders/materials/cloth_rough.js +1 -1
  36. package/dist/shaders/materials/cloth_smooth.d.ts +1 -1
  37. package/dist/shaders/materials/cloth_smooth.d.ts.map +1 -1
  38. package/dist/shaders/materials/cloth_smooth.js +2 -2
  39. package/dist/shaders/materials/common.d.ts +1 -1
  40. package/dist/shaders/materials/common.d.ts.map +1 -1
  41. package/dist/shaders/materials/common.js +10 -0
  42. package/dist/shaders/materials/default.d.ts +1 -1
  43. package/dist/shaders/materials/default.d.ts.map +1 -1
  44. package/dist/shaders/materials/default.js +37 -32
  45. package/dist/shaders/materials/eye.d.ts +1 -1
  46. package/dist/shaders/materials/eye.d.ts.map +1 -1
  47. package/dist/shaders/materials/eye.js +40 -35
  48. package/dist/shaders/materials/face.d.ts +1 -1
  49. package/dist/shaders/materials/face.d.ts.map +1 -1
  50. package/dist/shaders/materials/face.js +90 -85
  51. package/dist/shaders/materials/hair.d.ts +1 -1
  52. package/dist/shaders/materials/hair.d.ts.map +1 -1
  53. package/dist/shaders/materials/hair.js +85 -75
  54. package/dist/shaders/materials/metal.d.ts +1 -1
  55. package/dist/shaders/materials/metal.d.ts.map +1 -1
  56. package/dist/shaders/materials/metal.js +1 -1
  57. package/dist/shaders/materials/stockings.d.ts +1 -1
  58. package/dist/shaders/materials/stockings.d.ts.map +1 -1
  59. package/dist/shaders/materials/stockings.js +1 -1
  60. package/dist/shaders/passes/physics-debug.d.ts +2 -0
  61. package/dist/shaders/passes/physics-debug.d.ts.map +1 -0
  62. package/dist/shaders/passes/physics-debug.js +69 -0
  63. package/package.json +1 -1
  64. package/src/engine.ts +36 -21
  65. package/src/model.ts +18 -1
  66. package/src/physics/body.ts +5 -0
  67. package/src/physics/constraint.ts +35 -6
  68. package/src/physics/physics.ts +423 -56
  69. package/src/physics/solver.ts +213 -38
  70. package/src/physics/types.ts +10 -2
  71. package/src/physics/world.ts +33 -4
  72. package/src/pmx-loader.ts +38 -20
  73. package/src/shaders/materials/body.ts +97 -92
  74. package/src/shaders/materials/cloth_rough.ts +1 -1
  75. package/src/shaders/materials/cloth_smooth.ts +2 -2
  76. package/src/shaders/materials/common.ts +10 -0
  77. package/src/shaders/materials/default.ts +45 -40
  78. package/src/shaders/materials/eye.ts +48 -43
  79. package/src/shaders/materials/face.ts +97 -92
  80. package/src/shaders/materials/hair.ts +92 -82
  81. package/src/shaders/materials/metal.ts +1 -1
  82. package/src/shaders/materials/stockings.ts +1 -1
  83. package/dist/gpu-profile.d.ts +0 -19
  84. package/dist/gpu-profile.d.ts.map +0 -1
  85. package/dist/gpu-profile.js +0 -120
  86. package/dist/physics/profile.d.ts +0 -18
  87. package/dist/physics/profile.d.ts.map +0 -1
  88. package/dist/physics/profile.js +0 -44
package/src/model.ts CHANGED
@@ -235,6 +235,9 @@ export class Model {
235
235
  private rigidbodies: Rigidbody[] = []
236
236
  private joints: Joint[] = []
237
237
 
238
+ // Non-fatal problems collected while parsing the PMX (see PmxLoader.warn).
239
+ private loadWarnings: string[] = []
240
+
238
241
  // Runtime skeleton pose state (updated each frame)
239
242
  private runtimeSkeleton!: SkeletonRuntime
240
243
 
@@ -293,7 +296,8 @@ export class Model {
293
296
  skinning: Skinning,
294
297
  morphing: Morphing,
295
298
  rigidbodies: Rigidbody[] = [],
296
- joints: Joint[] = []
299
+ joints: Joint[] = [],
300
+ loadWarnings: string[] = []
297
301
  ) {
298
302
  // Store base vertex data (original positions before morphing)
299
303
  this.baseVertexData = new Float32Array(vertexData)
@@ -307,6 +311,7 @@ export class Model {
307
311
  this.morphing = morphing
308
312
  this.rigidbodies = rigidbodies
309
313
  this.joints = joints
314
+ this.loadWarnings = loadWarnings
310
315
 
311
316
  if (this.skeleton.bones.length == 0) {
312
317
  throw new Error("Model has no bones")
@@ -631,6 +636,18 @@ export class Model {
631
636
  return this.skinning
632
637
  }
633
638
 
639
+ // True when the PMX carried a usable rigidbody section. False means the
640
+ // model renders but has no physics — surface this in the UI instead of
641
+ // letting it read as "physics silently broken".
642
+ hasPhysicsData(): boolean {
643
+ return this.rigidbodies.length > 0
644
+ }
645
+
646
+ // Non-fatal PMX parse problems (truncated sections, suspicious counts…).
647
+ getLoadWarnings(): readonly string[] {
648
+ return this.loadWarnings
649
+ }
650
+
634
651
  getRigidbodies(): Rigidbody[] {
635
652
  return this.rigidbodies
636
653
  }
@@ -19,6 +19,9 @@ export class RigidBodyStore {
19
19
  readonly linearDamping: Float32Array
20
20
  readonly angularDamping: Float32Array
21
21
  readonly type: Uint8Array
22
+ // PMX mode-2 bodies: dynamic, but the bone takes rotation only and the
23
+ // body position re-pins to the animated bone each frame.
24
+ readonly aligned: Uint8Array
22
25
  readonly boneIndex: Int32Array
23
26
  readonly friction: Float32Array
24
27
  readonly restitution: Float32Array
@@ -59,6 +62,7 @@ export class RigidBodyStore {
59
62
  this.linearDamping = new Float32Array(N)
60
63
  this.angularDamping = new Float32Array(N)
61
64
  this.type = new Uint8Array(N)
65
+ this.aligned = new Uint8Array(N)
62
66
  this.boneIndex = new Int32Array(N)
63
67
  this.bodyOffsetMatrix = new Float32Array(N * 16)
64
68
  this.bodyOffsetInverse = new Float32Array(N * 16)
@@ -92,6 +96,7 @@ export class RigidBodyStore {
92
96
  this.linearDamping[i] = rb.linearDamping
93
97
  this.angularDamping[i] = rb.angularDamping
94
98
  this.type[i] = rb.type
99
+ this.aligned[i] = rb.aligned ? 1 : 0
95
100
  this.boneIndex[i] = rb.boneIndex
96
101
  this.friction[i] = rb.friction
97
102
  this.restitution[i] = rb.restitution
@@ -37,15 +37,37 @@ export interface SixDofSpringConstraint {
37
37
  cacheLinCrossA: Float32Array // 9: (rA × ax) per axis
38
38
  cacheLinCrossB: Float32Array // 9
39
39
  cacheLinJacInv: Float32Array // 3: 1/(im+im+cA²·ii+cB²·ii) per axis
40
- cacheLinTargetVel: Float32Array // 3: limit ERP + spring drive, signed
40
+ // Limit rows are unilateral (Bullet-style): the per-substep accumulated
41
+ // impulse is clamped to the corrective sign, so a limit can push a body
42
+ // back into range but never pull it deeper / brake its natural recovery —
43
+ // bilateral limit rows act as motors and pump energy into swinging cloth.
44
+ cacheLinTargetVel: Float32Array // 3: limit ERP target, signed
41
45
  cacheLinActive: Uint8Array // 3
42
- cacheAngAxes: Float32Array // 9
43
- cacheAngTargetVel: Float32Array // 3
44
- cacheAngActive: Uint8Array // 3
45
- cacheAngJacInv: number // 1 — same for all 3 angular axes
46
+ cacheLinLimitImp: Float32Array // 3: accumulated limit impulse (per substep)
47
+ // Spring rows are velocity-target drives; setup clamps k to the deadbeat
48
+ // stability bound so they cannot pump energy.
49
+ cacheLinSpringTarget: Float32Array // 3
50
+ cacheLinSpringActive: Uint8Array // 3
51
+ cacheAngAxes: Float32Array // 9 (spring rows)
52
+ cacheAngTargetVel: Float32Array // 3 (spring rows)
53
+ cacheAngActive: Uint8Array // 3 (spring rows)
54
+ cacheAngJacInv: number // 1 — same for all angular rows
55
+ // Single geodesic limit row: shortest rotation from the current relative
56
+ // orientation to the euler-clamped target. Per-axis euler limit rows are
57
+ // geometrically inconsistent for large violations (asin singularity) and
58
+ // pump energy instead of converging. Unilateral like the linear limits.
59
+ cacheAngLimAxis: Float32Array // 3, world-space unit axis
60
+ cacheAngLimTarget: number // target relative angular velocity along axis
61
+ cacheAngLimActive: number
62
+ cacheAngLimImp: number // accumulated impulse (per substep)
46
63
  }
47
64
 
48
- export const STOP_ERP = 0.475
65
+ // Stop-limit ERP. PMX rigs are tuned against MMD's stiff limit response;
66
+ // lowering this makes cloth resting against its limits sink visibly deeper
67
+ // (equilibrium penetration scales with 1/ERP). Rest chatter at this
68
+ // stiffness was fixed at the source (spring double-drive, unilateral
69
+ // stops) — don't lower ERP to paper over jitter.
70
+ export const STOP_ERP = 0.45
49
71
 
50
72
  // Build per-joint constraints from PMX data:
51
73
  // frameA = (bodyA_worldBind)^-1 · jointWorldBind
@@ -128,10 +150,17 @@ export function buildConstraints(
128
150
  cacheLinJacInv: new Float32Array(3),
129
151
  cacheLinTargetVel: new Float32Array(3),
130
152
  cacheLinActive: new Uint8Array(3),
153
+ cacheLinLimitImp: new Float32Array(3),
154
+ cacheLinSpringTarget: new Float32Array(3),
155
+ cacheLinSpringActive: new Uint8Array(3),
131
156
  cacheAngAxes: new Float32Array(9),
132
157
  cacheAngTargetVel: new Float32Array(3),
133
158
  cacheAngActive: new Uint8Array(3),
134
159
  cacheAngJacInv: 0,
160
+ cacheAngLimAxis: new Float32Array(3),
161
+ cacheAngLimTarget: 0,
162
+ cacheAngLimActive: 0,
163
+ cacheAngLimImp: 0,
135
164
  })
136
165
  }
137
166