Beispiel #1
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()
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)
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)
    def draw_callback_px(self, context):
        if context.region.id != self.region_id:
            return
        posx = 70
        posy1 = 30
        posy2 = 50
        text_interval = 5
        font_id = 0
        blf.size(font_id, 11, context.user_preferences.system.dpi)
        bgl.glEnable(bgl.GL_BLEND)
        if self.changing_mgtype:
            bgl.glColor4f(1.0, 1.0, 0.0, 1.0)
        else:
            bgl.glColor4f(1.0, 1.0, 1.0, 1.0)

        # draw origin
        bgl.glLineWidth(2)
        radius = path_threthold
        radius2 = radius + 5
        x, y, z = self.path[0]
        bgl.glBegin(bgl.GL_LINES)
        for i in range(4):
            r = math.pi / 2 * i + math.pi / 4
            bgl.glVertex2f(x + radius * math.cos(r), y + radius * math.sin(r))
            bgl.glVertex2f(x + radius2 * math.cos(r),
                           y + radius2 * math.sin(r))
        bgl.glEnd()
        bgl.glLineWidth(1)

        # draw lines
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
        bgl.glLineStipple(1, int(0b101010101010101))  # (factor, pattern)
        bgl.glBegin(bgl.GL_LINE_STRIP)
        for v in self.path:
            bgl.glVertex2f(v[0], v[1])
        bgl.glEnd()
        bgl.glLineStipple(1, 1)
        bgl.glDisable(bgl.GL_LINE_STIPPLE)

        # draw txt
        if self.action or self.mgitem:
            x = posx
            for txt in self.action:
                blf.position(font_id, x, posy1, 0)
                blf.draw(font_id, txt)
                text_width, text_height = blf.dimensions(font_id, txt)
                x += text_width + text_interval
            if self.mgitem:
                blf.position(font_id, posx, posy2, 0)
                blf.draw(font_id, self.mgitem.name)
        else:
            #blf.position(font_id, posx, posy2, 0)
            #blf.draw(font_id, '[Mouse Gesture]')
            pass

        # restore opengl defaults
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
        blf.size(0, 11, context.user_preferences.system.dpi)
Beispiel #5
0
def draw_circle_select(m_coords, radius = 16, p_col = (0.7,0.8,1.0,0.6), enabled = False, sub = False):
    if(enabled):
        f_col = p_col
        if sub:
            f_col = (1.0, 0.5, 0.4, 0.6)
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glBegin(bgl.GL_POLYGON)
        bgl.glColor4f(f_col[0], f_col[1], f_col[2], f_col[3]/3)

        point_x = m_coords[0]
        point_y = m_coords[1]

        radius = int(radius)

        for x in range(0, radius*2):
            bgl.glVertex2f(point_x + radius * math.cos(x * (360/(radius*2)) / 180 * 3.14159), point_y + radius * math.sin(x * (360/(radius*2)) / 180 * 3.14159))
        bgl.glEnd()

        bgl.glBegin(bgl.GL_LINES)
        bgl.glColor4f(f_col[0], f_col[1], f_col[2], f_col[3])
        for x in range(0, radius*2):
            bgl.glVertex2f(point_x + radius * math.cos(x * (360 / (radius * 2)) / 180 * 3.14159),
                           point_y + radius * math.sin(x * (360 / (radius * 2)) / 180 * 3.14159))

        bgl.glEnd()
        # restore opengl defaults
        bgl.glLineWidth(1)
        bgl.glDisable(bgl.GL_BLEND)
        bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
 def draw_Cartesian(self):#vertices):
     ob = bpy.context.scene.objects.active.location
     rgn = bpy.context.region
     rv3d = bpy.context.space_data.region_3d
     #bgl.glClear()
     
     bgl.glEnable(bgl.GL_BLEND)
     bgl.glLineWidth(4)    
     bgl.glBegin(bgl.GL_LINE_STRIP)
     v3d = Vector((0, 0, 0))
     v2d = location_3d_to_region_2d(rgn, rv3d, v3d)
     bgl.glVertex2f(*v2d)
     bgl.glColor4f(100, 0.0, 0.0, 1)
     v3d = mathutils.Vector((ob.x,0,0))
     v2d = location_3d_to_region_2d(rgn, rv3d, v3d)
     bgl.glVertex2f(*v2d)
     bgl.glColor4f(0, 100.0, 0.0, 1)
     v3d = mathutils.Vector((ob.x,ob.y,0))
     v2d = location_3d_to_region_2d(rgn, rv3d, v3d)
     bgl.glVertex2f(*v2d)
     bgl.glColor4f(0, 0.0, 100.0, 1)
     v3d = mathutils.Vector((ob.x,ob.y,ob.z))
     v2d = location_3d_to_region_2d(rgn, rv3d, v3d)
     bgl.glVertex2f(*v2d)
     bgl.glEnd()
     bgl.glLineWidth(1)
     bgl.glDisable(bgl.GL_BLEND)
     
     bgl.glColor4f(1, 1, 1, 1)
     self.draw_value(Vector((ob.x/2,0,0)), str(round(ob.x, 2)))
     self.draw_value(Vector((ob.x, ob.y/2, 0)), str(round(ob.y, 2)))
     self.draw_value(Vector((ob.x, ob.y, ob.z/2)), str(round(ob.z, 2)))
