def __init__(self): width = self.WINDOW_SIZE[0] height = self.WINDOW_SIZE[1] self.camera = PerspectiveCamera(fov=45, aspect=width / height, near=0.01, far=1000) scene = Scene(background_color=color.rgb["white"], ambient_light=(0.2, 0.2, 0.2)) light = PointLight(color=(0.8, 0.8, 0.8)) light.world_position = Vector3([2, 2, 2]) scene.add(light) self.cube_1 = CubeObject3D(1, 1, 1, name="Cube_1", color=(0.9, 0.5, 0.4)) self.cube_2 = CubeObject3D(1, 1, 1, name="Cube_2", color=(0.5, 0.9, 0.4)) self.cube_3 = CubeObject3D(1, 1, 1, name="Cube_3", color=(0.4, 0.5, 0.9)) self.cube_1.add(self.cube_2) self.cube_2.add(self.cube_3) self.cube_2.local_position = Vector3([5., 0, 0]) self.cube_3.local_position = Vector3([0, 3, 0]) self.camera.local_position = Vector3([0, 0, 30]) scene.add(self.cube_1) self.renderer = GLRenderer(scene, self.camera)
class PerformanceScene(Example): def __init__(self): GRID_SIZE = 15 width = self.WINDOW_SIZE[0] height = self.WINDOW_SIZE[1] self.camera = PerspectiveCamera(fov=45, aspect=width / height, near=1.0, far=1000) # It is very important to set auto_update to false for huge performance gain scene = Scene(background_color=color.rgb["white"], ambient_light=(0.2, 0.2, 0.2), auto_update=False) light = PointLight(color=(0.8, 0.8, 0.8)) light.world_position = Vector3([GRID_SIZE / 2., GRID_SIZE / 2., GRID_SIZE / 2.]) scene.add(light) for i in range(0, GRID_SIZE): for j in range(0, GRID_SIZE): for k in range(0, GRID_SIZE): cube = CubeObject3D(0.3, 0.3, 0.3, name="Cube(%d, %d, %d)" % (i, j, k), color=(0.9, 0.5, 0.4)) cube.local_position = [i, j, k] scene.add(cube) self.camera.local_position = Vector3([GRID_SIZE / 2. - 0.5, GRID_SIZE / 2. - 0.5, GRID_SIZE / 2. - 0.5]) # Update matrices once because auto update is disabled scene.update_world_matrix() self.renderer = GLRenderer(scene, self.camera) def update(self): rot = self.wnd.time * 40 self.camera.local_euler_angles = [0., rot % 90, 0.] self.renderer.viewport = self.wnd.viewport self.renderer.render()
class ObjectsScene(Example): def __init__(self): width = self.WINDOW_SIZE[0] height = self.WINDOW_SIZE[1] camera = PerspectiveCamera(fov=45, aspect=width / height, near=0.01, far=1000) scene = Scene(background_color=color.rgb["white"], ambient_light=(0.2, 0.2, 0.2)) light = PointLight(color=(0.8, 0.8, 0.8)) light.world_position = Vector3([0, 4, 3]) scene.add(light) line_one_y = 1 line_two_y = -1 self.cube = CubeObject3D(1, 1, 1, name="Cube", color=(0.9, 0.5, 0.4)) self.icosahedron = IcosahedronObject3D(1, name="Icosahedron", color=(0.5, 0.4, 0.9)) self.plane = PlaneObject3D(1, 1, name="Plane", color=(0.5, 0.9, 0.4)) self.circle = CircleObject3D(0.7, name="Circle", color=(0.9, 0.9, 0.3)) self.triangle = TriangleObject3D(1, 1, name="Triangle", color=(0.3, 0.9, 0.9)) self.cylinder = CylinderObject3D(0.7, 0.4, name="Cylinder", color=(0.9, 0.3, 0.9)) self.tetrahedral = TetrahedralObject3D(1, name="Tetrahedral", color=(0.3, 0.8, 0.9)) self.pyramid = PyramidObject3D(1, 1.5, name="Pyramid", color=(0.9, 0.9, 0.2)) self.cube.local_position = [2, line_one_y, 0] self.icosahedron.local_position = [-2, line_one_y, 0] self.cylinder.local_position = [0, line_one_y, 0] self.tetrahedral.local_position = [4, line_one_y, 0] self.pyramid.local_position = [-4, line_one_y, 0] self.circle.local_position = [0, line_two_y, 0] self.plane.local_position = [-2, line_two_y, 0] self.triangle.local_position = [2, line_two_y, 0] camera.local_position = Vector3([0, 0, 10]) camera.local_euler_angles = Vector3([0, 0, 0]) scene.add(self.cube) scene.add(self.plane) scene.add(self.icosahedron) scene.add(self.circle) scene.add(self.triangle) scene.add(self.cylinder) scene.add(self.tetrahedral) scene.add(self.pyramid) self.renderer = GLRenderer(scene, camera) def update(self): rot = self.wnd.time * 100 self.cube.local_euler_angles = Vector3([rot, rot, 0]) self.icosahedron.local_euler_angles = Vector3([0, rot, rot]) self.cylinder.local_euler_angles = Vector3([rot, -rot, 0]) self.tetrahedral.local_euler_angles = Vector3([rot, rot, 0]) self.pyramid.local_euler_angles = Vector3([rot, rot, 0]) self.plane.local_euler_angles = Vector3([-90, rot, math.sin(self.wnd.time) * 45]) self.circle.local_euler_angles = Vector3([-90, rot, math.sin(self.wnd.time) * 45]) self.triangle.local_euler_angles = Vector3([-90, rot, math.sin(self.wnd.time) * 45]) self.renderer.viewport = self.wnd.viewport self.renderer.render()
class HierarchyScene(Example): def __init__(self): width = self.WINDOW_SIZE[0] height = self.WINDOW_SIZE[1] self.camera = PerspectiveCamera(fov=45, aspect=width / height, near=0.01, far=1000) scene = Scene(background_color=color.rgb["white"], ambient_light=(0.2, 0.2, 0.2)) light = PointLight(color=(0.8, 0.8, 0.8)) light.world_position = Vector3([2, 2, 2]) scene.add(light) self.cube_1 = CubeObject3D(1, 1, 1, name="Cube_1", color=(0.9, 0.5, 0.4)) self.cube_2 = CubeObject3D(1, 1, 1, name="Cube_2", color=(0.5, 0.9, 0.4)) self.cube_3 = CubeObject3D(1, 1, 1, name="Cube_3", color=(0.4, 0.5, 0.9)) self.cube_1.add(self.cube_2) self.cube_2.add(self.cube_3) self.cube_2.local_position = Vector3([5., 0, 0]) self.cube_3.local_position = Vector3([0, 3, 0]) self.camera.local_position = Vector3([0, 0, 30]) scene.add(self.cube_1) self.renderer = GLRenderer(scene, self.camera) def update(self): rot = self.wnd.time * 100 scale = math.fabs(math.sin(self.wnd.time)) + 1 self.cube_1.local_euler_angles = Vector3([0, rot, 0]) self.cube_2.local_euler_angles = Vector3([0, -rot, rot]) self.cube_1.scale = Vector3([scale, scale, scale]) self.cube_2.scale = Vector3([scale, scale, scale]) * 0.5 self.cube_3.scale = Vector3([scale, scale, scale]) self.renderer.viewport = self.wnd.viewport self.renderer.render()
def __init__(self): width = self.WINDOW_SIZE[0] height = self.WINDOW_SIZE[1] camera = PerspectiveCamera(fov=45, aspect=width / height, near=0.01, far=1000) scene = Scene(background_color=(1, 1, 1), ambient_light=(0.2, 0.2, 0.2)) light = PointLight(color=(0.8, 0.8, 0.8)) light.world_position = Vector3([1, 1, 1]) scene.add(light) self.cube = CubeObject3D(1, 1, 1, color=(0.4, 0.5, 0.9)) self.cube.name = "Cube_1" camera.local_position += Vector3([0, 0, 10]) scene.add(self.cube) self.renderer = GLRenderer(scene, camera)
class SimpleScene(Example): def __init__(self): width = self.WINDOW_SIZE[0] height = self.WINDOW_SIZE[1] camera = PerspectiveCamera(fov=45, aspect=width / height, near=0.01, far=1000) scene = Scene(background_color=(1, 1, 1), ambient_light=(0.2, 0.2, 0.2)) light = PointLight(color=(0.8, 0.8, 0.8)) light.world_position = Vector3([1, 1, 1]) scene.add(light) self.cube = CubeObject3D(1, 1, 1, color=(0.4, 0.5, 0.9)) self.cube.name = "Cube_1" camera.local_position += Vector3([0, 0, 10]) scene.add(self.cube) self.renderer = GLRenderer(scene, camera) def update(self): self.renderer.viewport = self.wnd.viewport self.renderer.render() self.cube.local_euler_angles = Vector3([0, self.wnd.time * 100, 0])