1
1
use bevy:: prelude:: * ;
2
2
use bevy:: render:: renderer:: RenderDevice ;
3
+ use bevy_editor_cam:: DefaultEditorCamPlugins ;
4
+ use bevy_editor_cam:: prelude:: EditorCam ;
3
5
use bevy_rapier3d:: geometry:: RapierColliderHandle ;
4
6
use bevy_rapier3d:: plugin:: ReadRapierContext ;
5
7
use bevy_rapier3d:: prelude:: { Collider , RigidBody } ;
@@ -9,6 +11,7 @@ use bevy_wgsparkl::resources::{AppState, PhysicsContext};
9
11
use nalgebra:: { Vector3 , vector} ;
10
12
use wgrapier3d:: dynamics:: body:: { BodyCoupling , BodyCouplingEntry } ;
11
13
use wgsparkl3d:: models:: DruckerPrager ;
14
+ use wgsparkl3d:: solver:: ParticlePhase ;
12
15
use wgsparkl3d:: {
13
16
models:: ElasticCoefficients ,
14
17
pipeline:: MpmData ,
@@ -17,7 +20,7 @@ use wgsparkl3d::{
17
20
18
21
pub fn main ( ) {
19
22
App :: new ( )
20
- . add_plugins ( DefaultPlugins )
23
+ . add_plugins ( ( DefaultPlugins , DefaultEditorCamPlugins ) )
21
24
. add_plugins ( bevy_rapier3d:: plugin:: RapierPhysicsPlugin :: < ( ) > :: default ( ) )
22
25
. add_plugins ( RapierDebugRenderPlugin :: default ( ) )
23
26
. add_plugins ( bevy_wgsparkl:: WgSparklPlugin )
@@ -28,13 +31,17 @@ pub fn main() {
28
31
pub fn setup_scene ( mut commands : Commands ) {
29
32
commands. spawn ( (
30
33
Camera3d :: default ( ) ,
34
+ EditorCam {
35
+ last_anchor_depth : 110f64 ,
36
+ ..Default :: default ( )
37
+ } ,
31
38
Transform :: from_xyz ( -30.0 , 30.0 , 100.0 ) . looking_at ( Vec3 :: new ( 0.0 , 10.0 , 0.0 ) , Vec3 :: Y ) ,
32
39
) ) ;
33
40
/*
34
41
* Ground
35
42
*/
36
43
let ground_size = 200.1 ;
37
- let ground_height = 0.1 ;
44
+ let ground_height = 2.0 ;
38
45
39
46
commands. spawn ( (
40
47
Transform :: from_xyz ( 0.0 , -ground_height, 0.0 ) ,
@@ -68,10 +75,9 @@ pub fn setup_mpm_particles(
68
75
let grid_size_x = 25 ;
69
76
let grid_size_y = 25 ;
70
77
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;
72
79
73
- let rocks = ( 0 ..num_rocks)
74
- . into_iter ( )
80
+ let particle_positions = ( 0 ..num_particles)
75
81
. map ( |i| {
76
82
let x = i % grid_size_x;
77
83
let y = ( i / grid_size_x) % grid_size_y;
@@ -103,7 +109,7 @@ pub fn setup_mpm_particles(
103
109
let device = device. wgpu_device ( ) ;
104
110
105
111
if !app_state. restarting {
106
- app_state. num_substeps = 32 ;
112
+ app_state. num_substeps = 8 ;
107
113
app_state. gravity_factor = 1.0 ;
108
114
} ;
109
115
@@ -112,30 +118,49 @@ pub fn setup_mpm_particles(
112
118
dt : ( 1.0 / 60.0 ) / ( app_state. num_substeps as f32 ) ,
113
119
} ;
114
120
115
- let cell_width = 0.5 ;
121
+ let cell_width = 1.0 ;
116
122
let mut particles = vec ! [ ] ;
117
123
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
+ }
139
164
}
140
165
141
166
println ! ( "Number of simulated particles: {}" , particles. len( ) ) ;
0 commit comments