"""CC0 1.0 original controlled mesh handoff in Blender, not a scan trial. Set SCANNER_BLENDER_INPUT to the directory with the three original STL fixtures. Set SCANNER_BLENDER_OUTPUT to a new directory. Run with background Blender. No source files are repaired, overwritten, uploaded or removed. """ from pathlib import Path import csv,hashlib,json,math,os,sys import bpy,bmesh source=Path(os.environ['SCANNER_BLENDER_INPUT']).resolve();out=Path(os.environ['SCANNER_BLENDER_OUTPUT']).resolve() assert not out.exists(),'Use a fresh output folder; previous results are retained' out.mkdir(parents=True);checks=[] bpy.context.scene.unit_settings.system='METRIC' bpy.context.scene.unit_settings.scale_length=0.001 bpy.context.scene.unit_settings.length_unit='MILLIMETERS' def digest(path):return hashlib.sha256(path.read_bytes()).hexdigest() def only_selected(obj): for existing in bpy.context.view_layer.objects:existing.select_set(False) obj.select_set(True);bpy.context.view_layer.objects.active=obj def inspect(obj,stage,input_name,scale=1,scene_unit=False): vertices=[obj.matrix_world@v.co for v in obj.data.vertices] minimum=[min(v[i] for v in vertices) for i in range(3)];maximum=[max(v[i] for v in vertices) for i in range(3)] spans=[b-a for a,b in zip(minimum,maximum)] bm=bmesh.new();bm.from_mesh(obj.data) boundary=sum(len(edge.link_faces)==1 for edge in bm.edges) overlinked=sum(len(edge.link_faces)>2 for edge in bm.edges) wire=sum(len(edge.link_faces)==0 for edge in bm.edges) closed=boundary==0 and overlinked==0 and wire==0 volume=abs(bm.calc_volume(signed=True))*abs(obj.matrix_world.determinant()) if closed else None row={'stage':stage,'source_file':input_name,'source_sha256':digest(source/input_name) if (source/input_name).is_file() else digest(out/input_name),'global_scale':scale,'use_scene_unit':scene_unit,'forward_axis':'Y','up_axis':'Z','vertices':len(obj.data.vertices),'polygons':len(obj.data.polygons),'bounds_min_mm':minimum,'bounds_max_mm':maximum,'spans_mm':spans,'boundary_edges':boundary,'edges_with_more_than_two_faces':overlinked,'wire_edges':wire,'closed_edge_incidence':closed,'volume_mm3':volume,'scene_scale_length':bpy.context.scene.unit_settings.scale_length,'self_intersections_tested':False} checks.append(row);bm.free();return row def import_stl(path): before=set(bpy.data.objects) result=bpy.ops.wm.stl_import(filepath=str(path),global_scale=1.0,use_scene_unit=False,forward_axis='Y',up_axis='Z',use_mesh_validate=True) assert result=={'FINISHED'} added=[obj for obj in bpy.data.objects if obj not in before and obj.type=='MESH'];assert len(added)==1 return added[0] def expect(row,spans,polygons,boundary,volume): assert all(abs(a-b)