def glLoadObjWireFrameUV(self, filename, scalefactor, t): model = object_loader(filename) # for vt in model.textures: # print((vt[0] * scalefactor) - 0.5, (vt[1] * scalefactor) - 0.5) # self.glVertex((vt[0] * scalefactor) - 0.5, (vt[1] * scalefactor) - 0.5) for face in model.faces: vcount = len(face) for j in range(vcount): f1 = face[j][1] f2 = face[(j + 1) % vcount][1] v1 = model.textures[f1 - 1] v2 = model.textures[f2 - 1] # print("f1, f2, v1, v2: " + str(f1) + ', ' + str(f2) +', ' + str(v1) + ', ' + str(v2)) x1 = (v1[0] * scalefactor) - t y1 = (v1[1] * scalefactor) - t x2 = (v2[0] * scalefactor) - t y2 = (v2[1] * scalefactor) - t self.glLine(x1, y1, x2, y2)
def glLoadObjWireFrame(self, filename, scalefactor): model = object_loader(filename) for face in model.faces: vcount = len(face) for j in range(vcount): f1 = face[j][0] f2 = face[(j + 1) % vcount][0] v1 = model.vertices[f1 - 1] v2 = model.vertices[f2 - 1] x1 = v1[0] * scalefactor y1 = v1[1] * scalefactor x2 = v2[0] * scalefactor y2 = v2[1] * scalefactor self.glLine(x1, y1, x2, y2)
def glLoadObj(self, filename, t=(0, 0, 0), s=(1, 1, 1), r=(0, 0, 0), intensity=1, tex=None): self.glLoadModelMatrix(t, s, r) model = object_loader(filename) if tex: self.active_tex = tex vertex_buffer = [] for face in model.faces: for fi in face: transformed_vertex = matrix_transform( VERTEX_3(*model.vertices[fi[0]]), self.ViewPortMatrix, self.ProjectionMatrix, self.ViewMatrix, self.ModelMatrix) vertex_buffer.append(transformed_vertex) if self.active_tex: for fi in face: tex_vertex = VERTEX_3(*model.textures[fi[1]]) vertex_buffer.append(tex_vertex) for fi in face: normal_vertex = VERTEX_3(*model.normals[fi[2]]) vertex_buffer.append(normal_vertex) self.active_v_array = iter(vertex_buffer) try: while True: self.glBarycentricTriangle() except StopIteration: pass
def glLoadObj(self, filename, t=(0, 0, 0), s=(1, 1, 1), intensity=1, bary=False, tex=None): model = object_loader(filename) for face in model.faces: # print('face is: ' + str(face)) vcount = len(face) if vcount == 3: f1 = face[0][0] - 1 f2 = face[1][0] - 1 f3 = face[2][0] - 1 point_A = transform(model.vertices[f1], t, s) point_B = transform(model.vertices[f2], t, s) point_C = transform(model.vertices[f3], t, s) normal = vector_normal( cross_product(sub(point_B, point_A), sub(point_C, point_A))) grey = self.glShaderIntensity(normal, intensity) # print('about to draw triangle at points: (A,B,C)' + str(point_A) + ', ' + str(point_B) + ', ' + str(point_C)) if not tex: if grey < 0: continue if bary: self.glBarycentricTriangle(point_A, point_B, point_C, color(grey, grey, grey)) else: self.glTriangle(point_A, point_B, point_C, color(grey, grey, grey)) else: tex_A = VERTEX_3(*model.textures[face[0][1] - 1]) tex_B = VERTEX_3(*model.textures[face[1][1] - 1]) tex_C = VERTEX_3(*model.textures[face[2][1] - 1]) tex_coords = (tex_A, tex_B, tex_C) tex_intensity = dot_product(normal, VERTEX_3(0, 0, intensity)) if bary: self.glBarycentricTriangle(point_A, point_B, point_C, tex=tex, tex_coords=tex_coords, intensity=tex_intensity) else: self.glTriangle(point_A, point_B, point_C, color(grey, grey, grey)) else: # we have 4 faces (asuming we have a square to paint!) f1 = face[0][0] - 1 f2 = face[1][0] - 1 f3 = face[2][0] - 1 f4 = face[3][0] - 1 # print('f1, f2, f3, f4: ' + str(f1) + ', ' + str(f2) + ', ' + str(f3) + ', ' + str(f4)) vertices = [ transform(model.vertices[f1], t, s), transform(model.vertices[f2], t, s), transform(model.vertices[f3], t, s), transform(model.vertices[f4], t, s) ] # print('vertices: ' + str(vertices)) normal = vector_normal( cross_product(sub(vertices[0], vertices[1]), sub(vertices[1], vertices[2]))) grey = self.glShaderIntensity(normal, intensity) point_A, point_B, point_C, point_D = vertices # print('about to draw 2 triangles at points: (A,B,C,D)' + str(point_A) + ', ' + str(point_B) + ', ' + str(point_C) + ', ' + str(point_D)) if not tex: if grey < 0: continue if bary: self.glBarycentricTriangle(point_A, point_B, point_C, color(grey, grey, grey)) self.glBarycentricTriangle(point_A, point_C, point_D, color(grey, grey, grey)) else: self.glTriangle(point_A, point_B, point_C, color(grey, grey, grey)) self.glTriangle(point_A, point_C, point_D, color(grey, grey, grey)) else: tex_A = VERTEX_3(*model.textures[face[0][1] - 1]) tex_B = VERTEX_3(*model.textures[face[1][1] - 1]) tex_C = VERTEX_3(*model.textures[face[2][1] - 1]) tex_D = VERTEX_3(*model.textures[face[3][1] - 1]) tex_intensity = dot_product(normal, VERTEX_3(0, 0, intensity)) if bary: tex_coords = (tex_A, tex_B, tex_C) self.glBarycentricTriangle(point_A, point_B, point_C, tex=tex, tex_coords=tex_coords, intensity=tex_intensity) tex_coords = (tex_A, tex_C, tex_D) self.glBarycentricTriangle(point_A, point_C, point_D, tex=tex, tex_coords=tex_coords, intensity=tex_intensity) else: self.glTriangle(point_A, point_B, point_C, color(grey, grey, grey)) self.glTriangle(point_A, point_C, point_D, color(grey, grey, grey))
def glLoadObj(self, filename, save_coords): model = object_loader(filename) vcount = len(model.vertices) print(vcount) self.current_polygon = [] # for vertex in model.vertices: # print(vertex) for j in range(1, vcount): v1 = model.vertices[j - 1] v2 = model.vertices[j] x1 = v1[0] y1 = v1[1] x2 = v2[0] y2 = v2[1] self.glLine(x1, y1, x2, y2, save_coords) # finish connecting last vertex and first vertex v1 = model.vertices[vcount - 1] v2 = model.vertices[0] x1 = v1[0] y1 = v1[1] x2 = v2[0] y2 = v2[1] self.glLine(x1, y1, x2, y2, save_coords) x_coords = [] for vertex in self.current_polygon: print(vertex) x_coords.append(vertex[0]) x_max = max(x_coords) x_min = min(x_coords) print('x max is: ' + str(x_max)) print('x min is: ' + str(x_min)) for y in range(x_min, x_max): vertices = list(filter(lambda x: x[0] == y, self.current_polygon)) print('vertices for x coord ' + str(y) + ' are: ' + str(vertices)) # if (len(vertices) == 2): # v1 = vertices[0] # v2 = vertices[1] # self.glLine(v1[0], v1[1], v2[0], v2[1], False) list_vcount = len(vertices) for k in range(1, list_vcount, 1): v1 = vertices[k - 1] v2 = vertices[k] x1 = v1[0] y1 = v1[1] x2 = v2[0] y2 = v2[1] self.glLine(x1, y1, x2, y2, False)