示例#1
0
def on_display():
    global theta, phi
    gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)

    theta += 0.05
    phi += 0.05
    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)

    gl.glPolygonOffset(1, 1)
    gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL)
    gl.glEnable(gl.GL_POLYGON_OFFSET_FILL)
    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()
示例#2
0
 def render(self, t):
     reltime = t - self.start
     M = np.eye(4, dtype=np.float32)
     transforms.scale(M, 1.5/50, .4, 1)
     transforms.translate(M, (self.slot+.5) * 2.0/50 - 1, (reltime / -5) +.6 , 0)
     self.bar.setModelView(M)
     self.bar.render()
示例#3
0
    def render(self, t):
        p = math.floor(t / 8)
        off = t - p * 8

        b = max(0, 1 - ((t % 1) * 4))
        m = 1 if off % 0.75 < 0.2 else 0
        d = max(0, 1 - ((t % 16) * 1))
		

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

		
        self.square.setProjection(self.projection)
        self.square.setModelView(M)
        self.square.setColor((b,0,d,1))
        self.square.render()
        M = np.eye(4, dtype=np.float32)

        transforms.translate(M, -1, -.5, 0)
        #transforms.rotate(M, t*90, 0, 0, 1)
        transforms.scale(M, 5, 5, 5)

        self.square.setProjection(self.projection)
        self.square.setModelView(M)
        self.square.setColor((m,m,m,1))
        self.square.render()
示例#4
0
 def render(self, t):
     reltime = t - self.start
     M = np.eye(4, dtype=np.float32)
     transforms.scale(M, 1.5 / 50, .4, 1)
     transforms.translate(M, (self.slot + .5) * 2.0 / 50 - 1,
                          (reltime / -5) + .6, 0)
     self.bar.setModelView(M)
     self.bar.render()
示例#5
0
def draw_ply(plypath, pos=(0, 0, 0), size=0.1, color=(0, 1, 0, 1), rotation=0):
    global program
    plydata = PlyData.read(plypath)
    verts = plydata['vertex']
    #verts = np.vstack((verts['x'],verts['y'],verts['z'])).transpose()
    verts = np.vstack([
        (verts[l] - verts[l].min()) / (verts[l].max() - verts[l].min()) * 2 - 1
        for l in ['x', 'y', 'z']
    ]).transpose().astype(np.float32).copy()
    # verts = verts*size

    indices = np.zeros((0), dtype=np.uint32)
    norms = np.zeros((verts.shape[0], 3))
    norms[:, 1] = 1
    for face in plydata['face']['vertex_indices']:
        indices = np.hstack((indices, face.astype(np.uint32)))

        norms[face[1], :] = normalize(
            np.cross(verts[face[0]] - verts[face[1]],
                     verts[face[2]] - verts[face[1]]))
    #indices = np.arange(0,indices.shape[0],dtype = np.uint32)
    vertsbuf = glGenBuffers(1)
    indicesbuf = glGenBuffers(1)
    normsbuf = glGenBuffers(1)
    model = np.eye(4, dtype=np.float32)
    tr.rotate(model, rotation, 0.0, 1.0, 0.0)
    tr.translate(model, pos[0], pos[1], pos[2])

    # print(verts)
    # print(indices)
    # print(norms)

    offset = ctypes.c_void_p(0)
    glBindBuffer(GL_ARRAY_BUFFER, vertsbuf)
    glBufferData(GL_ARRAY_BUFFER, verts.nbytes, verts, GL_DYNAMIC_DRAW)
    stride = verts.strides[0]
    loc = glGetAttribLocation(program, "vertex")
    glEnableVertexAttribArray(loc)
    glVertexAttribPointer(loc, 3, GL_FLOAT, False, stride, offset)

    glBindBuffer(GL_ARRAY_BUFFER, normsbuf)
    glBufferData(GL_ARRAY_BUFFER, norms.nbytes, norms, GL_DYNAMIC_DRAW)
    stride = norms.strides[0]
    loc = glGetAttribLocation(program, "normal")
    glEnableVertexAttribArray(loc)
    glVertexAttribPointer(loc, 3, GL_FLOAT, False, stride, offset)

    loc = glGetUniformLocation(program, "objectMatrix")
    glUniformMatrix4fv(loc, 1, GL_FALSE, model)

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indicesbuf)
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.nbytes, indices,
                 GL_DYNAMIC_DRAW)
    loc = glGetUniformLocation(program, "vertex_color")
    glUniform4f(loc, color[0], color[1], color[2], color[3])

    glDrawElements(GL_TRIANGLES, indices.shape[0], GL_UNSIGNED_INT,
                   ctypes.c_void_p(0))
