reze-engine 0.31.2 → 0.31.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.
@@ -25,6 +25,9 @@ export declare class RigidBodyStore {
25
25
  readonly bodyOffsetInverse: Float32Array;
26
26
  private boneOffsetsReady;
27
27
  private collisionPairs;
28
+ /** Index of the built-in floor body (see RezePhysics constructor), -1 if none.
29
+ * Excluded from the pair list; findContacts gives it a dedicated plane pass. */
30
+ groundIndex: number;
28
31
  constructor(rigidbodies: Rigidbody[]);
29
32
  updateInvInertiaWorld(): void;
30
33
  updateAabbs(margin?: number): void;
@@ -1 +1 @@
1
- {"version":3,"file":"body.d.ts","sourceRoot":"","sources":["../../src/physics/body.ts"],"names":[],"mappings":"AACA,OAAO,EAAiC,KAAK,SAAS,EAAE,MAAM,SAAS,CAAA;AAIvE,qBAAa,cAAc;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IAEtB,QAAQ,CAAC,SAAS,EAAE,YAAY,CAAA;IAChC,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAA;IACnC,QAAQ,CAAC,gBAAgB,EAAE,YAAY,CAAA;IACvC,QAAQ,CAAC,iBAAiB,EAAE,YAAY,CAAA;IAExC,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAA;IAO9B,QAAQ,CAAC,eAAe,EAAE,YAAY,CAAA;IACtC,QAAQ,CAAC,eAAe,EAAE,YAAY,CAAA;IACtC,QAAQ,CAAC,aAAa,EAAE,YAAY,CAAA;IACpC,QAAQ,CAAC,cAAc,EAAE,YAAY,CAAA;IACrC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;IAGzB,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAA;IAC5B,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAA;IAC9B,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAA;IAC/B,QAAQ,CAAC,WAAW,EAAE,YAAY,CAAA;IAIlC,QAAQ,CAAC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AC,IAAI,EAAE,UAAU,CAAA;IAGzB,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAA;IAC5B,QAAQ,CAAC,SAAS,EAAE,UAAU,CAAA;IAC9B,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAA;IAC/B,QAAQ,CAAC,WAAW,EAAE,YAAY,CAAA;IAIlC,QAAQ,CAAC,cAAc,EAAE,WAAW,CAAA;IACpC,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAA;IAErC,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAA;IAC1B,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAA;IAE3B,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAA;IAC9B,QAAQ,CAAC,OAAO,EAAE,YAAY,CAAA;IAI9B,QAAQ,CAAC,gBAAgB,EAAE,YAAY,CAAA;IACvC,QAAQ,CAAC,iBAAiB,EAAE,YAAY,CAAA;IACxC,OAAO,CAAC,gBAAgB,CAAQ;IAMhC,OAAO,CAAC,cAAc,CAA2B;IAEjD;qFACiF;IACjF,WAAW,SAAK;gBAEJ,WAAW,EAAE,SAAS,EAAE;IAgEpC,qBAAqB,IAAI,IAAI;IAwC7B,WAAW,CAAC,MAAM,SAAM,GAAG,IAAI;IA2F/B,kBAAkB,CAAC,uBAAuB,EAAE,YAAY,GAAG,IAAI;IAqD/D,kBAAkB,IAAI,OAAO;IAM7B,iBAAiB,IAAI,WAAW;CAoBjC"}
@@ -10,6 +10,9 @@ export class RigidBodyStore {
10
10
  // once collapses 60k pair tests/step (349 bodies) down to a few thousand.
11
11
  // Built lazily on first access.
12
12
  this.collisionPairs = null;
13
+ /** Index of the built-in floor body (see RezePhysics constructor), -1 if none.
14
+ * Excluded from the pair list; findContacts gives it a dedicated plane pass. */
15
+ this.groundIndex = -1;
13
16
  const N = rigidbodies.length;
14
17
  this.count = N;
15
18
  this.positions = new Float32Array(N * 3);
@@ -1 +1 @@
1
- {"version":3,"file":"contact.d.ts","sourceRoot":"","sources":["../../src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IAAI;IAGb,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO;CAGxB;AASD,wBAAgB,WAAW,CAAC,KAAK,EAAE,cAAc,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAahF;AAkxBD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,cAAc,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAuCrG;AA4BD,wBAAgB,YAAY,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAsB3E"}
@@ -720,4 +720,88 @@ export function findContacts(store, pool) {
720
720
  continue;
721
721
  generateContacts(store, i, j, pool);
722
722
  }
723
+ // Built-in floor: a plane pass against every dynamic body. Cheaper and more
724
+ // complete than routing the huge ground box through the pair machinery —
725
+ // one y-test per body, and box hems collide too (there is no generic
726
+ // box-box narrowphase to lean on).
727
+ const g = store.groundIndex;
728
+ if (g >= 0) {
729
+ const minA = store.aabbMin;
730
+ for (let i = 0; i < store.count; i++) {
731
+ if (store.invMass[i] <= 0)
732
+ continue;
733
+ if (minA[i * 3 + 1] > CONTACT_MARGIN)
734
+ continue;
735
+ detectFloor(store, i, g, pool);
736
+ }
737
+ }
738
+ }
739
+ // The floor's top face is the model-space plane y = 0; its body (`g`) exists so
740
+ // contact rows have a static B side. Normal convention matches the detectors:
741
+ // A→B, so pointing DOWN into the floor; depth > 0 = penetrating.
742
+ function detectFloor(store, a, g, pool) {
743
+ const ai = a * 3;
744
+ const pos = store.positions;
745
+ const gx = pos[g * 3 + 0];
746
+ const gy = pos[g * 3 + 1];
747
+ const gz = pos[g * 3 + 2];
748
+ const emit = (px, py, pz, depth) => {
749
+ const c = pool.acquire();
750
+ c.bodyA = a;
751
+ c.bodyB = g;
752
+ c.nx = 0;
753
+ c.ny = -1;
754
+ c.nz = 0;
755
+ c.depth = depth;
756
+ c.rAx = px - pos[ai + 0];
757
+ c.rAy = py - pos[ai + 1];
758
+ c.rAz = pz - pos[ai + 2];
759
+ c.rBx = px - gx;
760
+ c.rBy = py - gy;
761
+ c.rBz = pz - gz;
762
+ combineMaterials(store, a, g, c);
763
+ };
764
+ const cx = pos[ai + 0];
765
+ const cy = pos[ai + 1];
766
+ const cz = pos[ai + 2];
767
+ switch (store.shape[a]) {
768
+ case RigidbodyShape.Sphere: {
769
+ const r = store.size[ai + 0];
770
+ const low = cy - r;
771
+ if (low <= CONTACT_MARGIN)
772
+ emit(cx, low, cz, -low);
773
+ break;
774
+ }
775
+ case RigidbodyShape.Capsule: {
776
+ const r = store.size[ai + 0];
777
+ const h = store.size[ai + 1] * 0.5;
778
+ const ax = _capPoint;
779
+ capsuleAxis(store, a, ax);
780
+ for (const sgn of [-1, 1]) {
781
+ const ex = cx + ax[0] * h * sgn;
782
+ const ey = cy + ax[1] * h * sgn;
783
+ const ez = cz + ax[2] * h * sgn;
784
+ const low = ey - r;
785
+ if (low <= CONTACT_MARGIN)
786
+ emit(ex, low, ez, -low);
787
+ }
788
+ break;
789
+ }
790
+ case RigidbodyShape.Box: {
791
+ const hx = store.size[ai + 0];
792
+ const hy = store.size[ai + 1];
793
+ const hz = store.size[ai + 2];
794
+ const out = _capPointB;
795
+ for (let k = 0; k < 8; k++) {
796
+ const lx = k & 1 ? hx : -hx;
797
+ const ly = k & 2 ? hy : -hy;
798
+ const lz = k & 4 ? hz : -hz;
799
+ bodyLocalToWorldDir(store, a, lx, ly, lz, out);
800
+ const wy = cy + out[1];
801
+ if (wy <= CONTACT_MARGIN)
802
+ emit(cx + out[0], wy, cz + out[2], -wy);
803
+ }
804
+ break;
805
+ }
806
+ }
723
807
  }
@@ -1 +1 @@
1
- {"version":3,"file":"physics.d.ts","sourceRoot":"","sources":["../../src/physics/physics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC1C,OAAO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YAAY,CAAc;IAClC,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,YAAY,CAAc;IAClC,OAAO,CAAC,eAAe,CAAc;IAMrC,OAAO,CAAC,OAAO,CAAY;IAE3B,OAAO,CAAC,aAAa,CAAY;IAMjC,OAAO,CAAC,WAAW,CAAY;IAG/B,aAAa,SAAI;gBAEL,WAAW,EAAE,SAAS,EAAE,EAAE,MAAM,GAAE,KAAK,EAAO;IA4D1D,OAAO,CAAC,mBAAmB;IA4B3B,OAAO,CAAC,aAAa;IAKrB,UAAU,CAAC,OAAO,EAAE,IAAI,GAAG,IAAI;IAG/B,UAAU,IAAI,IAAI;IAGlB,cAAc,IAAI,SAAS,EAAE;IAG7B,SAAS,IAAI,KAAK,EAAE;IAGpB,QAAQ,IAAI,cAAc;IAI1B,sBAAsB,IAAI,KAAK,CAAC;QAAE,QAAQ,EAAE,IAAI,CAAC;QAAC,QAAQ,EAAE,IAAI,CAAA;KAAE,CAAC;IAiBnE,KAAK,CAAC,iBAAiB,EAAE,IAAI,EAAE,GAAG,IAAI;IActC,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,EAAE,uBAAuB,EAAE,YAAY,GAAG,IAAI;IA2ExF,OAAO,CAAC,iBAAiB;IAuCzB,OAAO,CAAC,uBAAuB;IAqF/B,OAAO,CAAC,yBAAyB;IAgEjC,OAAO,CAAC,sBAAsB;IAmC9B,OAAO,CAAC,2BAA2B;IA6EnC,OAAO,CAAC,wBAAwB;IA2BhC,OAAO,CAAC,sBAAsB;IAqC9B,OAAO,CAAC,oBAAoB;CA6D7B"}
@@ -1,5 +1,5 @@
1
1
  import { Vec3, Quat, Mat4 } from "../math";
2
- import { RigidbodyType } from "./types";
2
+ import { RigidbodyType, RigidbodyShape } from "./types";
3
3
  import { RigidBodyStore } from "./body";
4
4
  import { World } from "./world";
5
5
  import { buildConstraints } from "./constraint";
@@ -25,7 +25,37 @@ export class RezePhysics {
25
25
  this.teleportCount = 0;
26
26
  this.rigidbodies = rigidbodies;
27
27
  this.joints = joints;
28
- this.store = new RigidBodyStore(rigidbodies);
28
+ // The floor is part of every world: a huge static box whose top face is
29
+ // model-space y = 0, so hair and hems rest on the ground instead of
30
+ // clipping through when a pose reaches it. Boneless (every bone-sync loop
31
+ // skips boneIndex < 0); collides with EVERY dynamic body regardless of
32
+ // group masks via findContacts' dedicated plane pass (spheres, capsules
33
+ // and boxes — box hems included).
34
+ const ground = {
35
+ name: "__ground__",
36
+ englishName: "__ground__",
37
+ boneIndex: -1,
38
+ group: 0,
39
+ collisionMask: 0xffff,
40
+ shape: RigidbodyShape.Box,
41
+ size: new Vec3(500, 1, 500),
42
+ shapePosition: new Vec3(0, -1, 0),
43
+ shapeRotation: new Vec3(0, 0, 0),
44
+ mass: 0,
45
+ linearDamping: 0,
46
+ angularDamping: 0,
47
+ restitution: 0,
48
+ friction: 0.6,
49
+ type: RigidbodyType.Static,
50
+ bodyOffsetMatrixInverse: Mat4.identity(),
51
+ };
52
+ this.store = new RigidBodyStore([...rigidbodies, ground]);
53
+ const gi = this.store.count - 1;
54
+ // Mask 0 keeps the floor OUT of the generic pair list — findContacts runs a
55
+ // dedicated plane pass against every dynamic body (all shapes, boxes too).
56
+ this.store.collisionGroup[gi] = 0;
57
+ this.store.willCollideMask[gi] = 0;
58
+ this.store.groundIndex = gi;
29
59
  this.world = new World(new Vec3(0, -98, 0));
30
60
  this.constraints = buildConstraints(rigidbodies, joints);
31
61
  this.contacts = new ContactPool();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reze-engine",
3
- "version": "0.31.2",
3
+ "version": "0.31.3",
4
4
  "description": "A lightweight WebGPU engine for real-time 3D MMD/PMX model rendering",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -53,6 +53,10 @@ export class RigidBodyStore {
53
53
  // Built lazily on first access.
54
54
  private collisionPairs: Uint16Array | null = null
55
55
 
56
+ /** Index of the built-in floor body (see RezePhysics constructor), -1 if none.
57
+ * Excluded from the pair list; findContacts gives it a dedicated plane pass. */
58
+ groundIndex = -1
59
+
56
60
  constructor(rigidbodies: Rigidbody[]) {
57
61
  const N = rigidbodies.length
58
62
  this.count = N
@@ -993,4 +993,84 @@ export function findContacts(store: RigidBodyStore, pool: ContactPool): void {
993
993
  if (!aabbOverlap(store, i, j)) continue
994
994
  generateContacts(store, i, j, pool)
995
995
  }
996
+ // Built-in floor: a plane pass against every dynamic body. Cheaper and more
997
+ // complete than routing the huge ground box through the pair machinery —
998
+ // one y-test per body, and box hems collide too (there is no generic
999
+ // box-box narrowphase to lean on).
1000
+ const g = store.groundIndex
1001
+ if (g >= 0) {
1002
+ const minA = store.aabbMin
1003
+ for (let i = 0; i < store.count; i++) {
1004
+ if (store.invMass[i] <= 0) continue
1005
+ if (minA[i * 3 + 1] > CONTACT_MARGIN) continue
1006
+ detectFloor(store, i, g, pool)
1007
+ }
1008
+ }
1009
+ }
1010
+
1011
+ // The floor's top face is the model-space plane y = 0; its body (`g`) exists so
1012
+ // contact rows have a static B side. Normal convention matches the detectors:
1013
+ // A→B, so pointing DOWN into the floor; depth > 0 = penetrating.
1014
+ function detectFloor(store: RigidBodyStore, a: number, g: number, pool: ContactPool): void {
1015
+ const ai = a * 3
1016
+ const pos = store.positions
1017
+ const gx = pos[g * 3 + 0]
1018
+ const gy = pos[g * 3 + 1]
1019
+ const gz = pos[g * 3 + 2]
1020
+ const emit = (px: number, py: number, pz: number, depth: number) => {
1021
+ const c = pool.acquire()
1022
+ c.bodyA = a
1023
+ c.bodyB = g
1024
+ c.nx = 0
1025
+ c.ny = -1
1026
+ c.nz = 0
1027
+ c.depth = depth
1028
+ c.rAx = px - pos[ai + 0]
1029
+ c.rAy = py - pos[ai + 1]
1030
+ c.rAz = pz - pos[ai + 2]
1031
+ c.rBx = px - gx
1032
+ c.rBy = py - gy
1033
+ c.rBz = pz - gz
1034
+ combineMaterials(store, a, g, c)
1035
+ }
1036
+ const cx = pos[ai + 0]
1037
+ const cy = pos[ai + 1]
1038
+ const cz = pos[ai + 2]
1039
+ switch (store.shape[a]) {
1040
+ case RigidbodyShape.Sphere: {
1041
+ const r = store.size[ai + 0]
1042
+ const low = cy - r
1043
+ if (low <= CONTACT_MARGIN) emit(cx, low, cz, -low)
1044
+ break
1045
+ }
1046
+ case RigidbodyShape.Capsule: {
1047
+ const r = store.size[ai + 0]
1048
+ const h = store.size[ai + 1] * 0.5
1049
+ const ax = _capPoint
1050
+ capsuleAxis(store, a, ax)
1051
+ for (const sgn of [-1, 1]) {
1052
+ const ex = cx + ax[0] * h * sgn
1053
+ const ey = cy + ax[1] * h * sgn
1054
+ const ez = cz + ax[2] * h * sgn
1055
+ const low = ey - r
1056
+ if (low <= CONTACT_MARGIN) emit(ex, low, ez, -low)
1057
+ }
1058
+ break
1059
+ }
1060
+ case RigidbodyShape.Box: {
1061
+ const hx = store.size[ai + 0]
1062
+ const hy = store.size[ai + 1]
1063
+ const hz = store.size[ai + 2]
1064
+ const out = _capPointB
1065
+ for (let k = 0; k < 8; k++) {
1066
+ const lx = k & 1 ? hx : -hx
1067
+ const ly = k & 2 ? hy : -hy
1068
+ const lz = k & 4 ? hz : -hz
1069
+ bodyLocalToWorldDir(store, a, lx, ly, lz, out)
1070
+ const wy = cy + out[1]
1071
+ if (wy <= CONTACT_MARGIN) emit(cx + out[0], wy, cz + out[2], -wy)
1072
+ }
1073
+ break
1074
+ }
1075
+ }
996
1076
  }
@@ -1,6 +1,6 @@
1
1
  import { Vec3, Quat, Mat4 } from "../math"
2
2
  import type { Rigidbody, Joint } from "./types"
3
- import { RigidbodyType } from "./types"
3
+ import { RigidbodyType, RigidbodyShape } from "./types"
4
4
  import { RigidBodyStore } from "./body"
5
5
  import { World } from "./world"
6
6
  import { buildConstraints, type SixDofSpringConstraint } from "./constraint"
@@ -67,7 +67,37 @@ export class RezePhysics {
67
67
  constructor(rigidbodies: Rigidbody[], joints: Joint[] = []) {
68
68
  this.rigidbodies = rigidbodies
69
69
  this.joints = joints
70
- this.store = new RigidBodyStore(rigidbodies)
70
+ // The floor is part of every world: a huge static box whose top face is
71
+ // model-space y = 0, so hair and hems rest on the ground instead of
72
+ // clipping through when a pose reaches it. Boneless (every bone-sync loop
73
+ // skips boneIndex < 0); collides with EVERY dynamic body regardless of
74
+ // group masks via findContacts' dedicated plane pass (spheres, capsules
75
+ // and boxes — box hems included).
76
+ const ground: Rigidbody = {
77
+ name: "__ground__",
78
+ englishName: "__ground__",
79
+ boneIndex: -1,
80
+ group: 0,
81
+ collisionMask: 0xffff,
82
+ shape: RigidbodyShape.Box,
83
+ size: new Vec3(500, 1, 500),
84
+ shapePosition: new Vec3(0, -1, 0),
85
+ shapeRotation: new Vec3(0, 0, 0),
86
+ mass: 0,
87
+ linearDamping: 0,
88
+ angularDamping: 0,
89
+ restitution: 0,
90
+ friction: 0.6,
91
+ type: RigidbodyType.Static,
92
+ bodyOffsetMatrixInverse: Mat4.identity(),
93
+ }
94
+ this.store = new RigidBodyStore([...rigidbodies, ground])
95
+ const gi = this.store.count - 1
96
+ // Mask 0 keeps the floor OUT of the generic pair list — findContacts runs a
97
+ // dedicated plane pass against every dynamic body (all shapes, boxes too).
98
+ this.store.collisionGroup[gi] = 0
99
+ this.store.willCollideMask[gi] = 0
100
+ this.store.groundIndex = gi
71
101
  this.world = new World(new Vec3(0, -98, 0))
72
102
  this.constraints = buildConstraints(rigidbodies, joints)
73
103
  this.contacts = new ContactPool()