Beispiel #1
0
def display():
    global projection, view
    global theta, phi

    theta += .43
    phi += .37
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

    model = np.eye(4, dtype=np.float32)
    rotate(model, theta, 0,0,1)
    rotate(model, phi, 0,1,0)
    shader.bind()
    shader.uniformf('u_color', 1.0, 1.0, 1.0, 1.0 )
    shader.uniform_matrixf('u_view', view)
    shader.uniform_matrixf('u_projection', projection)
    shader.uniform_matrixf('u_model', model)
    gl.glDisable( gl.GL_BLEND )
    gl.glEnable( gl.GL_DEPTH_TEST )
    gl.glEnable( gl.GL_POLYGON_OFFSET_FILL )
    obj.draw( gl.GL_TRIANGLES )
    gl.glDisable( gl.GL_POLYGON_OFFSET_FILL )
    gl.glEnable( gl.GL_BLEND );
    gl.glDepthMask( gl.GL_FALSE );
    shader.uniformf('u_color', 0.0, 0.0, 0.0, 0.25 )
    outline.draw( gl.GL_LINES )
    gl.glDepthMask( gl.GL_TRUE )
    gl.glUseProgram( 0 )

    glut.glutSwapBuffers()
Beispiel #2
0
 def update_transforms(self,event):
     self.theta += .5
     self.phi += .5
     self.model = np.eye(4, dtype=np.float32)
     rotate(self.model, self.theta, 0,0,1)
     rotate(self.model, self.phi,   0,1,0)
     self.program.uniforms['u_model'] = self.model
     self.update()
Beispiel #3
0
    def update_transforms(self, event):
        self.theta += .5
        self.phi += .5
        self.model = np.eye(4, dtype=np.float32)
        rotate(self.model, self.theta, 0, 0, 1)
        rotate(self.model, self.phi, 0, 1, 0)

        # Redraw and invoke new timer
        glut.glutTimerFunc(1000 / fps, self.update_transforms, fps)
        glut.glutPostRedisplay()
Beispiel #4
0
 def update_transforms(self, event):
     self.theta += .5
     self.phi += .5
     self.model = np.eye(4, dtype=np.float32)
     rotate(self.model, self.theta, 0,0,1)
     rotate(self.model, self.phi,   0,1,0)
     
     # Redraw and invoke new timer
     glut.glutTimerFunc(1000/fps, self.update_transforms, fps)
     glut.glutPostRedisplay()
def timer(fps):
    global theta, phi
    theta += .5
    phi += .5
    model = np.eye(4, dtype=np.float32)
    rotate(model, theta, 0,0,1)
    rotate(model, phi, 0,1,0)
    program['model'] = model
    glut.glutTimerFunc(1000/fps, timer, fps)
    glut.glutPostRedisplay()
def timer(fps):
    global theta, phi
    theta += .5
    phi += .5
    model = np.eye(4, dtype=np.float32)
    rotate(model, theta, 0, 0, 1)
    rotate(model, phi, 0, 1, 0)
    program['model'] = model
    glut.glutTimerFunc(1000 / fps, timer, fps)
    glut.glutPostRedisplay()
