"""Reopen every delivered .blend and compare physical meshes with the snapshot.""" import bpy import bmesh import hashlib import json from pathlib import Path ROOT=Path(__file__).resolve().parents[4] SOURCE=Path(__file__).resolve().parent/'snapshot' catalog=json.loads((ROOT/'assets/collections/storybook/catalog.json').read_text()) bpy.ops.wm.open_mainfile(filepath=str(SOURCE/'source_snapshot.blend')) def geometry(obj): return ([list(v.co) for v in obj.data.vertices], [list(p.vertices) for p in obj.data.polygons]) baseline={kind:geometry(bpy.data.objects[kind]) for kind in catalog['models'] if kind in bpy.data.objects} checks=[] for kind,data in catalog['models'].items(): path=ROOT/data['sourceBlend'] bpy.ops.wm.open_mainfile(filepath=str(path)) obj=bpy.data.objects[kind] physical=[o for o in bpy.context.scene.objects if not o.name.startswith('ink_')] authored=data.get('geometryOrigin')=='authored' mesh_match=None if authored else geometry(obj)==baseline[kind] correct=(len(physical)==1 and physical[0].name==kind and (authored or mesh_match) and obj.location.length<1e-6 and all(abs(x-1)<1e-6 for x in obj.scale)) check={'id':kind,'passed':correct,'objects':[o.name for o in bpy.context.scene.objects], 'geometryMatchesSnapshot':mesh_match, 'origin':list(obj.location),'dimensions':list(obj.dimensions), 'materials':[m.name for m in obj.data.materials]} if kind=='iron_ball': radius=max(v.co.length for v in obj.data.vertices) check['measuredRadius']=radius correct=correct and abs(radius-data['radius'])<1e-6 check['passed']=correct if authored: bm=bmesh.new();bm.from_mesh(obj.data) volume=abs(bm.calc_volume(signed=True));closed=all(e.is_manifold for e in bm.edges);bm.free() correct=correct and closed and all(abs(d-1)<1e-6 for d in obj.dimensions) if kind in ('wall','directional_boost'): correct=correct and abs(volume-1)<1e-6 if kind=='directional_boost': arrow=bpy.data.objects.get('ink_boost_arrow_fill') correct=correct and arrow is not None if arrow is not None: points=[v.co for v in arrow.data.vertices] tip=max(points,key=lambda v:v.x) correct=correct and tip.x>0 and abs(tip.y)<1e-6 and all(1