コード例 #1
0
    def draw_callback(self, op, context):
        # Force Stop
        if self.is_handler_list_empty():
            self.unregister_handler()
            return

        bgl.glEnable(bgl.GL_BLEND)
        bgl.glEnable(bgl.GL_LINE_SMOOTH)
        bgl.glHint(bgl.GL_LINE_SMOOTH_HINT, bgl.GL_NICEST)
        bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)

        bgl.glEnable(bgl.GL_DEPTH_TEST)
        bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL)
        bgl.glPolygonOffset(1.0, 1.0)

        bgl.glColorMask(bgl.GL_FALSE, bgl.GL_FALSE, bgl.GL_FALSE, bgl.GL_FALSE)
        bgl.glPolygonMode(bgl.GL_FRONT_AND_BACK, bgl.GL_FILL)

        self.fill_batch.draw(self.fill_shader)

        bgl.glColorMask(bgl.GL_TRUE, bgl.GL_TRUE, bgl.GL_TRUE, bgl.GL_TRUE)
        bgl.glDisable(bgl.GL_POLYGON_OFFSET_FILL)

        bgl.glDepthMask(bgl.GL_FALSE)
        bgl.glPolygonMode(bgl.GL_FRONT_AND_BACK, bgl.GL_LINE)

        self.line_batch.draw(self.line_shader)

        bgl.glPolygonMode(bgl.GL_FRONT_AND_BACK, bgl.GL_FILL)
        bgl.glDepthMask(bgl.GL_TRUE)
        bgl.glDisable(bgl.GL_DEPTH_TEST)
コード例 #2
0
ファイル: edges.py プロジェクト: yanshuaitu/keentools-blender
    def draw_callback(self, op, context):
        if not self.is_visible():
            return
        # Force Stop
        wireframe_image = find_bpy_image_by_name(Config.coloring_texture_name)
        if self.is_handler_list_empty() or \
                not self._check_coloring_image(wireframe_image):
            self.unregister_handler()
            return

        bgl.glEnable(bgl.GL_BLEND)
        bgl.glEnable(bgl.GL_LINE_SMOOTH)
        bgl.glHint(bgl.GL_LINE_SMOOTH_HINT, bgl.GL_NICEST)
        bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)

        bgl.glEnable(bgl.GL_DEPTH_TEST)
        bgl.glEnable(bgl.GL_POLYGON_OFFSET_FILL)
        bgl.glPolygonOffset(1.0, 1.0)

        bgl.glColorMask(bgl.GL_FALSE, bgl.GL_FALSE, bgl.GL_FALSE, bgl.GL_FALSE)
        bgl.glPolygonMode(bgl.GL_FRONT_AND_BACK, bgl.GL_FILL)

        self.fill_batch.draw(self.fill_shader)

        bgl.glColorMask(bgl.GL_TRUE, bgl.GL_TRUE, bgl.GL_TRUE, bgl.GL_TRUE)
        bgl.glDisable(bgl.GL_POLYGON_OFFSET_FILL)

        bgl.glDepthMask(bgl.GL_FALSE)
        bgl.glPolygonMode(bgl.GL_FRONT_AND_BACK, bgl.GL_LINE)
        bgl.glEnable(bgl.GL_DEPTH_TEST)

        if not self._use_simple_shader:
            # coloring_image.bindcode should not be zero
            # if we don't want to destroy video driver in Blender
            if not wireframe_image or wireframe_image.bindcode == 0:
                self.switch_to_simple_shader()
            else:
                bgl.glActiveTexture(bgl.GL_TEXTURE0)
                bgl.glBindTexture(bgl.GL_TEXTURE_2D, wireframe_image.bindcode)
                self.line_shader.bind()
                self.line_shader.uniform_int('image', 0)
                self.line_shader.uniform_float('opacity', self._opacity)
                self.line_batch.draw(self.line_shader)

        if self._use_simple_shader:
            self.simple_line_shader.bind()
            self.simple_line_shader.uniform_float(
                'color', ((*self._colors[0][:3], self._opacity)))
            self.simple_line_batch.draw(self.simple_line_shader)

        bgl.glPolygonMode(bgl.GL_FRONT_AND_BACK, bgl.GL_FILL)
        bgl.glDepthMask(bgl.GL_TRUE)
        bgl.glDisable(bgl.GL_DEPTH_TEST)
