extends RefCounted var failures=[] func check(ok,label): if not ok and not label in failures:failures.append(label);push_error("POSTURE QA: "+label) func lean(actor): var direction=actor.global_basis.inverse()*(actor.gait.point("head")-actor.gait.point("root")) return rad_to_deg(atan2(direction.x,direction.y)) func run(g): await g.get_tree().create_timer(.3).timeout g.start_game();g.set_process(false);g.avatar.set_process(false) for i in range(3):g.workshop.add_helper() var actors=[g.avatar] for h in g.workshop.helpers:h.model.set_process(false);actors.append(h.model) for index in range(actors.size()): var actor=actors[index];actor.get_parent().position=Vector3.ZERO;actor.rotation=Vector3(0,index*.7,0);actor.reset_gait() for scenario in ["continuous_walk","stop_start","idle","whip_walk"]: var maximum=0.0 for frame in range(1800): var moving=scenario=="continuous_walk" or (scenario=="stop_start" and frame%30<15) or (scenario=="whip_walk" and frame%90>30) actor.set_walking(moving) if moving:actor.get_parent().position+=actor.global_basis.z.normalized()*(3.3 if index==0 else 2.5)/60 if scenario=="whip_walk" and frame%90==0:actor.strike(.45) actor._process(1.0/60) maximum=maxf(maximum,absf(lean(actor))) check(maximum<2.0,"torso remains upright: actor %d %s"%[index,scenario]) if scenario=="idle":check(absf(lean(actor))<.1,"idle returns to neutral") print("POSTURE_METRIC ",JSON.stringify({"actor":index,"scenario":scenario,"simulated_seconds":30,"max_lateral_tilt_degrees":maximum})) g.paused=true;var before=actor.gait.point("head");actor._process(.05);check(actor.gait.point("head").is_equal_approx(before),"pause retains pose");g.paused=false if failures.is_empty():print("ALL POSTURE TESTS PASSED: four succubi, 480 simulated seconds, continuous walking, stop/start, idle and repeated whip transitions; lateral tilt under 2 degrees") g.get_tree().quit(0 if failures.is_empty() else 1)