A scene containing objects and lights for 3D OpenGL rendering.
| 10 | from .render import OpenGLRenderer |
| 11 | |
| 12 | class Scene(object): |
| 13 | """A scene containing objects and lights for 3D OpenGL rendering. |
| 14 | """ |
| 15 | |
| 16 | def __init__(self, background_color=np.array([1.0, 1.0, 1.0]), |
| 17 | camera=None): |
| 18 | """Initialize a Scene object. |
| 19 | |
| 20 | Parameters |
| 21 | ---------- |
| 22 | background_color : (3,) float |
| 23 | The background color for the scene. |
| 24 | camera : :obj:`VirtualCamera` |
| 25 | Camera to use for rendering |
| 26 | """ |
| 27 | self._objects = {} |
| 28 | self._lights = {} |
| 29 | self._ambient_light = AmbientLight(np.array([0.,0.,0.]), 0.0) |
| 30 | self._background_color = background_color |
| 31 | |
| 32 | self._renderer = None |
| 33 | self.camera = camera |
| 34 | |
| 35 | @property |
| 36 | def background_color(self): |
| 37 | """(3,) float: The background color for the scene. |
| 38 | """ |
| 39 | return self._background_color |
| 40 | |
| 41 | @background_color.setter |
| 42 | def background_color(self, bgcolor): |
| 43 | self._background_color = bgcolor |
| 44 | |
| 45 | @property |
| 46 | def objects(self): |
| 47 | """dict: Dictionary mapping object names to their corresponding SceneObject. |
| 48 | """ |
| 49 | return self._objects |
| 50 | |
| 51 | @property |
| 52 | def lights(self): |
| 53 | """dict: Dictionary mapping light names to their corresponding PointLight or DirectionalLight. |
| 54 | |
| 55 | Note that this doesn't include the ambient light, since only one of those can exist at a time. |
| 56 | """ |
| 57 | return self._lights |
| 58 | |
| 59 | @property |
| 60 | def point_lights(self): |
| 61 | """list of PointLight: The set of point lights active in the scene. |
| 62 | """ |
| 63 | return [x for x in self.lights.values() if isinstance(x, PointLight)] |
| 64 | |
| 65 | @property |
| 66 | def directional_lights(self): |
| 67 | """list of DirectionalLight: The set of directional lights active in the scene. |
| 68 | """ |
| 69 | return [x for x in self.lights.values() if isinstance(x, DirectionalLight)] |