def drawLine(self, point0, point1, color=(255, 255, 0, 255)): if Util.dist2(point0, point1) < 2: return middlePoint = Util.middlePoint2(point0, point1) self.drawPoint(middlePoint, color) self.drawLine(point0, middlePoint) self.drawLine(middlePoint, point1)
def main(): print("Loading meshes...") verts = [ (-1, 1, 1), (1, 1, 1), (-1, -1, 1), (1, -1, 1), (-1, 1, -1), (1, 1, -1), (1, -1, -1), (-1, -1, -1) ] faces = [ (0, 1, 2), (1, 2, 3), (1, 3, 6), (1, 5, 6), (0, 1, 4), (1, 4, 5), (2, 3, 7), (3, 6, 7), (0, 2, 7), (0, 4, 7), (4, 5, 6), (4, 6, 7), ] cube = Mesh('Cube', Util.model2np(verts), faces, (0.0, 0.0, 0.0)) camera = Camera(CAMERA_POS, (0.0, 0.0, 0.0)) device = Device() meshes = [] meshes.extend(device.createMeshesFromJSON(json.loads(open('cul.json', 'r').read()))) meshes[0].rotation = (radians(-90), 0.0, 0.0) #meshes.append(cube) meshes = [cube] print("Done!\n") fps = 60.0 frameLen = int(1.0/fps * 1000) #print(frameLen) print("Init Tk... ") root = Tk() root.resizable(False, False) root.title('3-DEEEEEEEEEEEEEEEEEEEEEE') w = Canvas(root, width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT) w.pack() device.render(camera, meshes) frame = device.getFrameImage() canvasImg = w.create_image((DEFAULT_WIDTH/2, DEFAULT_HEIGHT/2), image=frame) root.after(0, renderLoop, frameLen, camera, meshes, device, root, w, canvasImg) print("Done!\n") mainloop()
def createMeshesFromJSON(self, jsonObject): meshes = [] for mesh in jsonObject['meshes']: vertices = mesh['vertices'] faces = mesh['indices'] uvCount = mesh['uvCount'] verticesStep = 1 if uvCount == 0: verticesStep = 6 elif uvCount == 1: verticesStep = 8 elif uvCount == 2: verticesStep = 10 verticesCount = int(len(vertices) / verticesStep) facesCount = int(len(faces) / 3) verts = [] for i in range(verticesCount): x = vertices[i * verticesStep] y = vertices[i * verticesStep + 1] z = vertices[i * verticesStep + 2] verts.append((x, y, z)) feces = [] for i in range(facesCount): a = faces[i * 3] b = faces[i * 3 + 1] c = faces[i * 3 + 2] feces.append((a, b, c)) m = Mesh('Monkey', Util.model2np(verts), feces, (mesh['position'][0], mesh['position'][1], mesh['position'][2])) meshes.append(m) return meshes