def __init__(self, width=500, height=500): self.mesh_shader = load_shader('visualization/shader/mesh') trackball = Trackball(Position("position")) self.mesh_shader['transform'] = trackball trackball.theta, trackball.phi, trackball.zoom = 80, -135, 5 self.img_shader = load_shader('visualization/shader/image') self.img_shader['position'] = [(-1, -1), (-1, 1), (1, -1), (1, 1)] self.window = self.set_window(width, height) self.click = None self.click_callback = None self.key_dict = {} self.vertices = None
def mostrar(V, T, N, F_V, F_T, F_N): # Building the vertices V = np.array(V) F_V = np.array(F_V) vtype = [('position', np.float32, 3)] if len(N): N = np.array(N) F_N = np.array(F_N) vtype.append(('normal', np.float32, 3)) vertices = np.empty(len(F_V), vtype) vertices["position"] = V[F_V, :3] if len(N) and len(F_N): vertices["normal"] = N[F_N] vertices = vertices.view(gloo.VertexBuffer) # Centering and scaling to fit the unit box xmin, xmax = vertices["position"][:, 0].min(), vertices["position"][:, 0].max() ymin, ymax = vertices["position"][:, 1].min(), vertices["position"][:, 1].max() zmin, zmax = vertices["position"][:, 2].min(), vertices["position"][:, 2].max() vertices["position"][:, 0] -= (xmax + xmin) / 2.0 vertices["position"][:, 1] -= (ymax + ymin) / 2.0 vertices["position"][:, 2] -= (zmax + zmin) / 2.0 scale = max(max(xmax - xmin, ymax - ymin), zmax - zmin) / 2.0 vertices["position"] /= scale obj.bind(vertices) trackball = Trackball(Position("position")) obj['transform'] = trackball trackball.theta, trackball.phi, trackball.zoom = 90, 0, 18 window.attach(obj['transform']) app.run()
program['u_antialias'] = 1.0 # Polar domains program['u_major_grid_step'] = np.array([ 1.00, np.pi/6]) program['u_minor_grid_step'] = np.array([ 0.25, np.pi/60]) program['u_limits1'] = -5.1, +5.1, -5.1, +5.1 program['u_limits2'] = 1.0, 5.0, 0*np.pi, 2*np.pi # Cartesian domains # program['u_major_grid_step'] = np.array([ 1.00, 1.00]) # program['u_minor_grid_step'] = np.array([ 0.10, 0.10]) # program['u_limits1'] = -5.1, +5.1, -5.1, +5.1 # program['u_limits2'] = -5.0, +5.0, -5.0, +5.0 # Hammer domains # program['u_major_grid_step'] = np.array([ 1.00, 0.50]) * np.pi/ 6.0 # program['u_minor_grid_step'] = np.array([ 1.00, 0.50]) * np.pi/30.0 # program['u_limits1'] = -3.0, +3.0, -1.5, +1.5 # program['u_limits2'] = -np.pi, +np.pi, -np.pi/3, +np.pi/3 program['transform'] = shaders.get("transforms/polar.glsl") # program['transform'] = shaders.get("transforms/identity.glsl") # program['transform'] = shaders.get("transforms/hammer.glsl") program['trackball'] = Trackball(Position2D("texcoord")) program['trackball'].theta = 0 program['trackball'].phi = 0 program['trackball'].zoom = 7.5 window.attach(program['trackball']) app.run()
window = app.Window(width=1024, height=1024, color=(.75, .75, .75, 1)) @window.event def on_draw(dt): window.clear() teapot.draw(gl.GL_TRIANGLES, indices) @window.event def on_init(): gl.glEnable(gl.GL_BLEND) gl.glEnable(gl.GL_DEPTH_TEST) vertices, indices = primitives.teapot() vertices["position"] *= 10 teapot = gloo.Program(teapot_vert, teapot_frag) teapot.bind(vertices) teapot['texture'] = data.checkerboard() trackball = Trackball(Position("position"), znear=0.1, zfar=100.0, distance=50) teapot['transform'] = trackball trackball.theta = 40 trackball.phi = 135 trackball.zoom = 40 window.attach(teapot['transform']) app.run()
# program['u_minor_grid_step'] = np.array([ 0.25, np.pi/60]) # program['u_limits1'] = -5.1, +5.1, -5.1, +5.1 # program['u_limits2'] = 1.0, 5.0, 0*np.pi, 2*np.pi # Cartesian domains program['u_major_grid_step'] = np.array([1.00, 1.00]) program['u_minor_grid_step'] = np.array([0.10, 0.10]) program['u_limits1'] = -5.1, +5.1, -5.1, +5.1 program['u_limits2'] = -5.0, +5.0, -5.0, +5.0 # Hammer domains # program['u_major_grid_step'] = np.array([ 1.00, 0.50]) * np.pi/ 6.0 # program['u_minor_grid_step'] = np.array([ 1.00, 0.50]) * np.pi/30.0 # program['u_limits1'] = -3.0, +3.0, -1.5, +1.5 # program['u_limits2'] = -np.pi, +np.pi, -np.pi/3, +np.pi/3 # program['transform'] = shaders.get("transforms/polar.glsl") # program['transform'] = shaders.get("transforms/hammer.glsl") program['transform_forward'] = gloo.Snippet( library.get("transforms/identity_forward.glsl")) program['transform_inverse'] = gloo.Snippet( library.get("transforms/identity_inverse.glsl")) program['trackball'] = Trackball(Position("texcoord")) program['trackball'].theta = 0 program['trackball'].phi = 0 program['trackball'].zoom = 7.5 window.attach(program['trackball']) app.run()
'''Models''' # V, I = primitives.sphere() V, I = primitives.teapot() # V, I = primitives.cube() # V, I = primitives.cubesphere() # V, I = primitives.tube() # V, I = data.get('teapot.obj') path = '../models/bunny.obj' # V, I = data.load(path) obj = gloo.Program(vertex_shader, fragment_shader) obj.bind(V) trackball = Trackball(Position("position")) obj['transform'] = trackball trackball.theta, trackball.phi, trackball.zoom = 45, 45, 25 #40, 135, 25 '''lights''' # obj["lightPositions[0]"] = np.array((10, 10, -10)) # obj["lightPositions[1]"] = np.array((0, 5, +10)) # obj["lightPositions[2]"] = np.array((-5, 0, +10)) # obj["lightPositions[3]"] = np.array((0, -5, +10)) # obj['lightPositions'] = np.array((0,0,10)) obj['lightColors'] = np.array((1, 1, 1)) * 500 obj['camPos'] = np.array((0, 0, 5)) '''textures''' obj['albedoMap'] = np.array( Image.open( "../textures/chipped-paint-metal/chipped-paint-metal-albedo.png")) obj['normalMap'] = np.array( Image.open(
path_to_pc = join(opt.path_to_data, 'scene3d') img = io.imread(join(path_to_pc, '{0}.jpg'.format(basename)), dtype=np.float32) vertices, indices = objload(join(path_to_pc, '{0}.obj'.format(basename))) vertices['texcoord'][:, 1] = 1.0 - vertices['texcoord'][:, 1] tex_program = gloo.Program(vertex_tex, fragment_tex) tex_program.bind(vertices) tex_program['u_texture'] = img tex_program['transform'] = trackball all_programs.append(tex_program) trackball.theta, trackball.phi, trackball.zoom = -10, 0, 15 window = app.Window(width=512, height=512, color=(0.30, 0.30, 0.35, 1.00)) time_counter = 0 play_or_pause = 0 @window.event def on_draw(dt): global time_counter, n_frames, play_or_pause window.clear() field.draw(gl.GL_TRIANGLES, indices_field) all_programs[time_counter].draw(gl.GL_TRIANGLES)
framebuffer = gloo.FrameBuffer(color=[accumulation,revealage]) # Three quads quads = gloo.Program(vert_quads, frag_quads, count=12) quads["position"] = [ (-1,-1,-1), (-1,+1,-1), (+1,-1,-1), (+1,+1,-1), (-1,-1, 0), (-1,+1, 0), (+1,-1, 0), (+1,+1, 0), (-1,-1,+1), (-1,+1,+1), (+1,-1,+1), (+1,+1,+1) ] quads["position"] *= 10 quads["color"] = C1,C1,C1,C1, C2,C2,C2,C2, C3,C3,C3,C3 indices = np.zeros((3,6),dtype=np.uint32) indices[0] = 0 + np.array([0,1,2,1,2,3]) indices[1] = 4 + np.array([0,1,2,1,2,3]) indices[2] = 8 + np.array([0,1,2,1,2,3]) indices = indices.view(gloo.IndexBuffer) # Post composition post = gloo.Program(vert_post, frag_post) post['tex_accumulation'] = accumulation post['tex_revealage'] = revealage post['position'] = [(-1,-1), (-1,1), (1,-1), (1,1)] trackball = Trackball(Position("position"), znear=0.1, zfar=100.0, distance=50) quads['transform'] = trackball trackball.theta = 40 trackball.phi = 45 trackball.zoom = 40 window.attach(quads['transform']) app.run()
} vec3 color_linear = ambient_color + lambertian * diffuse_color + specular * specular_color; vec3 color_gamma = pow(color_linear, vec3(1.0/gamma)); gl_FragColor = vec4(color_gamma, 1.0); } """ log.info("Loading brain mesh") vertices,indices = data.get("brain.obj") brain = gloo.Program(vertex, fragment) brain.bind(vertices) trackball = Trackball(Position("position")) brain['transform'] = trackball trackball.theta, trackball.phi, trackball.zoom = 80, -135, 15 window = app.Window(width=1024, height=768) def update(): model = brain['transform']['model'].reshape(4,4) view = brain['transform']['view'].reshape(4,4) brain['m_view'] = view brain['m_model'] = model brain['m_normal'] = np.array(np.matrix(np.dot(view, model)).I.T) @window.event def on_draw(dt): window.clear() brain.draw(gl.GL_TRIANGLES)
@window.event def on_draw(dt): window.clear() teapot.draw(gl.GL_TRIANGLES, indices) @window.event def on_mouse_drag(x, y, dx, dy, button): update() @window.event def on_init(): gl.glEnable(gl.GL_DEPTH_TEST) update() vertices, indices = primitives.teapot() teapot = gloo.Program(vertex, fragment) teapot.bind(vertices) trackball = Trackball(Position("position")) teapot['transform'] = trackball trackball.theta, trackball.phi, trackball.zoom = 40, 135, 25 teapot["light_position[0]"] = 3, 0, 0+5 teapot["light_position[1]"] = 0, 3, 0+5 teapot["light_position[2]"] = -3, -3, +5 teapot["light_color[0]"] = 1, 0, 0 teapot["light_color[1]"] = 0, 1, 0 teapot["light_color[2]"] = 0, 0, 1 window.attach(teapot['transform']) app.run()
} vec3 color_linear = ambient_color + lambertian * diffuse_color + specular * specular_color; vec3 color_gamma = pow(color_linear, vec3(1.0/gamma)); gl_FragColor = vec4(color_gamma, 1.0); } """ log.info("Loading brain mesh") vertices, indices = data.get("brain.obj") brain = gloo.Program(vertex, fragment) brain.bind(vertices) trackball = Trackball(Position("position")) brain['transform'] = trackball trackball.theta, trackball.phi, trackball.zoom = 80, -135, 15 window = app.Window(width=1024, height=768) def update(): model = brain['transform']['model'].reshape(4, 4) view = brain['transform']['view'].reshape(4, 4) brain['m_view'] = view brain['m_model'] = model brain['m_normal'] = np.array(np.matrix(np.dot(view, model)).I.T) @window.event def on_draw(dt): window.clear()