Expand description
Progressive validation system for 3MF models.
This module provides a four-level validation system that lets you choose the right balance between performance and thoroughness for your use case.
§Validation Levels
The ValidationLevel enum defines four progressively stricter validation modes:
§Minimal
Basic structural checks:
- Required attributes present (
unit,id, etc.) - Valid XML structure
- No obviously malformed data
Performance: Very fast (< 1ms for typical models) Use case: Quick sanity check, development testing
§Standard (Recommended)
Reference integrity and semantic correctness:
- All resource IDs are unique
- Build items reference valid objects
- Material references point to existing materials
- Component references form valid DAG (no cycles)
- Vertex indices within mesh bounds
Performance: Fast (< 10ms for typical models) Use case: Production parsing, most applications
§Strict
Full 3MF specification compliance:
- All Standard checks
- Metadata requirements enforced
- No unknown attributes or elements
- Extension namespaces correctly declared
Performance: Moderate Use case: Spec conformance testing, quality assurance
§Paranoid
Deep geometry analysis with advanced algorithms:
- All Strict checks
- Mesh manifoldness (edge-manifold, vertex-manifold)
- Self-intersection detection (BVH-accelerated)
- Orientation consistency (outward-facing normals)
- Degenerate triangle detection
- Island detection (connected components)
- Type-specific constraints (Model objects must be manifold)
Performance: Slow (can be seconds for complex models, O(n²) worst case) Use case: Critical manufacturing workflows, geometry repair pipelines
§Usage
use lib3mf_core::{Model, validation::ValidationLevel};
let model = Model::default();
// Quick check
let report = model.validate(ValidationLevel::Minimal);
assert!(!report.has_errors());
// Production use
let report = model.validate(ValidationLevel::Standard);
if report.has_errors() {
for item in &report.items {
eprintln!("[{}] {}", item.code, item.message);
}
}
// Critical applications
let report = model.validate(ValidationLevel::Paranoid);§Validation Report
Validation returns a ValidationReport containing:
- Errors: Spec violations, broken references, invalid geometry
- Warnings: Suspicious patterns, deprecated features, non-standard usage
- Info: Informational messages, optimization suggestions
Each item includes:
- Error code (numeric, for programmatic handling)
- Human-readable message
- Optional suggestion for fixing the issue
- Optional context (e.g., “Object 5”, “Triangle 123”)
§Geometry Validation Algorithms
The geometry module implements advanced mesh validation:
- Manifoldness: Each edge shared by exactly 2 triangles (edge-manifold). Each vertex has a single connected fan of triangles (vertex-manifold).
- Self-intersection: BVH (Bounding Volume Hierarchy) acceleration for O(n log n) triangle-triangle
intersection tests. See
bvhmodule. - Orientation: Directed edge analysis to detect reversed normals.
- Island detection: Connected component analysis using depth-first search.
§Performance Optimization
For large models, validation can be expensive. Strategies:
- Use Standard for production: Catches 99% of issues in < 10ms
- Defer Paranoid to background: Run geometry checks asynchronously
- Cache results: Validation reports are cloneable and serializable
- Progressive checking: Validate incrementally during parsing (not yet implemented)
Re-exports§
pub use displacement::validate_displacement;pub use geometry::validate_geometry;pub use report::ValidationReport;pub use report::ValidationSeverity;
Modules§
Enums§
- Validation
Level - Level of validation to perform.