Esempio n. 1
0
 def write(self, model, current_matrix=Identity(), current_position=Vector(0,0,0), level=0):
     for obj in model.objects:
         if isinstance(obj, Piece):
             part = self.parts.part(code=obj.part)
             if part:
                 matrix = obj.matrix
                 blah = current_position + current_matrix * obj.position
                 self.write(part, current_matrix * matrix, blah, level+1)
             else: 
                 sys.stderr.write("Part not found: %s\n" % obj.part)
         elif isinstance(obj, Triangle):
             p1 = current_matrix * obj.p1 + current_position
             p2 = current_matrix * obj.p2 + current_position
             p3 = current_matrix * obj.p3 + current_position
             if abs((p3 - p1).cross(p2-p1)) !=0:
                 self._write_triangle(p1, p2, p3) 
         elif isinstance(obj, Quadrilateral):
             p1 = current_matrix * obj.p1 + current_position
             p2 = current_matrix * obj.p2 + current_position
             p3 = current_matrix * obj.p3 + current_position
             p4 = current_matrix * obj.p4 + current_position
             if abs((p3-p1).cross(p2-p1)) != 0:
                 self._write_triangle(p1,p2,p3)
             if abs((p3-p1).cross(p4-p1)) != 0:
                 self._write_triangle(p3, p4, p1) 
     #the moment of truth
     visual.faces(pos=self.positions, normal=self.normals)
Esempio n. 2
0
def drawCameraFrame():  # create frame and draw its contents
    global  cam_box, cent_plane,  cam_lab, cam_tri, range_lab, linelen, fwd_line
    global fwd_arrow, mouse_line, mouse_arrow, mouse_lab, fov, range_x, cam_dist, cam_frame
    global ray
    cam_frame = vs.frame( pos = vs.vector(0,2,2,),  axis = (0,0,1))
               # NB: contents are rel to this frame.  start with camera looking "forward"
               # origin is at simulated scene.center
    fov = vs.pi/3.0  # 60 deg 
    range_x = 6  # simulates scene.range.x  
    cam_dist = range_x / vs.tan(fov/2.0)  # distance between camera and center. 
    ray = vs.vector(-20.0, 2.5, 3.0).norm()  # (unit) direction of ray vector (arbitrary)
                                         #  REL TO CAMERA FRAME
    cam_box = vs.box(frame=cam_frame, length=1.5, height=1, width=1.0, color=clr.blue,
                                                   pos=(cam_dist,0,0)) # camera-box
    cent_plane = vs.box(frame=cam_frame, length=0.01, height=range_x*1.3, width=range_x*2,
                                                    pos=(0,0,0), opacity=0.5 )  # central plane
    cam_lab = vs.label(frame=cam_frame, text= 'U', pos= (cam_dist,0,0), height= 9, xoffset= 6)
    cam_tri = vs.faces( frame=cam_frame, pos=[(0,0,0), (0,0,-range_x), (cam_dist,0,0)])
    cam_tri.make_normals()
    cam_tri.make_twosided()
    range_lab = vs.label(frame=cam_frame, text= 'R', pos= (0, 0, -range_x), height= 9, xoffset= 6)
    linelen = scene_size + vs.mag( cam_frame.axis.norm()*cam_dist + cam_frame.pos)
                                                                   # len of lines from camera
    fwd_line = drawLine( vs.vector(cam_dist,0,0), linelen, vs.vector(-1,0,0))
    fwd_arrow = vs.arrow(frame=cam_frame, axis=(-2,0,0), pos=(cam_dist, 0, 0), shaftwidth=0.08,
                                                                            color=clr.yellow)
    vs.label(frame=cam_frame, text='C', pos=(0,0,0), height=9, xoffset=6, color=clr.yellow)
    mouse_line = drawLine ( vs.vector(cam_dist,0,0), linelen, ray ) 
    mouse_arrow = vs.arrow(frame=cam_frame, axis=ray*2, pos=(cam_dist,0,0), shaftwidth=0.08,
                                                                                   color=clr.red)
    mouse_lab = vs.label(frame=cam_frame, text= 'M', height= 9, xoffset= 10, color=clr.red, 
                                pos=  -ray*(cam_dist/vs.dot(ray,(1,0,0))) + (cam_dist,0,0))
