1010//! functions that forward to a singleton Graphics object pub(crate) behind the scenes.
1111mod glfw;
1212mod graphics;
13+ pub ( crate ) mod material;
1314
1415use graphics:: { Geometry , Graphics , Image , Light , Topology , get_graphics, get_graphics_mut} ;
16+ use material:: Material ;
1517use pyo3:: {
1618 exceptions:: PyRuntimeError ,
1719 prelude:: * ,
@@ -27,6 +29,7 @@ fn processing(m: &Bound<'_, PyModule>) -> PyResult<()> {
2729 m. add_class :: < Image > ( ) ?;
2830 m. add_class :: < Light > ( ) ?;
2931 m. add_class :: < Topology > ( ) ?;
32+ m. add_class :: < Material > ( ) ?;
3033 m. add_function ( wrap_pyfunction ! ( size, m) ?) ?;
3134 m. add_function ( wrap_pyfunction ! ( run, m) ?) ?;
3235 m. add_function ( wrap_pyfunction ! ( mode_3d, m) ?) ?;
@@ -48,6 +51,8 @@ fn processing(m: &Bound<'_, PyModule>) -> PyResult<()> {
4851 m. add_function ( wrap_pyfunction ! ( create_directional_light, m) ?) ?;
4952 m. add_function ( wrap_pyfunction ! ( create_point_light, m) ?) ?;
5053 m. add_function ( wrap_pyfunction ! ( create_spot_light, m) ?) ?;
54+ m. add_function ( wrap_pyfunction ! ( draw_sphere, m) ?) ?;
55+ m. add_function ( wrap_pyfunction ! ( use_material, m) ?) ?;
5156
5257 Ok ( ( ) )
5358}
@@ -112,7 +117,7 @@ fn run(module: &Bound<'_, PyModule>) -> PyResult<()> {
112117 let builtins = PyModule :: import ( py, "builtins" ) ?;
113118 let locals = builtins. getattr ( "locals" ) ?. call0 ( ) ?;
114119
115- let mut setup_fn = locals. get_item ( "setup" ) ?;
120+ let setup_fn = locals. get_item ( "setup" ) ?;
116121 let mut draw_fn = locals. get_item ( "draw" ) ?;
117122
118123 // call setup
@@ -140,7 +145,7 @@ fn run(module: &Bound<'_, PyModule>) -> PyResult<()> {
140145 }
141146 }
142147
143- setup_fn = locals. get_item ( "setup" ) . unwrap ( ) . unwrap ( ) ;
148+ // setup_fn = locals.get_item("setup").unwrap().unwrap();
144149 draw_fn = locals. get_item ( "draw" ) . unwrap ( ) . unwrap ( ) ;
145150
146151 dbg ! ( locals) ;
@@ -320,3 +325,20 @@ fn create_spot_light(
320325) -> PyResult < Light > {
321326 get_graphics ( module) ?. light_spot ( r, g, b, intensity, range, radius, inner_angle, outer_angle)
322327}
328+
329+ #[ pyfunction]
330+ #[ pyo3( pass_module, signature = ( radius, sectors=32 , stacks=18 ) ) ]
331+ fn draw_sphere (
332+ module : & Bound < ' _ , PyModule > ,
333+ radius : f32 ,
334+ sectors : u32 ,
335+ stacks : u32 ,
336+ ) -> PyResult < ( ) > {
337+ get_graphics ( module) ?. draw_sphere ( radius, sectors, stacks)
338+ }
339+
340+ #[ pyfunction]
341+ #[ pyo3( pass_module, signature = ( material) ) ]
342+ fn use_material ( module : & Bound < ' _ , PyModule > , material : & Bound < ' _ , Material > ) -> PyResult < ( ) > {
343+ get_graphics ( module) ?. use_material ( & * material. extract :: < PyRef < Material > > ( ) ?)
344+ }
0 commit comments