Beispiel #7
0
def display():
    gl.glStencilMask(255)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT
               | gl.GL_STENCIL_BUFFER_BIT)

    gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, fbo)
    shadowProgram.draw(gl.GL_TRIANGLES, indices)
    gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, 0)

    # Filled cube
    # gl.glDisable(gl.GL_BLEND)
    # gl.glEnable(gl.GL_DEPTH_TEST)
    # gl.glEnable(gl.GL_POLYGON_OFFSET_FILL)
    program['u_color'] = 1, 1, 1, 1
    program['u_scale'] = 1, 1, 1
    program['draw_shadow'] = 1
    program.draw(gl.GL_TRIANGLES, indices)

    gl.glEnable(gl.GL_STENCIL_TEST)
    gl.glStencilFunc(gl.GL_ALWAYS, 1, 255)
    gl.glStencilOp(gl.GL_KEEP, gl.GL_KEEP, gl.GL_REPLACE)
    # gl.glStencilFunc(gl.GL_NEVER, 1, 255)
    # gl.glStencilOp(gl.GL_REPLACE, gl.GL_REPLACE, gl.GL_REPLACE)
    gl.glStencilMask(255)
    gl.glDepthMask(gl.GL_FALSE)
    program2['u_color'] = 1, 1, 1, 1
    program2['u_scale'] = 1, 1, 1
    program2.draw(gl.GL_TRIANGLE_STRIP)

    gl.glStencilFunc(gl.GL_EQUAL, 1, 255)
    #gl.glStencilOp(gl.GL_KEEP, gl.GL_KEEP, gl.GL_REPLACE)
    gl.glStencilMask(0)
    gl.glDepthMask(gl.GL_TRUE)

    model = np.eye(4, dtype=np.float32)
    translate(model, 0, -2, 0)
    rotate(model, phi, 0, 1, 0)
    program['model'] = model
    program['u_color'] = 0.5, 0.5, 0.5, 1
    program['u_scale'] = 1, -1, 1
    program['draw_shadow'] = 0
    program.draw(gl.GL_TRIANGLES, indices)
    gl.glDisable(gl.GL_STENCIL_TEST)

    # Outlined cube
    # gl.glDisable(gl.GL_POLYGON_OFFSET_FILL)
    # gl.glEnable(gl.GL_BLEND)
    # gl.glDepthMask(gl.GL_FALSE)
    # program['u_color'] = 0,0,0,1
    # program.draw(gl.GL_LINES, outline)
    # gl.glDepthMask(gl.GL_TRUE)

    glut.glutSwapBuffers()
Beispiel #8
0
def timer(fps):
    global theta, phi
    theta += 0.5
    phi += 0.5
    model = np.eye(4, dtype=np.float32)
    rotate(model, theta, 0, 0, 1)
    rotate(model, phi, 0, 1, 0)
    program["u_model"] = model
    normal = np.array(np.matrix(np.dot(view, model)).I.T)
    program["u_normal"] = normal
    glut.glutTimerFunc(1000 / fps, timer, fps)
    glut.glutPostRedisplay()
def timer(fps):
    global theta, phi
    theta += .5
    phi += .5
    model = np.eye(4, dtype=np.float32)
    rotate(model, theta, 0, 0, 1)
    rotate(model, phi, 0, 1, 0)
    normal = np.array(np.matrix(np.dot(view, model)).I.T)
    program['u_model'] = model
    program['u_normal'] = normal
    glut.glutTimerFunc(1000 / fps, timer, fps)
    glut.glutPostRedisplay()
Beispiel #10
0
def display():
    gl.glStencilMask(255)
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT |
               gl.GL_STENCIL_BUFFER_BIT)

    gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, fbo)
    shadowProgram.draw(gl.GL_TRIANGLES, indices)
    gl.glBindFramebuffer(gl.GL_FRAMEBUFFER, 0)

    # Filled cube
    # gl.glDisable(gl.GL_BLEND)
    # gl.glEnable(gl.GL_DEPTH_TEST)
    # gl.glEnable(gl.GL_POLYGON_OFFSET_FILL)
    program['u_color'] = 1,1,1,1
    program['u_scale'] = 1,1,1
    program['draw_shadow'] = 1
    program.draw(gl.GL_TRIANGLES, indices)

    gl.glEnable(gl.GL_STENCIL_TEST)
    gl.glStencilFunc(gl.GL_ALWAYS, 1, 255)
    gl.glStencilOp(gl.GL_KEEP, gl.GL_KEEP, gl.GL_REPLACE)
    # gl.glStencilFunc(gl.GL_NEVER, 1, 255)
    # gl.glStencilOp(gl.GL_REPLACE, gl.GL_REPLACE, gl.GL_REPLACE)
    gl.glStencilMask(255)
    gl.glDepthMask(gl.GL_FALSE)
    program2['u_color'] = 1,1,1,1
    program2['u_scale'] = 1,1,1
    program2.draw(gl.GL_TRIANGLE_STRIP)

    gl.glStencilFunc(gl.GL_EQUAL, 1, 255);
    #gl.glStencilOp(gl.GL_KEEP, gl.GL_KEEP, gl.GL_REPLACE)
    gl.glStencilMask(0)
    gl.glDepthMask(gl.GL_TRUE)

    model = np.eye(4, dtype=np.float32)
    translate(model, 0, -2, 0)
    rotate(model, phi, 0,1,0)
    program['model'] = model
    program['u_color'] = 0.5, 0.5, 0.5, 1
    program['u_scale'] = 1,-1,1
    program['draw_shadow'] = 0
    program.draw(gl.GL_TRIANGLES, indices)
    gl.glDisable(gl.GL_STENCIL_TEST)

    # Outlined cube
    # gl.glDisable(gl.GL_POLYGON_OFFSET_FILL)
    # gl.glEnable(gl.GL_BLEND)
    # gl.glDepthMask(gl.GL_FALSE)
    # program['u_color'] = 0,0,0,1
    # program.draw(gl.GL_LINES, outline)
    # gl.glDepthMask(gl.GL_TRUE)

    glut.glutSwapBuffers()
