-
Notifications
You must be signed in to change notification settings - Fork 2
Banana example #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
device: RenderDevice, | ||
app_state: &mut AppState, | ||
_callbacks: &mut Callbacks, | ||
) -> PhysicsContext { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
examples function signature was changed to be slightly less bevy-specific, the device is still a bevy struct ; and the other parameters implement resource though 🤔
// NOTE: Heightfield may be more efficient or more predictable than trimesh for the knife. | ||
let heights = nalgebra::DMatrix::zeros(10, 5); | ||
let heightfield = rapier3d::prelude::HeightField::new(heights, vector![2.0, 1.0, 10.0]); | ||
let (mut vtx, idx) = heightfield.to_trimesh(); | ||
vtx.iter_mut().for_each(|pt| { | ||
*pt = Isometry3::rotation(vector![0f32, 0f32, -90f32.to_radians()]) * *pt | ||
+ vector![0.0, 1f32, 0f32] | ||
}); | ||
let co = ColliderBuilder::trimesh(vtx, idx).unwrap(); | ||
rapier_data | ||
.colliders | ||
.insert_with_parent(co, parent_handle, &mut rapier_data.bodies); | ||
*/ | ||
for (vertices, indices) in slicer_trimeshes.iter() { | ||
// Insert collider into rapier state. | ||
|
||
let collider = ColliderBuilder::new( | ||
SharedShape::trimesh_with_flags( | ||
vertices.clone(), | ||
indices | ||
.chunks_exact(3) | ||
.map(|i| [i[0] as u32, i[1] as u32, i[2] as u32]) | ||
.collect(), | ||
TriMeshFlags::FIX_INTERNAL_EDGES, | ||
) | ||
.unwrap(), | ||
); | ||
rapier_data | ||
.colliders | ||
.insert_with_parent(collider, parent_handle, &mut rapier_data.bodies); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what's the preferred behaviour there, using a model for collision is interesting, using a heightmap will probably be more stable (but it should probably be a quad if we're after simplicity)
let y_pos = 1.3; | ||
let z_pos = -1.5; | ||
let velocity = 0.9; | ||
let extended_width = 0.15; // extended width for the horizontal move to the right |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to keep the code similar to the taichi implementation, with adapted values above to fit the models used.
I added "extended_width" to have additional room for the banana slices to split more correctly (otherwise they have a tendency to stick together)
49a074a
to
c7fe2b3
Compare
# Notes | ||
|
||
banana example: | ||
|
||
- oneway+dynamic coupling makes the knife going places (bouncing weirdly). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to remove
Adds an example based on taichi mpm demo, cutting a banana ; it also features a particle coloring based on closest vertex's color
Screencast.from.03-11-2025.03_52_13.PM.mp4
Screencast.from.03-12-2025.01_04_04.PM.mp4
other PRs are based on this one: