Skip to content

Commit 848cd9b

Browse files
committed
alpha.4 fixes
1 parent 1c3a88a commit 848cd9b

6 files changed

Lines changed: 41 additions & 7 deletions

File tree

‎Cargo.lock‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "processing"
3-
version = "0.0.9-alpha.4"
3+
version = "0.0.9-alpha.5"
44
edition = "2024"
55
autoexamples = false
66

‎crates/processing_pyo3/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "processing_pyo3"
3-
version = "0.0.9-alpha.4"
3+
version = "0.0.9-alpha.5"
44
edition = "2024"
55

66
[lints]

‎crates/processing_pyo3/src/lib.rs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,6 +1300,7 @@ pub mod mewnala {
13001300
.end_draw()?;
13011301

13021302
loop {
1303+
py.check_signals()?;
13031304
{
13041305
let mut graphics = get_graphics_mut(module)?
13051306
.ok_or_else(|| PyRuntimeError::new_err("call size() first"))?;
@@ -1320,6 +1321,8 @@ pub mod mewnala {
13201321
let mut first_frame = true;
13211322

13221323
loop {
1324+
// also catches Ctrl-C while paused, when no Python code runs
1325+
py.check_signals()?;
13231326
{
13241327
let mut graphics = get_graphics_mut(module)?
13251328
.ok_or_else(|| PyRuntimeError::new_err("call size() first"))?;
@@ -1390,6 +1393,17 @@ pub mod mewnala {
13901393
}
13911394

13921395
Ok(())
1396+
})
1397+
.or_else(|e: PyErr| {
1398+
// Ctrl-C quits the sketch like closing its window, rather than a
1399+
// traceback from wherever draw() happened to be
1400+
Python::attach(|py| {
1401+
if e.is_instance_of::<pyo3::exceptions::PyKeyboardInterrupt>(py) {
1402+
Ok(())
1403+
} else {
1404+
Err(e)
1405+
}
1406+
})
13931407
});
13941408

13951409
// tear down the app while the thread-local is still alive; the eager

‎crates/processing_pyo3/src/particles.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,8 @@ impl Particles {
10011001
for (key, value) in kwargs.iter() {
10021002
let name: String = key.extract()?;
10031003
let attr_entity = self.resolve_attribute(&key)?;
1004+
particles_ensure_attribute(self.entity, attr_entity)
1005+
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
10041006
let (_, fmt) = geometry_attribute_info(attr_entity)
10051007
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
10061008
let fmt = AttributeFormat::from_inner(fmt);

‎crates/processing_render/src/particles/mod.rs‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ pub struct Particles {
100100
/// Ring-buffer write cursor; wraps at `capacity`.
101101
pub emit_head: u32,
102102
pub neighbor_lists: Option<NeighborLists>,
103+
/// The mesh a system made from a `Geometry` came from. Attributes created
104+
/// later start from its data when it has them, so only what's used is copied.
105+
pub source_mesh: Option<Handle<Mesh>>,
103106
}
104107

105108
/// The `neighbors` (up to `max` indices per particle) and `neighbor_count` attributes.
@@ -163,6 +166,7 @@ pub fn create(
163166
connectivity: None,
164167
emit_head: 0,
165168
neighbor_lists: None,
169+
source_mesh: None,
166170
})
167171
.id();
168172
Ok(entity)
@@ -245,6 +249,7 @@ pub fn create_from_geometry(
245249
connectivity,
246250
emit_head: 0,
247251
neighbor_lists: None,
252+
source_mesh: Some(geom.handle.clone()),
248253
})
249254
.id();
250255
Ok(entity)
@@ -434,6 +439,7 @@ pub fn materialize_attribute(
434439
mut commands: Commands,
435440
mut particles_q: Query<&mut Particles>,
436441
attributes: Query<&Attribute>,
442+
meshes: Res<Assets<Mesh>>,
437443
mut shader_buffers: ResMut<Assets<ShaderBuffer>>,
438444
render_device: Res<RenderDevice>,
439445
) -> Result<Entity> {
@@ -442,7 +448,7 @@ pub fn materialize_attribute(
442448
.map_err(|_| ProcessingError::InvalidEntity)?
443449
.clone();
444450

445-
let capacity = {
451+
let (capacity, from_mesh) = {
446452
let particles = particles_q
447453
.get(particles_entity)
448454
.map_err(|_| ProcessingError::ParticlesNotFound)?;
@@ -477,7 +483,15 @@ pub fn materialize_attribute(
477483
))),
478484
};
479485
}
480-
particles.capacity as usize
486+
let capacity = particles.capacity as usize;
487+
let from_mesh = particles
488+
.source_mesh
489+
.as_ref()
490+
.and_then(|handle| meshes.get(handle))
491+
.and_then(|mesh| mesh.attribute(attr.inner))
492+
.and_then(|values| attribute_values_to_bytes(values, attr.format))
493+
.filter(|bytes| bytes.len() == capacity * attr.format.byte_size());
494+
(capacity, from_mesh)
481495
};
482496

483497
let elem_size = attr.format.byte_size();
@@ -506,7 +520,11 @@ pub fn materialize_attribute(
506520
}
507521
};
508522

509-
let initial = tile_seed(&per_element, capacity);
523+
// an explicit default wins over the mesh's data
524+
let initial = match (&seed, from_mesh) {
525+
(AttributeSeed::Declare(Some(_)), _) | (_, None) => tile_seed(&per_element, capacity),
526+
(_, Some(bytes)) => bytes,
527+
};
510528
let buffer_entity = make_buffer(&mut commands, &mut shader_buffers, &render_device, &initial);
511529
particles_q
512530
.get_mut(particles_entity)

0 commit comments

Comments
 (0)