예제 #1
0
 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  
예제 #2
0
def mi_draw_3d_polyline(points, p_size, p_col, x_ray):
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(1)

    if x_ray is True:
        bgl.glDisable(bgl.GL_DEPTH_TEST)

    bgl.glPointSize(p_size)
#    bgl.glBegin(bgl.GL_LINE_LOOP)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glColor4f(p_col[0], p_col[1], p_col[2], p_col[3])
 #   bgl.glBegin(bgl.GL_POLYGON)

    for point in points:
        bgl.glVertex3f(point[0], point[1], point[2])

    if x_ray is True:
        bgl.glEnable(bgl.GL_DEPTH_TEST)

    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #3
0
 def text_line(fx, fy, reduce, c, str):
     bgl.glColor4f(c[0], c[1], c[2], c[3])
     blf.position(0, fx, fy, 0)
     blf.draw(0, str)
     if reduce:
         fy -= 20
     return fy
예제 #4
0
def draw_callback_px(self, context):
    
    if init_functions(self, context) == None:
        return
        
    region = context.region
    rv3d = context.space_data.region_3d
    points, guide_verts = init_functions(self, context)
    
    arc_verts = get_arc_from_state(points, guide_verts, context)

    # draw bevel, followed by symmetry line, then fillet edge loop
    draw_polyline_from_coordinates(context, points, "GL_LINE_STIPPLE")
    draw_polyline_from_coordinates(context, guide_verts, "GL_LINE_STIPPLE")
    draw_polyline_from_coordinates(context, arc_verts, "GL_BLEND")

    # draw arc verts, then radial centre   
    if DRAW_POINTS:
        draw_points(context, arc_verts, 4.2, gl_col1)    
        draw_points(context, [guide_verts[1]], 5.2, gl_col2)
    
    # draw bottom left, above object name the number of vertices in the fillet
    draw_text(context, (65, 30), context.scene.NumVerts)
        
    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    return
예제 #5
0
def vicon_view3d_draw(x, y, w, h, alpha=1.0):
    cx = x + w / 2
    cy = y + h / 2
    d = max(2, h / 3)

    bgl.glColor4f(0.5, 0.5, 0.5, alpha)
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex2f(x, cy - d)
    bgl.glVertex2f(x + w, cy - d)
    bgl.glVertex2f(x, cy + d)
    bgl.glVertex2f(x + w, cy + d)

    bgl.glVertex2f(cx - d, y)
    bgl.glVertex2f(cx - d, y + h)
    bgl.glVertex2f(cx + d, y)
    bgl.glVertex2f(cx + d, y + h)
    bgl.glEnd()

    bgl.glColor4f(0.0, 0.0, 0.0, alpha)
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex2f(x, cy)
    bgl.glVertex2f(x + w, cy)
    bgl.glVertex2f(cx, y)
    bgl.glVertex2f(cx, y + h)
    bgl.glEnd()
예제 #6
0
def draw_polyline_from_points(context, points, color, thickness, LINE_TYPE):
    '''
    a simple way to draw a line
    args:
        points: a list of tuples representing x,y SCREEN coordinate eg [(10,30),(11,31),...]
        color: tuple (r,g,b,a)
        thickness: integer? maybe a float
        LINE_TYPE:  eg...bgl.GL_LINE_STIPPLE or 
    '''
    
    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)
    
    current_width = bgl.GL_LINE_WIDTH
    bgl.glColor4f(*color)
    bgl.glLineWidth(thickness)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    
    for coord in points:  
        bgl.glVertex2f(*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 uninterupted lines  
      
    return
def draw_callback_px(self, context):
    #print("callback_px")
    # Maybe print a nice red circle in some corner

    bgl.glPushAttrib(bgl.GL_CLIENT_ALL_ATTRIB_BITS)

    FONT_RGBA = (0.8, 0.1, 0.1, 0.5)
    bgl.glColor4f(*FONT_RGBA)

    font_size = 11
    DPI = 72

    blf.size(0, font_size, DPI)
    msg = "Logging..."
    
    msg_w,msg_h = blf.dimensions(0, msg)

    pos_x = context.region.width - msg_w
    pos_y = font_size / 2
    blf.position(0, pos_x, pos_y, 0)
    #blf.position(0, 10, 10, 0)

    blf.draw(0, msg)

    bgl.glPopAttrib()

    pass
예제 #8
0
def display_line_between_two_points(region, rv3d, p1_3d, p2_3d):

    bgl.glEnable(bgl.GL_BLEND)

    p1_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, p1_3d)
    p2_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, p2_3d)

    if p1_2d is None:
        p1_2d = (0.0, 0.0)
        p2_2d = (0.0, 0.0)

    col_line_main = addon_settings_graph()['col_line_main']
    col_line_shadow = addon_settings_graph()['col_line_shadow']

    bgl.glColor4f(*col_line_shadow)
    bgl.glLineWidth(1.4)
    bgl.glBegin(bgl.GL_LINE_STRIP) 
    bgl.glVertex2f((p1_2d[0]-1),(p1_2d[1]-1))
    bgl.glVertex2f((p2_2d[0]-1),(p2_2d[1]-1))
    bgl.glEnd()
    bgl.glColor4f(*col_line_main)
    bgl.glLineWidth(1.4)
    bgl.glBegin(bgl.GL_LINE_STRIP) 
    bgl.glVertex2f(*p1_2d)
    bgl.glVertex2f(*p2_2d)
    bgl.glEnd()

    bgl.glDisable(bgl.GL_BLEND)
예제 #9
0
def draw_line(self, context, vertexloc, vertexnorm, colour, thick):
    obj = context.active_object
    
    #get obj rotation
    rot = obj.rotation_euler.to_matrix().inverted()
    scale = obj.scale
    vertex = vertexloc * rot
    normal = vertexnorm * rot

    x1 = vertex[0] * scale[0] + obj.location[0]
    y1 = vertex[1] * scale[1] + obj.location[1]
    z1 = vertex[2] * scale[2] + obj.location[2]
    
    x2 = normal[0]*context.scene.tool_settings.normal_size* scale[0] + x1
    y2 = normal[1]*context.scene.tool_settings.normal_size* scale[1] + y1
    z2 = normal[2]*context.scene.tool_settings.normal_size* scale[2] + z1
    
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(thick)
    # set colour
    bgl.glColor4f(*colour)
    
    # draw line
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex3f(x1,y1,z1)
    bgl.glVertex3f(x2,y2,z2)
    bgl.glEnd()
    bgl.glDisable(bgl.GL_BLEND)
예제 #10
0
def draw_polyline_from_3dpoints(context, points_3d, color, thickness, LINE_TYPE):
    '''
    a simple way to draw a line
    slow...becuase it must convert to screen every time
    but allows you to pan and zoom around
    
    args:
        points_3d: a list of tuples representing x,y SCREEN coordinate eg [(10,30),(11,31),...]
        color: tuple (r,g,b,a)
        thickness: integer? maybe a float
        LINE_TYPE:  eg...bgl.GL_LINE_STIPPLE or 
    '''
    points = [location_3d_to_region_2d(context.region, context.space_data.region_3d, loc) for loc in points_3d]
    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.glBegin(bgl.GL_LINE_STRIP)
    for coord in points:  
        bgl.glVertex2f(*coord)  
    
    bgl.glEnd()  
      
    if LINE_TYPE == "GL_LINE_STIPPLE":  
        bgl.glDisable(bgl.GL_LINE_STIPPLE)  
        bgl.glEnable(bgl.GL_BLEND)  # back to uninterupted lines  
        bgl.glLineWidth(1)
    return
