Beispiel #1
0
 def restore_opengl(self):
     # Restore OpenGL to its default state.
     bgl.glColor4f(0, 0, 0, 1)
     bgl.glDepthRange(0, 1)
     bgl.glLineWidth(1)
     bgl.glPolygonOffset(0, 0)
     bgl.glDisable(bgl.GL_BLEND | bgl.GL_POLYGON_OFFSET_FILL)
Beispiel #2
0
    def clean(self, opts=None):
        if not self.is_dirty:
            return

        # make not dirty first in case bad things happen while drawing
        self.is_dirty = False

        if self.src_bvh:
            # normal_update() will destroy normals of
            # verts not connected to faces :(
            self.tar_bmesh.normal_update()
            for bmv in self.tar_bmesh.verts:
                if len(bmv.link_faces) != 0:
                    continue
                _, n, _, _ = self.src_bvh.find_nearest(self.src_imx * bmv.co)
                bmv.normal = (self.src_mxnorm * n).normalized()

        bgl.glNewList(self.calllist, bgl.GL_COMPILE)
        # do not change attribs if they're not set
        glSetDefaultOptions(opts=opts)
        # bgl.glPushMatrix()
        # bgl.glMultMatrixf(self.bglMatrix)
        glDrawBMFaces(self.tar_bmesh.faces, opts=opts, enableShader=False)
        glDrawBMEdges(self.tar_bmesh.edges, opts=opts, enableShader=False)
        glDrawBMVerts(self.tar_bmesh.verts, opts=opts, enableShader=False)
        bgl.glDepthRange(0, 1)
        # bgl.glPopMatrix()
        bgl.glEndList()
 def draw3d_closed_polylines(context, lpoints, color, thickness, LINE_TYPE):
     lpoints = list(lpoints)
     if LINE_TYPE == "GL_LINE_STIPPLE":
         bgl.glLineStipple(4, 0x5555)  #play with this later
         bgl.glEnable(bgl.GL_LINE_STIPPLE)  
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glLineWidth(thickness)
     bgl.glDepthRange(0.0, 0.997)
     bgl.glColor4f(*color)
     for points in lpoints:
         bgl.glBegin(bgl.GL_LINE_STRIP)
         for coord in points:
             bgl.glVertex3f(*coord)
         bgl.glVertex3f(*points[0])
         bgl.glEnd()
     if settings.symmetry_plane == 'x':
         bgl.glColor4f(*color_mirror)
         for points in lpoints:
             bgl.glBegin(bgl.GL_LINE_STRIP)
             for coord in points:
                 bgl.glVertex3f(-coord.x, coord.y, coord.z)
             bgl.glVertex3f(-points[0].x, points[0].y, points[0].z)
             bgl.glEnd()
         
     bgl.glLineWidth(1)
     if LINE_TYPE == "GL_LINE_STIPPLE":
         bgl.glDisable(bgl.GL_LINE_STIPPLE)
         bgl.glEnable(bgl.GL_BLEND)  # back to uninterrupted lines  
def draw_points_3d(points, color, size, far=0.997):
    bgl.glColor4f(*color)
    bgl.glPointSize(size)
    bgl.glDepthRange(0.0, far)
    bgl.glBegin(bgl.GL_POINTS)
    for coord in points: bgl.glVertex3f(*coord)
    bgl.glEnd()
    bgl.glPointSize(1.0)
 def draw3d_points(context, points, color, size):
     bgl.glColor4f(*color)
     bgl.glPointSize(size)
     bgl.glDepthRange(0.0, 0.997)
     bgl.glBegin(bgl.GL_POINTS)
     for coord in points: bgl.glVertex3f(*coord)
     bgl.glEnd()
     bgl.glPointSize(1.0)
Beispiel #6
0
    def draw_brush(self, brush, outline_color=(0, 0, 0, 1),
                   outline_thickness=1, interior_color=(0, 0, 0, 0.2)):
        if not self.is_enabled:
            return

        # Treat the brush as a sphere centered at the origin with a pole in the
        # direction of it's normal.  Given this scenario, find a point on the
        # sphere's equator.
        brush_radius = brush.radius
        brush_normal = brush.normal
        if brush.normal.xy != Vector((0, 0)):
            point_on_equator = brush_radius * (
                Vector((brush_normal.y, -brush_normal.x, 0)).normalized()
            )
        else:
            point_on_equator = brush_radius * (
                Vector((brush_normal.z, -brush_normal.y, 0)).normalized()
            )

        # Generate a list of radially symmetrical vertices around the pole.
        segments = 48
        rotation_matrix = Matrix.Rotation(2 * pi / segments, 3, brush_normal)
        vertices = [point_on_equator]
        for side in range(segments - 1):
            vertices.append(rotation_matrix * vertices[-1])

        # Translate the vertices from the world origin to the brush's center.
        brush_center = brush.center
        brush_center_x = brush_center.x
        brush_center_y = brush_center.y
        brush_center_z = brush_center.z
        for vertex in vertices:
            vertex.x += brush_center_x
            vertex.y += brush_center_y
            vertex.z += brush_center_z

        bgl.glEnable(bgl.GL_BLEND)
        bgl.glDepthRange(0, 0.1)

        # Draw the brush's outline.
        if outline_color[3] > 0:
            bgl.glLineWidth(outline_thickness)
            bgl.glColor4f(*outline_color)
            bgl.glBegin(bgl.GL_LINE_LOOP)
            for vertex in vertices:
                bgl.glVertex3f(*vertex)
            bgl.glEnd()

        # Draw the brush's interior.
        if interior_color[3] > 0:
            bgl.glColor4f(*interior_color)
            bgl.glBegin(bgl.GL_POLYGON)
            for vertex in vertices:
                bgl.glVertex3f(*vertex)
            bgl.glEnd()

        self.restore_opengl()
Beispiel #7
0
def draw_callback_3d(self, context):
    # object locations
    if context.scene.hecl_path_obj not in context.scene.objects:
        return
    obj = context.scene.objects[context.scene.hecl_path_obj]
    if obj.type != 'MESH':
        return
    obj_mtx = obj.matrix_world

    bm = None
    height_lay = None
    if obj == context.edit_object:
        bm = bmesh.from_edit_mesh(obj.data)
        if 'Height' in bm.faces.layers.float:
            height_lay = bm.faces.layers.float['Height']
    else:
        if 'Height' in obj.data.polygon_layers_float:
            height_lay = obj.data.polygon_layers_float['Height']

    # Deselected colors
    top_color = (0.0, 0.0, 1.0, 0.7)
    side_color = (1.0, 0.0, 0.0, 0.7)
    if bm is not None:
        for f in bm.faces:
            height = 1.0
            if height_lay is not None:
                selected = f.select
                if selected:
                    continue
                height = f[height_lay]
            draw_face(f, obj_mtx, height, top_color, side_color)
    else:
        for p in obj.data.polygons:
            height = 1.0
            if height_lay is not None:
                height = height_lay.data[p.index].value
            draw_poly(p, obj, obj_mtx, height, top_color, side_color)
    bgl.glEnd()

    # Selected colors
    if bm is not None:
        top_color = (1.0, 0.0, 1.0, 0.7)
        side_color = (0.0, 1.0, 0.0, 0.7)
        # Avoid z-fighting on selected lines
        bgl.glDepthRange(-0.001, 0.999)
        for f in bm.faces:
            if height_lay is not None:
                selected = f.select
                if not selected:
                    continue
                height = f[height_lay]
                draw_face(f, obj_mtx, height, top_color, side_color)
        bgl.glEnd()
        bgl.glDepthRange(0.0, 1.0)

    # restore opengl defaults
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
 def set_depthrange(near=0.0, far=1.0, points=None):
     if points and len(points) and view_loc:
         d2 = min((view_loc-p).length_squared for p in points)
         d = math.sqrt(d2)
         d2 /= 10.0
         near = near / d2
         far = 1.0 - ((1.0 - far) / d2)
     near = max(0.0, min(1.0, near))
     far = max(near, min(1.0, far))
     bgl.glDepthRange(near, far)
def glSetOptions(prefix, opts):
    if opts == None: return
    prefix = '%s '%prefix if prefix else ''
    if '%sdepth'%prefix in opts: bgl.glDepthRange(*opts['%sdepth'%prefix])
    if '%scolor'%prefix in opts: glColor(opts['%scolor'%prefix])
    if '%swidth'%prefix in opts: bgl.glLineWidth(opts['%swidth'%prefix])
    if '%ssize'%prefix  in opts: bgl.glPointSize(opts['%ssize'%prefix])
    if opts.get('%sstipple'%prefix, False):
        bgl.glLineStipple(4, 0x5555)  #play with this later
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
def draw3d_quad(context, points, color):
    if context.space_data.region_3d.view_perspective == 'ORTHO':
        bias = 0.9999
    else:
        bias = 0.999
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(*color)
    bgl.glDepthRange(0.0, bias)
    bgl.glBegin(bgl.GL_QUADS)
    for coord in points: bgl.glVertex3f(*coord)
    bgl.glEnd()
def set_depthrange(near, far, points, view_loc, view_ortho):
    d2 = min((view_loc-p).length_squared for p in points)
    d = math.sqrt(d2)
    d2 /= 10.0
    near = near / d2
    far = 1.0 - ((1.0 - far) / d2)
    if view_ortho:
        far *= 0.9999
    near = max(0.0, min(1.0, near))
    far = max(near, min(1.0, far))
    bgl.glDepthRange(near, far)
 def draw3d_quad(context, points, color):
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glDepthRange(0.0, 0.999)
     bgl.glBegin(bgl.GL_QUADS)
     bgl.glColor4f(*color)
     for coord in points:
         bgl.glVertex3f(*coord)
     if settings.symmetry_plane == 'x':
         bgl.glColor4f(*color_mirror)
         for coord in points:
             bgl.glVertex3f(-coord.x,coord.y,coord.z)
     bgl.glEnd()
def draw3d_points(context, points, color, size):
    if context.space_data.region_3d.view_perspective == 'ORTHO':
        bias = 0.9997
    else:
        bias = 0.997
    bgl.glColor4f(*color)
    bgl.glPointSize(size)
    bgl.glDepthRange(0.0, bias)
    bgl.glBegin(bgl.GL_POINTS)
    for coord in points: bgl.glVertex3f(*coord)  
    bgl.glEnd()
    bgl.glPointSize(1.0)
Beispiel #14
0
    def Draw(self, index_offset):
        self.first_index = index_offset
        bgl.glUseProgram(self.shader.program)
        bgl.glBindVertexArray(self.vao[0])

        bgl.glUniformMatrix4fv(self.unif_MV, 1, bgl.GL_TRUE, self.MV)
        bgl.glUniformMatrix4fv(self.unif_MVP, 1, bgl.GL_TRUE, self.MVP)

        if self.draw_tris:
            bgl.glUniform1f(self.unif_offset, float(index_offset)) # bgl has no glUniform1ui :\

            bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, self.vbo_tris[0])
            bgl.glEnableVertexAttribArray(self.attr_pos)
            bgl.glVertexAttribPointer(self.attr_pos, 3, bgl.GL_FLOAT, bgl.GL_FALSE, 0, self._NULL)

            bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, self.vbo_tri_indices[0])
            bgl.glEnableVertexAttribArray(self.attr_primitive_id)
            bgl.glVertexAttribPointer(self.attr_primitive_id, 1, bgl.GL_FLOAT, bgl.GL_FALSE, 0, self._NULL)

            bgl.glDrawArrays(bgl.GL_TRIANGLES, 0, self.num_tris * 3)

            index_offset += self.num_tris
            bgl.glDepthRange(-0.00005, 0.99995)

        if self.draw_edges:
            bgl.glUniform1f(self.unif_offset, float(index_offset)) #TODO: use glUniform1ui

            bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, self.vbo_edges[0])
            bgl.glVertexAttribPointer(self.attr_pos, 3, bgl.GL_FLOAT, bgl.GL_FALSE, 0, self._NULL)
            bgl.glEnableVertexAttribArray(self.attr_pos)

            bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, self.vbo_edge_indices[0])
            bgl.glVertexAttribPointer(self.attr_primitive_id, 1, bgl.GL_FLOAT, bgl.GL_FALSE, 0, self._NULL)
            bgl.glEnableVertexAttribArray(self.attr_primitive_id)

            bgl.glDrawArrays(bgl.GL_LINES, 0, self.num_edges * 2)

            index_offset += self.num_edges

        if self.draw_verts:
            bgl.glUniform1f(self.unif_offset, float(index_offset)) #TODO: use glUniform1ui

            bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, self.vbo_verts[0])
            bgl.glVertexAttribPointer(self.attr_pos, 3, bgl.GL_FLOAT, bgl.GL_FALSE, 0, self._NULL)
            bgl.glEnableVertexAttribArray(self.attr_pos)

            bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, self.vbo_looseverts_indices[0])
            bgl.glVertexAttribPointer(self.attr_primitive_id, 1, bgl.GL_FLOAT, bgl.GL_FALSE, 0, self._NULL)
            bgl.glEnableVertexAttribArray(self.attr_primitive_id)

            bgl.glDrawArrays(bgl.GL_POINTS, 0, self.num_verts)

        bgl.glDepthRange(0.0, 1.0)
 def draw3d_polyline(context, points, color, thickness, LINE_TYPE):
     if LINE_TYPE == "GL_LINE_STIPPLE":
         bgl.glLineStipple(4, 0x5555)  #play with this later
         bgl.glEnable(bgl.GL_LINE_STIPPLE)  
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glColor4f(*color)
     bgl.glLineWidth(thickness)
     bgl.glDepthRange(0.0, 0.997)
     bgl.glBegin(bgl.GL_LINE_STRIP)
     for coord in points: bgl.glVertex3f(*coord)
     bgl.glEnd()
     bgl.glLineWidth(1)
     if LINE_TYPE == "GL_LINE_STIPPLE":
         bgl.glDisable(bgl.GL_LINE_STIPPLE)
         bgl.glEnable(bgl.GL_BLEND)  # back to uninterrupted lines  
def draw3d_quads(context, lpoints, color): #, color_mirror):
    lpoints = list(lpoints)
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glDepthRange(0.0, 0.999)
    bgl.glBegin(bgl.GL_QUADS)
    bgl.glColor4f(*color)
    for points in lpoints:
        for coord in points:
            bgl.glVertex3f(*coord)
    
    #TODO, generic mirror pt and plane
    #if settings.symmetry_plane == 'x':
    #    bgl.glColor4f(*color_mirror)
    #    for points in lpoints:
    #        for coord in points:
    #            bgl.glVertex3f(-coord.x,coord.y,coord.z)
    bgl.glEnd()
Beispiel #17
0
    def _draw_buffered(self, alpha_above, alpha_below, cull_backfaces, alpha_backface):
        opts = dict(self.opts)
        for xyz in self.rfmesh.symmetry:
            opts['mirror %s' % xyz] = True

        opts['cull backfaces'] = cull_backfaces
        opts['alpha backface'] = alpha_backface
        opts['dpi mult'] = self.drawing.get_dpi_mult()

        # do not change attribs if they're not set
        bmegl.glSetDefaultOptions(opts=self.opts)

        bgl.glDepthMask(bgl.GL_FALSE)       # do not overwrite the depth buffer

        pr = profiler.start('geometry above')
        bgl.glDepthFunc(bgl.GL_LEQUAL)
        opts['poly hidden'] = 1 - alpha_above
        opts['poly mirror hidden'] = 1 - alpha_above
        opts['line hidden'] = 1 - alpha_above
        opts['line mirror hidden'] = 1 - alpha_above
        opts['point hidden'] = 1 - alpha_above
        opts['point mirror hidden'] = 1 - alpha_above
        for buffered_render in self.buffered_renders:
            buffered_render.draw(opts)
        pr.done()

        if not opts.get('no below', False):
            # draw geometry hidden behind
            pr = profiler.start('geometry below')
            bgl.glDepthFunc(bgl.GL_GREATER)
            opts['poly hidden'] = 1 - alpha_below
            opts['poly mirror hidden'] = 1 - alpha_below
            opts['line hidden'] = 1 - alpha_below
            opts['line mirror hidden'] = 1 - alpha_below
            opts['point hidden'] = 1 - alpha_below
            opts['point mirror hidden'] = 1 - alpha_below
            for buffered_render in self.buffered_renders:
                buffered_render.draw(opts)
            pr.done()

        bgl.glDepthFunc(bgl.GL_LEQUAL)
        bgl.glDepthMask(bgl.GL_TRUE)
        bgl.glDepthRange(0, 1)
 def draw(self, opts=None):
     if self.is_dirty:
         # make not dirty first in case bad things happen while drawing
         self.is_dirty = False
         
         bgl.glNewList(self.calllist, bgl.GL_COMPILE)
         # do not change attribs if they're not set
         glSetDefaultOptions(opts=opts)
         if self.mx:
             bgl.glPushMatrix()
             bgl.glMultMatrixf(self.bglMatrix)
         glDrawBMFaces(self.bmesh.faces, opts=opts)
         glDrawBMEdges(self.bmesh.edges, opts=opts)
         glDrawBMVerts(self.bmesh.verts, opts=opts)
         bgl.glDepthRange(0, 1)
         if self.mx:
             bgl.glPopMatrix()
         bgl.glEndList()
     
     bgl.glCallList(self.calllist)
def draw3d_polyline(context, points, color, thickness, LINE_TYPE):
    if context.region_data.view_perspective == 'ORTHO':
        bias = 0.9997
    else:
        bias = 0.997
        
    if LINE_TYPE == "GL_LINE_STIPPLE":
        bgl.glLineStipple(4, 0x5555)  #play with this later
        bgl.glEnable(bgl.GL_LINE_STIPPLE)  
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(*color)
    bgl.glLineWidth(thickness)
    bgl.glDepthRange(0.0, bias)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    for coord in points: bgl.glVertex3f(*coord)
    bgl.glEnd()
    bgl.glLineWidth(1)
    if LINE_TYPE == "GL_LINE_STIPPLE":
        bgl.glDisable(bgl.GL_LINE_STIPPLE)
        bgl.glEnable(bgl.GL_BLEND)  # back to uninterrupted lines  
