def bikeseat(): return [ pv.box([5.95,0.25,4.75], [6,0.75,5.25], "Grey"), pv.box([5.7,0.2,4.75], [6,0.25,5.25], "Grey"), ]
def box(image, coord, extent, color, shadow=False, finish=None): # coord is (x, y, z). extent is (width, height, depth). import povray as pr x = _format_appearance(color, finish) finish, pigment, interior = x w = image.handle.write coord1 = _coord2pr(image, coord) x, y, z = coord1 width, height, depth = extent coord2 = x + width, y - height, z - depth name = image._make_object_name() #print coord1, coord2 ns = None if not shadow: ns = pr.no_shadow() w( pr.declare( name, pr.box( pr.vector(*coord1), pr.vector(*coord2), pigment, finish, interior, ns, ))) w(pr.object_(name)) w("\n")
def bikeframe(): return [ pv.box([centerx-(bikelength/2),centery, centerz-(bikewidth/2)], [centerx+(bikelength/2), centery+bikeframeheight, centerz+(bikewidth/2)], bikeframecolor) ]
def povfile(): return [ pv.incfiles(), # pv.skysphere(), # pv.plane("y",0,"White"), bikeframe(), bikeseat(), pv.box([0,0,0],[10,2,10],"Grey"), pv.camera([4,1,3],[5,0.5,5]), pv.lightsource([5,1.9,5],"White"), ]
def text(image, text, coord, depth, fontsize, color, shadow=False, center_x=False, center_y=False, center_z=False, wrong_x=False, wrong_y=False, wrong_z=False, min_x=False, max_x=False, min_y=False, max_y=False, background=None, vertical=False, finish=None): # The coordinate should be at the upper left point of the text. # depth grows in the +z direction (toward the user). # center_x means the x-coord is at the middle, and wrong_x means # the x-coord is at the right. They should not both be True. import operator import povray as pr import graphconst as gc assert not (center_x and wrong_x) assert not (center_y and wrong_y) assert not (center_z and wrong_z) assert not (min_x and max_x) assert not (min_y and max_y) # Background should be a true value, or the color of the background. if background and not operator.isSequenceType(background): background = (1, 1, 1) assert not background or len(background) == 3 x = _format_appearance(color, finish) pr_finish, pr_pigment, pr_interior = x w = image.handle.write # Fix the coordinates. If min_x, max_x, min_y, or max_y are # given, then x or y are relative coordinates. #old_coord = coord pr_coord = _coord2pr(image, coord) x, y, z = coord pr_x, pr_y, pr_z = pr_coord if min_x or max_x: pr_x = x if min_y or max_y: pr_y = -y pr_z = pr_z - depth # povray z is flipped coord = pr_x, pr_y, pr_z # Declare the text object and apply translations. rotate = pr.rotate(0, 0, 0) if vertical: rotate = pr.rotate(0, 0, 90) name = image._make_object_name() ns = None if not shadow: ns = pr.no_shadow() w( pr.declare( name, pr.text( "FONTFILE", text, depth, 0, pr_pigment, pr_finish, pr_interior, ns, rotate, pr.scale(fontsize, fontsize, 1), pr.translate(*coord), ))) # Translate by min or max of everything drawn. x_trans = y_trans = 0 names = [x for x in image._objects if x != name] if min_x and image._objects: x = ["min_extent(%s).x" % x for x in names] x = "min(\n %s)" % ",\n ".join(x) x_trans = x elif max_x and image._objects: x = ["max_extent(%s).x" % x for x in names] x = "max(\n %s)" % ",\n ".join(x) x_trans = x if min_y and image._objects: # Convert coordinates to POV-RAY. x = ["max_extent(%s).y" % x for x in names] x = "max(\n %s)" % ",\n ".join(x) y_trans = x elif max_y and image._objects: # Hack: max_y can be an integer that indicates the number of # last objects to ignore. n = names if type(max_y) is type(0): max_y = min(max_y, len(names)) n = names[:-max_y] if n: x = ["min_extent(%s).y" % x for x in n] x = "min(\n %s)" % ",\n ".join(x) y_trans = x if x_trans or y_trans: w(pr.declare(name, pr.object_(name, pr.translate(x_trans, y_trans, 0)))) # Translate by extent. x_extent = 0 y_extent = -1 # povray coordinates are from the lower left z_extent = 0 if vertical: x_extent += 1 # Rotating will throw off the coordinates. if center_x: x_extent += -0.5 elif wrong_x: x_extent += -1.0 if center_y: y_extent += 0.5 elif wrong_y: y_extent += 1.0 if center_z: z_extent += 0.5 elif wrong_z: z_extent += 1.0 if x_extent or y_extent or z_extent: w( pr.declare( name, pr.object_( name, pr.translate_by_extent(name, x_extent, y_extent, z_extent)))) w(pr.object_(name)) # Coordinates are hard to calculate. Hope this isn't necessary. #image._add_object(name, None, None) if not background: return #background = (1, 0, 0) x = _format_appearance(background, gc.TRANSPARENT) pr_finish, pr_pigment, pr_interior = x BACKGROUND_DEPTH = 0.2 * depth coord1 = ("min_extent(%s).x" % name, "min_extent(%s).y" % name, pr_z) coord2 = ("max_extent(%s).x" % name, "max_extent(%s).y" % name, pr_z - BACKGROUND_DEPTH) w( pr.box(pr.vector(*coord1), pr.vector(*coord2), pr_pigment, pr_finish, pr_interior, pr.no_shadow())) w("\n")