예제 #11
0
def cursor_history_draw(cls,context):
    cc = context.scene.cursor_history

    draw = 0
    if hasattr(cc, "historyDraw"):
        draw = cc.historyDraw

    if(draw):
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glShadeModel(bgl.GL_FLAT)
        alpha = 1-PHI_INV
        # History Trace
        if cc.historyPosition[0]<0:
            return
        bgl.glBegin(bgl.GL_LINE_STRIP)
        ccc = 0
        for iii in range(cc.historyWindow+1):
            ix_rel = iii - int(cc.historyWindow / 2)
            ix = cc.historyPosition[0] + ix_rel
            if(ix<0 or ix>=len(cc.historyLocation)):
                continue
            ppp = region3d_get_2d_coordinates(context, cc.historyLocation[ix])
            if(ix_rel<=0):
                bgl.glColor4f(0, 0, 0, alpha)
            else:
                bgl.glColor4f(1, 0, 0, alpha)
            bgl.glVertex2f(ppp[0], ppp[1])
            ccc = ccc + 1
        bgl.glEnd()
예제 #12
0
    def hud(dummy, self, context) :
        if 'type' in dir(self) :
            city = bpy.context.scene.city
            mdl = city.modal
            evt = self
            
            x_min,x,x_max = self._regions
            y_min,y_max = self._regionsy

            if x < self.mouse_x < x_max and y_min < self.mouse_y < y_max :
                mouse_x = self.mouse_x - x
                mouse_y = self.mouse_y - y_min
            else :
                mouse_x = False
                mouse_y = False
                
            # timer
            if mdl.timer :
                if evt.type == 'TIMER' : self.idx = (self.idx + 1)%4
                blf.size(0, 11, 72)
                blf.position(0, 35, 50, 0)
                blf.draw(0, "timer %1.3f : %s"%( mdl.timer_refresh, ('|/-\\')[self.idx]) )

            # is over ?
            overcrop = False
            bgl.glColor4f(1,1,1,1)
            #if mouse_x :
            blf.position(0, 35, 35, 0)
            blf.size(0, 11, 72)
            blf.draw(0, 'Mx: %s My: %s %s'%(mouse_x, mouse_y,self._regions))
            blf.position(0, 35, 20, 0)
            blf.size(0, 11, 72)
            blf.draw(0, 'Mx: %s My: %s'%(self.mouse_x, self.mouse_y))
예제 #13
0
 def draw_borders(x=0, y=0, w=30, h=10, color=(0.0, 0.0, 0.0, 1.0)):
     # function to draw a border color around the texture
     bgl.glColor4f(*color)
     bgl.glBegin(bgl.GL_LINE_LOOP)
     for coord in [(x, y), (x + w, y), (w + x, y - h), (x, y - h)]:
         bgl.glVertex2f(*coord)
     bgl.glEnd()
예제 #14
0
def screen_v3dBGL(context, args):
    region = context.region
    region3d = context.space_data.region_3d
    
    points = args[0]
    colors = args[1]
    size= 5.0
    
    bgl.glEnable(bgl.GL_POINT_SMOOTH) # for round vertex
    bgl.glPointSize(size)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    
    if colors:
        bgl.glBegin(bgl.GL_POINTS)
        for coord, color in zip(points, colors):
            bgl.glColor4f(*color)    
            bgl.glVertex3f(*coord)
        bgl.glEnd()

    else:
        gl_col = (0.9, 0.9, 0.8, 1.0)
        bgl.glColor4f(*gl_col)    
        bgl.glBegin(bgl.GL_POINTS)
        for coord in points:
            bgl.glVertex3f(*coord)
        bgl.glEnd()        
    
    bgl.glDisable(bgl.GL_POINT_SMOOTH)
    bgl.glDisable(bgl.GL_POINTS)
예제 #15
0
파일: test.py 프로젝트: CGCookie/retopoflow
    def draw_preview(self):
        bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)
        bgl.glMatrixMode(bgl.GL_MODELVIEW)
        bgl.glPushMatrix()
        bgl.glLoadIdentity()
        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glPushMatrix()
        bgl.glLoadIdentity()

        bgl.glEnable(bgl.GL_BLEND)
        bgl.glDisable(bgl.GL_DEPTH_TEST)

        bgl.glBegin(bgl.GL_QUADS)   # TODO: not use immediate mode
        bgl.glColor4f(0,0,0.2,0.5)
        bgl.glVertex2f(-1, -1)
        bgl.glVertex2f( 1, -1)
        bgl.glColor4f(0,0,0.2,0)
        bgl.glVertex2f( 1,  1)
        bgl.glVertex2f(-1,  1)
        bgl.glEnd()

        bgl.glPopMatrix()
        bgl.glMatrixMode(bgl.GL_MODELVIEW)
        bgl.glPopMatrix()
        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glPopAttrib()
예제 #16
0
파일: test.py 프로젝트: CGCookie/retopoflow
    def draw_postpixel(self):
        bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)

        bgl.glEnable(bgl.GL_BLEND)

        bgl.glMatrixMode(bgl.GL_MODELVIEW)
        bgl.glPushMatrix()
        bgl.glLoadIdentity()
        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glPushMatrix()
        bgl.glLoadIdentity()

        bgl.glColor4f(1,0,0,0.2)    # TODO: use window background color??
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glDisable(bgl.GL_DEPTH_TEST)
        bgl.glBegin(bgl.GL_QUADS)   # TODO: not use immediate mode
        bgl.glVertex2f(-1, -1)
        bgl.glVertex2f( 1, -1)
        bgl.glVertex2f( 1,  1)
        bgl.glVertex2f(-1,  1)
        bgl.glEnd()

        bgl.glPopMatrix()
        bgl.glMatrixMode(bgl.GL_MODELVIEW)
        bgl.glPopMatrix()
        bgl.glMatrixMode(bgl.GL_PROJECTION)
        bgl.glPopAttrib()
예제 #17
0
def draw_ephestos(self,context):
    global show_world
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
    bgl.glLineWidth(1.5)

    """
    #set colour to use
    bgl.glColor4f(0.5,0.0,0.5,0.3)

    x_region = round((bpy.context.area.regions[4].width-5)/2)
    y_region = round((bpy.context.area.regions[4].height-5)/2)
    print("x_region : ",x_region)
    print("y_region : ",y_region)
    bgl.glRecti(5,5,x_region, y_region)
    """
#    if show_world:
    world.draw()
    '''
    good_rounded_box.draw_new(ephestos)
    world.draw_new(ephestos)
#        show_world = False
    red_morph.draw_new(ephestos)
    green_morph.draw_new(ephestos)
    blue_morph.draw_new(ephestos)
    multiline_text.draw_new(ephestos)
    rounded_box.draw_new(ephestos)
    one_String.draw_new(ephestos)
#PKHG.stringfieldTest.???
    test_stringfield.draw_new( ephestos)
    '''
    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #18
0
    def draw(self, context, render=False):
        """
            render flag when rendering
        """

        # print("draw_line %s" % (type(self).__name__))
        bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
        if self.style == bgl.GL_LINE_STIPPLE:
            bgl.glLineStipple(1, 0x9999)
        bgl.glEnable(self.style)
        bgl.glEnable(bgl.GL_BLEND)
        if render:
            # enable anti-alias on lines
            bgl.glEnable(bgl.GL_LINE_SMOOTH)
        bgl.glColor4f(*self.colour)
        bgl.glLineWidth(self.width)
        if self.closed:
            bgl.glBegin(bgl.GL_LINE_LOOP)
        else:
            bgl.glBegin(bgl.GL_LINE_STRIP)

        for pt in self.pts:
            x, y = self.position_2d_from_coord(context, pt, render)
            bgl.glVertex2f(x, y)
        self._end()