Beispiel #11
0
def display():
    global u_projection, u_view
    global theta, phi

    theta += .23
    phi += .29
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

    u_model = np.eye(4, dtype=np.float32)
    rotate(u_model, theta, 0, 0, 1)
    rotate(u_model, phi, 0, 1, 0)
    u_viewport = gl.glGetIntegerv(gl.GL_VIEWPORT)
    u_viewport = np.array(u_viewport, dtype=np.float32)

    shader.bind()
    shader.uniformf('u_color', 1.0, 1.0, 0.0, .5)
    shader.uniform_matrixf('u_view', u_view)
    shader.uniform_matrixf('u_projection', u_projection)
    shader.uniform_matrixf('u_model', u_model)

    gl.glDisable(gl.GL_BLEND)
    gl.glColorMask(gl.GL_FALSE, gl.GL_FALSE, gl.GL_FALSE, gl.GL_FALSE)
    gl.glEnable(gl.GL_DEPTH_TEST)
    obj.draw(gl.GL_TRIANGLES)
    gl.glUseProgram(0)

    gl.glEnable(gl.GL_BLEND)
    gl.glColorMask(gl.GL_TRUE, gl.GL_TRUE, gl.GL_TRUE, gl.GL_TRUE)
    gl.glDisable(gl.GL_DEPTH_TEST)
    index, period = outline.dash_atlas['dashed']
    outline.dash_index = index
    outline.fg_color = (.5, .5, .5, 1)
    outline.draw(
        uniforms={
            'u_projection': u_projection,
            'u_model': u_model,
            'u_view': u_view,
            'u_viewport': u_viewport
        })

    gl.glEnable(gl.GL_DEPTH_TEST)
    outline.fg_color = (0, 0, 0, 1)
    index, period = outline.dash_atlas['solid']
    outline.dash_index = index
    outline.draw(
        uniforms={
            'u_projection': u_projection,
            'u_model': u_model,
            'u_view': u_view,
            'u_viewport': u_viewport
        })

    glut.glutSwapBuffers()
