Skip to content
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

Sample color model #6

Open
wants to merge 25 commits into
base: cpic
Choose a base branch
from
Open

Conversation

Vrixyz
Copy link
Contributor

@Vrixyz Vrixyz commented Mar 8, 2025

Based on #5 ; an interesting improvement to demos would be to sample material textures to apply a relevant color to each particle.

Screencast.from.03-11-2025.03_52_13.PM.mp4
Screencast.from.03-12-2025.01_04_04.PM.mp4

@Vrixyz Vrixyz mentioned this pull request Mar 18, 2025
Comment on lines +3 to +8
# cargo build -p wgsparkl-examples-2d --release --target wasm32-unknown-unknown
cargo build -p wgsparkl-examples-3d --release --target wasm32-unknown-unknown
# wasm-bindgen --no-typescript --target web --out-dir dist2d --out-name wgsparkl-examples-2d ./target/wasm32-unknown-unknown/release/wgsparkl-examples-2d.wasm
wasm-bindgen --no-typescript --target web --out-dir dist3d --out-name wgsparkl-examples-3d ./target/wasm32-unknown-unknown/release/wgsparkl-examples-3d.wasm
# wasm-opt -Oz -o ./dist2d/opt.wasm ./dist2d/wgsparkl-examples-2d_bg.wasm && mv ./dist2d/opt.wasm ./dist2d/wgsparkl-examples-2d_bg.wasm
wasm-opt -Oz -o ./dist3d/opt.wasm ./dist3d/wgsparkl-examples-3d_bg.wasm && mv ./dist3d/opt.wasm ./dist3d/wgsparkl-examples-3d_bg.wasm
Copy link
Contributor Author

Choose a reason for hiding this comment

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

2d examples seem broken on cpic branch?

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)

@Vrixyz Vrixyz force-pushed the sample_color_model branch from 49a074a to c7fe2b3 Compare March 18, 2025 09:20
@Vrixyz Vrixyz 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

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.

1 participant