Beispiel #7
0
def draw_line(point0, point1, width):
    bgl.glLineWidth(width)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    bgl.glVertex3f(point0.x, point0.y, point0.z)
    bgl.glVertex3f(point1.x, point1.y, point1.z)
    bgl.glEnd()
    bgl.glLineWidth(1)
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)
Beispiel #9
0
def draw_texture(x, y, w, h, texture, mode=None):
    mode_bak = bgl.Buffer(bgl.GL_INT, 1)
    bgl.glGetIntegerv(bgl.GL_DRAW_BUFFER, mode_bak)
    if mode is not None:
        bgl.glDrawBuffer(mode)

    bgl.glEnable(bgl.GL_TEXTURE_2D)
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, texture)

    bgl.glColor4d(1.0, 1.0, 1.0, 1.0)
    bgl.glBegin(bgl.GL_TRIANGLE_FAN)
    bgl.glTexCoord2d(0.0, 0.0)
    bgl.glVertex2i(x, y)
    bgl.glTexCoord2d(1.0, 0.0)
    bgl.glVertex2i(x + w, y)
    bgl.glTexCoord2d(1.0, 1.0)
    bgl.glVertex2i(x + w, y + h)
    bgl.glTexCoord2d(0.0, 1.0)
    bgl.glVertex2i(x, y + h)
    bgl.glEnd()

    bgl.glDisable(bgl.GL_TEXTURE_2D)
    bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0)

    if mode is not None:
        bgl.glDrawBuffer(mode_bak[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  
    def post_view_callback(self, context):
        start = self.vertex_co
        normal_size = context.tool_settings.normal_size
        view_3d_theme = context.user_preferences.themes['Default'].view_3d

        default_color = view_3d_theme.split_normal
        highlight_color = [0.25, 1.0, 0.56]

        # Draw all normals of selected vertex.
        bgl.glBegin(bgl.GL_LINES)
        bgl.glColor3f(*default_color)
        bgl.glLineWidth(1)
        for n in self.normals:
            end = start + Vector(n) * normal_size
            bgl.glVertex3f(*start)
            bgl.glVertex3f(*end)
        bgl.glEnd()

        # Highlight selected normal.
        bgl.glColor3f(*highlight_color)
        bgl.glLineWidth(2)
        bgl.glBegin(bgl.GL_LINES)
        end = start + Vector(self.normals[self.normals_idx]) * normal_size
        bgl.glVertex3f(*start)
        bgl.glVertex3f(*end)
        bgl.glEnd()
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
Beispiel #13
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)
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
	def drawCurvePoints(self):
		#Draw Lines between Control Points

		bgl.glEnable(bgl.GL_POINT_SMOOTH)
		bgl.glColor3d(0,1,0)
		bgl.glPointSize(3)
		bgl.glBegin(bgl.GL_POINTS)

		for i in range(len(self.curvePoints)):
			tup = self.curvePoints[i].to_tuple()
			bgl.glVertex3f( *tup )
		bgl.glEnd()

		bgl.glLineWidth(1)
		bgl.glColor3f(0,.5,0)
		bgl.glBegin(bgl.GL_LINES)
		'''
		for i in range(0, len(self.curvePoints)-1):
			if i%(self.tesselate+1) != self.tesselate:
				tup = self.curvePoints[i]
				tup1 = self.curvePoints[i+1]
				bgl.glVertex3f( *tup )
				bgl.glVertex3f( *tup1 )
		'''
		for i in range(0, len(self.curvePoints)-1):
			tup = self.curvePoints[i].to_tuple()
			tup1 = self.curvePoints[i+1].to_tuple()
			bgl.glVertex3f(tup[0], tup[1], tup[2])
			bgl.glVertex3f(tup1[0], tup1[1], tup1[2])
		bgl.glEnd()
	def draw_callback_postview(self, context):
		bgl.glPushAttrib(bgl.GL_ALL_ATTRIB_BITS)    # save OpenGL attributes
		self.draw_postview(context)
		if len(self.selectCntrl):
			cntrlLength = len(self.selectCntrl)
			for x in range(0,cntrlLength):
				# assuming that we have only one control point, so if
				# anything is selected it would be the only point
				p111 = self.selectCntrl[x]
				t111 = p111.to_tuple()
				vrot = context.space_data.region_3d.view_rotation
				dx = (vrot * Vector((1,0,0))).normalized()          # compute right dir relative to view
				dy = (vrot * Vector((0,1,0))).normalized()          # compute up dir relative to view
				px = tuple(p111 + dx*0.5)
				py = tuple(p111 + dy*0.5)

				# highlight the point
				bgl.glColor3f(1,1,0)
				bgl.glBegin(bgl.GL_POINTS)
				bgl.glVertex3f(*t111)
				bgl.glEnd()

				# draw lines to indicate right (red) and up (green)
				bgl.glBegin(bgl.GL_LINES)
				bgl.glColor3f(1,0,0)
				bgl.glVertex3f(*t111)
				bgl.glVertex3f(*px)
				bgl.glColor3f(0,1,0)
				bgl.glVertex3f(*t111)
				bgl.glVertex3f(*py)
				bgl.glEnd()
		bgl.glPopAttrib()                           # restore OpenGL attributes
Beispiel #17
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)
Beispiel #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()
Beispiel #19
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)
Beispiel #20
0
def draw_callback(self, context):
    mid = int(360 * self.recv / self.fsize)
    cx = 200
    cy = 30
    blf.position(0, 230, 23, 0)
    blf.size(0, 20, 72)
    blf.draw(0, "{0:2d}% of {1}".format(100 * self.recv // self.fsize, self.hfsize))

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(0.7, 0.7, 0.7, 0.8)
    bgl.glBegin(bgl.GL_TRIANGLE_FAN)
    bgl.glVertex2i(cx, cy)
    for i in range(mid):
        x = cx + 20 * math.sin(math.radians(float(i)))
        y = cy + 20 * math.cos(math.radians(float(i)))
        bgl.glVertex2f(x, y)
    bgl.glEnd()

    bgl.glColor4f(0.0, 0.0, 0.0, 0.6)
    bgl.glBegin(bgl.GL_TRIANGLE_FAN)
    bgl.glVertex2i(cx, cy)
    for i in range(mid, 360):
        x = cx + 20 * math.sin(math.radians(float(i)))
        y = cy + 20 * math.cos(math.radians(float(i)))
        bgl.glVertex2f(x, y)
    bgl.glEnd()

    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Beispiel #21
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)
Beispiel #22
0
def draw_elipse(cen, r, axis, xy_ratio, mat):

    base_axis = mathutils.Vector((0, 0, 1))
    axis = mathutils.Vector(axis)

    dot = base_axis.dot(axis)
    cross = base_axis.cross(axis)

    rot_mat = mathutils.Matrix.Rotation(math.acos(dot), 4, cross)

    bgl.glBegin(bgl.GL_LINE_STRIP)

    iterations = 32
    for i in range (iterations + 1):
        i = (1 if i == iterations + 1 else i)
        i *= 2 * math.pi / iterations
        co = (math.cos(i) * r, math.sin(i) * r * xy_ratio, 0)
        co = mathutils.Vector(co)

        co = rot_mat * co

        co[0] += cen[0]
        co[1] += cen[1]
        co[2] += cen[2]

        co = mat * co
        bgl.glVertex3f(co[0], co[1], co[2])

    bgl.glEnd()
Beispiel #23
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)
def draw_box(xmin, ymin, w, h, poly=False):
    bgl.glBegin(bgl.GL_QUADS if poly else bgl.GL_LINE_LOOP)
    bgl.glVertex2f(xmin, ymin)
    bgl.glVertex2f(xmin + w, ymin)
    bgl.glVertex2f(xmin + w, ymin + h)
    bgl.glVertex2f(xmin, ymin + h)
    bgl.glEnd()