Beispiel #20
0
    def Draw(self, index_offset, depth_offset = -0.00005):
        self.first_index = index_offset
        if self.draw_tris:
            self.shader.uniform_int("offset", (index_offset,))
            self.batch_tris.draw(self.shader)
            index_offset += len(self.tri_verts)
            bgl.glDepthRange(depth_offset, 1 + depth_offset)

        if self.draw_edges:
            self.shader.uniform_int("offset", (index_offset,))
            #bgl.glLineWidth(3.0)
            self.batch_edges.draw(self.shader)
            #bgl.glLineWidth(1.0)
            index_offset += len(self.edge_verts)

        if self.draw_verts:
            self.shader.uniform_int("offset", (index_offset,))
            self.batch_lverts.draw(self.shader)

        bgl.glDepthRange(0.0, 1.0)
Beispiel #21
0
    def draw_postview(self):
        if self.rfcontext.nav: return
        if not self.nearest_edge: return
        if self.rfcontext.actions.ctrl and not self.rfcontext.actions.shift and self.mode == 'main':
            # draw new edge strip/loop

            def draw():
                if not self.edges_: return
                self.drawing.enable_stipple()
                if self.edge_loop:
                    bgl.glBegin(bgl.GL_LINE_LOOP)
                else:
                    bgl.glBegin(bgl.GL_LINE_STRIP)
                for _,c0,c1 in self.edges_:
                    c = c0 + (c1 - c0) * self.percent
                    bgl.glVertex3f(*c)
                bgl.glEnd()
                self.drawing.disable_stipple()

            self.drawing.point_size(5.0)
            self.drawing.line_width(2.0)
            bgl.glDisable(bgl.GL_CULL_FACE)
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glDepthMask(bgl.GL_FALSE)
            bgl.glDepthRange(0, 0.9990)     # squeeze depth just a bit

            # draw above
            bgl.glEnable(bgl.GL_DEPTH_TEST)
            bgl.glDepthFunc(bgl.GL_LEQUAL)
            bgl.glColor4f(0.15, 1.00, 0.15, 1.00)
            draw()

            # draw below
            bgl.glDepthFunc(bgl.GL_GREATER)
            bgl.glColor4f(0.15, 1.00, 0.15, 0.25)
            draw()

            bgl.glEnable(bgl.GL_CULL_FACE)
            bgl.glDepthMask(bgl.GL_TRUE)
            bgl.glDepthFunc(bgl.GL_LEQUAL)
            bgl.glDepthRange(0, 1)
Beispiel #22
0
def draw3d_closed_polylines(context, lpoints, color, thickness, LINE_TYPE):
    if context.space_data.region_3d.view_perspective == 'ORTHO':
        bias = 0.9997
    else:
        bias = 0.997
    if LINE_TYPE == "GL_LINE_STIPPLE":
        bgl.glLineStipple(4, 0x5555)  #play with this later
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(*color)
    bgl.glLineWidth(thickness)
    bgl.glDepthRange(0.0, bias)
    for points in lpoints:
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for coord in points:
            bgl.glVertex3f(*coord)
        bgl.glVertex3f(*points[0])
        bgl.glEnd()
    bgl.glLineWidth(1)
    if LINE_TYPE == "GL_LINE_STIPPLE":
        bgl.glDisable(bgl.GL_LINE_STIPPLE)
        bgl.glEnable(bgl.GL_BLEND)  # back to uninterrupted lines
    def draw_circle(self, world_loc, radius, inner_ratio, color_outside, color_inside):
        bgl.glDepthRange(0, 0.9999)     # squeeze depth just a bit
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glDepthMask(bgl.GL_FALSE)   # do not overwrite depth
        bgl.glEnable(bgl.GL_DEPTH_TEST)
        bgl.glDepthFunc(bgl.GL_LEQUAL)  # draw in front of geometry

        circleShader.enable()
        self.drawing.point_size(2.0 * radius)
        circleShader['uMVPMatrix'] = self.drawing.get_view_matrix_buffer()
        circleShader['uInOut']     = inner_ratio

        bgl.glBegin(bgl.GL_POINTS)
        circleShader['vOutColor'] = color_outside
        circleShader['vInColor']  = color_inside
        bgl.glVertex3f(*world_loc)
        bgl.glEnd()

        circleShader.disable()

        bgl.glDepthFunc(bgl.GL_LEQUAL)
        bgl.glDepthRange(0.0, 1.0)
        bgl.glDepthMask(bgl.GL_TRUE)
    def draw_circle(self, world_loc, radius, inner_ratio, color_outside, color_inside):
        bgl.glDepthRange(0, 0.9999)     # squeeze depth just a bit
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glDepthMask(bgl.GL_FALSE)   # do not overwrite depth
        bgl.glEnable(bgl.GL_DEPTH_TEST)
        bgl.glDepthFunc(bgl.GL_LEQUAL)  # draw in front of geometry

        circleShader.enable()
        self.drawing.point_size(2.0 * radius)
        circleShader['uMVPMatrix'] = self.drawing.get_view_matrix_buffer()
        circleShader['uInOut']     = inner_ratio

        bgl.glBegin(bgl.GL_POINTS)
        circleShader['vOutColor'] = color_outside
        circleShader['vInColor']  = color_inside
        bgl.glVertex3f(*world_loc)
        bgl.glEnd()

        circleShader.disable()

        bgl.glDepthFunc(bgl.GL_LEQUAL)
        bgl.glDepthRange(0.0, 1.0)
        bgl.glDepthMask(bgl.GL_TRUE)
            def draw_brush(self):
                xy = self.rfcontext.actions.mouse
                p,n,_,_ = self.rfcontext.raycast_sources_mouse()
                if not p: return
                depth = self.rfcontext.Point_to_depth(p)
                if not depth: return
                self.scale = self.rfcontext.size2D_to_size(1.0, xy, depth)

                r = self.radius
                co = self.outer_color
                ci = self.inner_color
                cc = self.fill_color * self.fill_color_scale
                ff = math.pow(0.5, 1.0 / self.falloff)
                fs = (1-ff) * r * self.scale
                bgl.glDepthRange(0.0, 0.99996)
                Globals.drawing.draw3D_circle(p, r*self.scale - fs, cc, n=n, width=fs)
                bgl.glDepthRange(0.0, 0.99995)
                Globals.drawing.draw3D_circle(p, r*self.scale, co, n=n, width=2*self.scale)
                Globals.drawing.draw3D_circle(p, r*self.scale*ff, ci, n=n, width=2*self.scale)
                bgl.glDepthRange(0.0, 1.0)
    def draw_3D_stuff(self):

        return

        context = self.context
        region, r3d = context.region, context.space_data.region_3d
        view_dir = r3d.view_rotation * Vector((0, 0, -1))
        view_loc = r3d.view_location - view_dir * r3d.view_distance
        view_ortho = (r3d.view_perspective == 'ORTHO')
        if view_ortho: view_loc -= view_dir * 1000.0

        bgl.glEnable(bgl.GL_POINT_SMOOTH)
        bgl.glDepthRange(0.0, 1.0)
        bgl.glEnable(bgl.GL_DEPTH_TEST)
        bgl.glLineWidth(1)
        bgl.glDepthRange(0.0, 1.0)

        if self._state != 'segmentation':
            #CurveNetwork, BezierSegments
            for seg in self.spline_net.segments:
                if len(seg.draw_tessellation) == 0: continue

                #has not been successfully converted to InputPoints and InputSegments
                if seg.is_inet_dirty:
                    draw3d_polyline(seg.draw_tessellation, orange2, 4,
                                    view_loc, view_ortho)

                #if len(seg.ip_tesselation):
                #    draw3d_polyline(seg.ip_tesselation,  blue, 2, view_loc, view_ortho)
                #    draw3d_points(seg.ip_tesselation, green2, 4, view_loc, view_ortho)

            draw3d_points(self.spline_net.point_world_locs, green2, 6,
                          view_loc, view_ortho)

            # Polylines...InputSegments
            for seg in self.input_net.segments:
                #bad segment with a preview path provided by geodesic
                if seg.bad_segment and not len(seg.path) > 2:
                    draw3d_polyline([seg.ip0.world_loc, seg.ip1.world_loc],
                                    pink, 2, view_loc, view_ortho)

                #s
                elif len(
                        seg.path
                ) >= 2 and not seg.bad_segment and seg not in self.network_cutter.completed_segments:
                    draw3d_polyline(seg.path, blue, 2, view_loc, view_ortho)

                elif len(
                        seg.path
                ) >= 2 and not seg.bad_segment and seg in self.network_cutter.completed_segments:
                    draw3d_polyline(seg.path, green2, 2, view_loc, view_ortho)

                elif len(seg.path) >= 2 and seg.bad_segment:
                    draw3d_polyline(seg.path, orange2, 2, view_loc, view_ortho)
                    draw3d_polyline([seg.ip0.world_loc, seg.ip1.world_loc],
                                    orange2, 2, view_loc, view_ortho)

                elif seg.calculation_complete == False:
                    draw3d_polyline([seg.ip0.world_loc, seg.ip1.world_loc],
                                    orange2, 2, view_loc, view_ortho)
                else:
                    draw3d_polyline([seg.ip0.world_loc, seg.ip1.world_loc],
                                    blue2, 2, view_loc, view_ortho)

            if self.network_cutter.the_bad_segment:
                seg = self.network_cutter.the_bad_segment
                draw3d_polyline([seg.ip0.world_loc, seg.ip1.world_loc], red, 4,
                                view_loc, view_ortho)

        if self._state == 'segmentation':
            #draw the hovered patch
            #TODO, segmentation only happens AFTER CUtting
            #So it would be MUCH easier to just draw the damn edges of the patch
            if self.net_ui_context.hovered_near[0] == 'PATCH':
                p = self.net_ui_context.hovered_near[1]
                if p != self.network_cutter.active_patch:
                    for spline_seg in p.spline_net_segments:
                        for iseg in spline_seg.input_segments:
                            draw3d_polyline([iseg.ip0.world_loc] + iseg.path +
                                            [iseg.ip1.world_loc], orange2, 4,
                                            view_loc, view_ortho)

            if self.network_cutter.active_patch:
                for spline_seg in self.network_cutter.active_patch.spline_net_segments:
                    for iseg in spline_seg.input_segments:
                        draw3d_polyline([iseg.ip0.world_loc] + iseg.path +
                                        [iseg.ip1.world_loc], orange2, 4,
                                        view_loc, view_ortho)

        if self._state == 'spline':
            draw3d_points(self.input_net.point_world_locs, blue, 2, view_loc,
                          view_ortho)
        elif self._state != 'segmentation':
            draw3d_points(self.input_net.point_world_locs, blue, 6, view_loc,
                          view_ortho)

        #draw the seed/face patch points
        draw3d_points([p.world_loc for p in self.network_cutter.face_patches],
                      orange2, 6, view_loc, view_ortho)

        #draw the actively processing Input Point (IP Steper Debug) for debug stepper cutting
        if self.network_cutter.active_ip:
            draw3d_points([self.network_cutter.active_ip.world_loc], purple,
                          20, view_loc, view_ortho)
            draw3d_points(
                [ip.world_loc for ip in self.network_cutter.ip_chain], purple,
                12, view_loc, view_ortho)

        if self.network_cutter.seg_enter:
            draw3d_polyline(self.network_cutter.seg_enter.path, green2, 4,
                            view_loc, view_ortho)

        if self.network_cutter.seg_exit:
            draw3d_polyline(self.network_cutter.seg_exit.path, red, 4,
                            view_loc, view_ortho)

        bgl.glLineWidth(1)
        bgl.glDepthFunc(bgl.GL_LEQUAL)
        bgl.glDepthRange(0.0, 1.0)
        bgl.glDepthMask(bgl.GL_TRUE)
    def Draw(self, index_offset):
        self.first_index = index_offset
        bgl.glUseProgram(self.shader.program)
        bgl.glBindVertexArray(self.vao[0])

        bgl.glUniformMatrix4fv(self.unif_MV, 1, bgl.GL_TRUE, self.MV)
        bgl.glUniformMatrix4fv(self.unif_MVP, 1, bgl.GL_TRUE, self.MVP)

        if self.draw_tris:
            bgl.glUniform1f(self.unif_offset,
                            float(index_offset))  # bgl has no glUniform1ui :\

            bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, self.vbo_tris[0])
            bgl.glEnableVertexAttribArray(self.attr_pos)
            bgl.glVertexAttribPointer(self.attr_pos, 3, bgl.GL_FLOAT,
                                      bgl.GL_FALSE, 0, self._NULL)

            bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, self.vbo_tri_indices[0])
            bgl.glEnableVertexAttribArray(self.attr_primitive_id)
            bgl.glVertexAttribPointer(self.attr_primitive_id, 1, bgl.GL_FLOAT,
                                      bgl.GL_FALSE, 0, self._NULL)

            bgl.glDrawArrays(bgl.GL_TRIANGLES, 0, self.num_tris * 3)

            index_offset += self.num_tris
            bgl.glDepthRange(-0.00005, 0.99995)

        if self.draw_edges:
            bgl.glUniform1f(self.unif_offset,
                            float(index_offset))  #TODO: use glUniform1ui

            bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, self.vbo_edges[0])
            bgl.glVertexAttribPointer(self.attr_pos, 3, bgl.GL_FLOAT,
                                      bgl.GL_FALSE, 0, self._NULL)
            bgl.glEnableVertexAttribArray(self.attr_pos)

            bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, self.vbo_edge_indices[0])
            bgl.glVertexAttribPointer(self.attr_primitive_id, 1, bgl.GL_FLOAT,
                                      bgl.GL_FALSE, 0, self._NULL)
            bgl.glEnableVertexAttribArray(self.attr_primitive_id)

            bgl.glDrawArrays(bgl.GL_LINES, 0, self.num_edges * 2)

            index_offset += self.num_edges

        if self.draw_verts:
            bgl.glUniform1f(self.unif_offset,
                            float(index_offset))  #TODO: use glUniform1ui

            bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER, self.vbo_verts[0])
            bgl.glVertexAttribPointer(self.attr_pos, 3, bgl.GL_FLOAT,
                                      bgl.GL_FALSE, 0, self._NULL)
            bgl.glEnableVertexAttribArray(self.attr_pos)

            bgl.glBindBuffer(bgl.GL_ARRAY_BUFFER,
                             self.vbo_looseverts_indices[0])
            bgl.glVertexAttribPointer(self.attr_primitive_id, 1, bgl.GL_FLOAT,
                                      bgl.GL_FALSE, 0, self._NULL)
            bgl.glEnableVertexAttribArray(self.attr_primitive_id)

            bgl.glDrawArrays(bgl.GL_POINTS, 0, self.num_verts)

        bgl.glDepthRange(0.0, 1.0)
