diff --git a/crates/processing_pyo3/src/graphics.rs b/crates/processing_pyo3/src/graphics.rs index 7fdc031..cc8277d 100644 --- a/crates/processing_pyo3/src/graphics.rs +++ b/crates/processing_pyo3/src/graphics.rs @@ -124,23 +124,6 @@ fn normalize_src_rect(entity: Entity, rect: Option<[f32; 4]>) -> PyResult<[f32; } } -/// Resolve a composite source (`Image`, `Webcam`, or `Graphics`) to a -/// texture-bearing entity, plus the graphics entity that must be flushed first -/// when the source is a graphics (so its latest content is what gets sampled). -/// A `Graphics` source uses its render-target surface entity, which carries an -/// `Image` component for offscreen graphics. -fn resolve_composite_source(src: &Bound<'_, PyAny>) -> PyResult<(Entity, Option)> { - if let Ok(img) = src.extract::() { - return Ok((img.entity, None)); - } - if let Ok(g) = src.extract::>() { - return Ok((g.surface.entity, Some(g.entity))); - } - Err(PyValueError::new_err( - "composite source must be an Image, Webcam, or Graphics", - )) -} - /// Run the built-in composite filter: blend the `src` texture into the `dst` /// graphics target using `mode`, with normalized src/dst rects. This is the /// shader-based composite pass shared by `copy`/`blend`/`mask`. @@ -446,6 +429,36 @@ impl Light { let v = extract_vec3(args)?; transform_look_at(self.entity, v).map_err(|e| PyRuntimeError::new_err(format!("{e}"))) } + + #[pyo3(signature = (*args))] + pub fn translate(&self, args: &Bound<'_, PyTuple>) -> PyResult<()> { + let v = extract_vec3(args)?; + transform_translate(self.entity, v).map_err(rt_err) + } + + pub fn rotate_x(&self, angle: f32) -> PyResult<()> { + transform_rotate_x(self.entity, angle).map_err(rt_err) + } + + pub fn rotate_y(&self, angle: f32) -> PyResult<()> { + transform_rotate_y(self.entity, angle).map_err(rt_err) + } + + pub fn rotate_z(&self, angle: f32) -> PyResult<()> { + transform_rotate_z(self.entity, angle).map_err(rt_err) + } + + /// Rotate by `angle` radians around `axis`. + #[pyo3(signature = (angle, *axis))] + pub fn rotate_axis(&self, angle: f32, axis: &Bound<'_, PyTuple>) -> PyResult<()> { + let axis = extract_vec3(axis)?; + transform_rotate_axis(self.entity, angle, axis).map_err(rt_err) + } + + /// Back to the origin with no rotation. + pub fn reset(&self) -> PyResult<()> { + transform_reset(self.entity).map_err(rt_err) + } } impl Light { @@ -565,8 +578,22 @@ impl Image { } } +/// Anything that can be sampled as an image: an `Image`, a `Webcam`, or an +/// offscreen `Graphics`. pub(crate) struct ImageRef { - pub entity: Entity, + entity: Entity, + graphics: Option, +} + +impl ImageRef { + /// The entity carrying the image. A `Graphics` source with pending draws is + /// flushed first, so what it has drawn so far is what gets sampled. + pub(crate) fn texture(&self) -> PyResult { + if let Some(graphics) = self.graphics { + graphics_flush_pending(graphics).map_err(rt_err)?; + } + Ok(self.entity) + } } impl<'a, 'py> FromPyObject<'a, 'py> for ImageRef { @@ -574,7 +601,10 @@ impl<'a, 'py> FromPyObject<'a, 'py> for ImageRef { fn extract(ob: pyo3::Borrowed<'a, 'py, PyAny>) -> PyResult { if let Ok(img) = ob.extract::>() { - return Ok(ImageRef { entity: img.entity }); + return Ok(ImageRef { + entity: img.entity, + graphics: None, + }); } // an offscreen Graphics renders into an image; a window has no texture to sample if let Ok(g) = ob.extract::>() { @@ -585,12 +615,14 @@ impl<'a, 'py> FromPyObject<'a, 'py> for ImageRef { } return Ok(ImageRef { entity: g.surface.entity, + graphics: Some(g.entity), }); } #[cfg(feature = "webcam")] if let Ok(cam) = ob.extract::>() { return Ok(ImageRef { entity: cam.image_entity()?, + graphics: None, }); } Err(pyo3::exceptions::PyTypeError::new_err( @@ -629,6 +661,26 @@ impl Image { .map_err(|e| PyRuntimeError::new_err(format!("{e}"))) } + /// Resize to `width` x `height` pixels. A 0 for either keeps the aspect ratio. + pub fn resize(&self, width: u32, height: u32) -> PyResult<()> { + let (w, h) = image_size(self.entity).map_err(rt_err)?; + let (width, height) = match (width, height) { + (0, 0) => return Err(PyValueError::new_err("resize() needs a non-zero size")), + (0, height) => ((w as f32 * height as f32 / h as f32).round() as u32, height), + (width, 0) => (width, (h as f32 * width as f32 / w as f32).round() as u32), + size => size, + }; + image_resize( + self.entity, + Extent3d { + width: width.max(1), + height: height.max(1), + depth_or_array_layers: 1, + }, + ) + .map_err(rt_err) + } + /// Image width in pixels. #[getter] fn width(&self) -> PyResult { @@ -1237,8 +1289,19 @@ impl Graphics { .map_err(|e| PyRuntimeError::new_err(format!("{e}"))) } + /// A color (same arguments as `fill()`), or an `Image`, `Graphics` or + /// `Webcam` stretched over the canvas. #[pyo3(signature = (*args))] pub fn background(&self, args: &Bound<'_, PyTuple>) -> PyResult<()> { + if args.len() == 1 + && let Ok(image) = args.get_item(0)?.extract::() + { + return graphics_record_command( + self.entity, + DrawCommand::BackgroundImage(image.texture()?), + ) + .map_err(|e| PyRuntimeError::new_err(format!("{e}"))); + } let color = extract_color_with_mode( args, &graphics_get_color_mode(self.entity) @@ -1248,11 +1311,6 @@ impl Graphics { .map_err(|e| PyRuntimeError::new_err(format!("{e}"))) } - pub fn background_image(&self, image: &Image) -> PyResult<()> { - graphics_record_command(self.entity, DrawCommand::BackgroundImage(image.entity)) - .map_err(|e| PyRuntimeError::new_err(format!("{e}"))) - } - pub fn clear(&self) -> PyResult<()> { graphics_record_command( self.entity, @@ -1930,7 +1988,7 @@ impl Graphics { graphics_record_command( self.entity, DrawCommand::Image { - entity: source.entity, + entity: source.texture()?, dx, dy, d_width, @@ -2319,7 +2377,7 @@ impl Graphics { } pub fn texture(&self, source: ImageRef) -> PyResult<()> { - graphics_record_command(self.entity, DrawCommand::Texture(source.entity)) + graphics_record_command(self.entity, DrawCommand::Texture(source.texture()?)) .map_err(|e| PyRuntimeError::new_err(format!("{e}"))) } @@ -2452,10 +2510,7 @@ impl Graphics { MULTIPLY, SCREEN, REPLACE)", ) })?; - let (src_entity, flush) = resolve_composite_source(src)?; - if let Some(g) = flush { - graphics_flush(g).map_err(rt_err)?; - } + let src_entity = src.extract::()?.texture()?; let sr = normalize_src_rect(src_entity, src_rect)?; let dr = normalize_rect(dst_rect, self.width as f32, self.height as f32); composite_apply(self.entity, src_entity, code, sr, dr, opacity) @@ -2471,10 +2526,7 @@ impl Graphics { src_rect: Option<[f32; 4]>, dst_rect: Option<[f32; 4]>, ) -> PyResult<()> { - let (src_entity, flush) = resolve_composite_source(src)?; - if let Some(g) = flush { - graphics_flush(g).map_err(rt_err)?; - } + let src_entity = src.extract::()?.texture()?; let sr = normalize_src_rect(src_entity, src_rect)?; let dr = normalize_rect(dst_rect, self.width as f32, self.height as f32); composite_apply(self.entity, src_entity, COMPOSITE_MODE_REPLACE, sr, dr, 1.0) @@ -2498,10 +2550,7 @@ impl Graphics { /// Applies a mask source's brightness as this graphics' alpha channel /// (Processing `mask`). `mask` may be an `Image`, webcam, or `Graphics`. pub fn mask(&self, mask: &Bound<'_, PyAny>) -> PyResult<()> { - let (src_entity, flush) = resolve_composite_source(mask)?; - if let Some(g) = flush { - graphics_flush(g).map_err(rt_err)?; - } + let src_entity = mask.extract::()?.texture()?; composite_apply( self.entity, src_entity, diff --git a/crates/processing_pyo3/src/lib.rs b/crates/processing_pyo3/src/lib.rs index 4b9b526..87d0710 100644 --- a/crates/processing_pyo3/src/lib.rs +++ b/crates/processing_pyo3/src/lib.rs @@ -1713,13 +1713,7 @@ pub mod processing_py { #[pyfunction] #[pyo3(pass_module, signature = (*args))] fn background(module: &Bound<'_, PyModule>, args: &Bound<'_, PyTuple>) -> PyResult<()> { - let graphics = graphics!(module); - let first = args.get_item(0)?; - if first.is_instance_of::() { - graphics.background_image(&*first.extract::>()?) - } else { - graphics.background(args) - } + graphics!(module).background(args) } #[pyfunction] diff --git a/crates/processing_pyo3/src/material.rs b/crates/processing_pyo3/src/material.rs index 95cf57a..6d630fd 100644 --- a/crates/processing_pyo3/src/material.rs +++ b/crates/processing_pyo3/src/material.rs @@ -16,7 +16,7 @@ pub struct Material { pub(crate) fn py_to_shader_value(value: &Bound<'_, PyAny>) -> PyResult { if let Ok(img_ref) = value.extract::() { - return Ok(shader_value::ShaderValue::Texture(img_ref.entity)); + return Ok(shader_value::ShaderValue::Texture(img_ref.texture()?)); } if let Ok(int_val) = value.cast::() { if let Ok(v) = int_val.extract::() { @@ -47,6 +47,16 @@ pub(crate) fn py_to_shader_value(value: &Bound<'_, PyAny>) -> PyResult() { + let m = bevy::math::Mat4::from_cols_array(&rows).transpose(); + return Ok(shader_value::ShaderValue::Mat4(m.to_cols_array())); + } + if let Ok(rows) = value.extract::<[[f32; 4]; 4]>() { + let m = bevy::math::Mat4::from_cols_array_2d(&rows).transpose(); + return Ok(shader_value::ShaderValue::Mat4(m.to_cols_array())); + } + if let Ok(v) = value.extract::<[f32; 4]>() { return Ok(shader_value::ShaderValue::Float4(v)); } @@ -88,6 +98,32 @@ fn apply_albedo(entity: Entity, value: &Bound<'_, PyAny>) -> PyResult<()> { ))) } +fn apply_emissive(entity: Entity, value: &Bound<'_, PyAny>) -> PyResult<()> { + let rt = |e| PyRuntimeError::new_err(format!("{e}")); + if let Ok(buf) = value.extract::>() { + return material_set_emissive_buffer(entity, buf.entity).map_err(rt); + } + // emissive is a linear radiance, not an sRGB color + let linear: bevy::color::LinearRgba = if let Ok(c) = value.extract::>() { + c.0.into() + } else if let Ok([r, g, b, a]) = value.extract::<[f32; 4]>() { + bevy::color::LinearRgba::new(r, g, b, a) + } else if let Ok([r, g, b]) = value.extract::<[f32; 3]>() { + bevy::color::LinearRgba::new(r, g, b, 1.0) + } else { + return Err(PyRuntimeError::new_err(format!( + "unsupported emissive type: {} (expected Color, Buffer, or [r,g,b,(a)])", + value.get_type().name()? + ))); + }; + material_set( + entity, + "emissive", + shader_value::ShaderValue::Float4([linear.red, linear.green, linear.blue, linear.alpha]), + ) + .map_err(rt) +} + fn py_truthy(value: &Bound<'_, PyAny>) -> PyResult { value .extract::() @@ -100,6 +136,7 @@ fn apply_kwargs(entity: Entity, kwargs: &Bound<'_, PyDict>) -> PyResult<()> { let rt = |e| PyRuntimeError::new_err(format!("{e}")); match name.as_str() { "albedo" => apply_albedo(entity, &value)?, + "emissive" => apply_emissive(entity, &value)?, "unlit" => material_set_unlit(entity, py_truthy(&value)?).map_err(rt)?, "double_sided" => material_set_double_sided(entity, py_truthy(&value)?).map_err(rt)?, "depth_write" => material_set_depth_write(entity, py_truthy(&value)?).map_err(rt)?, @@ -148,17 +185,6 @@ impl Material { Ok(Self { entity }) } - #[staticmethod] - #[pyo3(signature = (**kwargs))] - pub fn unlit(kwargs: Option<&Bound<'_, PyDict>>) -> PyResult { - let entity = material_create_pbr().map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; - material_set_unlit(entity, true).map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; - if let Some(kwargs) = kwargs { - apply_kwargs(entity, kwargs)?; - } - Ok(Self { entity }) - } - #[pyo3(signature = (**kwargs))] pub fn set(&self, kwargs: Option<&Bound<'_, PyDict>>) -> PyResult<()> { let Some(kwargs) = kwargs else { @@ -166,6 +192,48 @@ impl Material { }; apply_kwargs(self.entity, kwargs) } + + pub fn opaque(&self) -> PyResult<()> { + material_set_alpha_mode(self.entity, 0, 0.0).map_err(rt) + } + + /// Discards fragments with alpha below `cutoff`. + #[pyo3(signature = (cutoff=0.5))] + pub fn mask(&self, cutoff: f32) -> PyResult<()> { + material_set_alpha_mode(self.entity, 1, cutoff).map_err(rt) + } + + pub fn transparent(&self) -> PyResult<()> { + material_set_alpha_mode(self.entity, 2, 0.0).map_err(rt) + } + + /// Skips lighting; errors on a custom shader, which does its own. + #[pyo3(signature = (value=true, /))] + pub fn unlit(&self, value: bool) -> PyResult<()> { + material_set_unlit(self.entity, value).map_err(rt) + } + + #[pyo3(signature = (value=true, /))] + pub fn double_sided(&self, value: bool) -> PyResult<()> { + material_set_double_sided(self.entity, value).map_err(rt) + } + + #[pyo3(signature = (value=true, /))] + pub fn depth_write(&self, value: bool) -> PyResult<()> { + material_set_depth_write(self.entity, value).map_err(rt) + } + + /// Blends with what's behind it using a `BlendMode` (`ADD`, `MULTIPLY`, a custom one, ...). + pub fn blend_mode(&self, mode: &crate::graphics::PyBlendMode) -> PyResult<()> { + let state = mode + .blend_state + .unwrap_or(bevy::render::render_resource::BlendState::ALPHA_BLENDING); + material_set_custom_blend(self.entity, state).map_err(rt) + } +} + +fn rt(e: impl std::fmt::Display) -> PyErr { + PyRuntimeError::new_err(format!("{e}")) } impl Drop for Material { diff --git a/crates/processing_render/src/graphics.rs b/crates/processing_render/src/graphics.rs index a412b5a..793ef1a 100644 --- a/crates/processing_render/src/graphics.rs +++ b/crates/processing_render/src/graphics.rs @@ -757,6 +757,15 @@ pub fn flush(app: &mut App, entity: Entity) -> Result<()> { Ok(()) } +/// Brings the target up to date with what was drawn so far; no update when nothing is queued +pub fn flush_pending(app: &mut App, entity: Entity) -> Result<()> { + if has_commands(app, entity) { + flush(app, entity) + } else { + upload_dirty(app, entity) + } +} + fn has_commands(app: &App, entity: Entity) -> bool { app.world() .get::(entity) diff --git a/crates/processing_render/src/image.rs b/crates/processing_render/src/image.rs index fee055d..5183aeb 100644 --- a/crates/processing_render/src/image.rs +++ b/crates/processing_render/src/image.rs @@ -84,6 +84,7 @@ fn blit_backgrounds( &src.texture_view, dst, target.main_texture_format(), + wgpu::FilterMode::Linear, true, ); } @@ -119,15 +120,19 @@ pub enum BlitSource { Graphics(Entity), } -/// Caches one `wgpu::util::TextureBlitter` per destination format and blend. Lives +/// Caches one `wgpu::util::TextureBlitter` per destination format, filter and blend. Lives /// in the render world; blitters are cheap to reuse and expensive to rebuild. #[derive(Resource, Default)] pub struct BlitterCache { - blitters: std::collections::HashMap<(TextureFormat, bool), wgpu::util::TextureBlitter>, + blitters: std::collections::HashMap< + (TextureFormat, wgpu::FilterMode, bool), + wgpu::util::TextureBlitter, + >, } impl BlitterCache { /// Draws `src` over all of `dst`, which has `format`; `blend` alpha-blends instead of replacing + #[allow(clippy::too_many_arguments)] pub fn copy( &mut self, device: &wgpu::Device, @@ -135,23 +140,40 @@ impl BlitterCache { src: &wgpu::TextureView, dst: &wgpu::TextureView, format: TextureFormat, + filter: wgpu::FilterMode, blend: bool, ) { - let blitter = self.blitters.entry((format, blend)).or_insert_with(|| { - let builder = wgpu::util::TextureBlitterBuilder::new(device, format); - if blend { - builder - .sample_type(wgpu::FilterMode::Linear) - .blend_state(wgpu::BlendState::ALPHA_BLENDING) - .build() - } else { - builder.build() - } - }); + let blitter = self + .blitters + .entry((format, filter, blend)) + .or_insert_with(|| { + let builder = + wgpu::util::TextureBlitterBuilder::new(device, format).sample_type(filter); + if blend { + builder + .blend_state(wgpu::BlendState::ALPHA_BLENDING) + .build() + } else { + builder.build() + } + }); blitter.copy(device, encoder, src, dst); } } +/// Linear when the device can filter `format`, else nearest (32-bit floats need a feature) +pub fn sample_filter(device: &RenderDevice, format: TextureFormat) -> wgpu::FilterMode { + let filterable = format + .guaranteed_format_features(device.features()) + .flags + .contains(wgpu::TextureFormatFeatureFlags::FILTERABLE); + if filterable { + wgpu::FilterMode::Linear + } else { + wgpu::FilterMode::Nearest + } +} + /// Blit `source` into the destination image (a sampling copy: handles differing /// size and format, unlike a raw `copy_texture_to_texture`). Runs in the render /// world; the destination image's texture is used as the render target. @@ -190,7 +212,16 @@ pub fn blit( let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: Some("processing_blit"), }); - cache.copy(device, &mut encoder, src_view, dst_view, format, false); + let filter = sample_filter(&render_device, format); + cache.copy( + device, + &mut encoder, + src_view, + dst_view, + format, + filter, + false, + ); render_queue.submit(std::iter::once(encoder.finish())); Ok(()) } @@ -402,34 +433,136 @@ pub fn load(In(path): In, world: &mut World) -> Result { .id()) } -pub fn resize( - In((entity, new_size)): In<(Entity, Extent3d)>, - mut p_images: Query<&mut Image>, - mut images: ResMut>, - render_device: Res, -) -> Result<()> { - let mut p_image = p_images - .get_mut(entity) - .map_err(|_| ProcessingError::ImageNotFound)?; +/// Scales on the GPU with bilinear filtering, halving first so a large shrink averages +/// every source texel; the asset handle is kept, so materials holding it see the new size +pub fn resize(app: &mut App, entity: Entity, new_size: Extent3d) -> Result<()> { + let src = texture_for_read(app, entity)?; + let (handle, format, old_size) = { + let p_image = app + .world() + .get::(entity) + .ok_or(ProcessingError::ImageNotFound)?; + (p_image.handle.clone(), p_image.texture_format, p_image.size) + }; + let render_device = app.world().resource::().clone(); + let render_queue = app.world().resource::().clone(); + let device = render_device.wgpu_device(); + let filter = sample_filter(&render_device, format); + + let steps: Vec = resize_steps(old_size, new_size) + .into_iter() + .map(|size| { + render_device.create_texture(&wgpu::TextureDescriptor { + label: Some("processing_resize_step"), + size, + mip_level_count: 1, + sample_count: 1, + dimension: TextureDimension::D2, + format, + usage: TextureUsages::RENDER_ATTACHMENT | TextureUsages::TEXTURE_BINDING, + view_formats: &[], + }) + }) + .collect(); + let scaled = steps.last().expect("resize_steps ends at the new size"); - images - .get_mut(&p_image.handle) - .ok_or(ProcessingError::ImageNotFound)? - .resize_in_place(new_size); - p_image.coherence = Coherence::InSync; + let render_world = app.sub_app_mut(RenderApp).world_mut(); + render_world.resource_scope(|_, mut cache: Mut| { + let mut encoder = device.create_command_encoder(&CommandEncoderDescriptor { + label: Some("processing_resize"), + }); + // a loaded image may carry mips; scale from the full-size level + let mut from = src.create_view(&wgpu::TextureViewDescriptor { + mip_level_count: Some(1), + ..default() + }); + for step in &steps { + let to = step.create_view(&default()); + cache.copy(device, &mut encoder, &from, &to, format, filter, false); + from = to; + } + render_queue.submit(std::iter::once(encoder.finish())); + }); - p_image.readback_buffer = create_readback_buffer( - &render_device, - new_size.width, - new_size.height, - p_image.texture_format, - "Image Readback Buffer", - )?; - p_image.size = new_size; + { + let mut images = app.world_mut().resource_mut::>(); + let mut image = images + .get_mut(&handle) + .ok_or(ProcessingError::ImageNotFound)?; + image.data = None; + let descriptor = &mut image.texture_descriptor; + descriptor.size = new_size; + descriptor.mip_level_count = 1; + // loaded images aren't render targets until now + descriptor.usage |= TextureUsages::RENDER_ATTACHMENT; + } + { + let mut p_image = app + .world_mut() + .get_mut::(entity) + .ok_or(ProcessingError::ImageNotFound)?; + p_image.readback_buffer = create_readback_buffer( + &render_device, + new_size.width, + new_size.height, + format, + "Image Readback Buffer", + )?; + p_image.size = new_size; + p_image.coherence = Coherence::GpuAhead; + } + // re-prepares the asset's texture at the new size, then the result lands in it + app.update(); + let dst = gpu_image(app, entity)?; + if dst.texture_descriptor.size != new_size { + return Err(ProcessingError::ImageNotFound); + } + let dst_view = dst.texture_view.clone(); + let render_world = app.sub_app_mut(RenderApp).world_mut(); + render_world.resource_scope(|_, mut cache: Mut| { + let mut encoder = device.create_command_encoder(&CommandEncoderDescriptor { + label: Some("processing_resize_copy"), + }); + let from = scaled.create_view(&default()); + cache.copy( + device, + &mut encoder, + &from, + &dst_view, + format, + wgpu::FilterMode::Nearest, + false, + ); + render_queue.submit(std::iter::once(encoder.finish())); + }); Ok(()) } +/// Sizes to blit through: halvings while a step would shrink more than 2x, which bilinear +/// sampling would skip texels on, then `to` +fn resize_steps(from: Extent3d, to: Extent3d) -> Vec { + let (mut width, mut height) = (from.width, from.height); + let mut steps = Vec::new(); + while width > to.width * 2 || height > to.height * 2 { + if width > to.width * 2 { + width /= 2; + } + if height > to.height * 2 { + height /= 2; + } + steps.push(Extent3d { + width, + height, + depth_or_array_layers: 1, + }); + } + if steps.last() != Some(&to) { + steps.push(to); + } + steps +} + pub fn readback( In((entity, texture)): In<(Entity, Texture)>, mut p_images: Query<&mut Image>, diff --git a/crates/processing_render/src/lib.rs b/crates/processing_render/src/lib.rs index f527626..1d79f75 100644 --- a/crates/processing_render/src/lib.rs +++ b/crates/processing_render/src/lib.rs @@ -552,6 +552,11 @@ pub fn graphics_flush(graphics_entity: Entity) -> error::Result<()> { app_mut(|app| graphics::flush(app, graphics_entity)) } +/// Flush only if draws or `set` pixels are pending, for sampling the graphics as an image. +pub fn graphics_flush_pending(graphics_entity: Entity) -> error::Result<()> { + app_mut(|app| graphics::flush_pending(app, graphics_entity)) +} + /// Present the current frame to the surface. pub fn graphics_present(graphics_entity: Entity) -> error::Result<()> { app_mut(|app| graphics::present(app, graphics_entity)) @@ -1177,12 +1182,7 @@ pub async fn image_load(path: &str) -> error::Result { /// Resize an existing image to new size. pub fn image_resize(entity: Entity, new_size: Extent3d) -> error::Result<()> { - app_mut(|app| { - image::sync_cpu(app, entity)?; - app.world_mut() - .run_system_cached_with(image::resize, (entity, new_size)) - .unwrap() - }) + app_mut(|app| image::resize(app, entity, new_size)) } /// Get the pixel dimensions `(width, height)` of an image.