def draw_channel_color(scroller_width, channel_coords, curx, color):
    from bgl import glColor4f, glRectf, glEnable, glDisable, glBlendFunc, GL_BLEND, GL_ONE, GL_SRC_ALPHA

    context = bpy.context

    # Strip coords
    s_x1, s_y1, s_x2, s_y2 = channel_coords

    # Drawing coords
    x = 0
    d_y1 = s_y1
    d_y2 = s_y2
    d_x1 = s_x1
    d_x2 = s_x2

    # be careful not to override the current frame line
    cf_x = context.scene.frame_current_final
    y = 0

    r, g, b, a = color
    glColor4f(r, g, b, a)
    glEnable(GL_BLEND)
    # glBlendFunc(GL_SRC_ALPHA, GL_ONE);

    if d_x1 < cf_x and cf_x < d_x2:
        # current frame line over strip
        glRectf(d_x1, d_y1, cf_x - curx, d_y2)
        glRectf(cf_x + curx, d_y1, d_x2, d_y2)
    else:
        # Normal, full rectangle draw
        glRectf(d_x1, d_y1, d_x2, d_y2)

    glDisable(GL_BLEND)
예제 #20
0
 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  
예제 #21
0
    def draw_index(rgb, rgb2, index, vec, text=''):

        vec_4d = perspective_matrix * vec.to_4d()
        if vec_4d.w <= 0.0:
            return

        x = region_mid_width + region_mid_width * (vec_4d.x / vec_4d.w)
        y = region_mid_height + region_mid_height * (vec_4d.y / vec_4d.w)
        if text:
            index = str(text[0])
        else:
            index = str(index)

        if draw_bg:
            polyline = get_points(index)

            ''' draw polygon '''
            bgl.glColor4f(*rgb2)
            bgl.glBegin(bgl.GL_POLYGON)
            for pointx, pointy in polyline:
                bgl.glVertex2f(pointx+x, pointy+y)
            bgl.glEnd()

        ''' draw text '''
        txt_width, txt_height = blf.dimensions(0, index)
        bgl.glColor4f(*rgb)
        blf.position(0, x - (txt_width / 2), y - (txt_height / 2), 0)
        blf.draw(0, index)
예제 #22
0
def draw_normal(context, vertexloc, vertexnorm, objscale, is_selected = True):
    # draw normals in object mode
    obj = context.active_object
    color1, thick1 = (0.5, 1.0, 1.0, 1.0), 3

    # input in localspace
    vertexloc = copy.copy(vertexloc)
    vertexloc.resize_4d()
    obmat = obj.matrix_world
    r1 = obmat*vertexloc
    r1.resize_3d()
    del vertexloc
    r2 = obj.rotation_euler.to_matrix() * mathutils.Vector(vertexnorm)
    r2 = r2* objscale
    r2 = r2* context.scene.tool_settings.normal_size + r1

    bgl.glEnable(bgl.GL_BLEND)

    bgl.glLineWidth(thick1)
    # set colour
    bgl.glColor4f(*color1)
    # draw line
    bgl.glBegin(bgl.GL_LINES)

    bgl.glVertex3f(r1.x,r1.y,r1.z)
    bgl.glVertex3f(r2.x,r2.y,r2.z)

    bgl.glEnd()
    bgl.glDisable(bgl.GL_BLEND)
예제 #23
0
def drawText2D(color, text):
    font_id = 0  # XXX, need to find out how best to get this.
    # draw some text
    bgl.glColor4f(*color)
    blf.position(font_id, 20, 70, 0)
    blf.size(font_id, 20, 72)
    blf.draw(font_id, text)
예제 #24
0
 def __exit__(self, type, value, traceback):
     bgl.glEnd()
     # restore opengl defaults
     bgl.glLineWidth(1)
     bgl.glDisable(bgl.GL_BLEND)
     bgl.glEnable(bgl.GL_DEPTH_TEST)
     bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #25
0
def draw_callback_px(self, context):
    print("mouse points", len(self.mouse_path))

    font_id = 0  # XXX, need to find out how best to get this.

    # draw some text
    blf.position(font_id, 15, 30, 0)
    blf.size(font_id, 20, 72)
    blf.draw(font_id, "Hello Word " + str(len(self.mouse_path)))

    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
    bgl.glLineWidth(2)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    for x, y in self.mouse_path:
        bgl.glVertex2i(x, y)

    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #26
0
파일: putil.py 프로젝트: jdpillon/pgui
def h_draw_gradient_rect(bounds, gradient, border_width=1, border_radius=0, border_color=(0, 0, 0, 1), wire=False):
    if len(gradient.colors) != len(gradient.offsets): return
    
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    
    h_mask_begin(bounds, border_radius)
    
    mode = bgl.GL_LINE_STRIP if wire else bgl.GL_TRIANGLE_STRIP
    
    bgl.glBegin(mode)
    if gradient.orientation == 0: # HOR
        for i in range(len(gradient.colors)):
            bgl.glColor4f(*gradient.colors[i])
            x = (bounds[2] * clamp(gradient.offsets[i], 0.0, 1.0)) + bounds[0]
            bgl.glVertex2f(x, bounds[1])
            bgl.glVertex2f(x, bounds[1]+bounds[3])
    elif gradient.orientation == 1: # VER
        for i in range(len(gradient.colors)):
            bgl.glColor4f(*gradient.colors[i])
            y = (bounds[3] * clamp(gradient.offsets[i], 0.0, 1.0)) + bounds[1]
            bgl.glVertex2f(bounds[0], y)
            bgl.glVertex2f(bounds[0]+bounds[2], y)
    bgl.glEnd()
        
    h_mask_end()
    
    if border_width > 0:
        h_round_rect_wire(bounds, border_radius, color=border_color, width=border_width)
    
    bgl.glDisable(bgl.GL_BLEND)
예제 #27
0
 def draw(self, context, render=False):
     if self.image is None:
         return
     bgl.glPushAttrib(bgl.GL_ENABLE_BIT)
     p0 = self.pts[0]
     p1 = self.pts[1]
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glColor4f(*self.colour)
     bgl.glRectf(p0.x, p0.y, p1.x, p1.y)
     self.image.gl_load()
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.image.bindcode[0])
     bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_NEAREST)
     bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_NEAREST)
     bgl.glEnable(bgl.GL_TEXTURE_2D)
     bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
     # bgl.glColor4f(1, 1, 1, 1)
     bgl.glBegin(bgl.GL_QUADS)
     bgl.glTexCoord2d(0, 0)
     bgl.glVertex2d(p0.x, p0.y)
     bgl.glTexCoord2d(0, 1)
     bgl.glVertex2d(p0.x, p1.y)
     bgl.glTexCoord2d(1, 1)
     bgl.glVertex2d(p1.x, p1.y)
     bgl.glTexCoord2d(1, 0)
     bgl.glVertex2d(p1.x, p0.y)
     bgl.glEnd()
     self.image.gl_free()
     bgl.glDisable(bgl.GL_TEXTURE_2D)