Beispiel #28
0
    def draw_3d(self, context):
        settings = common_utilities.get_settings()
        region, r3d = context.region, context.space_data.region_3d
        view_dir = r3d.view_rotation * Vector((0, 0, -1))
        view_loc = r3d.view_location - view_dir * r3d.view_distance
        if r3d.view_perspective == 'ORTHO': view_loc -= view_dir * 1000.0
        view_loc_x = vector_mirror_x(view_loc)

        color_inactive = settings.theme_colors_mesh[settings.theme]
        color_selection = settings.theme_colors_selection[settings.theme]
        color_active = settings.theme_colors_active[settings.theme]

        color_frozen = settings.theme_colors_frozen[settings.theme]
        color_warning = settings.theme_colors_warning[settings.theme]

        bgl.glEnable(bgl.GL_POINT_SMOOTH)

        color_handle = (color_inactive[0], color_inactive[1],
                        color_inactive[2], 1.00)
        color_border = (color_inactive[0], color_inactive[1],
                        color_inactive[2], 1.00)
        color_fill = (color_inactive[0], color_inactive[1], color_inactive[2],
                      0.20)
        color_mirror = (color_frozen[0], color_frozen[1], color_frozen[2],
                        0.20)

        #bgl.glDepthRange(0.0, 0.999)
        bgl.glDepthRange(0.0, 1.0)
        bgl.glEnable(bgl.GL_DEPTH_TEST)

        def set_depthrange(near=0.0, far=1.0, points=None):
            if points and len(points) and view_loc:
                d2 = min((view_loc - p).length_squared for p in points)
                d = math.sqrt(d2)
                d2 /= 10.0
                near = near / d2
                far = 1.0 - ((1.0 - far) / d2)
            if r3d.view_perspective == 'ORTHO':
                far *= 0.9999
            near = max(0.0, min(1.0, near))
            far = max(near, min(1.0, far))
            bgl.glDepthRange(near, far)
            #bgl.glDepthRange(0.0, 0.5)

        def draw3d_polyline(context,
                            points,
                            color,
                            thickness,
                            LINE_TYPE,
                            mirror,
                            zfar=0.997):
            points = [mirror(pt) for pt in points]
            if len(points) == 0: return
            # if type(points) is types.GeneratorType:
            #     points = list(points)
            if LINE_TYPE == "GL_LINE_STIPPLE":
                bgl.glLineStipple(4, 0x5555)  #play with this later
                bgl.glEnable(bgl.GL_LINE_STIPPLE)
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glColor4f(*color)
            bgl.glLineWidth(thickness)
            set_depthrange(0.0, zfar, points)
            bgl.glBegin(bgl.GL_LINE_STRIP)
            for coord in points:
                bgl.glVertex3f(*coord)
            bgl.glEnd()
            bgl.glLineWidth(1)
            if LINE_TYPE == "GL_LINE_STIPPLE":
                bgl.glDisable(bgl.GL_LINE_STIPPLE)
                bgl.glEnable(bgl.GL_BLEND)  # back to uninterrupted lines

        def draw3d_closed_polylines(context, lpoints, color, thickness,
                                    LINE_TYPE, mirror):
            #if type(lpoints) is types.GeneratorType:
            #    lpoints = list(lpoints)
            lpoints = [[mirror(pt) for pt in points] for points in lpoints]
            if len(lpoints) == 0: return
            if LINE_TYPE == "GL_LINE_STIPPLE":
                bgl.glLineStipple(4, 0x5555)  #play with this later
                bgl.glEnable(bgl.GL_LINE_STIPPLE)
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glLineWidth(thickness)
            bgl.glColor4f(*color)
            for points in lpoints:
                set_depthrange(0.0, 0.997, points)
                bgl.glBegin(bgl.GL_LINE_STRIP)
                for coord in chain(points, points[:1]):
                    bgl.glVertex3f(*coord)
                bgl.glEnd()
            # if settings.symmetry_plane == 'x':
            #     bgl.glColor4f(*color_mirror)
            #     for points in lpoints:
            #         bgl.glBegin(bgl.GL_LINE_STRIP)
            #         for coord in points:
            #             bgl.glVertex3f(-coord.x, coord.y, coord.z)
            #         bgl.glVertex3f(-points[0].x, points[0].y, points[0].z)
            #         bgl.glEnd()

            bgl.glLineWidth(1)
            if LINE_TYPE == "GL_LINE_STIPPLE":
                bgl.glDisable(bgl.GL_LINE_STIPPLE)
                bgl.glEnable(bgl.GL_BLEND)  # back to uninterrupted lines

        def draw3d_quad(context, points, color, mirror):
            #if type(points) is types.GeneratorType:
            #    points = list(points)
            points = [mirror(pt) for pt in points]
            if len(points) == 0: return
            bgl.glEnable(bgl.GL_BLEND)
            set_depthrange(0.0, 0.998, points)
            bgl.glBegin(bgl.GL_QUADS)
            bgl.glColor4f(*color)
            for coord in points:
                bgl.glVertex3f(*coord)
            # if settings.symmetry_plane == 'x':
            #     bgl.glColor4f(*color_mirror)
            #     for coord in points:
            #         bgl.glVertex3f(-coord.x,coord.y,coord.z)
            bgl.glEnd()

        def draw3d_quads(context, lpoints, color, mirror):
            #if type(lpoints) is types.GeneratorType:
            #    lpoints = list(lpoints)
            lpoints = [[mirror(pt) for pt in points] for points in lpoints]
            if len(lpoints) == 0: return
            bgl.glEnable(bgl.GL_BLEND)
            set_depthrange(0.0, 0.998, [p for pts in lpoints for p in pts])
            bgl.glBegin(bgl.GL_QUADS)
            bgl.glColor4f(*color)
            for points in lpoints:
                for coord in points:
                    bgl.glVertex3f(*coord)
            # if settings.symmetry_plane == 'x':
            #     bgl.glColor4f(*color_mirror)
            #     for points in lpoints:
            #         for coord in points:
            #             bgl.glVertex3f(-coord.x,coord.y,coord.z)
            bgl.glEnd()

        def draw3d_points(context, points, color, size, mirror):
            #if type(points) is types.GeneratorType:
            #    points = list(points)
            points = [mirror(pt) for pt in points]
            if len(points) == 0: return
            bgl.glColor4f(*color)
            bgl.glPointSize(size)
            set_depthrange(0.0, 0.997, points)
            bgl.glBegin(bgl.GL_POINTS)
            for coord in points:
                bgl.glVertex3f(*coord)
            bgl.glEnd()
            bgl.glPointSize(1.0)

        def freeze_color(c):
            return (c[0] * 0.5 + color_frozen[0] * 0.5,
                    c[1] * 0.5 + color_frozen[1] * 0.5,
                    c[2] * 0.5 + color_frozen[2] * 0.5, c[3])

        ### Existing Geometry ###
        opts = {
            'poly color':
            (color_frozen[0], color_frozen[1], color_frozen[2], 0.20),
            'poly depth': (0, 0.999),
            'poly mirror color': (color_mirror[0], color_mirror[1],
                                  color_mirror[2], color_mirror[3]),
            'poly mirror depth': (0, 0.999),
            'line color':
            (color_frozen[0], color_frozen[1], color_frozen[2], 1.00),
            'line depth': (0, 0.997),
            'line mirror color': (color_mirror[0], color_mirror[1],
                                  color_mirror[2], color_mirror[3]),
            'line mirror depth': (0, 0.997),
            'line mirror stipple':
            True,
            'mirror x':
            self.settings.symmetry_plane == 'x',
        }
        self.tar_bmeshrender.draw(opts=opts)

        ### Patches ###
        for gpatch in self.polystrips.gpatches:
            if gpatch == self.act_gpatch:
                color_border = (color_active[0], color_active[1],
                                color_active[2], 0.50)
                color_fill = (color_active[0], color_active[1],
                              color_active[2], 0.20)
            else:
                color_border = (color_inactive[0], color_inactive[1],
                                color_inactive[2], 0.50)
                color_fill = (color_inactive[0], color_inactive[1],
                              color_inactive[2], 0.10)
            if gpatch.is_frozen() and gpatch == self.act_gpatch:
                color_border = (color_frozen[0], color_frozen[1],
                                color_frozen[2], 1.00)
                color_fill = (color_active[0], color_active[1],
                              color_active[2], 0.20)
            elif gpatch.is_frozen():
                color_border = (color_frozen[0], color_frozen[1],
                                color_frozen[2], 1.00)
                color_fill = (color_frozen[0], color_frozen[1],
                              color_frozen[2], 0.20)
            if gpatch.count_error and gpatch == self.act_gpatch:
                color_border = (color_warning[0], color_warning[1],
                                color_warning[2], 0.50)
                color_fill = (color_active[0], color_active[1],
                              color_active[2], 0.20)
            elif gpatch.count_error:
                color_border = (color_warning[0], color_warning[1],
                                color_warning[2], 0.50)
                color_fill = (color_warning[0], color_warning[1],
                              color_warning[2], 0.10)

            draw3d_quads(context, gpatch.iter_segments(view_loc), color_fill,
                         vector_mirror_0)
            draw3d_closed_polylines(context, gpatch.iter_segments(view_loc),
                                    color_border, 1, "GL_LINE_STIPPLE",
                                    vector_mirror_0)
            draw3d_points(context, gpatch.iter_pts(view_loc), color_border, 3,
                          vector_mirror_0)
            if settings.symmetry_plane == 'x':
                draw3d_quads(context, gpatch.iter_segments(view_loc_x),
                             color_mirror, vector_mirror_x)
                draw3d_closed_polylines(context,
                                        gpatch.iter_segments(view_loc_x),
                                        color_mirror, 1, "GL_LINE_STIPPLE",
                                        vector_mirror_x)
                #draw3d_points(context, gpatch.iter_pts(view_loc_x), color_border, 3, vector_mirror_x)

        ### Edges ###
        for gedge in self.polystrips.gedges:
            # Color active strip
            if gedge == self.act_gedge:
                color_border = (color_active[0], color_active[1],
                                color_active[2], 1.00)
                color_fill = (color_active[0], color_active[1],
                              color_active[2], 0.20)
            # Color selected strips
            elif gedge in self.sel_gedges:
                color_border = (color_selection[0], color_selection[1],
                                color_selection[2], 0.75)
                color_fill = (color_selection[0], color_selection[1],
                              color_selection[2], 0.20)
            # Color unselected strips
            else:
                color_border = (color_inactive[0], color_inactive[1],
                                color_inactive[2], 1.00)
                color_fill = (color_inactive[0], color_inactive[1],
                              color_inactive[2], 0.20)

            if gedge.is_frozen() and gedge in self.sel_gedges:
                color_border = (color_frozen[0], color_frozen[1],
                                color_frozen[2], 1.00)
                color_fill = (color_active[0], color_active[1],
                              color_active[2], 0.20)
            elif gedge.is_frozen():
                color_border = (color_frozen[0], color_frozen[1],
                                color_frozen[2], 1.00)
                color_fill = (color_frozen[0], color_frozen[1],
                              color_frozen[2], 0.20)

            draw3d_quads(context, gedge.iter_segments(view_loc), color_fill,
                         vector_mirror_0)
            draw3d_closed_polylines(context, gedge.iter_segments(view_loc),
                                    color_border, 1, "GL_LINE_STIPPLE",
                                    vector_mirror_0)
            if settings.symmetry_plane == 'x':
                draw3d_quads(context, gedge.iter_segments(view_loc_x),
                             color_mirror, vector_mirror_x)
                draw3d_closed_polylines(context,
                                        gedge.iter_segments(view_loc_x),
                                        color_mirror, 1, "GL_LINE_STIPPLE",
                                        vector_mirror_x)

            if settings.debug >= 2:
                # draw bezier
                p0, p1, p2, p3 = gedge.get_snappositions(
                )  #gvert0.snap_pos, gedge.gvert1.snap_pos, gedge.gvert2.snap_pos, gedge.gvert3.snap_pos
                n0, n1, n2, n3 = gedge.get_snapnormals()
                r0, r1, r2, r3 = gedge.get_radii()
                p1 = p1 + (n1 * (r0 * max(0.0, (1.0 - n0.dot(n3)) +
                                          (1.0 - n0.dot(n1)))))
                p2 = p2 + (n2 * (r3 * max(0.0, (1.0 - n0.dot(n3)) +
                                          (1.0 - n3.dot(n2)))))
                p3d = [
                    cubic_bezier_blend_t(p0, p1, p2, p3, t / 16.0)
                    for t in range(17)
                ]
                draw3d_polyline(context, p3d, (1, 1, 1, 0.5), 1,
                                "GL_LINE_STIPPLE", vector_mirror_0)

        if settings.debug >= 2:
            for gp in self.polystrips.gpatches:
                for rev, gedgeseries in zip(gp.rev, gp.gedgeseries):
                    for revge, ge in zip(gedgeseries.rev, gedgeseries.gedges):
                        color = (0.25, 0.5, 0.25,
                                 0.9) if not revge else (0.5, 0.25, 0.25, 0.9)
                        draw3d_arrow(context, ge.gvert0.snap_pos,
                                     ge.gvert3.snap_pos, ge.gvert0.snap_norm,
                                     color, 2, '')
                    color = (0.5, 1.0, 0.5, 0.5) if not rev else (1, 0.5, 0.5,
                                                                  0.5)
                    draw3d_arrow(context, gedgeseries.gvert0.snap_pos,
                                 gedgeseries.gvert3.snap_pos,
                                 gedgeseries.gvert0.snap_norm, color, 2, '')

        ### Verts ###
        for gv in self.polystrips.gverts:
            p0, p1, p2, p3 = gv.get_corners()

            if gv.is_unconnected() and not gv.from_mesh: continue

            is_active = False
            is_active |= gv == self.act_gvert
            is_active |= self.act_gedge != None and (
                self.act_gedge.gvert0 == gv or self.act_gedge.gvert1 == gv)
            is_active |= self.act_gedge != None and (
                self.act_gedge.gvert2 == gv or self.act_gedge.gvert3 == gv)

            # Theme colors for selected and unselected gverts
            if is_active:
                color_border = (color_active[0], color_active[1],
                                color_active[2], 0.75)
                color_fill = (color_active[0], color_active[1],
                              color_active[2], 0.20)
            else:
                color_border = (color_inactive[0], color_inactive[1],
                                color_inactive[2], 1.00)
                color_fill = (color_inactive[0], color_inactive[1],
                              color_inactive[2], 0.20)
            # # Take care of gverts in selected edges
            if gv in self.sel_gverts:
                color_border = (color_selection[0], color_selection[1],
                                color_selection[2], 0.75)
                color_fill = (color_selection[0], color_selection[1],
                              color_selection[2], 0.20)
            if gv.is_frozen() and is_active:
                color_border = (color_frozen[0], color_frozen[1],
                                color_frozen[2], 1.00)
                color_fill = (color_active[0], color_active[1],
                              color_active[2], 0.20)
            elif gv.is_frozen():
                color_border = (color_frozen[0], color_frozen[1],
                                color_frozen[2], 1.00)
                color_fill = (color_frozen[0], color_frozen[1],
                              color_frozen[2], 0.20)

            p3d = [p0, p1, p2, p3, p0]
            if gv.is_visible(r3d):
                draw3d_quads(context, [[p0, p1, p2, p3]], color_fill,
                             vector_mirror_0)
                draw3d_polyline(context, p3d, color_border, 1,
                                "GL_LINE_STIPPLE", vector_mirror_0)
            if settings.symmetry_plane == 'x' and gv.is_visible(r3d,
                                                                mirror_x=True):
                draw3d_quads(context, [[p0, p1, p2, p3]], color_mirror,
                             vector_mirror_x)
                draw3d_polyline(context, p3d, color_mirror, 1,
                                "GL_LINE_STIPPLE", vector_mirror_x)

            if settings.debug >= 2:
                l = 0.1
                sp, sn, sx, sy = gv.snap_pos, gv.snap_norm, gv.snap_tanx, gv.snap_tany
                draw3d_polyline(context, [sp, sp + sn * l], (0, 0, 1, 0.5), 1,
                                "", vector_mirror_0)
                draw3d_polyline(context, [sp, sp + sx * l], (1, 0, 0, 0.5), 1,
                                "", vector_mirror_0)
                draw3d_polyline(context, [sp, sp + sy * l], (0, 1, 0, 0.5), 1,
                                "", vector_mirror_0)

        # Draw inner gvert handles (dots) on each gedge
        p3d = [
            gvert.position for gvert in self.polystrips.gverts
            if not gvert.is_unconnected() and gvert.is_visible(r3d)
        ]
        # color_handle = (color_active[0], color_active[1], color_active[2], 1.00)
        draw3d_points(context, p3d, color_handle, 4, vector_mirror_0)

        ### Vert Handles ###
        if self.act_gvert:
            color_handle = (color_active[0], color_active[1], color_active[2],
                            1.00)
            gv = self.act_gvert
            p0 = gv.position
            draw3d_points(context, [p0], color_handle, 8, vector_mirror_0)

            if gv.is_inner():
                # Draw inner handle when selected
                innergv = gv.gedge_inner.get_outer_gvert_at(gv)
                if innergv.is_visible(r3d):
                    bgl.glDisable(bgl.GL_DEPTH_TEST)
                p1 = innergv.position
                draw3d_polyline(context, [p0, p1], color_handle, 2,
                                "GL_LINE_SMOOTH", vector_mirror_0)
            else:
                # Draw both handles when gvert is selected
                innergvs = [
                    ge.get_inner_gvert_at(gv)
                    for ge in gv.get_gedges_notnone()
                    if not ge.is_zippered() and not ge.is_frozen()
                ]
                draw3d_points(context,
                              [innergv.position for innergv in innergvs],
                              color_handle, 8, vector_mirror_0)
                # Draw connecting line between handles
                p0vis = gv.is_visible(r3d)
                for innergv in innergvs:
                    p1 = innergv.position
                    p1vis = innergv.is_visible(r3d)
                    if p0vis and p1vis:
                        bgl.glDisable(bgl.GL_DEPTH_TEST)
                    else:
                        bgl.glEnable(bgl.GL_DEPTH_TEST)
                    draw3d_polyline(context, [p0, p1], color_handle, 2,
                                    "GL_LINE_SMOOTH", vector_mirror_0)

            bgl.glEnable(bgl.GL_DEPTH_TEST)

        # Draw gvert handles on active gedge
        if self.act_gedge and not self.act_gedge.is_frozen():
            color_handle = (color_active[0], color_active[1], color_active[2],
                            1.00)
            ge = self.act_gedge
            if self.act_gedge.is_zippered():
                p3d = [ge.gvert0.position, ge.gvert3.position]
                draw3d_points(context, p3d, color_handle, 8, vector_mirror_0)
            else:
                vis = [gv.is_visible(r3d) for gv in ge.gverts()]
                p3d = [gv.position for gv in ge.gverts()]
                draw3d_points(context, p3d, color_handle, 8, vector_mirror_0)
                if vis[0] and vis[1]:
                    bgl.glDisable(bgl.GL_DEPTH_TEST)
                draw3d_polyline(context, [p3d[0], p3d[1]], color_handle, 2,
                                "GL_LINE_SMOOTH", vector_mirror_0)
                if vis[2] and vis[3]:
                    bgl.glDisable(bgl.GL_DEPTH_TEST)
                else:
                    bgl.glEnable(bgl.GL_DEPTH_TEST)
                draw3d_polyline(context, [p3d[2], p3d[3]], color_handle, 2,
                                "GL_LINE_SMOOTH", vector_mirror_0)
                bgl.glEnable(bgl.GL_DEPTH_TEST)
                if False:
                    # draw each normal of each gvert
                    for p, n in zip(p3d, [gv.snap_norm for gv in ge.gverts()]):
                        draw3d_polyline(context, [p, p + n * 0.1],
                                        color_handle, 1, "GL_LINE_SMOOTH",
                                        vector_mirror_0)

        if self.hov_gvert:  #TODO, hover color
            color_border = (color_selection[0], color_selection[1],
                            color_selection[2], 1.00)
            color_fill = (color_selection[0], color_selection[1],
                          color_selection[2], 0.20)

            gv = self.hov_gvert
            p0, p1, p2, p3 = gv.get_corners()
            p3d = [p0, p1, p2, p3, p0]
            draw3d_quad(context, [p0, p1, p2, p3], color_fill, vector_mirror_0)
            draw3d_polyline(context, p3d, color_border, 1, "GL_LINE_STIPPLE",
                            vector_mirror_0)

        bgl.glLineWidth(1)
        bgl.glDepthRange(0.0, 1.0)
    def draw_3d(self, context):
        settings = common_utilities.get_settings()
        region,r3d = context.region,context.space_data.region_3d
        
        color_inactive = settings.theme_colors_mesh[settings.theme]
        color_selection = settings.theme_colors_selection[settings.theme]
        color_active = settings.theme_colors_active[settings.theme]

        color_frozen = settings.theme_colors_frozen[settings.theme]
        color_warning = settings.theme_colors_warning[settings.theme]

        bgl.glEnable(bgl.GL_POINT_SMOOTH)

        color_handle = (color_inactive[0], color_inactive[1], color_inactive[2], 1.00)
        color_border = (color_inactive[0], color_inactive[1], color_inactive[2], 1.00)
        color_fill   = (color_inactive[0], color_inactive[1], color_inactive[2], 0.20)
        color_mirror = (color_frozen[0], color_frozen[1], color_frozen[2], 0.20)
        
        bgl.glDepthRange(0.0, 0.999)
        bgl.glEnable(bgl.GL_DEPTH_TEST)
        
        def draw3d_polyline(context, points, color, thickness, LINE_TYPE):
            if LINE_TYPE == "GL_LINE_STIPPLE":
                bgl.glLineStipple(4, 0x5555)  #play with this later
                bgl.glEnable(bgl.GL_LINE_STIPPLE)  
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glColor4f(*color)
            bgl.glLineWidth(thickness)
            bgl.glDepthRange(0.0, 0.997)
            bgl.glBegin(bgl.GL_LINE_STRIP)
            for coord in points: bgl.glVertex3f(*coord)
            bgl.glEnd()
            bgl.glLineWidth(1)
            if LINE_TYPE == "GL_LINE_STIPPLE":
                bgl.glDisable(bgl.GL_LINE_STIPPLE)
                bgl.glEnable(bgl.GL_BLEND)  # back to uninterrupted lines  
        def draw3d_closed_polylines(context, lpoints, color, thickness, LINE_TYPE):
            lpoints = list(lpoints)
            if LINE_TYPE == "GL_LINE_STIPPLE":
                bgl.glLineStipple(4, 0x5555)  #play with this later
                bgl.glEnable(bgl.GL_LINE_STIPPLE)  
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glLineWidth(thickness)
            bgl.glDepthRange(0.0, 0.997)
            bgl.glColor4f(*color)
            for points in lpoints:
                bgl.glBegin(bgl.GL_LINE_STRIP)
                for coord in points:
                    bgl.glVertex3f(*coord)
                bgl.glVertex3f(*points[0])
                bgl.glEnd()
            if settings.symmetry_plane == 'x':
                bgl.glColor4f(*color_mirror)
                for points in lpoints:
                    bgl.glBegin(bgl.GL_LINE_STRIP)
                    for coord in points:
                        bgl.glVertex3f(-coord.x, coord.y, coord.z)
                    bgl.glVertex3f(-points[0].x, points[0].y, points[0].z)
                    bgl.glEnd()
                
            bgl.glLineWidth(1)
            if LINE_TYPE == "GL_LINE_STIPPLE":
                bgl.glDisable(bgl.GL_LINE_STIPPLE)
                bgl.glEnable(bgl.GL_BLEND)  # back to uninterrupted lines  
        def draw3d_quad(context, points, color):
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glDepthRange(0.0, 0.999)
            bgl.glBegin(bgl.GL_QUADS)
            bgl.glColor4f(*color)
            for coord in points:
                bgl.glVertex3f(*coord)
            if settings.symmetry_plane == 'x':
                bgl.glColor4f(*color_mirror)
                for coord in points:
                    bgl.glVertex3f(-coord.x,coord.y,coord.z)
            bgl.glEnd()
        def draw3d_quads(context, lpoints, color, color_mirror):
            lpoints = list(lpoints)
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glDepthRange(0.0, 0.999)
            bgl.glBegin(bgl.GL_QUADS)
            bgl.glColor4f(*color)
            for points in lpoints:
                for coord in points:
                    bgl.glVertex3f(*coord)
            if settings.symmetry_plane == 'x':
                bgl.glColor4f(*color_mirror)
                for points in lpoints:
                    for coord in points:
                        bgl.glVertex3f(-coord.x,coord.y,coord.z)
            bgl.glEnd()
        def draw3d_points(context, points, color, size):
            bgl.glColor4f(*color)
            bgl.glPointSize(size)
            bgl.glDepthRange(0.0, 0.997)
            bgl.glBegin(bgl.GL_POINTS)
            for coord in points: bgl.glVertex3f(*coord)
            bgl.glEnd()
            bgl.glPointSize(1.0)
        
        def freeze_color(c):
            return (
                c[0] * 0.5 + color_frozen[0] * 0.5,
                c[1] * 0.5 + color_frozen[1] * 0.5,
                c[2] * 0.5 + color_frozen[2] * 0.5,
                c[3])


        ### Existing Geometry ###
        opts = {
            'poly color': (color_frozen[0], color_frozen[1], color_frozen[2], 0.20),
            'poly depth': (0, 0.999),
            'poly mirror color': (color_mirror[0], color_mirror[1], color_mirror[2], color_mirror[3]),
            'poly mirror depth': (0, 0.999),
            
            'line color': (color_frozen[0], color_frozen[1], color_frozen[2], 1.00),
            'line depth': (0, 0.997),
            'line mirror color': (color_mirror[0], color_mirror[1], color_mirror[2], color_mirror[3]),
            'line mirror depth': (0, 0.997),
            'line mirror stipple': True,
            
            'mirror x': self.settings.symmetry_plane == 'x',
        }
        self.tar_bmeshrender.draw(opts=opts)

        ### Patches ###
        for gpatch in self.polystrips.gpatches:
            if gpatch == self.act_gpatch:
                color_border = (color_active[0], color_active[1], color_active[2], 0.50)
                color_fill = (color_active[0], color_active[1], color_active[2], 0.20)
            else:
                color_border = (color_inactive[0], color_inactive[1], color_inactive[2], 0.50)
                color_fill = (color_inactive[0], color_inactive[1], color_inactive[2], 0.10)
            if gpatch.is_frozen() and gpatch == self.act_gpatch:
                color_border = (color_frozen[0], color_frozen[1], color_frozen[2], 1.00)
                color_fill   = (color_active[0], color_active[1], color_active[2], 0.20)
            elif gpatch.is_frozen():
                color_border = (color_frozen[0], color_frozen[1], color_frozen[2], 1.00)
                color_fill   = (color_frozen[0], color_frozen[1], color_frozen[2], 0.20)
            if gpatch.count_error and gpatch == self.act_gpatch:
                color_border = (color_warning[0], color_warning[1], color_warning[2], 0.50)
                color_fill   = (color_active[0], color_active[1], color_active[2], 0.20)
            elif gpatch.count_error:
                color_border = (color_warning[0], color_warning[1], color_warning[2], 0.50)
                color_fill   = (color_warning[0], color_warning[1], color_warning[2], 0.10)
            
            draw3d_quads(context, gpatch.iter_segments(), color_fill, color_mirror)
            draw3d_closed_polylines(context, gpatch.iter_segments(), color_border, 1, "GL_LINE_STIPPLE")
            draw3d_points(context, [p for p,v,k in gpatch.pts if v], color_border, 3)
            

        ### Edges ###
        for gedge in self.polystrips.gedges:
            # Color active strip
            if gedge == self.act_gedge:
                color_border = (color_active[0], color_active[1], color_active[2], 1.00)
                color_fill   = (color_active[0], color_active[1], color_active[2], 0.20)
            # Color selected strips
            elif gedge in self.sel_gedges:
                color_border = (color_selection[0], color_selection[1], color_selection[2], 0.75)
                color_fill   = (color_selection[0], color_selection[1], color_selection[2], 0.20)
            # Color unselected strips
            else:
                color_border = (color_inactive[0], color_inactive[1], color_inactive[2], 1.00)
                color_fill   = (color_inactive[0], color_inactive[1], color_inactive[2], 0.20)
            
            if gedge.is_frozen() and gedge in self.sel_gedges:
                color_border = (color_frozen[0], color_frozen[1], color_frozen[2], 1.00)
                color_fill   = (color_active[0], color_active[1], color_active[2], 0.20)
            elif gedge.is_frozen():
                color_border = (color_frozen[0], color_frozen[1], color_frozen[2], 1.00)
                color_fill   = (color_frozen[0], color_frozen[1], color_frozen[2], 0.20)
            
            draw3d_quads(context, gedge.iter_segments(), color_fill, color_mirror)
            draw3d_closed_polylines(context, gedge.iter_segments(), color_border, 1, "GL_LINE_STIPPLE")

            if settings.debug >= 2:
                # draw bezier
                p0,p1,p2,p3 = gedge.gvert0.snap_pos, gedge.gvert1.snap_pos, gedge.gvert2.snap_pos, gedge.gvert3.snap_pos
                p3d = [cubic_bezier_blend_t(p0,p1,p2,p3,t/16.0) for t in range(17)]
                draw3d_polyline(context, p3d, (1,1,1,0.5),1, "GL_LINE_STIPPLE")
        
        if settings.debug >= 2:
            for gp in self.polystrips.gpatches:
                for rev,gedgeseries in zip(gp.rev, gp.gedgeseries):
                    for revge,ge in zip(gedgeseries.rev, gedgeseries.gedges):
                        color = (0.25,0.5,0.25,0.9) if not revge else (0.5,0.25,0.25,0.9)
                        draw3d_arrow(context, ge.gvert0.snap_pos, ge.gvert3.snap_pos, ge.gvert0.snap_norm, color, 2, '')
                    color = (0.5,1.0,0.5,0.5) if not rev else (1,0.5,0.5,0.5)
                    draw3d_arrow(context, gedgeseries.gvert0.snap_pos, gedgeseries.gvert3.snap_pos, gedgeseries.gvert0.snap_norm, color, 2, '')

        ### Verts ###
        for gv in self.polystrips.gverts:
            p0,p1,p2,p3 = gv.get_corners()

            if gv.is_unconnected() and not gv.from_mesh: continue

            is_active = False
            is_active |= gv == self.act_gvert
            is_active |= self.act_gedge!=None and (self.act_gedge.gvert0 == gv or self.act_gedge.gvert1 == gv)
            is_active |= self.act_gedge!=None and (self.act_gedge.gvert2 == gv or self.act_gedge.gvert3 == gv)

            # Theme colors for selected and unselected gverts
            if is_active:
                color_border = (color_active[0], color_active[1], color_active[2], 0.75)
                color_fill   = (color_active[0], color_active[1], color_active[2], 0.20)
            else:
                color_border = (color_inactive[0], color_inactive[1], color_inactive[2], 1.00)
                color_fill   = (color_inactive[0], color_inactive[1], color_inactive[2], 0.20)
            # # Take care of gverts in selected edges
            if gv in self.sel_gverts:
                color_border = (color_selection[0], color_selection[1], color_selection[2], 0.75)
                color_fill   = (color_selection[0], color_selection[1], color_selection[2], 0.20)
            if gv.is_frozen() and is_active :
                color_border = (color_frozen[0], color_frozen[1], color_frozen[2], 1.00)
                color_fill   = (color_active[0], color_active[1], color_active[2], 0.20)
            elif gv.is_frozen():
                color_border = (color_frozen[0], color_frozen[1], color_frozen[2], 1.00)
                color_fill   = (color_frozen[0], color_frozen[1], color_frozen[2], 0.20)

            p3d = [p0,p1,p2,p3,p0]
            draw3d_quads(context, [[p0,p1,p2,p3]], color_fill, color_mirror)
            draw3d_polyline(context, p3d, color_border, 1, "GL_LINE_STIPPLE")

        # Draw inner gvert handles (dots) on each gedge
        p3d = [gvert.position for gvert in self.polystrips.gverts if not gvert.is_unconnected()]
        # color_handle = (color_active[0], color_active[1], color_active[2], 1.00)
        draw3d_points(context, p3d, color_handle, 4)

        ### Vert Handles ###
        if self.act_gvert:
            color_handle = (color_active[0], color_active[1], color_active[2], 1.00)
            gv = self.act_gvert
            p0 = gv.position
            draw3d_points(context, [p0], color_handle, 8)
            
            if gv.is_inner():
                # Draw inner handle when selected
                p1 = gv.gedge_inner.get_outer_gvert_at(gv).position
                draw3d_polyline(context, [p0,p1], color_handle, 2, "GL_LINE_SMOOTH")
            else:
                # Draw both handles when gvert is selected
                p3d = [ge.get_inner_gvert_at(gv).position for ge in gv.get_gedges_notnone() if not ge.is_zippered() and not ge.is_frozen()]
                draw3d_points(context, p3d, color_handle, 8)
                # Draw connecting line between handles
                for p1 in p3d:
                    draw3d_polyline(context, [p0,p1], color_handle, 2, "GL_LINE_SMOOTH")

        # Draw gvert handles on active gedge
        if self.act_gedge and not self.act_gedge.is_frozen():
            color_handle = (color_active[0], color_active[1], color_active[2], 1.00)
            ge = self.act_gedge
            if self.act_gedge.is_zippered():
                p3d = [ge.gvert0.position, ge.gvert3.position]
                draw3d_points(context, p3d, color_handle, 8)
            else:
                p3d = [gv.position for gv in ge.gverts()]
                draw3d_points(context, p3d, color_handle, 8)
                draw3d_polyline(context, [p3d[0], p3d[1]], color_handle, 2, "GL_LINE_SMOOTH")
                draw3d_polyline(context, [p3d[2], p3d[3]], color_handle, 2, "GL_LINE_SMOOTH")
                if False:
                    # draw each normal of each gvert
                    for p,n in zip(p3d,[gv.snap_norm for gv in ge.gverts()]):
                        draw3d_polyline(context, [p,p+n*0.1], color_handle, 1, "GL_LINE_SMOOTH")
        
        if self.hov_gvert:  #TODO, hover color
            color_border = (color_selection[0], color_selection[1], color_selection[2], 1.00)
            color_fill   = (color_selection[0], color_selection[1], color_selection[2], 0.20)
            
            gv = self.hov_gvert
            p0,p1,p2,p3 = gv.get_corners()
            p3d = [p0,p1,p2,p3,p0]
            draw3d_quad(context, [p0,p1,p2,p3], color_fill)
            draw3d_polyline(context, p3d, color_border, 1, "GL_LINE_STIPPLE")
            

        bgl.glLineWidth(1)
        bgl.glDepthRange(0.0, 1.0)
    def draw_3d(self, context):
        settings = common_utilities.get_settings()
        region,r3d = context.region,context.space_data.region_3d
        view_dir = r3d.view_rotation * Vector((0,0,-1))
        view_loc = r3d.view_location - view_dir * r3d.view_distance
        if r3d.view_perspective == 'ORTHO': view_loc -= view_dir * 1000.0
        view_loc_x = vector_mirror_x(view_loc)
        
        color_inactive = settings.theme_colors_mesh[settings.theme]
        color_selection = settings.theme_colors_selection[settings.theme]
        color_active = settings.theme_colors_active[settings.theme]

        color_frozen = settings.theme_colors_frozen[settings.theme]
        color_warning = settings.theme_colors_warning[settings.theme]

        bgl.glEnable(bgl.GL_POINT_SMOOTH)

        color_handle = (color_inactive[0], color_inactive[1], color_inactive[2], 1.00)
        color_border = (color_inactive[0], color_inactive[1], color_inactive[2], 1.00)
        color_fill   = (color_inactive[0], color_inactive[1], color_inactive[2], 0.20)
        color_mirror = (color_frozen[0], color_frozen[1], color_frozen[2], 0.20)
        
        #bgl.glDepthRange(0.0, 0.999)
        bgl.glDepthRange(0.0, 1.0)
        bgl.glEnable(bgl.GL_DEPTH_TEST)
        
        def set_depthrange(near=0.0, far=1.0, points=None):
            if points and len(points) and view_loc:
                d2 = min((view_loc-p).length_squared for p in points)
                d = math.sqrt(d2)
                d2 /= 10.0
                near = near / d2
                far = 1.0 - ((1.0 - far) / d2)
            if r3d.view_perspective == 'ORTHO':
                far *= 0.9999
            near = max(0.0, min(1.0, near))
            far = max(near, min(1.0, far))
            bgl.glDepthRange(near, far)
            #bgl.glDepthRange(0.0, 0.5)
        
        def draw3d_polyline(context, points, color, thickness, LINE_TYPE, mirror, zfar=0.997):
            points = [mirror(pt) for pt in points]
            if len(points) == 0: return
            # if type(points) is types.GeneratorType:
            #     points = list(points)
            if LINE_TYPE == "GL_LINE_STIPPLE":
                bgl.glLineStipple(4, 0x5555)  #play with this later
                bgl.glEnable(bgl.GL_LINE_STIPPLE)  
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glColor4f(*color)
            bgl.glLineWidth(thickness)
            set_depthrange(0.0, zfar, points)
            bgl.glBegin(bgl.GL_LINE_STRIP)
            for coord in points: bgl.glVertex3f(*coord)
            bgl.glEnd()
            bgl.glLineWidth(1)
            if LINE_TYPE == "GL_LINE_STIPPLE":
                bgl.glDisable(bgl.GL_LINE_STIPPLE)
                bgl.glEnable(bgl.GL_BLEND)  # back to uninterrupted lines
        
        def draw3d_closed_polylines(context, lpoints, color, thickness, LINE_TYPE, mirror):
            #if type(lpoints) is types.GeneratorType:
            #    lpoints = list(lpoints)
            lpoints = [[mirror(pt) for pt in points] for points in lpoints]
            if len(lpoints) == 0: return
            if LINE_TYPE == "GL_LINE_STIPPLE":
                bgl.glLineStipple(4, 0x5555)  #play with this later
                bgl.glEnable(bgl.GL_LINE_STIPPLE)  
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glLineWidth(thickness)
            bgl.glColor4f(*color)
            for points in lpoints:
                set_depthrange(0.0, 0.997, points)
                bgl.glBegin(bgl.GL_LINE_STRIP)
                for coord in chain(points,points[:1]):
                    bgl.glVertex3f(*coord)
                bgl.glEnd()
            # if settings.symmetry_plane == 'x':
            #     bgl.glColor4f(*color_mirror)
            #     for points in lpoints:
            #         bgl.glBegin(bgl.GL_LINE_STRIP)
            #         for coord in points:
            #             bgl.glVertex3f(-coord.x, coord.y, coord.z)
            #         bgl.glVertex3f(-points[0].x, points[0].y, points[0].z)
            #         bgl.glEnd()
                
            bgl.glLineWidth(1)
            if LINE_TYPE == "GL_LINE_STIPPLE":
                bgl.glDisable(bgl.GL_LINE_STIPPLE)
                bgl.glEnable(bgl.GL_BLEND)  # back to uninterrupted lines  
        
        def draw3d_quad(context, points, color, mirror):
            #if type(points) is types.GeneratorType:
            #    points = list(points)
            points = [mirror(pt) for pt in points]
            if len(points) == 0: return
            bgl.glEnable(bgl.GL_BLEND)
            set_depthrange(0.0, 0.998, points)
            bgl.glBegin(bgl.GL_QUADS)
            bgl.glColor4f(*color)
            for coord in points: bgl.glVertex3f(*coord)
            # if settings.symmetry_plane == 'x':
            #     bgl.glColor4f(*color_mirror)
            #     for coord in points:
            #         bgl.glVertex3f(-coord.x,coord.y,coord.z)
            bgl.glEnd()
        
        def draw3d_quads(context, lpoints, color, mirror):
            #if type(lpoints) is types.GeneratorType:
            #    lpoints = list(lpoints)
            lpoints = [[mirror(pt) for pt in points] for points in lpoints]
            if len(lpoints) == 0: return
            bgl.glEnable(bgl.GL_BLEND)
            set_depthrange(0.0, 0.998, [p for pts in lpoints for p in pts])
            bgl.glBegin(bgl.GL_QUADS)
            bgl.glColor4f(*color)
            for points in lpoints:
                for coord in points:
                    bgl.glVertex3f(*coord)
            # if settings.symmetry_plane == 'x':
            #     bgl.glColor4f(*color_mirror)
            #     for points in lpoints:
            #         for coord in points:
            #             bgl.glVertex3f(-coord.x,coord.y,coord.z)
            bgl.glEnd()
        
        def draw3d_points(context, points, color, size, mirror):
            #if type(points) is types.GeneratorType:
            #    points = list(points)
            points = [mirror(pt) for pt in points]
            if len(points) == 0: return
            bgl.glColor4f(*color)
            bgl.glPointSize(size)
            set_depthrange(0.0, 0.997, points)
            bgl.glBegin(bgl.GL_POINTS)
            for coord in points: bgl.glVertex3f(*coord)
            bgl.glEnd()
            bgl.glPointSize(1.0)
        
        def freeze_color(c):
            return (
                c[0] * 0.5 + color_frozen[0] * 0.5,
                c[1] * 0.5 + color_frozen[1] * 0.5,
                c[2] * 0.5 + color_frozen[2] * 0.5,
                c[3])


        ### Existing Geometry ###
        opts = {
            'poly color': (color_frozen[0], color_frozen[1], color_frozen[2], 0.20),
            'poly depth': (0, 0.999),
            'poly mirror color': (color_mirror[0], color_mirror[1], color_mirror[2], color_mirror[3]),
            'poly mirror depth': (0, 0.999),
            
            'line color': (color_frozen[0], color_frozen[1], color_frozen[2], 1.00),
            'line depth': (0, 0.997),
            'line mirror color': (color_mirror[0], color_mirror[1], color_mirror[2], color_mirror[3]),
            'line mirror depth': (0, 0.997),
            'line mirror stipple': True,
            
            'mirror x': self.settings.symmetry_plane == 'x',
        }
        self.tar_bmeshrender.draw(opts=opts)

        ### Patches ###
        for gpatch in self.polystrips.gpatches:
            if gpatch == self.act_gpatch:
                color_border = (color_active[0], color_active[1], color_active[2], 0.50)
                color_fill = (color_active[0], color_active[1], color_active[2], 0.20)
            else:
                color_border = (color_inactive[0], color_inactive[1], color_inactive[2], 0.50)
                color_fill = (color_inactive[0], color_inactive[1], color_inactive[2], 0.10)
            if gpatch.is_frozen() and gpatch == self.act_gpatch:
                color_border = (color_frozen[0], color_frozen[1], color_frozen[2], 1.00)
                color_fill   = (color_active[0], color_active[1], color_active[2], 0.20)
            elif gpatch.is_frozen():
                color_border = (color_frozen[0], color_frozen[1], color_frozen[2], 1.00)
                color_fill   = (color_frozen[0], color_frozen[1], color_frozen[2], 0.20)
            if gpatch.count_error and gpatch == self.act_gpatch:
                color_border = (color_warning[0], color_warning[1], color_warning[2], 0.50)
                color_fill   = (color_active[0], color_active[1], color_active[2], 0.20)
            elif gpatch.count_error:
                color_border = (color_warning[0], color_warning[1], color_warning[2], 0.50)
                color_fill   = (color_warning[0], color_warning[1], color_warning[2], 0.10)
            
            draw3d_quads(context, gpatch.iter_segments(view_loc), color_fill, vector_mirror_0)
            draw3d_closed_polylines(context, gpatch.iter_segments(view_loc), color_border, 1, "GL_LINE_STIPPLE", vector_mirror_0)
            draw3d_points(context, gpatch.iter_pts(view_loc), color_border, 3, vector_mirror_0)
            if settings.symmetry_plane == 'x':
                draw3d_quads(context, gpatch.iter_segments(view_loc_x), color_mirror, vector_mirror_x)
                draw3d_closed_polylines(context, gpatch.iter_segments(view_loc_x), color_mirror, 1, "GL_LINE_STIPPLE", vector_mirror_x)
                #draw3d_points(context, gpatch.iter_pts(view_loc_x), color_border, 3, vector_mirror_x)
            

        ### Edges ###
        for gedge in self.polystrips.gedges:
            # Color active strip
            if gedge == self.act_gedge:
                color_border = (color_active[0], color_active[1], color_active[2], 1.00)
                color_fill   = (color_active[0], color_active[1], color_active[2], 0.20)
            # Color selected strips
            elif gedge in self.sel_gedges:
                color_border = (color_selection[0], color_selection[1], color_selection[2], 0.75)
                color_fill   = (color_selection[0], color_selection[1], color_selection[2], 0.20)
            # Color unselected strips
            else:
                color_border = (color_inactive[0], color_inactive[1], color_inactive[2], 1.00)
                color_fill   = (color_inactive[0], color_inactive[1], color_inactive[2], 0.20)
            
            if gedge.is_frozen() and gedge in self.sel_gedges:
                color_border = (color_frozen[0], color_frozen[1], color_frozen[2], 1.00)
                color_fill   = (color_active[0], color_active[1], color_active[2], 0.20)
            elif gedge.is_frozen():
                color_border = (color_frozen[0], color_frozen[1], color_frozen[2], 1.00)
                color_fill   = (color_frozen[0], color_frozen[1], color_frozen[2], 0.20)
            
            draw3d_quads(context, gedge.iter_segments(view_loc), color_fill, vector_mirror_0)
            draw3d_closed_polylines(context, gedge.iter_segments(view_loc), color_border, 1, "GL_LINE_STIPPLE", vector_mirror_0)
            if settings.symmetry_plane == 'x':
                draw3d_quads(context, gedge.iter_segments(view_loc_x), color_mirror, vector_mirror_x)
                draw3d_closed_polylines(context, gedge.iter_segments(view_loc_x), color_mirror, 1, "GL_LINE_STIPPLE", vector_mirror_x)

            if settings.debug >= 2:
                # draw bezier
                p0,p1,p2,p3 = gedge.get_snappositions() #gvert0.snap_pos, gedge.gvert1.snap_pos, gedge.gvert2.snap_pos, gedge.gvert3.snap_pos
                n0,n1,n2,n3 = gedge.get_snapnormals()
                r0,r1,r2,r3 = gedge.get_radii()
                p1 = p1 + (n1 * (r0 * max(0.0, (1.0 - n0.dot(n3)) + (1.0 - n0.dot(n1))) ))
                p2 = p2 + (n2 * (r3 * max(0.0, (1.0 - n0.dot(n3)) + (1.0 - n3.dot(n2))) ))
                p3d = [cubic_bezier_blend_t(p0,p1,p2,p3,t/16.0) for t in range(17)]
                draw3d_polyline(context, p3d, (1,1,1,0.5),1, "GL_LINE_STIPPLE", vector_mirror_0)
        
        if settings.debug >= 2:
            for gp in self.polystrips.gpatches:
                for rev,gedgeseries in zip(gp.rev, gp.gedgeseries):
                    for revge,ge in zip(gedgeseries.rev, gedgeseries.gedges):
                        color = (0.25,0.5,0.25,0.9) if not revge else (0.5,0.25,0.25,0.9)
                        draw3d_arrow(context, ge.gvert0.snap_pos, ge.gvert3.snap_pos, ge.gvert0.snap_norm, color, 2, '')
                    color = (0.5,1.0,0.5,0.5) if not rev else (1,0.5,0.5,0.5)
                    draw3d_arrow(context, gedgeseries.gvert0.snap_pos, gedgeseries.gvert3.snap_pos, gedgeseries.gvert0.snap_norm, color, 2, '')

        ### Verts ###
        for gv in self.polystrips.gverts:
            p0,p1,p2,p3 = gv.get_corners()

            if gv.is_unconnected() and not gv.from_mesh: continue

            is_active = False
            is_active |= gv == self.act_gvert
            is_active |= self.act_gedge!=None and (self.act_gedge.gvert0 == gv or self.act_gedge.gvert1 == gv)
            is_active |= self.act_gedge!=None and (self.act_gedge.gvert2 == gv or self.act_gedge.gvert3 == gv)

            # Theme colors for selected and unselected gverts
            if is_active:
                color_border = (color_active[0], color_active[1], color_active[2], 0.75)
                color_fill   = (color_active[0], color_active[1], color_active[2], 0.20)
            else:
                color_border = (color_inactive[0], color_inactive[1], color_inactive[2], 1.00)
                color_fill   = (color_inactive[0], color_inactive[1], color_inactive[2], 0.20)
            # # Take care of gverts in selected edges
            if gv in self.sel_gverts:
                color_border = (color_selection[0], color_selection[1], color_selection[2], 0.75)
                color_fill   = (color_selection[0], color_selection[1], color_selection[2], 0.20)
            if gv.is_frozen() and is_active :
                color_border = (color_frozen[0], color_frozen[1], color_frozen[2], 1.00)
                color_fill   = (color_active[0], color_active[1], color_active[2], 0.20)
            elif gv.is_frozen():
                color_border = (color_frozen[0], color_frozen[1], color_frozen[2], 1.00)
                color_fill   = (color_frozen[0], color_frozen[1], color_frozen[2], 0.20)

            p3d = [p0,p1,p2,p3,p0]
            if gv.is_visible(r3d):
                draw3d_quads(context, [[p0,p1,p2,p3]], color_fill, vector_mirror_0)
                draw3d_polyline(context, p3d, color_border, 1, "GL_LINE_STIPPLE", vector_mirror_0)
            if settings.symmetry_plane == 'x' and gv.is_visible(r3d, mirror_x=True):
                draw3d_quads(context, [[p0,p1,p2,p3]], color_mirror, vector_mirror_x)
                draw3d_polyline(context, p3d, color_mirror, 1, "GL_LINE_STIPPLE", vector_mirror_x)
            
            if settings.debug >= 2:
                l = 0.1
                sp,sn,sx,sy = gv.snap_pos,gv.snap_norm,gv.snap_tanx,gv.snap_tany
                draw3d_polyline(context, [sp,sp+sn*l], (0,0,1,0.5), 1, "", vector_mirror_0)
                draw3d_polyline(context, [sp,sp+sx*l], (1,0,0,0.5), 1, "", vector_mirror_0)
                draw3d_polyline(context, [sp,sp+sy*l], (0,1,0,0.5), 1, "", vector_mirror_0)

        # Draw inner gvert handles (dots) on each gedge
        p3d = [gvert.position for gvert in self.polystrips.gverts if not gvert.is_unconnected() and gvert.is_visible(r3d)]
        # color_handle = (color_active[0], color_active[1], color_active[2], 1.00)
        draw3d_points(context, p3d, color_handle, 4, vector_mirror_0)

        ### Vert Handles ###
        if self.act_gvert:
            color_handle = (color_active[0], color_active[1], color_active[2], 1.00)
            gv = self.act_gvert
            p0 = gv.position
            draw3d_points(context, [p0], color_handle, 8, vector_mirror_0)
            
            if gv.is_inner():
                # Draw inner handle when selected
                innergv = gv.gedge_inner.get_outer_gvert_at(gv)
                if innergv.is_visible(r3d):
                    bgl.glDisable(bgl.GL_DEPTH_TEST)
                p1 = innergv.position
                draw3d_polyline(context, [p0,p1], color_handle, 2, "GL_LINE_SMOOTH", vector_mirror_0)
            else:
                # Draw both handles when gvert is selected
                innergvs = [ge.get_inner_gvert_at(gv) for ge in gv.get_gedges_notnone() if not ge.is_zippered() and not ge.is_frozen()]
                draw3d_points(context, [innergv.position for innergv in innergvs], color_handle, 8, vector_mirror_0)
                # Draw connecting line between handles
                p0vis = gv.is_visible(r3d)
                for innergv in innergvs:
                    p1 = innergv.position
                    p1vis = innergv.is_visible(r3d)
                    if p0vis and p1vis:
                        bgl.glDisable(bgl.GL_DEPTH_TEST)
                    else:
                        bgl.glEnable(bgl.GL_DEPTH_TEST)
                    draw3d_polyline(context, [p0,p1], color_handle, 2, "GL_LINE_SMOOTH", vector_mirror_0)
            
            bgl.glEnable(bgl.GL_DEPTH_TEST)

        # Draw gvert handles on active gedge
        if self.act_gedge and not self.act_gedge.is_frozen():
            color_handle = (color_active[0], color_active[1], color_active[2], 1.00)
            ge = self.act_gedge
            if self.act_gedge.is_zippered():
                p3d = [ge.gvert0.position, ge.gvert3.position]
                draw3d_points(context, p3d, color_handle, 8, vector_mirror_0)
            else:
                vis = [gv.is_visible(r3d) for gv in ge.gverts()]
                p3d = [gv.position for gv in ge.gverts()]
                draw3d_points(context, p3d, color_handle, 8, vector_mirror_0)
                if vis[0] and vis[1]:
                    bgl.glDisable(bgl.GL_DEPTH_TEST)
                draw3d_polyline(context, [p3d[0], p3d[1]], color_handle, 2, "GL_LINE_SMOOTH", vector_mirror_0)
                if vis[2] and vis[3]:
                    bgl.glDisable(bgl.GL_DEPTH_TEST)
                else:
                    bgl.glEnable(bgl.GL_DEPTH_TEST)
                draw3d_polyline(context, [p3d[2], p3d[3]], color_handle, 2, "GL_LINE_SMOOTH", vector_mirror_0)
                bgl.glEnable(bgl.GL_DEPTH_TEST)
                if False:
                    # draw each normal of each gvert
                    for p,n in zip(p3d,[gv.snap_norm for gv in ge.gverts()]):
                        draw3d_polyline(context, [p,p+n*0.1], color_handle, 1, "GL_LINE_SMOOTH", vector_mirror_0)
        
        if self.hov_gvert:  #TODO, hover color
            color_border = (color_selection[0], color_selection[1], color_selection[2], 1.00)
            color_fill   = (color_selection[0], color_selection[1], color_selection[2], 0.20)
            
            gv = self.hov_gvert
            p0,p1,p2,p3 = gv.get_corners()
            p3d = [p0,p1,p2,p3,p0]
            draw3d_quad(context, [p0,p1,p2,p3], color_fill, vector_mirror_0)
            draw3d_polyline(context, p3d, color_border, 1, "GL_LINE_STIPPLE", vector_mirror_0)
            

        bgl.glLineWidth(1)
        bgl.glDepthRange(0.0, 1.0)
    def draw_callback_px(self, context):
        # draw 3d point OpenGL in the 3D View
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glDisable(bgl.GL_DEPTH_TEST)
        # bgl.glPushMatrix()
        # bgl.glMultMatrixf(self.obj_glmatrix)

