def obj_load(filename): V, Vi = [], [] with open(filename) as f: for line in f.readlines(): if line.startswith('#'): continue values = line.split() if not values: continue if values[0] == 'v': V.append([float(x) for x in values[1:4]]) elif values[0] == 'f': Vi.append([int(x) for x in values[1:4]]) V, Vi = np.array(V), np.array(Vi) - 1 V = glm.fit_unit_cube(V) return V, Vi
V, Vi = [], [] with open(filename) as f: for line in f.readlines(): if line.startswith('#'): continue values = line.split() if not values: continue if values[0] == 'v': V.append([float(x) for x in values[1:4]]) elif values[0] == 'f' : Vi.append([int(x) for x in values[1:4]]) return np.array(V), np.array(Vi)-1 # --- main -------------------------------------------------------------------- if __name__ == "__main__": import matplotlib.pyplot as plt fig = plt.figure(figsize=(4,4)) ax = fig.add_axes([0,0,1,1], xlim=[-1,+1], ylim=[-1,+1], aspect=1) ax.axis("off") camera = Camera("ortho", scale=2) vertices, faces = obj_load("data/bunny.obj") vertices = glm.fit_unit_cube(vertices) mesh = Mesh(ax, camera.transform, vertices, faces, cmap=plt.get_cmap("magma"), edgecolors=(0,0,0,0.25)) camera.connect(ax, mesh.update) plt.savefig("bunny.png", dpi=600) plt.show()
# --- main -------------------------------------------------------------------- if __name__ == "__main__": import matplotlib.pyplot as plt fig = plt.figure(figsize=(4, 4)) ax = fig.add_axes([0, 0, 1, 1], xlim=[-1, +1], ylim=[-1, +1], aspect=1) ax.axis("off") P = np.load("data/protein.npy") V, C, S = P["position"], P["color"], P["radius"] FC = np.ones((len(V), 4)) FC[:, :3] = C EC = np.ones((len(V), 4)) EC[:] = 0, 0, 0, .75 S = 100 + S * 300 V = glm.fit_unit_cube(V) camera = Camera("ortho", 55, -15, scale=2) scatter = Scatter(ax, camera.transform, V, facecolors=FC, edgecolors=EC, sizes=S) camera.connect(ax, scatter.update) plt.savefig("protein.png", dpi=600) plt.show()