Beispiel #12
0
def draw():
    global camera, scene_objects, scales, command_socket, command_conn, default_box, frame_counter

    # data = command_conn.recv(1024)
    #     if not data:
    #         print("Closing connection")
    #         command_conn.close()
    #         print("Waiting for connection...")
    #         command_conn, reply_addr = command_socket.accept()
    #         print("Client connected: ", reply_addr)
    #         data = command_conn.recv(1024)
    #     plypath = pickle.loads(data)
    #plypath = "./output/output88.ply"
    plypath = "bunny2.ply"
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT)
    glEnable(GL_DEPTH_TEST)
    tr.rotate(camera.view, rotation.x, 1, 0, 0)
    tr.rotate(camera.view, rotation.y, 0, 1, 0)
    rotation.reset()
    loc = glGetUniformLocation(program, "modelViewMatrix")
    glUniformMatrix4fv(loc, 1, GL_FALSE, camera.view)
    draw_ply(plypath, size=1. / 1000)  #1.0/(frame_counter**2))
    print("Frame", frame_counter)
    frame_counter += 1
    # img = None
    #     if (img_mode&1) != 0:
    #         img = np.zeros((windowsize[0], windowsize[1], 3),np.uint8)
    #         glReadPixels(0,0,windowsize[0], windowsize[1], GL_RGB, GL_UNSIGNED_BYTE, img)
    #         img = np.flipud(img)
    #         packet = pickle.dumps(img)
    #     if (img_mode&2) != 0:
    #         depth = np.zeros(windowsize, np.float32)
    #         glReadPixels(0, 0, windowsize[0], windowsize[1], GL_DEPTH_COMPONENT, GL_FLOAT, depth)
    #         depth = np.flipud(depth)
    #         if (img_mode&1) != 0:
    #             packet = pickle.dumps((img, depth))
    #         else:
    #             packet = pickle.dumps(depth)
    #     length = struct.pack('!I', len(packet))
    #     packet = length + packet
    #     try:
    #         command_conn.send(packet)
    #     except BrokenPipeError:
    #         print("Closing connection")
    #         command_conn.close()
    #         print("Waiting for connection...")
    #         command_conn, reply_addr = command_socket.accept()
    #         print("Client connected: ", reply_addr)

    glutSwapBuffers()
Beispiel #13
0
def timer(fps):
    global theta,clock
    theta += .5

    clock += 0.01
    program["u_clock"] = clock

    model = np.eye(4, dtype=np.float32)
    rotate(model, theta, 0,0,1)
    rotate(model, -45, 1,0,0)
    normal = np.array(np.matrix(np.dot(view,model)).I.T)
    program['u_model'] = model
    program['u_normal'] = normal

    glut.glutTimerFunc(1000/fps, timer, fps)
    glut.glutPostRedisplay()
Beispiel #14
0
def timer(fps):
    global theta, clock
    theta += .5

    clock += 0.01
    program["u_clock"] = clock

    model = np.eye(4, dtype=np.float32)
    rotate(model, theta, 0, 0, 1)
    rotate(model, -45, 1, 0, 0)
    normal = np.array(np.matrix(np.dot(view, model)).I.T)
    program['u_model'] = model
    program['u_normal'] = normal

    glut.glutTimerFunc(1000 / fps, timer, fps)
    glut.glutPostRedisplay()
def on_display():
    global theta, phi
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

    theta += .04
    phi += .03
    u_view[...] = np.identity(4,dtype=np.float32)
    rotate(u_view, theta, 0,1,0)
    rotate(u_view, phi, 1,0,0)
    translate(u_view, 0,0,-5)
    u_viewport = gl.glGetIntegerv( gl.GL_VIEWPORT )
    u_viewport = np.array(u_viewport,dtype=np.float32)
    lines.draw( uniforms= {'u_projection': u_projection,
                           'u_model' :     u_model,
                           'u_view' :      u_view,
                           'u_viewport' :  u_viewport})

    glut.glutSwapBuffers()
Beispiel #16
0
    def render(self, t):
        gl.glEnable(gl.GL_DEPTH_TEST)
        gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)

        M = np.eye(4, dtype=np.float32)
        #transforms.rotate(M, t*20, 0, 1, 0)
        #transforms.rotate(M, t*20, 1, 0, 0)
        transforms.scale(M, .5, .5, .5)
        transforms.translate(M, 0, 0, -2)

        transforms.rotate(M, 00, 1, 0, 0)
        transforms.scale(M, .4, .4, .4)
        transforms.translate(M, 0, 0, -10)

        projection = pyrr.matrix44.create_perspective_projection(
            3, 1, 0.001, 10000)
        self.tree.setProjection(projection)
        self.tree.setModelView(M)
        self.tree.render()
        #        self.lt.render()
        gl.glDisable(gl.GL_DEPTH_TEST)
