Ejemplo n.º 1
0
def create_obb_gl_list(obb):
    from OpenGL.GL import glGenLists, glNewList, glFrontFace, glBegin, glEnd, glEndList, glColor3fv, glVertex3fv, \
        GL_CCW, GL_COMPILE, GL_LINES
    gl_list = glGenLists(1)
    glNewList(gl_list, GL_COMPILE)
    glFrontFace(GL_CCW)
    glBegin(GL_LINES)
    glColor3fv((1, 0, 0))

    def input_vertex(x, y, z):
        glVertex3fv((obb.rotation[0][0] * x + obb.rotation[0][1] * y +
                     obb.rotation[0][2] * z, obb.rotation[1][0] * x +
                     obb.rotation[1][1] * y + obb.rotation[1][2] * z,
                     obb.rotation[2][0] * x + obb.rotation[2][1] * y +
                     obb.rotation[2][2] * z))

    input_vertex(*obb.max)
    input_vertex(obb.max[0], obb.min[1], obb.max[2])

    input_vertex(obb.max[0], obb.min[1], obb.max[2])
    input_vertex(obb.min[0], obb.min[1], obb.max[2])

    input_vertex(obb.min[0], obb.min[1], obb.max[2])
    input_vertex(obb.min[0], obb.max[1], obb.max[2])

    input_vertex(obb.min[0], obb.max[1], obb.max[2])
    input_vertex(*obb.max)

    input_vertex(obb.max[0], obb.max[1], obb.max[2])
    input_vertex(obb.max[0], obb.max[1], obb.min[2])

    input_vertex(obb.max[0], obb.min[1], obb.max[2])
    input_vertex(obb.max[0], obb.min[1], obb.min[2])

    input_vertex(obb.min[0], obb.max[1], obb.max[2])
    input_vertex(obb.min[0], obb.max[1], obb.min[2])

    input_vertex(obb.min[0], obb.min[1], obb.max[2])
    input_vertex(obb.min[0], obb.min[1], obb.min[2])

    input_vertex(obb.max[0], obb.max[1], obb.min[2])
    input_vertex(obb.max[0], obb.min[1], obb.min[2])

    input_vertex(obb.max[0], obb.min[1], obb.min[2])
    input_vertex(*obb.min)

    input_vertex(*obb.min)
    input_vertex(obb.min[0], obb.max[1], obb.min[2])

    input_vertex(obb.min[0], obb.max[1], obb.min[2])
    input_vertex(obb.max[0], obb.max[1], obb.min[2])

    glEnd()
    glEndList()

    return gl_list
Ejemplo n.º 2
0
    def render(self) -> None:
        """Render colored axes and arrows."""
        if self._quadric is None:
            return

        glBindVertexArray(self._vao_axes)
        glDrawArrays(GL_LINES, 0, 6)
        glBindVertexArray(self._vao_arrows[0])
        glMultiDrawArrays(GL_TRIANGLE_FAN, (0, 17, 34), (17, 17, 17), 3)
        glFrontFace(GL_CW)
        glBindVertexArray(self._vao_arrows[1])
        glMultiDrawArrays(GL_TRIANGLE_FAN, (0, 17, 34), (17, 17, 17), 3)
        glFrontFace(GL_CCW)

        glBindVertexArray(0)
Ejemplo n.º 3
0
def create_gl_list(shape):
    from OpenGL.GL import glGenLists, glNewList, glFrontFace, glBegin, glEnd, glEndList, glNormal3fv, glVertex3fv, \
        GL_COMPILE, GL_CCW, GL_TRIANGLES
    vertices = shape['vertices']
    normals = shape['normals']
    indices = shape['indices']
    gl_list = glGenLists(1)
    glNewList(gl_list, GL_COMPILE)
    glFrontFace(GL_CCW)
    glBegin(GL_TRIANGLES)
    for idx in indices:
        glNormal3fv(normals[idx])
        glVertex3fv(vertices[idx])
    glEnd()
    glEndList()
    return gl_list
Ejemplo n.º 4
0
    def initializeGL(self):
        print("initializeGL")
        self.texNumeros, self.texDecor = self.load_textures()
        glEnable(GL_TEXTURE_2D)
        glShadeModel(GL_SMOOTH)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_CULL_FACE)

        glFrontFace(GL_CCW)

        light_ambient = [0.3, 0.3, 0.3, 0.1]

        glEnable(GL_LIGHTING)
        lightpos = (0, 0, 50)
        glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient)
        glLightfv(GL_LIGHT0, GL_POSITION, lightpos)
        glEnable(GL_LIGHT0)
        glEnable(GL_COLOR_MATERIAL)
        glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE)

        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
Ejemplo n.º 5
0
    def build_from_mesh_data(self, mesh_data: MeshData):
        """Uses a loaded mesh to create 3d geometry to store in the view.

        All groups in the mesh will pre-computed and stored by name.

        :param mesh_data: the source data that 3d geometry will be pre-computed from.
        """
        material_library = mesh_data.material_library

        for key in mesh_data.groups:
            new_gl_list = glGenLists(1)  # pylint: disable=assignment-from-no-return
            glNewList(new_gl_list, GL_COMPILE)

            group = mesh_data.groups[key]

            glEnable(GL_TEXTURE_2D)
            glFrontFace(GL_CCW)

            for face in group.faces:
                self._apply_material(
                    material_library.get_material_by_name(face.material))

                # Polygon (N verts) with optional normals and tex coords
                glBegin(GL_POLYGON)
                for i in range(face.vertex_count):
                    normal_index = face.normal_ids[i]
                    if normal_index > 0:
                        glNormal3fv(mesh_data.normals[normal_index - 1])
                    tex_coord_index = face.tex_ids[i]
                    if tex_coord_index > 0:
                        glTexCoord2fv(mesh_data.tex_coords[tex_coord_index -
                                                           1])
                    glVertex3fv(mesh_data.vertices[face.position_ids[i] - 1])
                glEnd()

            glDisable(GL_TEXTURE_2D)
            glEndList()

            self._display_lists[key] = new_gl_list
Ejemplo n.º 6
0
def cylinder(radius, height, **kwargs):
    """ Draw a cylinder with given radius and height."""

    # Get any keyword arguments
    style = kwargs.get("style", "wireframe")
    texture = kwargs.get("texture", None)

    quadric = _get_quadric()

    # Setup texture if specified
    if texture:
        style = "solid"
        gluQuadricTexture(quadric, True)
        texture.bind()

    # Set the quadric draw style (line or fill)
    _set_draw_style(style)

    # Draw the bottom end of the cylinder
    glFrontFace(GL_CW)
    gluDisk(quadric, 0, radius, DiskRes["slices"], DiskRes["loops"])
    glFrontFace(GL_CCW)

    # Draw the body of the cylinder
    gluCylinder(quadric, radius, radius, height, CylinderRes["slices"], CylinderRes["stacks"])

    # Draw the top end of the cylinder
    glPushMatrix()
    translateZ(height)
    gluDisk(quadric, 0, radius, DiskRes["slices"], DiskRes["loops"])
    glPopMatrix()

    # Clean up texture data if specified
    if texture:
        texture.unbind()
        gluQuadricTexture(quadric, False)