예제 #28
0
def write():
    """write on screen"""
    # retrieve timer
    global game_timer
    scene = logic.getCurrentScene()
    game_timer = int(active_camera["Timer"])
    catched = bamboo_counter["catched"]
    total = bamboo_counter["total"]
    vortex = panda.power
    width = render.getWindowWidth()
    height = render.getWindowHeight()

    # OpenGL setup
    bgl.glMatrixMode(bgl.GL_PROJECTION)
    bgl.glLoadIdentity()
    bgl.gluOrtho2D(0, width, 0, height)
    bgl.glMatrixMode(bgl.GL_MODELVIEW)
    bgl.glLoadIdentity()
    
    bgl.glColor4f(1, 1, 1, 1)
    
    # BLF drawing routine
    font_id = logic.font_id
    blf.size(font_id, int(18 * (width/dpi) * 0.06), dpi)
    blf.position(font_id, width*0.02, height*0.95, 0)
    if game_timer < 60:
        blf.draw(font_id, "{0} : {1:02d}".format(l_timer,game_timer))
    else:
        blf.draw(font_id, "{0} : {1}:{2:02d}".format(l_timer,game_timer//60,game_timer%60))
    blf.position(font_id, width*0.02, height*0.90, 0)
    blf.draw(font_id, "{0} : {1}".format(l_level, level))
    blf.position(font_id, width*0.02, height*0.85, 0)
    blf.draw(font_id, "{0} : {1} / {2}".format(l_score, catched, total))
    blf.position(font_id, width*0.02, height*0.80, 0)
    blf.draw(font_id, "{0} : {1}".format(l_vortex, vortex))
예제 #29
0
def draw_callback(self, context):

    scene = context.scene
    x = int(round(context.region.width * 0.01 + (self._t_target - scene.frame_start) * self._ppf))
    string = str(self._t_target)
    string = string[0 : string.index(".") + 3]
    font_id = 0  # XXX, need to find out how best to get this.

    # draw marker
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1, 0, 0, 1)
    bgl.glLineWidth(2)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex2i(x, 17)
    bgl.glVertex2i(x, context.region.height)
    bgl.glEnd()

    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)

    # draw frame number
    if self._show_frame_indicator:
        blf.position(font_id, x + 5, 21, 0)
        blf.size(font_id, 12, 72)
        blf.draw(font_id, string)
예제 #30
0
def DRAW_RunResize(self, context):

    # Restore opengl defaults
    bgl.glDisable(bgl.GL_POINTS)
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #31
0
def draw_polyline_from_coordinates(context,
                                   points,
                                   width,
                                   LINE_TYPE='GL_LINE_STRIP',
                                   color=(1, 1, 1, 1)):
    region = context.region
    rv3d = context.space_data.region_3d

    bgl.glColor4f(*color)
    bgl.glLineWidth(width)
    if LINE_TYPE == "GL_LINE_STIPPLE":
        bgl.glLineStipple(4, 0x5555)
        bgl.glEnable(bgl.GL_LINE_STIPPLE)

    bgl.glBegin(bgl.GL_LINE_STRIP)
    for coord in points:
        vector3d = (coord.x, coord.y, coord.z)
        vector2d = view3d_utils.location_3d_to_region_2d(
            region, rv3d, vector3d)
        bgl.glVertex2f(*vector2d)
    bgl.glEnd()
    bgl.glLineWidth(1)

    return
예제 #32
0
    def _draw_exception(self, context):
        """OpenGL drawing code for the EXCEPTION state."""

        import textwrap

        content_height, content_width = self._window_size(context)

        bgl.glEnable(bgl.GL_BLEND)
        bgl.glColor4f(0.2, 0.0, 0.0, 0.6)
        bgl.glRectf(0, 0, content_width, content_height)

        font_id = 0
        ex = self.async_task.exception()
        if isinstance(ex, pillar.UserNotLoggedInError):
            ex_msg = 'You are not logged in on Blender ID. Please log in at User Preferences, ' \
                     'System, Blender ID.'
        else:
            ex_msg = str(ex)
            if not ex_msg:
                ex_msg = str(type(ex))
        text = "An error occurred:\n%s" % ex_msg
        lines = textwrap.wrap(text)

        bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
        blf.size(font_id, 20, 72)
        _, text_height = blf.dimensions(font_id, 'yhBp')

        def position(line_nr):
            blf.position(font_id,
                         content_width * 0.1,
                         content_height * 0.8 - line_nr * text_height, 0)

        for line_idx, line in enumerate(lines):
            position(line_idx)
            blf.draw(font_id, line)
        bgl.glDisable(bgl.GL_BLEND)
예제 #33
0
def drawText(context, text, location):
    v3d = context.space_data;
    rv3d = v3d.region_3d;
    text_scale = TEXT_SCALE_VALUE * ((max(min(MAX_ZOOM_DISTANCE, rv3d.view_distance), MIN_ZOOM_DISTANCE)) / FRIENDLY_ZOOM_DISTANCE);
#     print("RV3D PARAMETERS ::: " , rv3d.view_location, rv3d.view_distance);
#     print('TEXT SCALE USED :::: ', text_scale);
    
    
    font_id = 0;
    
    axis, angle = getScreenLookAxis(context);
    
    bgl.glPushMatrix();
    bgl.glTranslatef(location.x, location.y , location.z);
    
    bgl.glPushMatrix();
    bgl.glRotatef(angle, axis.x, axis.y, axis.z);
    
    bgl.glPushMatrix();
    bgl.glScalef(text_scale,text_scale,text_scale);
    
    bgl.glPushMatrix();
    bgl.glRotatef(90.0, 1.0, 0.0, 0.0);
    
    blf.position(font_id, 0.0, 0.0 , 0.0);
    blf.size(font_id, 72, 72);
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0);
    blf.draw(0, text);
#     blf.rotation(0, 1.57);
    bgl.glPopMatrix();
    
    bgl.glPopMatrix();
    
    bgl.glPopMatrix();
    
    bgl.glPopMatrix();
예제 #34
0
    def draw_texture(self, context):
        sc = context.scene

        # no textures are selected
        if sc.muv_texproj_tex_image == "None":
            return

        # setup rendering region
        rect = get_canvas(context, sc.muv_texproj_tex_magnitude)
        positions = [[rect.x0, rect.y0], [rect.x0, rect.y1],
                     [rect.x1, rect.y1], [rect.x1, rect.y0]]
        tex_coords = [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]]

        # get texture to be renderred
        img = bpy.data.images[sc.muv_texproj_tex_image]

        # OpenGL configuration
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glEnable(bgl.GL_TEXTURE_2D)
        if img.bindcode:
            bind = img.bindcode
            bgl.glBindTexture(bgl.GL_TEXTURE_2D, bind)
            bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER,
                                bgl.GL_LINEAR)
            bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER,
                                bgl.GL_LINEAR)
            bgl.glTexEnvi(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE,
                          bgl.GL_MODULATE)

        # render texture
        bgl.glBegin(bgl.GL_QUADS)
        bgl.glColor4f(1.0, 1.0, 1.0, sc.muv_texproj_tex_transparency)
        for (v1, v2), (u, v) in zip(positions, tex_coords):
            bgl.glTexCoord2f(u, v)
            bgl.glVertex2f(v1, v2)
        bgl.glEnd()
예제 #35
0
def draw_main(context):
    region = bpy.context.region
    rv3d = bpy.context.space_data.region_3d
    scene = bpy.context.scene
    # Get visible layers
    layers = []
    for x in range(0, 20):
        if bpy.context.scene.layers[x] is True:
            layers.extend([x])

    bgl.glEnable(bgl.GL_BLEND)
    # Display selected or all
    if scene.measureit_gl_ghost is False:
        objlist = context.selected_objects
    else:
        objlist = context.scene.objects
    # ---------------------------------------
    # Generate all OpenGL calls
    # ---------------------------------------
    for myobj in objlist:
        if myobj.hide is False:
            if 'MeasureGenerator' in myobj:
                # verify visible layer
                for x in range(0, 20):
                    if myobj.layers[x] is True:
                        if x in layers:
                            op = myobj.MeasureGenerator[0]
                            draw_segments(context, myobj, op, region, rv3d)
                        break

    # -----------------------
    # restore opengl defaults
    # -----------------------
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #36
0
def draw_callback_px(self, context):

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
    bgl.glLineWidth(2)

    if self.selecting:
        # when selecting draw dashed line box
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
        bgl.glLineStipple(2, 0x3333)
        bgl.glBegin(bgl.GL_LINE_LOOP)

        bgl.glVertex2i(self.min_x, self.min_y)
        bgl.glVertex2i(self.min_x, self.max_y)
        bgl.glVertex2i(self.max_x, self.max_y)
        bgl.glVertex2i(self.max_x, self.min_y)

        bgl.glEnd()

        bgl.glDisable(bgl.GL_LINE_STIPPLE)
    else:
        # before selection starts draw infinite cross
        bgl.glBegin(bgl.GL_LINES)

        bgl.glVertex2i(0, self.max_y)
        bgl.glVertex2i(context.area.width, self.max_y)

        bgl.glVertex2i(self.max_x, 0)
        bgl.glVertex2i(self.max_x, context.area.height)

        bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #37
