Ejemplo n.º 1
0
def draw(self, context):
    width = self.region.width
    height = self.region.height
    x = self.view_padding_left
    y = self.view_padding_top

    # Gem map
    # -----------------------------

    if not self.use_navigate:
        gpu.state.blend_set("ALPHA")
        draw_texture_2d(self.offscreen.texture_color, (0, 0), width, height)

    # Onscreen text
    # -----------------------------

    y = onscreen_text.onscreen_gem_table(self, x, y)
    y -= self.view_margin

    if self.show_warn:
        y = onscreen_text.onscreen_warning(self, x, y)
        y -= self.view_margin

    view3d_lib.options_display(self, context, x, y)

    # Reset state
    # ----------------------------

    gpu.state.blend_set("NONE")
Ejemplo n.º 2
0
def Draw_Image_Texture(_image, _pos, _width, _height):
    try:
        if _image.gl_load():
            raise Exception()
    except:
        pass
    draw_texture_2d(_image.bindcode, _pos, _width, _height)
Ejemplo n.º 3
0
def draw_image():
    """
    This is doesn't work for now (black image?) -> Bug with BGL, just doesn't work no matter what unfortunately :(
    """
    w = 500
    h = 500
    x = 0
    y = 0

    filepath = "G:/TEMP/4.png"
    image = bpy.data.images.load(filepath, check_existing=True)
    draw_texture_2d(image.bindcode, (x, y), w, h)
Ejemplo n.º 4
0
def draw():
    context = bpy.context
    scene = context.scene

    view_matrix = scene.camera.matrix_world.inverted()

    projection_matrix = scene.camera.calc_matrix_camera(
        context.evaluated_depsgraph_get(), x=WIDTH, y=HEIGHT)

    offscreen.draw_view3d(scene, context.view_layer, context.space_data,
                          context.region, view_matrix, projection_matrix)

    bgl.glDisable(bgl.GL_DEPTH_TEST)
    draw_texture_2d(offscreen.color_texture, (10, 10), WIDTH, HEIGHT)
Ejemplo n.º 5
0
def draw():
    context = bpy.context
    scene = context.scene

    view_matrix = scene.camera.matrix_world.inverted()

    projection_matrix = scene.camera.calc_matrix_camera(
        context.evaluated_depsgraph_get(), x=WIDTH, y=HEIGHT)

    offscreen.draw_view3d(scene, context.view_layer, context.space_data,
                          context.region, view_matrix, projection_matrix, True)

    gpu.state.depth_mask_set(False)
    draw_texture_2d(offscreen.texture_color, (10, 10), WIDTH, HEIGHT)
Ejemplo n.º 6
0
def texshare_capture(self, context, camera, object, offscreen, spoutSender):
    scene = context.scene
    dWIDTH = camera.texshare.capture_width
    dHEIGHT = camera.texshare.capture_height

    view_matrix = object.matrix_world.inverted()

    projection_matrix = object.calc_matrix_camera(
        context.evaluated_depsgraph_get(), x=dWIDTH, y=dHEIGHT)

    offscreen.draw_view3d(scene, context.view_layer, context.space_data,
                          context.region, view_matrix, projection_matrix)

    bgl.glDisable(bgl.GL_DEPTH_TEST)
    draw_texture_2d(offscreen.color_texture, (10, 10), 40, 40)

    spoutSender.SendTexture(offscreen.color_texture, bgl.GL_TEXTURE_2D, dWIDTH,
                            dHEIGHT, True, 0)
    def draw_texture(self, texture_id, scene):
        if scene.rpr.render_mode in ('WIREFRAME', 'MATERIAL_INDEX', 'POSITION',
                                     'NORMAL', 'TEXCOORD'):
            # Draw without color management
            draw_texture_2d(texture_id, self.viewport_settings.border[0],
                            *self.viewport_settings.border[1])

        else:
            # Bind shader that converts from scene linear to display space,
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glBlendFunc(bgl.GL_ONE, bgl.GL_ONE_MINUS_SRC_ALPHA)
            self.rpr_engine.bind_display_space_shader(scene)

            # note this has to draw to region size, not scaled down size
            self._draw_texture(texture_id, *self.viewport_settings.border[0],
                               *self.viewport_settings.border[1])

            self.rpr_engine.unbind_display_space_shader()
            bgl.glDisable(bgl.GL_BLEND)
