from visual import * infile = "cubes.obj" def cube_in_triangles(ps): fa = ps[3], ps[2], ps[1], ps[0] fb = ps[4], ps[7], ps[3], ps[0] fc = ps[0], ps[1], ps[5], ps[4] fd = ps[1], ps[2], ps[6], ps[5] fe = ps[2], ps[3], ps[7], ps[6] ff = ps[4], ps[5], ps[6], ps[7] def draw_face(f): return [f[2], f[1], f[0], f[3], f[2], f[0]] triangle_list = [] for face in [fa, fb, fc, fd, fe, ff]: triangle_list.extend(draw_face(face)) return triangle_list list_of_positions = [] file_lines = open(infile).read().strip().split("\n") vcount = 0 ccube = [] list_of_cubes = [] for line in file_lines: if line[0] == 'o': name = line.split()[1] if "cube" in name.lower(): # we found a cube print("We're starting to process ", name) if line[0] == 'v': x, y, z = [float(thing) for thing in line.split() if thing != 'v'] list_of_positions.append((x, y, z)) vcount += 1 ccube.append((x, y, z)) if vcount == 8: print len(ccube) list_of_cubes.append(ccube) ccube = [] vcount = 0 display(background=(1, 1, 1)) print(list_of_positions) for p in list_of_positions: sphere(pos=p, radius = 0.1, color=(0, 0, 0)) curve(pos=list_of_positions, radius=0.05, color=(1, 0, 0)) faces(pos=[(0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0)]) for ccube in list_of_cubes: faces(pos=cube_in_triangles(ccube), color=[(0, 1, 0) for p in list_of_positions]) # Maybe set color to something, with color=list_of_colors