STL Mass Calculation Skill
This skill parses binary STL files where the 2-byte attribute field stores a Material ID, finds the largest connected component (filtering out debris), computes the enclosed volume using signed tetrahedra, and calculates mass using a material density lookup table.
Quick Start
pythonimport sys sys.path.insert(0, '/app/environment/skills/evo-stl-mass/scripts') from utils import compute_mass, validate_report result = compute_mass( stl_path='/root/scan_data.stl', density_table_path='/root/material_density_table.md', output_path='/root/mass_report.json' ) print(result) validate_report('/root/mass_report.json')
Key Functions
parse_binary_stl(filepath)- Parse binary STL, extract triangles with material IDsfind_connected_components(triangles, tolerance)- Union-Find based component detectioncompute_mesh_volume(triangles, indices)- Signed tetrahedra volume calculationget_component_material_id(triangles, indices)- Majority vote material IDparse_density_table(filepath)- Parse markdown density tablecompute_mass(stl_path, density_table_path, output_path)- End-to-end entry pointvalidate_report(output_path)- Validate output JSON
Algorithm
- Parse binary STL: 80-byte header + 4-byte count + N*50-byte records
- Each record: 12 floats (normal + 3 vertices) + 2-byte attribute (Material ID)
- Build vertex adjacency with tolerance-based matching
- Union-Find to group connected triangles
- Select largest component by triangle count
- Compute volume via signed tetrahedra sum
- Convert units (mm^3 to cm^3 if needed)
- Look up density and compute mass


