Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
1 change: 0 additions & 1 deletion crates/processing_pyo3/assets

This file was deleted.

1 change: 1 addition & 0 deletions crates/processing_pyo3/examples/assets
2 changes: 1 addition & 1 deletion crates/processing_pyo3/examples/gltf_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def draw():
r = math.sin(t * 8.0) * 0.5 + 0.5
g = math.sin(t * 8.0 + 2.0) * 0.5 + 0.5
b = math.sin(t * 8.0 + 4.0) * 0.5 + 0.5
duck_mat.set_float4("base_color", r, g, b, 1.0)
duck_mat.set(base_color=[r, g, b, 1.0])

background(25)
use_material(duck_mat)
Expand Down
8 changes: 4 additions & 4 deletions crates/processing_pyo3/examples/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ def setup():
point_light.position(200.0, 200.0, 400.0)

mat = Material()
mat.set_float("roughness", 0.3)
mat.set_float("metallic", 0.8)
mat.set_float4("base_color", 1.0, 0.85, 0.57, 1.0)
mat.set(roughness=0.3)
mat.set(metallic=0.8)
mat.set(base_color=[1.0, 0.85, 0.57, 1.0])

def draw():
camera_position(0.0, 0.0, 200.0)
camera_look_at(0.0, 0.0, 0.0)
background(12, 12, 18)

use_material(mat)
draw_sphere(50.0)
sphere(50.0)

run()
1 change: 1 addition & 0 deletions crates/processing_pyo3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ fn processing(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<Material>()?;
m.add_class::<Gltf>()?;
m.add_class::<Shader>()?;
m.add_class::<Geometry>()?;
m.add_function(wrap_pyfunction!(gltf::load_gltf, m)?)?;
m.add_function(wrap_pyfunction!(size, m)?)?;
m.add_function(wrap_pyfunction!(run, m)?)?;
Expand Down
5 changes: 2 additions & 3 deletions crates/processing_render/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,13 @@ fn create_app(config: Config) -> App {
let has_sketch_file = config
.get(ConfigKey::SketchFileName)
.is_some_and(|f| !f.is_empty());
if has_sketch_file {
if let Some(sketch_path) = config.get(ConfigKey::SketchRootPath) {
if has_sketch_file
&& let Some(sketch_path) = config.get(ConfigKey::SketchRootPath) {
app.register_asset_source(
"sketch_directory",
AssetSourceBuilder::platform_default(sketch_path, None),
);
}
}

#[cfg(not(target_arch = "wasm32"))]
let plugins = DefaultPlugins
Expand Down
19 changes: 7 additions & 12 deletions crates/processing_render/src/material/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,13 @@ pub fn set_property(
}

let param_name = find_param_containing_field(&material.shader, name);
if let Some(param_name) = param_name {
if let Some(param) = material.shader.field_mut(&param_name) {
if let ReflectMut::Struct(s) = param.reflect_mut() {
if let Some(field) = s.field_mut(name) {
if let Some(param_name) = param_name
&& let Some(param) = material.shader.field_mut(&param_name)
&& let ReflectMut::Struct(s) = param.reflect_mut()
&& let Some(field) = s.field_mut(name) {
field.apply(&*reflect_value);
return Ok(());
}
}
}
}

Err(ProcessingError::UnknownMaterialProperty(name.to_string()))
}
Expand All @@ -281,13 +278,11 @@ fn material_value_to_reflect(value: &MaterialValue) -> Result<Box<dyn PartialRef

fn find_param_containing_field(shader: &DynamicShader, field_name: &str) -> Option<String> {
for i in 0..shader.field_len() {
if let Some(field) = shader.field_at(i) {
if let ReflectRef::Struct(s) = field.reflect_ref() {
if s.field(field_name).is_some() {
if let Some(field) = shader.field_at(i)
&& let ReflectRef::Struct(s) = field.reflect_ref()
&& s.field(field_name).is_some() {
return shader.name_at(i).map(|s: &str| s.to_string());
}
}
}
}
None
}
Expand Down
10 changes: 4 additions & 6 deletions crates/processing_render/src/surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
//! - macOS: `create_surface_macos`
//! - Windows: `create_surface_windows`
//! - WebAssembly: `create_surface_web`
#[cfg(any(target_os = "linux", target_arch = "wasm32"))]
use std::ffi::c_void;
#[cfg(not(target_os = "windows"))]
use std::ptr::NonNull;

use bevy::{
app::{App, Plugin},
Expand All @@ -41,6 +37,8 @@ use crate::{
image::{Image, ImageTextures},
};

use std::ptr::NonNull;

#[derive(Component, Debug, Clone)]
pub struct Surface;

Expand Down Expand Up @@ -226,15 +224,15 @@ pub fn create_surface_wayland(
HandleError::Unavailable,
));
}
let window_handle_ptr = NonNull::new(window_handle as *mut c_void).unwrap();
let window_handle_ptr = NonNull::new(window_handle as *mut std::ffi::c_void).unwrap();
let window = WaylandWindowHandle::new(window_handle_ptr);

if display_handle == 0 {
return Err(error::ProcessingError::HandleError(
HandleError::Unavailable,
));
}
let display_handle_ptr = NonNull::new(display_handle as *mut c_void).unwrap();
let display_handle_ptr = NonNull::new(display_handle as *mut std::ffi::c_void).unwrap();
let display = WaylandDisplayHandle::new(display_handle_ptr);

spawn_surface(
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn sketch() -> error::Result<()> {
let mut glfw_ctx = GlfwContext::new(width, height)?;
init(Config::default())?;

let surface = glfw_ctx.create_surface(width, height, 1.0)?;
let surface = glfw_ctx.create_surface(width, height)?;
let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?;
let box_geo = geometry_box(100.0, 100.0, 100.0)?;

Expand Down
2 changes: 1 addition & 1 deletion examples/gltf_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn sketch() -> error::Result<()> {
init(Config::default())?;

let surface = glfw_ctx.create_surface(width, height)?;
let graphics = graphics_create(surface, width, height)?;
let graphics = graphics_create(surface, width, height, TextureFormat::Rgba16Float)?;

let gltf = gltf_load(graphics, "gltf/Duck.glb")?;
let duck = gltf_geometry(gltf, "LOD3spShape")?;
Expand Down
Loading