def testUVCoordinates(self): plane = Plane() ray1 = Ray(origin=Point(0, 0, 1), dir=-VEC_Z) intersection1 = plane.ray_intersection(ray1) assert intersection1.surface_point.is_close(Vec2d(0.0, 0.0)) ray2 = Ray(origin=Point(0.25, 0.75, 1), dir=-VEC_Z) intersection2 = plane.ray_intersection(ray2) assert intersection2.surface_point.is_close(Vec2d(0.25, 0.75)) ray3 = Ray(origin=Point(4.25, 7.75, 1), dir=-VEC_Z) intersection3 = plane.ray_intersection(ray3) assert intersection3.surface_point.is_close(Vec2d(0.25, 0.75))
def step_create_plane_p2_with(context): context.p2 = Plane() for row in context.table: if row['variable'] == 'material.reflective': context.p2.material.reflective = float(row['value']) if row['variable'] == 'transform': context.p2.set_transform(TRANSFORMATIONS.get(row['value']))
def testTransformation(self): plane = Plane(transformation=rotation_y(angle_deg=90.0)) ray1 = Ray(origin=Point(1, 0, 0), dir=-VEC_X) intersection1 = plane.ray_intersection(ray1) assert intersection1 assert HitRecord( world_point=Point(0.0, 0.0, 0.0), normal=Normal(1.0, 0.0, 0.0), surface_point=Vec2d(0.0, 0.0), t=1.0, ray=ray1, material=plane.material, ).is_close(intersection1) ray2 = Ray(origin=Point(0, 0, 1), dir=VEC_Z) intersection2 = plane.ray_intersection(ray2) assert not intersection2 ray3 = Ray(origin=Point(0, 0, 1), dir=VEC_X) intersection3 = plane.ray_intersection(ray3) assert not intersection3 ray4 = Ray(origin=Point(0, 0, 1), dir=VEC_Y) intersection4 = plane.ray_intersection(ray4) assert not intersection4
def parse_plane(input_file: InputStream, scene: Scene) -> Plane: expect_symbol(input_file, "(") material_name = expect_identifier(input_file) if material_name not in scene.materials.keys(): # We raise the exception here because input_file is pointing to the end of the wrong identifier raise GrammarError(input_file.location, f"unknown material {material_name}") expect_symbol(input_file, ",") transformation = parse_transformation(input_file, scene) expect_symbol(input_file, ")") return Plane(transformation=transformation, material=scene.materials[material_name])
def import_objects(self, engine): ''' Imports all objects stored in the ObjectData table according to their type. ''' for name, colour, points, lines, surfaces, position, _type, *args in self.cursor.execute( 'SELECT * FROM ObjectData'): args = [attribute for attribute in args if attribute != None] if _type == 'Cube': object_3d = Cube(name, data_handling.string_to_float_array(position), *args, colour) if _type == 'Quad': object_3d = Quad(name, data_handling.string_to_float_array(position), *args, colour) if _type == 'Plane': object_3d = Plane( name, data_handling.string_to_float_array(position), *args, colour) if _type == 'Polygon': object_3d = Polygon( name, data_handling.string_to_float_array(position), *args, colour) if _type == 'Sphere': object_3d = Sphere( name, data_handling.string_to_float_array(position), *args, colour) if _type == 'Line2D': object_3d = Line2D( name, data_handling.string_to_float_array(position), *args, colour) if _type == 'Line3D': object_3d = Line3D( name, data_handling.string_to_float_array(position), data_handling.string_to_float_array(*args), colour) object_3d.add_points( Matrix(data_handling.string_to_2d_float_array(points, 3))) object_3d.add_lines(data_handling.string_to_2d_int_array(lines, 2)) object_3d.add_surfaces( data_handling.string_to_2d_int_array(surfaces, 4)) engine.add_object(object_3d)
def step_create_plane_p(context): context.p = Plane()
def step_create_plane_s_from_yaml(context): context.s = Plane.from_yaml(context.data)
def add_plane_to_board(): global plane x, y = pygame.mouse.get_pos() plane = Plane(x, y)
MatGreen = Material(color=green, ambient=0.7, diffuse=0.6, specular=1., shinyness=80.) MatOrange = Material(color=orange, ambient=0.1, diffuse=0.9, specular=1., shinyness=80., refraction_weight=.4) MatWhite = Material(color=white, ambient=0.1, diffuse=0.9, specular=1., shinyness=80.) MatBack = Material(color=light_green, ambient=0.1, diffuse=0.9, specular=1., shinyness=80.) MatBack2 = Material(color=light_pink, ambient=0.1, diffuse=0.9, specular=1., shinyness=80.) # build shapes s1 = Sphere(np.array([170.,0.,20]), 20, MatBlue) s2 = Sphere(np.array([250.,95.,60]), 60, MatGreen) s3 = Sphere(np.array([260.,-35.,35]), 35, MatRed) s4 = Sphere(np.array([200.,-15.,45]), 5, MatOrange) s5 = Sphere(np.array([0., 0., 20.]), 20, MatRed) s6 = Sphere(np.array([-20., 10., 5.]), 5, MatOrange) s7 = Sphere(np.array([-20., -10., 5.]), 5, MatGreen) back = Plane(np.array([300., 0., 0.]), np.array([1., 0., 0.]), MatBack) right = Plane(np.array([0., -170., 0.]), np.array([0, -1., 0.]), MatBack2) left = Plane(np.array([0., 170., 0.]), np.array([0, 1., 0.]), MatBack2) b = CheckBoard(np.array([0., 0., 0.]), np.array([0., 0., 1.]), MatGray) if True: s = ShapeSet() s.addShape(s1) s.addShape(s2) s.addShape(s3) s.addShape(s4) s.addShape(b) s.addShape(back) s.addShape(right)
def _setup_path(self): # type: () -> List[np.ndarray] """ Creates a list of path transformations that position the camera around the part and orient the Z-axis towards the part's center location with the Y-axis parallel to the XY plane and X-axis pointing up. Usage: automatically called by __init__ """ x_len = self._x_scale * self._size[0] y_len = self._x_scale * self._size[1] z_len = self._z_scale * self._size[2] plane_xz1 = Plane(self._x_count, self._z_count, x_len, z_len) plane_xz2 = Plane(self._x_count, self._z_count, x_len, z_len) plane_yz1 = Plane(self._x_count, self._z_count, y_len, z_len) plane_yz2 = Plane(self._x_count, self._z_count, y_len, z_len) plane_xz1_offset = np.array( [-0.5 * x_len, 0.5 * self._size[1] + self._clearance, 0]) plane_xz2_offset = np.array( [-0.5 * x_len, -1 * (0.5 * self._size[1] + self._clearance), 0]) plane_yz1_offset = np.array( [0.5 * self._size[0] + self._clearance, -0.5 * y_len, 0]) plane_yz2_offset = np.array( [-1 * (0.5 * self._size[0] + self._clearance), -0.5 * y_len, 0]) # Find how far we can tilt each plane, scale that based on self._slope h = 0.5 * self._size[2] theta = self._slope * np.arctan(h / self._clearance) # each plane's rotation rot_xz1 = self.tf.create_rotation_matrix([theta], 'x') rot_xz2 = self.tf.create_rotation_matrix([-1 * theta], 'x') rot_yz1 = self.tf.create_rotation_matrix([0.5 * np.pi, -1 * theta], 'zy') rot_yz2 = self.tf.create_rotation_matrix([0.5 * np.pi, theta], 'zy') # combine into a transformation matrix to place planes around global origin tf_xz1 = self.tf.get_transformation(rot_xz1, plane_xz1_offset) tf_xz2 = self.tf.get_transformation(rot_xz2, plane_xz2_offset) tf_yz1 = self.tf.get_transformation(rot_yz1, plane_yz1_offset) tf_yz2 = self.tf.get_transformation(rot_yz2, plane_yz2_offset) no_rotation = np.identity(3) tf_final_offset = self.tf.get_transformation(no_rotation, [0, 0, -1 * self._offset]) # Create rotation transformations path_as_transforms = [] planes = [plane_xz1, plane_yz1, plane_xz2, plane_yz2] for i, plane in enumerate(planes): for p in plane.get_points(): # planes are just List[x,y,z], to move them around we make them info a vector # [x, y, z, 1]' and apply homogenous transforms p.append(1) point = np.asarray(p).reshape(4) # place around origin if i == 0: # xz1 point_around_origin = np.matmul(tf_xz1, point) elif i == 1: # yz1 point_around_origin = np.matmul(tf_yz1, point) elif i == 2: # xz2 point_around_origin = np.matmul(tf_xz2, point) else: # 'yz2' point_around_origin = np.matmul(tf_yz2, point) # Now that the points are spaced around the origin we can get their orientation # to describe them as a full homogeneous matrix xyz = point_around_origin[:-1] point_rot = self._get_z_axis_oriented_rotation(xyz) tf_around_origin = self.tf.get_transformation(point_rot, xyz) # place around part and apply offset tf_around_part = np.matmul(self._locator_tf, tf_around_origin) # post to move relative to each frame instead of the world frame tf_with_offset = np.matmul(tf_around_part, tf_final_offset) path_as_transforms.append(tf_with_offset) return path_as_transforms
def render_scene_with_plane(): floor = Plane() floor.set_transform(scaling(10, 0.01, 10)) # floor.set_transform( # multiply_matrix(translation(0, 0.33, 0), scaling(10, 0.01, 10))) floor.material = Material() floor.material.color = color(1, 0.9, 0.9) floor.material.specular = 0 # left_wall = Plane() # left_wall.set_transform( # multiply_matrix( # translation(0, 0, 5), # multiply_matrix(rotation_y(-pi / 4), # multiply_matrix(rotation_x(pi / 2), scaling(10, 0.01, 10))))) # left_wall.material = floor.material # right_wall = Plane() # right_wall.set_transform( # multiply_matrix( # translation(0, 0, 5), # multiply_matrix(rotation_y(pi / 4), # multiply_matrix(rotation_x(pi / 2), scaling(10, 0.01, 10))))) middle = Sphere() middle.set_transform(translation(-0.5, 1, 0.5)) middle.material = Material() middle.material.pattern = StripePattern(color(0.6, 1.0, 0.6), color(0.3, 0.6, 0.3)) middle.material.color = color(0.1, 1, 0.5) middle.material.diffuse = 0.7 middle.material.specular = 0.3 middle.material.pattern.set_transform( multiply_matrix(scaling(0.2, 0.2, 0.2), rotation_y(pi / 4))) right = Sphere() right.set_transform( multiply_matrix(translation(1.5, 0.5, -0.5), scaling(0.5, 0.5, 0.5))) right.material = Material() right.material.color = color(0.5, 1, 0.1) # right.material.diffuse = 0.7 right.material.diffuse = 0.2 right.material.specular = 0.3 right.material.reflective = 0.7 left = Sphere() left.set_transform( multiply_matrix(translation(-1.5, 0.33, -0.75), scaling(0.33, 0.33, 0.33))) left.material = Material() left.material.color = color(1, 0.8, 0.1) left.material.diffuse = 0.7 left.material.specular = 0.3 world = World() world.add_light(PointLight(point(-10, 10, -10), color(1, 1, 1))) world.objects.append(floor) # world.objects.append(left_wall) # world.objects.append(right_wall) world.objects.append(middle) world.objects.append(right) world.objects.append(left) camera = Camera(600, 500, pi / 3) camera.set_transform( view_transform(point(0, 1.5, -5), point(0, 1, 0), vector(0, 1, 0))) # camera.set_transform( # view_transform(point(0, 4, -1), point(0, 1, 0), vector(0, 1, 0))) canvas = RayTracer().render(camera, world) ppm = canvas.to_ppm() outf = open('render_scene_with_plane.ppm', 'w') outf.write(ppm)
def step_create_plane_p_with(context): context.p = Plane() set_shape_attributes(context.p, context.table)