def draw_line(vertexloc, vertexnorm, scale):
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex3f(vertexloc[0], vertexloc[1], vertexloc[2])
    bgl.glVertex3f(((vertexnorm[0] * scale) + vertexloc[0]),
                   ((vertexnorm[1] * scale) + vertexloc[1]),
                   ((vertexnorm[2] * scale) + vertexloc[2]))
    bgl.glEnd()
 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  
Beispiel #27
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()
	def redraw(self):

		drawregion = bpy.context.region

		rv3d = self.rv3ds[drawregion]
		vec = self.originvert.co.copy()
		vec.rotate(self.selobj.matrix_world)
		vec.rotate(self.selobj.matrix_world)
		self.space3d.cursor_location =  vec * self.selobj.matrix_world + self.selobj.matrix_world.to_translation()

		bgl.glColor3f(1.0, 1.0, 0)
		bgl.glBegin(bgl.GL_POLYGON)
		x, y = self.getscreencoords(Vector(self.originvert.co), drawregion, rv3d)
		bgl.glVertex2f(x-2, y-2)
		bgl.glVertex2f(x-2, y+2)
		bgl.glVertex2f(x+2, y+2)
		bgl.glVertex2f(x+2, y-2)
		bgl.glEnd()

		bgl.glColor3f(1, 1, 0.7)
		bgl.glMatrixMode(bgl.GL_PROJECTION)
		bgl.glLoadIdentity()
		bgl.gluOrtho2D(0, self.region.width, 0, self.region.height)
		bgl.glMatrixMode(bgl.GL_MODELVIEW)
		bgl.glLoadIdentity()
		blf.position(0, self.region.width/2 - 80, self.region.height - 20, 0)
		blf.size(0, 12, 72)
		blf.draw(0, "FastOrigin :  Enter confirms - ESC cancels")
