Skip to content

Conversation

@ThierryBerger
Copy link
Contributor

@ThierryBerger ThierryBerger commented Mar 8, 2025

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:

Comment on lines +25 to +28
device: RenderDevice,
app_state: &mut AppState,
_callbacks: &mut Callbacks,
) -> PhysicsContext {
Copy link
Contributor Author

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 🤔

Comment on lines +80 to +109
// 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);
Copy link
Contributor Author

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
Copy link
Contributor Author

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)

@ThierryBerger ThierryBerger marked this pull request as ready for review March 19, 2025 08:36
Comment on lines +1 to +5
# Notes

banana example:

- oneway+dynamic coupling makes the knife going places (bouncing weirdly).
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to remove

@ThierryBerger ThierryBerger changed the title Sample color model Banana example Apr 4, 2025
@ThierryBerger ThierryBerger requested a review from sebcrozet April 7, 2025 07:22
@sebcrozet sebcrozet deleted the branch dimforge:cpic April 7, 2025 17:12
@sebcrozet sebcrozet closed this Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants