Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/processing_core/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ pub const TOP: &str = "top"; // vertical text align
pub const BOTTOM: &str = "bottom";
pub const BASELINE: &str = "baseline";

pub const NORMAL: &str = "normal"; // text style
pub const NORMAL: &str = "normal"; // text style, texture mode
pub const IMAGE: &str = "image"; // texture mode
pub const ITALIC: &str = "italic";
pub const BOLD: &str = "bold";
pub const BOLD_ITALIC: &str = "bold_italic";
Expand Down
31 changes: 22 additions & 9 deletions crates/processing_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1041,7 +1041,15 @@ pub extern "C" fn processing_end_shape(graphics_id: u64, close: bool) {
pub extern "C" fn processing_vertex(graphics_id: u64, x: f32, y: f32) {
error::clear_error();
let graphics_entity = Entity::from_bits(graphics_id);
error::check(|| graphics_record_command(graphics_entity, DrawCommand::ShapeVertex { x, y }));
error::check(|| {
graphics_record_command(
graphics_entity,
DrawCommand::ShapeVertex {
position: Vec3::new(x, y, 0.0),
uv: None,
},
)
});
}

/// Add a cubic bezier vertex to the current shape.
Expand All @@ -1061,12 +1069,9 @@ pub extern "C" fn processing_bezier_vertex(
graphics_record_command(
graphics_entity,
DrawCommand::ShapeBezierVertex {
cx1,
cy1,
cx2,
cy2,
x,
y,
c1: Vec3::new(cx1, cy1, 0.0),
c2: Vec3::new(cx2, cy2, 0.0),
to: Vec3::new(x, y, 0.0),
},
)
});
Expand All @@ -1080,7 +1085,10 @@ pub extern "C" fn processing_quadratic_vertex(graphics_id: u64, cx: f32, cy: f32
error::check(|| {
graphics_record_command(
graphics_entity,
DrawCommand::ShapeQuadraticVertex { cx, cy, x, y },
DrawCommand::ShapeQuadraticVertex {
c: Vec3::new(cx, cy, 0.0),
to: Vec3::new(x, y, 0.0),
},
)
});
}
Expand All @@ -1091,7 +1099,12 @@ pub extern "C" fn processing_curve_vertex(graphics_id: u64, x: f32, y: f32) {
error::clear_error();
let graphics_entity = Entity::from_bits(graphics_id);
error::check(|| {
graphics_record_command(graphics_entity, DrawCommand::ShapeCurveVertex { x, y })
graphics_record_command(
graphics_entity,
DrawCommand::ShapeCurveVertex {
to: Vec3::new(x, y, 0.0),
},
)
});
}

