Skip to content

Commit 9f9152f

Browse files
committed
Refactor light helpers to use correct naming.
1 parent a9f0774 commit 9f9152f

4 files changed

Lines changed: 44 additions & 16 deletions

File tree

crates/processing_pyo3/examples/camera_controllers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def setup():
88
mode_3d()
99
orbit_camera()
1010

11-
dir_light = create_directional_light((1.0, 0.98, 0.95), 1500.0)
11+
dir_light = directional_light((1.0, 0.98, 0.95), 1500.0)
1212
dir_light.position(300.0, 400.0, 300.0)
1313
dir_light.look_at(0.0, 0.0, 0.0)
1414

crates/processing_pyo3/examples/lights.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ def setup():
77
mode_3d()
88

99
# Directional Light
10-
dir_light = create_directional_light((0.5, 0.24, 1.0), 1500.0)
10+
dir_light = directional_light((0.5, 0.24, 1.0), 1500.0)
1111

1212
# Point Lights
13-
point_light_a = create_point_light((1.0, 0.5, 0.25), 1000000.0, 200.0, 0.5)
13+
point_light_a = point_light((1.0, 0.5, 0.25), 1000000.0, 200.0, 0.5)
1414
point_light_a.position(-25.0, 5.0, 51.0)
1515
point_light_a.look_at(0.0, 0.0, 0.0)
1616

17-
point_light_b = create_point_light((0.0, 0.5, 0.75), 2000000.0, 200.0, 0.25)
17+
point_light_b = point_light((0.0, 0.5, 0.75), 2000000.0, 200.0, 0.25)
1818
point_light_b.position(0.0, 5.0, 50.5)
1919
point_light_b.look_at(0.0, 0.0, 0.0)
2020

2121
# Spot Light
22-
spot_light = create_spot_light((0.25, 0.8, 0.19), 15.0 * 1000000.0, 200.0, 0.84, 0.0, 0.7854)
22+
spot_light = spot_light((0.25, 0.8, 0.19), 15.0 * 1000000.0, 200.0, 0.84, 0.0, 0.7854)
2323
spot_light.position(40.0, 0.0, 70.0)
2424
spot_light.look_at(0.0, 0.0, 0.0)
2525

crates/processing_pyo3/examples/materials.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ def setup():
77
size(800, 600)
88
mode_3d()
99

10-
dir_light = create_directional_light((1.0, 0.98, 0.95), 1500.0)
11-
point_light = create_point_light((1.0, 1.0, 1.0), 100000.0, 800.0, 0.0)
10+
dir_light = directional_light((1.0, 0.98, 0.95), 1500.0)
11+
point_light = point_light((1.0, 1.0, 1.0), 100000.0, 800.0, 0.0)
1212
point_light.position(200.0, 200.0, 400.0)
1313

1414
mat = Material()

crates/processing_pyo3/src/lib.rs

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,46 +1370,74 @@ mod mewnala {
13701370
graphics.create_image(width, height)
13711371
}
13721372

1373+
fn apply_light_transform(
1374+
light: &Light,
1375+
position: Option<super::math::Vec3Like>,
1376+
look_at: Option<super::math::Vec3Like>,
1377+
) -> PyResult<()> {
1378+
if let Some(p) = position {
1379+
::processing::prelude::transform_set_position(light.entity, p.into_vec3())
1380+
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
1381+
}
1382+
if let Some(la) = look_at {
1383+
::processing::prelude::transform_look_at(light.entity, la.into_vec3())
1384+
.map_err(|e| PyRuntimeError::new_err(format!("{e}")))?;
1385+
}
1386+
Ok(())
1387+
}
1388+
13731389
#[pyfunction]
1374-
#[pyo3(pass_module)]
1375-
fn create_directional_light(
1390+
#[pyo3(pass_module, signature = (color, illuminance, *, position=None, look_at=None))]
1391+
fn directional_light(
13761392
module: &Bound<'_, PyModule>,
13771393
color: super::color::ColorLike,
13781394
illuminance: f32,
1395+
position: Option<super::math::Vec3Like>,
1396+
look_at: Option<super::math::Vec3Like>,
13791397
) -> PyResult<Light> {
13801398
let graphics =
13811399
get_graphics(module)?.ok_or_else(|| PyRuntimeError::new_err("call size() first"))?;
1382-
graphics.light_directional(color, illuminance)
1400+
let light = graphics.light_directional(color, illuminance)?;
1401+
apply_light_transform(&light, position, look_at)?;
1402+
Ok(light)
13831403
}
13841404

13851405
#[pyfunction]
1386-
#[pyo3(pass_module)]
1387-
fn create_point_light(
1406+
#[pyo3(pass_module, signature = (color, intensity, range, radius, *, position=None, look_at=None))]
1407+
fn point_light(
13881408
module: &Bound<'_, PyModule>,
13891409
color: super::color::ColorLike,
13901410
intensity: f32,
13911411
range: f32,
13921412
radius: f32,
1413+
position: Option<super::math::Vec3Like>,
1414+
look_at: Option<super::math::Vec3Like>,
13931415
) -> PyResult<Light> {
13941416
let graphics =
13951417
get_graphics(module)?.ok_or_else(|| PyRuntimeError::new_err("call size() first"))?;
1396-
graphics.light_point(color, intensity, range, radius)
1418+
let light = graphics.light_point(color, intensity, range, radius)?;
1419+
apply_light_transform(&light, position, look_at)?;
1420+
Ok(light)
13971421
}
13981422

13991423
#[pyfunction]
1400-
#[pyo3(pass_module)]
1401-
fn create_spot_light(
1424+
#[pyo3(pass_module, signature = (color, intensity, range, radius, inner_angle, outer_angle, *, position=None, look_at=None))]
1425+
fn spot_light(
14021426
module: &Bound<'_, PyModule>,
14031427
color: super::color::ColorLike,
14041428
intensity: f32,
14051429
range: f32,
14061430
radius: f32,
14071431
inner_angle: f32,
14081432
outer_angle: f32,
1433+
position: Option<super::math::Vec3Like>,
1434+
look_at: Option<super::math::Vec3Like>,
14091435
) -> PyResult<Light> {
14101436
let graphics =
14111437
get_graphics(module)?.ok_or_else(|| PyRuntimeError::new_err("call size() first"))?;
1412-
graphics.light_spot(color, intensity, range, radius, inner_angle, outer_angle)
1438+
let light = graphics.light_spot(color, intensity, range, radius, inner_angle, outer_angle)?;
1439+
apply_light_transform(&light, position, look_at)?;
1440+
Ok(light)
14131441
}
14141442

14151443
#[pyfunction(name = "sphere")]

0 commit comments

Comments
 (0)