Ejemplo n.º 8
0
def Draw_Texture(_bincode, _pos, _width, _height):
    draw_texture_2d(_bincode, _pos, _width, _height)
Ejemplo n.º 9
0
 def draw(self):
     self.image.gl_touch()
     draw_texture_2d(self.image.bindcode, self.pos, self.width, self.height)
 def draw(self):
     draw_texture_2d(self.texture, (0, 0), self.texture.width,
                     self.texture.height)
            def draw_callback_px(self, context):
                # import images
                dirname = os.path.dirname(os.path.abspath(__file__))
                gaugedir = os.path.join(dirname, "images/generic_gauge.png")
                huddir = os.path.join(dirname, "images/hud.png")
                previewdir = os.path.join(dirname, "images/gauge_preview.png")

                # dev paths
                gaugedir = os.path.join(
                    "C:/Users/rishi/Documents/Rishi/GitHub/Blender2MTS-Addons/mts_instrument_pos/images/generic_gauge.png"
                )
                huddir = os.path.join(
                    "C:/Users/rishi/Documents/Rishi/GitHub/Blender2MTS-Addons/mts_instrument_pos/images/hud.png"
                )
                previewdir = os.path.join(
                    "C:/Users/rishi/Documents/Rishi/GitHub/Blender2MTS-Addons/mts_instrument_pos/images/gauge_preview.png"
                )

                # load if they exist
                try:
                    gauge = bpy.data.images.load(gaugedir, check_existing=True)
                except:
                    self.report({'ERROR'},
                                "INSTRUMENT Image Not Found At: " + gaugedir)

                try:
                    prev_gauge = bpy.data.images.load(previewdir,
                                                      check_existing=True)
                except:
                    self.report({'ERROR'},
                                "PREVIEW Image Not Found At: " + previewdir)

                try:
                    hud = bpy.data.images.load(huddir, check_existing=True)
                except:
                    self.report({'ERROR'}, "HUD Image Not Found At: " + huddir)

                gauge.gl_load()
                prev_gauge.gl_load()
                hud.gl_load()

                # draw the hud
                presets.draw_texture_2d(hud.bindcode, (self.panel_offset, 0),
                                        400, 140)

                # set properties of the instrument
                self.gauge_dimensions = 128 * self.instSet.scale
                self.gauge_pos = [
                    (self.instSet.hudX -
                     (self.gauge_dimensions / 2)) + self.panel_offset,
                    (-self.instSet.hudY - (self.gauge_dimensions / 2)) + 140
                ]

                # for each unselected instrument draw the preview
                for obj in context.scene.objects:
                    if obj != context.object and obj.mts_instrument_settings.isInstrument:
                        instSet = obj.mts_instrument_settings

                        inst_dimension = 128 * instSet.scale
                        inst_pos = [
                            (instSet.hudX -
                             (inst_dimension / 2)) + self.panel_offset,
                            (-instSet.hudY - (inst_dimension / 2)) + 140
                        ]
                        presets.draw_texture_2d(prev_gauge.bindcode,
                                                (inst_pos[0], inst_pos[1]),
                                                inst_dimension, inst_dimension)

                # draw the instrument
                presets.draw_texture_2d(gauge.bindcode,
                                        (self.gauge_pos[0], self.gauge_pos[1]),
                                        self.gauge_dimensions,
                                        self.gauge_dimensions)

                # draw the pos text
                font_id = 0
                blf.enable(font_id, 4)
                blf.color(font_id, 1, 1, 1, 1)
                blf.shadow(font_id, 5, 0, 0, 0, 1)
                blf.shadow_offset(font_id, 1, -1)
                blf.position(font_id, 20, 40, 0)
                blf.size(font_id, 20, 72)
                blf.draw(font_id, "X: {}".format(self.instSet.hudX))
                blf.position(font_id, 20, 20, 0)
                blf.draw(font_id, "Y: {}".format(self.instSet.hudY))