Beispiel #29
0
def draw_arc(center, radius, axis, angle_min, angle_max, local_transf_mat=None):
    base_axis = mathutils.Vector((0, 0, 1))
    axis = mathutils.Vector(axis)
    dot = base_axis.dot(axis)
    cross = base_axis.cross(axis)
    axis_rotation = mathutils.Matrix.Rotation(math.acos(dot), 4, cross)

    bgl.glBegin(bgl.GL_LINE_STRIP)

    phi_range = wrap_2pi(angle_max - angle_min)

    points = []

    co_from = calc_circ_coords(center, radius, axis_rotation, angle_min, local_transf_mat)
    bgl.glVertex3f(co_from.x, co_from.y, co_from.z)
    points.append(co_from)

    for i in range(1, NUM_SECTORS + 1):
        i *= 2 * math.pi / NUM_SECTORS
       
        if i < phi_range:
            co = calc_circ_coords(center, radius, axis_rotation, i + angle_min, local_transf_mat)
            bgl.glVertex3f(co.x, co.y, co.z)
            points.append(co)

    co_to = calc_circ_coords(center, radius, axis_rotation, angle_max, local_transf_mat)
    bgl.glVertex3f(co_to.x, co_to.y, co_to.z)
    points.append(co_to)

    bgl.glEnd()

    return points
    def drawPoint(x, y, main=True):
        r = 6 if main else 3

        bgl.glBegin(bgl.GL_LINES)
        bgl.glColor3f(1.0, 1.0, 1.0)
        bgl.glVertex2i(x - r, y)
        bgl.glVertex2i(x - r, y + r)
        bgl.glVertex2i(x - r, y + r)
        bgl.glVertex2i(x, y + r)

        bgl.glVertex2i(x + r, y)
        bgl.glVertex2i(x + r, y - r)
        bgl.glVertex2i(x + r, y - r)
        bgl.glVertex2i(x, y - r)

        bgl.glColor3f(0.0, 0.0, 0.0)
        bgl.glVertex2i(x, y + r)
        bgl.glVertex2i(x + r, y + r)
        bgl.glVertex2i(x + r, y + r)
        bgl.glVertex2i(x + r, y)

        bgl.glVertex2i(x, y - r)
        bgl.glVertex2i(x - r, y - r)
        bgl.glVertex2i(x - r, y - r)
        bgl.glVertex2i(x - r, y)
        bgl.glEnd()
Beispiel #31
0
def draw_star_px(self, context):
    if len(self.strokes) < 2:
        return
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glLineWidth(1)
    bgl.glColor4f(0.75, 0.75, 0.75, 1.0)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    sx, sy = self.strokes[0]["mouse"]
    ex, ey = self.strokes[-1]["mouse"]
    o = math.atan2(ey-sy, ex-sx)
    m = 5.0
    for n in range(int(m) + 1):
        ang = 2 * PI/m * n
        rad = math.sqrt((ex - sx) ** 2 + (ey - sy) ** 2)
        x = rad * math.cos(ang + o) + sx
        y = rad * math.sin(ang + o) + sy
        bgl.glVertex2i(int(x), int(y))
    bgl.glEnd()
    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Beispiel #32
0
def draw_shape_map_point(mat, scene_scs_props):
    """
    Draws shape for "Locator" of "Map Point" type.
    :param mat:
    :param scene_scs_props:
    :return:
    """
    glLineWidth(2.0)
    glBegin(GL_LINES)
    glColor3f(scene_scs_props.locator_prefab_wire_color.r,
              scene_scs_props.locator_prefab_wire_color.g,
              scene_scs_props.locator_prefab_wire_color.b)
    glVertex3f(*(mat * Vector((-0.17678, -0.17678, 0.17678))))
    glVertex3f(*(mat * Vector((0.17678, 0.17678, -0.17678))))
    glVertex3f(*(mat * Vector((-0.17678, 0.17678, 0.17678))))
    glVertex3f(*(mat * Vector((0.17678, -0.17678, -0.17678))))
    glVertex3f(*(mat * Vector((-0.17678, -0.17678, -0.17678))))
    glVertex3f(*(mat * Vector((0.17678, 0.17678, 0.17678))))
    glVertex3f(*(mat * Vector((-0.17678, 0.17678, -0.17678))))
    glVertex3f(*(mat * Vector((0.17678, -0.17678, 0.17678))))
    glEnd()
    glLineWidth(1.0)
Beispiel #33
0
def draw_circle3d(p, u, v, radius, color=(0, 0, 0, 1), width=1, half=False):
    u = u.normalized()
    v = v.normalized()
    bgl.glPointSize(1)
    bgl.glLineWidth(width)
    bgl.glColor4f(color[0], color[1], color[2], color[3])
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glBegin(bgl.GL_LINE_STRIP)

    r = radius
    t = 0
    last = math.pi * 2 if not half else math.pi
    dt = last / 20
    while t < last:
        q = p + r * math.cos(t) * u + r * math.sin(t) * v
        bgl.glVertex3f(q.x, q.y, q.z)
        t += dt
    t = last
    q = p + r * math.cos(t) * u + r * math.sin(t) * v
    bgl.glVertex3f(q.x, q.y, q.z)
    bgl.glEnd()
    restore_bgl()
