Download tasks/sw-four-bar/tests/inspect_blend.py from refreshdotdev/Refresh-GUI-dataset: direct link, hf CLI and curl.
- Browser
- Download file 3.84 kB
-
https://huggingface.co/datasets/refreshdotdev/Refresh-GUI-dataset/resolve/main/tasks/sw-four-bar/tests/inspect_blend.py
- Command line
-
hf download hf://datasets/refreshdotdev/Refresh-GUI-dataset/tasks/sw-four-bar/tests/inspect_blend.py
-
curl -L -o inspect_blend.py https://huggingface.co/datasets/refreshdotdev/Refresh-GUI-dataset/resolve/main/tasks/sw-four-bar/tests/inspect_blend.py
3.84 kB
| import bpy,json,sys,math | |
| from pathlib import Path | |
| out=Path(sys.argv[sys.argv.index('--')+1]);objects={} | |
| for o in bpy.data.objects: | |
| d={'type':o.type,'location':list(o.location),'rotation':list(o.rotation_euler),'scale':list(o.scale),'dimensions':list(o.dimensions),'modifiers':[{'name':m.name,'type':m.type,'target':getattr(getattr(m,'object',None),'name',None)} for m in o.modifiers],'parent':getattr(o.parent,'name',None)} | |
| if o.type=='MESH': | |
| mesh=o.data;d.update(vertices=len(mesh.vertices),polygons=len(mesh.polygons),materials=[m.name for m in mesh.materials if m],vertex_groups=[g.name for g in o.vertex_groups],shape_keys=list(mesh.shape_keys.key_blocks.keys()) if mesh.shape_keys else []) | |
| deps=bpy.context.evaluated_depsgraph_get();ev=o.evaluated_get(deps);me=ev.to_mesh();pts=[list(o.matrix_world@v.co) for v in me.vertices];d['evaluated_vertices']=len(pts);d['bounds']=[[min(p[i] for p in pts),max(p[i] for p in pts)] for i in range(3)] if pts else [];ev.to_mesh_clear() | |
| # Coarse spatial shape descriptor independent of vertex numbering. | |
| if pts: | |
| bins=[0]*216;lo=[min(p[i] for p in pts) for i in range(3)];hi=[max(p[i] for p in pts) for i in range(3)] | |
| for p in pts: | |
| q=[min(5,int(6*(p[i]-lo[i])/max(hi[i]-lo[i],1e-9))) for i in range(3)];bins[q[0]*36+q[1]*6+q[2]]+=1 | |
| d['spatial_histogram']=[v/len(pts) for v in bins] | |
| if o.type=='ARMATURE': | |
| d['bones']={b.name:{'head':list(b.head_local),'tail':list(b.tail_local),'parent':getattr(b.parent,'name',None),'deform':b.use_deform,'connected':b.use_connect} for b in o.data.bones} | |
| d['pose']={b.name:{'constraints':[{'type':c.type,'target':getattr(getattr(c,'target',None),'name',None),'subtarget':getattr(c,'subtarget',None)} for c in b.constraints],'custom_shape':getattr(b.custom_shape,'name',None),'rotation':list(b.rotation_euler)} for b in o.pose.bones} | |
| d['collections']=[{'name':c.name,'visible':c.is_visible} for c in o.data.collections] | |
| if o.type=='MESH': | |
| for m in o.modifiers: | |
| if m.type=='NODES' and m.node_group:d['node_graph']=[{'name':n.name,'type':n.bl_idname,'inputs':{i.name:str(i.default_value) for i in n.inputs if hasattr(i,'default_value')}} for n in m.node_group.nodes] | |
| ad=o.animation_data | |
| if ad and ad.action: | |
| d['action']=ad.action.name | |
| try:d['fcurves']=[{'path':f.data_path,'index':f.array_index,'keys':[[float(p.co.x),float(p.co.y),p.interpolation] for p in f.keyframe_points]} for f in ad.action.fcurves] | |
| except AttributeError:d['animation_inspection_error']='Layered actions require version-specific inspector; calibration cannot use this feature.' | |
| objects[o.name]=d | |
| scene=bpy.context.scene | |
| result={'objects':objects,'scene':{'frame_start':scene.frame_start,'frame_end':scene.frame_end,'fps':scene.render.fps/scene.render.fps_base,'resolution':[scene.render.resolution_x,scene.render.resolution_y],'camera':getattr(scene.camera,'name',None)},'counts':{k:sum(o.type==k for o in bpy.data.objects) for k in ['MESH','ARMATURE','CAMERA','LIGHT']}} | |
| # Pose probes are verifier-controlled, not candidate-defined. | |
| probes=Path('/tests/oracle/pose-probes.json') | |
| if probes.exists(): | |
| result['pose_probes']={} | |
| for probe in json.loads(probes.read_text()): | |
| arm=bpy.data.objects[probe['armature']];bone=arm.pose.bones[probe['bone']];old=bone.rotation_euler.copy();bone.rotation_mode='XYZ';bone.rotation_euler=probe['rotation'];bpy.context.view_layer.update() | |
| result['pose_probes'][probe['id']]={} | |
| for name in probe['meshes']: | |
| ob=bpy.data.objects[name];deps=bpy.context.evaluated_depsgraph_get();ev=ob.evaluated_get(deps);me=ev.to_mesh();p=[list(ob.matrix_world@v.co) for v in me.vertices];result['pose_probes'][probe['id']][name]=[[min(v[i] for v in p),max(v[i] for v in p)] for i in range(3)];ev.to_mesh_clear() | |
| bone.rotation_euler=old;bpy.context.view_layer.update() | |
| out.write_text(json.dumps(result,indent=2,allow_nan=False)) | |