0
    def draw_callback_3d(self, context):
        global particle_vertices
        global particle_vertex_colors

        domain = context.scene.flip_fluid.get_domain_object()
        dprops = context.scene.flip_fluid.get_domain_properties()
        if domain is None or len(particle_vertices) == 0:
            return

        if vcu.get_object_hide_viewport(domain):
            return

        if not vcu.is_blender_28():
            dlayers = [i for i,v in enumerate(domain.layers) if v]
            slayers = [i for i,v in enumerate(context.scene.layers) if v]
            if not (set(dlayers) & set(slayers)):
                return

        if vcu.is_blender_28():
            global particle_shader
            global particle_batch_draw
            particle_batch_draw.draw(particle_shader)
        else:
            bgl.glPointSize(dprops.debug.particle_size)
            bgl.glBegin(bgl.GL_POINTS)

            current_color = None
            for i in range(len(particle_vertices)):
                if current_color != particle_vertex_colors[i]:
                    current_color = particle_vertex_colors[i]
                    bgl.glColor4f(current_color[0], current_color[1], current_color[2], 1.0)
                bgl.glVertex3f(*(particle_vertices[i]))

            bgl.glEnd()
            bgl.glPointSize(1)
            bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_3d_points(context, points, color, size):
    '''
    draw a bunch of dots
    args:
        points: a list of tuples representing x,y SCREEN coordinate eg [(10,30),(11,31),...]
        color: tuple (r,g,b,a)
        size: integer? maybe a float
    '''
    points_2d = [
        location_3d_to_region_2d(context.region, context.space_data.region_3d,
                                 loc) for loc in points
    ]
    if None in points_2d:
        points_2d = filter(None, points_2d)
    bgl.glColor4f(*color)
    bgl.glPointSize(size)
    bgl.glBegin(bgl.GL_POINTS)
    for coord in points_2d:
        #TODO:  Debug this problem....perhaps loc_3d is returning points off of the screen.
        if coord:
            bgl.glVertex2f(*coord)

    bgl.glEnd()
    return
예제 #39
0
파일: overlay.py 프로젝트: huggaida/scripts
def _draw_line(space, text, size, r, g, b, a):
    ctx = bpy.context
    blf.size(0, size, 72)
    w, h = blf.dimensions(0, text)

    global _line_y

    if "LEFT" in space.alignment:
        x = space.offset
    elif "RIGHT" in space.alignment:
        x = ctx.region.width - w - space.offset
    else:
        x = 0.5 * ctx.region.width - 0.5 * w

    if "TOP" in space.alignment:
        _line_y += size + 3
        y = ctx.region.height - _line_y - space.offset
    else:
        y = _line_y + space.offset
        _line_y += size + 3

    blf.position(0, x, y, 0)
    bgl.glColor4f(r, g, b, a)
    blf.draw(0, text)
예제 #40
0
파일: display.py 프로젝트: yarrrtem/phobos
def draw_2dpolygon(points,
                   linecolor=None,
                   fillcolor=None,
                   distance=0.2,
                   linewidth=1):
    """

    Args:
      points: 
      linecolor: (Default value = None)
      fillcolor: (Default value = None)
      distance: (Default value = 0.2)
      linewidth: (Default value = 1)

    Returns:

    """
    # background
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(linewidth)
    if fillcolor:
        bgl.glColor4f(*fillcolor)
        bgl.glBegin(bgl.GL_POLYGON)
        for p in points:
            bgl.glVertex3f(*p, distance)
        bgl.glEnd()
    # frame
    if linecolor:
        bgl.glColor4f(*linecolor)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for p in points:
            bgl.glVertex3f(*p, distance)
        bgl.glVertex3f(*points[0], distance)
        bgl.glEnd()
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
예제 #41
0
def draw_callback_px(self, context):
    if (self.ShowCursor):
        region = bpy.context.region
        rv3d = bpy.context.space_data.region_3d
        view_width = context.region.width
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glLineWidth(2)
        bgl.glColor4f(1.0, 0.8, 0.0, 1.0)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        idx = 0
        for i in range(int(len(self.CLR_C) / 3)):
            vector3d = (self.CLR_C[idx * 3] * self.CRadius + self.CurLoc.x,
                        self.CLR_C[idx * 3 + 1] * self.CRadius + self.CurLoc.y,
                        self.CLR_C[idx * 3 + 2] * self.CRadius + self.CurLoc.z)
            vector2d = bpy_extras.view3d_utils.location_3d_to_region_2d(
                region, rv3d, vector3d)
            bgl.glVertex2f(*vector2d)
            idx += 1
        bgl.glEnd()
        bgl.glBegin(bgl.GL_LINE_STRIP)
        idx = 0
        for i in range(int(len(self.CLR_C) / 3)):
            vector3d = (self.CLR_C[idx * 3] * self.CRadius / 3.0 +
                        self.CurLoc.x,
                        self.CLR_C[idx * 3 + 1] * self.CRadius / 3.0 +
                        self.CurLoc.y,
                        self.CLR_C[idx * 3 + 2] * self.CRadius / 3.0 +
                        self.CurLoc.z)
            vector2d = bpy_extras.view3d_utils.location_3d_to_region_2d(
                region, rv3d, vector3d)
            bgl.glVertex2f(*vector2d)
            idx += 1
        bgl.glEnd()
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #42
0
    def draw(self, highlighted: bool):
        bgl.glEnable(bgl.GL_BLEND)
        if highlighted:
            bgl.glColor4f(0.555, 0.555, 0.555, 0.8)
        else:
            bgl.glColor4f(0.447, 0.447, 0.447, 0.8)

        bgl.glRectf(self.x, self.y, self.x + self.width, self.y + self.height)

        texture = self.icon
        err = texture.gl_load(filter=bgl.GL_NEAREST, mag=bgl.GL_NEAREST)
        assert not err, 'OpenGL error: %i' % err

        bgl.glColor4f(0.0, 0.0, 1.0, 0.5)
        # bgl.glLineWidth(1.5)

        # ------ TEXTURE ---------#
        bgl.glBindTexture(bgl.GL_TEXTURE_2D, texture.bindcode[0])
        bgl.glEnable(bgl.GL_TEXTURE_2D)
        bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)

        bgl.glColor4f(1, 1, 1, 1)
        bgl.glBegin(bgl.GL_QUADS)
        bgl.glTexCoord2d(0, 0)
        bgl.glVertex2d(self.x + self.icon_margin_x, self.y)
        bgl.glTexCoord2d(0, 1)
        bgl.glVertex2d(self.x + self.icon_margin_x, self.y + ICON_HEIGHT)
        bgl.glTexCoord2d(1, 1)
        bgl.glVertex2d(self.x + self.icon_margin_x + ICON_WIDTH,
                       self.y + ICON_HEIGHT)
        bgl.glTexCoord2d(1, 0)
        bgl.glVertex2d(self.x + self.icon_margin_x + ICON_WIDTH, self.y)
        bgl.glEnd()
        bgl.glDisable(bgl.GL_TEXTURE_2D)
        bgl.glDisable(bgl.GL_BLEND)

        texture.gl_free()

        # draw some text
        font_id = 0
        blf.position(
            font_id,
            self.x + self.icon_margin_x + ICON_WIDTH + self.text_margin_x,
            self.y + ICON_HEIGHT * 0.5 - 0.25 * self.text_height, 0)
        blf.size(font_id, self.text_height, self.text_width)
        blf.draw(font_id, self.label_text)
