Skip to content
Open
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
2 changes: 1 addition & 1 deletion crates/processing_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2405,7 +2405,7 @@ pub extern "C" fn processing_geometry_normal(geo_id: u64, nx: f32, ny: f32, nz:
pub extern "C" fn processing_geometry_color(geo_id: u64, r: f32, g: f32, b: f32, a: f32) {
error::clear_error();
let entity = Entity::from_bits(geo_id);
error::check(|| geometry_color(entity, Vec4::new(r, g, b, a)));
error::check(|| geometry_color(entity, bevy::color::Color::srgba(r, g, b, a)));
}

#[unsafe(no_mangle)]
Expand Down
2 changes: 1 addition & 1 deletion crates/processing_node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ pub fn js_geometry_normal(geo_id: BigInt, nx: f64, ny: f64, nz: f64) -> Result<(
pub fn js_geometry_color(geo_id: BigInt, r: f64, g: f64, b: f64, a: f64) -> Result<()> {
check(geometry_color(
ent(geo_id),
Vec4::new(r as f32, g as f32, b as f32, a as f32),
bevy::color::Color::srgba(r as f32, g as f32, b as f32, a as f32),
))
}

Expand Down
6 changes: 3 additions & 3 deletions crates/processing_pyo3/examples/Demos/Graphics/depth_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ def setup():
for i in range(10):
c = hsva(remap(i, 0, 10, 0, 360), 1.0, 1.0, 0.3)
tri = create_geometry(topology=TRIANGLES)
tri.color(c.r, c.g, c.b, c.a)
tri.color(c)
tri.vertex(200, 50, -50)
tri.color(c.r, c.g, c.b, c.a)
tri.color(c)
tri.vertex(100, 100, 50)
tri.color(c.r, c.g, c.b, c.a)
tri.color(c)
tri.vertex(100, 0, 20)
tri.index(0)
tri.index(1)
Expand Down
10 changes: 7 additions & 3 deletions crates/processing_pyo3/examples/Demos/Graphics/ribbons.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ def draw():
arcball.run()

translate(model_shift.x, model_shift.y, model_shift.z)
no_stroke()
if render_mode == 0:
# Lines take the stroke color, multiplied by the vertex colors
stroke(1.0)
else:
no_stroke()
for i in range(len(models)):
draw_geometry(models[i])

Expand Down Expand Up @@ -462,7 +466,7 @@ def create_ribbon_model(residues, trj):
for line in (vertices0, vertices1, vertices2):
model = create_geometry(topology=LINE_STRIP)
for pos_vec in line:
model.color(ribbon_color.r, ribbon_color.g, ribbon_color.b, ribbon_color.a)
model.color(ribbon_color)
model.vertex(pos_vec.x, pos_vec.y, pos_vec.z)
trj.append(model)
else:
Expand All @@ -473,7 +477,7 @@ def create_ribbon_model(residues, trj):
for i in range(len(vertices)):
pos_vec = vertices[i]
norm_vec = normals[i]
model.color(ribbon_color.r, ribbon_color.g, ribbon_color.b, ribbon_color.a)
model.color(ribbon_color)
model.normal(-norm_vec.x, -norm_vec.y, -norm_vec.z)
model.vertex(pos_vec.x, pos_vec.y, pos_vec.z)
trj.append(model)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def add_box(g, x, y, z, s, c):
h = s / 2
base = g.vertex_count()
for (dx, dy, dz) in [(-1, -1, -1), (1, -1, -1), (1, 1, -1), (-1, 1, -1), (-1, -1, 1), (1, -1, 1), (1, 1, 1), (-1, 1, 1)]:
g.color(c.r, c.g, c.b, c.a)
g.color(c)
g.vertex(x + dx * h, y + dy * h, z + dz * h)
for (a, b, d) in [(0, 2, 1), (0, 3, 2), (4, 5, 6), (4, 6, 7), (0, 1, 5), (0, 5, 4), (2, 3, 7), (2, 7, 6), (1, 2, 6), (1, 6, 5), (0, 4, 7), (0, 7, 3)]:
g.index(base + a)
Expand Down
2 changes: 2 additions & 0 deletions crates/processing_pyo3/examples/Demos/Performance/esfera.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def draw():
for i in range(len(lista)):
lista[i].dibujar()

# Lines take the stroke color, multiplied by the vertex colors
stroke(1.0)
stroke_weight(1)
draw_geometry(pelos)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ def setup():
star = create_geometry(topology=TRIANGLES)
# You can set fill and stroke
star.color(0.4, 0.4, 0.4, 1.0)
stroke(1.0) # GAP: Geometry has no stroke; the outline is not drawn
stroke_weight(2) # GAP: Geometry has no stroke_weight
no_stroke() # GAP: stroke() on a Geometry draws every triangle edge; the polygon outline needs a Shape
# Here, we are hardcoding a series of vertices;
# the first one is the center, so the star can be built as a triangle fan
star.vertex(0, 0, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ def __init__(self):
# Now make the geometry with those vertices
self.s = create_geometry(topology=TRIANGLES)
self.s.color(0.5, 0.5, 0.5, 1.0)
stroke(0.0) # GAP: Geometry has no stroke; the outline is not drawn
stroke_weight(2) # GAP: Geometry has no stroke_weight
no_stroke() # GAP: stroke() on a Geometry draws every triangle edge; the polygon outline needs a Shape
for v in self.original:
self.s.vertex(v.x, v.y, 0)
# The circle is convex, so a triangle fan from the first vertex fills it
Expand Down
4 changes: 2 additions & 2 deletions crates/processing_pyo3/examples/Topics/Geometry/icosahedra.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ def draw():
rotate_y(frame_count * PI / -200)
stroke(0.67, 0.0, 0.0)
no_fill()
ico1.create() # GAP: stroke()/no_fill() wireframe outline on draw_geometry
ico1.create()
pop_matrix()

push_matrix()
rotate_x(frame_count * PI / 200)
rotate_y(frame_count * PI / 300)
stroke(0.59, 0.0, 0.71)
fill(0.67, 0.67, 0.0)
ico2.create() # GAP: stroke() outline on draw_geometry
ico2.create()
pop_matrix()

push_matrix()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def draw():

for i in range(cuantos):
lista[i].dibujar()
# Lines take the fill color, multiplied by the vertex colors
fill(1.0) # GAP: LINES geometry ignores stroke(); it is colored by fill() times vertex colors
# Lines take the stroke color, multiplied by the vertex colors
stroke(1.0)
draw_geometry(pelos)


Expand Down
58 changes: 29 additions & 29 deletions crates/processing_pyo3/examples/Topics/Geometry/rgb_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,35 +50,35 @@ def draw():
def build_cube():
g = create_geometry(topology=TRIANGLES)

g.color(0, 1, 1, 1); g.vertex(-1, 1, 1)
g.color(1, 1, 1, 1); g.vertex(1, 1, 1)
g.color(1, 0, 1, 1); g.vertex(1, -1, 1)
g.color(0, 0, 1, 1); g.vertex(-1, -1, 1)

g.color(1, 1, 1, 1); g.vertex(1, 1, 1)
g.color(1, 1, 0, 1); g.vertex(1, 1, -1)
g.color(1, 0, 0, 1); g.vertex(1, -1, -1)
g.color(1, 0, 1, 1); g.vertex(1, -1, 1)

g.color(1, 1, 0, 1); g.vertex(1, 1, -1)
g.color(0, 1, 0, 1); g.vertex(-1, 1, -1)
g.color(0, 0, 0, 1); g.vertex(-1, -1, -1)
g.color(1, 0, 0, 1); g.vertex(1, -1, -1)

g.color(0, 1, 0, 1); g.vertex(-1, 1, -1)
g.color(0, 1, 1, 1); g.vertex(-1, 1, 1)
g.color(0, 0, 1, 1); g.vertex(-1, -1, 1)
g.color(0, 0, 0, 1); g.vertex(-1, -1, -1)

g.color(0, 1, 0, 1); g.vertex(-1, 1, -1)
g.color(1, 1, 0, 1); g.vertex(1, 1, -1)
g.color(1, 1, 1, 1); g.vertex(1, 1, 1)
g.color(0, 1, 1, 1); g.vertex(-1, 1, 1)

g.color(0, 0, 0, 1); g.vertex(-1, -1, -1)
g.color(1, 0, 0, 1); g.vertex(1, -1, -1)
g.color(1, 0, 1, 1); g.vertex(1, -1, 1)
g.color(0, 0, 1, 1); g.vertex(-1, -1, 1)
g.color(0.0, 1.0, 1.0, 1.0); g.vertex(-1, 1, 1)
g.color(1.0, 1.0, 1.0, 1.0); g.vertex(1, 1, 1)
g.color(1.0, 0.0, 1.0, 1.0); g.vertex(1, -1, 1)
g.color(0.0, 0.0, 1.0, 1.0); g.vertex(-1, -1, 1)

g.color(1.0, 1.0, 1.0, 1.0); g.vertex(1, 1, 1)
g.color(1.0, 1.0, 0.0, 1.0); g.vertex(1, 1, -1)
g.color(1.0, 0.0, 0.0, 1.0); g.vertex(1, -1, -1)
g.color(1.0, 0.0, 1.0, 1.0); g.vertex(1, -1, 1)

g.color(1.0, 1.0, 0.0, 1.0); g.vertex(1, 1, -1)
g.color(0.0, 1.0, 0.0, 1.0); g.vertex(-1, 1, -1)
g.color(0.0, 0.0, 0.0, 1.0); g.vertex(-1, -1, -1)
g.color(1.0, 0.0, 0.0, 1.0); g.vertex(1, -1, -1)

g.color(0.0, 1.0, 0.0, 1.0); g.vertex(-1, 1, -1)
g.color(0.0, 1.0, 1.0, 1.0); g.vertex(-1, 1, 1)
g.color(0.0, 0.0, 1.0, 1.0); g.vertex(-1, -1, 1)
g.color(0.0, 0.0, 0.0, 1.0); g.vertex(-1, -1, -1)

g.color(0.0, 1.0, 0.0, 1.0); g.vertex(-1, 1, -1)
g.color(1.0, 1.0, 0.0, 1.0); g.vertex(1, 1, -1)
g.color(1.0, 1.0, 1.0, 1.0); g.vertex(1, 1, 1)
g.color(0.0, 1.0, 1.0, 1.0); g.vertex(-1, 1, 1)

g.color(0.0, 0.0, 0.0, 1.0); g.vertex(-1, -1, -1)
g.color(1.0, 0.0, 0.0, 1.0); g.vertex(1, -1, -1)
g.color(1.0, 0.0, 1.0, 1.0); g.vertex(1, -1, 1)
g.color(0.0, 0.0, 1.0, 1.0); g.vertex(-1, -1, 1)

# Each group of four vertices is a quad: two triangles
for face in range(6):
Expand Down
2 changes: 1 addition & 1 deletion crates/processing_pyo3/examples/Topics/Geometry/toroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def draw():
# wireframe or solid
if is_wire_frame:
stroke(1.0, 1.0, 0.59)
no_fill() # GAP: stroke()/no_fill() wireframe outline on draw_geometry
no_fill()
else:
no_stroke()
fill(0.59, 0.76, 0.49)
Expand Down
1 change: 1 addition & 0 deletions crates/processing_pyo3/examples/animated_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def draw():
camera_position(150.0, -150.0, 150.0)
camera_look_at( 0.0, 0.0, 0.0)
background(220, 200, 140)
no_stroke()

for z in range(grid_size):
for x in range(grid_size):
Expand Down
1 change: 1 addition & 0 deletions crates/processing_pyo3/examples/geometry_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def setup():

def draw():
background(220)
no_stroke()
camera_position(0.0, 0.0, 200.0)
camera_look_at(0.0, 0.0, 0.0)
draw_geometry(geometry)
Expand Down
6 changes: 3 additions & 3 deletions crates/processing_pyo3/src/graphics.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::color::{ColorMode, ColorSpace, extract_color_with_mode, parse_numeric};
use crate::glfw::GlfwContext;
use crate::input;
use crate::math::{Vec3Like, extract_vec2, extract_vec3, extract_vec4};
use crate::math::{Vec3Like, extract_vec2, extract_vec3};
use bevy::{
color::{ColorToPacked, LinearRgba, Srgba},
math::{Affine3A, Mat4, Vec3, Vec4},
Expand Down Expand Up @@ -830,8 +830,8 @@ impl Geometry {

#[pyo3(signature = (*args))]
pub fn color(&self, args: &Bound<'_, PyTuple>) -> PyResult<()> {
let v = extract_vec4(args)?;
geometry_color(self.entity, v).map_err(|e| PyRuntimeError::new_err(format!("{e}")))
let color = extract_color_with_mode(args, &ColorMode::default())?;
geometry_color(self.entity, color).map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}

#[pyo3(signature = (*args))]
Expand Down
19 changes: 0 additions & 19 deletions crates/processing_pyo3/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,6 @@ impl Vec3Arg {
}
}

#[derive(FromPyObject)]
pub(crate) enum Vec4Arg {
Instance((PyVec4,)),
Components(f32, f32, f32, f32),
}

impl Vec4Arg {
pub fn into_vec4(self) -> Vec4 {
match self {
Vec4Arg::Instance((v,)) => v.0,
Vec4Arg::Components(x, y, z, w) => Vec4::new(x, y, z, w),
}
}
}

// Vec3Like for single-object extraction (e.g., Quat::from_axis_angle(axis, angle))
#[derive(FromPyObject)]
pub(crate) enum Vec3Like {
Expand All @@ -101,10 +86,6 @@ pub(crate) fn extract_vec3(args: &Bound<'_, PyTuple>) -> PyResult<Vec3> {
Ok(args.extract::<Vec3Arg>()?.into_vec3())
}

pub(crate) fn extract_vec4(args: &Bound<'_, PyTuple>) -> PyResult<Vec4> {
Ok(args.extract::<Vec4Arg>()?.into_vec4())
}

// Implements a PyVecN class with the given name, fields, and underlying glam type,
// including arithmetic operations, indexing, iteration, and common vector methods, etc.
// The `extra` block can be used to add additional methods specific to certain vector types
Expand Down
32 changes: 27 additions & 5 deletions crates/processing_render/src/geometry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ impl Topology {
}
}

/// Which edges of a triangle mesh the stroke draws.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Edges {
#[default]
Triangles,
/// built-in primitives, whose triangle pairs are faces
Quads,
/// an imported model, which is never stroked
None,
}

#[derive(Component)]
pub struct Geometry {
pub handle: Handle<Mesh>,
Expand All @@ -85,6 +96,7 @@ pub struct Geometry {
pub custom_current: HashMap<MeshVertexAttributeId, AttributeValue>,
/// set once a color with alpha below one is used; never cleared
pub translucent: bool,
pub edges: Edges,
}

impl Geometry {
Expand All @@ -97,8 +109,14 @@ impl Geometry {
current_uv: [0.0, 0.0],
custom_current: HashMap::new(),
translucent: false,
edges: Edges::default(),
}
}

pub fn with_edges(mut self, edges: Edges) -> Self {
self.edges = edges;
self
}
}

pub fn create(
Expand Down Expand Up @@ -187,7 +205,9 @@ pub fn create_box(
]))
.id();

commands.spawn(Geometry::new(handle, layout_entity)).id()
commands
.spawn(Geometry::new(handle, layout_entity).with_edges(Edges::Quads))
.id()
}

pub fn create_sphere(
Expand All @@ -207,7 +227,9 @@ pub fn create_sphere(
]))
.id();