コード例 #3
0
ファイル: __init__.py プロジェクト: pllpll2003/BlenderSource
    def clear(self):
        is_bound = self is _SnapOffscreen.bound
        if not is_bound:
            self.bind()

        bgl.glColorMask(bgl.GL_TRUE, bgl.GL_TRUE, bgl.GL_TRUE, bgl.GL_TRUE)
        bgl.glClearColor(0.0, 0.0, 0.0, 0.0)

        bgl.glDepthMask(bgl.GL_TRUE)
        bgl.glClearDepth(1.0);

        bgl.glClear(bgl.GL_COLOR_BUFFER_BIT | bgl.GL_DEPTH_BUFFER_BIT)

        if not is_bound:
            self.unbind()
コード例 #4
0
ファイル: __init__.py プロジェクト: sambler/myblenderaddons
    def clear(self):
        is_bound = self is _SnapOffscreen.bound
        if not is_bound:
            self.bind()

        bgl.glColorMask(bgl.GL_TRUE, bgl.GL_TRUE, bgl.GL_TRUE, bgl.GL_TRUE)
        bgl.glClearColor(0.0, 0.0, 0.0, 0.0)

        bgl.glDepthMask(bgl.GL_TRUE)
        bgl.glClearDepth(1.0);

        bgl.glClear(bgl.GL_COLOR_BUFFER_BIT | bgl.GL_DEPTH_BUFFER_BIT)

        if not is_bound:
            self.unbind()
コード例 #5
0
def h_mask_begin(bounds, radius=0):
    bgl.glEnable(bgl.GL_STENCIL_TEST)
    bgl.glColorMask(False, False, False, False)
    bgl.glDepthMask(False)
    bgl.glStencilFunc(bgl.GL_NEVER, 1, 0xFF)
    bgl.glStencilOp(bgl.GL_REPLACE, bgl.GL_KEEP, bgl.GL_KEEP)
    
    bgl.glStencilMask(0xFF)
    bgl.glClear(bgl.GL_STENCIL_BUFFER_BIT)
    
    h_round_rect(bounds, radius)
    
    bgl.glColorMask(True, True, True, True)
    bgl.glDepthMask(True)
    bgl.glStencilMask(0x00);
    bgl.glStencilFunc(bgl.GL_EQUAL, 0, 0xFF)
    
    bgl.glStencilFunc(bgl.GL_EQUAL, 1, 0xFF)