Beispiel #17
0
def on_display():
    global theta, phi
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

    theta += .04
    phi += .03
    u_view[...] = np.identity(4, dtype=np.float32)
    rotate(u_view, theta, 0, 1, 0)
    rotate(u_view, phi, 1, 0, 0)
    translate(u_view, 0, 0, -5)
    u_viewport = gl.glGetIntegerv(gl.GL_VIEWPORT)
    u_viewport = np.array(u_viewport, dtype=np.float32)
    lines.draw(
        uniforms={
            'u_projection': u_projection,
            'u_model': u_model,
            'u_view': u_view,
            'u_viewport': u_viewport
        })

    glut.glutSwapBuffers()
Beispiel #18
0
def display():
    global projection, view
    global theta, phi

    theta += .5
    phi += .5


    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

    model = np.eye(4, dtype=np.float32)
    rotate(model, theta, 0,0,1)
    rotate(model, phi, 0,1,0)

    shader.bind()
    shader.uniform_matrixf('u_view', view)
    shader.uniform_matrixf('u_projection', projection)
    shader.uniform_matrixf('u_model', model)

    gl.glDisable( gl.GL_BLEND )
    gl.glEnable( gl.GL_DEPTH_TEST )
    gl.glEnable( gl.GL_POLYGON_OFFSET_FILL )

    shader.uniformf('u_color', 1.0, 1.0, 1.0, 1.0 )
    cube.draw( gl.GL_TRIANGLES )

    gl.glDisable( gl.GL_POLYGON_OFFSET_FILL )
    gl.glEnable( gl.GL_BLEND );
    gl.glDepthMask( gl.GL_FALSE );

    shader.uniformf('u_color', 0.0, 0.0, 0.0, 0.5 )
    outline.draw( gl.GL_LINES )

    gl.glDepthMask( gl.GL_TRUE )
    gl.glUseProgram( 0 )

    glut.glutSwapBuffers()
Beispiel #19
0
def display():
    global projection, view
    global theta, phi

    theta += .025
    phi += .025
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
    

    u_model = np.eye(4, dtype=np.float32)
    rotate(u_model, theta, 0,0,1)
    rotate(u_model, phi, 0,1,0)
    translate(u_model, 0,0,-5)

    shader.bind()
    shader.uniformf('u_color', 1.0, 1.0, 1.0, 1.0 )
    shader.uniform_matrixf('u_view', u_view)
    shader.uniform_matrixf('u_projection', u_projection)
    shader.uniform_matrixf('u_model', u_model)
    gl.glEnable( gl.GL_POLYGON_OFFSET_FILL )
    obj.draw( gl.GL_TRIANGLES )
    gl.glDisable( gl.GL_POLYGON_OFFSET_FILL )
    gl.glDepthMask( gl.GL_FALSE );
    shader.uniformf('u_color', 0.0, 0.0, 0.0, 0.1 )
    outline.draw( gl.GL_LINES )
    gl.glDepthMask( gl.GL_TRUE )
    gl.glUseProgram( 0 )


    u_model = np.identity(4,dtype=np.float32)
    rotate(u_model, theta, 0,1,0)
    rotate(u_model, phi, 1,0,0)
    translate(u_model, 0,0,-5)
    u_viewport = gl.glGetIntegerv( gl.GL_VIEWPORT )
    u_viewport = np.array(u_viewport,dtype=np.float32)
    lines.draw( uniforms= {'u_projection': u_projection,
                           'u_model' :     u_model,
                           'u_view' :      u_view,
                           'u_viewport' :  u_viewport})

    glut.glutSwapBuffers()
Beispiel #20
0
    4, 3, 7, 3, 2, 4, 7, 6, 4, 6, 5
]
indices = IndexBuffer(I)

O = [0, 1, 1, 2, 2, 3, 3, 0, 4, 7, 7, 6, 6, 5, 5, 4, 0, 5, 1, 6, 2, 7, 3, 4]
outline = IndexBuffer(O)

