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
15 changes: 15 additions & 0 deletions crates/processing_pyo3/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2206,6 +2206,21 @@ impl Graphics {
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}

pub fn texture(&self, source: ImageRef) -> PyResult<()> {
graphics_record_command(self.entity, DrawCommand::Texture(source.entity))
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}

pub fn no_texture(&self) -> PyResult<()> {
graphics_record_command(self.entity, DrawCommand::NoTexture)
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}

pub fn texture_transform(&self, transform: crate::math::PyAffine2) -> PyResult<()> {
graphics_record_command(self.entity, DrawCommand::TextureTransform(transform.0))
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}

pub fn unlit(&self) -> PyResult<()> {
graphics_record_command(self.entity, DrawCommand::Unlit)
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
Expand Down
21 changes: 21 additions & 0 deletions crates/processing_pyo3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2029,6 +2029,27 @@ pub mod mewnala {
graphics!(module).emissive(args)
}

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

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

#[pyfunction]
#[pyo3(pass_module)]
fn texture_transform(
module: &Bound<'_, PyModule>,
transform: crate::math::PyAffine2,
) -> PyResult<()> {
graphics!(module).texture_transform(transform)
}

#[pyfunction]
#[pyo3(pass_module)]
fn unlit(module: &Bound<'_, PyModule>) -> PyResult<()> {
Expand Down
14 changes: 6 additions & 8 deletions crates/processing_pyo3/src/webcam.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ use processing_webcam::{
};
use pyo3::{exceptions::PyRuntimeError, prelude::*};

use crate::graphics::Image;

#[pyclass(unsendable)]
pub struct Webcam {
entity: Entity,
}

impl Webcam {
pub(crate) fn image_entity(&self) -> PyResult<Entity> {
webcam_image(self.entity).map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}
}

#[pymethods]
impl Webcam {
/// Opaque id for this object.
Expand Down Expand Up @@ -45,12 +49,6 @@ impl Webcam {
pub fn resolution(&self) -> PyResult<(u32, u32)> {
webcam_resolution(self.entity).map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}

pub fn image(&self) -> PyResult<Image> {
let entity =
webcam_image(self.entity).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
Ok(Image::from_entity(entity))
}
}

impl Drop for Webcam {
Expand Down
8 changes: 8 additions & 0 deletions crates/processing_render/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@ pub fn blit(
Ok(())
}

#[derive(Component)]
#[relationship(relationship_target = LinkedImageTarget)]
pub struct LinkedImage(pub Entity);

#[derive(Component)]
#[relationship_target(relationship = LinkedImage)]
pub struct LinkedImageTarget(Entity);

#[derive(Component)]
pub struct Image {
pub handle: Handle<bevy::image::Image>,
Expand Down
4 changes: 4 additions & 0 deletions crates/processing_render/src/render/command.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bevy::math::Affine2;
use bevy::math::Affine3A;
use bevy::prelude::*;
use bevy::render::render_resource::{BlendComponent, BlendFactor, BlendOperation, BlendState};
Expand Down Expand Up @@ -515,6 +516,9 @@ pub enum DrawCommand {
Roughness(f32),
Metallic(f32),
Emissive(Color),
Texture(Entity),
NoTexture,
TextureTransform(Affine2),
Unlit,
Tint(Color),
NoTint,
Expand Down
19 changes: 19 additions & 0 deletions crates/processing_render/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,25 @@ pub fn flush_draw_commands(
pbr.blend_state = None;
state.style.material_key = pbr.into();
}
DrawCommand::Texture(entity) => {
if let Ok(img) = p_images.get(entity) {
let mut pbr = state.style.material_key.as_pbr();
pbr.base_color_texture = Some(img.handle.clone());
state.style.material_key = pbr.into();
}
}
DrawCommand::NoTexture => {
if let MaterialKey::Pbr { .. } = &state.style.material_key {
let mut pbr = state.style.material_key.as_pbr();
pbr.base_color_texture = None;
state.style.material_key = pbr.into();
}
}
DrawCommand::TextureTransform(transform) => {
let mut pbr = state.style.material_key.as_pbr();
pbr.uv_transform = transform;
state.style.material_key = pbr.into();
}
DrawCommand::Unlit => {
state.style.material_key = MaterialKey::Color {
transparent: state.fill_is_transparent(),
Expand Down
5 changes: 5 additions & 0 deletions crates/processing_webcam/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ fn create_with_format(In(format): In<WebcamFormat>, mut commands: Commands) -> E
}

fn create_image(In(entity): In<Entity>, world: &mut World) -> Result<Entity> {
if let Some(linked) = world.get::<image::LinkedImage>(entity) {
return Ok(linked.0);
}

let stream = world
.get::<WebcamStream>(entity)
.ok_or(ProcessingError::WebcamNotConnected)?;
Expand All @@ -39,6 +43,7 @@ fn create_image(In(entity): In<Entity>, world: &mut World) -> Result<Entity> {
let child = world
.run_system_once_with(image::from_handle, handle)
.unwrap()?;
world.entity_mut(entity).insert(image::LinkedImage(child));
world.entity_mut(entity).add_child(child);
Ok(child)
}
Expand Down
Loading