"""Original CC0 file-package receiving exercise. Run in Blender bundled Python. SCANNER_FORMAT_INPUT: directory with the nine source fixtures. SCANNER_FORMAT_OUTPUT: new, absent result directory. No source overwrite/delete. """ from pathlib import Path from datetime import datetime,timezone import csv,hashlib,json,os,sys import bpy source=Path(os.environ['SCANNER_FORMAT_INPUT']).resolve();out=Path(os.environ['SCANNER_FORMAT_OUTPUT']).resolve();assert not out.exists(),'Use a fresh output directory';out.mkdir(parents=True) bpy.context.scene.unit_settings.system='METRIC';bpy.context.scene.unit_settings.scale_length=0.001;bpy.context.scene.unit_settings.length_unit='MILLIMETERS' inputs=['box.stl','box.obj','box.mtl','checker.png','missing-material.obj','missing-texture.obj','missing-texture.mtl','colored-mesh.ply','colored-points.ply'];assert all((source/x).is_file() for x in inputs) assert not (source/'not-supplied-material.mtl').exists() and not (source/'not-supplied-checker.png').exists() sha=lambda p:hashlib.sha256(p.read_bytes()).hexdigest();rows=[] for case,filename,kind in [('stl_surface','box.stl','stl'),('obj_complete','box.obj','obj'),('obj_missing_material','missing-material.obj','obj'),('obj_missing_texture','missing-texture.obj','obj'),('ply_colored_mesh','colored-mesh.ply','ply'),('ply_colored_points','colored-points.ply','ply')]: before=set(bpy.data.objects);settings={'global_scale':1.0,'forward_axis':'Y','up_axis':'Z'} if kind=='stl':settings.update(use_scene_unit=False,use_mesh_validate=True) if kind=='ply':settings.update(use_scene_unit=False,merge_verts=False,import_colors='SRGB',import_attributes=True) if kind=='obj':settings.update(validate_meshes=True,mtl_name_collision_mode='MAKE_UNIQUE') result=getattr(bpy.ops.wm,kind+'_import')(filepath=str(source/filename),**settings);assert result=={'FINISHED'} added=[o for o in bpy.data.objects if o not in before and o.type=='MESH'];assert len(added)==1;obj=added[0];bpy.context.view_layer.update();coords=[obj.matrix_world@v.co for v in obj.data.vertices] minimum=[min(v[i] for v in coords) for i in range(3)];maximum=[max(v[i] for v in coords) for i in range(3)];spans=[b-a for a,b in zip(minimum,maximum)] materials=[];images=[] for material in obj.data.materials: if material is None:continue materials.append({'name':material.name,'diffuse_color':list(material.diffuse_color),'use_nodes':material.use_nodes}) if material.use_nodes: for node in material.node_tree.nodes: if node.type=='TEX_IMAGE': image=node.image;image_size=list(image.size) if image else [];images.append({'material':material.name,'image':image.name if image else None,'file':Path(image.filepath).name if image else None,'has_data':bool(image and image.has_data),'size':image_size,'channels':image.channels if image else None,'first_pixel':list(image.pixels[:4]) if image and image.has_data else []}) colors=[] for attr in obj.data.color_attributes: unique=sorted(set(tuple(round(c,6) for c in item.color) for item in attr.data));colors.append({'name':attr.name,'domain':attr.domain,'type':attr.data_type,'values':len(attr.data),'unique_colors':unique}) rows.append({'case':case,'source_file':filename,'source_sha256':sha(source/filename),'import_settings':settings,'vertices':len(obj.data.vertices),'faces':len(obj.data.polygons),'bounds_min_declared_mm':minimum,'bounds_max_declared_mm':maximum,'spans_declared_mm':spans,'uv_layers':len(obj.data.uv_layers),'materials':materials,'image_nodes':images,'color_attributes':colors}) checks=[] def check(name,condition): checks.append({'name':name,'pass':bool(condition)}) for row in rows: check(row['case']+' eight vertices and expected faces',row['vertices']==8 and row['faces']==(0 if row['case']=='ply_colored_points' else 12)) check(row['case']+' declared spans',all(abs(a-b)<1e-5 for a,b in zip(row['spans_declared_mm'],[100,40,20]))) by={x['case']:x for x in rows} check('STL does not acquire materials or vertex colors',not by['stl_surface']['materials'] and not by['stl_surface']['color_attributes']) images=by['obj_complete']['image_nodes'];check('Complete OBJ loads original16x16checker withUV',by['obj_complete']['uv_layers']==1 and len(images)==1 and images[0]['has_data'] and images[0]['size']==[16,16] and images[0]['file']=='checker.png') check('Absent MTL creates no image texture despite retained geometry',len(by['obj_missing_material']['image_nodes'])==0) images=by['obj_missing_texture']['image_nodes'];check('Absent PNG is an actual unloaded image node',len(images)==1 and not images[0]['has_data'] and images[0]['file']=='not-supplied-checker.png') for key in ['ply_colored_mesh','ply_colored_points']:check(key+' retains two vertex colors',len(by[key]['color_attributes'])==1 and len(by[key]['color_attributes'][0]['unique_colors'])==2 and not by[key]['image_nodes']) report={'status':'PASS' if all(x['pass'] for x in checks) else 'FAIL','performed_at_utc':datetime.now(timezone.utc).isoformat(),'application':'Blender','version':list(bpy.app.version),'build_hash':bpy.app.build_hash.decode(),'background':bpy.app.background,'scene_units':{'system':bpy.context.scene.unit_settings.system,'scale_length':bpy.context.scene.unit_settings.scale_length,'length_unit':bpy.context.scene.unit_settings.length_unit},'source_files':[{'file':x,'bytes':(source/x).stat().st_size,'sha256':sha(source/x)} for x in inputs],'rows':rows,'checks':checks,'actual_operations':len(rows),'gui_workflow_tested':False,'publisher_scanner_hardware_test':False,'cad_solid_or_history_tested':False,'other_importers_tested':False,'limits':['Original authored coordinates with declared millimeters, not physical scans or automatic unit recognition.','Native imported geometry, image-node data after querying Image.size, and vertex-color attributes inspected; shaded appearance/GUI not tested.','The planted MTL/PNG omissions are never-created files, not evidence of exporter or scanner failure.','Counts/bounds do not establish self-intersection absence, printability or physical accuracy.','No external model/photograph used; original deterministic checker image and fixtures are CC0.']} with (out/'file-check.json').open('x',encoding='utf8') as f:json.dump(report,f,indent=2) with (out/'file-check.csv').open('x',encoding='utf8',newline='') as f: w=csv.writer(f);w.writerow(['case','source_file','vertices','faces','x_declared_mm','y_declared_mm','z_declared_mm','material_slots','loaded_image_nodes','unloaded_image_nodes','color_layers']) for row in rows:w.writerow([row['case'],row['source_file'],row['vertices'],row['faces'],*row['spans_declared_mm'],len(row['materials']),sum(x['has_data'] for x in row['image_nodes']),sum(not x['has_data'] for x in row['image_nodes']),len(row['color_attributes'])]) print('FORMAT_HANDOFF_RESULT '+json.dumps({'status':report['status'],'operations':len(rows),'checks':len(checks),'failed':[x['name'] for x in checks if not x['pass']],'version':report['version']}),flush=True) if report['status']!='PASS':raise AssertionError('Native format checks failed; keep actual raw results')