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_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 draw3d_closed_polylines(context, lpoints, color, thickness, LINE_TYPE, mirror): #if type(lpoints) is types.GeneratorType: # lpoints = list(lpoints) lpoints = [[mirror(pt) for pt in points] for points in lpoints] if len(lpoints) == 0: return if LINE_TYPE == "GL_LINE_STIPPLE": bgl.glLineStipple(4, 0x5555) #play with this later bgl.glEnable(bgl.GL_LINE_STIPPLE) bgl.glEnable(bgl.GL_BLEND) bgl.glLineWidth(thickness) bgl.glColor4f(*color) for points in lpoints: set_depthrange(0.0, 0.997, points) bgl.glBegin(bgl.GL_LINE_STRIP) for coord in chain(points,points[:1]): bgl.glVertex3f(*coord) bgl.glEnd() # if settings.symmetry_plane == 'x': # bgl.glColor4f(*color_mirror) # for points in lpoints: # bgl.glBegin(bgl.GL_LINE_STRIP) # for coord in points: # bgl.glVertex3f(-coord.x, coord.y, coord.z) # bgl.glVertex3f(-points[0].x, points[0].y, points[0].z) # bgl.glEnd() bgl.glLineWidth(1) if LINE_TYPE == "GL_LINE_STIPPLE": bgl.glDisable(bgl.GL_LINE_STIPPLE) bgl.glEnable(bgl.GL_BLEND) # back to uninterrupted lines
def draw3d_closed_polylines(context, lpoints, color, thickness, LINE_TYPE): lpoints = list(lpoints) if LINE_TYPE == "GL_LINE_STIPPLE": bgl.glLineStipple(4, 0x5555) #play with this later bgl.glEnable(bgl.GL_LINE_STIPPLE) bgl.glEnable(bgl.GL_BLEND) bgl.glLineWidth(thickness) bgl.glDepthRange(0.0, 0.997) bgl.glColor4f(*color) for points in lpoints: bgl.glBegin(bgl.GL_LINE_STRIP) for coord in points: bgl.glVertex3f(*coord) bgl.glVertex3f(*points[0]) bgl.glEnd() if settings.symmetry_plane == 'x': bgl.glColor4f(*color_mirror) for points in lpoints: bgl.glBegin(bgl.GL_LINE_STRIP) for coord in points: bgl.glVertex3f(-coord.x, coord.y, coord.z) bgl.glVertex3f(-points[0].x, points[0].y, points[0].z) bgl.glEnd() bgl.glLineWidth(1) if LINE_TYPE == "GL_LINE_STIPPLE": bgl.glDisable(bgl.GL_LINE_STIPPLE) bgl.glEnable(bgl.GL_BLEND) # back to uninterrupted lines
def draw_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): 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)
def _start_line(self, colour, width=2, style=bgl.GL_LINE_STIPPLE): bgl.glPushAttrib(bgl.GL_ENABLE_BIT) bgl.glLineStipple(1, 0x9999) bgl.glEnable(style) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(*colour) bgl.glLineWidth(width) bgl.glBegin(bgl.GL_LINE_STRIP)
def h_draw_selected(bounds): selbounds = [bounds[0]+2, bounds[1]+2, bounds[2]-4, bounds[3]-4] bgl.glEnable(bgl.GL_LINE_STIPPLE) bgl.glLineStipple(2, 0xAAAAAA) bgl.glLineWidth(0.5) bgl.glColor4f(*(0,0,0,0.6)) h_draw_quad_wire(selbounds) bgl.glDisable(bgl.GL_LINE_STIPPLE)
def draw_box_select(anchor, m_coords, region, p_col = (0.7,0.8,1.0,0.6), enabled = False, dragging = 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.glLineStipple(1, 0xCCCC) bgl.glEnable(bgl.GL_LINE_STIPPLE) bgl.glBegin(bgl.GL_LINES) bgl.glColor4f(f_col[0], f_col[1], f_col[2], f_col[3]) point_x = m_coords[0] point_y = m_coords[1] bgl.glVertex2f(point_x,0) bgl.glVertex2f(point_x, region.height) bgl.glVertex2f(0, point_y) bgl.glVertex2f(region.width, point_y) bgl.glEnd() bgl.glDisable(bgl.GL_LINE_STIPPLE) bgl.glDisable(bgl.GL_BLEND) if dragging: bgl.glEnable(bgl.GL_BLEND) bgl.glBegin(bgl.GL_QUADS) 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] anc_x = anchor[0] anc_y = anchor[1] bgl.glVertex2f(anc_x, anc_y) bgl.glVertex2f(point_x, anc_y) bgl.glVertex2f(point_x,point_y) bgl.glVertex2f(anc_x,point_y) bgl.glEnd() bgl.glLineStipple(1, 0xCCCC) bgl.glEnable(bgl.GL_LINE_STIPPLE) bgl.glBegin(bgl.GL_LINE_LOOP) bgl.glColor4f(f_col[0], f_col[1], f_col[2], f_col[3]) bgl.glVertex2f(anc_x, anc_y) bgl.glVertex2f(point_x, anc_y) bgl.glVertex2f(point_x, point_y) bgl.glVertex2f(anc_x, point_y) bgl.glEnd() # restore opengl defaults bgl.glLineWidth(1) bgl.glDisable(bgl.GL_LINE_STIPPLE) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_tetrahedron(region, rv3d, context, tetra_coords): apex, base1, base2, base3 = tetra_coords # converting to screen coordinates screen_apex = loc3d2d(region, rv3d, apex) screen_base1 = loc3d2d(region, rv3d, base1) screen_base2 = loc3d2d(region, rv3d, base2) screen_base3 = loc3d2d(region, rv3d, base3) # colour + line setup, 50% alpha, 1 px width line bgl.glEnable(bgl.GL_BLEND) bgl.glLineWidth(1) # linear distance line bgl.glColor4f(0.6, 0.6, 0.6, 0.8) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(*screen_apex) bgl.glVertex2f(*screen_base3) bgl.glEnd() # x bgl.glColor4f(1.0, 0.1, 0.1, 0.8) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(*screen_base3) bgl.glVertex2f(*screen_base2) bgl.glEnd() # y bgl.glColor4f(0.0, 1.0, 0.1, 0.8) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(*screen_base2) bgl.glVertex2f(*screen_base1) bgl.glEnd() # z bgl.glColor4f(0.1, 0.3, 1.0, 0.8) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(*screen_apex) bgl.glVertex2f(*screen_base1) bgl.glEnd() # distraction line 1 & 2 bgl.glColor4f(0.3, 0.3, 0.3, 0.6) bgl.glLineStipple(4, 0x5555) bgl.glEnable(bgl.GL_LINE_STIPPLE) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(*screen_apex) bgl.glVertex2f(*screen_base2) bgl.glVertex2f(*screen_base1) bgl.glVertex2f(*screen_base3) bgl.glEnd() # done bgl.glDisable(bgl.GL_LINE_STIPPLE) bgl.glEnable(bgl.GL_BLEND) # back to uninterupted lines
def draw_callback_px(self, context): bgl.glPushAttrib(bgl.GL_ENABLE_BIT) # glPushAttrib is done to return everything to normal after drawing bgl.glLineStipple(10, 0x9999) bgl.glEnable(bgl.GL_LINE_STIPPLE) # 50% alpha, 2 pixel width line bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 1.0, 1.0, 0.8) bgl.glLineWidth(5) bgl.glBegin(bgl.GL_LINE_STRIP) for x, y in self.mouse_path: bgl.glVertex2i(x, y) bgl.glEnd() bgl.glPopAttrib() bgl.glEnable(bgl.GL_BLEND) # ...api_current/bpy.types.Area.html?highlight=bpy.types.area header_height = context.area.regions[0].height # 26px width = context.area.width height = context.area.height - header_height p1_2d = (0,0) p2_2d = (width, height) p3_2d = (width, 0) p4_2d = (0, height) # green line bgl.glLineWidth(3) draw_line_2d((0.0, 1.0, 0.0, 0.8), p1_2d, p2_2d) # yellow line bgl.glLineWidth(5) draw_line_2d((1.0, 1.0, 0.0, 0.8), p3_2d, p4_2d) # white circle bgl.glLineWidth(4) draw_circle_2d((1.0, 1.0, 1.0, 0.8), width/2, height/2, 70, 360) # red circle bgl.glLineWidth(5) draw_circle_2d((1.0, 0.0, 0.0, 0.4), width/2, height/2, 230, 5) # draw text draw_typo_2d((1.0, 1.0, 1.0, 1), "Hello Word " + str(len(self.mouse_path))) # restore opengl defaults bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def glSetOptions(prefix, opts): if opts == None: return prefix = '%s '%prefix if prefix else '' if '%sdepth'%prefix in opts: bgl.glDepthRange(*opts['%sdepth'%prefix]) if '%scolor'%prefix in opts: glColor(opts['%scolor'%prefix]) if '%swidth'%prefix in opts: bgl.glLineWidth(opts['%swidth'%prefix]) if '%ssize'%prefix in opts: bgl.glPointSize(opts['%ssize'%prefix]) if opts.get('%sstipple'%prefix, False): bgl.glLineStipple(4, 0x5555) #play with this later bgl.glEnable(bgl.GL_LINE_STIPPLE)
def draw_block_box(): if not show_block_bounds(): return box = block_bounds() color = bpy.context.user_preferences.themes[0].view_3d.object_selected glLineWidth(1.0) glColor3f(*color) glLineStipple(1, 0x3333) glEnable(GL_LINE_STIPPLE) draw_box(box) glDisable(GL_LINE_STIPPLE)
def draw_matrix(self, mat): bb = self.bb zero_tx = mat * self.zero axis = [ [(1.0, 0.2, 0.2), self.x_p], [(0.6, 0.0, 0.0), self.x_n], [(0.2, 1.0, 0.2), self.y_p], [(0.0, 0.6, 0.0), self.y_n], [(0.2, 0.2, 1.0), self.z_p], [(0.0, 0.0, 0.6), self.z_n] ] glLineWidth(2.0) for col, axial in axis: glColor3f(*col) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * axial)) glEnd() # bounding box vertices i = 0 glColor3f(1.0, 1.0, 1.0) series1 = (-0.5, -0.3, -0.1, 0.1, 0.3, 0.5) series2 = (-0.5, 0.5) z = 0 for x in series1: for y in series2: bb[i][:] = x, y, z bb[i] = mat * bb[i] i += 1 for y in series1: for x in series2: bb[i][:] = x, y, z bb[i] = mat * bb[i] i += 1 # bounding box drawing glLineWidth(1.0) glLineStipple(1, 0xAAAA) glEnable(GL_LINE_STIPPLE) for i in range(0, 24, 2): glBegin(GL_LINE_STRIP) glVertex3f(*bb[i]) glVertex3f(*bb[i+1]) glEnd() glDisable(GL_LINE_STIPPLE)
def draw2d_polyline(points, color, thickness, stipple=False): 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) bgl.glBegin(bgl.GL_LINE_STRIP) for coord in points: bgl.glVertex2f(*coord) bgl.glEnd() bgl.glLineWidth(1) if stipple: bgl.glDisable(bgl.GL_LINE_STIPPLE) bgl.glEnable(bgl.GL_BLEND) # back to uninterupted lines
def draw3d_polyline(context, points, color, thickness, LINE_TYPE): if LINE_TYPE == "GL_LINE_STIPPLE": bgl.glLineStipple(4, 0x5555) #play with this later bgl.glEnable(bgl.GL_LINE_STIPPLE) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(*color) bgl.glLineWidth(thickness) bgl.glDepthRange(0.0, 0.997) bgl.glBegin(bgl.GL_LINE_STRIP) for coord in points: bgl.glVertex3f(*coord) bgl.glEnd() bgl.glLineWidth(1) if LINE_TYPE == "GL_LINE_STIPPLE": bgl.glDisable(bgl.GL_LINE_STIPPLE) bgl.glEnable(bgl.GL_BLEND) # back to uninterrupted lines
def draw3d_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
def draw3d_polyline(context, points, color, thickness, LINE_TYPE, mirror, zfar=0.997): points = [mirror(pt) for pt in points] if len(points) == 0: return # if type(points) is types.GeneratorType: # points = list(points) if LINE_TYPE == "GL_LINE_STIPPLE": bgl.glLineStipple(4, 0x5555) #play with this later bgl.glEnable(bgl.GL_LINE_STIPPLE) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(*color) bgl.glLineWidth(thickness) set_depthrange(0.0, zfar, points) bgl.glBegin(bgl.GL_LINE_STRIP) for coord in points: bgl.glVertex3f(*coord) bgl.glEnd() bgl.glLineWidth(1) if LINE_TYPE == "GL_LINE_STIPPLE": bgl.glDisable(bgl.GL_LINE_STIPPLE) bgl.glEnable(bgl.GL_BLEND) # back to uninterrupted lines
def 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
def draw3d_polyline(context, points, color, thickness, LINE_TYPE): if context.region_data.view_perspective == 'ORTHO': bias = 0.9997 else: bias = 0.997 if LINE_TYPE == "GL_LINE_STIPPLE": bgl.glLineStipple(4, 0x5555) #play with this later bgl.glEnable(bgl.GL_LINE_STIPPLE) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(*color) bgl.glLineWidth(thickness) bgl.glDepthRange(0.0, bias) bgl.glBegin(bgl.GL_LINE_STRIP) for coord in points: bgl.glVertex3f(*coord) bgl.glEnd() bgl.glLineWidth(1) if LINE_TYPE == "GL_LINE_STIPPLE": bgl.glDisable(bgl.GL_LINE_STIPPLE) bgl.glEnable(bgl.GL_BLEND) # back to uninterrupted lines
def draw_polyline_from_coordinates2D(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: bgl.glVertex2f(coord[0],coord[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
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
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)
def draw_rotation_line(): v1 = rotation_helper_params.c_world 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)
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 draw(self, context, render=False): """ render flag when rendering """ 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_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)
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
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)
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)
def draw_matrix(mat): zero_tx = mat * zero glLineWidth(2.0) # x glColor3f(1.0, 0.2, 0.2) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * x_p)) glEnd() glColor3f(0.6, 0.0, 0.0) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * x_n)) glEnd() # y glColor3f(0.2, 1.0, 0.2) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * y_p)) glEnd() glColor3f(0.0, 0.6, 0.0) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * y_n)) glEnd() # z glColor3f(0.2, 0.2, 1.0) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * z_p)) glEnd() glColor3f(0.0, 0.0, 0.6) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * z_n)) glEnd() # bounding box i = 0 glColor3f(1.0, 1.0, 1.0) for x in (-1.0, 1.0): for y in (-1.0, 1.0): for z in (-1.0, 1.0): bb[i][:] = x, y, z bb[i] = mat * bb[i] i += 1 # strip glLineWidth(1.0) glLineStipple(1, 0xAAAA) glEnable(GL_LINE_STIPPLE) glBegin(GL_LINE_STRIP) for i in 0, 1, 3, 2, 0, 4, 5, 7, 6, 4: glVertex3f(*bb[i]) glEnd() # not done by the strip glBegin(GL_LINES) glVertex3f(*bb[1]) glVertex3f(*bb[5]) glVertex3f(*bb[2]) glVertex3f(*bb[6]) glVertex3f(*bb[3]) glVertex3f(*bb[7]) glEnd() glDisable(GL_LINE_STIPPLE)
def draw_callback_px(self, context): font_id = 0 blf.position(font_id, 150, 10, 0) blf.size(font_id, 20, 72) blf.draw(font_id, 'Draw') n1 = len(pt_buf.list_) if n1 != 0: bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(0.0, 1.0, 0.0, 1.0) bgl.glPointSize(4.0) bgl.glBegin(bgl.GL_POINTS) for j in pt_buf.list_: bgl.glVertex2f(j[0], j[1]) bgl.glEnd() bgl.glLineStipple(4, 0x5555) bgl.glEnable(bgl.GL_LINE_STIPPLE) # -- -- -- -- #bgl.glLineWidth(1) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(pt_buf.list_[-1][0], pt_buf.list_[-1][1]) bgl.glVertex2f(pt_buf.x, pt_buf.y) bgl.glEnd() pos = (pt_buf.list_[-1] + Vector((pt_buf.x, pt_buf.y))) * 0.5 vec1_3d = region_2d_to_location_3d(context.region, context.space_data.region_3d, Vector((pt_buf.list_[-1][0], pt_buf.list_[-1][1])), Vector((0.0, 0.0, 0.0))) vec2_3d = region_2d_to_location_3d(context.region, context.space_data.region_3d, Vector((pt_buf.x, pt_buf.y)), Vector((0.0, 0.0, 0.0))) blf.position(font_id, pos[0] + 10, pos[1] + 10, 0) blf.size(font_id, 14, 72) blf.draw(font_id, str(round((vec1_3d -vec2_3d).length, 4))) if n1 >= 2: vec0_3d = region_2d_to_location_3d(context.region, context.space_data.region_3d, Vector((pt_buf.list_[-2][0], pt_buf.list_[-2][1])), Vector((0.0, 0.0, 0.0))) vec = vec2_3d - vec1_3d if vec.length == 0.0: pass else: ang = (vec).angle(vec0_3d - vec1_3d) if round(degrees(ang)) == 0.0: pass else: bgl.glColor4f(0.027, 0.663, 1.0, 1.0) blf.position(font_id, pt_buf.list_[-1][0] + 10, pt_buf.list_[-1][1] + 10, 0) blf.size(font_id, 14, 72) blf.draw(font_id, str(round(degrees(ang), 2)) + ' Degrees') bgl.glColor4f(0.0, 1.0, 0.0, 1.0) # -- -- -- -- bgl.glBegin(bgl.GL_LINE_STRIP) for i in range(n1): bgl.glVertex2f(pt_buf.list_[i][0], pt_buf.list_[i][1]) bgl.glEnd() bgl.glDisable(bgl.GL_LINE_STIPPLE) #bgl.glLineWidth(1) bgl.glPointSize(1.0) bgl.glColor4f(1.0, 1.0, 1.0, 1.0) bgl.glDisable(bgl.GL_BLEND)
def draw_matrix(self, mat, bbcol=(1.0, 1.0, 1.0), skip=False, grid=True): bb = self.bb if not isinstance(mat, Matrix): mat = Matrix(mat) zero_tx = mat * self.zero axis = [ [(1.0, 0.2, 0.2), self.x_p], [(0.6, 0.0, 0.0), self.x_n], [(0.2, 1.0, 0.2), self.y_p], [(0.0, 0.6, 0.0), self.y_n], [(0.2, 0.2, 1.0), self.z_p], [(0.0, 0.0, 0.6), self.z_n] ] glLineWidth(2.0) for idx, (col, axial) in enumerate(axis): if idx % 2 and skip: continue glColor3f(*col) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * axial)) glEnd() # bounding box vertices i = 0 glColor3f(*bbcol) series1 = (-0.5, -0.3, -0.1, 0.1, 0.3, 0.5) series2 = (-0.5, 0.5) z = 0 if not grid: return # bounding box drawing glLineWidth(1.0) def yield_xy(): for x in series1: for y in series2: yield x, y for y in series1: for x in series2: yield x, y for x, y in yield_xy(): bb[i][:] = x, y, z bb[i] = mat * bb[i] i += 1 glLineStipple(1, 0xAAAA) glEnable(GL_LINE_STIPPLE) for i in range(0, 24, 2): glBegin(GL_LINE_STRIP) glVertex3f(*bb[i]) glVertex3f(*bb[i+1]) glEnd() glDisable(GL_LINE_STIPPLE)
def draw_matrix(mat): zero_tx = mat * zero glLineWidth(2.0) # x glColor3f(1.0, 0.2, 0.2) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * x_p)) glEnd() glColor3f(0.6, 0.0, 0.0) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * x_n)) glEnd() # y glColor3f(0.2, 1.0, 0.2) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * y_p)) glEnd() glColor3f(0.0, 0.6, 0.0) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * y_n)) glEnd() # z glColor3f(0.2, 0.2, 1.0) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * z_p)) glEnd() glColor3f(0.0, 0.0, 0.6) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * z_n)) glEnd() # bounding box vertices i = 0 glColor3f(1.0, 1.0, 1.0) series1 = (-0.5, -0.3, -0.1, 0.1, 0.3, 0.5) series2 = (-0.5, 0.5) z = 0 for x in series1: for y in series2: bb[i][:] = x, y, z bb[i] = mat * bb[i] i += 1 for y in series1: for x in series2: bb[i][:] = x, y, z bb[i] = mat * bb[i] i += 1 # bounding box drawing glLineWidth(1.0) glLineStipple(1, 0xAAAA) glEnable(GL_LINE_STIPPLE) for i in range(0, 24, 2): glBegin(GL_LINE_STRIP) glVertex3f(*bb[i]) glVertex3f(*bb[i + 1]) glEnd()
def draw_callback_px(self, context): font_id = 0 alpha = context.scene.pen_tool_props.a font_size = context.scene.pen_tool_props.fs bgl.glColor4f(0.0, 0.6, 1.0, alpha) bgl.glPointSize(4.0) bgl.glBegin(bgl.GL_POINTS) bgl.glVertex2f(pt_buf.x, pt_buf.y) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) # location 3d if context.scene.pen_tool_props.b2 is True: mloc3d = region_2d_to_location_3d(context.region, context.space_data.region_3d, Vector((pt_buf.x, pt_buf.y)), pt_buf.depth_location) blf.position(font_id, pt_buf.x + 15, pt_buf.y - 15, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw( font_id, '(' + str(round(mloc3d[0], 4)) + ', ' + str(round(mloc3d[1], 4)) + ', ' + str(round(mloc3d[2], 4)) + ')') n = len(pt_buf.list_m_loc_3d) if n != 0: # add points bgl.glEnable(bgl.GL_BLEND) bgl.glPointSize(4.0) bgl.glBegin(bgl.GL_POINTS) for i in pt_buf.list_m_loc_3d: loc_0 = location_3d_to_region_2d(context.region, context.space_data.region_3d, i) bgl.glVertex2f(loc_0[0], loc_0[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) # text next to the mouse m_loc_3d = region_2d_to_location_3d(context.region, context.space_data.region_3d, Vector((pt_buf.x, pt_buf.y)), pt_buf.depth_location) vec0 = pt_buf.list_m_loc_3d[-1] - m_loc_3d blf.position(font_id, pt_buf.x + 15, pt_buf.y + 15, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round(vec0.length, 4))) # angle first after mouse if n >= 2: vec1 = pt_buf.list_m_loc_3d[-2] - pt_buf.list_m_loc_3d[-1] if vec0.length == 0.0 or vec1.length == 0.0: pass else: ang = vec0.angle(vec1) if round(degrees(ang), 2) == 180.0: text_0 = '0.0' elif round(degrees(ang), 2) == 0.0: text_0 = '180.0' else: text_0 = str(round(degrees(ang), 2)) loc_4 = location_3d_to_region_2d(context.region, context.space_data.region_3d, pt_buf.list_m_loc_3d[-1]) bgl.glColor4f(0.0, 1.0, 0.525, alpha) blf.position(font_id, loc_4[0] + 10, loc_4[1] + 10, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, text_0 + '') bgl.glLineStipple(4, 0x5555) bgl.glEnable(bgl.GL_LINE_STIPPLE) # enable line stipple bgl.glColor4f(0.0, 0.6, 1.0, alpha) # draw line between last point and mouse bgl.glEnable(bgl.GL_BLEND) bgl.glBegin(bgl.GL_LINES) loc_1 = location_3d_to_region_2d(context.region, context.space_data.region_3d, pt_buf.list_m_loc_3d[-1]) bgl.glVertex2f(loc_1[0], loc_1[1]) bgl.glVertex2f(pt_buf.x, pt_buf.y) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) # draw lines between points bgl.glEnable(bgl.GL_BLEND) bgl.glBegin(bgl.GL_LINE_STRIP) for j in pt_buf.list_m_loc_3d: loc_2 = location_3d_to_region_2d(context.region, context.space_data.region_3d, j) bgl.glVertex2f(loc_2[0], loc_2[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) bgl.glDisable(bgl.GL_LINE_STIPPLE) # disable line stipple # draw line length between points if context.scene.pen_tool_props.b1 is True: for k in range(n - 1): loc_3 = location_3d_to_region_2d( context.region, context.space_data.region_3d, (pt_buf.list_m_loc_3d[k] + pt_buf.list_m_loc_3d[(k + 1) % n]) * 0.5) blf.position(font_id, loc_3[0] + 10, loc_3[1] + 10, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw( font_id, str( round((pt_buf.list_m_loc_3d[k] - pt_buf.list_m_loc_3d[(k + 1) % n]).length, 4))) # draw all angles if context.scene.pen_tool_props.b0 is True: for h in range(n - 1): if n >= 2: if h == 0: pass else: vec_ = pt_buf.list_m_loc_3d[h] - pt_buf.list_m_loc_3d[ (h - 1) % n] vec_1_ = pt_buf.list_m_loc_3d[h] vec_2_ = pt_buf.list_m_loc_3d[(h - 1) % n] if vec_.length == 0.0 or vec_1_.length == 0.0 or vec_2_.length == 0.0: pass else: ang = vec_.angle(vec_1_ - vec_2_) if round(degrees(ang)) == 0.0: pass else: loc_4 = location_3d_to_region_2d( context.region, context.space_data.region_3d, pt_buf.list_m_loc_3d[h]) bgl.glColor4f(0.0, 1.0, 0.525, alpha) blf.position(font_id, loc_4[0] + 10, loc_4[1] + 10, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round(degrees(ang), 2)) + '') # tool on / off bgl.glColor4f(1.0, 1.0, 1.0, 1.0) blf.position(font_id, self.text_location, 20, 0) blf.size(font_id, 15, context.user_preferences.system.dpi) blf.draw(font_id, 'Draw On')
def draw_box_select(anchor, m_coords, region, p_col=(0.7, 0.8, 1.0, 0.6), enabled=False, dragging=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.glLineStipple(1, 0xCCCC) bgl.glEnable(bgl.GL_LINE_STIPPLE) bgl.glBegin(bgl.GL_LINES) bgl.glColor4f(f_col[0], f_col[1], f_col[2], f_col[3]) point_x = m_coords[0] point_y = m_coords[1] bgl.glVertex2f(point_x, 0) bgl.glVertex2f(point_x, region.height) bgl.glVertex2f(0, point_y) bgl.glVertex2f(region.width, point_y) bgl.glEnd() bgl.glDisable(bgl.GL_LINE_STIPPLE) bgl.glDisable(bgl.GL_BLEND) if dragging: bgl.glEnable(bgl.GL_BLEND) bgl.glBegin(bgl.GL_QUADS) 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] anc_x = anchor[0] anc_y = anchor[1] bgl.glVertex2f(anc_x, anc_y) bgl.glVertex2f(point_x, anc_y) bgl.glVertex2f(point_x, point_y) bgl.glVertex2f(anc_x, point_y) bgl.glEnd() bgl.glLineStipple(1, 0xCCCC) bgl.glEnable(bgl.GL_LINE_STIPPLE) bgl.glBegin(bgl.GL_LINE_LOOP) bgl.glColor4f(f_col[0], f_col[1], f_col[2], f_col[3]) bgl.glVertex2f(anc_x, anc_y) bgl.glVertex2f(point_x, anc_y) bgl.glVertex2f(point_x, point_y) bgl.glVertex2f(anc_x, point_y) bgl.glEnd() # restore opengl defaults bgl.glLineWidth(1) bgl.glDisable(bgl.GL_LINE_STIPPLE) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_callback_px(self, context): use_texture = self.use_texture if not use_texture: if context.region != self.region: return U = context.user_preferences prefs = MouseGesturePreferences.get_instance() dpi = U.system.dpi widget_unit = int((PIXEL_SIZE * dpi * 20 + 36) / 72) font_id = 0 theme_style = U.ui_styles[0] blf.size(font_id, theme_style.widget.points, dpi) bgl.glEnable(bgl.GL_BLEND) bgl.glColor3f(*U.themes['Default'].view_3d.space.text_hi) win = context.window w, h = win.width, win.height if use_texture: bgl.glDisable(bgl.GL_SCISSOR_TEST) with window_space(win): if use_texture: draw_texture(0, 0, w, h, self.texture_back) # draw origin coords = self.coords + [self.mco] bgl.glLineWidth(2) r1 = prefs.threshold r2 = r1 + 5 x, y = coords[0] bgl.glBegin(bgl.GL_LINES) for i in range(4): a = math.pi / 2 * i + math.pi / 4 bgl.glVertex2f(x + r1 * math.cos(a), y + r1 * math.sin(a)) bgl.glVertex2f(x + r2 * math.cos(a), y + r2 * math.sin(a)) 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 coords: bgl.glVertex2f(v[0], v[1]) bgl.glEnd() bgl.glLineStipple(1, 1) bgl.glDisable(bgl.GL_LINE_STIPPLE) if use_texture: bgl.glEnable(bgl.GL_SCISSOR_TEST) # draw txt xmin, ymin, xmax, ymax = self.region_drawing_rectangle( context, self.area, self.region) xmin += self.region.x ymin += self.region.y xmax += self.region.x ymax += self.region.y if self.area.type == 'VIEW_3D': if U.view.show_mini_axis: # view3d_draw.c: 1019: draw_selected_name() posx = xmin + widget_unit + U.view.mini_axis_size * 2 else: # view3d_draw.c: 928: draw_selected_name() posx = xmin + 1.5 * widget_unit posy = ymin + widget_unit * 1.5 else: posx = xmin + widget_unit * 0.5 posy = ymin + widget_unit * 0.5 char_space = 5 group = prefs.gesture_groups.get(self.group) use_relative = group and group.use_relative gesture = self.gesture_rel if use_relative else self.gesture_abs # 文字はregionに収まるように(はみ出すと見た目が悪いから) scissor_box = bgl.Buffer(bgl.GL_INT, 4) bgl.glGetIntegerv(bgl.GL_SCISSOR_BOX, scissor_box) bgl.glScissor(xmin, ymin, xmax - xmin + 1, ymax - ymin + 1) with window_space(win): if gesture: x = posx for txt in gesture: blf.position(font_id, x, posy, 0) blf.draw(font_id, txt) text_width, text_height = blf.dimensions(font_id, txt) x += text_width + char_space if self.item: blf.position(font_id, posx, posy + widget_unit, 0) blf.draw(font_id, self.item.name) bgl.glScissor(*scissor_box) # restore opengl defaults bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_matrix(mat): zero_tx = mat * zero glLineWidth(2.0) # x glColor3f(1.0, 0.2, 0.2) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * x_p)) glEnd() glColor3f(0.6, 0.0, 0.0) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * x_n)) glEnd() # y glColor3f(0.2, 1.0, 0.2) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * y_p)) glEnd() glColor3f(0.0, 0.6, 0.0) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * y_n)) glEnd() # z glColor3f(0.4, 0.4, 1.0) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * z_p)) glEnd() glColor3f(0.0, 0.0, 0.6) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * z_n)) glEnd() # bounding box if bbox_hide: return i = 0 glColor3f(1.0, 1.0, 1.0) for x in (-bbox_scale, bbox_scale): for y in (-bbox_scale, bbox_scale): for z in (-bbox_scale, bbox_scale): bb[i][:] = x, y, z bb[i] = mat * bb[i] i += 1 # strip glLineWidth(1.0) glLineStipple(1, 0xAAAA) glEnable(GL_LINE_STIPPLE) glBegin(GL_LINE_STRIP) for i in 0, 1, 3, 2, 0, 4, 5, 7, 6, 4: glVertex3f(*bb[i]) glEnd() # not done by the strip glBegin(GL_LINES) glVertex3f(*bb[1]) glVertex3f(*bb[5]) glVertex3f(*bb[2]) glVertex3f(*bb[6]) glVertex3f(*bb[3]) glVertex3f(*bb[7]) glEnd() glDisable(GL_LINE_STIPPLE)
def draw_callback_line_px(self, context): region = context.region rv3d = context.space_data.region_3d # Draw Points bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.8, 0.0, 1.0) bgl.glPointSize(5.0) bgl.glBegin(bgl.GL_POINTS) # bgl.glVertex2f(self.mouse_path[0], self.mouse_path[1]) for x in self.list_construction_points: loc_1 = view3d_utils.location_3d_to_region_2d(region, rv3d, x.point) bgl.glVertex2f(loc_1[0], loc_1[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) # Draw Normal point bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(0.3, 0.8, 0.8, 1.0) bgl.glPointSize(2.0) bgl.glBegin(bgl.GL_POINTS) for x in self.list_construction_points: loc_1 = view3d_utils.location_3d_to_region_2d(region, rv3d, x.point + x.normal) bgl.glVertex2f(loc_1[0], loc_1[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) # 50% alpha, 2 pixel width line bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 0.0, 0.0, 1.0) bgl.glLineStipple(2, 0x9999) bgl.glEnable(bgl.GL_LINE) bgl.glBegin(bgl.GL_LINE_STRIP) for x in self.list_construction_points: loc_1 = view3d_utils.location_3d_to_region_2d(region, rv3d, x.point) bgl.glVertex2f(loc_1[0], loc_1[1]) bgl.glVertex2f(self.mouse_path[0], self.mouse_path[1]) bgl.glEnd() bgl.glDisable(bgl.GL_LINE_STRIP) bgl.glDisable(bgl.GL_BLEND) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 1.0, 0.0, 1.0) bgl.glLineWidth(1) for x in self.list_construction_points: bgl.glEnable(bgl.GL_LINE) bgl.glBegin(bgl.GL_LINE_STRIP) root = view3d_utils.location_3d_to_region_2d(region, rv3d, x.point) bgl.glVertex2f(root[0], root[1]) tip = view3d_utils.location_3d_to_region_2d(region, rv3d, x.point + x.normal) bgl.glVertex2f(tip[0], tip[1]) bgl.glEnd() bgl.glDisable(bgl.GL_LINE_STRIP) bgl.glDisable(bgl.GL_BLEND) if self.surface_found: #if there is a surface under mouse cursor bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 1.0, 0.0, 1.0) bgl.glLineWidth(1) bgl.glEnable(bgl.GL_LINE) bgl.glBegin(bgl.GL_LINE_STRIP) bgl.glVertex2f(self.mouse_path[0], self.mouse_path[1]) loc_1 = view3d_utils.location_3d_to_region_2d(region, rv3d, self.surface_normal) bgl.glVertex2f(loc_1[0], loc_1[1]) bgl.glEnd() bgl.glDisable(bgl.GL_LINE_STRIP) bgl.glDisable(bgl.GL_BLEND)
def glEnableStipple(enable=True): if enable: bgl.glLineStipple(4, 0x5555) bgl.glEnable(bgl.GL_LINE_STIPPLE) else: bgl.glDisable(bgl.GL_LINE_STIPPLE)
def draw_callback_px(self, context): if context.mode == "EDIT_MESH": en0 = context.scene.dt_custom_props.en0 font_id = 0 font_size = context.scene.dt_custom_props.fs ob_act = context.active_object bme = bmesh.from_edit_mesh(ob_act.data) mtrx = ob_act.matrix_world list_0 = [v.index for v in bme.verts if v.select] if len(list_0) != 0: p = bme.verts[list_0[0]].co.copy() p_loc_2d = location_3d_to_region_2d(context.region, context.space_data.region_3d, p) q = mtrx * bme.verts[list_0[0]].co.copy() q_loc_2d = location_3d_to_region_2d(context.region, context.space_data.region_3d, q) # -- -- -- -- distance to adjacent vertices if context.scene.dt_custom_props.b0 == True: list_ = [[v.index for v in e.verts] for e in bme.verts[list_0[0]].link_edges] for ek in list_: vi = [i for i in ek if i != list_0[0]][0] p1 = bme.verts[vi].co.copy() loc_0_3d = mtrx * ((p + p1) * 0.5) loc_0_2d = location_3d_to_region_2d(context.region, context.space_data.region_3d, loc_0_3d) bgl.glColor4f(1.0, 1.0, 0.0, context.scene.dt_custom_props.a) blf.position(font_id, loc_0_2d[0] + 4, loc_0_2d[1] + 4, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round((p - p1).length, 4))) bgl.glLineStipple(4, 0xAAAA) bgl.glEnable(bgl.GL_LINE_STIPPLE) # -- -- -- -- distance to axis local global if context.scene.dt_custom_props.b1 == True: # -- -- -- -- local if en0 == 'opt0': # -- -- -- -- x axis px = mtrx * Vector((0.0, p[1], p[2])) px_loc_2d = location_3d_to_region_2d(context.region, context.space_data.region_3d, px) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 0.0, 0.0, context.scene.dt_custom_props.a) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(q_loc_2d[0], q_loc_2d[1]) bgl.glVertex2f(px_loc_2d[0], px_loc_2d[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) if context.scene.dt_custom_props.b2 == False: lx = (q_loc_2d + px_loc_2d) * 0.5 bgl.glColor4f(1.0, 0.0, 0.0, context.scene.dt_custom_props.a) blf.position(font_id, lx[0] + 4, lx[1] + 4, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round(p[0], 4))) # -- -- -- -- y axis py = mtrx * Vector((p[0], 0.0, p[2])) py_loc_2d = location_3d_to_region_2d(context.region, context.space_data.region_3d, py) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(0.0, 1.0, 0.0, context.scene.dt_custom_props.a) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(q_loc_2d[0], q_loc_2d[1]) bgl.glVertex2f(py_loc_2d[0], py_loc_2d[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) if context.scene.dt_custom_props.b2 == False: ly = (q_loc_2d + py_loc_2d) * 0.5 bgl.glColor4f(0.0, 1.0, 0.0, context.scene.dt_custom_props.a) blf.position(font_id, ly[0] + 4, ly[1] + 4, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round(p[1], 4))) # -- -- -- -- z axis pz = mtrx * Vector((p[0], p[1], 0.0)) pz_loc_2d = location_3d_to_region_2d(context.region, context.space_data.region_3d, pz) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 1.0, context.scene.dt_custom_props.a) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(q_loc_2d[0], q_loc_2d[1]) bgl.glVertex2f(pz_loc_2d[0], pz_loc_2d[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) if context.scene.dt_custom_props.b2 == False: lz = (q_loc_2d + pz_loc_2d) * 0.5 bgl.glColor4f(0.0, 0.0, 1.0, context.scene.dt_custom_props.a) blf.position(font_id, lz[0] + 4, lz[1] + 4, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round(p[2], 4))) # -- -- -- -- if context.scene.dt_custom_props.b2 == True and context.scene.dt_custom_props.b1 == True: blf.size(font_id, font_size, context.user_preferences.system.dpi) bgl.glColor4f(1.0, 0.0, 0.0, context.scene.dt_custom_props.a) blf.position(font_id, q_loc_2d[0] + 4, q_loc_2d[1] + 4 + font_size + 4 + font_size + 4, 0) blf.draw(font_id, 'x ' + str(round(p[0], 4))) bgl.glColor4f(0.0, 1.0, 0.0, context.scene.dt_custom_props.a) blf.position(font_id, q_loc_2d[0] + 4, q_loc_2d[1] + 4 + font_size + 4, 0) blf.draw(font_id, 'y ' + str(round(p[1], 4))) bgl.glColor4f(0.0, 0.0, 1.0, context.scene.dt_custom_props.a) blf.position(font_id, q_loc_2d[0] + 4, q_loc_2d[1] + 4, 0) blf.draw(font_id, 'z ' + str(round(p[2], 4))) # -- -- -- -- global elif en0 == 'opt1': # -- -- -- -- x axis ip_x = intersect_line_plane(q, q + (Vector((1.0, 0.0, 0.0)) * 0.1), Vector((0.0, 1.0, 0.0)), Vector((1.0, 0.0, 0.0))) ip_x_loc_2d = location_3d_to_region_2d(context.region, context.space_data.region_3d, ip_x) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 0.0, 0.0, context.scene.dt_custom_props.a) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(q_loc_2d[0], q_loc_2d[1]) bgl.glVertex2f(ip_x_loc_2d[0], ip_x_loc_2d[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) if context.scene.dt_custom_props.b2 == False: loc_1_2d = (q_loc_2d + ip_x_loc_2d) * 0.5 bgl.glColor4f(1.0, 0.0, 0.0, context.scene.dt_custom_props.a) blf.position(font_id, loc_1_2d[0] + 4, loc_1_2d[1] + 4, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round((q - ip_x).length, 4))) # -- -- -- -- y axis ip_y = intersect_line_plane(q, q + (Vector((0.0, 1.0, 0.0)) * 0.1), Vector((1.0, 0.0, 0.0)), Vector((0.0, 1.0, 0.0))) ip_y_loc_2d = location_3d_to_region_2d(context.region, context.space_data.region_3d, ip_y) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(0.0, 1.0, 0.0, context.scene.dt_custom_props.a) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(q_loc_2d[0], q_loc_2d[1]) bgl.glVertex2f(ip_y_loc_2d[0], ip_y_loc_2d[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) if context.scene.dt_custom_props.b2 == False: loc_2_2d = (q_loc_2d + ip_y_loc_2d) * 0.5 bgl.glColor4f(0.0, 1.0, 0.0, context.scene.dt_custom_props.a) blf.position(font_id, loc_2_2d[0] + 4, loc_2_2d[1] + 4, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round((q - ip_y).length, 4))) # -- -- -- -- z axis ip_z = intersect_line_plane(q, q + (Vector((0.0, 0.0, 1.0)) * 0.1), Vector((1.0, 0.0, 0.0)), Vector((0.0, 0.0, 1.0))) ip_z_loc_2d = location_3d_to_region_2d(context.region, context.space_data.region_3d, ip_z) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 1.0, context.scene.dt_custom_props.a) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(q_loc_2d[0], q_loc_2d[1]) bgl.glVertex2f(ip_z_loc_2d[0], ip_z_loc_2d[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) if context.scene.dt_custom_props.b2 == False: loc_3_2d = (q_loc_2d + ip_z_loc_2d) * 0.5 bgl.glColor4f(0.0, 0.0, 1.0, context.scene.dt_custom_props.a) blf.position(font_id, loc_3_2d[0] + 4, loc_3_2d[1] + 4, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round((q - ip_z).length, 4))) # -- -- -- -- if context.scene.dt_custom_props.b2 == True and context.scene.dt_custom_props.b1 == True: blf.size(font_id, font_size, context.user_preferences.system.dpi) bgl.glColor4f(1.0, 0.0, 0.0, context.scene.dt_custom_props.a) blf.position(font_id, q_loc_2d[0] + 4, q_loc_2d[1] + 4 + font_size + 4 + font_size + 4, 0) blf.draw(font_id, 'x ' + str(round((q - ip_x).length, 4))) bgl.glColor4f(0.0, 1.0, 0.0, context.scene.dt_custom_props.a) blf.position(font_id, q_loc_2d[0] + 4, q_loc_2d[1] + 4 + font_size + 4, 0) blf.draw(font_id, 'y ' + str(round((q - ip_y).length, 4))) bgl.glColor4f(0.0, 0.0, 1.0, context.scene.dt_custom_props.a) blf.position(font_id, q_loc_2d[0] + 4, q_loc_2d[1] + 4, 0) blf.draw(font_id, 'z ' + str(round((q - ip_z).length, 4))) # -- -- -- -- mouse location if context.scene.dt_custom_props.b4 == True: rgn = context.region # region rgn_3d = context.space_data.region_3d # region 3d bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 1.0, 1.0, context.scene.dt_custom_props.a) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(0, dt_buf.y ) bgl.glVertex2f(dt_buf.x - 15, dt_buf.y) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 1.0, 1.0, context.scene.dt_custom_props.a) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(rgn.width, dt_buf.y ) bgl.glVertex2f(dt_buf.x + 15, dt_buf.y) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 1.0, 1.0, context.scene.dt_custom_props.a) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(dt_buf.x, 0 ) bgl.glVertex2f(dt_buf.x, dt_buf.y - 15) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 1.0, 1.0, context.scene.dt_custom_props.a) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(dt_buf.x, rgn.height ) bgl.glVertex2f(dt_buf.x, dt_buf.y + 15) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) bgl.glDisable(bgl.GL_LINE_STIPPLE) t = str(dt_buf.x) + ', ' + str(dt_buf.y) lo = region_2d_to_location_3d(context.region, context.space_data.region_3d, Vector((dt_buf.x, dt_buf.y)), Vector((0.0, 0.0, 0.0))) t1 = '( ' + str(round(lo[0], 4)) + ', ' + str(round(lo[1], 4)) + ', ' + str(round(lo[2], 4)) + ' )' bgl.glColor4f(1.0, 1.0, 1.0, context.scene.dt_custom_props.a) blf.position(font_id, dt_buf.x + 15, dt_buf.y + 15, 0) blf.size(font_id, 14, context.user_preferences.system.dpi) blf.draw(font_id, t1 if context.scene.dt_custom_props.b5 == True else t) bgl.glDisable(bgl.GL_LINE_STIPPLE) # -- -- -- -- angles if context.scene.dt_custom_props.b3 == True: list_ek = [[v.index for v in e.verts] for e in bme.verts[list_0[0]].link_edges] n1 = len(list_ek) for j in range(n1): vec1 = p - bme.verts[[ i for i in list_ek[j] if i != list_0[0] ][0]].co.copy() vec2 = p - bme.verts[[ i for i in list_ek[(j + 1) % n1] if i != list_0[0]][0]].co.copy() ang = vec1.angle(vec2) a_loc_2d = location_3d_to_region_2d(context.region, context.space_data.region_3d, mtrx * (((p - (vec1.normalized() * 0.1)) + (p - (vec2.normalized() * 0.1))) * 0.5)) bgl.glColor4f(0.0, 0.757, 1.0, context.scene.dt_custom_props.a) blf.position(font_id, a_loc_2d[0], a_loc_2d[1], 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round(ang, 4) if context.scene.dt_custom_props.b6 == True else round(degrees(ang), 2))) # -- -- -- -- tool on/off bgl.glColor4f(1.0, 1.0, 1.0, 1.0) blf.position(font_id, 150, 10, 0) blf.size(font_id, 20, context.user_preferences.system.dpi) blf.draw(font_id, 'Ruler On')
def enable_stipple(self): bgl.glLineStipple(4, 0x5555) bgl.glEnable(bgl.GL_LINE_STIPPLE)
def draw_callback_px(self, context): font_id = 0 alpha = context.scene.pen_tool_props.a font_size = context.scene.pen_tool_props.fs bgl.glColor4f(0.0, 0.6, 1.0, alpha) bgl.glPointSize(4.0) bgl.glBegin(bgl.GL_POINTS) bgl.glVertex2f(pt_buf.x, pt_buf.y) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) # location 3d if context.scene.pen_tool_props.b2 is True: mloc3d = region_2d_to_location_3d( context.region, context.space_data.region_3d, Vector((pt_buf.x, pt_buf.y)), pt_buf.depth_location ) blf.position(font_id, pt_buf.x + 15, pt_buf.y - 15, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, '(' + str(round(mloc3d[0], 4)) + ', ' + str(round(mloc3d[1], 4)) + ', ' + str(round(mloc3d[2], 4)) + ')') n = len(pt_buf.list_m_loc_3d) if n != 0: # add points bgl.glEnable(bgl.GL_BLEND) bgl.glPointSize(4.0) bgl.glBegin(bgl.GL_POINTS) for i in pt_buf.list_m_loc_3d: loc_0 = location_3d_to_region_2d( context.region, context.space_data.region_3d, i ) bgl.glVertex2f(loc_0[0], loc_0[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) # text next to the mouse m_loc_3d = region_2d_to_location_3d( context.region, context.space_data.region_3d, Vector((pt_buf.x, pt_buf.y)), pt_buf.depth_location ) vec0 = pt_buf.list_m_loc_3d[-1] - m_loc_3d blf.position(font_id, pt_buf.x + 15, pt_buf.y + 15, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round(vec0.length, 4))) # angle first after mouse if n >= 2: vec1 = pt_buf.list_m_loc_3d[-2] - pt_buf.list_m_loc_3d[-1] if vec0.length == 0.0 or vec1.length == 0.0: pass else: ang = vec0.angle(vec1) if round(degrees(ang), 2) == 180.0: text_0 = '0.0' elif round(degrees(ang), 2) == 0.0: text_0 = '180.0' else: text_0 = str(round(degrees(ang), 2)) loc_4 = location_3d_to_region_2d( context.region, context.space_data.region_3d, pt_buf.list_m_loc_3d[-1] ) bgl.glColor4f(0.0, 1.0, 0.525, alpha) blf.position(font_id, loc_4[0] + 10, loc_4[1] + 10, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, text_0 + '') bgl.glLineStipple(4, 0x5555) bgl.glEnable(bgl.GL_LINE_STIPPLE) # enable line stipple bgl.glColor4f(0.0, 0.6, 1.0, alpha) # draw line between last point and mouse bgl.glEnable(bgl.GL_BLEND) bgl.glBegin(bgl.GL_LINES) loc_1 = location_3d_to_region_2d( context.region, context.space_data.region_3d, pt_buf.list_m_loc_3d[-1] ) bgl.glVertex2f(loc_1[0], loc_1[1]) bgl.glVertex2f(pt_buf.x, pt_buf.y) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) # draw lines between points bgl.glEnable(bgl.GL_BLEND) bgl.glBegin(bgl.GL_LINE_STRIP) for j in pt_buf.list_m_loc_3d: loc_2 = location_3d_to_region_2d(context.region, context.space_data.region_3d, j) bgl.glVertex2f(loc_2[0], loc_2[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) bgl.glDisable(bgl.GL_LINE_STIPPLE) # disable line stipple # draw line length between points if context.scene.pen_tool_props.b1 is True: for k in range(n - 1): loc_3 = location_3d_to_region_2d( context.region, context.space_data.region_3d, (pt_buf.list_m_loc_3d[k] + pt_buf.list_m_loc_3d[(k + 1) % n]) * 0.5 ) blf.position(font_id, loc_3[0] + 10, loc_3[1] + 10, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round((pt_buf.list_m_loc_3d[k] - pt_buf.list_m_loc_3d[(k + 1) % n]).length, 4))) # draw all angles if context.scene.pen_tool_props.b0 is True: for h in range(n - 1): if n >= 2: if h == 0: pass else: vec_ = pt_buf.list_m_loc_3d[h] - pt_buf.list_m_loc_3d[(h - 1) % n] vec_1_ = pt_buf.list_m_loc_3d[h] vec_2_ = pt_buf.list_m_loc_3d[(h - 1) % n] if vec_.length == 0.0 or vec_1_.length == 0.0 or vec_2_.length == 0.0: pass else: ang = vec_.angle(vec_1_ - vec_2_) if round(degrees(ang)) == 0.0: pass else: loc_4 = location_3d_to_region_2d( context.region, context.space_data.region_3d, pt_buf.list_m_loc_3d[h] ) bgl.glColor4f(0.0, 1.0, 0.525, alpha) blf.position(font_id, loc_4[0] + 10, loc_4[1] + 10, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round(degrees(ang), 2)) + '') # tools on / off bgl.glColor4f(1.0, 1.0, 1.0, 1.0) blf.position(font_id, self.text_location, 20, 0) blf.size(font_id, 15, context.user_preferences.system.dpi) blf.draw(font_id, "Draw On") blf.position(font_id, self.text_location, 40, 0) blf.draw(font_id, "Extrude On" if pt_buf.ctrl else "Extrude Off")
def draw_matrix(mat): zero_tx = mat * zero glLineWidth(2.0) # x glColor3f(1.0, 0.2, 0.2) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * x_p)) glEnd() glColor3f(0.6, 0.0, 0.0) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * x_n)) glEnd() # y glColor3f(0.2, 1.0, 0.2) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * y_p)) glEnd() glColor3f(0.0, 0.6, 0.0) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * y_n)) glEnd() # z glColor3f(0.2, 0.2, 1.0) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * z_p)) glEnd() glColor3f(0.0, 0.0, 0.6) glBegin(GL_LINES) glVertex3f(*(zero_tx)) glVertex3f(*(mat * z_n)) glEnd() # bounding box vertices i = 0 glColor3f(1.0, 1.0, 1.0) series1 = (-0.5, -0.3, -0.1, 0.1, 0.3, 0.5) series2 = (-0.5, 0.5) z = 0 for x in series1: for y in series2: bb[i][:] = x, y, z bb[i] = mat * bb[i] i += 1 for y in series1: for x in series2: bb[i][:] = x, y, z bb[i] = mat * bb[i] i += 1 # bounding box drawing glLineWidth(1.0) glLineStipple(1, 0xAAAA) glEnable(GL_LINE_STIPPLE) for i in range(0,24,2): glBegin(GL_LINE_STRIP) glVertex3f(*bb[i]) glVertex3f(*bb[i+1]) glEnd()
def draw_callback_wg_view(context): gta_tools = bpy.context.scene.gta_tools global wg_state if 'VIEW_3D' != bpy.context.space_data.type: return if 'EDIT' != bpy.context.active_object.mode: return draw_size = gta_tools.weight_props.wg_line_size draw_alpha = gta_tools.weight_props.wg_line_alpha if "PLANE" == gta_tools.weight_props.grad_contour: if wg_state.enabled[1]: bgl.glEnable(bgl.GL_BLEND) bgl.glShadeModel(bgl.GL_SMOOTH) # 1st Point col_1st = get_heat4f(gta_tools.weight_props.grad_range[0], draw_alpha) col_2nd = get_heat4f(gta_tools.weight_props.grad_range[1], draw_alpha) loc_1st = wg_state.cur_loc[1] bgl.glPointSize(draw_size) bgl.glBegin(bgl.GL_POINTS) bgl.glColor4f(*col_1st) bgl.glVertex3f(*loc_1st) bgl.glEnd() if wg_state.enabled[2]: # 2nd Point loc_2nd = wg_state.cur_loc[2] bgl.glPointSize(draw_size) bgl.glBegin(bgl.GL_POINTS) bgl.glColor4f(*col_2nd) bgl.glVertex3f(*loc_2nd) bgl.glEnd() else: loc_2nd = bpy.context.scene.cursor_location q = get_heat4f_line( [gta_tools.weight_props.grad_range[0], loc_1st], [gta_tools.weight_props.grad_range[1], loc_2nd], draw_alpha) bgl.glLineWidth(draw_size) bgl.glBegin(bgl.GL_LINE_STRIP) for i in q: bgl.glColor4f(*i[2]) bgl.glVertex3f(*i[1]) bgl.glEnd() # restore opengl defaults bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0) else: if wg_state.enabled[0]: bgl.glEnable(bgl.GL_BLEND) bgl.glEnable(bgl.GL_LINE_STIPPLE) bgl.glShadeModel(bgl.GL_SMOOTH) # Gradient Center if wg_state.enabled[0]: if wg_state.enabled[1]: col_center = (0.5, 0.5, 0.5, draw_alpha) else: col_center = (1.0, 1.0, 1.0, draw_alpha) loc_center = wg_state.cur_loc[0] bgl.glPointSize(draw_size) bgl.glBegin(bgl.GL_POINTS) bgl.glColor4f(*col_center) bgl.glVertex3f(*loc_center) bgl.glEnd() # 1st Point if wg_state.enabled[1]: loc_1st = wg_state.cur_loc[1] bgl.glPointSize(draw_size) bgl.glBegin(bgl.GL_POINTS) bgl.glColor4f(*col_center) bgl.glVertex3f(*loc_1st) bgl.glEnd() else: loc_1st = bpy.context.scene.cursor_location bgl.glLineWidth(1.0) bgl.glLineStipple(1, 0xcccc) bgl.glBegin(bgl.GL_LINE_STRIP) bgl.glColor4f(*col_center) bgl.glVertex3f(*loc_center) bgl.glVertex3f(*loc_1st) bgl.glEnd() # 2nd Point if wg_state.enabled[1]: col_2nd = get_heat4f(gta_tools.weight_props.grad_range[1], draw_alpha) if wg_state.enabled[2]: loc_2nd = wg_state.cur_loc[2] bgl.glPointSize(draw_size) bgl.glBegin(bgl.GL_POINTS) bgl.glColor4f(*col_2nd) bgl.glVertex3f(*loc_2nd) bgl.glEnd() else: loc_2nd = bpy.context.scene.cursor_location col_mid = get_heat4f(gta_tools.weight_props.grad_range[0], draw_alpha) loc_mid = calc_midpoint(loc_center, loc_1st, loc_2nd) bgl.glLineWidth(1.0) bgl.glLineStipple(1, 0xcccc) bgl.glBegin(bgl.GL_LINE_STRIP) bgl.glColor4f(*col_center) bgl.glVertex3f(*loc_center) bgl.glVertex3f(*loc_mid) bgl.glEnd() bgl.glPointSize(draw_size) bgl.glBegin(bgl.GL_POINTS) bgl.glColor4f(*col_mid) bgl.glVertex3f(*loc_mid) bgl.glEnd() q = get_heat4f_line( [gta_tools.weight_props.grad_range[0], loc_mid], [gta_tools.weight_props.grad_range[1], loc_2nd], draw_alpha) bgl.glLineWidth(draw_size) bgl.glLineStipple(1, 0xffff) bgl.glBegin(bgl.GL_LINE_STRIP) for i in q: bgl.glColor4f(*i[2]) bgl.glVertex3f(*i[1]) bgl.glEnd() # restore opengl defaults bgl.glLineWidth(1) bgl.glDisable(bgl.GL_LINE_STIPPLE) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_callback_px(self, context): if context.mode == "EDIT_MESH": en0 = context.scene.dt_custom_props.en0 font_id = 0 font_size = context.scene.dt_custom_props.fs ob_act = context.active_object bme = bmesh.from_edit_mesh(ob_act.data) mtrx = ob_act.matrix_world list_0 = [v.index for v in bme.verts if v.select] if len(list_0) != 0: p = bme.verts[list_0[0]].co.copy() p_loc_2d = location_3d_to_region_2d(context.region, context.space_data.region_3d, p) q = mtrx * bme.verts[list_0[0]].co.copy() q_loc_2d = location_3d_to_region_2d(context.region, context.space_data.region_3d, q) # -- -- -- -- distance to adjacent vertices if context.scene.dt_custom_props.b0 == True: list_ = [[v.index for v in e.verts] for e in bme.verts[list_0[0]].link_edges] for ek in list_: vi = [i for i in ek if i != list_0[0]][0] p1 = bme.verts[vi].co.copy() loc_0_3d = mtrx * ((p + p1) * 0.5) loc_0_2d = location_3d_to_region_2d( context.region, context.space_data.region_3d, loc_0_3d) bgl.glColor4f(1.0, 1.0, 0.0, context.scene.dt_custom_props.a) blf.position(font_id, loc_0_2d[0] + 4, loc_0_2d[1] + 4, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round((p - p1).length, 4))) bgl.glLineStipple(4, 0xAAAA) bgl.glEnable(bgl.GL_LINE_STIPPLE) # -- -- -- -- distance to axis local global if context.scene.dt_custom_props.b1 == True: # -- -- -- -- local if en0 == 'opt0': # -- -- -- -- x axis px = mtrx * Vector((0.0, p[1], p[2])) px_loc_2d = location_3d_to_region_2d( context.region, context.space_data.region_3d, px) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 0.0, 0.0, context.scene.dt_custom_props.a) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(q_loc_2d[0], q_loc_2d[1]) bgl.glVertex2f(px_loc_2d[0], px_loc_2d[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) if context.scene.dt_custom_props.b2 == False: lx = (q_loc_2d + px_loc_2d) * 0.5 bgl.glColor4f(1.0, 0.0, 0.0, context.scene.dt_custom_props.a) blf.position(font_id, lx[0] + 4, lx[1] + 4, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round(p[0], 4))) # -- -- -- -- y axis py = mtrx * Vector((p[0], 0.0, p[2])) py_loc_2d = location_3d_to_region_2d( context.region, context.space_data.region_3d, py) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(0.0, 1.0, 0.0, context.scene.dt_custom_props.a) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(q_loc_2d[0], q_loc_2d[1]) bgl.glVertex2f(py_loc_2d[0], py_loc_2d[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) if context.scene.dt_custom_props.b2 == False: ly = (q_loc_2d + py_loc_2d) * 0.5 bgl.glColor4f(0.0, 1.0, 0.0, context.scene.dt_custom_props.a) blf.position(font_id, ly[0] + 4, ly[1] + 4, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round(p[1], 4))) # -- -- -- -- z axis pz = mtrx * Vector((p[0], p[1], 0.0)) pz_loc_2d = location_3d_to_region_2d( context.region, context.space_data.region_3d, pz) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 1.0, context.scene.dt_custom_props.a) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(q_loc_2d[0], q_loc_2d[1]) bgl.glVertex2f(pz_loc_2d[0], pz_loc_2d[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) if context.scene.dt_custom_props.b2 == False: lz = (q_loc_2d + pz_loc_2d) * 0.5 bgl.glColor4f(0.0, 0.0, 1.0, context.scene.dt_custom_props.a) blf.position(font_id, lz[0] + 4, lz[1] + 4, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round(p[2], 4))) # -- -- -- -- if context.scene.dt_custom_props.b2 == True and context.scene.dt_custom_props.b1 == True: blf.size(font_id, font_size, context.user_preferences.system.dpi) bgl.glColor4f(1.0, 0.0, 0.0, context.scene.dt_custom_props.a) blf.position( font_id, q_loc_2d[0] + 4, q_loc_2d[1] + 4 + font_size + 4 + font_size + 4, 0) blf.draw(font_id, 'x ' + str(round(p[0], 4))) bgl.glColor4f(0.0, 1.0, 0.0, context.scene.dt_custom_props.a) blf.position(font_id, q_loc_2d[0] + 4, q_loc_2d[1] + 4 + font_size + 4, 0) blf.draw(font_id, 'y ' + str(round(p[1], 4))) bgl.glColor4f(0.0, 0.0, 1.0, context.scene.dt_custom_props.a) blf.position(font_id, q_loc_2d[0] + 4, q_loc_2d[1] + 4, 0) blf.draw(font_id, 'z ' + str(round(p[2], 4))) # -- -- -- -- global elif en0 == 'opt1': # -- -- -- -- x axis ip_x = intersect_line_plane( q, q + (Vector((1.0, 0.0, 0.0)) * 0.1), Vector((0.0, 1.0, 0.0)), Vector((1.0, 0.0, 0.0))) ip_x_loc_2d = location_3d_to_region_2d( context.region, context.space_data.region_3d, ip_x) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 0.0, 0.0, context.scene.dt_custom_props.a) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(q_loc_2d[0], q_loc_2d[1]) bgl.glVertex2f(ip_x_loc_2d[0], ip_x_loc_2d[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) if context.scene.dt_custom_props.b2 == False: loc_1_2d = (q_loc_2d + ip_x_loc_2d) * 0.5 bgl.glColor4f(1.0, 0.0, 0.0, context.scene.dt_custom_props.a) blf.position(font_id, loc_1_2d[0] + 4, loc_1_2d[1] + 4, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round((q - ip_x).length, 4))) # -- -- -- -- y axis ip_y = intersect_line_plane( q, q + (Vector((0.0, 1.0, 0.0)) * 0.1), Vector((1.0, 0.0, 0.0)), Vector((0.0, 1.0, 0.0))) ip_y_loc_2d = location_3d_to_region_2d( context.region, context.space_data.region_3d, ip_y) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(0.0, 1.0, 0.0, context.scene.dt_custom_props.a) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(q_loc_2d[0], q_loc_2d[1]) bgl.glVertex2f(ip_y_loc_2d[0], ip_y_loc_2d[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) if context.scene.dt_custom_props.b2 == False: loc_2_2d = (q_loc_2d + ip_y_loc_2d) * 0.5 bgl.glColor4f(0.0, 1.0, 0.0, context.scene.dt_custom_props.a) blf.position(font_id, loc_2_2d[0] + 4, loc_2_2d[1] + 4, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round((q - ip_y).length, 4))) # -- -- -- -- z axis ip_z = intersect_line_plane( q, q + (Vector((0.0, 0.0, 1.0)) * 0.1), Vector((1.0, 0.0, 0.0)), Vector((0.0, 0.0, 1.0))) ip_z_loc_2d = location_3d_to_region_2d( context.region, context.space_data.region_3d, ip_z) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 1.0, context.scene.dt_custom_props.a) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(q_loc_2d[0], q_loc_2d[1]) bgl.glVertex2f(ip_z_loc_2d[0], ip_z_loc_2d[1]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) if context.scene.dt_custom_props.b2 == False: loc_3_2d = (q_loc_2d + ip_z_loc_2d) * 0.5 bgl.glColor4f(0.0, 0.0, 1.0, context.scene.dt_custom_props.a) blf.position(font_id, loc_3_2d[0] + 4, loc_3_2d[1] + 4, 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw(font_id, str(round((q - ip_z).length, 4))) # -- -- -- -- if context.scene.dt_custom_props.b2 == True and context.scene.dt_custom_props.b1 == True: blf.size(font_id, font_size, context.user_preferences.system.dpi) bgl.glColor4f(1.0, 0.0, 0.0, context.scene.dt_custom_props.a) blf.position( font_id, q_loc_2d[0] + 4, q_loc_2d[1] + 4 + font_size + 4 + font_size + 4, 0) blf.draw(font_id, 'x ' + str(round((q - ip_x).length, 4))) bgl.glColor4f(0.0, 1.0, 0.0, context.scene.dt_custom_props.a) blf.position(font_id, q_loc_2d[0] + 4, q_loc_2d[1] + 4 + font_size + 4, 0) blf.draw(font_id, 'y ' + str(round((q - ip_y).length, 4))) bgl.glColor4f(0.0, 0.0, 1.0, context.scene.dt_custom_props.a) blf.position(font_id, q_loc_2d[0] + 4, q_loc_2d[1] + 4, 0) blf.draw(font_id, 'z ' + str(round((q - ip_z).length, 4))) # -- -- -- -- mouse location if context.scene.dt_custom_props.b4 == True: rgn = context.region # region rgn_3d = context.space_data.region_3d # region 3d bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 1.0, 1.0, context.scene.dt_custom_props.a) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(0, dt_buf.y) bgl.glVertex2f(dt_buf.x - 15, dt_buf.y) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 1.0, 1.0, context.scene.dt_custom_props.a) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(rgn.width, dt_buf.y) bgl.glVertex2f(dt_buf.x + 15, dt_buf.y) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 1.0, 1.0, context.scene.dt_custom_props.a) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(dt_buf.x, 0) bgl.glVertex2f(dt_buf.x, dt_buf.y - 15) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 1.0, 1.0, context.scene.dt_custom_props.a) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(dt_buf.x, rgn.height) bgl.glVertex2f(dt_buf.x, dt_buf.y + 15) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) bgl.glDisable(bgl.GL_LINE_STIPPLE) t = str(dt_buf.x) + ', ' + str(dt_buf.y) lo = region_2d_to_location_3d(context.region, context.space_data.region_3d, Vector((dt_buf.x, dt_buf.y)), Vector((0.0, 0.0, 0.0))) t1 = '( ' + str(round(lo[0], 4)) + ', ' + str(round( lo[1], 4)) + ', ' + str(round(lo[2], 4)) + ' )' bgl.glColor4f(1.0, 1.0, 1.0, context.scene.dt_custom_props.a) blf.position(font_id, dt_buf.x + 15, dt_buf.y + 15, 0) blf.size(font_id, 14, context.user_preferences.system.dpi) blf.draw(font_id, t1 if context.scene.dt_custom_props.b5 == True else t) bgl.glDisable(bgl.GL_LINE_STIPPLE) # -- -- -- -- angles if context.scene.dt_custom_props.b3 == True: list_ek = [[v.index for v in e.verts] for e in bme.verts[list_0[0]].link_edges] n1 = len(list_ek) for j in range(n1): vec1 = p - bme.verts[[ i for i in list_ek[j] if i != list_0[0] ][0]].co.copy() vec2 = p - bme.verts[[ i for i in list_ek[(j + 1) % n1] if i != list_0[0] ][0]].co.copy() ang = vec1.angle(vec2) a_loc_2d = location_3d_to_region_2d( context.region, context.space_data.region_3d, mtrx * (((p - (vec1.normalized() * 0.1)) + (p - (vec2.normalized() * 0.1))) * 0.5)) bgl.glColor4f(0.0, 0.757, 1.0, context.scene.dt_custom_props.a) blf.position(font_id, a_loc_2d[0], a_loc_2d[1], 0) blf.size(font_id, font_size, context.user_preferences.system.dpi) blf.draw( font_id, str( round(ang, 4) if context.scene.dt_custom_props. b6 == True else round(degrees(ang), 2))) # -- -- -- -- tool on/off bgl.glColor4f(1.0, 1.0, 1.0, 1.0) blf.position(font_id, 150, 10, 0) blf.size(font_id, 20, context.user_preferences.system.dpi) blf.draw(font_id, 'Ruler On')