Download tasks/t19-blender-rig-full/tests/sample_endpoint.py from refreshdotdev/Refresh-GUI-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.55 kB
-
https://huggingface.co/datasets/refreshdotdev/Refresh-GUI-dataset/resolve/main/tasks/t19-blender-rig-full/tests/sample_endpoint.py
- Command line
-
hf download hf://datasets/refreshdotdev/Refresh-GUI-dataset/tasks/t19-blender-rig-full/tests/sample_endpoint.py
-
curl -L -o sample_endpoint.py https://huggingface.co/datasets/refreshdotdev/Refresh-GUI-dataset/resolve/main/tasks/t19-blender-rig-full/tests/sample_endpoint.py
2.55 kB
| """Blender-only extraction; mappings are independently inferred by the verifier.""" | |
| import json | |
| import sys | |
| from pathlib import Path | |
| import bpy | |
| from mathutils import Vector | |
| args = sys.argv[sys.argv.index("--")+1:] | |
| mapping = json.loads(Path(args[0]).read_text()) | |
| scene = bpy.context.scene | |
| arm = bpy.data.objects[mapping["armature"]] | |
| body = bpy.data.objects[mapping["body"]] | |
| root = mapping["root"] | |
| feet = mapping["feet"] | |
| if scene.frame_end - scene.frame_start > 2400: | |
| raise ValueError("Animation exceeds supported 2401-frame inspection; evaluator review required") | |
| height = max(v.co.z for v in body.data.vertices)-min(v.co.z for v in body.data.vertices) | |
| height *= abs(body.matrix_world.to_scale().z) | |
| rest_root = arm.matrix_world @ arm.data.bones[root].matrix_local | |
| foot = arm.data.bones[feet[0]] | |
| forward = arm.matrix_world.to_3x3() @ (foot.tail_local-foot.head_local) | |
| forward.z = 0 | |
| if forward.length < .00001: | |
| raise ValueError("Cannot infer character facing from mapped foot") | |
| forward.normalize() | |
| forward_in_root = rest_root.to_3x3().inverted() @ forward | |
| rows = [] | |
| initial_vertices = None | |
| for frame in range(scene.frame_start, scene.frame_end+1): | |
| scene.frame_set(frame) | |
| graph = bpy.context.evaluated_depsgraph_get() | |
| ea = arm.evaluated_get(graph) | |
| rm = ea.matrix_world @ ea.pose.bones[root].matrix | |
| direction = rm.to_3x3() @ forward_in_root | |
| direction.z = 0 | |
| direction.normalize() | |
| fp = [ea.matrix_world @ ea.pose.bones[n].head for n in feet] | |
| eb = body.evaluated_get(graph) | |
| mesh = eb.to_mesh() | |
| try: | |
| verts = [rm.inverted() @ (eb.matrix_world @ v.co) for v in mesh.vertices] | |
| if initial_vertices is None: | |
| initial_vertices = [v.copy() for v in verts] | |
| if len(verts) != len(initial_vertices): | |
| raise ValueError("Changing topology needs evaluator review") | |
| rms = (sum((a-b).length_squared for a,b in zip(verts,initial_vertices))/len(verts))**.5 | |
| finally: | |
| eb.to_mesh_clear() | |
| rows.append({"frame":frame,"position":list(rm.translation),"forward":list(direction), | |
| "foot_lead":(fp[0]-fp[1]).dot(direction), | |
| "foot_heights":[p.z-rm.translation.z for p in fp],"deformation_rms":rms}) | |
| report = {"blender_version":bpy.app.version_string,"mapping":mapping,"character_height":height, | |
| "fps":scene.render.fps/scene.render.fps_base,"frames":rows, | |
| "bound_character":any(m.type=="ARMATURE" and m.object==arm and m.show_viewport for m in body.modifiers)} | |
| Path(args[1]).write_text(json.dumps(report)+"\n") | |