コード例 #6
0
ファイル: __init__.py プロジェクト: samia-done/blender_ctools
    def draw_callback(self, context):
        """
        :type context: bpy.types.Context
        """

        prefs = QuickBooleanPreferences.get_instance()
        color = prefs.color
        snap_color = prefs.snap_color

        region = context.region

        glsettings = vagl.GLSettings(context)
        glsettings.push()

        bgl.glEnable(bgl.GL_BLEND)
        bgl.glColor4f(*color)

        show_reversed = False
        if self.reverse:
            if self.mode == 'POLYGON':
                if len(self.mouse_coords) >= 3:
                    show_reversed = True
            else:
                if len(self.mouse_coords) >= 2:
                    if self.mouse_coords[0] != self.mouse_coords[1]:
                        show_reversed = True
        if show_reversed:
            bgl.glEnable(bgl.GL_DEPTH_TEST)
            bgl.glClearDepth(1.0)
            bgl.glClear(bgl.GL_DEPTH_BUFFER_BIT)
            bgl.glDepthMask(1)
            bgl.glColorMask(0, 0, 0, 0)

        lines = []
        if self.mouse_coords:
            if self.mode == 'LINE':
                w = region.width
                h = region.height
                p1, p2 = self.mouse_coords
                line = (p2 - p1).normalized()
                normal = Vector([-line[1], line[0]])
                corners = [
                    Vector([0, 0]),
                    Vector([w, 0]),
                    Vector([w, h]),
                    Vector([0, h])
                ]
                corners_ofs = [v - p1 for v in corners]
                dists = [v.project(line).dot(line) for v in corners_ofs]
                i = dists.index(min(dists))
                line_min = corners_ofs[i].project(line) + p1
                i = dists.index(max(dists))
                line_max = corners_ofs[i].project(line) + p1
                dists = [v.project(normal).dot(normal) for v in corners_ofs]
                i = dists.index(max(dists))
                normal_max_f = corners_ofs[i].project(normal).dot(normal)
                vec = normal * normal_max_f
                coords = [line_min, line_max, line_max + vec, line_min + vec]
                bgl.glBegin(bgl.GL_QUADS)
                for co in coords:
                    bgl.glVertex2f(*co)
                bgl.glEnd()
                lines = self.mouse_coords

            elif self.mode == 'BOX':
                p1, p2 = self.mouse_coords
                bgl.glRectf(p1[0], p1[1], p2[0], p2[1])
                lines = [
                    p1,
                    Vector((p2[0], p1[1])),
                    Vector((p2[0], p2[1])),
                    Vector((p1[0], p2[1])), p1
                ]
            elif self.mode == 'CIRCLE':
                p1, p2 = self.mouse_coords
                bgl.glBegin(bgl.GL_TRIANGLE_FAN)
                bgl.glVertex2f(*p1)
                r = (p2 - p1).length
                coords = calc_circle_coords(p1, r, self.circle_segments,
                                            self.circle_direction)
                for co in coords:
                    bgl.glVertex2f(*co)
                bgl.glVertex2f(*coords[0])
                bgl.glEnd()
                lines = coords + [coords[0]]
            elif self.mode == 'POLYGON':
                if len(self.mouse_coords) >= 3:
                    tris = mathutils.geometry.tessellate_polygon(
                        [[co.to_3d() for co in self.mouse_coords]])

                    bgl.glBegin(bgl.GL_TRIANGLES)
                    for tri in tris:
                        for i in tri:
                            bgl.glVertex2f(*self.mouse_coords[i])
                    bgl.glEnd()
                if len(self.mouse_coords) > 1:
                    lines = self.mouse_coords + [self.mouse_coords[0]]

        if show_reversed:
            bgl.glColorMask(1, 1, 1, 1)
            bgl.glBegin(bgl.GL_QUADS)
            bgl.glVertex3f(0, 0, -1)
            bgl.glVertex3f(region.width, 0, -1)
            bgl.glVertex3f(region.width, region.height, -1)
            bgl.glVertex3f(0, region.height, -1)
            bgl.glEnd()
            bgl.glDisable(bgl.GL_DEPTH_TEST)

        bgl.glColor4f(*color[:3], 1.0)
        bgl.glPointSize(1)
        bgl.glLineWidth(1)
        if len(lines) > 1:
            bgl.glBegin(bgl.GL_LINE_STRIP)
            for co in lines:
                bgl.glVertex2f(*co)
            bgl.glEnd()
        if self.mode == 'POLYGON':
            if len(self.mouse_coords) == 1:
                bgl.glPointSize(5)
                bgl.glBegin(bgl.GL_POINTS)
                for co in self.mouse_coords:
                    bgl.glVertex2f(*co)
                bgl.glEnd()
                bgl.glPointSize(1)
                bgl.glLineWidth(1)

        if self.mco_ctrl:
            SIZE = 12
            bgl.glColor4f(*snap_color)
            bgl.glBegin(bgl.GL_LINE_LOOP)
            v = self.mco_mod
            x = v[0] - SIZE / 2
            y = v[1] - SIZE / 2
            bgl.glVertex2f(x, y)
            bgl.glVertex2f(x + SIZE, y)
            bgl.glVertex2f(x + SIZE, y + SIZE)
            bgl.glVertex2f(x, y + SIZE)
            bgl.glEnd()

        glsettings.pop()
        glsettings.font_size()
