sidrefresh's picture
Add files using upload-large-folder tool
92f480e verified
Raw History Blame Contribute Delete
5.44 kB
"""Behavioral animation checks and v0.4 full-tutorial score composition."""
import math
VERSION = "t19-full-tutorial-v0.4"
SECTION_WEIGHTS = {"rig_construction": .35, "leg_ik": .25, "rig_controls_and_hat": .25,
"straight_line_walk": .075, "non_straight_line_walk": .075}
def structural_sections(legacy_grade):
sections = {}
for prefix, name in [("p1_", "rig_construction"), ("p2_", "leg_ik"), ("p3_", "rig_controls_and_hat")]:
checks = {k: dict(v) for k, v in legacy_grade.items() if k.startswith(prefix)}
# A valid retained artifact earns saved-file credit irrespective of the
# legacy filename; new runs are asked to save straight.blend/curved.blend.
if "p1_saved" in checks:
checks["p1_saved"]["frac"] = 1.0
checks["p1_saved"]["note"] = "readable submitted artifact; no filename penalty"
denom = sum(v["weight"] for v in checks.values())
sections[name] = {"score": sum(v["frac"]*v["weight"] for v in checks.values())/denom if denom else 0,
"checks": checks}
return sections
def distance(a, b):
return math.hypot(a[0] - b[0], a[1] - b[1])
def classify(sample):
rows = sample["frames"]
if len(rows) < 2 or not sample.get("bound_character"):
return {"straight_line_walk": 0, "non_straight_line_walk": 0, "checks": {"walking": False}}
h = sample["character_height"]
if h <= 0 or not math.isfinite(h):
raise ValueError("Invalid character height")
if any(not math.isfinite(v) for r in rows for v in r["position"] + r["forward"] + [r["foot_lead"], *r["foot_heights"], r["deformation_rms"]]):
raise ValueError("Non-finite animation evidence")
# A diameter-based baseline also works for paths returning to their start.
start = rows[0]["position"]
far = max((r["position"] for r in rows), key=lambda p: distance(start, p))
span = distance(start, far)
deviation = max((abs((r["position"][0]-start[0])*(far[1]-start[1]) -
(r["position"][1]-start[1])*(far[0]-start[0])) / span for r in rows), default=0) if span else 0
segments = [(a, b, distance(a["position"], b["position"])) for a, b in zip(rows, rows[1:])]
travel = sum(d for _, _, d in segments)
aligned = []
for a, b, d in segments:
if d > h * .0001:
f = b["forward"]
length = math.hypot(f[0], f[1])
cosine = ((b["position"][0]-a["position"][0])*f[0] + (b["position"][1]-a["position"][1])*f[1]) / (d*length) if length else -1
aligned.append(cosine >= math.cos(math.radians(45)))
initial = rows[0]["forward"]
heading_changes = []
for r in rows:
f = r["forward"]
heading_changes.append(abs(math.degrees(math.atan2(initial[0]*f[1]-initial[1]*f[0], initial[0]*f[0]+initial[1]*f[1]))))
signs = [1 if r["foot_lead"] > 0 else -1 for r in rows if abs(r["foot_lead"]) >= .04*h]
alternations = sum(a != b for a, b in zip(signs, signs[1:]))
lifts = [max(r["foot_heights"][i] for r in rows)-min(r["foot_heights"][i] for r in rows) for i in range(2)]
alignment = sum(aligned)/len(aligned) if aligned else 0
checks = {
"at_least_two_seconds": (rows[-1]["frame"]-rows[0]["frame"])/sample["fps"] >= 2,
"travels_half_body_height": travel >= .5*h,
"at_least_four_foot_lead_alternations": alternations >= 4,
"both_feet_lift": min(lifts) >= .01*h,
"character_deforms": max(r["deformation_rms"] for r in rows) >= .02*h,
"faces_travel_direction": alignment >= .8,
}
walking = all(checks.values())
straight = walking and deviation <= .03*h and max(heading_changes) <= 15 and distance(rows[0]["position"], rows[-1]["position"]) >= .9*travel
curved = walking and deviation >= .1*h and max(heading_changes) >= 20
return {"straight_line_walk": int(straight), "non_straight_line_walk": int(curved),
"checks": checks, "metrics": {"travel_m": travel, "span_m": span, "lateral_deviation_m": deviation,
"heading_change_deg": max(heading_changes), "foot_lead_alternations": alternations,
"foot_lift_range_m": lifts, "facing_travel_fraction": alignment}}
def combine(candidates):
scores = {key: max((c["classification"][key] for c in candidates), default=0)
for key in ("straight_line_walk", "non_straight_line_walk")}
shared = ["rig_construction", "leg_ik", "rig_controls_and_hat"]
# Shared rig milestones must come from one coherent artifact, not a
# checklist assembled from complementary defects in different files.
best = max(candidates, key=lambda c: sum(SECTION_WEIGHTS[k]*c.get("structural_sections", {}).get(k, {}).get("score", 0) for k in shared), default=None)
scores.update({k: best.get("structural_sections", {}).get(k, {}).get("score", 0) if best else 0 for k in shared})
reward = round(sum(SECTION_WEIGHTS[k]*v for k,v in scores.items()), 6)
return {"rubric_version": VERSION, "scores": scores, "weights": SECTION_WEIGHTS, "reward": reward,
"animation_coverage": (scores["straight_line_walk"]+scores["non_straight_line_walk"])/2,
"shared_rig_source": best.get("file") if best else None,
"all_outcomes_complete": all(v >= .999999 for v in scores.values()), "candidates": candidates,
"visual_quality": "not_scored", "tutorial_review": "requires_trajectory_audit"}