Mutating mesh data
Opened this issue · 0 comments
medakk commented
What is the correct way to mutate Mesh coords/faces?
Currently, I have:
use kiss3d::resource::Mesh;
pub struct ClothViz {
mesh: Rc<RefCell<Mesh>>,
}
And a function where I update it:
pub fn update(&mut self, hookean: &HookeanSurface) {
let xs = hookean.x(); // This is just a na::DMatrix<f32>
// Update mesh
let mesh = self.mesh.borrow();
let mut coords = mesh.coords().write().unwrap();
if let Some(data) = coords.data_mut() {
for (i, p) in data.iter_mut().enumerate() {
let row = xs.row(i);
for j in 0..3 {
p.coords[j] = row[j];
}
}
coords.load_to_gpu();
} else {
panic!("coords not in RAM");
}
}
This works, but I'm wondering what to do if the vertices are not in RAM. I found a load_to_ram
function in kiss3d's source code but its commented out.
(Unrelated here: but I also couldn't figure out a way to copy from my DMatrix to the Vec of Point3s without for loops)