git.haldean.org
add point-based draw method Will Haldean Brown 6 years ago
2 changed file(s) with 30 addition(s) and 8 deletion(s).
 0 import functools 0 1 import numpy as np 1 2 from symrep import * 2 3 from symrep.render import * 53 54 solids.write_point_cloud(points, f) 54 55 55 56 voxel_map = voxelize(points, bbox_lo, bbox_hi, 0.125) 56 show_voxels(voxel_map) 57 size = voxel_map.hi - voxel_map.lo 58 #draw_loop(functools.partial(draw_quads, voxels_to_quads(voxel_map)), size) 59 draw_loop(functools.partial(draw_points, points=points, res=0.05), size)
 101 101 glRotatef(4, 1, 0, 0) 102 102 103 103 glPushMatrix() 104 glRotatef(rot, 0, 1, 0) 104 glRotatef(rot, 0, 1, 0) 105 105 glBegin(GL_QUADS) 106 106 for quad, normal in quads: 107 107 glNormal3f(*normal) 112 112 113 113 glPopMatrix() 114 114 115 def show_voxels(voxel_map): 116 dist = -np.linalg.norm(voxel_map.hi - voxel_map.lo) 115 def draw_points(points, rot, res): 116 glPushMatrix() 117 glColor3fv((1., 0.7, 0.)) 118 glRotatef(4, 1, 0, 0) 119 120 glPushMatrix() 121 glRotatef(rot, 0, 1, 0) 122 glBegin(GL_TRIANGLES) 123 for point in points: 124 glNormal3f(1, 0, 0) 125 for delta in [[0, 0, 0], [0, res, 0], [0, 0, res]]: 126 glVertex3f(*(point[:3] + delta)) 127 # glNormal3f(0, 0, 1) 128 # for delta in [[0, 0, 0], [0, res, 0], [res, 0, 0]]: 129 # glVertex3f(*(point[:3] + delta)) 130 glEnd() 131 glPopMatrix() 132 133 glPopMatrix() 134 135 136 def draw_loop(draw_func, size): 137 dist = -np.linalg.norm(size) 117 138 w = 800 118 139 h = 800 119 140 pygame.init() 120 141 pygame.display.set_mode((w, h), OPENGL|DOUBLEBUF) 121 142 122 143 glEnable(GL_DEPTH_TEST) 123 glClearColor(.2, .2, .3, 1.) 144 glClearColor(.0, .0, .1, 1.) 124 145 125 146 glMatrixMode(GL_PROJECTION) 126 147 glLoadIdentity() 138 159 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (1., 1., 1., 1.)) 139 160 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, (50.,)) 140 161 141 quads = voxels_to_quads(voxel_map) 142 162 rot = 0 143 163 while True: 144 164 event = pygame.event.poll() 148 168 149 169 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) 150 170 151 draw_quads(quads, rot) 171 draw_func(rot=rot) 152 172 pygame.display.flip() 153 pygame.time.wait(3) 154 173 rot += 2.