git.haldean.org symrep / a2426ce
add point-based draw method Will Haldean Brown 4 years ago
2 changed file(s) with 30 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
0 import functools
01 import numpy as np
12 from symrep import *
23 from symrep.render import *
5354 solids.write_point_cloud(points, f)
5455
5556 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)
101101 glRotatef(4, 1, 0, 0)
102102
103103 glPushMatrix()
104 glRotatef(rot, 0, 1, 0)
104 glRotatef(rot, 0, 1, 0)
105105 glBegin(GL_QUADS)
106106 for quad, normal in quads:
107107 glNormal3f(*normal)
112112
113113 glPopMatrix()
114114
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)
117138 w = 800
118139 h = 800
119140 pygame.init()
120141 pygame.display.set_mode((w, h), OPENGL|DOUBLEBUF)
121142
122143 glEnable(GL_DEPTH_TEST)
123 glClearColor(.2, .2, .3, 1.)
144 glClearColor(.0, .0, .1, 1.)
124145
125146 glMatrixMode(GL_PROJECTION)
126147 glLoadIdentity()
138159 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, (1., 1., 1., 1.))
139160 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, (50.,))
140161
141 quads = voxels_to_quads(voxel_map)
142162 rot = 0
143163 while True:
144164 event = pygame.event.poll()
148168
149169 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
150170
151 draw_quads(quads, rot)
171 draw_func(rot=rot)
152172 pygame.display.flip()
153 pygame.time.wait(3)
154173 rot += 2.