# Build program
# --------------------------------------
program = Program(vertex, fragment)
program.bind(vertices)

# Build view, model, projection & normal
# --------------------------------------
view = np.eye(4, dtype=np.float32)
rotate(view, 20, 1, 0, 0)
translate(view, 0, 1, -8)
model = np.eye(4, dtype=np.float32)
projection = np.eye(4, dtype=np.float32)
program['model'] = model
program['view'] = view
program['o_projection'] = ortho(-10, 10, -10, 10, -10, 20)
phi, theta = 0, 0

program2 = Program(vertex, ilio.read('black.frag'), count=4)
program2['model'] = model
program2['view'] = view
program2["position"] = [[-2, -1, 2], [-2, -1, -2], [2, -1, 2], [2, -1, -2]]

depthv = ilio.read('depth.vert')
depthf = ilio.read('depth.frag')
Beispiel #21
0
 def update(self, pos, size, color, rotation=0):
     self.verts, self.indices, self.norms = create_cube((0, 0, 0), size)
     self.color = np.array(color, dtype=np.float32)
     self.model = np.eye(4, dtype=np.float32)
     tr.rotate(self.model, rotation, 0.0, 1.0, 0.0)
     tr.translate(self.model, pos[0], pos[1], pos[2])
Beispiel #22
0
indices = IndexBuffer(I)

O = [0,1, 1,2, 2,3, 3,0,
     4,7, 7,6, 6,5, 5,4,
     0,5, 1,6, 2,7, 3,4 ]
outline = IndexBuffer(O)

# Build program
# --------------------------------------
program = Program(vertex, fragment)
program.bind(vertices)

# Build view, model, projection & normal
# --------------------------------------
view = np.eye(4,dtype=np.float32)
rotate(view, 20, 1, 0, 0)
translate(view, 0,1 ,-8)
model = np.eye(4,dtype=np.float32)
projection = np.eye(4,dtype=np.float32)
program['model'] = model
program['view'] = view
program['o_projection'] = ortho(-10, 10, -10, 10, -10, 20)
phi, theta = 0,0

program2 = Program(vertex, ilio.read('black.frag'), count=4)
program2['model'] = model
program2['view'] = view
program2["position"] = [[-2,-1, 2],[-2, -1, -2], [2, -1, 2], [2,-1, -2]]

depthv = ilio.read('depth.vert')
depthf = ilio.read('depth.frag')
Beispiel #23
0
lower_right = view_plane[1]
lower_left = view_plane[3]

w_proj = 3
distance = 6

proj_plane = [[w_proj / 2, 0, w_proj / 2], [w_proj / 2, 0, -w_proj / 2],
              [-w_proj / 2, 0, w_proj / 2], [-w_proj / 2, 0, -w_proj / 2],
              [0, distance, 0]]
proj_plane = np.array(proj_plane)

proj_tri_triangulated = [[0, 1, 3], [0, 2, 3]]

proj_tri_triangulated = np.array(proj_tri_triangulated)

proj_plane = trfs.rotate(proj_plane, 'x', -50, True)
proj_plane = trfs.translate(proj_plane, 0, 9, -17)

proj_origin = proj_plane[4]

X, Y, Z = utl.unpack_array_to_tuple(view_plane[:4])
mesh1 = go.Mesh3d(x=X, y=Y, z=Z, delaunayaxis='y', color='cyan')
A, B, C = utl.unpack_array_to_tuple(proj_plane[:4])
mesh2 = go.Mesh3d(x=A, y=B, z=C, color='lightpink')
figure_data = [mesh1, mesh2]
'''
Define Bezier mesh
'''
Cx = [[-15, -15, -15, -15], [-5, -5, -5, -5], [5, 5, 5, 5], [15, 15, 15, 15]]
Cx = np.array(Cx)
 def __init__(self, angles, name=''):
     super(RotateNode, self).__init__(
         name + " <rotate by %s>" % str(tuple(angles.flatten())),
         transforms.rotate(angles))