##        if DEBUG:
##            mesh_drawing._store_current_shader_state(mesh_drawing.PreviousGLState)
##            self.screen.Draw(self.sctx._texture)
##            mesh_drawing._restore_shader_state(mesh_drawing.PreviousGLState)

        if self.vector_constrain:
            vc = self.vector_constrain
            if hasattr(self, 'preloc') and self.type in {'VERT', 'FACE'}:
                bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
                bgl.glPointSize(5)
                bgl.glBegin(bgl.GL_POINTS)
                bgl.glVertex3f(*self.preloc)
                bgl.glEnd()
            if vc[2] == 'X':
                Color4f = (self.axis_x_color + (1.0,))
            elif vc[2] == 'Y':
                Color4f = (self.axis_y_color + (1.0,))
            elif vc[2] == 'Z':
                Color4f = (self.axis_z_color + (1.0,))
            else:
                Color4f = self.constrain_shift_color
        else:
            if self.type == 'OUT':
                Color4f = self.out_color
            elif self.type == 'FACE':
                Color4f = self.face_color
            elif self.type == 'EDGE':
                Color4f = self.edge_color
            elif self.type == 'VERT':
                Color4f = self.vert_color
            elif self.type == 'CENTER':
                Color4f = self.center_color
            elif self.type == 'PERPENDICULAR':
                Color4f = self.perpendicular_color
            else: # self.type == None
                Color4f = self.out_color

        bgl.glColor4f(*Color4f)
        bgl.glPointSize(10)
        bgl.glBegin(bgl.GL_POINTS)
        bgl.glVertex3f(*self.location)
        bgl.glEnd()

        # draw 3d line OpenGL in the 3D View
        bgl.glEnable(bgl.GL_DEPTH_TEST)
        bgl.glDepthRange(0, 0.9999)
        bgl.glColor4f(1.0, 0.8, 0.0, 1.0)
        bgl.glLineWidth(2)
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for vert_co in self.list_verts_co:
            bgl.glVertex3f(*vert_co)
        bgl.glVertex3f(*self.location)
        bgl.glEnd()

        # restore opengl defaults
        # bgl.glPopMatrix()
        bgl.glDepthRange(0, 1)
        bgl.glPointSize(1)
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glDisable(bgl.GL_LINE_STIPPLE)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
 def _set(self, instance, value):
     glDepthRange(value[0], value[1])
    def brushstroke_postview(self):
        if self.mode not in {'main','brushstroke'}: return
        if not self.hit: return
        cx,cy,cp = self.hit_x,self.hit_y,self.hit_p
        cs_outer = self.scale * self.size
        cs_inner = self.scale * self.size * 0.5
        cr,cg,cb = self.color

        bgl.glDepthRange(0, 0.999)      # squeeze depth just a bit
        bgl.glEnable(bgl.GL_BLEND)
        self.drawing.line_width(2.0)
        self.drawing.point_size(3.0)

        ######################################
        # draw in front of geometry

        bgl.glDepthFunc(bgl.GL_LEQUAL)
        bgl.glDepthMask(bgl.GL_FALSE)   # do not overwrite depth

        bgl.glColor4f(cr, cg, cb, 1.0)       # outer ring
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x,y in self.points:
            p = (cs_outer * ((cx * x) + (cy * y))) + cp
            bgl.glVertex3f(*p)
        bgl.glEnd()

        bgl.glColor4f(cr, cg, cb, 0.1)     # inner ring
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x,y in self.points:
            p = (cs_inner * ((cx * x) + (cy * y))) + cp
            bgl.glVertex3f(*p)
        bgl.glEnd()

        bgl.glColor4f(1, 1, 1, 0.25)    # center point
        bgl.glBegin(bgl.GL_POINTS)
        bgl.glVertex3f(*cp)
        bgl.glEnd()

        ######################################
        # draw behind geometry (hidden below)

        bgl.glDepthFunc(bgl.GL_GREATER)
        bgl.glDepthMask(bgl.GL_FALSE)   # do not overwrite depth

        bgl.glColor4f(cr, cg, cb, 0.05)    # outer ring
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x,y in self.points:
            p = (cs_outer * ((cx * x) + (cy * y))) + cp
            bgl.glVertex3f(*p)
        bgl.glEnd()

        bgl.glColor4f(cr, cg, cb, 0.01)   # inner ring
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x,y in self.points:
            p = (cs_inner * ((cx * x) + (cy * y))) + cp
            bgl.glVertex3f(*p)
        bgl.glEnd()

        ######################################
        # reset to defaults

        bgl.glDepthFunc(bgl.GL_LEQUAL)
        bgl.glDepthMask(bgl.GL_TRUE)

        bgl.glDepthRange(0, 1)