Beispiel #34
0
def draw_box(xmin, ymin, w, h, angle=0.0, poly=False, colors=None):
    """左下から反時計回りに描画。
    :param angle: 0.0以外なら(xmin, ymin)を中心に回転する
    :param colors: 各頂点に色を指定する[[R,G,B], ...] or [[R,G,B,A], ...]
    """
    coords = ((xmin, ymin), (xmin + w, ymin), (xmin + w, ymin + h), (xmin,
                                                                     ymin + h))
    if angle != 0.0:
        m = Matrix.Rotation(angle, 2)
        v = Vector(coords[0])
        coords = [m * (Vector(co) - v) + v for co in coords]

    bgl.glBegin(bgl.GL_QUADS if poly else bgl.GL_LINE_LOOP)
    if colors:
        glColor = bgl.glColor3f if len(colors[0]) == 3 else bgl.glColor4f
        for co, col in zip(coords, colors):
            glColor(*col)
            bgl.glVertex2f(*co)
    else:
        for co in coords:
            bgl.glVertex2f(*co)
    bgl.glEnd()
Beispiel #35
0
def draw_callback_px(self, context):
    """Modally called function that draws the lines as they are streamed.
    Firstly updates the viewport's text.
    Then draws the line based on points in self.point_path.
    """
    print("data points", len(self.point_path))

    # get region so can draw intermediate lines
    region = context.region
    rv3d = context.space_data.region_3d

    draw_text_on_viewport("{} vertices added, timestamp {}".format(
        str(len(self.point_path)), str(self.latest_ts)))
    # set the line parameters
    # 50% alpha, 2 pixel width line
    bgl.glEnable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
    bgl.glLineWidth(2)

    # draw the line here.....
    bgl.glBegin(bgl.GL_LINE_STRIP)
    # start from the origin for visual purposes
    for i in [0]:
        vertex = loc3d2d(region, rv3d, (i, i, i))
        print('vertex is', vertex)
        bgl.glVertex2f(vertex[0], vertex[1])

    for i, loc3d in enumerate(self.point_path):
        loc2d = loc3d2d(region, rv3d, loc3d)
        print(loc2d[0], loc2d[1], 'is the viewport coordinates')
        bgl.glVertex2i(math.floor(loc2d[0]), math.floor(loc2d[1]))
        #bgl.glVertex2i(math.floor(loc2d[0]%10), math.floor(loc2d[1]%10))

    bgl.glEnd()

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Beispiel #36
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()
Beispiel #37
0
    def draw(_, context):
        sc = context.scene
        props = sc.muv_props.uvinsp
        prefs = context.user_preferences.addons["uv_magic_uv"].preferences

        # OpenGL configuration
        bgl.glEnable(bgl.GL_BLEND)

        # render overlapped UV
        if sc.muv_uvinsp_show_overlapped:
            color = prefs.uvinsp_overlapped_color
            for info in props.overlapped_info:
                if sc.muv_uvinsp_show_mode == 'PART':
                    for poly in info["polygons"]:
                        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
                        bgl.glColor4f(color[0], color[1], color[2], color[3])
                        for uv in poly:
                            x, y = context.region.view2d.view_to_region(
                                uv.x, uv.y)
                            bgl.glVertex2f(x, y)
                        bgl.glEnd()
                elif sc.muv_uvinsp_show_mode == 'FACE':
                    bgl.glBegin(bgl.GL_TRIANGLE_FAN)
                    bgl.glColor4f(color[0], color[1], color[2], color[3])
                    for uv in info["subject_uvs"]:
                        x, y = context.region.view2d.view_to_region(uv.x, uv.y)
                        bgl.glVertex2f(x, y)
                    bgl.glEnd()

        # render flipped UV
        if sc.muv_uvinsp_show_flipped:
            color = prefs.uvinsp_flipped_color
            for info in props.flipped_info:
                if sc.muv_uvinsp_show_mode == 'PART':
                    for poly in info["polygons"]:
                        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
                        bgl.glColor4f(color[0], color[1], color[2], color[3])
                        for uv in poly:
                            x, y = context.region.view2d.view_to_region(
                                uv.x, uv.y)
                            bgl.glVertex2f(x, y)
                        bgl.glEnd()
                elif sc.muv_uvinsp_show_mode == 'FACE':
                    bgl.glBegin(bgl.GL_TRIANGLE_FAN)
                    bgl.glColor4f(color[0], color[1], color[2], color[3])
                    for uv in info["uvs"]:
                        x, y = context.region.view2d.view_to_region(uv.x, uv.y)
                        bgl.glVertex2f(x, y)
                    bgl.glEnd()
def drawZoomBox(self, context):

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

    if self.zoomBoxMode and not self.zoomBoxDrag:
        # before selection starts draw infinite cross
        bgl.glBegin(bgl.GL_LINES)

        px, py = self.zb_xmax, self.zb_ymax

        bgl.glVertex2i(0, py)
        bgl.glVertex2i(context.area.width, py)

        bgl.glVertex2i(px, 0)
        bgl.glVertex2i(px, context.area.height)

        bgl.glEnd()

    elif self.zoomBoxMode and self.zoomBoxDrag:
        # 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.zb_xmin, self.zb_ymin)
        bgl.glVertex2i(self.zb_xmin, self.zb_ymax)
        bgl.glVertex2i(self.zb_xmax, self.zb_ymax)
        bgl.glVertex2i(self.zb_xmax, self.zb_ymin)

        bgl.glEnd()

        bgl.glDisable(bgl.GL_LINE_STIPPLE)

    # restore opengl defaults
    bgl.glLineWidth(1)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Beispiel #39