示例#6
0
    def init_transforms(self):
        self.view = np.eye(4, dtype=np.float32)
        self.model = np.eye(4, dtype=np.float32)
        self.projection = np.eye(4, dtype=np.float32)

        self.theta = 0
        self.phi = 0

        translate(self.view, 0, 0, -5)
示例#7
0
 def __init__(self, pos, size, color, rotation=0):
     self.verts, self.indices, self.norms = create_cube((0, 0, 0), size)
     self.vertsbuf = glGenBuffers(1)
     self.indicesbuf = glGenBuffers(1)
     self.normsbuf = glGenBuffers(1)
     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])
示例#8
0
 def render(self, t):
     M = np.eye(4, dtype=np.float32)
     transforms.scale(M, self.size, self.size, 1)
     transforms.translate(M, self.pos[0], self.pos[1])
     transforms.translate(M, math.sin(t * math.pi * 2 / 2 + self.phase) * 0.008 , 0)
     self.geometry.setModelView(M)
     self.geometry.setProjection(self.projection)
     self.geometry.setColor(self.color)
     self.geometry.render()
示例#9
0
 def init_transforms(self):
     self.view       = np.eye(4,dtype=np.float32)
     self.model      = np.eye(4,dtype=np.float32)
     self.projection = np.eye(4,dtype=np.float32)
     
     self.theta = 0
     self.phi = 0
     
     translate(self.view, 0,0,-5)
示例#10
0
        def render(self, t):
            self.update(t - self.reltime)
            M = np.eye(4, dtype=np.float32)
            transforms.scale(M, self.size, self.size, 1)
            transforms.translate(M, self.pos[0], self.pos[1])

            self.geometry.setColor(self.color)
            self.geometry.setModelView(M)
            self.geometry.setProjection(self.projection)
            self.geometry.render()
示例#11
0
        def render(self, t):
            self.update(t - self.reltime)
            M = np.eye(4, dtype=np.float32)
            transforms.scale(M, self.size, self.size, 1)
            transforms.translate(M, self.pos[0], self.pos[1])

            self.geometry.setColor(self.color)
            self.geometry.setModelView(M)
            self.geometry.setProjection(self.projection)
            self.geometry.render()
示例#12
0
 def render(self, t):
     M = np.eye(4, dtype=np.float32)
     transforms.scale(M, self.size, self.size, 1)
     transforms.translate(M, self.pos[0], self.pos[1])
     transforms.translate(
         M,
         math.sin(t * math.pi * 2 / 2 + self.phase) * 0.008, 0)
     self.geometry.setModelView(M)
     self.geometry.setProjection(self.projection)
     self.geometry.setColor(self.color)
     self.geometry.render()
示例#13
0
 def init_transforms(self):
     self.view       = np.eye(4,dtype=np.float32)
     self.model      = np.eye(4,dtype=np.float32)
     self.projection = np.eye(4,dtype=np.float32)
     
     self.theta = 0
     self.phi = 0
     
     translate(self.view, 0,0,-5)
     self.program.uniforms['u_model'] = self.model
     self.program.uniforms['u_view'] = self.view
示例#14
0
def face3dm(username):
    skin = fetch_skin(username)
    im = skin.crop((8, 8, 16, 16))
    model = ThreeDM("{}'s face".format(username))
    shapes = imTo3d(im)
    for shape in shapes:
        model.addShape(shape)
    model.transform(tf.reflectY())
    model.transform(tf.translate(0, 8, 0))
    model.transform(tf.translate(1, 1, 0))
    return str(model)
