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
107 changes: 88 additions & 19 deletions crates/processing_ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,25 +558,6 @@ pub extern "C" fn processing_mode_2d(graphics_id: u64) {
error::check(|| graphics_mode_2d(graphics_entity));
}

#[unsafe(no_mangle)]
pub extern "C" fn processing_camera_position(graphics_id: u64, x: f32, y: f32, z: f32) {
error::clear_error();
let graphics_entity = Entity::from_bits(graphics_id);
error::check(|| graphics_camera_position(graphics_entity, x, y, z));
}

#[unsafe(no_mangle)]
pub extern "C" fn processing_camera_look_at(
graphics_id: u64,
target_x: f32,
target_y: f32,
target_z: f32,
) {
error::clear_error();
let graphics_entity = Entity::from_bits(graphics_id);
error::check(|| graphics_camera_look_at(graphics_entity, target_x, target_y, target_z));
}

#[unsafe(no_mangle)]
pub extern "C" fn processing_perspective(
graphics_id: u64,
Expand Down Expand Up @@ -605,6 +586,94 @@ pub extern "C" fn processing_ortho(
error::check(|| graphics_ortho(graphics_entity, left, right, bottom, top, near, far));
}

#[unsafe(no_mangle)]
pub extern "C" fn processing_transform_set_position(entity_id: u64, x: f32, y: f32, z: f32) {
error::clear_error();
let entity = Entity::from_bits(entity_id);
error::check(|| transform_set_position(entity, x, y, z));
}

#[unsafe(no_mangle)]
pub extern "C" fn processing_transform_translate(entity_id: u64, x: f32, y: f32, z: f32) {
error::clear_error();
let entity = Entity::from_bits(entity_id);
error::check(|| transform_translate(entity, x, y, z));
}

#[unsafe(no_mangle)]
pub extern "C" fn processing_transform_set_rotation(entity_id: u64, x: f32, y: f32, z: f32) {
error::clear_error();
let entity = Entity::from_bits(entity_id);
error::check(|| transform_set_rotation(entity, x, y, z));
}

#[unsafe(no_mangle)]
pub extern "C" fn processing_transform_rotate_x(entity_id: u64, angle: f32) {
error::clear_error();
let entity = Entity::from_bits(entity_id);
error::check(|| transform_rotate_x(entity, angle));
}

#[unsafe(no_mangle)]
pub extern "C" fn processing_transform_rotate_y(entity_id: u64, angle: f32) {
error::clear_error();
let entity = Entity::from_bits(entity_id);
error::check(|| transform_rotate_y(entity, angle));
}

#[unsafe(no_mangle)]
pub extern "C" fn processing_transform_rotate_z(entity_id: u64, angle: f32) {
error::clear_error();
let entity = Entity::from_bits(entity_id);
error::check(|| transform_rotate_z(entity, angle));
}

#[unsafe(no_mangle)]
pub extern "C" fn processing_transform_rotate_axis(
entity_id: u64,
angle: f32,
axis_x: f32,
axis_y: f32,
axis_z: f32,
) {
error::clear_error();
let entity = Entity::from_bits(entity_id);
error::check(|| transform_rotate_axis(entity, angle, axis_x, axis_y, axis_z));
}

#[unsafe(no_mangle)]
pub extern "C" fn processing_transform_set_scale(entity_id: u64, x: f32, y: f32, z: f32) {
error::clear_error();
let entity = Entity::from_bits(entity_id);
error::check(|| transform_set_scale(entity, x, y, z));
}

#[unsafe(no_mangle)]
pub extern "C" fn processing_transform_scale(entity_id: u64, x: f32, y: f32, z: f32) {
error::clear_error();
let entity = Entity::from_bits(entity_id);
error::check(|| transform_scale(entity, x, y, z));
}

#[unsafe(no_mangle)]
pub extern "C" fn processing_transform_look_at(
entity_id: u64,
target_x: f32,
target_y: f32,
target_z: f32,
) {
error::clear_error();
let entity = Entity::from_bits(entity_id);
error::check(|| transform_look_at(entity, target_x, target_y, target_z));
}

#[unsafe(no_mangle)]
pub extern "C" fn processing_transform_reset(entity_id: u64) {
error::clear_error();
let entity = Entity::from_bits(entity_id);
error::check(|| transform_reset(entity));
}

pub const PROCESSING_ATTR_FORMAT_FLOAT: u8 = 1;
pub const PROCESSING_ATTR_FORMAT_FLOAT2: u8 = 2;
pub const PROCESSING_ATTR_FORMAT_FLOAT3: u8 = 3;
Expand Down
4 changes: 2 additions & 2 deletions crates/processing_pyo3/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,12 @@ impl Graphics {
}

pub fn camera_position(&self, x: f32, y: f32, z: f32) -> PyResult<()> {
graphics_camera_position(self.entity, x, y, z)
transform_set_position(self.entity, x, y, z)
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}

pub fn camera_look_at(&self, target_x: f32, target_y: f32, target_z: f32) -> PyResult<()> {
graphics_camera_look_at(self.entity, target_x, target_y, target_z)
transform_look_at(self.entity, target_x, target_y, target_z)
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))
}

Expand Down
2 changes: 2 additions & 0 deletions crates/processing_render/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ pub enum ProcessingError {
GeometryNotFound,
#[error("Layout not found")]
LayoutNotFound,
#[error("Transform not found")]
TransformNotFound,
}
29 changes: 0 additions & 29 deletions crates/processing_render/src/graphics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,35 +344,6 @@ pub fn mode_2d(
Ok(())
}