コード例 #7
0
    def draw_lasso_shader(self):
        # create batches
        vertices = [Vector(v) for v in self.lasso_poly]
        vertices.append(Vector(self.lasso_poly[0]))

        lengths = [0]
        for a, b in zip(vertices[:-1], vertices[1:]):
            lengths.append(lengths[-1] + (a - b).length)

        bbox_vertices = ((self.lasso_xmin, self.lasso_ymax), (self.lasso_xmin,
                                                              self.lasso_ymin),
                         (self.lasso_xmax, self.lasso_ymin), (self.lasso_xmax,
                                                              self.lasso_ymax))

        fill_batch = batch_for_shader(fill_shader, 'TRI_FAN',
                                      {"pos": vertices})
        border_batch = batch_for_shader(border_shader, 'LINE_STRIP', {
            "pos": vertices,
            "len": lengths
        })
        stencil_batch = batch_for_shader(fill_shader, 'TRI_FAN',
                                         {"pos": bbox_vertices})

        matrix = gpu.matrix.get_projection_matrix()
        segment_color = (1.0, 1.0, 1.0, 1.0)
        gap_color = (0.2, 0.2, 0.2, 1.0)
        shadow_color = (0.3, 0.3, 0.3, 1.0)
        fill_color = (1.0, 1.0, 1.0, 0.04)

        # stencil mask
        # https://stackoverflow.com/a/25468363/5106051
        glClear(GL_STENCIL_BUFFER_BIT)
        glEnable(GL_STENCIL_TEST)
        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE)
        glStencilFunc(GL_ALWAYS, 0, 1)
        glStencilOp(GL_KEEP, GL_KEEP, GL_INVERT)
        glStencilMask(1)
        fill_shader.bind()
        fill_shader.uniform_float("u_ViewProjectionMatrix", matrix)
        fill_shader.uniform_vector_float(self.unif_fill_color,
                                         pack("4f", *fill_color), 4)
        fill_batch.draw(fill_shader)
        glStencilFunc(GL_EQUAL, 1, 1)
        glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP)
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE)

        # fill
        glEnable(GL_BLEND)
        stencil_batch.draw(fill_shader)
        glDisable(GL_BLEND)

        dashed = 0 if self.curr_behavior == 'CONTAIN' else 1

        if not dashed:
            # solid border shadow
            glLineWidth(3)
            border_shader.bind()
            border_shader.uniform_float("u_ViewProjectionMatrix", matrix)
            border_shader.uniform_int("u_Dashed", dashed)
            border_shader.uniform_vector_float(self.unif_segment_color,
                                               pack("4f", *shadow_color), 4)
            border_batch.draw(border_shader)
            glLineWidth(1)

            # solid border
            glDisable(GL_STENCIL_TEST)
            border_shader.uniform_vector_float(self.unif_segment_color,
                                               pack("4f", *segment_color), 4)
            border_batch.draw(border_shader)
        else:
            # dashed border
            glDisable(GL_STENCIL_TEST)
            border_shader.bind()
            border_shader.uniform_float("u_ViewProjectionMatrix", matrix)
            border_shader.uniform_int("u_Dashed", dashed)
            border_shader.uniform_vector_float(self.unif_segment_color,
                                               pack("4f", *segment_color), 4)
            border_shader.uniform_vector_float(self.unif_gap_color,
                                               pack("4f", *gap_color), 4)
            border_batch.draw(border_shader)
