-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathelastic_cut2.rs
127 lines (114 loc) · 3.65 KB
/
elastic_cut2.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use wgsparkl_testbed2d::{wgsparkl, RapierData};
use bevy::prelude::*;
use bevy::render::renderer::RenderDevice;
use nalgebra::{point, vector, Similarity2, Vector2};
use rapier2d::prelude::{ColliderBuilder, RigidBodyBuilder};
use wgebra::GpuSim2;
use wgparry2d::parry::shape::Cuboid;
use wgrapier2d::dynamics::{BodyDesc, GpuVelocity};
use wgsparkl::models::DruckerPrager;
use wgsparkl::solver::ParticlePhase;
use wgsparkl::{
models::ElasticCoefficients,
pipeline::MpmData,
solver::{Particle, SimulationParams},
};
use wgsparkl2d::solver::ParticleDynamics;
use wgsparkl_testbed2d::{init_testbed, AppState, PhysicsContext, SceneInits};
fn main() {
panic!("Run the `testbed3` example instead.");
}
pub fn elastic_cut_demo(
device: RenderDevice,
app_state: &mut AppState,
_callbacks: &mut Callbacks,
) -> PhysicsContext {
let mut rapier_data = RapierData::default();
let device = device.wgpu_device();
let offset_y = 46.0;
// let cell_width = 0.1;
let cell_width = 0.2;
let mut particles = vec![];
for i in 0..700 {
for j in 0..700 {
let position = vector![i as f32 + 0.5, j as f32 + 0.5] * cell_width / 2.0
+ Vector2::y() * offset_y;
let density = 1000.0;
let radius = cell_width / 4.0;
particles.push(Particle {
position,
dynamics: ParticleDynamics::with_density(radius, density),
model: ElasticCoefficients::from_young_modulus(5_000_000.0, 0.2),
plasticity: None,
phase: Some(ParticlePhase {
phase: 1.0,
max_stretch: f32::MAX,
}),
color: None,
});
}
}
if !app_state.restarting {
app_state.num_substeps = 15;
app_state.gravity_factor = 1.0;
};
let params = SimulationParams {
gravity: vector![0.0, -9.81] * app_state.gravity_factor,
dt: (1.0 / 60.0) / (app_state.num_substeps as f32),
padding: 0.0,
};
const ANGVEL: f32 = 1.0; // 2.0;
/*
* Static platforms.
*/
let rb = RigidBodyBuilder::fixed().translation(vector![35.0, 20.0]);
let rb_handle = rapier_data.bodies.insert(rb);
let co = ColliderBuilder::cuboid(70.0, 1.0);
rapier_data
.colliders
.insert_with_parent(co, rb_handle, &mut rapier_data.bodies);
let mut polyline = vec![];
let subdivs = 100;
let length = 84.0;
let start = point![35.0, 70.0] - vector![length / 2.0, 0.0];
for i in 0..=subdivs {
let step = length / (subdivs as f32);
let dx = i as f32 * step;
polyline.push(start + vector![dx, dx.sin()])
}
let rb = RigidBodyBuilder::fixed();
let rb_handle = rapier_data.bodies.insert(rb);
let co = ColliderBuilder::polyline(polyline, None).build();
rapier_data
.colliders
.insert_with_parent(co, rb_handle, &mut rapier_data.bodies);
for k in 0..6 {
let rb = RigidBodyBuilder::fixed();
let rb_handle = rapier_data.bodies.insert(rb);
let co = ColliderBuilder::polyline(
vec![
point![0.0 + k as f32 * 15.0, 20.0],
point![-10.0 + k as f32 * 15.0, 45.0],
],
None,
)
.build();
rapier_data
.colliders
.insert_with_parent(co, rb_handle, &mut rapier_data.bodies);
}
let data = MpmData::new(
device,
params,
&particles,
&rapier_data.bodies,
&rapier_data.colliders,
cell_width,
60_000,
);
PhysicsContext {
data,
rapier_data,
particles,
}
}