0
def draw_circle(matrix,
                radius=.1,
                num_segments=16,
                offset=0,
                offset_axis="Z",
                color=None,
                width=1,
                fill=False):
    #precalculate the sine and cosine
    theta = 2 * math.pi / num_segments
    c = math.cos(theta)
    s = math.sin(theta)
    x = radius
    y = 0

    vector_list = []
    for i in range(num_segments):
        vector_list.append(Vector((x, y, 0)))  # output vertex
        t = x
        x = c * x - s * y
        y = s * t + c * y

    translate = {
        'X': Vector((offset, 0, 0)),
        'Y': Vector((0, offset, 0)),
        'Z': Vector((0, 0, offset))
    }

    color = (0.0, 0.0, 0.0, 1.0) if color is None else color
    bgl.glColor4f(*color)
    bgl.glLineWidth(width)
    if not fill:  # bgl.GL_TRIANGLE_FAN, http://www.glprogramming.com/red/chapter02.html
        bgl.glBegin(bgl.GL_LINE_LOOP)
    else:
        bgl.glBegin(bgl.GL_TRIANGLE_FAN)
    for v in vector_list:
        coord = matrix * (v + translate[offset_axis])
        bgl.glVertex3f(*coord)
    bgl.glEnd()
Beispiel #40
0
    def draw_texture(cls, _, context):
        sc = context.scene

        if not cls.is_running(context):
            return

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

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

        # 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]]

        # OpenGL configuration
        bgl.glEnable(bgl.GL_BLEND)
        bgl.glEnable(bgl.GL_TEXTURE_2D)
        if img.bindcode:
            bind = img.bindcode[0]
            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()
def draw_rotation_line():
    v1 = rotation_helper_params.c
    if rotation_helper_params.mouse_world:
        v2 = rotation_helper_params.mouse_world
    else:
        v2 = mathutils.Vector()

    bgl.glEnable(bgl.GL_BLEND)
    bgl.glEnable(bgl.GL_LINE_STIPPLE)
    bgl.glLineWidth(1)
    bgl.glLineStipple(3, 0xAAAA)
    bgl.glDepthMask(bgl.GL_FALSE)
    bgl.glDisable(bgl.GL_DEPTH_TEST)
    bgl.glColor4f(0, 0, 0, 1)
    bgl.glBegin(bgl.GL_LINES)
    bgl.glVertex3f(v1.x, v1.y, v1.z)
    bgl.glVertex3f(v2.x, v2.y, v2.z)
    bgl.glEnd()
    bgl.glEnable(bgl.GL_DEPTH_TEST)
    bgl.glDepthMask(bgl.GL_TRUE)
    bgl.glDisable(bgl.GL_LINE_STIPPLE)
    bgl.glDisable(bgl.GL_BLEND)
Beispiel #42
0
def draw_polyline_2d_loop(context, points, scale, offset, color, LINE_TYPE):
    '''
    '''
    bgl.glColor4f(*color)  #black or white?

    if LINE_TYPE == "GL_LINE_STIPPLE":
        bgl.glLineStipple(4, 0x5555)
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
        bgl.glColor4f(0.3, 0.3, 0.3, 1.0)  #boring grey

    bgl.glBegin(bgl.GL_LINE_STRIP)
    for coord in points:
        bgl.glVertex2f(scale * coord[0] + offset[0],
                       scale * coord[1] + offset[1])
    bgl.glVertex2f(scale * points[0][0] + offset[0],
                   scale * points[0][1] + offset[1])
    bgl.glEnd()

    if LINE_TYPE == "GL_LINE_STIPPLE":
        bgl.glDisable(bgl.GL_LINE_STIPPLE)
        bgl.glEnable(bgl.GL_BLEND)  # back to uninterupted lines
    return
Beispiel #43
0
def draw_callback_view():
    from bgl import glColor3f, glVertex3f, glPointSize, glBegin, glEnd, GL_POINTS

    points = (
        (0, 0, 0),
        (1, 1, 1),
        (1, 1, -1),
        (1, -1, 1),
        (1, -1, -1),
        (-1, 1, 1),
        (-1, 1, -1),
        (-1, -1, 1),
        (-1, -1, -1),
    )

    glPointSize(3.0)
    glBegin(GL_POINTS)
    glColor3f(1.0, 0.0, 0.0)
    for point in points:
        glVertex3f(*point)
    glEnd()
    glPointSize(1.0)
Beispiel #44
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 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_size[1] - 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)

    font_id = 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_size[1] - img_y)/img_size[1], clip=True)
        
        blf.position(font_id, rx+5, ry+5, 0)
        text = str((round(pix[0]),round(pix[1])))
        
        blf.draw(font_id, text)
        
        blf.position(font_id, rx+5, ry+20, 0)
        text = str((round(pix[0]),round(pix[1])))
def draw_callback_px(self, context):

    bgl.glEnable(bgl.GL_BLEND)

    if self.selecting:
        # when selecting draw dashed line box
        bgl.glColor4f(1.0, 1.0, 1.0, .9)
        bgl.glLineWidth(2)
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
        bgl.glLineStipple(1, 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)

    # restore opengl defaults
    bgl.glLineWidth(2)
    bgl.glDisable(bgl.GL_BLEND)
    bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