예제 #43
0
    def draw_brush(cls, obj, context):
        sc = context.scene
        user_prefs = compat.get_user_preferences(context)
        prefs = user_prefs.addons["magic_uv"].preferences

        num_segment = 180
        theta = 2 * pi / num_segment
        fact_t = tan(theta)
        fact_r = cos(theta)
        color = prefs.uv_sculpt_brush_color

        bgl.glBegin(bgl.GL_LINE_STRIP)
        bgl.glColor4f(color[0], color[1], color[2], color[3])
        x = sc.muv_uv_sculpt_radius * cos(0.0)
        y = sc.muv_uv_sculpt_radius * sin(0.0)
        for _ in range(num_segment):
            bgl.glVertex2f(x + obj.current_mco.x, y + obj.current_mco.y)
            tx = -y
            ty = x
            x = x + tx * fact_t
            y = y + ty * fact_t
            x = x * fact_r
            y = y * fact_r
        bgl.glEnd()
예제 #44
0
    def draw_callback(self):
        # 50% alpha, 2 pixel width line
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glColor4f(1.0, 0.0, 0.0, 0.7)
        bgl.glLineWidth(2)

        # Draw POST cell to end
        for loc in self.post_cells_locs:
            bgl.glBegin(bgl.GL_LINES)  # bgl.GL_LINE_STRIP for
            bgl.glVertex3f(*self.axon_end_pt)
            bgl.glVertex3f(*loc)
            bgl.glEnd()

        # Draw PRE cell to start
        for loc in self.pre_cells_locs:
            bgl.glBegin(bgl.GL_LINES)  # bgl.GL_LINE_STRIP for
            bgl.glVertex3f(*self.axon_start_pt)
            bgl.glVertex3f(*loc)
            bgl.glEnd()

        # restore opengl defaults
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #45
0
    def draw_image(self, image, x, y, w, h, color=(0, 0, 0, 0.1)):
        bgl.glColor4f(0.5, 0.0, 0.5, 0.7)

        # draw main line and handles
        # bgl.glBegin(bgl.GL_LINES)
        bgl.glRectf(x, y, x+w, y+h)
        # bgl.glEnd()
        x1 = x
        y1 = y
        x2 = x + w
        y2 = y + h
        color = [0.5, 0.5, 0.5, 1]

        idx = image.gl_load(bgl.GL_NEAREST, bgl.GL_NEAREST)
        print([i for i in image.bindcode])

        bgl.glBindTexture(bgl.GL_TEXTURE_2D, image.bindcode[0])
        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_NEAREST)

        bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_NEAREST)
        bgl.glEnable(bgl.GL_TEXTURE_2D)
        bgl.glEnable(bgl.GL_BLEND)
        #bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
        bgl.glColor4f(color[0], color[1], color[2], color[3])
        bgl.glBegin(bgl.GL_QUADS)
        bgl.glTexCoord2f(0, 0)
        bgl.glVertex2f(x1, y1)
        bgl.glTexCoord2f(0, 1)
        bgl.glVertex2f(x1, y2)
        bgl.glTexCoord2f(1, 1)
        bgl.glVertex2f(x2, y2)
        bgl.glTexCoord2f(1, 0)
        bgl.glVertex2f(x2, y1)
        bgl.glEnd()
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glDisable(bgl.GL_TEXTURE_2D)
예제 #46
0
def draw_points(context, points, size, gl_col):
    region = context.region
    rv3d = context.space_data.region_3d
    
    this_object = context.active_object
    matrix_world = this_object.matrix_world  
    
    # needed for adjusting the size of gl_points    
    bgl.glEnable(bgl.GL_POINT_SMOOTH)
    bgl.glPointSize(size)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    
    bgl.glBegin(bgl.GL_POINTS)
    bgl.glColor4f(*gl_col)    
    for coord in points:
        # vector3d = matrix_world * (coord.x, coord.y, coord.z)
        vector3d = matrix_world * coord
        vector2d = loc3d2d(region, rv3d, vector3d)
        bgl.glVertex2f(*vector2d)
    bgl.glEnd()
    
    bgl.glDisable(bgl.GL_POINT_SMOOTH)
    bgl.glDisable(bgl.GL_POINTS)
    return
예제 #47
0
def image_quad(img, color, verts):
    img.gl_load(bgl.GL_NEAREST, bgl.GL_NEAREST)
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, img.bindcode)
    bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER,
                        bgl.GL_NEAREST)
    bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER,
                        bgl.GL_NEAREST)
    bgl.glEnable(bgl.GL_TEXTURE_2D)
    bgl.glEnable(bgl.GL_BLEND)
    #bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
    bgl.glColor4f(color[0], color[1], color[2], color[3])
    bgl.glBegin(bgl.GL_QUADS)
    #http://h30097.www3.hp.com/docs/base_doc/DOCUMENTATION/V51B_HTML/MAN/MAN3/2025____.HTM
    bgl.glTexCoord2f(0, 0)
    bgl.glVertex2f(verts[0][0], verts[0][1])
    bgl.glTexCoord2f(0, 1)
    bgl.glVertex2f(verts[1][0], verts[1][1])
    bgl.glTexCoord2f(1, 1)
    bgl.glVertex2f(verts[2][0], verts[2][1])
    bgl.glTexCoord2f(1, 0)
    bgl.glVertex2f(verts[3][0], verts[3][1])
    bgl.glEnd()
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glDisable(bgl.GL_TEXTURE_2D)
예제 #48
0
    def draw_VIEW3D(self, args):
        if self.stash.obj:
            mesh = self.stash.obj.data

            # NOTE you can also draw quads, perhaps even ngons:
            # https://blender.stackexchange.com/questions/71980/modal-operator-to-highlight

            # offset amount depends on size of active object
            offset = sum([d for d in self.active.dimensions]) / 3 * 0.001

            edgewidth = 2
            edgecolor = (1.0, 1.0, 1.0, 0.75)

            bgl.glEnable(bgl.GL_BLEND)

            if self.xray:
                bgl.glDisable(bgl.GL_DEPTH_TEST)

            for edge in mesh.edges:
                v1 = mesh.vertices[edge.vertices[0]]
                v2 = mesh.vertices[edge.vertices[1]]

                # bring the coordinates into world space
                # and push them out abit so they are drawn on top of the mesh
                v1co = v1.co + v1.normal * offset + self.active.location
                v2co = v2.co + v2.normal * offset + self.active.location

                bgl.glLineWidth(edgewidth)
                bgl.glColor4f(*edgecolor)

                bgl.glBegin(bgl.GL_LINES)

                bgl.glVertex3f(*v1co)
                bgl.glVertex3f(*v2co)

            draw_end()