Esempio n. 3
0
File: rmf.py Progetto: bzamecnik/gpg
def makeFaces(vertices, fillEnds=False):
    f = visual.faces(color=(1, 1, 1))
    # one end
    if fillEnds:
        f.append(pos=vertices[0][0])
        f.append(pos=vertices[0][1])
        f.append(pos=vertices[0][2])
        f.append(pos=vertices[0][0])
        f.append(pos=vertices[0][2])
        f.append(pos=vertices[0][3])
    for i in range(0, len(vertices) - 1):
        profile = vertices[i]
        profile_len = len(profile)
        next_profile = vertices[i + 1]
        for j in range(0, profile_len):
            # two triangles to make a square
            f.append(pos=profile[j % profile_len])
            f.append(pos=next_profile[j % profile_len])
            f.append(pos=next_profile[(j + 1) % profile_len])
            f.append(pos=profile[j % profile_len])
            f.append(pos=next_profile[(j + 1) % profile_len])
            f.append(pos=profile[(j + 1) % profile_len])
    # another end
    if fillEnds:
        f.append(pos=vertices[-1][0])
        f.append(pos=vertices[-1][2])
        f.append(pos=vertices[-1][1])
        f.append(pos=vertices[-1][0])
        f.append(pos=vertices[-1][3])
        f.append(pos=vertices[-1][2])
    f.make_normals()
    return f
Esempio n. 4
0
    def drawFace(self, index, frame):
        subfaces = []
        coeff = 0.2
        for i in range(len(self.vertices) - 2):
            coords0 = list(self.vertices[0].coords)
            coords1 = list(self.vertices[i + 1].coords)
            coords2 = list(self.vertices[i + 2].coords)
            for coords in [coords0, coords1, coords2]:
                coords[2] += index * coeff
            f1 = faces(pos=[coords0, coords1, coords2],
                       frame=frame,
                       color=BACK_COLOR)
            f2 = faces(pos=[coords0, coords2, coords1],
                       frame=frame,
                       color=FRONT_COLOR)
            subfaces.extend([f1, f2])

        for edge in self.edges:
            edge.drawEdge(index, coeff, frame)

        self.subfaces = subfaces
Esempio n. 5
0
def draw_camera_frame():
    """Create frame and draw its contents."""
    global  CAM_BOX, CENT_PLANE, CAM_LAB, CAN_TRI, RANGE_LAB, LINELEN, FWD_LINE
    global FWR_ARROW, MOUSE_LINE, MOUSE_ARROW, MOUSE_LAB, FOV, RANGE_X, CAM_DIST, CAM_FRAME
    global RAY
    CAM_FRAME = vs.frame(pos=vs.vector(0, 2, 2, ), axis=(0, 0, 1))
               # NB: contents are rel to this frame.  start with camera looking "forward"
               # origin is at simulated scene.center
    FOV = vs.pi/3.0  # 60 deg
    RANGE_X = 6  # simulates scene.range.x
    CAM_DIST = RANGE_X / vs.tan(FOV/2.0)  # distance between camera and center.
    RAY = vs.vector(-20.0, 2.5, 3.0).norm()  # (unit) direction of ray vector (arbitrary)
                                         #  REL TO CAMERA FRAME
    CAM_BOX = vs.box(frame=CAM_FRAME, length=1.5, height=1, width=1.0,
                     color=CLR.blue, pos=(CAM_DIST, 0, 0)) # camera-box
    CENT_PLANE = vs.box(frame=CAM_FRAME, length=0.01, height=RANGE_X*1.3,
                        width=RANGE_X*2, pos=(0, 0, 0), opacity=0.5)  # central plane
    CAM_LAB = vs.label(frame=CAM_FRAME, text='U', pos=(CAM_DIST, 0, 0),
                       height=9, xoffset=6)
    CAN_TRI = vs.faces(frame=CAM_FRAME, pos=[
        (0, 0, 0), (0, 0, -RANGE_X), (CAM_DIST, 0, 0)])
    CAN_TRI.make_normals()
    CAN_TRI.make_twosided()
    RANGE_LAB = vs.label(frame=CAM_FRAME, text='R', pos=(0, 0, -RANGE_X),
                         height=9, xoffset=6)
    LINELEN = SCENE_SIZE + vs.mag(
        CAM_FRAME.axis.norm()*CAM_DIST + CAM_FRAME.pos)  # len of lines from camera

    FWD_LINE = draw_line(vs.vector(CAM_DIST, 0, 0), LINELEN, vs.vector(-1, 0, 0))
    FWR_ARROW = vs.arrow(frame=CAM_FRAME, axis=(-2, 0, 0), pos=(CAM_DIST, 0, 0),
                         shaftwidth=0.08, color=CLR.yellow)
    vs.label(frame=CAM_FRAME, text='C', pos=(0, 0, 0), height=9, xoffset=6,
             color=CLR.yellow)
    MOUSE_LINE = draw_line(vs.vector(CAM_DIST, 0, 0), LINELEN, RAY)
    MOUSE_ARROW = vs.arrow(frame=CAM_FRAME, axis=RAY*2, pos=(CAM_DIST, 0, 0),
                           shaftwidth=0.08, color=CLR.red)
    MOUSE_LAB = vs.label(
        frame=CAM_FRAME, text='M', height=9, xoffset=10,
        color=CLR.red,
        pos=-RAY*(CAM_DIST/vs.dot(RAY, (1, 0, 0))) + (CAM_DIST, 0, 0))
