Files
breeze/tests/sun_salutation_pose_behavior.zi
waozi 924553d6c2 Make the practice figures move naturally and show the VRoid figure
The owner picked pixiv's CC0 VRoid woman and man (practices
shared/figure). An audit of every practice at 30 frames a second (the
preview's new --audit) found 589 awkward moments; 9 small ones remain.

- Feet step and pivot instead of sliding: a stepping foot rises clear of
  the floor before it travels and lands after it arrives; a foot turning
  on the spot pivots on its heel or ball (the ball when it stands on its
  toes) with the other end raised first. One rule for Tai Chi's timeline,
  the Workout and Sun Salutation (TaiChiStepFoot); lunges no longer drag a
  foot 46 cm.
- Toes hanging from a lifted tiptoe foot bend up rather than go through
  the floor.
- Knees and elbows straighten smoothly over the last 1.2% of their reach
  instead of snapping straight.
- Each Tai Chi hand turns as one piece between keys, so its fingers and
  palm never blend through nothing and flip the hand (Snake Creeps Down).
- The side plank rolls over face down to the second side instead of
  jumping there.
- The course studio's solver and timeline match, and its parity reference
  is regenerated (export-app.mjs --reference).
- Workout and Sun Salutation tests check that planted feet stay within
  5 mm, nothing goes below the floor, nothing moves too fast and no knee
  bends backwards.
- The figure preview shows the woman or the man with hair on VRM spring
  bones and blinking eyes, and gains --audit, --shot, --video and --trace;
  it pins Kryon ac6c8f47 and practices d8b54df1.
2026-11-18 15:57:10 -03:00

189 lines
7.9 KiB
Ziran

// Sun Salutation owns its choreography and joint-direction regressions.
#import, file "../src/practices/sun_salutation/sun_salutation_pose.zi";
#import, file "../src/practices/sun_salutation/sun_salutation_rules.zi";
#import, file "../apps/practice/workout_moves.zi";
#import, file "../apps/practice/workout_rules.zi";
#import, file "../src/practices/tai_chi/tai_chi_math.zi";
#import, file "../src/practices/tai_chi/tai_chi_solve.zi";
#import, file "figure_test_support.zi";
// The joints whose motion must stay smooth.
SnapJoints :: (solved: *TaiChiSolved) -> [7]TaiChiVector3 {
joints: [7]TaiChiVector3
for side: cast(s32)0..1 {
joints[side] = solved.elbows[side]
joints[2 + side] = solved.wrists[side]
joints[4 + side] = solved.knees[side]
}
joints[6] = solved.head_center
return joints
}
CheckMoves :: (start_seconds: s32, end_seconds: s32) -> s32 {
rig := WorkoutRig()
// Every transition and held pose, with alternating leading legs.
for round: cast(s32)0..1 {
for step: cast(s32)0..11 {
state := SalutationInit(SunSalutationPracticeState.{})
state.start_seconds = start_seconds
state.end_seconds = end_seconds
state.step = step
state.repetition = round
previous: TaiChiSolved
steps: [7]TaiChiVector3
for ticks: cast(s32)0..SalutationStepSeconds(state) * 60 - 1 {
state.step_ticks = ticks
pose := SunSalutationPoseAt(state, *rig)
if !FigureSound(*pose, *rig, WORKOUT_PLANK) {
return 400 + step
}
solved := WorkoutSolve(*pose, *rig)
for side: cast(s32)0..1 {
if step == 3 || step == 8 {
ankle := TaiChiSub3(solved.ankles[side], solved.hips[side])
knee := TaiChiSub3(solved.knees[side], solved.hips[side])
// A knee bends forwards in the leg's plane. It must
// neither fold backwards nor swivel out to the side
// while the hip turns from the fold into the lunge.
if ankle.y * knee.z - ankle.z * knee.y > 0.00001 ||
TaiChiAbs(knee.x) > 0.04 {
return 420 + step
}
// The front foot stays planted while the other
// steps back.
planted := SunSalutationPose(step - 1, round == 1).feet[side].z ==
SunSalutationPose(step, round == 1).feet[side].z
if step == 3 && planted {
ground := TaiChiMin(solved.heels[side].y,
TaiChiMin(solved.balls[side].y, solved.toes[side].y))
if TaiChiAbs(ground) > 0.005 {
return 432
}
}
}
if step == 5 || step == 6 {
// Keep the elbows beside the ribs and never ahead
// of the hands while lowering the chest and lifting
// cobra; once clearly bent they point well back.
reach := TaiChiDistance3(solved.shoulders[side], solved.wrists[side])
bent := reach < 0.9 * (rig.upper_arm + rig.fore_arm)
behind := ifx bent then 0.04 else -0.005
if TaiChiAbs(solved.elbows[side].x - solved.shoulders[side].x) > 0.05 ||
solved.elbows[side].z > solved.wrists[side].z - behind {
return 440 + step
}
}
if ticks > 0 && (step == 3 || step == 8 || step == 5 || step == 6) {
if TaiChiDistance3(previous.knees[side], solved.knees[side]) > 0.02 ||
TaiChiDistance3(previous.elbows[side], solved.elbows[side]) > 0.02 {
return 460 + step
}
}
}
// No joint snaps: from one tick to the next its step may
// grow or shrink only gradually, through every move and hold,
// never by a large share of the step itself.
joints := SnapJoints(*solved)
if ticks > 0 {
before := SnapJoints(*previous)
for index: cast(s32)0..6 {
moved := TaiChiSub3(joints[index], before[index])
change := TaiChiDistance3(moved, steps[index])
largest := TaiChiMax(TaiChiLength3(moved), TaiChiLength3(steps[index]))
if ticks > 1 && change > 0.003 && change > 0.25 * largest {
return 470 + step
}
steps[index] = moved
}
}
previous = solved
}
// Each step ends exactly where the next begins.
if step < 11 {
next := state
next.step = step + 1
next.step_ticks = 0
next_pose := SunSalutationPoseAt(next, *rig)
after := WorkoutSolve(*next_pose, *rig)
end := SnapJoints(*previous)
start := SnapJoints(*after)
for index: cast(s32)0..6 {
if TaiChiDistance3(end[index], start[index]) > 0.004 {
return 490 + step
}
}
}
}
}
first_lunge := SunSalutationPose(3, false)
other_lunge := SunSalutationPose(3, true)
if first_lunge.feet[0].z == other_lunge.feet[0].z {
return 412
}
first_solved := WorkoutSolve(*first_lunge, *rig)
other_solved := WorkoutSolve(*other_lunge, *rig)
if first_solved.knees[0].y < 0.25 || first_solved.knees[1].y > 0.12 ||
other_solved.knees[1].y < 0.25 || other_solved.knees[0].y > 0.12 {
return 413
}
lowered := SunSalutationPose(5, false)
lowered_solved := WorkoutSolve(*lowered, *rig)
for side: cast(s32)0..1 {
if lowered_solved.knees[side].y < 0.035 || lowered_solved.knees[side].y > 0.075 {
return 414
}
}
return 42
}
#program_export
Answer :: () -> s32 {
starts: [3]s32 = .[8, 3, 12]
ends: [3]s32 = .[6, 3, 12]
for index: cast(s32)0..2 {
result := CheckMoves(starts[index], ends[index])
if result != 42 {
return result
}
}
return SunSalutationMotionNatural()
}
// Two rounds, played thirty times a second, move as a person would: feet
// step and pivot instead of sliding, stay above the floor, and nothing
// snaps. 42, or 600 plus the bound broken (sliding, floor, speed, knee).
SunSalutationMotionNatural :: () -> s32 {
rig := WorkoutRig()
check: MotionCheck
check.lowest = 1000.0
MotionStart(*check)
for round: cast(s32)0..1 {
for step: cast(s32)0..SUN_SALUTATION_STEP_COUNT - 1 {
state: SunSalutationPracticeState
state.repetitions = 2
state.repetition = round
state.step = step
state.start_seconds = SUN_SALUTATION_DEFAULT_START_SECONDS
state.end_seconds = SUN_SALUTATION_DEFAULT_END_SECONDS
ticks := SalutationStepSeconds(state) * 60
state.step_ticks = 0
while state.step_ticks < ticks {
pose := SunSalutationPoseAt(state, *rig)
solved := WorkoutSolve(*pose, *rig)
MotionStep(*check, *solved)
state.step_ticks += 2
}
}
}
if MotionWithin(*check, 0.005, 6.0) {
return 42
}
if check.worst_slide > 0.005 {
return 601
}
if check.lowest < -0.005 {
return 602
}
return ifx check.fastest > 6.0 then 603 else 604
}