Skip to content

Commit d0285b9

Browse files
committed
add point and spot light methods
1 parent eb6dc36 commit d0285b9

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

crates/processing_pyo3/examples/lights.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@
55
def setup():
66
size(800, 600)
77
mode_3d()
8+
9+
# Directional Light
810
dir_light = create_directional_light(0.5, 0.24, 1.0, 1500.0)
911

12+
# Point Lights
13+
point_light_a = create_point_light(1.0, 0.5, 0.25, 1000000.0, 200.0, 0.5)
14+
point_light_b = create_point_light(0.0, 0.5, 0.75, 2000000.0, 200.0, 0.25)
15+
16+
# Spot Light
17+
spot_light = create_spot_light(0.25, 0.8, 0.19, 15.0 * 1000000.0, 200.0, 0.84, 0.0, 0.7854)
18+
1019
def draw():
1120
global angle
1221
camera_position(100.0, 100.0, 300.0)

crates/processing_pyo3/src/graphics.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,48 @@ impl Graphics {
329329
Err(e) => Err(PyRuntimeError::new_err(format!("{e}"))),
330330
}
331331
}
332+
333+
pub fn light_point(
334+
&self,
335+
r: f32,
336+
g: f32,
337+
b: f32,
338+
intensity: f32,
339+
range: f32,
340+
radius: f32,
341+
) -> PyResult<Light> {
342+
let color = bevy::color::Color::srgb(r, g, b);
343+
match light_create_point(self.entity, color, intensity, range, radius) {
344+
Ok(light) => Ok(Light { entity: light }),
345+
Err(e) => Err(PyRuntimeError::new_err(format!("{e}"))),
346+
}
347+
}
348+
349+
pub fn light_spot(
350+
&self,
351+
r: f32,
352+
g: f32,
353+
b: f32,
354+
intensity: f32,
355+
range: f32,
356+
radius: f32,
357+
inner_angle: f32,
358+
outer_angle: f32,
359+
) -> PyResult<Light> {
360+
let color = bevy::color::Color::srgb(r, g, b);
361+
match light_create_spot(
362+
self.entity,
363+
color,
364+
intensity,
365+
range,
366+
radius,
367+
inner_angle,
368+
outer_angle,
369+
) {
370+
Ok(light) => Ok(Light { entity: light }),
371+
Err(e) => Err(PyRuntimeError::new_err(format!("{e}"))),
372+
}
373+
}
332374
}
333375

334376
// TODO: a real color type. or color parser? idk. color is confusing. let's think

crates/processing_pyo3/src/lib.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ fn processing(m: &Bound<'_, PyModule>) -> PyResult<()> {
4141
m.add_function(wrap_pyfunction!(image, m)?)?;
4242
m.add_function(wrap_pyfunction!(draw_geometry, m)?)?;
4343
m.add_function(wrap_pyfunction!(create_directional_light, m)?)?;
44+
m.add_function(wrap_pyfunction!(create_point_light, m)?)?;
45+
m.add_function(wrap_pyfunction!(create_spot_light, m)?)?;
4446

4547
Ok(())
4648
}
@@ -236,3 +238,33 @@ fn create_directional_light(
236238
) -> PyResult<Light> {
237239
get_graphics(module)?.light_directional(r, g, b, illuminance)
238240
}
241+
242+
#[pyfunction]
243+
#[pyo3(pass_module, signature = (r, g, b, intensity, range, radius))]
244+
fn create_point_light(
245+
module: &Bound<'_, PyModule>,
246+
r: f32,
247+
g: f32,
248+
b: f32,
249+
intensity: f32,
250+
range: f32,
251+
radius: f32,
252+
) -> PyResult<Light> {
253+
get_graphics(module)?.light_point(r, g, b, intensity, range, radius)
254+
}
255+
256+
#[pyfunction]
257+
#[pyo3(pass_module, signature = (r, g, b, intensity, range, radius, inner_angle, outer_angle))]
258+
fn create_spot_light(
259+
module: &Bound<'_, PyModule>,
260+
r: f32,
261+
g: f32,
262+
b: f32,
263+
intensity: f32,
264+
range: f32,
265+
radius: f32,
266+
inner_angle: f32,
267+
outer_angle: f32,
268+
) -> PyResult<Light> {
269+
get_graphics(module)?.light_spot(r, g, b, intensity, range, radius, inner_angle, outer_angle)
270+
}

0 commit comments

Comments
 (0)