commands.spawn(Geometry::new(handle, layout_entity)).id()
commands
.spawn(Geometry::new(handle, layout_entity).with_edges(Edges::Quads))
.id()
}

pub fn create_grid(
Expand Down Expand Up @@ -257,12 +279,12 @@ pub fn normal(world: &mut World, entity: Entity, normal: Vec3) -> Result<()> {
Ok(())
}

pub fn color(world: &mut World, entity: Entity, color: Vec4) -> Result<()> {
pub fn color(world: &mut World, entity: Entity, color: Color) -> Result<()> {
let mut geometry = world
.get_mut::<Geometry>(entity)
.ok_or(ProcessingError::GeometryNotFound)?;
geometry.current_color = color.to_array();
if color.w < 1.0 {
geometry.current_color = color.to_linear().to_f32_array();
if color.alpha() < 1.0 {
geometry.translucent = true;
}
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions crates/processing_render/src/gltf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use bevy::{
world_serialization::{InstanceId, WorldInstanceSpawner},
};

use crate::geometry::{BuiltinAttributes, Geometry, layout::VertexLayout};
use crate::geometry::{BuiltinAttributes, Edges, Geometry, layout::VertexLayout};
use crate::graphics;
use crate::light::{LightOf, ProcessingLight};
use crate::material::ProcessingMaterial;
Expand Down Expand Up @@ -208,7 +208,7 @@ pub fn geometry(
let layout_entity = world.spawn(VertexLayout::with_attributes(attrs)).id();
let entity = world
.spawn((
Geometry::new(mesh_handle, layout_entity),
Geometry::new(mesh_handle, layout_entity).with_edges(Edges::None),
GltfNodeTransform(global_transform),
))
.id();
Expand Down
2 changes: 1 addition & 1 deletion crates/processing_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1593,7 +1593,7 @@ pub fn geometry_normal(entity: Entity, normal: Vec3) -> error::Result<()> {
app_mut(|app| geometry::normal(app.world_mut(), entity, normal))
}

pub fn geometry_color(entity: Entity, color: Vec4) -> error::Result<()> {
pub fn geometry_color(entity: Entity, color: Color) -> error::Result<()> {
app_mut(|app| geometry::color(app.world_mut(), entity, color))
}

Expand Down
Loading
Loading