pub fn camera_position(
In((entity, x, y, z)): In<(Entity, f32, f32, f32)>,
mut transforms: Query<&mut Transform>,
) -> Result<()> {
let mut transform = transforms
.get_mut(entity)
.map_err(|_| ProcessingError::GraphicsNotFound)?;

transform.translation = Vec3::new(x, y, z);

Ok(())
}

pub fn camera_look_at(
In((entity, target_x, target_y, target_z)): In<(Entity, f32, f32, f32)>,
mut transforms: Query<&mut Transform>,
) -> Result<()> {
let mut transform = transforms
.get_mut(entity)
.map_err(|_| ProcessingError::GraphicsNotFound)?;

// TODO: allow specifying up vector?
// does anyone actually use anything other than Vec3::Y here?
let target = Vec3::new(target_x, target_y, target_z);
transform.look_at(target, Vec3::Y);

Ok(())
}

pub fn perspective(
In((
entity,
Expand Down
134 changes: 103 additions & 31 deletions crates/processing_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod graphics;
pub mod image;
pub mod render;
mod surface;
pub mod transform;

use std::{cell::RefCell, num::NonZero, path::PathBuf, sync::OnceLock};

Expand Down Expand Up @@ -483,37 +484,6 @@ pub fn graphics_mode_2d(graphics_entity: Entity) -> error::Result<()> {
})
}

pub fn graphics_camera_position(
graphics_entity: Entity,
x: f32,
y: f32,
z: f32,
) -> error::Result<()> {
app_mut(|app| {
flush(app, graphics_entity)?;
app.world_mut()
.run_system_cached_with(graphics::camera_position, (graphics_entity, x, y, z))
.unwrap()
})
}

pub fn graphics_camera_look_at(
graphics_entity: Entity,
target_x: f32,
target_y: f32,
target_z: f32,
) -> error::Result<()> {
app_mut(|app| {
flush(app, graphics_entity)?;
app.world_mut()
.run_system_cached_with(
graphics::camera_look_at,
(graphics_entity, target_x, target_y, target_z),
)
.unwrap()
})
}

pub fn graphics_perspective(
graphics_entity: Entity,
fov: f32,
Expand Down Expand Up @@ -571,6 +541,108 @@ pub fn graphics_ortho(
})
}

pub fn transform_set_position(entity: Entity, x: f32, y: f32, z: f32) -> error::Result<()> {
app_mut(|app| {
app.world_mut()
.run_system_cached_with(transform::set_position, (entity, x, y, z))
.unwrap()
})
}

pub fn transform_translate(entity: Entity, x: f32, y: f32, z: f32) -> error::Result<()> {
app_mut(|app| {
app.world_mut()
.run_system_cached_with(transform::translate, (entity, x, y, z))
.unwrap()
})
}

pub fn transform_set_rotation(entity: Entity, x: f32, y: f32, z: f32) -> error::Result<()> {
app_mut(|app| {
app.world_mut()
.run_system_cached_with(transform::set_rotation, (entity, x, y, z))
.unwrap()
})
}

pub fn transform_rotate_x(entity: Entity, angle: f32) -> error::Result<()> {
app_mut(|app| {
app.world_mut()
.run_system_cached_with(transform::rotate_x, (entity, angle))
.unwrap()
})
}

pub fn transform_rotate_y(entity: Entity, angle: f32) -> error::Result<()> {
app_mut(|app| {
app.world_mut()
.run_system_cached_with(transform::rotate_y, (entity, angle))
.unwrap()
})
}

pub fn transform_rotate_z(entity: Entity, angle: f32) -> error::Result<()> {
app_mut(|app| {
app.world_mut()
.run_system_cached_with(transform::rotate_z, (entity, angle))
.unwrap()
})
}

pub fn transform_rotate_axis(
entity: Entity,
angle: f32,
axis_x: f32,
axis_y: f32,
axis_z: f32,
) -> error::Result<()> {
app_mut(|app| {
app.world_mut()
.run_system_cached_with(
transform::rotate_axis,
(entity, angle, axis_x, axis_y, axis_z),
)
.unwrap()
})
}

pub fn transform_set_scale(entity: Entity, x: f32, y: f32, z: f32) -> error::Result<()> {
app_mut(|app| {
app.world_mut()
.run_system_cached_with(transform::set_scale, (entity, x, y, z))
.unwrap()
})
}

pub fn transform_scale(entity: Entity, x: f32, y: f32, z: f32) -> error::Result<()> {
app_mut(|app| {
app.world_mut()
.run_system_cached_with(transform::scale, (entity, x, y, z))
.unwrap()
})
}

pub fn transform_look_at(
entity: Entity,
target_x: f32,
target_y: f32,
target_z: f32,
) -> error::Result<()> {
app_mut(|app| {
app.world_mut()
.run_system_cached_with(transform::look_at, (entity, target_x, target_y, target_z))
.unwrap()
})
}

pub fn transform_reset(entity: Entity) -> error::Result<()> {
app_mut(|app| {
app.world_mut()
.run_system_cached_with(transform::reset, entity)
.unwrap()
})
}

/// Create a new image with given size and data.
pub fn image_create(
size: Extent3d,
Expand Down
Loading