示例#15
0
    def init_transforms(self):
        self.view = np.eye(4, dtype=np.float32)
        self.model = np.eye(4, dtype=np.float32)
        self.projection = np.eye(4, dtype=np.float32)

        self.theta = 0
        self.phi = 0

        translate(self.view, 0, 0, -5)
        self.program.uniforms['u_model'] = self.model
        self.program.uniforms['u_view'] = self.view
示例#16
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()
示例#17
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()
示例#18
0
    def render(self, t):
        self.square.setProjection(self.projection)

        M = np.eye(4, dtype=np.float32)
        transforms.translate(M, 0.0, -1, 0)
        #        transforms.rotate(M, t*90, 0, 0, 1)

        self.square.setModelView(M)
        self.square.setColor((1, 1, 1, 1))
        self.square.render()

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

        self.square.setModelView(M)
        self.square.setColor((1, 0, 0, 1))
        self.square.render()

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

        self.square.setModelView(M)
        self.square.setColor((0, 1, 0, 1))
        self.square.render()
        M = np.eye(4, dtype=np.float32)
        transforms.translate(M, 0.0, 0, 0)
        #        transforms.rotate(M, t*90, 0, 0, 1)

        self.square.setModelView(M)
        self.square.setColor((0, 0, 1, 1))
        self.square.render()
示例#19
0
def handlekeys(key, x, y):
    global rotation
    val = 5
    if key == GLUT_KEY_UP:
        rotation.x += val
    if key == GLUT_KEY_DOWN:
        rotation.x -= val
    if key == GLUT_KEY_LEFT:
        rotation.y += val
    if key == GLUT_KEY_RIGHT:
        rotation.y -= val
    if key == 97:
        tr.translate(camera.view, 0.3, 0, 0)
    if key == 106:
        tr.translate(camera.view, -0.3, 0, 0)
    if key == 115:
        tr.translate(camera.view, 0, 0, -0.3)
    if key == 119:
        tr.translate(camera.view, 0, 0, 0.3)
    if key == GLUT_KEY_F1:
        img = np.zeros((windowsize[0], windowsize[1], 3), np.uint8)
        glReadPixels(0, 0, windowsize[0], windowsize[1], GL_RGB,
                     GL_UNSIGNED_BYTE, img)
        scipy.misc.imsave('picture.png', np.flipud(img))
    if key == GLUT_KEY_F2:
        sys.exit(0)
示例#20
0
        def render(self, t):
            M = np.eye(4, dtype=np.float32)
            transforms.scale(M, .03 * self.m, .03 * self.m, 1)
            transforms.translate(M, self.pos[0], self.pos[1], 0)
            
            if t > self.flicker:
                dt = t - self.flicker

                a = max(0, .5 - (dt/4))

                n = math.sin(dt*20)/2 + 0.5
                self.part.setColor((1,.5 + n * .5, n, a))

            self.part.setModelView(M)
            self.part.render()
示例#21
0
        def render(self, t):
            M = np.eye(4, dtype=np.float32)
            transforms.scale(M, .03 * self.m, .03 * self.m, 1)
            transforms.translate(M, self.pos[0], self.pos[1], 0)
            
            if t > self.flicker:
                dt = t - self.flicker

                a = max(0, .5 - math.pow(dt/4, 2))

                n = math.sin(dt*30)/2 + 0.5
                self.part.setColor((1,.5 + n * .5, n, a))

            self.part.setModelView(M)
            self.part.render()
