@@ -4,108 +4,12 @@ use numpy::{Ix1, PyArray, PyReadonlyArray1};
44use pyo3:: prelude:: * ;
55use raydeon:: SceneLighting ;
66
7+ use crate :: camera:: Camera ;
78use crate :: light:: PointLight ;
8- use crate :: linear:: { ArbitrarySpace , Point2 , Point3 , Vec3 } ;
9+ use crate :: linear:: { ArbitrarySpace , Point2 , Point3 } ;
910use crate :: material:: Material ;
1011use crate :: shapes:: Geometry ;
1112
12- #[ derive( Debug , Clone ) ]
13- #[ pyclass( frozen) ]
14- pub ( crate ) struct Camera ( pub ( crate ) raydeon:: Camera ) ;
15-
16- impl :: std:: ops:: Deref for Camera {
17- type Target = raydeon:: Camera ;
18-
19- fn deref ( & self ) -> & Self :: Target {
20- & self . 0
21- }
22- }
23-
24- impl From < raydeon:: Camera > for Camera {
25- fn from ( value : raydeon:: Camera ) -> Self {
26- Self ( value)
27- }
28- }
29-
30- #[ pymethods]
31- impl Camera {
32- #[ new]
33- fn new ( ) -> Self {
34- raydeon:: Camera :: default ( ) . into ( )
35- }
36-
37- fn look_at (
38- & self ,
39- eye : & Bound < ' _ , PyAny > ,
40- center : & Bound < ' _ , PyAny > ,
41- up : & Bound < ' _ , PyAny > ,
42- ) -> PyResult < Camera > {
43- let eye = Point3 :: try_from ( eye) ?;
44- let center = Vec3 :: try_from ( center) ?;
45- let up = Vec3 :: try_from ( up) ?;
46- let mut ncam = self . 0 . clone ( ) ;
47- ncam. observation =
48- raydeon:: Camera :: look_at ( eye. cast_unit ( ) , center. cast_unit ( ) , up. cast_unit ( ) ) ;
49- Ok ( ncam. into ( ) )
50- }
51-
52- fn perspective ( & self , fovy : f64 , width : usize , height : usize , znear : f64 , zfar : f64 ) -> Camera {
53- let mut ncam = self . 0 . clone ( ) ;
54- ncam. perspective = raydeon:: Camera :: perspective ( fovy, width, height, znear, zfar) ;
55- ncam. into ( )
56- }
57-
58- #[ getter]
59- fn eye < ' py > ( & self , py : Python < ' py > ) -> Bound < ' py , PyArray < f64 , Ix1 > > {
60- PyArray :: from_slice_bound ( py, & self . 0 . observation . eye . to_array ( ) )
61- }
62-
63- #[ getter]
64- fn focus < ' py > ( & self , py : Python < ' py > ) -> Bound < ' py , PyArray < f64 , Ix1 > > {
65- PyArray :: from_slice_bound ( py, & self . 0 . observation . center . to_array ( ) )
66- }
67-
68- #[ getter]
69- fn up < ' py > ( & self , py : Python < ' py > ) -> Bound < ' py , PyArray < f64 , Ix1 > > {
70- PyArray :: from_slice_bound ( py, & self . 0 . observation . up . to_array ( ) )
71- }
72-
73- #[ getter]
74- fn fovy ( & self ) -> f64 {
75- self . 0 . perspective . fovy
76- }
77-
78- #[ getter]
79- fn width ( & self ) -> usize {
80- self . 0 . perspective . width
81- }
82-
83- #[ getter]
84- fn height ( & self ) -> usize {
85- self . 0 . perspective . height
86- }
87-
88- #[ getter]
89- fn aspect ( & self ) -> f64 {
90- self . 0 . perspective . aspect
91- }
92-
93- #[ getter]
94- fn znear ( & self ) -> f64 {
95- self . 0 . perspective . znear
96- }
97-
98- #[ getter]
99- fn zfar ( & self ) -> f64 {
100- self . 0 . perspective . zfar
101- }
102-
103- fn __repr__ ( slf : & Bound < ' _ , Self > ) -> PyResult < String > {
104- let class_name = slf. get_type ( ) . qualname ( ) ?;
105- Ok ( format ! ( "{}<{:?}>" , class_name, slf. borrow( ) . 0 ) )
106- }
107- }
108-
10913#[ pyclass( frozen) ]
11014pub ( crate ) struct Scene {
11115 scene : Arc < raydeon:: Scene > ,
@@ -228,14 +132,12 @@ impl LineSegment3D {
228132 ) -> PyResult < Self > {
229133 let p1 = Point3 :: try_from ( p1) ?;
230134 let p2 = Point3 :: try_from ( p2) ?;
231- Ok (
232- raydeon:: path:: LineSegment3D :: new (
233- p1. cast_unit ( ) ,
234- p2. cast_unit ( ) ,
235- material. map ( |i| i. 0 ) ,
236- )
237- . into ( ) ,
238- )
135+ Ok ( raydeon:: path:: LineSegment3D :: new ( )
136+ . p1 ( p1. cast_unit ( ) )
137+ . p2 ( p2. cast_unit ( ) )
138+ . maybe_material ( material. map ( |i| i. 0 ) )
139+ . build ( )
140+ . into ( ) )
239141 }
240142
241143 #[ getter]
@@ -255,7 +157,6 @@ impl LineSegment3D {
255157}
256158
257159pub ( crate ) fn register ( m : & Bound < ' _ , PyModule > ) -> PyResult < ( ) > {
258- m. add_class :: < Camera > ( ) ?;
259160 m. add_class :: < Scene > ( ) ?;
260161 m. add_class :: < LineSegment2D > ( ) ?;
261162 m. add_class :: < LineSegment3D > ( ) ?;
0 commit comments