blast_stress_solver/lib.rs
1//! # Blast Stress Solver
2//!
3//! Rust library wrapping the NVIDIA Blast stress solver for destructible structures.
4//!
5//! ## Features
6//!
7//! - **Core solver**: `ExtStressSolver` — manages nodes, bonds, actors, fracture detection and splitting
8//! - **Low-level solver**: `StressProcessor` — direct conjugate-gradient solver access
9//! - **Bond stress analysis**: `compute_bond_stress` — decompose impulses into compression/tension/shear
10//! - **Scenarios** (feature `scenarios`): Pre-built wall, tower, and bridge scenario builders
11//! - **Rapier integration** (feature `rapier`): `DestructionRuntime` for existing Rapier apps and
12//! `DestructibleSet` as the low-level escape hatch
13//! - **Authoring** (feature `authoring`): Auto-generate bonds from pre-fractured triangle chunks and
14//! assemble `ScenarioDesc` values from piece meshes
15//!
16//! `DestructionRuntime` is the recommended integration point when you already
17//! own a Rapier world and want normal Rapier contacts to drive fracture while
18//! still keeping `PhysicsPipeline::step(...)` in your app.
19//!
20//! ## Quick Start (without Rapier)
21//!
22//! ```no_run
23//! use blast_stress_solver::*;
24//!
25//! let nodes = vec![
26//! NodeDesc { centroid: Vec3::new(0.0, 0.0, 0.0), mass: 0.0, volume: 1.0 }, // support
27//! NodeDesc { centroid: Vec3::new(0.0, 1.0, 0.0), mass: 10.0, volume: 1.0 }, // dynamic
28//! ];
29//! let bonds = vec![
30//! BondDesc {
31//! centroid: Vec3::new(0.0, 0.5, 0.0),
32//! normal: Vec3::new(0.0, 1.0, 0.0),
33//! area: 1.0,
34//! node0: 0,
35//! node1: 1,
36//! },
37//! ];
38//! let settings = SolverSettings::default();
39//! let mut solver = ExtStressSolver::new(&nodes, &bonds, &settings).unwrap();
40//!
41//! solver.add_gravity(Vec3::new(0.0, -9.81, 0.0));
42//! solver.update();
43//!
44//! let overstressed = solver.overstressed_bond_count();
45//! ```
46
47mod ffi;
48
49// On `wasm32-unknown-unknown` the Blast C++ backend references dozens
50// of libc symbols (malloc, fwrite, abort, …) through libc++'s STL
51// helpers. We provide pure-Rust stubs for all of them in
52// `wasm_runtime_shims`, so the final wasm module imports neither
53// `env.*` libc functions nor `wasi_snapshot_preview1.*` wasi calls
54// — it is a pure library module.
55#[cfg(target_arch = "wasm32")]
56mod wasm_runtime_shims;
57
58// `-fno-exceptions` is not enough to strip every mention of
59// `__cxa_allocate_exception` / `__cxa_throw` from libc++ — STL
60// containers still emit them behind `throw_bad_alloc`-style helpers.
61// Provide trapping stubs so the wasm module stays self-contained.
62#[cfg(target_arch = "wasm32")]
63mod wasm_cxa_stubs;
64
65pub mod bond_stress;
66pub mod ext_stress_solver;
67pub mod stress_processor;
68pub mod types;
69
70#[cfg(feature = "authoring")]
71pub mod authoring;
72
73#[cfg(feature = "scenarios")]
74pub mod scenarios;
75
76#[cfg(feature = "rapier")]
77pub mod rapier;
78
79// Re-export primary types at crate root for convenience
80#[cfg(feature = "authoring")]
81pub use authoring::{
82 build_scenario_from_pieces, create_bonds_from_triangles, AuthoringError, BondingMode,
83 BondingOptions, ScenarioPiece, TriangleChunk,
84};
85pub use bond_stress::compute_bond_stress;
86pub use ext_stress_solver::ExtStressSolver;
87pub use stress_processor::{
88 StressBondDesc, StressDataParams, StressErrorSq, StressImpulse, StressNodeDesc,
89 StressProcessor, StressSolverParams, StressVelocity,
90};
91pub use types::*;