示例#22
0
    def render(self, t):
        dt = t - self.last
        x,y = self.getCenter(t)
        dx = (x - self.lastx)/dt
        dy = (y - self.lasty)/dt
        self.lastx = x
        self.lasty = y

        if int(t*self.freq) > int(self.last*self.freq):
            self.addstar(t, dx, dy)

        self.last = t

        positions = []
        colors = []
        for star in self.stars:
            star.step(t, dt)
            positions.append((star.x, star.y))
            colors.append(star.color)

        M = np.eye(4, dtype=np.float32)
        transforms.scale(M, 1.0/25, 1.0/25, 1)
        self.geometry.setStars(positions, colors)
        self.geometry.setModelView(M)
        self.geometry.render()			

        now = datetime.now()

        digits = [ now.hour / 10, now.hour % 10, now.minute / 10, now.minute % 10, now.second / 10, now.second % 10 ]
        digits = [ int(x) for x in digits ]
        
        n = 0
        for digit in digits:
            M = np.eye(4, dtype=np.float32)
            d = now.microsecond / 1000000
            s = 1.2 - d * 0.2
            transforms.scale(M, s, s, 1)
            transforms.scale(M, 1.0/12, -1.0/10, 1)
            transforms.translate(M, -.8 + (n * 0.3 ) , 0, 0)
            if n % 2 == 0:
                transforms.translate(M, 0.1 , 0, 0)
            self.digits[digit].setModelView(M)
            #self.digits[digit].color = (1,1,1, 0.5 + (1-d) * 0.5)
            self.digits[digit].render()
            n += 1
示例#23
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()
示例#24
0
 def render(self, t):
     n = 0
     d = (t * 10) % len(self.lamps)
     for p in self.lamps:
         M = np.eye(4, dtype=np.float32)
         transforms.scale(M, 1.0 / 60, 1.0 / 60, 1)
         transforms.translate(M, p[0], p[1], 0)
         self.star.setModelView(M)
         M = np.eye(4, dtype=np.float32)
         transforms.scale(M, 1, 1, 1)
         self.star.setProjection(M)
         if self.enabledLamp is not None:
             self.star.color = (1, 1, 1,
                                1) if n == self.enabledLamp else (.1, 0, 0,
                                                                  1)
         else:
             self.star.color = (1, 1, 1, 1) if int(d) == n else (.1, 0, 0,
                                                                 1)
         self.star.render()
         n += 1
示例#25
0
 def getMcam(self):
     k = (self._Peye - self._Pref)
     k = k / np.linalg.norm(k)
     i = np.cross(self._Vup[:3], k[:3])
     i = i / np.linalg.norm(i)
     j = np.cross(k[:3], i)
     i = np.concatenate((i, np.array([0])))
     j = np.concatenate((j, np.array([0])))
     rotmat = np.array([i, j, k, [0, 0, 0, 1]])  #already inversed
     transmat = transforms.translate(-self._Peye[:3])  #already inversed
     return np.matmul(rotmat, transmat)
示例#26
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()
示例#27
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()
示例#28
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)
示例#29
0
glut.glutKeyboardFunc(keyboard)
glut.glutDisplayFunc(display)
glut.glutTimerFunc(1000 / 60, timer, 60)

# Build cube data
# --------------------------------------
vertices, indices, _ = cube()
vertices = VertexBuffer(vertices)
indices = IndexBuffer(indices)

# Build view, model, projection & normal
# --------------------------------------
view = np.eye(4, dtype=np.float32)
model = np.eye(4, dtype=np.float32)
projection = np.eye(4, dtype=np.float32)
translate(view, 0, 0, -5)
normal = np.array(np.matrix(np.dot(view, model)).I.T)

# Build program
# --------------------------------------
program = Program(vertex, fragment)
program.bind(vertices)
program["light_position"] = 2, 2, 2
program["light_intensity"] = 1, 1, 1
program["u_model"] = model
program["u_view"] = view
program["u_normal"] = normal
phi, theta = 0, 0

# OpenGL initalization
# --------------------------------------
示例#30
0
def reshape(width,height):
    global projection, view
    gl.glViewport(0, 0, width, height)
    projection = perspective( 45.0, width/float(height), 2.0, 10.0 )
    view = np.identity(4,dtype=np.float32)
    translate(view, 0,0,-5)
示例#31
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')
shadowProgram = Program(depthv, depthf)
示例#32
0
                 [1, 1, 0, 1], [1, 1, 1, 1], [1, 0, 1, 1], [1, 0, 0, 1]]
vertices = VertexBuffer(V)

I = [0,1,2, 0,2,3,  0,3,4, 0,4,5,  0,5,6, 0,6,1,
     1,6,7, 1,7,2,  7,4,3, 7,3,2,  4,7,6, 4,6,5]
indices = IndexBuffer(I)

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

# Build view, model, projection & normal
# --------------------------------------
view = np.eye(4,dtype=np.float32)
model = np.eye(4,dtype=np.float32)
projection = np.eye(4,dtype=np.float32)
translate(view, 0,0,-5)
program['model'] = model
program['view'] = view
phi, theta = 0,0

# OpenGL initalization
# --------------------------------------
gl.glClearColor(1,1,1,1)
gl.glEnable(gl.GL_DEPTH_TEST)

# Start
# --------------------------------------
glut.glutMainLoop()
示例#33
0
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH)

glutCreateWindow('OpenGL renderer')
# glutReshapeWindow(windowsize[0], windowsize[1])
glutDisplayFunc(draw)
glutIdleFunc(draw)
glutReshapeFunc(reshape)
glutSpecialFunc(handlekeys)
glClearColor(0.2, 0.2, 0.2, 1)

program = create_program('shader.vert', 'shader.frag')
glUseProgram(program)

camera = Camera()
#tr.translate(camera.view, 0, -1, -4.5)
tr.translate(camera.view, 0, 0, -2.5)
loc = glGetUniformLocation(program, "projectionMatrix")
glUniformMatrix4fv(loc, 1, GL_FALSE, camera.projection)
loc = glGetUniformLocation(program, "modelViewMatrix")
glUniformMatrix4fv(loc, 1, GL_FALSE, camera.view)
loc = glGetUniformLocation(program, "sunDir")
glUniform3f(loc, -2.0, 2.0, 2.0)
loc = glGetUniformLocation(program, "ambientLight")
glUniform1f(loc, 0.3)
loc = glGetUniformLocation(program, "spotLightIntensity")
glUniform1f(loc, 0.7)

frame_counter = 1
# default_box = Cube((-1,-1,-1),(2,2,2),[0,0,1,1])
default_box = Cube((-2.5, 0, -2.5), (5, 2.5, 10), [0, 0, 1, 1])
scene_objects = [default_box]
示例#34
0
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')
shadowProgram = Program(depthv, depthf)
示例#35
0
 def __init__(self, vec, name=''):
     super(TranslateNode,
           self).__init__(name + " <translate by %s>" % vec.flatten(),
                          transforms.translate(vec))
示例#36
0
program['u_kernel'] = np.load("spatial-filters.npy")

# Build colormap (hot colormap)
# --------------------------------------
colormap = np.zeros((512, 3), np.float32)
colormap[:, 0] = np.interp(np.arange(512), [0, 171, 342, 512], [0, 1, 1, 1])
colormap[:, 1] = np.interp(np.arange(512), [0, 171, 342, 512], [0, 0, 1, 1])
colormap[:, 2] = np.interp(np.arange(512), [0, 171, 342, 512], [0, 0, 0, 1])
program['u_colormap'] = colormap

# Build view, model, projection & normal
# --------------------------------------
view = np.eye(4, dtype=np.float32)
model = np.eye(4, dtype=np.float32)
projection = np.eye(4, dtype=np.float32)
translate(view, 0, 0, -4)
normal = np.array(np.matrix(np.dot(view, model)).I.T)
program['u_model'] = model
program['u_view'] = view
program['u_normal'] = normal
program["u_light_position[0]"] = 2, 2, 2
program["u_light_intensity[0]"] = 1, 1, 1
program['u_clock'] = 0
clock, theta = 0, 0

# OpenGL initalization
# --------------------------------------
gl.glClearColor(1, 1, 1, 1)
gl.glEnable(gl.GL_DEPTH_TEST)
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
gl.glPolygonOffset(1, 1)
示例#37
0
data['a_color'] = np.random.uniform(0.75,1.00,(n,3))
data['a_radius'] = np.random.uniform(5,10,n)/100.

# Build program
# --------------------------------------
program = Program(vertex, fragment)
program.bind(VertexBuffer(data))
program['u_light_position'] = 2,2,2


# Build view, model, projection
# --------------------------------------
view = np.eye(4,dtype=np.float32)
model = np.eye(4,dtype=np.float32)
projection = np.eye(4,dtype=np.float32)
translate(view, 0, 0,-10)
#view = look_at((4.0,3.0,1.0), (0.0,0.0,0.0), (0.0,0.0,1.0))
program['u_model'] = model
program['u_view'] = view
phi, theta = 0,0

# OpenGL initalization
# --------------------------------------
gl.glClearColor(1,1,1,1)
gl.glEnable(gl.GL_DEPTH_TEST)
#gl.glEnable(gl.GL_BLEND)
#gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
gl.glEnable(gl.GL_VERTEX_PROGRAM_POINT_SIZE)
gl.glEnable(gl.GL_POINT_SPRITE)

# Start
示例#38
0
@app.route('/face/<username>.3dm')
def face3dm(username):
    skin = fetch_skin(username)
    im = skin.crop((8, 8, 16, 16))
    model = ThreeDM("{}'s face".format(username))
    shapes = imTo3d(im)
    for shape in shapes:
        model.addShape(shape)
    model.transform(tf.reflectY())
    model.transform(tf.translate(0, 8, 0))
    model.transform(tf.translate(1, 1, 0))
    return str(model)


head_flip = tf.translate(0, 8, 0) @ tf.reflectY()

head_face = tf.translate(1, 1, 0) @ head_flip
head_back = tf.translate(1, 1, 9) @ tf.translate(8, 0,
                                                 0) @ tf.reflectX() @ head_flip
head_left = tf.translate(0, 1, 1) @ tf.translate(
    0, 0, 8) @ tf.reflectZ() @ tf.swapAxes(lambda p: (p[2], p[1], p[0]))
head_right = tf.translate(9, 0, 0) @ head_left
head_bottom = tf.translate(
    1, 0, 1) @ tf.swapAxes(lambda p: (p[0], p[2], p[1])) @ head_flip
head_top = tf.translate(0, 9, 0) @ head_bottom

head_parts = [((8, 8, 16, 16), head_face), ((32, 8, 40, 16), head_back),
              ((0, 8, 8, 16), head_left), ((16, 8, 24, 16), head_right),
              ((8, 0, 16, 8), head_top), ((16, 0, 24, 0), head_bottom)]
示例#39
0
program['u_kernel'] = np.load("spatial-filters.npy")

# Build colormap (hot colormap)
# --------------------------------------
colormap = np.zeros((512,3), np.float32)
colormap[:,0] = np.interp(np.arange(512), [0, 171, 342, 512], [0,1,1,1])
colormap[:,1] = np.interp(np.arange(512), [0, 171, 342, 512], [0,0,1,1])
colormap[:,2] = np.interp(np.arange(512), [0, 171, 342, 512], [0,0,0,1])
program['u_colormap'] = colormap

# Build view, model, projection & normal
# --------------------------------------
view = np.eye(4,dtype=np.float32)
model = np.eye(4,dtype=np.float32)
projection = np.eye(4,dtype=np.float32)
translate(view, 0,0,-4)
normal = np.array(np.matrix(np.dot(view,model)).I.T)
program['u_model'] = model
program['u_view'] = view
program['u_normal'] = normal
program["u_light_position[0]"] = 2,2,2
program["u_light_intensity[0]"] = 1,1,1
program['u_clock'] = 0
clock,theta = 0,0

# OpenGL initalization
# --------------------------------------
gl.glClearColor( 1, 1, 1, 1 )
gl.glEnable(gl.GL_DEPTH_TEST)
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
gl.glPolygonOffset(1, 1)
示例#40
0
# Use this file to set chart studio account credentials
# import plotly_set_credentials
'''
Define view and projection planes
'''
w = 5
distance = 7

view_plane = np.array([[w / 2, 0, w / 2], [w / 2, 0,
                                           -w / 2], [-w / 2, 0, w / 2],
                       [-w / 2, 0, -w / 2], [0, distance, 0]])

view_plane_triangulated = [[0, 1, 3], [0, 2, 3]]
view_plane_triangulated = np.array(view_plane_triangulated)

view_plane = trfs.translate(view_plane, 0, 25, 0)

viewpoint = view_plane[4]

upper_left = view_plane[2]
upper_right = view_plane[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)