INNER CODE UNIT · Python
CubeDrawable
mosra/magnum-examples · src/python/magnum-primitives-scenegraph.py:38
class CubeDrawable(scenegraph.Drawable3D):
def __init__(self, object: Object3D, drawables: scenegraph.DrawableGroup3D,
mesh: gl.Mesh, shader: shaders.PhongGL, color: Color4):
scenegraph.Drawable3D.__init__(self, object, drawables)
self._mesh = mesh
self._shader = shader
self.color = color # Settable from outside
def draw(self, transformation_matrix: Matrix4, camera: scenegraph.Camera3D):
self._shader.light_positions = [
Vector4(camera.camera_matrix.transform_point((-3.0, 5.0, 10.0)), 0.0)
]
self._shader.light_colors = [Color3(1.0)]
self._shader.diffuse_color = self.color
self._shader.ambient_color = Color3.from_hsv(self.color.hue(), 1.0, 0.3)
self._shader.transformation_matrix = transformation_matrix
self._shader.normal_matrix = transformation_matrix.rotation_scaling()