forked from dimforge/wgsparkl
-
Notifications
You must be signed in to change notification settings - Fork 0
Color particles depending on text #4
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
Open
Vrixyz
wants to merge
2
commits into
sample_color_model
Choose a base branch
from
text_to_collider_new
base: sample_color_model
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Vrixyz
commented
Apr 10, 2025
Comment on lines
+159
to
+195
pub mod read_particles { | ||
use super::*; | ||
|
||
use bevy::render::{render_resource::BufferUsages, renderer::RenderQueue}; | ||
use nalgebra::Vector4; | ||
use wgcore::tensor::GpuVector; | ||
use wgsparkl3d::solver::GpuParticles; | ||
|
||
pub fn read_particles_positions( | ||
render_device: RenderDevice, | ||
render_queue: RenderQueue, | ||
particles: &GpuParticles, | ||
) -> Vec<Vector4<f32>> { | ||
// Get the `render_device` is the `Res<RenderDevice>` bevy resource. | ||
let device = render_device.wgpu_device(); | ||
// Create the staging buffer. | ||
// Here `particles` is of type `GpuParticles`, accessible from | ||
// `PhysicsContext::data::particles`. | ||
let positions_staging: GpuVector<Vector4<f32>> = GpuVector::uninit( | ||
device, | ||
particles.len() as u32, | ||
BufferUsages::COPY_DST | BufferUsages::MAP_READ, | ||
); | ||
|
||
// Copy the buffer. | ||
// `render_queue` the `Res<RenderQueue>` bevy resource. | ||
let compute_queue = &*render_queue.0; | ||
let mut encoder = device.create_command_encoder(&Default::default()); | ||
positions_staging.copy_from(&mut encoder, &particles.positions); | ||
compute_queue.submit(Some(encoder.finish())); | ||
|
||
// Run the copy. The fourth component of each entry can be ignored. | ||
let positions: Vec<Vector4<f32>> = | ||
futures::executor::block_on(positions_staging.read(device)).unwrap(); | ||
positions | ||
} | ||
} |
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.
This would be useful as part of the main library.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This allows to have neat-looking demos disclosing a word: