def drawGL(self):
        if self.shader is not None:
            import numpy as np
            self.shader.bind()

            current_time = time.time()
            angle_x = self.rotation[0] * current_time
            angle_y = self.rotation[1] * current_time
            angle_z = self.rotation[2] * current_time

            mvp_rotX = np.matrix(
                [[1, 0, 0, 0], [0, np.cos(angle_x), -np.sin(angle_x), 0],
                 [0, np.sin(angle_x), np.cos(angle_x), 0], [0, 0, 0, 1]],
                dtype=np.float32)

            mvp_rotY = np.matrix(
                [[np.cos(angle_y), 0, np.sin(angle_y), 0], [0, 1, 0, 0],
                 [-np.sin(angle_y), 0, np.cos(angle_y), 0], [0, 0, 0, 1]],
                dtype=np.float32)

            mvp_rotZ = np.matrix(
                [[np.cos(angle_z), -np.sin(angle_z), 0, 0],
                 [np.sin(angle_z), np.cos(angle_z), 0, 0], [0, 0, 1, 0],
                 [0, 0, 0, 1]],
                dtype=np.float32)

            mvp = mvp_rotX * mvp_rotY * mvp_rotZ

            mvp[0:3, 0:3] *= 0.25

            self.shader.setUniform("modelViewProj", mvp)

            gl.Enable(gl.DEPTH_TEST)
            self.shader.drawIndexed(gl.TRIANGLES, 0, 12)
            gl.Disable(gl.DEPTH_TEST)
Exemplo n.º 2
0
    def drawContents(self):
        super(VoxelGridViewer, self).drawContents()

        self.render_context.shader.bind()
        gl.Enable(gl.DEPTH_TEST)
        draw_box(self.render_context.shader,
                 self.voxel_grids[self.disp_idx][1].vxbb_min,
                 self.voxel_grids[self.disp_idx][1].vxbb_max,
                 self.camera.viewproj, np.array([1, 1, 0], dtype=np.float32))

        if self.mesh is not None:
            self.mesh.draw_contents(self.camera, self.render_context,
                                    self.voxel_grids[self.disp_idx][1])
        self.voxel_grids[self.disp_idx][1].draw_contents(
            self.camera, self.render_context)
        if self.normals is not None:
            self.normals.draw_contents(self.camera, self.render_context)

        if self.selected_voxel is not None:
            vxgrid = self.voxel_grids[0][1]
            voxel_diag_ws = (vxgrid.vxbb_max -
                             vxgrid.vxbb_min) / vxgrid.voxel_grid_res
            # Round position to index

            minvox = (self.selected_voxel / vxgrid.voxel_grid_res) * \
                (vxgrid.vxbb_max - vxgrid.vxbb_min) + vxgrid.vxbb_min

            maxvox = minvox + voxel_diag_ws
            draw_box(self.render_context.shader, minvox, maxvox,
                     self.camera.viewproj, np.array([1, 0, 0],
                                                    dtype=np.float32))
Exemplo n.º 3
0
def draw_grid(shader, vp_mat):
    """Draws a simple grid plane in the viewport."""
    grid_extent = 5
    grid_step = 0.5
    r = np.arange(-grid_extent,
                  grid_extent + 1e-2,
                  grid_step,
                  dtype=np.float32)
    pos0 = np.zeros([3, r.shape[0] * 2], dtype=np.float32)
    pos0[:, 0::2] = np.stack(
        [r, np.zeros_like(r), -grid_extent * np.ones_like(r)])
    pos0[:,
         1::2] = np.stack([r,
                           np.zeros_like(r), grid_extent * np.ones_like(r)])
    pos1 = np.zeros([3, r.shape[0] * 2], dtype=np.float32)
    pos1[:, 0::2] = np.stack(
        [-grid_extent * np.ones_like(r),
         np.zeros_like(r), r])
    pos1[:,
         1::2] = np.stack([grid_extent * np.ones_like(r),
                           np.zeros_like(r), r])
    colors = 0.5 * np.ones(pos0.shape, dtype=np.float32)
    colors[:, colors.shape[1] // 2] *= 0
    colors[:, colors.shape[1] // 2 - 1] *= 0

    shader.setUniform("modelViewProj", vp_mat)
    shader.uploadAttrib("position", pos0)
    shader.uploadAttrib("color", colors)
    shader.drawArray(gl.LINES, 0, pos0.shape[1])
    shader.setUniform("modelViewProj", vp_mat)
    shader.uploadAttrib("position", pos1)
    shader.uploadAttrib("color", colors)
    shader.drawArray(gl.LINES, 0, pos1.shape[1])

    # Draw axis on top
    gl.Disable(gl.DEPTH_TEST)
    pos0 = np.zeros([3, 6], dtype=np.float32)
    pos0[0, 1] = grid_extent
    pos0[1, 3] = grid_extent
    pos0[2, 5] = grid_extent
    colors = np.ones(pos0.shape, dtype=np.float32)
    colors[1:, 0:2] *= 0
    colors[2, 2:4] *= 0
    colors[0, 2:4] *= 0
    colors[0:2, 4:6] *= 0
    shader.setUniform("modelViewProj", vp_mat)
    shader.uploadAttrib("position", pos0)
    shader.uploadAttrib("color", colors)
    shader.drawArray(gl.LINES, 0, pos0.shape[1])
    gl.Enable(gl.DEPTH_TEST)
Exemplo n.º 4
0
    def drawContents(self):
        super(ViewerApp, self).drawContents()
        self.handleEvents()
        self.fb.bind()
        color = self.background()
        glClearColor(color.r, color.g, color.b, 1.0)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glEnable(GL_BLEND)

        self.render_context.shader.bind()

        gl.Enable(gl.DEPTH_TEST)
        if self.show_grid:
            draw_grid(self.render_context.shader, self.camera.viewproj)
Exemplo n.º 5
0
def draw_full_screen_quad(shader, vp_mat, depth_map):
    """Draws a simple grid plane in the viewport."""

    tex = depth_map
    glBindTexture(GL_TEXTURE_2D, tex)
    glUniform1i(shader.uniform("renderedTexture"), 0)
    glActiveTexture(GL_TEXTURE0)
    glBindTexture(GL_TEXTURE_2D, tex)

    gl.Disable(gl.DEPTH_TEST)
    pos0 = np.array([[-1.0, -1.0, 0.0], [1.0, -1.0, 0.0], [-1.0, 1.0, 0.0],
                     [-1.0, 1.0, 0.0], [1.0, -1.0, 0.0], [1.0, 1.0, 0.0]],
                    dtype=np.float32).T
    uv = pos0[:2, :] * 0.5 + 0.5
    pos0 *= 0.5
    shader.uploadAttrib("position", pos0)
    shader.uploadAttrib("uv", uv)
    shader.drawArray(gl.TRIANGLES, 0, pos0.shape[1])
    gl.Enable(gl.DEPTH_TEST)
Exemplo n.º 6
0
 def drawGL(self):
     gl.Enable(gl.DEPTH_TEST)
     self.view.draw()
     gl.Disable(gl.DEPTH_TEST)