|
1 | 1 | import { describe, it, expect } from "vitest"; |
| 2 | +import fs from "node:fs"; |
2 | 3 | import * as THREE from "three"; |
3 | 4 | import { buildMannequin } from "../src/mannequin.js"; |
4 | 5 | import { buildTimeline } from "../src/timeline.js"; |
@@ -473,6 +474,49 @@ describe("ground-lock (shared solver)", () => { |
473 | 474 | return m; |
474 | 475 | } |
475 | 476 |
|
| 477 | + it("keeps the canonical demi-plié turned out without foot friction", () => { |
| 478 | + const source = fs.readFileSync( |
| 479 | + new URL("../../../spec/examples/demi-plie.posecode", import.meta.url), |
| 480 | + "utf8", |
| 481 | + ); |
| 482 | + const { ir, errors } = parse(source); |
| 483 | + expect(errors).toEqual([]); |
| 484 | + const timeline = buildTimeline(ir!); |
| 485 | + const m = buildMannequin(); |
| 486 | + |
| 487 | + expect(timeline.basePose.joints?.hip_left?.[1]).toBe(30); |
| 488 | + expect(timeline.basePose.joints?.hip_right?.[1]).toBe(-30); |
| 489 | + |
| 490 | + timeline.sample(0, m.bones); |
| 491 | + groundFigure(m); |
| 492 | + const basePosition = m.root.position.clone(); |
| 493 | + const baseRotation = m.root.quaternion.clone(); |
| 494 | + const anchors = new Map( |
| 495 | + ["ankle_left", "ankle_right"].map((id) => [ |
| 496 | + id, |
| 497 | + m.bones.get(id)!.getWorldPosition(new THREE.Vector3()), |
| 498 | + ]), |
| 499 | + ); |
| 500 | + |
| 501 | + let maxDrift = 0; |
| 502 | + for (let t = 0; t < timeline.duration; t += 0.025) { |
| 503 | + m.root.position.copy(basePosition); |
| 504 | + m.root.quaternion.copy(baseRotation); |
| 505 | + const info = timeline.sample(t, m.bones); |
| 506 | + m.root.updateMatrixWorld(true); |
| 507 | + applyGroundLock(m, info.groundLock, anchors); |
| 508 | + levelPlantedFeet(m, info.groundLock); |
| 509 | + m.root.updateMatrixWorld(true); |
| 510 | + for (const id of ["ankle_left", "ankle_right"]) { |
| 511 | + const point = m.bones.get(id)!.getWorldPosition(new THREE.Vector3()); |
| 512 | + const anchor = anchors.get(id)!; |
| 513 | + maxDrift = Math.max(maxDrift, Math.hypot(point.x - anchor.x, point.z - anchor.z)); |
| 514 | + } |
| 515 | + } |
| 516 | + |
| 517 | + expect(maxDrift).toBeLessThan(0.01); |
| 518 | + }); |
| 519 | + |
476 | 520 | it("drops the body and plants the foot mesh for a feet-only squat", () => { |
477 | 521 | const m = posedRaw( |
478 | 522 | [ |
|
0 commit comments