Esempio n. 6
0
            if count > triangle_number:
                break
        except EOFError:
            break
    fp.close()
 
 
def load_text_stl(filename):
    global list
    for dataline in open(filename,"r").readlines():
        if not dataline.strip(): # skip blank lines
            continue
        field = dataline.split() # split with no argument makes the right place!
        if field[0] == "vertex":
            list.append([float(x) for x in field[1:4]])
            #print (list)
            #break
            #for x in field[1:4]:
                #print(x)
 
load_stl(os.path.abspath('')+'/'+file)
 
 
# Graphics
model = faces(pos=list, color=(0.8,0.8,0.8),
              material=materials.plastic) # creates triangles
# 請注意, 這裡並沒有使用 STL 檔案中的平面 normal, 而是利用 VPython make_normals() 產生
model.make_normals() # creates plane normals
model.smooth(0.93) # smooths the edges
# = AllepunkteSTL points (pos = list, size = 3, color = Color.Black) # generates points
maxHeight = random.uniform(1,5)


plasma(0,0, width, height, random.uniform(1, maxHeight), random.uniform(1, maxHeight), random.uniform(1, maxHeight), random.uniform(1, maxHeight))

p = sorted(p, key=itemgetter(0,2))
print len(p)

Res = w-1

modCheck = 0
nCheck = 0
for n in range(1, len(p)-w):
    if(n%Res != modCheck or n == nCheck):
	f1 = visual.faces(frame=f, pos=[
                           p[n],
                           p[n+1],
			   p[(n+1)+Res]] )
	f2 = visual.faces(frame=f, pos=[
                           p[n+1],
                           p[(n+2)+Res],
			   p[(n+1)+Res]] )
    
	f1.make_normals()
	f1.smooth()
	f1.make_twosided()
	f2.make_normals()
	f2.smooth()
	f2.make_twosided()
	
    else:
	modCheck += 1
Esempio n. 8
0
 def __init__(self, x, y, z, topcolor=(1,0,0), botcolor=(0,1,1)):
     self.t = vp.faces(color=topcolor)         # top, bot faces
     self.b = vp.faces(color=botcolor)
     self.move(x, y, z)          # set initial position
gridSize = 1  # size between pixels
maxHeight = random.uniform(1, 5)

plasma(0, 0, width, height, random.uniform(1, maxHeight),
       random.uniform(1, maxHeight), random.uniform(1, maxHeight),
       random.uniform(1, maxHeight))

p = sorted(p, key=itemgetter(0, 2))
print len(p)

Res = w - 1

modCheck = 0
nCheck = 0
for n in range(1, len(p) - w):
    if (n % Res != modCheck or n == nCheck):
        f1 = visual.faces(frame=f, pos=[p[n], p[n + 1], p[(n + 1) + Res]])
        f2 = visual.faces(frame=f,
                          pos=[p[n + 1], p[(n + 2) + Res], p[(n + 1) + Res]])

        f1.make_normals()
        f1.smooth()
        f1.make_twosided()
        f2.make_normals()
        f2.smooth()
        f2.make_twosided()

    else:
        modCheck += 1
        nCheck += w