Beispiel #34
0
    def stroke_postview(self):
        if self.mode not in {'main','stroke'}: return
        if not self.hit: return
        cx,cy,cp = self.hit_x,self.hit_y,self.hit_p
        cs_outer = self.scale * 20
        cs_inner = self.scale * 20 * 0.5
        cr,cg,cb = self.color

        bgl.glDepthRange(0, 0.999)      # squeeze depth just a bit
        bgl.glEnable(bgl.GL_BLEND)
        self.drawing.line_width(2.0)
        self.drawing.point_size(3.0)

        ######################################
        # draw in front of geometry

        bgl.glDepthFunc(bgl.GL_LEQUAL)
        bgl.glDepthMask(bgl.GL_FALSE)   # do not overwrite depth

        bgl.glColor4f(cr, cg, cb, 1.0)       # outer ring
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x,y in self.points:
            p = (cs_outer * ((cx * x) + (cy * y))) + cp
            bgl.glVertex3f(*p)
        bgl.glEnd()

        bgl.glColor4f(cr, cg, cb, 0.1)     # inner ring
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x,y in self.points:
            p = (cs_inner * ((cx * x) + (cy * y))) + cp
            bgl.glVertex3f(*p)
        bgl.glEnd()

        bgl.glColor4f(1, 1, 1, 0.25)    # center point
        bgl.glBegin(bgl.GL_POINTS)
        bgl.glVertex3f(*cp)
        bgl.glEnd()

        ######################################
        # draw behind geometry (hidden below)

        bgl.glDepthFunc(bgl.GL_GREATER)
        bgl.glDepthMask(bgl.GL_FALSE)   # do not overwrite depth

        bgl.glColor4f(cr, cg, cb, 0.05)    # outer ring
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x,y in self.points:
            p = (cs_outer * ((cx * x) + (cy * y))) + cp
            bgl.glVertex3f(*p)
        bgl.glEnd()

        bgl.glColor4f(cr, cg, cb, 0.01)   # inner ring
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x,y in self.points:
            p = (cs_inner * ((cx * x) + (cy * y))) + cp
            bgl.glVertex3f(*p)
        bgl.glEnd()

        ######################################
        # reset to defaults

        bgl.glDepthFunc(bgl.GL_LEQUAL)
        bgl.glDepthMask(bgl.GL_TRUE)

        bgl.glDepthRange(0, 1)
    def draw_postview(self, context, mesh, isBaseMesh):
        #mesh = self.mesh #temporary in case we decide it should be named differently
        a1 = 1.0
        a2 = 1.0
        if isBaseMesh and self.sublvl > 0:
            a1 = 0.5
            a2 = .75

        bgl.glEnable(bgl.GL_POINT_SMOOTH)
        bgl.glEnable(bgl.GL_BLEND)

        #draw the vertices
        for v in mesh.vertices:
            if v in self.selected:
                bgl.glColor4d(0.9,0.5,0, a2)
                bgl.glPointSize(4)
            else:
                bgl.glColor4d(1, 1, 0, a1)
                bgl.glPointSize(2)

            bgl.glBegin(bgl.GL_POINTS)
            bgl.glVertex3f(*v.co.to_tuple())
            bgl.glEnd()


        bgl.glDepthRange(0.0, 0.9999)
        #draw the edges
        for e in mesh.edges:
            if e in self.selected:
                bgl.glColor4d(0.9,0.5,0, a2)
                bgl.glLineWidth(2)
            else:
                bgl.glColor4d(0.5, 0.5, 0, a1)
                bgl.glLineWidth(1)

            bgl.glBegin(bgl.GL_LINES)
            bgl.glVertex3f(*e.v0.co.to_tuple())
            bgl.glVertex3f(*e.v1.co.to_tuple())
            bgl.glEnd()
        bgl.glDepthRange(0.0, 1.0)


        #draw the faces
        bgl.glBegin(bgl.GL_TRIANGLES)

        for f in mesh.faces:
            if f in self.selected:
                bgl.glColor4d(0.6,0.2,0, a2)
            else:
                bgl.glColor4d(0.3, 0.3, 0.3, a1)
            a = 0
            b = 1
            c = 2
            for i in range(len(f.lvertices)-2):
                bgl.glVertex3f(*f.lvertices[a].co.to_tuple())
                bgl.glVertex3f(*f.lvertices[b].co.to_tuple())
                bgl.glVertex3f(*f.lvertices[c].co.to_tuple())
                b += 1
                c += 1

        bgl.glEnd()

        if False:
            bgl.glColor3f(0,1,1)
            bgl.glBegin(bgl.GL_LINES)
            for f in mesh.faces:
                p0 = Vector()
                for v in f.lvertices:
                    p0 += v.co
                p0 /= len(f.lvertices)
                p1 = p0 + f.normal * 0.2
                bgl.glVertex3f(*p0)
                bgl.glVertex3f(*p1)
            bgl.glEnd()
