"""Validate the actual optimized mesh, paint protection and all transferred clips.""" import bpy,numpy as np,json,struct from pathlib import Path r=Path(__file__).resolve().parent.parent;out=r/'Demon_v0.19/reviews/infernal_v01' bpy.ops.wm.open_mainfile(filepath=str(r/'tools/model_sources/infernal_game.blend')) o=bpy.data.objects['Infernal_Game_Mesh'];rig=bpy.data.objects['INFERNAL_RIG'];v=np.array([tuple(x.co) for x in o.data.vertices]);edges=np.array([tuple(e.vertices) for e in o.data.edges]);initial=np.linalg.norm(v[edges[:,0]]-v[edges[:,1]],axis=1) assert len(rig.data.bones)==166 assert np.isfinite(v).all() and v[:,2].min()>-.0001 floor=v[v[:,2]<.01];assert len(floor)>0 and abs(floor[:,0]).max()<.13,'pedestal left below feet' assert len(o.data.polygons)<100000 for vertex in o.data.vertices:assert abs(sum(group.weight for group in vertex.groups)-1)<.001 skin=next(m for m in o.data.materials if m.name=='Infernal exposed arm skin');shader=next(n for n in skin.node_tree.nodes if n.type=='BSDF_PRINCIPLED') assert not shader.inputs['Base Color'].is_linked and shader.inputs['Base Color'].default_value[0]>.3 for name in ['infernal_basecolor.png','infernal_normal.png','infernal_orm.png']: image=bpy.data.images[name];assert tuple(image.size)==(4096,4096) for t in rig.animation_data.nla_tracks:t.mute=True metrics={} for clip in ['Idle','Walk','Whip']: action=bpy.data.actions['Infernal / '+clip];rig.animation_data.action=action;maximum=0.;max_edge=0. for frame in range(1,int(action.frame_range[1])+1,4): bpy.context.scene.frame_set(frame);bpy.context.view_layer.update();ev=o.evaluated_get(bpy.context.evaluated_depsgraph_get());mesh=ev.to_mesh();p=np.array([tuple(x.co) for x in mesh.vertices]);ev.to_mesh_clear() assert np.isfinite(p).all() maximum=max(maximum,float(np.linalg.norm(p-v,axis=1).max()));growth=np.linalg.norm(p[edges[:,0]]-p[edges[:,1]],axis=1)-initial;max_edge=max(max_edge,float(growth.max())) if growth.max()>.14: edge=edges[growth.argmax()];print('BAD EDGE',clip,frame,[(v[i].round(3).tolist(),[(o.vertex_groups[x.group].name,round(x.weight,3)) for x in o.data.vertices[i].groups]) for i in edge],float(growth.max()),flush=True) assert maximum<1.2,(clip,maximum) assert max_edge<.15,(clip,'long stretched film',max_edge) metrics[clip]={'frames':int(action.frame_range[1]),'max_vertex_travel_m':round(maximum,5),'max_edge_growth_m':round(max_edge,5)} b=(out/'infernal_game.glb').read_bytes();length=struct.unpack_from('