数据与分析
evo-stl-mass
Parse binary STL files with material IDs in attribute bytes, find largest connected component, compute volume and mass. Use when calculating mass of 3D printed parts from STL scan data.
Zhang-Henry · 已有 AI 审核记录
安装与使用
运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。
npx skills add Zhang-Henry/CoEvoSkills --skill evo-stl-mass技能说明
name: evo-stl-mass description: "Parse binary STL files with material IDs in attribute bytes, find largest connected component, compute volume and mass. Use when calculating mass of 3D printed parts from STL scan data."
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
import 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