Beispiel #36
0
    def draw_spline(self):
        if not self.strips: return

        strips = self.strips
        hov_strips = self.hovering_strips

        def is_visible(v):
            return True
            return self.rfcontext.is_visible(v, None)

        def draw(alphamult, hov_alphamult, hover):
            nonlocal strips

            if not hover: hov_alphamult = alphamult

            size_outer = options['polystrips handle outer size']
            size_inner = options['polystrips handle inner size']
            border_outer = (size_outer - 2 *
                            options['polystrips handle border']) / size_outer
            border_inner = (size_inner - 2 *
                            options['polystrips handle border']) / size_inner

            bgl.glEnable(bgl.GL_BLEND)

            # draw outer-inner lines
            self.drawing.line_width(2.0)
            edgeShortenShader.enable()
            edgeShortenShader[
                'uMVPMatrix'] = self.drawing.get_view_matrix_buffer()
            edgeShortenShader['uScreenSize'] = self.rfcontext.actions.size
            bgl.glBegin(bgl.GL_LINES)
            for strip in strips:
                a = hov_alphamult if strip in hov_strips else alphamult
                p0, p1, p2, p3 = strip.curve.points()
                if is_visible(p0) and is_visible(p1):
                    edgeShortenShader['vColor'] = (1.00, 1.00, 1.00, 0.45 * a)
                    edgeShortenShader['vFrom'] = (p1.x, p1.y, p1.z, 1.0)
                    edgeShortenShader['vRadius'] = size_outer + 2
                    bgl.glVertex3f(*p0)
                    edgeShortenShader['vColor'] = (1.00, 1.00, 1.00, 0.45 * a)
                    edgeShortenShader['vFrom'] = (p0.x, p0.y, p0.z, 1.0)
                    edgeShortenShader['vRadius'] = size_inner + 2
                    bgl.glVertex3f(*p1)
                if is_visible(p2) and is_visible(p3):
                    edgeShortenShader['vColor'] = (1.00, 1.00, 1.00, 0.45 * a)
                    edgeShortenShader['vFrom'] = (p3.x, p3.y, p3.z, 1.0)
                    edgeShortenShader['vRadius'] = size_inner + 2
                    bgl.glVertex3f(*p2)
                    edgeShortenShader['vColor'] = (1.00, 1.00, 1.00, 0.45 * a)
                    edgeShortenShader['vFrom'] = (p2.x, p2.y, p2.z, 1.0)
                    edgeShortenShader['vRadius'] = size_outer + 2
                    bgl.glVertex3f(*p3)
            bgl.glEnd()
            edgeShortenShader.disable()

            # draw junction handles (outer control points of curve)
            faces_drawn = set(
            )  # keep track of faces, so don't draw same handles 2+ times
            circleShader.enable()
            circleShader['uMVPMatrix'] = self.drawing.get_view_matrix_buffer()
            circleShader['uInOut'] = border_outer
            self.drawing.point_size(size_outer)
            bgl.glBegin(bgl.GL_POINTS)
            for strip in strips:
                a = hov_alphamult if strip in hov_strips else alphamult
                circleShader['vOutColor'] = (0.00, 0.00, 0.00, 0.5 * a)
                circleShader['vInColor'] = (1.00, 1.00, 1.00, 1.0 * a)
                bmf0, bmf1 = strip.end_faces()
                p0, p1, p2, p3 = strip.curve.points()
                if bmf0 not in faces_drawn:
                    if is_visible(p0):
                        bgl.glVertex3f(*p0)
                    faces_drawn.add(bmf0)
                if bmf1 not in faces_drawn:
                    if is_visible(p3):
                        bgl.glVertex3f(*p3)
                    faces_drawn.add(bmf1)
            bgl.glEnd()
            circleShader.disable()

            # draw control handles (inner control points of curve)
            if options['polystrips arrows']:
                arrowShader.enable()
                arrowShader[
                    'uMVPMatrix'] = self.drawing.get_view_matrix_buffer()
                arrowShader['uInOut'] = border_inner
                self.drawing.point_size(size_inner)
                bgl.glBegin(bgl.GL_POINTS)
                for strip in strips:
                    a = hov_alphamult if strip in hov_strips else alphamult
                    p0, p1, p2, p3 = strip.curve.points()
                    arrowShader['vOutColor'] = (0.75, 0.75, 0.75, 0.4 * a)
                    arrowShader['vInColor'] = (0.25, 0.25, 0.25, 0.8 * a)
                    arrowShader['vFrom'] = (p0.x, p0.y, p0.z, 1.0)
                    bgl.glVertex3f(*p1)
                    arrowShader['vFrom'] = (p3.x, p3.y, p3.z, 1.0)
                    bgl.glVertex3f(*p2)
                bgl.glEnd()
                arrowShader.disable()
            else:
                circleShader.enable()
                circleShader[
                    'uMVPMatrix'] = self.drawing.get_view_matrix_buffer()
                circleShader['uInOut'] = border_inner
                self.drawing.point_size(size_inner)
                bgl.glBegin(bgl.GL_POINTS)
                for strip in strips:
                    a = hov_alphamult if strip in hov_strips else alphamult
                    circleShader['vOutColor'] = (0.75, 0.75, 0.75, 0.4 * a)
                    circleShader['vInColor'] = (0.25, 0.25, 0.25, 0.8 * a)
                    p0, p1, p2, p3 = strip.curve.points()
                    if is_visible(p1):
                        bgl.glVertex3f(*p1)
                    if is_visible(p2):
                        bgl.glVertex3f(*p2)
                bgl.glEnd()
                circleShader.disable()

            # draw curve
            if options['polystrips draw curve']:
                self.drawing.line_width(2.0)
                self.drawing.enable_stipple()
                bgl.glBegin(bgl.GL_LINES)
                for pts in self.strip_pts:
                    a = hov_alphamult if strip in hov_strips else alphamult
                    bgl.glColor4f(1, 1, 1, 0.5 * a)
                    for v0, v1 in zip(pts[:-1], pts[1:]):
                        bgl.glVertex3f(*v0)
                        bgl.glVertex3f(*v1)
                bgl.glEnd()
                self.drawing.disable_stipple()

        if True:
            # always draw on top!
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glDisable(bgl.GL_DEPTH_TEST)
            bgl.glDepthMask(bgl.GL_FALSE)
            draw(1.0, 1.0, False)
            bgl.glEnable(bgl.GL_DEPTH_TEST)
            bgl.glDepthMask(bgl.GL_TRUE)
        else:
            # allow handles to go under surface
            bgl.glDepthRange(0, 0.9999)  # squeeze depth just a bit
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glDepthMask(bgl.GL_FALSE)  # do not overwrite depth
            bgl.glEnable(bgl.GL_DEPTH_TEST)

            # draw in front of geometry
            bgl.glDepthFunc(bgl.GL_LEQUAL)
            draw(
                options['target alpha'],
                options['target alpha'],  # hover
                False,  #options['polystrips handle hover']
            )

            # draw behind geometry
            bgl.glDepthFunc(bgl.GL_GREATER)
            draw(
                options['target hidden alpha'],
                options['target hidden alpha'],  # hover
                False,  #options['polystrips handle hover']
            )

            bgl.glDepthFunc(bgl.GL_LEQUAL)
            bgl.glDepthRange(0.0, 1.0)
            bgl.glDepthMask(bgl.GL_TRUE)
def draw_callback_px(self, context):
    # draw 3d point OpenGL in the 3D View
    bgl.glEnable(bgl.GL_BLEND)
    if self.bool_constrain:
        if self.vector_constrain == Vector((1,0,0)):
            Color4f = (self.axis_x_color + (1.0,))
        elif self.vector_constrain == Vector((0,1,0)):
            Color4f = (self.axis_y_color + (1.0,))
        elif self.vector_constrain == Vector((0,0,1)):
            Color4f = (self.axis_z_color + (1.0,))
        else:
            Color4f = self.constrain_shift_color
    else:
        if self.type == 'OUT':
            Color4f = self.out_color 
        elif self.type == 'FACE':
            Color4f = self.face_color
        elif self.type == 'EDGE':
            Color4f = self.edge_color
        elif self.type == 'VERT':
            Color4f = self.vert_color
        elif self.type == 'CENTER':
            Color4f = self.center_color
        elif self.type == 'PERPENDICULAR':
            Color4f = self.perpendicular_color

    bgl.glColor4f(*Color4f)
    bgl.glDepthRange(0,0)    
    bgl.glPointSize(10)    
    bgl.glBegin(bgl.GL_POINTS)
    bgl.glVertex3f(*self.location)
    bgl.glEnd()
    bgl.glDisable(bgl.GL_BLEND)

    # draw 3d line OpenGL in the 3D View
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glDepthRange(0,0.9999)
    bgl.glColor4f(1.0, 0.8, 0.0, 1.0)    
    bgl.glLineWidth(2)    
    bgl.glEnable(bgl.GL_LINE_STIPPLE)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    for vert_co in self.list_vertices_co:
        bgl.glVertex3f(*vert_co)        
    bgl.glVertex3f(*self.location)        
    bgl.glEnd()

    # restore opengl defaults
    bgl.glDepthRange(0,1)
    bgl.glPointSize(1)
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glDisable(bgl.GL_LINE_STIPPLE)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)

    a = ""
    if self.list_vertices_co != [] and self.length_entered == "":
        a = 'length: '+ str(round((self.list_vertices_co[-1]-self.location).length, 3))
    elif self.list_vertices_co != [] and self.length_entered != "":
        a = 'length: '+ self.length_entered

    context.area.header_text_set("hit: %.3f %.3f %.3f %s" % (self.location[0], self.location[1], self.location[2], a))
    def draw(
        self,
        view_forward,
        unit_scaling_factor,
        buf_matrix_target,
        buf_matrix_target_inv,
        buf_matrix_view,
        buf_matrix_view_invtrans,
        buf_matrix_proj,
        alpha_above,
        alpha_below,
        cull_backfaces,
        alpha_backface,
    ):
        self.clean()
        if not self.buffered_renders:
            print("no renders")
            return

        try:
            bgl.glDepthMask(bgl.GL_FALSE)  # do not overwrite the depth buffer

            opts = dict(self.opts)

            opts['matrix model'] = self.d3_points.xform.mx_p
            opts['matrix normal'] = self.d3_points.xform.mx_n
            opts['matrix target'] = buf_matrix_target
            opts['matrix target inverse'] = buf_matrix_target_inv
            opts['matrix view'] = buf_matrix_view
            opts['matrix view normal'] = buf_matrix_view_invtrans
            opts['matrix projection'] = buf_matrix_proj
            opts['forward direction'] = view_forward
            opts['unit scaling factor'] = unit_scaling_factor

            bmegl.glSetDefaultOptions()

            opts['cull backfaces'] = cull_backfaces
            opts['alpha backface'] = alpha_backface
            opts['dpi mult'] = self.drawing.get_dpi_mult()
            mirror_axes = [
            ]  #self.spline_network.mirror_mod.xyz if self.spline_network.mirror_mod else []
            for axis in mirror_axes:
                opts['mirror %s' % axis] = True

            #pr = profiler.start('geometry above')
            if True:
                bgl.glDepthFunc(bgl.GL_LEQUAL)
                opts['point hidden'] = 1 - alpha_above
                opts['point mirror hidden'] = 1 - alpha_above
                for buffered_render in self.buffered_renders:
                    buffered_render.draw(opts, self.time)

            if not opts.get('no below', False):
                # draw geometry hidden behind
                #pr = profiler.start('geometry below')
                if True:
                    bgl.glDepthFunc(bgl.GL_GREATER)
                    opts['point hidden'] = 1 - alpha_below
                    opts['point mirror hidden'] = 1 - alpha_below
                    for buffered_render in self.buffered_renders:
                        buffered_render.draw(opts, self.time)
                #pr.done()

            bgl.glDepthFunc(bgl.GL_LEQUAL)
            bgl.glDepthMask(bgl.GL_TRUE)
            bgl.glDepthRange(0, 1)
        except:
            #print('Exception Exception')
            Debugger.print_exception()
            pass

        self.time += 1