Beispiel #47
0
def draw_3d_points(context, points, size, color=(1, 0, 0, 1)):
    region = context.region
    rv3d = context.space_data.region_3d

    bgl.glEnable(bgl.GL_POINT_SMOOTH)
    bgl.glPointSize(size)
    # bgl.glEnable(bgl.GL_BLEND)
    bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)

    bgl.glBegin(bgl.GL_POINTS)
    # draw red
    bgl.glColor4f(*color)
    for coord in points:
        vector3d = (coord.x, coord.y, coord.z)
        vector2d = location_3d_to_region_2d(region, rv3d, vector3d)
        if vector2d and vector3d:
            bgl.glVertex2f(*vector2d)
    bgl.glEnd()

    bgl.glDisable(bgl.GL_POINT_SMOOTH)
    bgl.glDisable(bgl.GL_POINTS)
    return
 def draw_greasemarks(self):
     return
     if not self.actions.r3d: return
     # THE FOLLOWING CODE NEEDS UPDATED TO NOT USE GLBEGIN!
     # grease marks
     bgl.glBegin(bgl.GL_QUADS)
     for stroke_data in self.grease_marks:
         bgl.glColor4f(*stroke_data['color'])
         t = stroke_data['thickness']
         s0,p0,n0,d0,d1 = None,None,None,None,None
         for s1 in stroke_data['marks']:
             p1,n1 = s1
             if p0 and p1:
                 v01 = p1 - p0
                 if d0 is None: d0 = Direction(v01.cross(n0))
                 d1 = Direction(v01.cross(n1))
                 bgl.glVertex3f(*(p0-d0*t+n0*0.001))
                 bgl.glVertex3f(*(p0+d0*t+n0*0.001))
                 bgl.glVertex3f(*(p1+d1*t+n1*0.001))
                 bgl.glVertex3f(*(p1-d1*t+n1*0.001))
             s0,p0,n0,d0 = s1,p1,n1,d1
     bgl.glEnd()
Beispiel #49
0
    def draw_callback_px(self, context):
        glsettings = vagl.GLSettings(context)
        glsettings.push()
        cm = glsettings.region_view3d_space().enter()

        # draw edgelines
        bgl.glColor4f(0.8, 0.8, 0.8, 1.0)
        bgl.glBegin(bgl.GL_LINES)
        for p1, p2 in self.edgelines:
            bgl.glVertex3f(*p1)
            bgl.glVertex3f(*p2)
        if self.modal_mouse.lock:
            bgl.glColor4f(0.0, 0.0, 1.0, 1.0)
        else:
            bgl.glColor4f(1.0, 1.0, .0, 1.0)
        for p1, p2 in self.translines:
            bgl.glVertex3f(*p1)
            bgl.glVertex3f(*p2)
        bgl.glEnd()

        cm.exit()
        glsettings.pop()
Beispiel #50
0
    def draw_VIEW3D(self, args):
        if not self.remove_all:
            stashobj = self.orphans[self.idx]

            mesh = stashobj.data
            mx = stashobj.MM.stashtargetmx

            alpha = 0.5
            if self.mark_delete[self.idx]:
                color = (1.0, 0.0, 0.0)
            else:
                color = (1.0, 1.0, 1.0)

            edgecolor = (*color, alpha)
            edgewidth = 2

            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 the verts out a bit
                v1co = mx * v1.co
                v2co = mx * v2.co

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

                bgl.glBegin(bgl.GL_LINES)

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

            draw_end()
