### Basic 3D Physics Scene Setup Source: https://github.com/avianphysics/avian/blob/main/README.md Sets up a Bevy application with Avian physics, including a static platform and a dynamic cube with initial angular velocity. ```rust use avian3d::prelude::*; use bevy::prelude::*; fn main() { App::new() // Enable physics .add_plugins((DefaultPlugins, PhysicsPlugins::default())) .add_systems(Startup, setup) .run(); } fn setup( mut commands: Commands, mut meshes: ResMut>, mut materials: ResMut>, ) { // Static physics object with a collision shape commands.spawn(( RigidBody::Static, Collider::cylinder(4.0, 0.1), Mesh3d(meshes.add(Cylinder::new(4.0, 0.1))), MeshMaterial3d(materials.add(Color::WHITE)), )); // Dynamic physics object with a collision shape and initial angular velocity commands.spawn(( RigidBody::Dynamic, Collider::cuboid(1.0, 1.0, 1.0), AngularVelocity(Vec3::new(2.5, 3.5, 1.5)), Mesh3d(meshes.add(Cuboid::from_length(1.0))), MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))), Transform::from_xyz(0.0, 4.0, 0.0), )); // Light commands.spawn(( PointLight { shadows_enabled: true, ..default() }, Transform::from_xyz(4.0, 8.0, 4.0), )); // Camera commands.spawn(( Camera3d::default(), Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Dir3::Y), )); } ``` -------------------------------- ### Markdown Example for Migration Guide Section Source: https://github.com/avianphysics/avian/blob/main/migration-guides/README.md Example of how to structure a section in a migration guide, including a title and associated PRs. ```markdown ## Sleeping and Simulation Islands PRs: [#809](https://github.com/avianphysics/avian/pull/809) Content goes here ``` -------------------------------- ### Running f64 Precision Examples Source: https://github.com/avianphysics/avian/blob/main/README.md Command to run examples with f64 precision by disabling default features and specifying features manually. ```shell cargo run --example cubes --no-default-features --features "3d f64 parry-f64" ``` -------------------------------- ### Rust Deprecated Attribute Example Source: https://github.com/avianphysics/avian/blob/main/migration-guides/README.md Demonstrates the usage of the `#[deprecated]` attribute in Rust to mark code as obsolete. This attribute downgrades errors to warnings and provides migration information in IDEs. ```rust #[deprecated(since = "0.4.0", note = "This message will appear in the deprecation warning.")] struct MyStruct; ``` -------------------------------- ### Calculate Stiffness and Damping from Frequency and Damping Ratio Source: https://github.com/avianphysics/avian/blob/main/src/dynamics/solver/softness_parameters/README.md These formulas demonstrate how to derive stiffness and damping coefficients using effective mass, frequency (omega), and damping ratio (zeta). ```rust let stiffness = effective_mass * omega * omega; let damping = 2.0 * effective_mass * zeta * omega; ``` -------------------------------- ### Run specific benchmark configuration Source: https://github.com/avianphysics/avian/blob/main/benches/README.md Executes the 'Large Pyramid 2D' benchmark with a specified thread range, step count, and repetition count. ```shell # Note: Make sure `benches` is the active working directory cargo run -- --name "Large Pyramid 2D" --threads 1..=6 --steps 500 --repeat 5 ``` -------------------------------- ### Calculate CFM and ERP from Stiffness and Damping Source: https://github.com/avianphysics/avian/blob/main/src/dynamics/solver/softness_parameters/README.md These formulas show how to compute CFM and ERP based on stiffness and damping values, which are common in physics simulations. ```rust let cfm = 1.0 / (delta_time * stiffness + damping); let erp = (delta_time * stiffness) / (delta_time * stiffness + damping); ``` -------------------------------- ### Add Avian Physics Dependency Source: https://github.com/avianphysics/avian/blob/main/README.md Add this to your Cargo.toml to use the latest version from the main branch. ```toml [dependencies] avian3d = { git = "https://github.com/avianphysics/avian", branch = "main" } ``` -------------------------------- ### Calculate Soft Constraint Parameters Source: https://github.com/avianphysics/avian/blob/main/src/dynamics/solver/softness_parameters/README.md Calculates coefficients for soft constraints based on damping ratio, frequency, and time step. These parameters are used to tune the stability and response of constraints. ```rust let zeta = 1.0; // Damping ratio (controls the amount of oscillation) let hertz = 5.0; // Frequency (cycles per second) let omega = 2.0 * PI * hertz; // Angular frequency (controls the rate of oscillation) // Shared expressions let a1 = 2.0 * zeta + omega * delta_time; let a2 = omega * delta_time * a1; let a3 = 1.0 / (1.0 + a2); // Coefficients let bias_coefficient = omega / a1; let mass_coefficient = a2 * a3; let impulse_coefficient = a3; ``` -------------------------------- ### Migrating Collision Event Handling Source: https://github.com/avianphysics/avian/blob/main/migration-guides/README.md Demonstrates the transition from version 0.3 to 0.4 for collision event readers, highlighting the change from EventReader to MessageReader and the updated event structure. ```rust // 0.3 fn print_started_collisions(mut collision_reader: EventReader) { for CollisionStarted(collider1, collider2) in collision_reader.read() { println!("{collider1} and {collider2} started colliding"); } } // 0.4 fn print_started_collisions(mut collision_reader: MessageReader) { // Note: The event now also stores `body1` and `body2` for event in collision_reader.read() { println!("{} and {} started colliding", event.collider1, event.collider2); } } ``` -------------------------------- ### Run benchmarks by dimension Source: https://github.com/avianphysics/avian/blob/main/benches/README.md Executes benchmarks filtered by 2D or 3D features using cargo flags. ```shell # List all 2D benchmarks cargo run --no-default-features --features 2d -- --list # Run all 3D benchmarks with default options cargo run --no-default-features --features 3d ``` -------------------------------- ### Add Avian3D Dependency Source: https://github.com/avianphysics/avian/blob/main/README.md Add the avian3d crate to your Cargo.toml file for 3D applications. ```toml # For 3D applications: [dependencies] avian3d = "0.6" ``` -------------------------------- ### Add Avian2D Dependency Source: https://github.com/avianphysics/avian/blob/main/README.md Add the avian2d crate to your Cargo.toml file for 2D applications. ```toml # For 2D applications: [dependencies] avian2d = "0.6" ``` -------------------------------- ### Compute Contact Impulse with Soft Constraints Source: https://github.com/avianphysics/avian/blob/main/src/dynamics/solver/softness_parameters/README.md Calculates the incremental impulse for a contact constraint using soft constraints. This method incorporates softness parameters for stable and controlled response. ```rust let biased_normal_speed = normal_speed + bias_coefficient * separation; let scaled_effective_mass = mass_coefficient * effective_mass; let extra_impulse = impulse_coefficient * accumulated_impulse; let incremental_impulse = -scaled_effective_mass * biased_normal_speed - extra_impulse; ``` -------------------------------- ### Compute Contact Impulse (PGS) Source: https://github.com/avianphysics/avian/blob/main/src/dynamics/solver/softness_parameters/README.md Calculates the incremental impulse for a contact constraint using Projected Gauss-Seidel (PGS) without stabilization. This is a baseline for impulse calculation. ```rust let incremental_impulse = -effective_mass * normal_speed; ``` -------------------------------- ### Define RigidBodyForces Traits Source: https://github.com/avianphysics/avian/blob/main/migration-guides/0.5-to-0.6.md Defines `ReadRigidBodyForces` and `WriteRigidBodyForces` traits, with `RigidBodyForces` combining both. Use these traits if your implementation of `RigidBodyForces` needs adjustments. ```rust pub trait RigidBodyForces: ReadRigidBodyForces + WriteRigidBodyForces {} ``` -------------------------------- ### Compute Contact Impulse with Baumgarte Stabilization Source: https://github.com/avianphysics/avian/blob/main/src/dynamics/solver/softness_parameters/README.md Calculates the incremental impulse for a contact constraint with Baumgarte stabilization. An additional bias term is added to correct for penetration depth. ```rust let bias = bias_factor / delta_time * penetration_depth.max(0.0); let incremental_impulse = -effective_mass * (normal_speed + bias); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.