"""CC0-1.0 synthetic cleanup and known-scale exercise, not scanner test data. Python 3.11, trimesh 4.9.0, numpy and networkx 3.4.2. Run in this directory. No files are uploaded. """ from pathlib import Path import csv,json,importlib.metadata as metadata import numpy as np import trimesh folder=Path(__file__).resolve().parent baseline=trimesh.creation.box(extents=[100,40,20]);baseline.apply_translation([50,20,10]) duplicates=trimesh.Trimesh(vertices=baseline.vertices.copy(),faces=np.vstack([baseline.faces,baseline.faces[0]]),process=False) dedup=duplicates.copy();dedup.update_faces(dedup.unique_faces());dedup.remove_unreferenced_vertices() top=baseline.face_normals[:,2]>.9 opened=trimesh.Trimesh(vertices=baseline.vertices.copy(),faces=baseline.faces[~top],process=False) filled=opened.copy();fill_result=trimesh.repair.fill_holes(filled) smoothed=baseline.copy() # Authored uniform neighbor averaging: two simultaneous steps, weight 0.5. # This is deliberately aggressive on a low-poly box and preserves no volume. neighbors=baseline.vertex_neighbors for _ in range(2): before=smoothed.vertices.copy() smoothed.vertices=np.array([.5*p+.5*np.mean(before[neighbors[i]],axis=0) for i,p in enumerate(before)]) scaled=baseline.copy();scaled.apply_scale(25.4) corrected=scaled.copy();corrected.apply_scale(1/25.4) meshes={'baseline.stl':baseline,'duplicate-face-raw.stl':duplicates,'duplicate-face-cleaned.stl':dedup,'open-top-raw.stl':opened,'known-top-restored.stl':filled,'aggressive-smoothing.stl':smoothed,'known-scale-error.stl':scaled,'known-scale-corrected.stl':corrected} records=[] for name,mesh in meshes.items(): mesh.export(folder/name) loaded=trimesh.load_mesh(folder/name,process=False) # Exact-coordinate merge is only for incidence checks of these synthetic files. checked=loaded.copy();checked.merge_vertices() edges=np.bincount(checked.edges_unique_inverse) records.append({'file':name,'triangles':len(loaded.faces),'bounds_mm':loaded.extents.tolist(),'boundary_edges':int(np.sum(edges==1)),'non_manifold_edges':int(np.sum(edges>2)),'watertight':bool(checked.is_watertight),'volume_mm3':float(checked.volume) if checked.is_watertight else None,'surface_area_mm2':float(loaded.area)}) by={r['file']:r for r in records} assert by['duplicate-face-raw.stl']['non_manifold_edges']>0 assert by['duplicate-face-cleaned.stl']['watertight'] and by['duplicate-face-cleaned.stl']['triangles']==12 assert by['open-top-raw.stl']['boundary_edges']==4 and by['open-top-raw.stl']['volume_mm3'] is None assert fill_result and by['known-top-restored.stl']['watertight'] and abs(by['known-top-restored.stl']['volume_mm3']-80000)<.01 assert np.allclose(by['known-scale-corrected.stl']['bounds_mm'],[100,40,20]) assert by['aggressive-smoothing.stl']['bounds_mm'][0]<100 result={'created_at':'2026-10-05','geometry':'author-defined synthetic 100 x 40 x 20 mm box','license':'CC0-1.0','versions':{'python':'3.11', 'trimesh':metadata.version('trimesh'),'numpy':metadata.version('numpy'),'networkx':metadata.version('networkx')},'operations':['remove duplicate faces via unique_faces','fill deliberately missing top using trimesh.repair.fill_holes','authored uniform neighbor averaging, weight .5, two simultaneous steps, no volume constraint','known correction: multiply planted 25.4-scaled coordinates by 1/25.4'],'scope':'Synthetic software exercise. No self-intersection certification, captured geometry, scanner measurement or CAD history is established.','files':records} (folder/'file-check.json').write_text(json.dumps(result,indent=2)+'\n') with (folder/'file-check.csv').open('w',newline='',encoding='utf-8') as f: w=csv.writer(f);w.writerow(['file','triangles','x_mm','y_mm','z_mm','boundary_edges','non_manifold_edges','watertight','volume_mm3','surface_area_mm2']) for r in records:w.writerow([r['file'],r['triangles'],*r['bounds_mm'],r['boundary_edges'],r['non_manifold_edges'],r['watertight'],r['volume_mm3'],r['surface_area_mm2']]) (folder/'README.txt').write_text('CC0-1.0. Original synthetic geometry, October 5, 2026.\nNOT physical scan data. Coordinates are authored in millimeters; choose mm on STL import.\nRun python reproduce.py with Python 3.11, trimesh 4.9.0, NumPy 2.4.6 and networkx 3.4.2.\nKeep raw files alongside processed copies. The known box top is restored only because its intended geometry is author-defined. A hole in scan data can be an uncaptured area or an intended feature; do not fill it without separate evidence.\nAggressive smoothing changes dimensions and removes corner shape. Correcting the planted 25.4 scale factor uses known author intent; it does not automatically discover a real scanner unit error.\nThe check measures bounds, exact-coordinate edge incidence, area and closed-mesh signed volume. It does not prove freedom from self-intersections, correct orientation in all meshes, physical accuracy or editable CAD.\n') print(json.dumps({'status':'PASS','files':len(records),'filled_top':bool(fill_result)}))