Beispiel #51
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
            bgl.glPointSize(dprops.debug.force_field_line_size)
            particle_batch_draw.draw(particle_shader)
        else:
            bgl.glPointSize(dprops.debug.force_field_line_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_VIEW3D(self, args):
        fixedcolor = (0.25, 1, 0.25)
        unmovedcolor = (1, 0.25, 0.25)
        alpha = 1

        mx = self.active.matrix_world

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


        # draw fixed verts

        pointcolor = (*fixedcolor, alpha)
        bgl.glColor4f(*pointcolor)
        bgl.glPointSize(8)
        bgl.glBegin(bgl.GL_POINTS)

        for coords in self.fixed_verts:
            vco = mx * coords

            bgl.glVertex3f(*vco)

        bgl.glEnd()

        # draw moveable verts

        pointcolor = (*unmovedcolor, alpha)
        bgl.glColor4f(*pointcolor)
        bgl.glPointSize(6)
        bgl.glBegin(bgl.GL_POINTS)

        for coords in self.unmoved_verts:
            vco = mx * coords

            bgl.glVertex3f(*vco)

        draw_end()
Beispiel #53
0
    def draw_VIEW3D(self, args):
        stashobj = self.orphans[self.idx]

        mesh = stashobj.data
        mx = stashobj.MM.stashtargetmx

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

        alpha = 0.5
        color = (1.0, 1.0, 1.0)

        edgecolor = (*color, alpha)
        edgewidth = 2

        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 the verts out a bit
            v1co = mx * v1.co
            v2co = mx * v2.co

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

            bgl.glBegin(bgl.GL_LINES)

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

        draw_end()
Beispiel #54
0
    def __render(context):
        # @include-source start [loc_to_region]
        # 指定したリージョンとスペースを取得する
        region, space = DrawObjectTrajectory.__get_region_space(
            context, 'VIEW_3D', 'WINDOW', 'VIEW_3D')
        if (region is None) or (space is None):
            return

        # 選択されたオブジェクトを取得
        objs = [o for o in bpy.data.objects if o.select]
        # オブジェクトの位置座標(3D座標)をリージョン座標(2D座標)に変換
        DrawObjectTrajectory.__loc_history.append([
            view3d_utils.location_3d_to_region_2d(region, space.region_3d,
                                                  o.location) for o in objs
        ])
        # @include-source end [loc_to_region]

        # @include-source start [delete_oldest_loc]
        # 一定期間後、最も古い位置情報を削除する
        if len(DrawObjectTrajectory.__loc_history) >= 100:
            DrawObjectTrajectory.__loc_history.pop(0)
# @include-source end [delete_oldest_loc]

# @include-source start [render_rect]
# 軌跡を描画
        size = 6.0
        bgl.glEnable(bgl.GL_BLEND)
        # 保存されている過去の位置情報をすべて表示
        for hist in DrawObjectTrajectory.__loc_history:
            # 選択されたすべてのオブジェクトについて表示
            for loc in hist:
                bgl.glBegin(bgl.GL_QUADS)
                bgl.glColor4f(0.2, 0.6, 1.0, 0.7)
                bgl.glVertex2f(loc.x - size / 2.0, loc.y - size / 2.0)
                bgl.glVertex2f(loc.x - size / 2.0, loc.y + size / 2.0)
                bgl.glVertex2f(loc.x + size / 2.0, loc.y + size / 2.0)
                bgl.glVertex2f(loc.x + size / 2.0, loc.y - size / 2.0)
                bgl.glEnd()
Beispiel #55
0
def draw_callback_view():
    context = bpy.context
    if context.mode != "EDIT_MESH":
        return
    ob = context.active_object
    if ob is None:
        return
    if ob.type != "MESH":
        return
    if ob.mode != "EDIT":
        return
    if False:
        # Respects modifiers, but not hidden edges
        ob.update_from_editmode()
        bm = bmesh.new()
        bm.from_object(ob, context.scene)
    else:
        # Faster bmesh access, but doesn't respect modifiers
        bm = bmesh.from_edit_mesh(ob.data)
    layer = get_edgecolor_layer(bm)
    if layer is None:
        return
    bgl.glLineWidth(3.0)
    bgl.glPushMatrix()
    b = bgl.Buffer(GL_FLOAT, [16], list(itertools.chain(*ob.matrix_world.col)))
    bgl.glMultMatrixf(b)
    for edge in bm.edges:
        if edge.hide: continue
        color_int = edge[layer]
        if color_int == 0: continue
        bgl.glColor3f(*colors[color_int])
        bgl.glBegin(GL_LINES)
        for v in edge.verts:
            bgl.glVertex3f(*v.co)
        bgl.glEnd()
    bgl.glPointSize(1.0)
    bgl.glLineWidth(1.0)
    bgl.glPopMatrix()
Beispiel #56
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)
Beispiel #57
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:
        if coord:
            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
Beispiel #58
0
def drawHollowCircleBillBoard(context, location, radius, resolution=20):
    fl_resolution = float(resolution)
    #Marker Highlight
    axis, angle = getScreenLookAxis(context, location)
    bgl.glPushMatrix()
    bgl.glTranslatef(location.x, location.y, location.z)
    bgl.glPushMatrix()
    bgl.glRotatef(angle + 90.0, axis.x, axis.y, axis.z)
    bgl.glPushMatrix()
    #     bgl.glBegin(bgl.GL_TRIANGLE_FAN);
    bgl.glLineWidth(5.0)
    bgl.glBegin(bgl.GL_LINE_LOOP)
    x, y = 0.0, 0.0
    for i in range(resolution):
        factor = (float(i) / fl_resolution) * TWOPI
        xpos = x + (radius * math.cos(factor))
        ypos = y + (radius * math.sin(factor))
        bgl.glVertex2f(xpos, ypos)

    bgl.glEnd()
    bgl.glPopMatrix()
    bgl.glPopMatrix()
    bgl.glPopMatrix()
Beispiel #59
0
def draw_polyline_from_coordinates(context, points, LINE_TYPE):
    region = context.region
    rv3d = context.space_data.region_3d

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

    if LINE_TYPE == "GL_LINE_STIPPLE":
        bgl.glLineStipple(4, 0x5555)
        bgl.glEnable(bgl.GL_LINE_STIPPLE)
        bgl.glColor4f(0.3, 0.3, 0.3, 1.0)

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

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

    return
def draw3d_polyline(points,
                    color,
                    thickness,
                    view_loc,
                    view_ortho,
                    stipple=False,
                    zfar=0.997):
    if not points: return
    if 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, view_loc, view_ortho)
    bgl.glBegin(bgl.GL_LINE_STRIP)
    for coord in points:
        bgl.glVertex3f(*coord)
    bgl.glEnd()
    bgl.glLineWidth(1)
    if stipple:
        bgl.glDisable(bgl.GL_LINE_STIPPLE)
        bgl.glEnable(bgl.GL_BLEND)  # back to uninterrupted lines