# How the DfAM Check Skill Measures Mesh Printability in text-to-cad

> Discover how the DfAM Check skill measures mesh printability in text-to-cad by analyzing overhang angles wall thickness and support volume using dfam_tool.py.

- Repository: [earthtojake/text-to-cad](https://github.com/earthtojake/text-to-cad)
- Tags: how-to-guide
- Published: 2026-09-11

---

**The DfAM Check skill evaluates mesh printability by analyzing geometric facts including overhang angles, wall thickness, and support volume requirements using the [`dfam_tool.py`](https://github.com/earthtojake/text-to-cad/blob/main/dfam_tool.py) script in the earthtojake/text-to-cad repository.**

The **DfAM (Design for Additive Manufacturing) Check** skill provides automated printability analysis for 3D meshes within the [earthtojake/text-to-cad](https://github.com/earthtojake/text-to-cad) open-source project. All geometric calculations are implemented in [`skills/dfam-check/scripts/dfam_tool.py`](https://github.com/earthtojake/text-to-cad/blob/main/skills/dfam-check/scripts/dfam_tool.py), which performs multi-faceted analysis to determine whether a mesh can be successfully printed. This article examines the specific algorithms and measurement techniques used to quantify printability.

## Core Printability Metrics in dfam_tool.py

The measurement workflow begins with fundamental geometric validation before proceeding to printability-specific calculations.

### Basic Mesh Statistics (_mesh_facts)

The `_mesh_facts()` function (lines 37-45 in [`dfam_tool.py`](https://github.com/earthtojake/text-to-cad/blob/main/dfam_tool.py)) extracts foundational data using **trimesh**:

- Bounding box dimensions
- Volume and surface area calculations
- Triangle count and watertightness status
- Euler number and body count

These baseline metrics establish whether the mesh represents a valid solid manifold suitable for 3D printing.

### Scale Validation (_scale_hint)

The `_scale_hint()` function (lines 8-27) performs a critical sanity check on mesh units. It calculates the bounding box diagonal and flags meshes where the diagonal is less than 1mm, indicating the model is likely not scaled in millimeters. This prevents analysis errors caused by meter or inch-based coordinate systems.

## Overhang and Support Analysis

Overhang detection represents the core printability metric, determining where support structures are required during printing.

### Calculating Overhang Areas (_overhang_facts)

The `_overhang_facts()` function (lines 48-95) implements the primary overhang detection algorithm through these steps:

1. **Face Normal Analysis**: Extracts face normals (`mesh.face_normals`) and areas (`mesh.area_faces`)
2. **Down-Facing Face Identification**: Selects faces where the Z-component points downward (`normals[:, 2] < -1e-6`)
3. **Surface Angle Computation**: Calculates the angle relative to horizontal using `surface_angle = 90 - degrees(arcsin(-normals[:, 2]))`, yielding 0° for flat ceilings and 90° for vertical walls
4. **Build Plate Exclusion**: Removes faces with centroids within 0.1mm of the lowest Z coordinate (`on_plate`)
5. **Angle Threshold Application**: Counts only faces where `surface_angle < angle_limit` (default **45°**)
6. **Aggregation**: Computes `down_facing_area_below_limit_mm2` as the summed area of qualifying faces, plus a percentage of total surface area
7. **Histogram Generation**: Builds a 10°-wide distribution histogram of all down-facing, off-plate faces
8. **Critical Zone Identification**: Returns the eight largest overhang faces with location coordinates, specific angles, and areas (lines 74-85)

### Support Volume Estimation (_support_volume_facts)

The `_support_volume_facts()` function (lines 34-60) approximates material requirements by constructing prismatic volumes from each overhang face down to the build plate. It calculates the estimated support volume by summing `area × height` for each overhang face, then computes the ratio of support volume to part volume to quantify print efficiency.

## Wall Thickness Validation

### Ray-Casting Thickness Measurement (_wall_facts)

The `_wall_facts()` function (lines 98-170) estimates interior wall thickness through ray-casting:

- Casts rays from each face inward (opposite the face normal)
- Records distances to intersection points to determine wall thickness
- Handles multi-body assemblies by splitting the mesh (`mesh.split`) and measuring each body separately via `_wall_facts_single()`

The function returns statistical distributions including minimum, median, 5th percentile, 25th percentile, and the eight thinnest sampled locations across the model.

## Orientation Optimization

### Evaluating Build Orientations (_orientation_facts)

The `_orientation_facts()` function (lines 62-90) optimizes build orientation by evaluating six candidate orientations:

1. Current orientation
2. Z-axis rotation
3. 180° flip on X-axis
4. ±90° rotations on X-axis
5. ±90° rotations on Y-axis

For each orientation, the function re-runs `_overhang_facts()` and reports:
- Support area in mm²
- Support area percentage of total surface
- Build height in mm

This comparison enables the skill to recommend orientations that minimize overhangs and reduce support material requirements.

## Error Handling and CLI Usage

The DfAM Check skill implements robust error management and provides a command-line interface for standalone operation.

### Resilient Execution (_safe)

All measurement functions are wrapped by `_safe()` (lines 93-100), which captures exceptions from degenerate meshes or calculation failures. Rather than aborting the entire analysis, errors are reported as JSON fields, ensuring partial results are preserved when specific measurements fail.

### Command-Line Interface

The tool supports two primary operations via CLI:

**Measure full printability (default 2000 samples, 45° angle limit):**

```bash
python dfam_tool.py measure path/to/model.stl

```

**Evaluate orientation candidates only:**

```bash
python dfam_tool.py orientations path/to/model.stl --angle-limit 30

```

Both commands output **JSON** reports containing sections for mesh facts, scale hints, overhang analysis, wall thickness measurements, support volume estimates, and orientation comparisons. The skill references [`skills/dfam-check/references/process-limits.md`](https://github.com/earthtojake/text-to-cad/blob/main/skills/dfam-check/references/process-limits.md) for printable process limits against which measurements are compared, and integrates into the broader agent workflow as defined in [`skills/dfam-check/SKILL.md`](https://github.com/earthtojake/text-to-cad/blob/main/skills/dfam-check/SKILL.md).

## Summary

- The DfAM Check skill quantifies printability through geometric analysis in [`skills/dfam-check/scripts/dfam_tool.py`](https://github.com/earthtojake/text-to-cad/blob/main/skills/dfam-check/scripts/dfam_tool.py)
- **Overhang detection** uses face normal analysis with a default 45° threshold, excluding faces within 0.1mm of the build plate
- **Wall thickness** is measured via inward ray-casting from mesh faces, supporting multi-body assemblies
- **Support volume** is estimated using prismatic approximations from overhang faces to the build plate
- **Orientation optimization** evaluates six candidate positions to minimize support requirements
- Error handling via `_safe()` ensures partial analysis completion even with degenerate geometry

## Frequently Asked Questions

### What is the default angle limit for overhang detection?

The default angle limit is **45 degrees**, defined in the `_overhang_facts()` function. This aligns with standard FDM printing capabilities where angles steeper than 45° typically require support structures. Users can override this via the `--angle-limit` CLI parameter.

### How does the DfAM Check Skill handle multi-body meshes?

For wall thickness measurements, the skill automatically splits multi-body assemblies using `mesh.split()` and analyzes each body separately through `_wall_facts_single()`. The mesh loading function `_load()` in [`dfam_tool.py`](https://github.com/earthtojake/text-to-cad/blob/main/dfam_tool.py) supports both single meshes and scenes via trimesh.

### What file formats does the DfAM Check Skill support?

The skill leverages **trimesh** for mesh loading, supporting standard formats including STL, OBJ, PLY, and GLB. The `_load()` function handles format detection automatically and manages both single mesh files and multi-mesh scenes.

### How does orientation exploration improve printability?

The `_orientation_facts()` function evaluates six candidate orientations by calculating overhang areas and build heights for each position. This allows the skill to recommend orientations that reduce support material requirements, decrease post-processing time, and improve surface quality on critical faces.