@driftengine/physics 4.6.1 → 4.7.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.
- package/dist/ragdoll.js +33 -0
- package/package.json +1 -1
- package/src/ragdoll.ts +32 -0
package/dist/ragdoll.js
CHANGED
|
@@ -149,6 +149,39 @@ export function ragdollFromBones(world, parents, worldMatrices, options = {}) {
|
|
|
149
149
|
anchorBY: -(halfOf[j] ?? 0),
|
|
150
150
|
});
|
|
151
151
|
}
|
|
152
|
+
/*
|
|
153
|
+
* **Bones hanging from a joint with no bone of its own are jointed to one another, at the head
|
|
154
|
+
* they share.** The header names the case: a humanoid's hips are usually a root, and the spine
|
|
155
|
+
* and both thighs hang off them. The loop above joints a bone to its parent's bone, and a root
|
|
156
|
+
* has none, so until 2026-10-02 those three bones were never joined to anything: a doll built
|
|
157
|
+
* from that rig fell as a torso and two loose legs. Each sibling is now jointed to the first
|
|
158
|
+
* bone under the same joint, head to head, with its own joint's limits; at rest the two heads
|
|
159
|
+
* are one point, so the first tick still moves nothing.
|
|
160
|
+
*/
|
|
161
|
+
const firstUnder = new Int32Array(jointCount).fill(-1);
|
|
162
|
+
for (let j = 0; j < jointCount; j++) {
|
|
163
|
+
const body = bodyOf[j] ?? -1;
|
|
164
|
+
if (body < 0)
|
|
165
|
+
continue;
|
|
166
|
+
const p = parents[j] ?? -1;
|
|
167
|
+
if (p < 0 || (bodyOf[p] ?? -1) >= 0)
|
|
168
|
+
continue;
|
|
169
|
+
const first = firstUnder[p] ?? -1;
|
|
170
|
+
if (first < 0) {
|
|
171
|
+
firstUnder[p] = j;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
world.addJoint({
|
|
175
|
+
type: JOINT_CONE_TWIST,
|
|
176
|
+
bodyA: bodyOf[first] ?? 0,
|
|
177
|
+
bodyB: body,
|
|
178
|
+
swingCos: limitAt(swingCos, Math.SQRT1_2, j),
|
|
179
|
+
twistSin: limitAt(twistSin, 0.3826834323650898, j),
|
|
180
|
+
axisY: 1,
|
|
181
|
+
anchorAY: -(halfOf[first] ?? 0),
|
|
182
|
+
anchorBY: -(halfOf[j] ?? 0),
|
|
183
|
+
});
|
|
184
|
+
}
|
|
152
185
|
/*
|
|
153
186
|
* **Bones that share an end must not collide, and it cannot be said with layers.**
|
|
154
187
|
*
|
package/package.json
CHANGED
package/src/ragdoll.ts
CHANGED
|
@@ -291,6 +291,38 @@ export function ragdollFromBones(
|
|
|
291
291
|
});
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
+
/*
|
|
295
|
+
* **Bones hanging from a joint with no bone of its own are jointed to one another, at the head
|
|
296
|
+
* they share.** The header names the case: a humanoid's hips are usually a root, and the spine
|
|
297
|
+
* and both thighs hang off them. The loop above joints a bone to its parent's bone, and a root
|
|
298
|
+
* has none, so until 2026-10-02 those three bones were never joined to anything: a doll built
|
|
299
|
+
* from that rig fell as a torso and two loose legs. Each sibling is now jointed to the first
|
|
300
|
+
* bone under the same joint, head to head, with its own joint's limits; at rest the two heads
|
|
301
|
+
* are one point, so the first tick still moves nothing.
|
|
302
|
+
*/
|
|
303
|
+
const firstUnder = new Int32Array(jointCount).fill(-1);
|
|
304
|
+
for (let j = 0; j < jointCount; j++) {
|
|
305
|
+
const body = bodyOf[j] ?? -1;
|
|
306
|
+
if (body < 0) continue;
|
|
307
|
+
const p = parents[j] ?? -1;
|
|
308
|
+
if (p < 0 || (bodyOf[p] ?? -1) >= 0) continue;
|
|
309
|
+
const first = firstUnder[p] ?? -1;
|
|
310
|
+
if (first < 0) {
|
|
311
|
+
firstUnder[p] = j;
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
world.addJoint({
|
|
315
|
+
type: JOINT_CONE_TWIST,
|
|
316
|
+
bodyA: bodyOf[first] ?? 0,
|
|
317
|
+
bodyB: body,
|
|
318
|
+
swingCos: limitAt(swingCos, Math.SQRT1_2, j),
|
|
319
|
+
twistSin: limitAt(twistSin, 0.3826834323650898, j),
|
|
320
|
+
axisY: 1,
|
|
321
|
+
anchorAY: -(halfOf[first] ?? 0),
|
|
322
|
+
anchorBY: -(halfOf[j] ?? 0),
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
|
|
294
326
|
/*
|
|
295
327
|
* **Bones that share an end must not collide, and it cannot be said with layers.**
|
|
296
328
|
*
|