Closed chongxi closed 6 years ago
obj
file into triangle-only meshfilename = "constraint_cue.obj"
ofilename = 'tri_' + filename
f = open(filename)
ofile = open(ofilename, "w")
line = "#SHOULD NOT BE HERE THIS LINE IS"
while line:
line = f.readline()
if len(line) == 0: continue
if line[0] == "f":
# if the number of entries following the f is more than 3,
# write multiple face lines as all triangles
faces = []
oldindex = 1
index = line.find(" ", 2)
while index != -1:
faces.append(line[oldindex+1:index])
oldindex = index
index = line.find(" ", index+1)
# I'm assuming no faces at end of line
faces.append(line[oldindex+1:len(line)-1])
#print faces
start = 1
while start + 1 < len(faces):
ofile.write("f " + faces[0] + " " + faces[start] + " " + faces[start+1] + "\n")
start += 1
else:
ofile.write(line)
ofile.close()
f.close()
color to gray
conversion and then certain Matrixtranform()
from vispy import scene
import numpy as np
from scipy.special import sph_harm
from vispy.visuals.transforms import STTransform, MatrixTransform
from vispy.io.mesh import read_mesh
canvas = scene.SceneCanvas(keys='interactive')
view = canvas.central_widget.add_view()
(vertices, faces, vertex_colors, _) = read_mesh('tri_constraint_cue.obj')
gray_mat = np.repeat(np.array([0.5989, 0.6870, 0.4140]), 3).reshape(-1,3)
vertex_colors = abs(vertex_colors.dot(gray_mat))
transparency = np.ones((vertex_colors.shape[0], 1))
print vertex_colors
# color = np.zeros((ys.shape[0], 4)) * np.array([0,1,1,1])
N = vertex_colors.shape[0]
# gray_vertex_colors = rgb2gray(vertex_colors)
# vertex_colors[:,0] = np.linspace(0,1,N)
# vertex_colors[:,2] = vertex_colors[::-1, 0]
mesh = scene.visuals.Mesh(vertices, faces, vertex_colors, shading=None)
# mesh.ambient_light_color = vispy.color.Color('white')
view.camera = 'turntable'
maze_scale_factor = 100
transform = MatrixTransform()
# transform.rotate(angle=90, axis=(1, 0, 0))
transform.scale(scale=[100,100,100,100])
transform.translate(pos=[0, 0])
mesh.transform = transform
view.add(mesh)
canvas.show()
if __name__ == '__main__':
canvas.app.run()