예제 #49
0
    def textbox_draw2D(self,
                       text,
                       pos: Point2D,
                       padding=5,
                       textbox_position=7,
                       fontid=None):
        '''
        textbox_position specifies where the textbox is drawn in relation to pos.
        ex: if textbox_position==7, then the textbox is drawn where pos is the upper-left corner
        tip: textbox_position is arranged same as numpad
                    +-----+
                    |7 8 9|
                    |4 5 6|
                    |1 2 3|
                    +-----+
        '''
        lh = self.line_height

        # TODO: wrap text!
        lines = text.splitlines()
        w = max(self.get_text_width(line) for line in lines)
        h = len(lines) * lh

        # find top-left corner (adjusting for textbox_position)
        l, t = round(pos[0]), round(pos[1])
        textbox_position -= 1
        lcr = textbox_position % 3
        tmb = int(textbox_position / 3)
        l += [w + padding, round(w / 2), -padding][lcr]
        t += [h + padding, round(h / 2), -padding][tmb]

        bgl.glEnable(bgl.GL_BLEND)

        bgl.glColor4f(0.0, 0.0, 0.0, 0.25)
        bgl.glBegin(bgl.GL_QUADS)
        bgl.glVertex2f(l + w + padding, t + padding)
        bgl.glVertex2f(l - padding, t + padding)
        bgl.glVertex2f(l - padding, t - h - padding)
        bgl.glVertex2f(l + w + padding, t - h - padding)
        bgl.glEnd()

        bgl.glColor4f(0.0, 0.0, 0.0, 0.75)
        self.drawing.line_width(1.0)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        bgl.glVertex2f(l + w + padding, t + padding)
        bgl.glVertex2f(l - padding, t + padding)
        bgl.glVertex2f(l - padding, t - h - padding)
        bgl.glVertex2f(l + w + padding, t - h - padding)
        bgl.glVertex2f(l + w + padding, t + padding)
        bgl.glEnd()

        bgl.glColor4f(1, 1, 1, 0.5)
        for i, line in enumerate(lines):
            th = self.get_text_height(line)
            y = t - (i + 1) * lh + int((lh - th) / 2)
            fm.draw(line, xyz=(l, y, 0), fontid=fontid)
예제 #50
0
def draw_callback_px(self, context):
    bgl.glPushAttrib(bgl.GL_CLIENT_ALL_ATTRIB_BITS)

    FONT_RGBA = (0.8, 0.1, 0.1, 0.5)
    bgl.glColor4f(*FONT_RGBA)

    font_size = 11
    DPI = 72

    blf.size(0, font_size, DPI)
    msg = "Head Camera on..."

    msg_w, msg_h = blf.dimensions(0, msg)

    pos_x = context.region.width - msg_w
    pos_y = font_size / 2
    blf.position(0, pos_x, pos_y, 0)
    #blf.position(0, 10, 10, 0)

    blf.draw(0, msg)

    bgl.glPopAttrib()

    pass
예제 #51
0
def draw_2dpolygon(points,
                   linecolor=None,
                   fillcolor=None,
                   distance=0.2,
                   linewidth=1):
    # background
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(linewidth)
    if fillcolor:
        bgl.glColor4f(*fillcolor)
        bgl.glBegin(bgl.GL_POLYGON)
        for p in points:
            bgl.glVertex3f(*p, distance)
        bgl.glEnd()
    # frame
    if linecolor:
        bgl.glColor4f(*linecolor)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for p in points:
            bgl.glVertex3f(*p, distance)
        bgl.glVertex3f(*points[0], distance)
        bgl.glEnd()
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
예제 #52
0
    def draw_HUD(self, args):
        draw_init(self, args)

        # alpha = 0.5
        alpha = self.countdown / self.time
        title = "Draw Timer"
        subtitle = "%.*fs" % (1, self.countdown)
        subtitleoffset = 200

        HUDcolor = m3.MM_prefs().modal_hud_color
        bgl.glColor4f(*HUDcolor, alpha)

        blf.position(self.font_id, self.HUDx - 7, self.HUDy, 0)
        blf.size(self.font_id, 20, 72)
        blf.draw(self.font_id, "» " + title)

        if subtitle:
            bgl.glColor4f(*HUDcolor, 0.25)
            blf.position(self.font_id, self.HUDx - 7 + subtitleoffset,
                         self.HUDy, 0)
            blf.size(self.font_id, 15, 72)
            blf.draw(self.font_id, subtitle)

        draw_end()
예제 #53
0
def img_editor_draw_callback_px(self, context):

    # draw text
    draw_typo_2d((1.0, 1.0, 1.0, 1), "Image Editor Window")
    
    #draw the user clicked points on the image
    bgl.glPointSize(5)
    bgl.glBegin(bgl.GL_POINTS)
    bgl.glColor4f(0.8, 0.2, 0.5, 1.0)
    for pix in self.pixel_coords:
        img_x, img_y = pix[0], pix[1]
        img_size = self.imgeditor_area.spaces.active.image.size
        rx,ry = context.region.view2d.view_to_region(img_x/img_size[0], img_y/img_size[1], clip=True)
        
        if rx and ry:
            bgl.glVertex2f(rx, ry)
        
    bgl.glEnd()
    
    # restore opengl defaults
    bgl.glPointSize(1)
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #54
0
def draw_polyline_2d_loop(verts, faces, loops, color, contour, width):
    dpi = int(bpy.context.user_preferences.system.pixel_size)

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

    bgl.glColor4f(*color)
    for face in faces:
        bgl.glBegin(bgl.GL_POLYGON)
        for v_index in face:
            coord = verts[v_index]
            bgl.glVertex2f(coord[0], coord[1])
        bgl.glEnd()

    #antialiasing contour
    bgl.glColor4f(*color)
    bgl.glLineWidth(1)
    for loop in loops:
        if faces:
            bgl.glBegin(bgl.GL_LINE_LOOP)
        else:
            bgl.glBegin(bgl.GL_LINE_STRIP)
        for v_index in loop:
            coord = verts[v_index]
            bgl.glVertex2f(coord[0], coord[1])
        bgl.glEnd()

    if width:
        bgl.glLineWidth(width * dpi)
        bgl.glColor4f(*contour)

        for loop in loops:
            bgl.glBegin(bgl.GL_LINE_LOOP)
            for v_index in loop:
                coord = verts[v_index]
                bgl.glVertex2f(coord[0], coord[1])
            bgl.glEnd()

    bgl.glDisable(bgl.GL_BLEND)
    bgl.glDisable(bgl.GL_LINE_SMOOTH)
    bgl.glEnd()

    return