def check_draw_bgl(self, context):
    objs = context.selected_objects
    if len(objs) > 0:
        props = context.preferences.addons[__package__].preferences

        theme = context.preferences.themes['Default']
        vertex_size = theme.view_3d.vertex_size

        bgl.glEnable(bgl.GL_BLEND)
        bgl.glLineWidth(props.edge_width + 1)
        bgl.glPointSize(vertex_size + 5)
        bgl.glCullFace(bgl.GL_BACK)

        if props.xray_che == False:
            bgl.glEnable(bgl.GL_DEPTH_TEST)
            bgl.glEnable(bgl.GL_CULL_FACE)

        if props.line_smooth:
            bgl.glEnable(bgl.GL_LINE_SMOOTH)

        bgl.glDepthRange(0, 0.9999)
        #bgl.glDepthFunc(600)
        bgl.glDepthMask(False)

        shader.bind()

        # COLOR
        #opacity_second = props.opacity + 0.1
        ngone_col = props.ngone_col[0], props.ngone_col[1], props.ngone_col[
            2], props.ngone_col[3]
        tris_col = props.tris_col[0], props.tris_col[1], props.tris_col[
            2], props.tris_col[3]
        e_non_col = props.non_manifold_color[0], props.non_manifold_color[
            1], props.non_manifold_color[2], props.non_manifold_color[3]
        e_pole_col = props.e_pole_col[0], props.e_pole_col[
            1], props.e_pole_col[2], props.e_pole_col[3]
        n_pole_col = props.n_pole_col[0], props.n_pole_col[
            1], props.n_pole_col[2], props.n_pole_col[3]
        f_pole_col = props.f_pole_col[0], props.f_pole_col[
            1], props.f_pole_col[2], props.f_pole_col[3]
        v_bound_col = props.bound_col[0], props.bound_col[1], props.bound_col[
            2], props.bound_col[3]
        v_alone_col = props.v_alone_color[0], props.v_alone_color[
            1], props.v_alone_color[2], props.v_alone_color[3]
        custom_col = props.custom_col[0], props.custom_col[
            1], props.custom_col[2], props.custom_col[3]

        if props.use_mod_che:
            depsgraph = context.evaluated_depsgraph_get()

        for obj in objs:
            if obj.type == 'MESH':

                me = obj.data
                if len(me.polygons) < 50000:

                    if context.mode == 'EDIT_MESH' and props.use_mod_che == False:
                        bm = bmesh.from_edit_mesh(obj.data)

                    else:
                        if props.use_mod_che:
                            if len(obj.modifiers) > 0:
                                depsgraph.update()

                            ob_eval = obj.evaluated_get(depsgraph)
                            me = ob_eval.to_mesh()

                        bm = bmesh.new()
                        bm.from_mesh(me,
                                     face_normals=True,
                                     use_shape_key=False)

                        bm.verts.ensure_lookup_table()
                        bm.edges.ensure_lookup_table()
                        bm.faces.ensure_lookup_table()

                    # --- N-Gone
                    if props.ngone:
                        ngone = []
                        for n in bm.faces:
                            if len(n.verts) > 4:
                                ngone.append(n.index)
                        #print("ngone",ngone)

                        copy = bm.copy()
                        copy.faces.ensure_lookup_table()
                        edge_n = [
                            e for i in ngone for e in copy.faces[i].edges
                        ]

                        for e in copy.edges:
                            if not e in edge_n:
                                e.hide_set(True)

                        bmesh.ops.triangulate(copy, faces=copy.faces[:])

                        v_index = []
                        ngone_co = []
                        for f in copy.faces:
                            v_index.extend(
                                [v.index for v in f.verts if not f.hide])
                            ngone_co.extend([
                                obj.matrix_world @ v.co for v in f.verts
                                if not f.hide
                            ])

                        copy.free()  # TODO может быть удалить ?

                        ngons_indices = []
                        ngons_indices.extend(
                            list(range(0, len(v_index)))[v_i:v_i + 3]
                            for v_i in range(0, len(v_index), 3))
                        NGONE = batch_for_shader(shader,
                                                 'TRIS', {"pos": ngone_co},
                                                 indices=ngons_indices)
                        shader.uniform_float("color", ngone_col)
                        NGONE.draw(shader)

                    # --- Custom
                    if props.custom_count:
                        custom_faces = []
                        for n in bm.faces:
                            if len(n.verts) == props.custom_count_verts:
                                custom_faces.append(n.index)

                        copy = bm.copy()
                        copy.faces.ensure_lookup_table()
                        edge_n = [
                            e for i in custom_faces
                            for e in copy.faces[i].edges
                        ]

                        for e in copy.edges:
                            if not e in edge_n:
                                e.hide_set(True)

                        bmesh.ops.triangulate(copy, faces=copy.faces[:])

                        v_index = []
                        custom_co = []
                        for f in copy.faces:
                            v_index.extend(
                                [v.index for v in f.verts if not f.hide])
                            custom_co.extend([
                                obj.matrix_world @ v.co for v in f.verts
                                if not f.hide
                            ])

                        copy.free()  # TODO может быть удалить ?

                        custom_faces_indices = []
                        custom_faces_indices.extend(
                            list(range(0, len(v_index)))[v_i:v_i + 3]
                            for v_i in range(0, len(v_index), 3))
                        CUSTOM = batch_for_shader(shader,
                                                  'TRIS', {"pos": custom_co},
                                                  indices=custom_faces_indices)
                        shader.uniform_float("color", custom_col)
                        CUSTOM.draw(shader)

                    if props.tris:
                        tris_co = [
                            obj.matrix_world @ v.co for f in bm.faces
                            for v in f.verts if len(f.verts) == 3
                        ]
                        TRIS = batch_for_shader(shader, 'TRIS',
                                                {"pos": tris_co})
                        shader.uniform_float("color", tris_col)
                        TRIS.draw(shader)

                    if props.non_manifold_check:
                        e_non_i = [
                            e.index for e in bm.edges if not e.is_manifold
                        ]
                        e_non_co = [
                            obj.matrix_world @ v.co for i in e_non_i
                            for v in bm.edges[i].verts
                        ]
                        EDGES_NON = batch_for_shader(shader, 'LINES',
                                                     {"pos": e_non_co})
                        shader.uniform_float("color", e_non_col)
                        EDGES_NON.draw(shader)

                    if props.e_pole:
                        e_pole_co = [
                            obj.matrix_world @ v.co for v in bm.verts
                            if len(v.link_edges) == 5
                        ]
                        E_POLE = batch_for_shader(shader, 'POINTS',
                                                  {"pos": e_pole_co})
                        shader.uniform_float("color", e_pole_col)
                        E_POLE.draw(shader)

                    if props.n_pole:
                        n_pole_co = [
                            obj.matrix_world @ v.co for v in bm.verts
                            if len(v.link_edges) == 3
                        ]
                        N_POLE = batch_for_shader(shader, 'POINTS',
                                                  {"pos": n_pole_co})
                        shader.uniform_float("color", n_pole_col)
                        N_POLE.draw(shader)

                    if props.f_pole:
                        f_pole_co = [
                            obj.matrix_world @ v.co for v in bm.verts
                            if len(v.link_edges) > 5
                        ]
                        F_POLE = batch_for_shader(shader, 'POINTS',
                                                  {"pos": f_pole_co})
                        shader.uniform_float("color", f_pole_col)
                        F_POLE.draw(shader)

                    if props.v_bound:
                        v_bound_co = [
                            obj.matrix_world @ v.co for v in bm.verts
                            if v.is_boundary or not v.is_manifold
                        ]
                        V_BOUND = batch_for_shader(shader, 'POINTS', {
                            "pos": v_bound_co,
                        })
                        shader.uniform_float("color", v_bound_col)
                        V_BOUND.draw(shader)

                    if props.v_alone:
                        v_alone_co = [
                            obj.matrix_world @ v.co for v in bm.verts
                            if len(v.link_edges) < 1
                        ]
                        V_ALONE = batch_for_shader(shader, 'POINTS',
                                                   {"pos": v_alone_co})
                        shader.uniform_float("color", v_alone_col)
                        V_ALONE.draw(shader)

                    if props.use_mod_che:
                        bm.free()

        if props.line_smooth:
            bgl.glDisable(bgl.GL_LINE_SMOOTH)

        bgl.glDisable(bgl.GL_DEPTH_TEST)
        bgl.glDisable(bgl.GL_CULL_FACE)
        bgl.glLineWidth(2)
        bgl.glPointSize(vertex_size)

        bgl.glDisable(bgl.GL_BLEND)
Beispiel #40
0
    def draw_post3d_spline(self):
        if not self.strips: return

        strips = self.strips
        hov_strips = self.hovering_strips

        Point_to_Point2D = self.rfcontext.Point_to_Point2D

        def is_visible(v):
            return True  # self.rfcontext.is_visible(v, None)

        def draw(alphamult, hov_alphamult, hover):
            nonlocal strips

            if not hover: hov_alphamult = alphamult

            size_outer = options['polystrips handle outer size']
            size_inner = options['polystrips handle inner size']
            border_outer = options['polystrips handle border']
            border_inner = options['polystrips handle border']

            bgl.glEnable(bgl.GL_BLEND)

            # draw outer-inner lines
            pts = [
                Point_to_Point2D(p) for strip in strips
                for p in strip.curve.points()
            ]
            self.rfcontext.drawing.draw2D_lines(pts, (1, 1, 1, 0.45), width=2)

            # draw junction handles (outer control points of curve)
            faces_drawn = set(
            )  # keep track of faces, so don't draw same handles 2+ times
            pts_outer, pts_inner = [], []
            for strip in strips:
                bmf0, bmf1 = strip.end_faces()
                p0, p1, p2, p3 = strip.curve.points()
                if bmf0 not in faces_drawn:
                    if is_visible(p0): pts_outer += [Point_to_Point2D(p0)]
                    faces_drawn.add(bmf0)
                if bmf1 not in faces_drawn:
                    if is_visible(p3): pts_outer += [Point_to_Point2D(p3)]
                    faces_drawn.add(bmf1)
                if is_visible(p1): pts_inner += [Point_to_Point2D(p1)]
                if is_visible(p2): pts_inner += [Point_to_Point2D(p2)]
            self.rfcontext.drawing.draw2D_points(pts_outer,
                                                 (1.00, 1.00, 1.00, 1.0),
                                                 radius=size_outer,
                                                 border=border_outer,
                                                 borderColor=(0.00, 0.00, 0.00,
                                                              0.5))
            self.rfcontext.drawing.draw2D_points(pts_inner,
                                                 (0.25, 0.25, 0.25, 0.8),
                                                 radius=size_inner,
                                                 border=border_inner,
                                                 borderColor=(0.75, 0.75, 0.75,
                                                              0.4))

        if True:
            # always draw on top!
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glDisable(bgl.GL_DEPTH_TEST)
            bgl.glDepthMask(bgl.GL_FALSE)
            draw(1.0, 1.0, False)
            bgl.glEnable(bgl.GL_DEPTH_TEST)
            bgl.glDepthMask(bgl.GL_TRUE)
        else:
            # allow handles to go under surface
            bgl.glDepthRange(0, 0.9999)  # squeeze depth just a bit
            bgl.glEnable(bgl.GL_BLEND)
            bgl.glDepthMask(bgl.GL_FALSE)  # do not overwrite depth
            bgl.glEnable(bgl.GL_DEPTH_TEST)

            # draw in front of geometry
            bgl.glDepthFunc(bgl.GL_LEQUAL)
            draw(
                options['target alpha'],
                options['target alpha'],  # hover
                False,  #options['polystrips handle hover']
            )

            # draw behind geometry
            bgl.glDepthFunc(bgl.GL_GREATER)
            draw(
                options['target hidden alpha'],
                options['target hidden alpha'],  # hover
                False,  #options['polystrips handle hover']
            )

            bgl.glDepthFunc(bgl.GL_LEQUAL)
            bgl.glDepthRange(0.0, 1.0)
            bgl.glDepthMask(bgl.GL_TRUE)