コード例 #8
0
ファイル: __init__.py プロジェクト: JuhaW/blender_ctools
    def draw_callback(self, context):
        """
        :type context: bpy.types.Context
        """

        prefs = QuickBooleanPreferences.get_instance()
        color = prefs.color
        snap_color = prefs.snap_color

        region = context.region

        glsettings = vagl.GLSettings(context)
        glsettings.push()

        bgl.glEnable(bgl.GL_BLEND)
        bgl.glColor4f(*color)

        show_reversed = False
        if self.reverse:
            if self.mode == 'POLYGON':
                if len(self.mouse_coords) >= 3:
                    show_reversed = True
            else:
                if len(self.mouse_coords) >= 2:
                    if self.mouse_coords[0] != self.mouse_coords[1]:
                        show_reversed = True
        if show_reversed:
            bgl.glEnable(bgl.GL_DEPTH_TEST)
            bgl.glClearDepth(1.0)
            bgl.glClear(bgl.GL_DEPTH_BUFFER_BIT)
            bgl.glDepthMask(1)
            bgl.glColorMask(0, 0, 0, 0)

        lines = []
        if self.mouse_coords:
            if self.mode == 'LINE':
                w = region.width
                h = region.height
                p1, p2 = self.mouse_coords
                line = (p2 - p1).normalized()
                normal = Vector([-line[1], line[0]])
                corners = [Vector([0, 0]), Vector([w, 0]), Vector([w, h]),
                           Vector([0, h])]
                corners_ofs = [v - p1 for v in corners]
                dists = [v.project(line).dot(line) for v in corners_ofs]
                i = dists.index(min(dists))
                line_min = corners_ofs[i].project(line) + p1
                i = dists.index(max(dists))
                line_max = corners_ofs[i].project(line) + p1
                dists = [v.project(normal).dot(normal) for v in corners_ofs]
                i = dists.index(max(dists))
                normal_max_f = corners_ofs[i].project(normal).dot(normal)
                vec = normal * normal_max_f
                coords = [line_min, line_max, line_max + vec, line_min + vec]
                bgl.glBegin(bgl.GL_QUADS)
                for co in coords:
                    bgl.glVertex2f(*co)
                bgl.glEnd()
                lines = self.mouse_coords

            elif self.mode == 'BOX':
                p1, p2 = self.mouse_coords
                bgl.glRectf(p1[0], p1[1], p2[0], p2[1])
                lines = [p1,
                         Vector((p2[0], p1[1])),
                         Vector((p2[0], p2[1])),
                         Vector((p1[0], p2[1])),
                         p1]
            elif self.mode == 'CIRCLE':
                p1, p2 = self.mouse_coords
                bgl.glBegin(bgl.GL_TRIANGLE_FAN)
                bgl.glVertex2f(*p1)
                r = (p2 - p1).length
                coords = calc_circle_coords(p1, r, self.circle_segments,
                                            self.circle_direction)
                for co in coords:
                    bgl.glVertex2f(*co)
                bgl.glVertex2f(*coords[0])
                bgl.glEnd()
                lines = coords + [coords[0]]
            elif self.mode == 'POLYGON':
                if len(self.mouse_coords) >= 3:
                    tris = mathutils.geometry.tessellate_polygon(
                        [[co.to_3d() for co in self.mouse_coords]])

                    bgl.glBegin(bgl.GL_TRIANGLES)
                    for tri in tris:
                        for i in tri:
                            bgl.glVertex2f(*self.mouse_coords[i])
                    bgl.glEnd()
                if len(self.mouse_coords) > 1:
                    lines = self.mouse_coords + [self.mouse_coords[0]]

        if show_reversed:
            bgl.glColorMask(1, 1, 1, 1)
            bgl.glBegin(bgl.GL_QUADS)
            bgl.glVertex3f(0, 0, -1)
            bgl.glVertex3f(region.width, 0, -1)
            bgl.glVertex3f(region.width, region.height, -1)
            bgl.glVertex3f(0, region.height, -1)
            bgl.glEnd()
            bgl.glDisable(bgl.GL_DEPTH_TEST)

        bgl.glColor4f(*color[:3], 1.0)
        bgl.glPointSize(1)
        bgl.glLineWidth(1)
        if len(lines) > 1:
            bgl.glBegin(bgl.GL_LINE_STRIP)
            for co in lines:
                bgl.glVertex2f(*co)
            bgl.glEnd()
        if self.mode == 'POLYGON':
            if len(self.mouse_coords) == 1:
                bgl.glPointSize(5)
                bgl.glBegin(bgl.GL_POINTS)
                for co in self.mouse_coords:
                    bgl.glVertex2f(*co)
                bgl.glEnd()
                bgl.glPointSize(1)
                bgl.glLineWidth(1)

        if self.mco_ctrl:
            SIZE = 12
            bgl.glColor4f(*snap_color)
            bgl.glBegin(bgl.GL_LINE_LOOP)
            v = self.mco_mod
            x = v[0] - SIZE / 2
            y = v[1] - SIZE / 2
            bgl.glVertex2f(x, y)
            bgl.glVertex2f(x + SIZE, y)
            bgl.glVertex2f(x + SIZE, y + SIZE)
            bgl.glVertex2f(x, y + SIZE)
            bgl.glEnd()

        glsettings.pop()
        glsettings.font_size()
コード例 #9
0
 def _set(self, instance, value):
     glColorMask(*(GL_TRUE if item else GL_FALSE for item in value))