def test_simple_example(self): print("\nSimple example", end="") scene = Scene("example") self.assertEqual(scene.name, "example") ruby_material = ColorMaterial(Color(255, 0, 0), Vector3d(0.1745, 0.01175, 0.01175), Vector3d(0.61424, 0.04136, 0.04136), Vector3d(0.727811, 0.626959, 0.626959), 76.8) sphere = Sphere(Vector3d(0, 0, 0), 10) object = RenderableObject(sphere, ruby_material) light = SpotLight(Vector3d(10, 10, 10)) camera = Camera(Vector3d(0, 0, -10), Vector3d(0, 0, 0), Vector3d(0, 1, 0), 60, 4 / 3, 1) scene.addObject(object) self.assertEqual(scene.objCnt, 1) scene.clearObjects() self.assertEqual(scene.objCnt, 0) scene.addLight(light) self.assertEqual(scene.lightCnt, 1) self.assertTrue(light.state) scene.setOnOffLight(0, False) self.assertFalse(light.state) scene.clearLights() self.assertEqual(scene.lightCnt, 0) scene.addCamera(camera) self.assertEqual(scene.camCnt, 1) scene.clearCameras() self.assertEqual(scene.camCnt, 0)
def test_simple_scene(self): scene = Scene("example") ruby_material = ColorMaterial(Color(255, 0, 0), Vector3d(0.1745, 0.01175, 0.01175), Vector3d(0.61424, 0.04136, 0.04136), Vector3d(0.727811, 0.626959, 0.626959), 76.8) scene.addObject( RenderableObject(Sphere(Vector3d(0, 0, 0), 3), ruby_material)) scene.addObject( RenderableObject(Sphere(Vector3d(4, 4, -4), 1), ruby_material)) scene.addLight(SpotLight(Vector3d(10, 10, -10))) scene.addLight(SpotLight(Vector3d(0, 10, -5))) scene.addCamera( Camera(Vector3d(0, 0, -15), Vector3d(0, 0, 0), Vector3d(0, 1, 0), 60, 4 / 3, 1)) image = Image(scene.frameWidth, scene.frameHeight) frames_cnt = 30 start = time.time() for i in range(frames_cnt): scene.getFrame(image) elapsed = time.time() - start print( "\nSimple case frames per second : Time = {}s, Frames = {}, FPS = {}" .format(round(elapsed, 4), frames_cnt, round(frames_cnt / elapsed, 4)), end="")
def create_scene_sample(camera_cnt=1, obj_cnt=1, light_cnt=1): scene = Scene("example") for i in range(camera_cnt): scene.addCamera( Camera(Vector3d(2 * i + 1, 3 * i + 1, 4 * i + 1), Vector3d(0, 0, 0), Vector3d(0, 1, 0), 60, 4 / 3, 1), True) ruby_material = ColorMaterial(Color(255, 0, 0), Vector3d(0.1745, 0.01175, 0.01175), Vector3d(0.61424, 0.04136, 0.04136), Vector3d(0.727811, 0.626959, 0.626959), 76.8) for i in range(obj_cnt): scene.addObject( RenderableObject(Sphere(Vector3d(i * 10), i * 5), ruby_material)) for i in range(light_cnt): scene.addLight(SpotLight(Vector3d(-i * 2, i * 4, i * 5))) return scene
def test(name="example"): width = 640 height = 480 scene = Scene(name, width, height) ruby_material = ColorMaterial(Color(255, 0, 0), Vector3d(0.1745, 0.01175, 0.01175), Vector3d(0.61424, 0.04136, 0.04136), Vector3d(0.727811, 0.626959, 0.626959), 76.8) scene.addObject(RenderableObject(Sphere(Vector3d(0), 2), ruby_material)) #scene.addObject(RenderableObject(Sphere(Vector3d(4,4,-4), 1), ruby_material)) #scene.addLight(SpotLight(Vector3d(10,10,10))) scene.addLight(SpotLight(Vector3d(5, 6, -6))) scene.addCamera( Camera(Vector3d(0, 7, 7), Vector3d(0, 0, 0), Vector3d(0, -1, 1).normalized(), 75, width * 1.0 / height, 2), True) scene.addCamera( Camera(Vector3d(0, 10, 0), Vector3d(0, 0, 0), Vector3d(0, 0, 1), 75, width * 1.0 / height, 2), False) scene.addCamera( Camera(Vector3d(10, 0, 0), Vector3d(0, 0, 0), Vector3d(0, -1, 0), 75, width * 1.0 / height, 2), False) scene.addCamera( Camera(Vector3d(0, 0, 10), Vector3d(0, 0, 0), Vector3d(0, -1, 0), 75, width * 1.0 / height, 2), False) with open(name + '.json', 'w') as f: json.dump(json.loads(repr(scene)), f) dump_scene_image(scene)
def test_simple_1000_spheres(self): scene = Scene("example") ruby_material = ColorMaterial(Color(255, 0, 0), Vector3d(0.1745, 0.01175, 0.01175), Vector3d(0.61424, 0.04136, 0.04136), Vector3d(0.727811, 0.626959, 0.626959), 76.8) x0 = -15 y0 = -15 for i in range(1000): x = x0 + i % 30 y = y0 + i // 30 z = 0 r = 0.5 scene.addObject( RenderableObject(Sphere(Vector3d(x, y, z), r), ruby_material)) scene.addLight(SpotLight(Vector3d(10, 10, -10))) scene.addCamera( Camera(Vector3d(0, 0, -25), Vector3d(0, 0, 0), Vector3d(0, 1, 0), 60, 4 / 3, 1)) image = Image(scene.frameWidth, scene.frameHeight) frames_cnt = 30 start = time.time() for i in range(frames_cnt): scene.getFrame(image) elapsed = time.time() - start print( "\n1000 spheres frames per second : Time = {}s, Frames = {}, FPS = {}" .format(round(elapsed, 4), frames_cnt, round(frames_cnt / elapsed, 4)), end="")