Expand Down
22 changes: 8 additions & 14 deletions crates/processing_node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,8 +865,8 @@ pub fn js_vertex(graphics_id: BigInt, x: f64, y: f64) -> Result<()> {
record(
graphics_id,
DrawCommand::ShapeVertex {
x: x as f32,
y: y as f32,
position: vec3(x, y, 0.0),
uv: None,
},
)
}
Expand All @@ -884,12 +884,9 @@ pub fn js_bezier_vertex(
record(
graphics_id,
DrawCommand::ShapeBezierVertex {
cx1: cx1 as f32,
cy1: cy1 as f32,
cx2: cx2 as f32,
cy2: cy2 as f32,
x: x as f32,
y: y as f32,
c1: vec3(cx1, cy1, 0.0),
c2: vec3(cx2, cy2, 0.0),
to: vec3(x, y, 0.0),
},
)
}
Expand All @@ -899,10 +896,8 @@ pub fn js_quadratic_vertex(graphics_id: BigInt, cx: f64, cy: f64, x: f64, y: f64
record(
graphics_id,
DrawCommand::ShapeQuadraticVertex {
cx: cx as f32,
cy: cy as f32,
x: x as f32,
y: y as f32,
c: vec3(cx, cy, 0.0),
to: vec3(x, y, 0.0),
},
)
}
Expand All @@ -912,8 +907,7 @@ pub fn js_curve_vertex(graphics_id: BigInt, x: f64, y: f64) -> Result<()> {
record(
graphics_id,
DrawCommand::ShapeCurveVertex {
x: x as f32,
y: y as f32,
to: vec3(x, y, 0.0),
},
)
}
Expand Down
1 change: 1 addition & 0 deletions crates/processing_pyo3/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub fn register(m: &Bound<'_, PyModule>) -> PyResult<()> {
// text align (LEFT/RIGHT/CENTER above), style, and wrap constants
add!(m, TOP, BOTTOM, BASELINE);
add!(m, NORMAL, ITALIC, BOLD, BOLD_ITALIC);
add!(m, IMAGE);
add!(m, WORD, CHAR);
add!(m, NEAREST, CLAMP, REPEAT, MIRROR);
add!(m, SRGB, LINEAR, HSL, HSV, HWB, OKLAB, OKLCH, LAB, LCH, XYZ);
Expand Down
110 changes: 88 additions & 22 deletions crates/processing_pyo3/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::input;
use crate::math::{Vec3Like, extract_vec2, extract_vec3};
use bevy::{
color::{ColorToPacked, LinearRgba, Srgba},
math::{Affine3A, Mat4, Vec3, Vec4},
math::{Affine3A, Mat4, Vec2, Vec3, Vec4},
prelude::{Entity, Transform},
render::render_resource::{Extent3d, TextureFormat},
};
Expand Down Expand Up @@ -1683,11 +1683,44 @@ impl Graphics {
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}

pub fn vertex(&self, x: f32, y: f32) -> PyResult<()> {
graphics_record_command(self.entity, DrawCommand::ShapeVertex { x, y })
/// `vertex(x, y)`, `vertex(x, y, z)`, `vertex(x, y, u, v)` or `vertex(x, y, z, u, v)`.
#[pyo3(signature = (x, y, *args))]
pub fn vertex(&self, x: f32, y: f32, args: &Bound<'_, PyTuple>) -> PyResult<()> {
let rest: Vec<f32> = args.extract()?;
let (position, uv) = match rest[..] {
[] => (Vec3::new(x, y, 0.0), None),
[z] => (Vec3::new(x, y, z), None),
[u, v] => (Vec3::new(x, y, 0.0), Some(Vec2::new(u, v))),
[z, u, v] => (Vec3::new(x, y, z), Some(Vec2::new(u, v))),
_ => {
return Err(pyo3::exceptions::PyTypeError::new_err(
"vertex() takes x, y or x, y, z, optionally followed by u, v",
));
}
};
graphics_record_command(self.entity, DrawCommand::ShapeVertex { position, uv })
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}

/// The normal of the vertices that follow in the current shape.
#[pyo3(signature = (*args))]
pub fn normal(&self, args: &Bound<'_, PyTuple>) -> PyResult<()> {
let normal = extract_vec3(args)?;
graphics_record_command(self.entity, DrawCommand::ShapeNormal(normal))
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}

/// `IMAGE` reads `vertex()` texture coordinates in pixels of the texture, `NORMAL` from 0 to 1.
pub fn texture_mode(&self, mode: &str) -> PyResult<()> {
let mode = processing::prelude::TextureMode::parse(mode)
.ok_or_else(|| PyValueError::new_err(format!("unknown texture mode: {mode:?}")))?;
graphics_record_command(self.entity, DrawCommand::TextureMode(mode))
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}

/// Two control points and an end point: six numbers, or nine in 3D (`x, y, z` each).
#[pyo3(signature = (cx1, cy1, cx2, cy2, x, y, *args))]
#[allow(clippy::too_many_arguments)]
pub fn bezier_vertex(
&self,
cx1: f32,
Expand All @@ -1696,34 +1729,67 @@ impl Graphics {
cy2: f32,
x: f32,
y: f32,
args: &Bound<'_, PyTuple>,
) -> PyResult<()> {
graphics_record_command(
self.entity,
DrawCommand::ShapeBezierVertex {
cx1,
cy1,
cx2,
cy2,
x,
y,
},
)
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
let rest: Vec<f32> = args.extract()?;
let [c1, c2, to] = match rest[..] {
[] => [
Vec3::new(cx1, cy1, 0.0),
Vec3::new(cx2, cy2, 0.0),
Vec3::new(x, y, 0.0),
],
// nine numbers read as three points
[a, b, c] => [
Vec3::new(cx1, cy1, cx2),
Vec3::new(cy2, x, y),
Vec3::new(a, b, c),
],
_ => {
return Err(pyo3::exceptions::PyTypeError::new_err(
"bezier_vertex() takes 6 numbers, or 9 in 3D",
));
}
};
graphics_record_command(self.entity, DrawCommand::ShapeBezierVertex { c1, c2, to })
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}

/// A control point and an end point: four numbers, or six in 3D (`x, y, z` each).
#[pyo3(signature = (cx, cy, x, y, *args))]
pub fn quadratic_vertex(
&self,
cx: f32,
cy: f32,
x: f32,
y: f32,
args: &Bound<'_, PyTuple>,
) -> PyResult<()> {
let rest: Vec<f32> = args.extract()?;
let [c, to] = match rest[..] {
[] => [Vec3::new(cx, cy, 0.0), Vec3::new(x, y, 0.0)],
// six numbers read as two points
[a, b] => [Vec3::new(cx, cy, x), Vec3::new(y, a, b)],
_ => {
return Err(pyo3::exceptions::PyTypeError::new_err(
"quadratic_vertex() takes 4 numbers, or 6 in 3D",
));
}
};
graphics_record_command(self.entity, DrawCommand::ShapeQuadraticVertex { c, to })
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}

pub fn quadratic_vertex(&self, cx: f32, cy: f32, x: f32, y: f32) -> PyResult<()> {
#[pyo3(signature = (x, y, z=0.0))]
pub fn curve_vertex(&self, x: f32, y: f32, z: f32) -> PyResult<()> {
graphics_record_command(
self.entity,
DrawCommand::ShapeQuadraticVertex { cx, cy, x, y },
DrawCommand::ShapeCurveVertex {
to: Vec3::new(x, y, z),
},
)
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}

pub fn curve_vertex(&self, x: f32, y: f32) -> PyResult<()> {
graphics_record_command(self.entity, DrawCommand::ShapeCurveVertex { x, y })
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}

pub fn begin_contour(&self) -> PyResult<()> {
graphics_record_command(self.entity, DrawCommand::BeginContour)
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
Expand Down
38 changes: 29 additions & 9 deletions crates/processing_pyo3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2605,13 +2605,31 @@ pub mod processing_py {
}

#[pyfunction]
#[pyo3(pass_module)]
fn vertex(module: &Bound<'_, PyModule>, x: f32, y: f32) -> PyResult<()> {
graphics!(module).vertex(x, y)
#[pyo3(pass_module, signature = (x, y, *args))]
fn vertex(
module: &Bound<'_, PyModule>,
x: f32,
y: f32,
args: &Bound<'_, PyTuple>,
) -> PyResult<()> {
graphics!(module).vertex(x, y, args)
}

#[pyfunction]
#[pyo3(pass_module, signature = (*args))]
fn normal(module: &Bound<'_, PyModule>, args: &Bound<'_, PyTuple>) -> PyResult<()> {
graphics!(module).normal(args)
}

#[pyfunction]
#[pyo3(pass_module)]
fn texture_mode(module: &Bound<'_, PyModule>, mode: &str) -> PyResult<()> {
graphics!(module).texture_mode(mode)
}

#[pyfunction]
#[pyo3(pass_module, signature = (cx1, cy1, cx2, cy2, x, y, *args))]
#[allow(clippy::too_many_arguments)]
fn bezier_vertex(
module: &Bound<'_, PyModule>,
cx1: f32,
Expand All @@ -2620,26 +2638,28 @@ pub mod processing_py {
cy2: f32,
x: f32,
y: f32,
args: &Bound<'_, PyTuple>,
) -> PyResult<()> {
graphics!(module).bezier_vertex(cx1, cy1, cx2, cy2, x, y)
graphics!(module).bezier_vertex(cx1, cy1, cx2, cy2, x, y, args)
}

#[pyfunction]
#[pyo3(pass_module)]
#[pyo3(pass_module, signature = (cx, cy, x, y, *args))]
fn quadratic_vertex(
module: &Bound<'_, PyModule>,
cx: f32,
cy: f32,
x: f32,
y: f32,
args: &Bound<'_, PyTuple>,
) -> PyResult<()> {
graphics!(module).quadratic_vertex(cx, cy, x, y)
graphics!(module).quadratic_vertex(cx, cy, x, y, args)
}

#[pyfunction]
#[pyo3(pass_module)]
fn curve_vertex(module: &Bound<'_, PyModule>, x: f32, y: f32) -> PyResult<()> {
graphics!(module).curve_vertex(x, y)
#[pyo3(pass_module, signature = (x, y, z=0.0))]
fn curve_vertex(module: &Bound<'_, PyModule>, x: f32, y: f32, z: f32) -> PyResult<()> {
graphics!(module).curve_vertex(x, y, z)
}

#[pyfunction]
Expand Down
8 changes: 8 additions & 0 deletions crates/processing_render/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,12 @@ pub fn mode_3d(
In(entity): In<Entity>,
mut projections: Query<&mut Projection>,
mut transforms: Query<&mut Transform>,
mut states: Query<&mut RenderState>,
sizes: Query<&SurfaceSize>,
) -> Result<()> {
if let Ok(mut state) = states.get_mut(entity) {
state.three_d = true;
}
let SurfaceSize(width, height) = sizes
.get(entity)
.map_err(|_| ProcessingError::GraphicsNotFound)?;
Expand Down Expand Up @@ -504,8 +508,12 @@ pub fn mode_2d(
In(entity): In<Entity>,
mut projections: Query<&mut Projection>,
mut transforms: Query<&mut Transform>,
mut states: Query<&mut RenderState>,
sizes: Query<&SurfaceSize>,
) -> Result<()> {
if let Ok(mut state) = states.get_mut(entity) {
state.three_d = false;
}
let SurfaceSize(width, height) = sizes
.get(entity)
.map_err(|_| ProcessingError::GraphicsNotFound)?;
Expand Down
1 change: 1 addition & 0 deletions crates/processing_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl Plugin for ProcessingRenderPlugin {
bevy::camera_controller::pan_camera::PanCameraPlugin,
text::font::TextPlugin,
))
.add_plugins(render::line::LineMaterialPlugin)
.add_plugins(ci::CiPlugin);

// Processing strokes every edge of a shape, so the wireframe pass never culls
Expand Down
Loading
Loading