예제 #55
0
def draw_lw(context, lw, cross_up_dir, draw_faloff):
    region = context.region
    rv3d = context.region_data

    start_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, lw.start_point.position)
    end_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, lw.end_point.position)
    middle_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, lw.middle_point.position)

    dist_ends = ((lw.start_point.position - lw.end_point.position).length * 0.1) * cross_up_dir
    end_p1 = view3d_utils.location_3d_to_region_2d(region, rv3d, lw.end_point.position + dist_ends)
    end_p2 = view3d_utils.location_3d_to_region_2d(region, rv3d, lw.end_point.position - dist_ends)

    if start_2d and end_2d and end_p1 and end_p2:
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glLineWidth(1)
        bgl.glPointSize(6)

        bgl.glBegin(bgl.GL_LINE_STRIP)
        bgl.glColor4f(0.99, 0.5, 0.99, 1.0)
        bgl.glVertex2f(start_2d[0], start_2d[1])
        bgl.glVertex2f(end_2d[0], end_2d[1])
        bgl.glEnd()

        if draw_faloff:
            bgl.glBegin(bgl.GL_LINE_LOOP)
            bgl.glColor4f(0.99, 0.5, 0.99, 1.0)
            bgl.glVertex2f(start_2d[0], start_2d[1])
            bgl.glVertex2f(end_p1[0], end_p1[1])
            bgl.glVertex2f(end_p2[0], end_p2[1])
            bgl.glEnd()

        bgl.glBegin(bgl.GL_POINTS)
     #   bgl.glBegin(bgl.GL_POLYGON)
        bgl.glColor4f(0.99, 0.8, 0.5, 1.0)
        bgl.glVertex2f(start_2d[0], start_2d[1])
        bgl.glVertex2f(middle_2d[0], middle_2d[1])
        bgl.glVertex2f(end_2d[0], end_2d[1])
        bgl.glEnd()

        # restore opengl defaults
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
예제 #56
0
def draw_callback_wc_view(context):
    gta_tools = bpy.context.scene.gta_tools
    global wc_state
    if wc_state.check_suspend(): return

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glShadeModel(bgl.GL_SMOOTH)

    # Mark Active VG Position
    if gta_tools.weight_props.mark_bone:
        active_bone_pos = get_acive_bone()
        bgl.glPointSize(10.0)
        bgl.glBegin(bgl.GL_POINTS)
        bgl.glColor4f(1.0, 1.0, 1.0, 1.0)
        bgl.glVertex3f(*active_bone_pos)
        bgl.glEnd()

    # Show Weight Color
    if gta_tools.weight_props.weight_color or gta_tools.weight_props.mark_unweighted:
        #if ditect_update(): update_vw()  # maybe removed, later
        #wc_state.check_update()
        check_update()
        bgl.glPointSize(gta_tools.weight_props.weight_size)
        bgl.glBegin(bgl.GL_POINTS)
        for vw in wc_state.vws:
            if (gta_tools.weight_props.weight_calc_margin < vw[1]):
                if gta_tools.weight_props.weight_color:
                    bgl.glColor4f(*get_heat4f(
                        vw[1], gta_tools.weight_props.weight_alpha))
                    bgl.glVertex3f(*vw[0])
            elif gta_tools.weight_props.weight_calc_margin < -vw[1]:
                if gta_tools.weight_props.mark_unweighted:
                    bgl.glColor4f(1.0, 0.0, 1.0,
                                  gta_tools.weight_props.weight_alpha)
                    bgl.glVertex3f(*vw[0])
        bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    def drawSegment(x1, y1, x2, y2, future=False, limit=False):
        dx = x2 - x1
        dy = y2 - y1
        if max(abs(dx), abs(dy)) < 20:
            return

        if future:
            alpha = 0.2
        else:
            alpha = 0.5

        if abs(dx) >= abs(dy):
            xa = x1 + sgn(dx) * 10
            xb = x2 - sgn(dx) * 10
            ratio = dy / abs(dx)
            ya = y1 + 10 * ratio
            yb = y2 - 10 * ratio
        else:
            ya = y1 + sgn(dy) * 10
            yb = y2 - sgn(dy) * 10
            ratio = dx / abs(dy)
            xa = x1 + 10 * ratio
            xb = x2 - 10 * ratio

        #bgl.glLineWidth(2)
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
        bgl.glEnable(bgl.GL_BLEND)

        if limit:
            bgl.glColor4f(1.0, 0.0, 0.0, alpha)
        else:
            bgl.glColor4f(0.0, 0.0, 0.0, alpha)

        bgl.glLineStipple(1, 0x00FF)
        bgl.glBegin(bgl.GL_LINES)
        bgl.glVertex2f(xa, ya)
        bgl.glVertex2f(xb, yb)
        bgl.glEnd()

        bgl.glColor4f(1.0, 1.0, 1.0, alpha)

        bgl.glLineStipple(1, 0xFF00)
        bgl.glBegin(bgl.GL_LINES)
        bgl.glVertex2f(xa, ya)
        bgl.glVertex2f(xb, yb)
        bgl.glEnd()

        bgl.glLineStipple(1, 0xFFFF)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glDisable(bgl.GL_LINE_STIPPLE)
예제 #58
0
def draw_line_3d(color, start, end, width=1.0):

    transparent = (color[0], color[1], color[2], 0)
    center = (start + end) * 0.5

    bgl.glLineWidth(width)

    bgl.glBegin(bgl.GL_LINES)
    bgl.glColor4f(*transparent)
    bgl.glVertex3f(*start)

    bgl.glColor4f(*color)
    bgl.glVertex3f(*center)
    bgl.glEnd()

    bgl.glBegin(bgl.GL_LINES)
    bgl.glColor4f(*color)
    bgl.glVertex3f(*center)

    bgl.glColor4f(*transparent)
    bgl.glVertex3f(*end)
    bgl.glEnd()
def DynamicNodes_DrawCallBack(self, context):
    if context.scene.DynamicNodes_Properties.arrange_mode:
        return
    bgl.glColor4f(0.6, 0.6, 0.7, 1)
    font_id = 0
    blf.size(font_id, 12, 0)
    blf.position(font_id, 12, context.area.height - 48, 0)
    blf.enable(font_id, blf.SHADOW)
    blf.shadow(font_id, 3, 0, 0, 0, 1)
    blf.draw(font_id, 'Dynamic Nodes')

    if self.ghost:
        bgl.glEnable(bgl.GL_BLEND)
        for node in context.selected_nodes:
            if node.parent: continue
            if hasattr(node, 'shrink'): continue
            x1, y1 = v2r(node.location[0] - 10, node.location[1] + 10)
            x2, y2 = v2r(node.location[0] + node.dimensions[0] + 10,
                         node.location[1] - node.dimensions[1] - 10)

            bgl.glColor4f(0.5, 0.95, 1.0, 0.1)
            bgl.glBegin(bgl.GL_QUADS)
            bgl.glVertex2i(x1, y1)
            bgl.glVertex2i(x2, y1)
            bgl.glVertex2i(x2, y2)
            bgl.glVertex2i(x1, y2)
            bgl.glEnd()

            bgl.glColor4f(0.0, 0.4, 0.7, 1)
            bgl.glBegin(bgl.GL_LINE_STRIP)
            bgl.glVertex2i(x1, y1)
            bgl.glVertex2i(x2, y1)
            bgl.glVertex2i(x2, y2)
            bgl.glVertex2i(x1, y2)
            bgl.glVertex2i(x1, y1)
            bgl.glEnd()
        bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
    blf.disable(font_id, blf.SHADOW)
예제 #60
0
def draw_callback_px(context):
    # Note that the "context" passed in here is a regular dictionary and not the Blender context
    global screen_display_lines
    pid = None
    if 'mcell' in bpy.context.scene:
        mcell = bpy.context.scene.mcell
        if 'run_simulation' in mcell:
            rs = mcell.run_simulation
            if len(rs.processes_list) > 0:
                pid_str = rs.processes_list[rs.active_process_index].name
                pid = pid_str.split(',')[0].split()[1]

    bgl.glPushAttrib(bgl.GL_ENABLE_BIT)

    if parameter_dictionary['Clear']['val']:
        bgl.glClearColor(0.0, 0.0, 0.0, 1.0)
        bgl.glClear(bgl.GL_COLOR_BUFFER_BIT)

    font_id = 0  # XXX, need to find out how best to get this.

    y_pos = 15 * (scroll_offset + 1)
    if pid and (pid in screen_display_lines):
        for l in screen_display_lines[pid]:
            blf.position(font_id, 15, y_pos, 0)
            y_pos += 15
            blf.size(font_id, 14, 72)  # fontid, size, DPI
            bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
            blf.draw(font_id, l)
    else:
        keys = screen_display_lines.keys()
        for k in keys:
            for l in screen_display_lines[k]:
                blf.position(font_id, 15, y_pos, 0)
                y_pos += 15
                blf.size(font_id, 14, 72)  # fontid, size, DPI
                bgl.glColor4f(1.0, 1.0, 1.0, 0.5)
                blf.draw(font_id, l)

    # 100% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)

    bgl.glPopAttrib()

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