Skip to content

Commit f8a5b04

Browse files
committed
add beginGeometry
1 parent d10b610 commit f8a5b04

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

crates/processing_pyo3/src/graphics.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,11 @@ impl Graphics {
308308
graphics_ortho(self.entity, left, right, bottom, top, near, far)
309309
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
310310
}
311+
312+
pub fn begin_geometry(&self) -> PyResult<()> {
313+
geometry_begin(self.entity)
314+
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
315+
}
311316
}
312317

313318
// TODO: a real color type. or color parser? idk. color is confusing. let's think

crates/processing_pyo3/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ fn processing(m: &Bound<'_, PyModule>) -> PyResult<()> {
4040
m.add_function(wrap_pyfunction!(rect, m)?)?;
4141
m.add_function(wrap_pyfunction!(image, m)?)?;
4242
m.add_function(wrap_pyfunction!(draw_geometry, m)?)?;
43-
43+
m.add_function(wrap_pyfunction!(begin_geometry, m)?)?;
44+
4445
Ok(())
4546
}
4647

@@ -223,3 +224,9 @@ fn rect(
223224
fn image(module: &Bound<'_, PyModule>, image_file: &str) -> PyResult<Image> {
224225
get_graphics(module)?.image(image_file)
225226
}
227+
228+
#[pyfunction]
229+
#[pyo3(pass_module)]
230+
fn begin_geometry(module: &Bound<'_, PyModule>) -> PyResult<()> {
231+
get_graphics(module)?.begin_geometry()
232+
}

crates/processing_render/src/geometry/mod.rs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use bevy::{
1616
render::render_resource::PrimitiveTopology,
1717
};
1818

19-
use crate::error::{ProcessingError, Result};
19+
use crate::{error::{ProcessingError, Result}, render::RenderState};
2020

2121
pub struct GeometryPlugin;
2222

@@ -365,3 +365,33 @@ pub fn destroy(
365365
commands.entity(entity).despawn();
366366
Ok(())
367367
}
368+
369+
pub fn begin(
370+
In(graphics_entity): In<Entity>,
371+
mut commands: Commands,
372+
mut state_query: Query<&mut RenderState>,
373+
mut meshes: ResMut<Assets<Mesh>>,
374+
builtins: Res<BuiltinAttributes>,
375+
) -> Result<()> {
376+
let layout_entity = commands
377+
.spawn(VertexLayout::with_attributes(vec![
378+
builtins.position,
379+
builtins.normal,
380+
builtins.color,
381+
builtins.uv,
382+
]))
383+
.id();
384+
385+
let mesh = Mesh::new(
386+
Topology::TriangleList.to_primitive_topology(),
387+
RenderAssetUsages::default(),
388+
);
389+
let handle = meshes.add(mesh);
390+
391+
let mut state = state_query
392+
.get_mut(graphics_entity)
393+
.map_err(|_| ProcessingError::GraphicsNotFound)?;
394+
395+
state.running_geometry = Some(Geometry::new(handle, layout_entity));
396+
Ok(())
397+
}

crates/processing_render/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,3 +1071,12 @@ pub fn geometry_box(width: f32, height: f32, depth: f32) -> error::Result<Entity
10711071
.unwrap())
10721072
})
10731073
}
1074+
1075+
pub fn geometry_begin(graphics_entity: Entity) -> error::Result<()> {
1076+
app_mut(|app| {
1077+
app
1078+
.world_mut()
1079+
.run_system_cached_with(geometry::begin, graphics_entity)
1080+
.unwrap()
1081+
})
1082+
}

0 commit comments

Comments
 (0)