Ejemplo n.º 12
0
def _draw_3dview_report(window, area, region):
    """Draws reports in 3d views.

    :param window: window of 3D viewport
    :type window: bpy.types.Window
    :param area: area of 3D viewport
    :type area: bpy.types.Area
    :param region: region of 3D viewport
    :type region: bpy.types.Region
    """
    from io_scs_tools.operators.wm import SCS_TOOLS_OT_Show3DViewReport as _Show3DViewReport

    # no reported lines, we don't draw anything
    if not _Show3DViewReport.has_lines():
        return

    # calculate dynamic left and top margins
    if bpy.context.preferences.system.use_region_overlap:
        pos_x = 75
        # try to find tools region and properly adopt position X
        for reg in area.regions:
            if reg.type == 'TOOLS':
                pos_x = reg.width + 20
                break
        pos_y = region.height - 105
    else:
        pos_x = 20
        pos_y = region.height - 80

    # draw BT banner
    (bindcode, width,
     height) = _Show3DViewReport.get_scs_banner_img_data(window)

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    draw_texture_2d(bindcode, (pos_x - 5, pos_y), width, height)
    bgl.glDisable(bgl.GL_BLEND)

    # draw control buttons, if controls are enabled
    if _Show3DViewReport.has_controls(window):

        blf.size(0, 20, 72)
        blf.color(0, .8, .8, .8, 1)

        # set x and y offsets to report operator, so that area calculations for buttons can be calculated properly
        # considering dynamic left and top margins.
        _Show3DViewReport.set_btns_xy_offset(pos_x, region.height - pos_y)

        # draw close button
        _primitive.draw_rect_2d(
            ((pos_x + _OP_consts.View3DReport.CLOSE_BTN_AREA[0],
              pos_y - _OP_consts.View3DReport.CLOSE_BTN_AREA[2]),
             (pos_x + _OP_consts.View3DReport.CLOSE_BTN_AREA[1],
              pos_y - _OP_consts.View3DReport.CLOSE_BTN_AREA[2]),
             (pos_x + _OP_consts.View3DReport.CLOSE_BTN_AREA[1],
              pos_y - _OP_consts.View3DReport.CLOSE_BTN_AREA[3]),
             (pos_x + _OP_consts.View3DReport.CLOSE_BTN_AREA[0],
              pos_y - _OP_consts.View3DReport.CLOSE_BTN_AREA[3])),
            (.25, .25, .25, 1))

        # draw close button text
        blf.position(0, pos_x + _OP_consts.View3DReport.CLOSE_BTN_TEXT_POS[0],
                     pos_y - _OP_consts.View3DReport.CLOSE_BTN_TEXT_POS[1], 0)
        blf.draw(0, _OP_consts.View3DReport.CLOSE_BTN_TEXT)

        # draw hide button
        _primitive.draw_rect_2d(
            ((pos_x + _OP_consts.View3DReport.HIDE_BTN_AREA[0],
              pos_y - _OP_consts.View3DReport.HIDE_BTN_AREA[2]),
             (pos_x + _OP_consts.View3DReport.HIDE_BTN_AREA[1],
              pos_y - _OP_consts.View3DReport.HIDE_BTN_AREA[2]),
             (pos_x + _OP_consts.View3DReport.HIDE_BTN_AREA[1],
              pos_y - _OP_consts.View3DReport.HIDE_BTN_AREA[3]),
             (pos_x + _OP_consts.View3DReport.HIDE_BTN_AREA[0],
              pos_y - _OP_consts.View3DReport.HIDE_BTN_AREA[3])),
            (.25, .25, .25, 1))

        # draw hide button text
        blf.position(0, pos_x + _OP_consts.View3DReport.HIDE_BTN_TEXT_POS[0],
                     pos_y - _OP_consts.View3DReport.HIDE_BTN_TEXT_POS[1], 0)
        blf.draw(0, _OP_consts.View3DReport.HIDE_BTN_TEXT)

        # draw scroll controls
        if _Show3DViewReport.is_scrolled() and _Show3DViewReport.is_shown():

            blf.size(0, 16, 72)

            # draw scroll up button
            _primitive.draw_rect_2d(
                ((pos_x + _OP_consts.View3DReport.SCROLLUP_BTN_AREA[0],
                  pos_y - _OP_consts.View3DReport.SCROLLUP_BTN_AREA[2]),
                 (pos_x + _OP_consts.View3DReport.SCROLLUP_BTN_AREA[1],
                  pos_y - _OP_consts.View3DReport.SCROLLUP_BTN_AREA[2]),
                 (pos_x + _OP_consts.View3DReport.SCROLLUP_BTN_AREA[1],
                  pos_y - _OP_consts.View3DReport.SCROLLUP_BTN_AREA[3]),
                 (pos_x + _OP_consts.View3DReport.SCROLLUP_BTN_AREA[0],
                  pos_y - _OP_consts.View3DReport.SCROLLUP_BTN_AREA[3])),
                (.25, .25, .25, 1))

            # draw scroll up button text
            blf.position(
                0, pos_x + _OP_consts.View3DReport.SCROLLUP_BTN_TEXT_POS[0],
                pos_y - _OP_consts.View3DReport.SCROLLUP_BTN_TEXT_POS[1], 0)
            blf.draw(0, _OP_consts.View3DReport.SCROLLUP_BTN_TEXT)

            # draw scroll down button
            _primitive.draw_rect_2d(
                ((pos_x + _OP_consts.View3DReport.SCROLLDOWN_BTN_AREA[0],
                  pos_y - _OP_consts.View3DReport.SCROLLDOWN_BTN_AREA[2]),
                 (pos_x + _OP_consts.View3DReport.SCROLLDOWN_BTN_AREA[1],
                  pos_y - _OP_consts.View3DReport.SCROLLDOWN_BTN_AREA[2]),
                 (pos_x + _OP_consts.View3DReport.SCROLLDOWN_BTN_AREA[1],
                  pos_y - _OP_consts.View3DReport.SCROLLDOWN_BTN_AREA[3]),
                 (pos_x + _OP_consts.View3DReport.SCROLLDOWN_BTN_AREA[0],
                  pos_y - _OP_consts.View3DReport.SCROLLDOWN_BTN_AREA[3])),
                (.25, .25, .25, 1))

            # draw scroll down button text
            blf.position(
                0, pos_x + _OP_consts.View3DReport.SCROLLDOWN_BTN_TEXT_POS[0],
                pos_y - _OP_consts.View3DReport.SCROLLDOWN_BTN_TEXT_POS[1], 0)
            blf.draw(0, _OP_consts.View3DReport.SCROLLDOWN_BTN_TEXT)

    # draw version string
    pos_y -= 12
    blf.size(0, 10, 72)
    blf.color(0, .952, .635, .062, 1)
    blf.position(0, pos_x, pos_y, 0)
    blf.draw(0, _info_utils.get_combined_ver_str(only_version_numbers=True))
    pos_y -= 20

    # draw actual operator title and message if shown
    if _Show3DViewReport.is_shown():

        blf.size(0, 12, 72)
        blf.color(0, 1, 1, 1, 1)
        blf.shadow(0, 5, 0, 0, 0, 1)

        if _Show3DViewReport.get_title() != "":
            blf.position(0, pos_x, pos_y, 0)
            blf.draw(0, _Show3DViewReport.get_title())
            pos_y -= 15

        blf.enable(0, blf.SHADOW)
        _Show3DViewReport.set_out_of_bounds(False)
        for line in _Show3DViewReport.get_lines():

            # finish printing if running out of space
            if pos_y - 60 < 0:
                blf.position(0, pos_x, pos_y, 0)
                blf.draw(0, "...")
                pos_y -= 15
                _Show3DViewReport.set_out_of_bounds(True)
                break

            blf.position(0, pos_x, pos_y, 0)
            if "ERROR" in line:
                blf.shadow(0, 5, 0.5, 0., 0, 1)
            elif "WARNING" in line:
                blf.shadow(0, 5, 0.3, 0.15, 0, 1)

            blf.draw(0, line)
            pos_y -= 15

        blf.disable(0, blf.SHADOW)