Beispiel #41
0
    def draw_callback_px(self, context):
        # draw 3d point OpenGL in the 3D View
        bgl.glEnable(bgl.GL_BLEND)

        if self.vector_constrain:
            vc = self.vector_constrain
            if hasattr(self, 'preloc') and self.type in {'VERT', 'FACE'}:
                bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
                bgl.glDepthRange(0, 0)
                bgl.glPointSize(5)
                bgl.glBegin(bgl.GL_POINTS)
                bgl.glVertex3f(*self.preloc)
                bgl.glEnd()
            if vc[2] == 'X':
                Color4f = (self.axis_x_color + (1.0, ))
            elif vc[2] == 'Y':
                Color4f = (self.axis_y_color + (1.0, ))
            elif vc[2] == 'Z':
                Color4f = (self.axis_z_color + (1.0, ))
            else:
                Color4f = self.constrain_shift_color
        else:
            if self.type == 'OUT':
                Color4f = self.out_color
            elif self.type == 'FACE':
                Color4f = self.face_color
            elif self.type == 'EDGE':
                Color4f = self.edge_color
            elif self.type == 'VERT':
                Color4f = self.vert_color
            elif self.type == 'CENTER':
                Color4f = self.center_color
            elif self.type == 'PERPENDICULAR':
                Color4f = self.perpendicular_color

        bgl.glColor4f(*Color4f)
        bgl.glDepthRange(0, 0)
        bgl.glPointSize(10)
        bgl.glBegin(bgl.GL_POINTS)
        bgl.glVertex3f(*self.location)
        bgl.glEnd()
        bgl.glDisable(bgl.GL_BLEND)

        # draw 3d line OpenGL in the 3D View
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glDepthRange(0, 0.9999)
        bgl.glColor4f(1.0, 0.8, 0.0, 1.0)
        bgl.glLineWidth(2)
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for vert_co in self.list_verts_co:
            bgl.glVertex3f(*vert_co)
        bgl.glVertex3f(*self.location)
        bgl.glEnd()

        # restore opengl defaults
        bgl.glDepthRange(0, 1)
        bgl.glPointSize(1)
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glDisable(bgl.GL_LINE_STIPPLE)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
 def _set(self, instance, value):
     bgl.glDepthRange(value[0], value[1])
    def draw_3D_stuff(self):
        context = self.context
        region,r3d = context.region,context.space_data.region_3d
        view_dir = r3d.view_rotation * Vector((0,0,-1))
        view_loc = r3d.view_location - view_dir * r3d.view_distance
        view_ortho = (r3d.view_perspective == 'ORTHO')
        if view_ortho: view_loc -= view_dir * 1000.0

        bgl.glEnable(bgl.GL_POINT_SMOOTH)
        bgl.glDepthRange(0.0, 1.0)
        bgl.glEnable(bgl.GL_DEPTH_TEST)
        bgl.glLineWidth(1)
        bgl.glDepthRange(0.0, 1.0)

        if self._state != 'segmentation':
            #CurveNetwork, BezierSegments
            for seg in self.spline_net.segments:
                if len(seg.draw_tessellation) == 0: continue

                #has not been successfully converted to InputPoints and InputSegments
                if seg.is_inet_dirty:
                    draw3d_polyline(seg.draw_tessellation, orange2, 4, view_loc, view_ortho)

                #if len(seg.ip_tesselation):
                #    draw3d_polyline(seg.ip_tesselation,  blue, 2, view_loc, view_ortho)
                #    draw3d_points(seg.ip_tesselation, green2, 4, view_loc, view_ortho)

            draw3d_points(self.spline_net.point_world_locs, green2, 6, view_loc, view_ortho)

            # Polylines...InputSegments
            for seg in self.input_net.segments:
                #bad segment with a preview path provided by geodesic
                if seg.bad_segment and not len(seg.path) > 2:
                    draw3d_polyline([seg.ip0.world_loc, seg.ip1.world_loc], pink, 2, view_loc, view_ortho)

                #s
                elif len(seg.path) >= 2 and not seg.bad_segment and seg not in self.network_cutter.completed_segments:
                    draw3d_polyline(seg.path,  blue, 2, view_loc, view_ortho)

                elif len(seg.path) >= 2 and not seg.bad_segment and seg in self.network_cutter.completed_segments:
                    draw3d_polyline(seg.path,  green2, 2, view_loc, view_ortho)

                elif len(seg.path) >= 2 and seg.bad_segment:
                    draw3d_polyline(seg.path,  orange2, 2, view_loc, view_ortho)
                    draw3d_polyline([seg.ip0.world_loc, seg.ip1.world_loc], orange2, 2, view_loc, view_ortho)

                elif seg.calculation_complete == False:
                    draw3d_polyline([seg.ip0.world_loc, seg.ip1.world_loc], orange2, 2, view_loc, view_ortho)
                else:
                    draw3d_polyline([seg.ip0.world_loc, seg.ip1.world_loc], blue2, 2, view_loc, view_ortho)


            if self.network_cutter.the_bad_segment:
                seg = self.network_cutter.the_bad_segment
                draw3d_polyline([seg.ip0.world_loc, seg.ip1.world_loc],  red, 4, view_loc, view_ortho)


        if self._state == 'segmentation':
            #draw the hovered patch
            #TODO, segmentation only happens AFTER CUtting
            #So it would be MUCH easier to just draw the damn edges of the patch
            if self.net_ui_context.hovered_near[0] == 'PATCH':
                p = self.net_ui_context.hovered_near[1]
                if p != self.network_cutter.active_patch:
                    for spline_seg in p.spline_net_segments:
                        for iseg in spline_seg.input_segments:
                            draw3d_polyline([iseg.ip0.world_loc] + iseg.path + [iseg.ip1.world_loc],  orange2, 4, view_loc, view_ortho)

            if self.network_cutter.active_patch:
                for spline_seg in self.network_cutter.active_patch.spline_net_segments:
                    for iseg in spline_seg.input_segments:
                            draw3d_polyline([iseg.ip0.world_loc] + iseg.path + [iseg.ip1.world_loc],  orange2, 4, view_loc, view_ortho)

        if self._state == 'spline':
            draw3d_points(self.input_net.point_world_locs, blue, 2, view_loc, view_ortho)
        elif self._state != 'segmentation':
            draw3d_points(self.input_net.point_world_locs, blue, 6, view_loc, view_ortho)

        #draw the seed/face patch points
        draw3d_points([p.world_loc for p in self.network_cutter.face_patches], orange2, 6, view_loc, view_ortho)


        #draw the actively processing Input Point (IP Steper Debug) for debug stepper cutting
        if self.network_cutter.active_ip:
            draw3d_points([self.network_cutter.active_ip.world_loc], purple, 20, view_loc, view_ortho)
            draw3d_points([ip.world_loc for ip in self.network_cutter.ip_chain], purple, 12, view_loc, view_ortho)

        if self.network_cutter.seg_enter:
            draw3d_polyline(self.network_cutter.seg_enter.path, green2, 4, view_loc, view_ortho)

        if self.network_cutter.seg_exit:
            draw3d_polyline(self.network_cutter.seg_exit.path, red, 4, view_loc, view_ortho)

        bgl.glLineWidth(1)
        bgl.glDepthFunc(bgl.GL_LEQUAL)
        bgl.glDepthRange(0.0, 1.0)
        bgl.glDepthMask(bgl.GL_TRUE)
    def draw_callback_px(self, context):
        # draw 3d point OpenGL in the 3D View
        bgl.glEnable(bgl.GL_BLEND)

        if self.vector_constrain:
            vc = self.vector_constrain
            if hasattr(self, 'preloc') and self.type in {'VERT', 'FACE'}:
                bgl.glColor4f(1.0,1.0,1.0,0.5)
                bgl.glDepthRange(0,0)
                bgl.glPointSize(5)
                bgl.glBegin(bgl.GL_POINTS)
                bgl.glVertex3f(*self.preloc)
                bgl.glEnd()
            if vc[2] == 'X':
                Color4f = (self.axis_x_color + (1.0,))
            elif vc[2] == 'Y':
                Color4f = (self.axis_y_color + (1.0,))
            elif vc[2] == 'Z':
                Color4f = (self.axis_z_color + (1.0,))
            else:
                Color4f = self.constrain_shift_color
        else:
            if self.type == 'OUT':
                Color4f = self.out_color 
            elif self.type == 'FACE':
                Color4f = self.face_color
            elif self.type == 'EDGE':
                Color4f = self.edge_color
            elif self.type == 'VERT':
                Color4f = self.vert_color
            elif self.type == 'CENTER':
                Color4f = self.center_color
            elif self.type == 'PERPENDICULAR':
                Color4f = self.perpendicular_color
                
        bgl.glColor4f(*Color4f)
        bgl.glDepthRange(0,0)
        bgl.glPointSize(10)
        bgl.glBegin(bgl.GL_POINTS)
        bgl.glVertex3f(*self.location)
        bgl.glEnd()
        bgl.glDisable(bgl.GL_BLEND)

        # draw 3d line OpenGL in the 3D View
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glDepthRange(0,0.9999)
        bgl.glColor4f(1.0, 0.8, 0.0, 1.0)    
        bgl.glLineWidth(2)    
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for vert_co in self.list_verts_co:
            bgl.glVertex3f(*vert_co)        
        bgl.glVertex3f(*self.location)        
        bgl.glEnd()
            
        # restore opengl defaults
        bgl.glDepthRange(0,1)
        bgl.glPointSize(1)
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glDisable(bgl.GL_LINE_STIPPLE)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Beispiel #45
0
    def draw(self,
             view_forward,
             unit_scaling_factor,
             buf_matrix_target,
             buf_matrix_target_inv,
             buf_matrix_view,
             buf_matrix_view_invtrans,
             buf_matrix_proj,
             alpha_above,
             alpha_below,
             cull_backfaces,
             alpha_backface,
             draw_mirrored,
             symmetry=None,
             symmetry_view=None,
             symmetry_effect=0.0,
             symmetry_frame: Frame = None):
        self.clean()
        if not self.buffered_renders_static and not self.buffered_renders_dynamic:
            return

        try:
            bgl.glDepthMask(bgl.GL_FALSE)  # do not overwrite the depth buffer

            opts = dict(self.opts)

            opts['matrix model'] = self.rfmesh.xform.mx_p
            opts['matrix normal'] = self.rfmesh.xform.mx_n
            opts['matrix target'] = buf_matrix_target
            opts['matrix target inverse'] = buf_matrix_target_inv
            opts['matrix view'] = buf_matrix_view
            opts['matrix view normal'] = buf_matrix_view_invtrans
            opts['matrix projection'] = buf_matrix_proj
            opts['forward direction'] = view_forward
            opts['unit scaling factor'] = unit_scaling_factor

            opts['symmetry'] = symmetry
            opts['symmetry frame'] = symmetry_frame
            opts['symmetry view'] = symmetry_view
            opts['symmetry effect'] = symmetry_effect
            opts['draw mirrored'] = draw_mirrored

            bmegl.glSetDefaultOptions()

            opts['no warning'] = not options['warn non-manifold']

            opts['cull backfaces'] = cull_backfaces
            opts['alpha backface'] = alpha_backface
            opts['dpi mult'] = self.drawing.get_dpi_mult()
            mirror_axes = self.rfmesh.mirror_mod.xyz if self.rfmesh.mirror_mod else []
            for axis in mirror_axes:
                opts['mirror %s' % axis] = True

            if not opts.get('no below', False):
                # draw geometry hidden behind
                # geometry below
                bgl.glDepthFunc(bgl.GL_GREATER)
                opts['poly hidden'] = 1 - alpha_below
                opts['poly mirror hidden'] = 1 - alpha_below
                opts['line hidden'] = 1 - alpha_below
                opts['line mirror hidden'] = 1 - alpha_below
                opts['point hidden'] = 1 - alpha_below
                opts['point mirror hidden'] = 1 - alpha_below
                for buffered_render in self.buffered_renders_static:
                    buffered_render.draw(opts)
                for buffered_render in self.buffered_renders_dynamic:
                    buffered_render.draw(opts)

            # geometry above
            bgl.glDepthFunc(bgl.GL_LEQUAL)
            opts['poly hidden'] = 1 - alpha_above
            opts['poly mirror hidden'] = 1 - alpha_above
            opts['line hidden'] = 1 - alpha_above
            opts['line mirror hidden'] = 1 - alpha_above
            opts['point hidden'] = 1 - alpha_above
            opts['point mirror hidden'] = 1 - alpha_above
            for buffered_render in self.buffered_renders_static:
                buffered_render.draw(opts)
            for buffered_render in self.buffered_renders_dynamic:
                buffered_render.draw(opts)

            bgl.glDepthFunc(bgl.GL_LEQUAL)
            bgl.glDepthMask(bgl.GL_TRUE)
            bgl.glDepthRange(0, 1)
        except:
            Debugger.print_exception()
            pass
Beispiel #46
0
def draw_callback_px(self, context):
    # draw 3d point OpenGL in the 3D View
    bgl.glEnable(bgl.GL_BLEND)
    if self.bool_constrain:
        if self.vector_constrain == Vector((1, 0, 0)):
            Color4f = (self.axis_x_color + (1.0, ))
        elif self.vector_constrain == Vector((0, 1, 0)):
            Color4f = (self.axis_y_color + (1.0, ))
        elif self.vector_constrain == Vector((0, 0, 1)):
            Color4f = (self.axis_z_color + (1.0, ))
        else:
            Color4f = self.constrain_shift_color
    else:
        if self.type == 'OUT':
            Color4f = self.out_color
        elif self.type == 'FACE':
            Color4f = self.face_color
        elif self.type == 'EDGE':
            Color4f = self.edge_color
        elif self.type == 'VERT':
            Color4f = self.vert_color
        elif self.type == 'CENTER':
            Color4f = self.center_color
        elif self.type == 'PERPENDICULAR':
            Color4f = self.perpendicular_color

    bgl.glColor4f(*Color4f)
    bgl.glDepthRange(0, 0)
    bgl.glPointSize(10)
    bgl.glBegin(bgl.GL_POINTS)
    bgl.glVertex3f(*self.location)
    bgl.glEnd()
    bgl.glDisable(bgl.GL_BLEND)

    # draw 3d line OpenGL in the 3D View
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glDepthRange(0, 0.9999)
    bgl.glColor4f(1.0, 0.8, 0.0, 1.0)
    bgl.glLineWidth(2)
    bgl.glEnable(bgl.GL_LINE_STIPPLE)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    for vert_co in self.list_vertices_co:
        bgl.glVertex3f(*vert_co)
    bgl.glVertex3f(*self.location)
    bgl.glEnd()

    # restore opengl defaults
    bgl.glDepthRange(0, 1)
    bgl.glPointSize(1)
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glDisable(bgl.GL_LINE_STIPPLE)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)

    a = ""
    if self.list_vertices_co != [] and self.length_entered == "":
        a = 'length: ' + str(
            round((self.list_vertices_co[-1] - self.location).length, 3))
    elif self.list_vertices_co != [] and self.length_entered != "":
        a = 'length: ' + self.length_entered

    context.area.header_text_set(
        "hit: %.3f %.3f %.3f %s" %
        (self.location[0], self.location[1], self.location[2], a))
 def _set(self, instance, value):
     glDepthRange(float(value[0]), float(value[1]))
    def draw_postview(self, context, mesh, isBaseMesh):
        #mesh = self.mesh #temporary in case we decide it should be named differently
        a1 = 1.0
        a2 = 1.0
        if isBaseMesh and self.sublvl > 0:
            a1 = 0.5
            a2 = .75

        bgl.glEnable(bgl.GL_POINT_SMOOTH)
        bgl.glEnable(bgl.GL_BLEND)

        #draw the vertices
        for v in mesh.vertices:
            if v in self.selected:
                bgl.glColor4d(0.9, 0.5, 0, a2)
                bgl.glPointSize(4)
            else:
                bgl.glColor4d(1, 1, 0, a1)
                bgl.glPointSize(2)

            bgl.glBegin(bgl.GL_POINTS)
            bgl.glVertex3f(*v.co.to_tuple())
            bgl.glEnd()

        bgl.glDepthRange(0.0, 0.9999)
        #draw the edges
        for e in mesh.edges:
            if e in self.selected:
                bgl.glColor4d(0.9, 0.5, 0, a2)
                bgl.glLineWidth(2)
            else:
                bgl.glColor4d(0.5, 0.5, 0, a1)
                bgl.glLineWidth(1)

            bgl.glBegin(bgl.GL_LINES)
            bgl.glVertex3f(*e.v0.co.to_tuple())
            bgl.glVertex3f(*e.v1.co.to_tuple())
            bgl.glEnd()
        bgl.glDepthRange(0.0, 1.0)

        #draw the faces
        bgl.glBegin(bgl.GL_TRIANGLES)

        for f in mesh.faces:
            if f in self.selected:
                bgl.glColor4d(0.6, 0.2, 0, a2)
            else:
                bgl.glColor4d(0.3, 0.3, 0.3, a1)
            a = 0
            b = 1
            c = 2
            for i in range(len(f.lvertices) - 2):
                bgl.glVertex3f(*f.lvertices[a].co.to_tuple())
                bgl.glVertex3f(*f.lvertices[b].co.to_tuple())
                bgl.glVertex3f(*f.lvertices[c].co.to_tuple())
                b += 1
                c += 1

        bgl.glEnd()

        if False:
            bgl.glColor3f(0, 1, 1)
            bgl.glBegin(bgl.GL_LINES)
            for f in mesh.faces:
                p0 = Vector()
                for v in f.lvertices:
                    p0 += v.co
                p0 /= len(f.lvertices)
                p1 = p0 + f.normal * 0.2
                bgl.glVertex3f(*p0)
                bgl.glVertex3f(*p1)
            bgl.glEnd()
Beispiel #49
0
    def draw(self, type, location, list_verts_co, vector_constrain, prevloc):
        import gpu

        # draw 3d point OpenGL in the 3D View
        bgl.glEnable(bgl.GL_BLEND)
        gpu.matrix.push()
        self._program_unif_col.bind()

        if list_verts_co:
            # draw 3d line OpenGL in the 3D View
            bgl.glDepthRange(0, 0.9999)
            bgl.glLineWidth(3.0)

            batch = self.batch_line_strip_create(
                [v.to_tuple() for v in list_verts_co] + [location.to_tuple()])

            self._program_unif_col.uniform_float("color", (1.0, 0.8, 0.0, 0.5))
            batch.draw(self._program_unif_col)
            del batch

        bgl.glDisable(bgl.GL_DEPTH_TEST)

        point_batch = self.batch_point_get()
        if vector_constrain:
            if prevloc:
                bgl.glPointSize(5)
                gpu.matrix.translate(prevloc)
                self._program_unif_col.uniform_float("color",
                                                     (1.0, 1.0, 1.0, 0.5))
                point_batch.draw(self._program_unif_col)
                gpu.matrix.translate(-prevloc)

            if vector_constrain[2] == 'X':
                Color4f = self.axis_x_color
            elif vector_constrain[2] == 'Y':
                Color4f = self.axis_y_color
            elif vector_constrain[2] == 'Z':
                Color4f = self.axis_z_color
            else:
                Color4f = self.constrain_shift_color
        else:
            if type == 'OUT':
                Color4f = self.out_color
            elif type == 'FACE':
                Color4f = self.face_color
            elif type == 'EDGE':
                Color4f = self.edge_color
            elif type == 'VERT':
                Color4f = self.vert_color
            elif type == 'CENTER':
                Color4f = self.center_color
            elif type == 'PERPENDICULAR':
                Color4f = self.perpendicular_color
            else:  # type == None
                Color4f = self.out_color

        bgl.glPointSize(10)

        gpu.matrix.translate(location)
        self._program_unif_col.uniform_float("color", Color4f)
        point_batch.draw(self._program_unif_col)

        # restore opengl defaults
        bgl.glDepthRange(0.0, 1.0)
        bgl.glPointSize(1.0)
        bgl.glLineWidth(1.0)
        bgl.glEnable(bgl.GL_DEPTH_TEST)
        bgl.glDisable(bgl.GL_BLEND)

        gpu.matrix.pop()
    def brushfalloff_postview(self):
        if self.mode != 'main': return
        if not self.hit: return
        cx,cy,cp = self.hit_x,self.hit_y,self.hit_p
        cs_outer = self.scale * self.radius
        cs_inner = self.scale * self.radius * math.pow(0.5, 1.0 / self.falloff)
        cr,cg,cb = self.color

        bgl.glDepthRange(0, 0.999)      # squeeze depth just a bit
        bgl.glEnable(bgl.GL_BLEND)
        self.drawing.line_width(2.0)
        self.drawing.point_size(3.0)

        ######################################
        # draw in front of geometry

        bgl.glDepthFunc(bgl.GL_LEQUAL)
        bgl.glDepthMask(bgl.GL_FALSE)   # do not overwrite depth

        bgl.glColor4f(cr, cg, cb, 0.75 * self.strength)
        bgl.glBegin(bgl.GL_TRIANGLES)
        for p0,p1 in zip(self.points[:-1], self.points[1:]):
            x0,y0 = p0
            x1,y1 = p1
            outer0 = (cs_outer * ((cx * x0) + (cy * y0))) + cp
            outer1 = (cs_outer * ((cx * x1) + (cy * y1))) + cp
            inner0 = (cs_inner * ((cx * x0) + (cy * y0))) + cp
            inner1 = (cs_inner * ((cx * x1) + (cy * y1))) + cp
            bgl.glVertex3f(*outer0)
            bgl.glVertex3f(*outer1)
            bgl.glVertex3f(*inner0)
            bgl.glVertex3f(*outer1)
            bgl.glVertex3f(*inner1)
            bgl.glVertex3f(*inner0)
        bgl.glEnd()

        bgl.glColor4f(1, 1, 1, 1)       # outer ring
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x,y in self.points:
            p = (cs_outer * ((cx * x) + (cy * y))) + cp
            bgl.glVertex3f(*p)
        bgl.glEnd()

        bgl.glColor4f(1, 1, 1, 0.5)     # inner ring
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x,y in self.points:
            p = (cs_inner * ((cx * x) + (cy * y))) + cp
            bgl.glVertex3f(*p)
        bgl.glEnd()

        bgl.glColor4f(1, 1, 1, 0.25)    # center point
        bgl.glBegin(bgl.GL_POINTS)
        bgl.glVertex3f(*cp)
        bgl.glEnd()

        ######################################
        # draw behind geometry (hidden below)

        bgl.glDepthFunc(bgl.GL_GREATER)
        bgl.glDepthMask(bgl.GL_FALSE)   # do not overwrite depth

        bgl.glColor4f(cr, cg, cb, 0.10 * self.strength)
        bgl.glBegin(bgl.GL_TRIANGLES)
        for p0,p1 in zip(self.points[:-1], self.points[1:]):
            x0,y0 = p0
            x1,y1 = p1
            outer0 = (cs_outer * ((cx * x0) + (cy * y0))) + cp
            outer1 = (cs_outer * ((cx * x1) + (cy * y1))) + cp
            inner0 = (cs_inner * ((cx * x0) + (cy * y0))) + cp
            inner1 = (cs_inner * ((cx * x1) + (cy * y1))) + cp
            bgl.glVertex3f(*outer0)
            bgl.glVertex3f(*outer1)
            bgl.glVertex3f(*inner0)
            bgl.glVertex3f(*outer1)
            bgl.glVertex3f(*inner1)
            bgl.glVertex3f(*inner0)
        bgl.glEnd()

        bgl.glColor4f(1, 1, 1, 0.05)    # outer ring
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x,y in self.points:
            p = (cs_outer * ((cx * x) + (cy * y))) + cp
            bgl.glVertex3f(*p)
        bgl.glEnd()

        bgl.glColor4f(1, 1, 1, 0.025)   # inner ring
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for x,y in self.points:
            p = (cs_inner * ((cx * x) + (cy * y))) + cp
            bgl.glVertex3f(*p)
        bgl.glEnd()

        ######################################
        # reset to defaults

        bgl.glDepthFunc(bgl.GL_LEQUAL)
        bgl.glDepthMask(bgl.GL_TRUE)

        bgl.glDepthRange(0, 1)