Пример #1
0
    def _draw_machine(self):
        glEnable(GL_BLEND)
        machine_model_path = profile.settings['machine_model_path']
        glEnable(GL_CULL_FACE)

        # Draw Platform
        if machine_model_path in self._platform_mesh:
            try:  # TODO: Fix this. If not in the Scanning workbench, _draw_machine() fails.
                self._platform_mesh[machine_model_path]._mesh.vbo.release()
            except:
                pass

        mesh = mesh_loader.load_mesh(machine_model_path)
        if mesh is not None:
            self._platform_mesh[machine_model_path] = mesh
        else:
            self._platform_mesh[machine_model_path] = None
        self._platform_mesh[machine_model_path]._draw_offset = numpy.array(
            [0, 0, 8.05], numpy.float32)
        glColor4f(0.6, 0.6, 0.6, 0.5)
        self._object_shader.bind()
        self._render_object(self._platform_mesh[machine_model_path])
        self._object_shader.unbind()
        glDisable(GL_CULL_FACE)

        glDepthMask(False)

        machine_shape = profile.settings['machine_shape']

        if machine_shape == 'Circular':
            size = numpy.array([
                profile.settings['roi_diameter'],
                profile.settings['roi_diameter'],
                profile.settings['roi_height']
            ], numpy.float32)
        elif machine_shape == 'Rectangular':
            size = numpy.array([
                profile.settings['roi_width'], profile.settings['roi_depth'],
                profile.settings['roi_height']
            ], numpy.float32)

        if self._view_roi:
            polys = profile.get_size_polygons(size, machine_shape)
            height = profile.settings['roi_height']

            # Draw the sides of the build volume.
            glBegin(GL_QUADS)
            for n in xrange(0, len(polys[0])):
                if machine_shape == 'Rectangular':
                    if n % 2 == 0:
                        glColor4ub(5, 171, 231, 96)
                    else:
                        glColor4ub(5, 171, 231, 64)
                elif machine_shape == 'Circular':
                    glColor4ub(5, 171, 231, 96)
                    # glColor4ub(200, 200, 200, 150)

                glVertex3f(polys[0][n][0], polys[0][n][1], height)
                glVertex3f(polys[0][n][0], polys[0][n][1], 0)
                glVertex3f(polys[0][n - 1][0], polys[0][n - 1][1], 0)
                glVertex3f(polys[0][n - 1][0], polys[0][n - 1][1], height)
            glEnd()

            # Draw bottom and top of build volume.
            glColor4ub(5, 171, 231, 150)  # 128)
            # glColor4ub(200, 200, 200, 200)
            glBegin(GL_TRIANGLE_FAN)
            for p in polys[0][::-1]:
                glVertex3f(p[0], p[1], 0)
            glEnd()
            glBegin(GL_TRIANGLE_FAN)
            for p in polys[0][::-1]:
                glVertex3f(p[0], p[1], height)
            glEnd()

            quadric = gluNewQuadric()
            gluQuadricNormals(quadric, GLU_SMOOTH)
            gluQuadricTexture(quadric, GL_TRUE)
            glColor4ub(0, 100, 200, 150)

            gluCylinder(quadric, 6, 6, 1, 32, 16)
            gluDisk(quadric, 0.0, 6, 32, 1)

            glTranslate(0, 0, height - 1)
            gluDisk(quadric, 0.0, 6, 32, 1)
            gluCylinder(quadric, 6, 6, 1, 32, 16)
            glTranslate(0, 0, -height + 1)

        polys = profile.get_machine_size_polygons(
            profile.settings["machine_shape"])

        # Draw checkerboard
        if self._platform_texture is None:
            self._platform_texture = opengl_helpers.load_gl_texture(
                'checkerboard.png')
            glBindTexture(GL_TEXTURE_2D, self._platform_texture)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
        glColor4f(1, 1, 1, 0.5)
        glBindTexture(GL_TEXTURE_2D, self._platform_texture)
        glEnable(GL_TEXTURE_2D)
        glBegin(GL_TRIANGLE_FAN)
        for p in polys[0]:
            glTexCoord2f(p[0] / 20, p[1] / 20)
            glVertex3f(p[0], p[1], 0)
        glEnd()
        glDisable(GL_TEXTURE_2D)

        glDepthMask(True)
        glDisable(GL_BLEND)
Пример #2
0
 def load_scene(self, filename):
     try:
         self._clear_scene()
         self._object = mesh_loader.load_mesh(filename)
     except:
         traceback.print_exc()