Esempio n. 10
0
def drawCameraFrame():  # create frame and draw its contents
    global cam_box, cent_plane, cam_lab, cam_tri, range_lab, linelen, fwd_line
    global fwd_arrow, mouse_line, mouse_arrow, mouse_lab, fov, range_x, cam_dist, cam_frame
    global ray
    cam_frame = vs.frame(pos=vs.vector(
        0,
        2,
        2,
    ), axis=(0, 0, 1))
    # NB: contents are rel to this frame.  start with camera looking "forward"
    # origin is at simulated scene.center
    fov = vs.pi / 3.0  # 60 deg
    range_x = 6  # simulates scene.range.x
    cam_dist = range_x / vs.tan(
        fov / 2.0)  # distance between camera and center.
    ray = vs.vector(-20.0, 2.5,
                    3.0).norm()  # (unit) direction of ray vector (arbitrary)
    #  REL TO CAMERA FRAME
    cam_box = vs.box(frame=cam_frame,
                     length=1.5,
                     height=1,
                     width=1.0,
                     color=clr.blue,
                     pos=(cam_dist, 0, 0))  # camera-box
    cent_plane = vs.box(frame=cam_frame,
                        length=0.01,
                        height=range_x * 1.3,
                        width=range_x * 2,
                        pos=(0, 0, 0),
                        opacity=0.5)  # central plane
    cam_lab = vs.label(frame=cam_frame,
                       text='U',
                       pos=(cam_dist, 0, 0),
                       height=9,
                       xoffset=6)
    cam_tri = vs.faces(frame=cam_frame,
                       pos=[(0, 0, 0), (0, 0, -range_x), (cam_dist, 0, 0)])
    cam_tri.make_normals()
    cam_tri.make_twosided()
    range_lab = vs.label(frame=cam_frame,
                         text='R',
                         pos=(0, 0, -range_x),
                         height=9,
                         xoffset=6)
    linelen = scene_size + vs.mag(cam_frame.axis.norm() * cam_dist +
                                  cam_frame.pos)
    # len of lines from camera
    fwd_line = drawLine(vs.vector(cam_dist, 0, 0), linelen,
                        vs.vector(-1, 0, 0))
    fwd_arrow = vs.arrow(frame=cam_frame,
                         axis=(-2, 0, 0),
                         pos=(cam_dist, 0, 0),
                         shaftwidth=0.08,
                         color=clr.yellow)
    vs.label(frame=cam_frame,
             text='C',
             pos=(0, 0, 0),
             height=9,
             xoffset=6,
             color=clr.yellow)
    mouse_line = drawLine(vs.vector(cam_dist, 0, 0), linelen, ray)
    mouse_arrow = vs.arrow(frame=cam_frame,
                           axis=ray * 2,
                           pos=(cam_dist, 0, 0),
                           shaftwidth=0.08,
                           color=clr.red)
    mouse_lab = vs.label(frame=cam_frame,
                         text='M',
                         height=9,
                         xoffset=10,
                         color=clr.red,
                         pos=-ray * (cam_dist / vs.dot(ray, (1, 0, 0))) +
                         (cam_dist, 0, 0))
Esempio n. 11
0
                break
        except EOFError:
            break
    fp.close()


def load_text_stl(filename):
    global list
    for dataline in open(filename, "r").readlines():
        if not dataline.strip():  # skip blank lines
            continue
        field = dataline.split(
        )  # split with no argument makes the right place!
        if field[0] == "vertex":
            list.append([float(x) for x in field[1:4]])
            #print (list)
            #break
            #for x in field[1:4]:
            #print(x)


load_stl(os.path.abspath('') + '/' + file)

# Graphics
model = faces(pos=list, color=(0.8, 0.8, 0.8),
              material=materials.plastic)  # creates triangles
# 請注意, 這裡並沒有使用 STL 檔案中的平面 normal, 而是利用 VPython make_normals() 產生
model.make_normals()  # creates plane normals
model.smooth(0.93)  # smooths the edges
# = AllepunkteSTL points (pos = list, size = 3, color = Color.Black) # generates points