11use bevy:: prelude:: * ;
22use bevy:: render:: renderer:: RenderDevice ;
3+ use bevy_editor_cam:: DefaultEditorCamPlugins ;
4+ use bevy_editor_cam:: prelude:: EditorCam ;
35use bevy_rapier3d:: geometry:: RapierColliderHandle ;
46use bevy_rapier3d:: plugin:: ReadRapierContext ;
57use bevy_rapier3d:: prelude:: { Collider , RigidBody } ;
@@ -9,6 +11,7 @@ use bevy_wgsparkl::resources::{AppState, PhysicsContext};
911use nalgebra:: { Vector3 , vector} ;
1012use wgrapier3d:: dynamics:: body:: { BodyCoupling , BodyCouplingEntry } ;
1113use wgsparkl3d:: models:: DruckerPrager ;
14+ use wgsparkl3d:: solver:: ParticlePhase ;
1215use wgsparkl3d:: {
1316 models:: ElasticCoefficients ,
1417 pipeline:: MpmData ,
@@ -17,7 +20,7 @@ use wgsparkl3d::{
1720
1821pub fn main ( ) {
1922 App :: new ( )
20- . add_plugins ( DefaultPlugins )
23+ . add_plugins ( ( DefaultPlugins , DefaultEditorCamPlugins ) )
2124 . add_plugins ( bevy_rapier3d:: plugin:: RapierPhysicsPlugin :: < ( ) > :: default ( ) )
2225 . add_plugins ( RapierDebugRenderPlugin :: default ( ) )
2326 . add_plugins ( bevy_wgsparkl:: WgSparklPlugin )
@@ -28,13 +31,17 @@ pub fn main() {
2831pub fn setup_scene ( mut commands : Commands ) {
2932 commands. spawn ( (
3033 Camera3d :: default ( ) ,
34+ EditorCam {
35+ last_anchor_depth : 110f64 ,
36+ ..Default :: default ( )
37+ } ,
3138 Transform :: from_xyz ( -30.0 , 30.0 , 100.0 ) . looking_at ( Vec3 :: new ( 0.0 , 10.0 , 0.0 ) , Vec3 :: Y ) ,
3239 ) ) ;
3340 /*
3441 * Ground
3542 */
3643 let ground_size = 200.1 ;
37- let ground_height = 0.1 ;
44+ let ground_height = 2.0 ;
3845
3946 commands. spawn ( (
4047 Transform :: from_xyz ( 0.0 , -ground_height, 0.0 ) ,
@@ -68,10 +75,9 @@ pub fn setup_mpm_particles(
6875 let grid_size_x = 25 ;
6976 let grid_size_y = 25 ;
7077 let grid_size_z = 25 ;
71- let num_rocks = grid_size_x * grid_size_y * grid_size_z;
78+ let num_particles = grid_size_x * grid_size_y * grid_size_z;
7279
73- let rocks = ( 0 ..num_rocks)
74- . into_iter ( )
80+ let particle_positions = ( 0 ..num_particles)
7581 . map ( |i| {
7682 let x = i % grid_size_x;
7783 let y = ( i / grid_size_x) % grid_size_y;
@@ -103,7 +109,7 @@ pub fn setup_mpm_particles(
103109 let device = device. wgpu_device ( ) ;
104110
105111 if !app_state. restarting {
106- app_state. num_substeps = 32 ;
112+ app_state. num_substeps = 8 ;
107113 app_state. gravity_factor = 1.0 ;
108114 } ;
109115
@@ -112,30 +118,49 @@ pub fn setup_mpm_particles(
112118 dt : ( 1.0 / 60.0 ) / ( app_state. num_substeps as f32 ) ,
113119 } ;
114120
115- let cell_width = 0.5 ;
121+ let cell_width = 1.0 ;
116122 let mut particles = vec ! [ ] ;
117123
118- for rock in & rocks {
119- let position = vector ! [ rock. x, rock. y, rock. z] ;
120-
121- let rock_size = vector ! [ 1.0 , 1.0 , 1.0 ] ;
122- let volume = rock_size. x * rock_size. y * rock_size. z ;
123- let density = 2700.0 ;
124- particles. push ( Particle {
125- position : vector ! [ position. x, position. y, position. z] ,
126- velocity : Vector3 :: zeros ( ) ,
127- volume : ParticleMassProps :: new ( density * volume, volume. cbrt ( ) / 2.0 ) ,
128- model : ElasticCoefficients :: from_young_modulus ( 10_000_000.0 , 0.2 ) ,
129- plasticity : Some ( DruckerPrager {
130- // TODO: tune these values.
131- h0 : 45.0f32 . to_radians ( ) ,
132- h1 : 50.0f32 . to_radians ( ) ,
133- h2 : 0.4 ,
134- h3 : 15.0f32 . to_radians ( ) ,
135- ..DruckerPrager :: new ( 10_000_000.0 , 0.2 )
136- } ) ,
137- phase : None ,
138- } ) ;
124+ for x in -1 ..2 {
125+ for z in -1 ..2 {
126+ let x = x as f32 ;
127+ let z = z as f32 ;
128+ let offset = vector ! [ x * grid_size_x as f32 , 0f32 , z * grid_size_z as f32 ] * 2f32 ;
129+ for particle in & particle_positions {
130+ let position = vector ! [ particle. x, particle. y, particle. z] ;
131+
132+ let particle_size = vector ! [ 1.0 , 1.0 , 1.0 ] ;
133+ let volume = particle_size. x * particle_size. y * particle_size. z ;
134+ let density = 1700.0 ;
135+ particles. push ( Particle {
136+ position : nalgebra:: Rotation :: from_axis_angle (
137+ & Vector3 :: z_axis ( ) ,
138+ 5f32 . to_radians ( ) ,
139+ ) * vector ! [ position. x, position. y, position. z]
140+ + offset,
141+ velocity : Vector3 :: zeros ( ) ,
142+ volume : ParticleMassProps :: new ( density * volume, volume. cbrt ( ) / 2.0 ) ,
143+ model : ElasticCoefficients :: from_young_modulus (
144+ 100_000_000.0 * 10f32 . powf ( z - 1f32 ) ,
145+ 0.2 + x * 0.05f32 ,
146+ ) ,
147+ plasticity : Some ( DruckerPrager {
148+ h0 : ( 45.0f32 + x * 20f32 ) . to_radians ( ) ,
149+ h1 : ( 70.0f32 + x * 20f32 ) . to_radians ( ) + z,
150+ h2 : 1.6 + z * 0.5f32 ,
151+ h3 : 25.0f32 . to_radians ( ) + x,
152+ ..DruckerPrager :: new (
153+ 100_000_000.0 * 10f32 . powf ( z - 1f32 ) ,
154+ 0.2 + x * 0.05f32 ,
155+ )
156+ } ) ,
157+ phase : Some ( ParticlePhase {
158+ phase : 0.5 + 0.5 * x,
159+ max_stretch : ( 0.0 + z) . clamp ( 0.0 , 1.0 ) ,
160+ } ) ,
161+ } ) ;
162+ }
163+ }
139164 }
140165
141166 println ! ( "Number of simulated particles: {}" , particles. len( ) ) ;
0 commit comments