def scene_one_triangle(device): """Create a test scene with one triangle.""" scene = fresnel.Scene(device, lights=conftest.test_lights()) geometry = fresnel.geometry.Mesh(scene, vertices=[[-1, -1, 0], [1, -1, 0], [-1, 1, 0]], N=1) geometry.color[:] = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] geometry.material = fresnel.material.Material(color=fresnel.color.linear( [1.0, 0, 0]), roughness=0.8, specular=0.5, primitive_color_mix=0.0, solid=1) geometry.outline_material = fresnel.material.Material( color=fresnel.color.linear([0, 1.0, 0]), roughness=0.8, specular=0.5, primitive_color_mix=0.0, solid=1) geometry.orientation[:] = [1, 0, 0, 0] scene.camera = fresnel.camera.Orthographic(position=(0, 0, 20), look_at=(0, 0, 0), up=(0, 1, 0), height=2.1) return scene
def scene_eight_polyhedra(device): """Create a test scene with eight polyhedra.""" scene = fresnel.Scene(device, lights=conftest.test_lights()) # place eight polyhedra position = [] for k in range(2): for i in range(2): for j in range(2): position.append([2.5 * i, 2.5 * j, 2.5 * k]) # create the polyhedron faces origins = [] normals = [] colors = [] for v in [-1, 1]: origins.append([v, 0, 0]) normals.append([v, 0, 0]) origins.append([0, v, 0]) normals.append([0, v, 0]) origins.append([0, 0, v]) normals.append([0, 0, v]) colors.append([178 / 255, 223 / 255, 138 / 255]) colors.append([178 / 255, 223 / 255, 138 / 255]) colors.append([178 / 255, 223 / 255, 138 / 255]) for x in [-1, 1]: for y in [-1, 1]: for z in [-1, 1]: normals.append([x, y, z]) origins.append([x * 0.75, y * 0.75, z * 0.75]) colors.append([166 / 255, 206 / 255, 227 / 255]) poly_info = { 'face_normal': normals, 'face_origin': origins, 'radius': math.sqrt(3), 'face_color': fresnel.color.linear(colors) } geometry = fresnel.geometry.ConvexPolyhedron(scene, poly_info, position=position) geometry.material = \ fresnel.material.Material(color=fresnel.color.linear([1.0, 0, 0]), roughness=0.8, specular=0.5, primitive_color_mix=0.0) geometry.orientation[:] = [1, 0, 0, 0] scene.camera = fresnel.camera.Orthographic(position=(20, 20, 20), look_at=(0, 0, 0), up=(0, 1, 0), height=7) return scene
def scene_box(device): """Create a test scene.""" scene = fresnel.Scene(device, lights=conftest.test_lights()) fresnel.geometry.Box(scene, [1, 2, 3, 0.4, 0.5, 0.6], box_radius=0.2, box_color=[1, 0, 1]) scene.camera = fresnel.camera.Orthographic(position=(10, 10, 10), look_at=(0, 0, 0), up=(0, 1, 0), height=4) return scene
def test_multiple_geometries(device_, generate=False): scene = fresnel.Scene(lights=conftest.test_lights()) scene.camera = fresnel.camera.orthographic(position=(0, 0, 10), look_at=(0,0,0), up=(0,1,0), height=7) geom1 = fresnel.geometry.Sphere(scene, position = [[-4, 1, 0], [-4, -1, 0], [-2, 1, 0], [-2, -1, 0]], radius=1.0) geom1.material = fresnel.material.Material(solid=1.0, color=fresnel.color.linear([0.42,0.267,1])) geom1.outline_width = 0.12 geom2 = fresnel.geometry.Sphere(scene, position = [[4, 1, 0], [4, -1, 0], [2, 1, 0], [2, -1, 0]], radius=1.0) geom2.material = fresnel.material.Material(solid=0.0, color=fresnel.color.linear([1,0.874,0.169])) buf_proxy = fresnel.preview(scene, w=200, h=100) if generate: PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(open('output/test_scene.test_multiple_geometries1.png', 'wb'), 'png'); else: conftest.assert_image_approx_equal(buf_proxy[:], 'reference/test_scene.test_multiple_geometries1.png') geom1.disable() buf_proxy = fresnel.preview(scene, w=200, h=100) if generate: PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(open('output/test_scene.test_multiple_geometries2.png', 'wb'), 'png'); else: conftest.assert_image_approx_equal(buf_proxy[:], 'reference/test_scene.test_multiple_geometries2.png') geom1.enable() buf_proxy = fresnel.preview(scene, w=200, h=100) if generate: PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(open('output/test_scene.test_multiple_geometries3.png', 'wb'), 'png'); else: conftest.assert_image_approx_equal(buf_proxy[:], 'reference/test_scene.test_multiple_geometries3.png') geom2.remove() buf_proxy = fresnel.preview(scene, w=200, h=100) if generate: PIL.Image.fromarray(buf_proxy[:], mode='RGBA').save(open('output/test_scene.test_multiple_geometries4.png', 'wb'), 'png'); else: conftest.assert_image_approx_equal(buf_proxy[:], 'reference/test_scene.test_multiple_geometries4.png')
def scene_four_spheres(device): """Create a test scene with four spheres.""" scene = fresnel.Scene(device, lights=conftest.test_lights()) mat = fresnel.material.Material( color=fresnel.color.linear([0.42, 0.267, 1])) fresnel.geometry.Sphere(scene, position=[[1, 0, 1], [1, 0, -1], [-1, 0, 1], [-1, 0, -1]], radius=1.0, material=mat, color=[[1, 0, 0], [0, 1, 0], [0, 0, 1], [1, 0, 1]]) scene.camera = fresnel.camera.Orthographic(position=(10, 10, 10), look_at=(0, 0, 0), up=(0, 1, 0), height=4) return scene
def scene_four_cylinders(device): scene = fresnel.Scene(device, lights=conftest.test_lights()) position = [[[-5, -5, 0], [-5, 5, 0]], [[5, -5, -5], [5, 5, 5]], [[3, 3, -3], [-3, -3, -3]], [[-2, 2, 2], [2, -2, -2]]] geometry = fresnel.geometry.Cylinder( scene, points=position, radius=1.0, color=[0.9, 0.9, 0.9], material=fresnel.material.Material( color=fresnel.color.linear([0.42, 0.267, 1])), ) scene.camera = fresnel.camera.orthographic(position=(0, 2, 10), look_at=(0, 0, 0), up=(0, 1, 0), height=15) return scene
def scene_rounded_polygons(device): scene = fresnel.Scene(device, lights=conftest.test_lights()) geometry = fresnel.geometry.Polygon(scene, N=2, rounding_radius=0.3, vertices=[[-1, -1], [1, -1], [1, 1], [0, 0], [-1, 1]], position=[[-1.5, 0], [1.5, 0]], angle=[0.1, -0.2], color=[[0, 0, 1], [0, 1, 0]], material=fresnel.material.Material( color=fresnel.color.linear( [0.42, 0.267, 1]), solid=1)) scene.camera = fresnel.camera.orthographic(position=(0, 0, -2), look_at=(0, 0, 0), up=(0, 1, 0), height=5) return scene
def scene_tetrahedra(device): """Create a test scene with a tetrahedron.""" scene = fresnel.Scene(device, lights=conftest.test_lights()) verts = [(1, 1, 1), (1, -1, -1), (-1, 1, -1), (-1, -1, 1)] triangles = [ verts[0], verts[1], verts[2], verts[2], verts[1], verts[3], verts[2], verts[3], verts[0], verts[1], verts[0], verts[3] ] geometry = fresnel.geometry.Mesh(scene, vertices=triangles, N=4) geometry.color[0:2, :] = [0.9, 0, 0] geometry.color[3:5, :] = [0, 0.9, 0] geometry.color[6:8, :] = [0, 0, 0.9] geometry.color[9:11, :] = [0.9, 0, 0.9] geometry.material = fresnel.material.Material(color=fresnel.color.linear( [1.0, 0, 0]), roughness=0.8, specular=0.5, primitive_color_mix=1.0, solid=0) geometry.position[:] = [[-2, -2, 0], [2, -2, 0], [2, 2, 0], [-2, 2, 0]] geometry.orientation[:] = [ [0.03723867, 0.38927173, -0.73216521, -0.55768711], [-0.32661186, 0.43644863, -0.09899935, 0.83248808], [0.25624845, 0.32632096, -0.11995704, -0.9019211], [-0.78025512, -0.12102377, 0.24947819, 0.56063877] ] scene.camera = fresnel.camera.Orthographic(position=(0, 0, -20), look_at=(0, 0, 0), up=(0, 1, 0), height=7.5) return scene
def scene_four_spheres(device): scene = fresnel.Scene(device, lights=conftest.test_lights()) position = [] for i in range(6): position.append([ 2 * math.cos(i * 2 * math.pi / 6), 2 * math.sin(i * 2 * math.pi / 6), 0 ]) geometry = fresnel.geometry.Sphere( scene, position=[[1, 0, 1], [1, 0, -1], [-1, 0, 1], [-1, 0, -1]], radius=1.0, material=fresnel.material.Material( color=fresnel.color.linear([0.42, 0.267, 1])), color=[[1, 0, 0], [0, 1, 0], [0, 0, 1], [1, 0, 1]]) scene.camera = fresnel.camera.orthographic(position=(10, 10, 10), look_at=(0, 0, 0), up=(0, 1, 0), height=4) return scene
def scene(device): """Create a test scene.""" scene = fresnel.Scene(device, lights=conftest.test_lights()) position = [] for i in range(-8, 8): for j in range(-8, 8): position.append([i, 0, j]) mat = fresnel.material.Material( color=fresnel.color.linear([0.42, 0.267, 0.9])) fresnel.geometry.Sphere( scene, position=position, radius=0.7, material=mat, ) scene.camera = fresnel.camera.Perspective(position=(0, 4, -10), look_at=(0, 0, 0), up=(0, 1, 0), focus_distance=10) return scene