def draw_dot(position, size, color): glColor4f(*color) glEnable(GL_BLEND) glPointSize(size) glBegin(GL_POINTS) glVertex2f(*position) glEnd()
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)
def sync_draw_callback(self, context): # polling if context.mode != "EDIT_MESH": return # draw vertices bgl.glColor4f(1.0, 0.0, 0.0, 1.0) bgl.glPointSize(4) bgl.glBegin(bgl.GL_POINTS) for x, y in self.position_vertices: bgl.glVertex2i(x, y) bgl.glEnd() # draw edges bgl.glColor4f(1.0, 0.0, 0.0, 1.0) bgl.glLineWidth(1.5) bgl.glBegin(bgl.GL_LINES) for x, y in self.position_edges: bgl.glVertex2i(x, y) bgl.glEnd() bgl.glLineWidth(1) # draw faces bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 0.0, 0.0, 0.3) bgl.glBegin(bgl.GL_QUADS) for x, y in self.position_faces: bgl.glVertex2i(x, y) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND)
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_3d_points_and_index(context, points, color, size): ''' draw a bunch of dots args: points: a list of tuples representing x,y SCREEN coordinate eg [(10,30),(11,31),...] color: tuple (r,g,b,a) size: integer? maybe a float ''' points_2d = [location_3d_to_region_2d(context.region, context.space_data.region_3d, loc) for loc in points] bgl.glColor4f(*color) bgl.glPointSize(size) bgl.glBegin(bgl.GL_POINTS) for coord in points_2d: #TODO: Debug this problem....perhaps loc_3d is returning points off of the screen. if coord: bgl.glVertex2f(*coord) else: continue bgl.glEnd() blf.size(0, 14, 72) for i, coord in enumerate(points_2d): blf.position(0,coord[0]+3, coord[1]+3, 0) blf.draw(0,str(i)) return
def screen_v3dBGL(context, args): region = context.region region3d = context.space_data.region_3d points = args[0] colors = args[1] size= 5.0 bgl.glEnable(bgl.GL_POINT_SMOOTH) # for round vertex bgl.glPointSize(size) bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA) if colors: bgl.glBegin(bgl.GL_POINTS) for coord, color in zip(points, colors): bgl.glColor4f(*color) bgl.glVertex3f(*coord) bgl.glEnd() else: gl_col = (0.9, 0.9, 0.8, 1.0) bgl.glColor4f(*gl_col) bgl.glBegin(bgl.GL_POINTS) for coord in points: bgl.glVertex3f(*coord) bgl.glEnd() bgl.glDisable(bgl.GL_POINT_SMOOTH) bgl.glDisable(bgl.GL_POINTS)
def draw_callback_px(self, context): bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 0.5) bgl.glLineWidth(2) if context.scene.curve_freehand.use_pressure: from mathutils import noise pt_a = self.mouse_path[0] for i in range(1, len(self.mouse_path)): # weak but good enough for preview pt_b = self.mouse_path[i] bgl.glPointSize(1 + (pt_a[2] * 40.0)) bgl.glBegin(bgl.GL_POINTS) bgl.glVertex2i(pt_a[0], pt_a[1]) bgl.glVertex2i(pt_b[0], pt_b[1]) bgl.glEnd() pt_a = pt_b else: bgl.glBegin(bgl.GL_LINE_STRIP) for pt in self.mouse_path: bgl.glVertex2i(pt[0], pt[1]) bgl.glEnd() bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_callback_px(self, context): 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() # 50% alpha, 2 pixel width line bgl.glColor4f(0.0, 1, 0.0, 1) bgl.glPointSize(5) bgl.glBegin(bgl.GL_POINTS) for v in self.spline_end_dict: bgl.glVertex2f(v[0], v[1]) 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_postview(self, context): ''' Called every frame to draw during modal ''' bgl.glEnable(bgl.GL_POINT_SMOOTH) bgl.glPointSize(1.5) bgl.glColor3d(0.1,0.1,0.1) bgl.glBegin(bgl.GL_POINTS) [bgl.glVertex3f(*v) for v in self.routedVertices] bgl.glPointSize(30) bgl.glColor3d(0,1,0) [bgl.glVertex3f(*v) for v in self.cntrlList] bgl.glEnd() bgl.glBegin(bgl.GL_LINES) bgl.glLineWidth(1) bgl.glColor3d(0.1,0.1,0.1) for i in range(1,len(self.routedVertices)-1): if(self.routedVertices[i][2] == self.routedVertices[i+1][2]): bgl.glVertex3f(*self.routedVertices[i]) bgl.glVertex3f(*self.routedVertices[i+1]) else: bgl.glVertex3f(*self.routedVertices[i]) bgl.glVertex3f(*self.routedVertices[i-self.numSegments+1]) startPos = 1 rotating = [False,False] if self.routedVertices[0][2] == self.routedVertices[1][2]: rotating[0] = True startPos = self.numSegments if self.routedVertices[-2][2] == self.routedVertices[-1][2]: rotating[1] = True if rotating[0]: # Bottom is rotating for i in range(0,self.numSegments): bgl.glVertex3f(*self.routedVertices[i]) bgl.glVertex3f(*self.routedVertices[i+self.numSegments]) else: # Bottom is single vertice for i in range(0,self.numSegments+1): bgl.glVertex3f(*self.routedVertices[0]) bgl.glVertex3f(*self.routedVertices[i]) if rotating[1]: # Top is rotating for i in range(0,self.numSegments): bgl.glVertex3f(*self.routedVertices[len(self.routedVertices)-i-1]) bgl.glVertex3f(*self.routedVertices[len(self.routedVertices)-i-1-self.numSegments]) else: # Top is single vertice for i in range(0,self.numSegments): bgl.glVertex3f(*self.routedVertices[len(self.routedVertices)-1]) bgl.glVertex3f(*self.routedVertices[len(self.routedVertices)-i-1]) ''' Everything in the middle ''' for j in range(1,len(self.bezierVertices)-2): for i in range(0,self.numSegments+1): a = i+startPos b = a+self.numSegments bgl.glVertex3f(*self.routedVertices[a]) bgl.glVertex3f(*self.routedVertices[b]) startPos += self.numSegments bgl.glEnd()
def draw_points_3d(points, color, size, far=0.997): bgl.glColor4f(*color) bgl.glPointSize(size) bgl.glDepthRange(0.0, far) bgl.glBegin(bgl.GL_POINTS) for coord in points: bgl.glVertex3f(*coord) bgl.glEnd() bgl.glPointSize(1.0)
def draw3d_points(context, points, color, size): bgl.glColor4f(*color) bgl.glPointSize(size) bgl.glDepthRange(0.0, 0.997) bgl.glBegin(bgl.GL_POINTS) for coord in points: bgl.glVertex3f(*coord) bgl.glEnd() bgl.glPointSize(1.0)
def draw3d_points(points, color, size, view_loc, view_ortho, zfar=0.997): if not points: return bgl.glColor4f(*color) bgl.glPointSize(size) set_depthrange(0.0, zfar, points, view_loc, view_ortho) bgl.glBegin(bgl.GL_POINTS) for coord in points: bgl.glVertex3f(*coord) bgl.glEnd() bgl.glPointSize(1.0)
def drawCallback(): if bpy.context.mode == 'OBJECT': if do_draw[0]: # from math_viz glPointSize(5.0) glBegin(GL_POINTS) glColor3f(0.0, 1.0, 0.0) glVertex3f(*com[0]) glEnd() glPointSize(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 draw3d_points(context, points, color, size): if context.space_data.region_3d.view_perspective == 'ORTHO': bias = 0.9997 else: bias = 0.997 bgl.glColor4f(*color) bgl.glPointSize(size) bgl.glDepthRange(0.0, bias) bgl.glBegin(bgl.GL_POINTS) for coord in points: bgl.glVertex3f(*coord) bgl.glEnd() bgl.glPointSize(1.0)
def draw3d_points(context, points, color, size, mirror): #if type(points) is types.GeneratorType: # points = list(points) points = [mirror(pt) for pt in points] if len(points) == 0: return bgl.glColor4f(*color) bgl.glPointSize(size) set_depthrange(0.0, 0.997, points) bgl.glBegin(bgl.GL_POINTS) for coord in points: bgl.glVertex3f(*coord) bgl.glEnd() bgl.glPointSize(1.0)
def sync_draw_callback2(self, context): # polling if context.mode != "EDIT_MESH": return # draw vertices bgl.glColor4f(1.0, 0.0, 0.0, 1.0) bgl.glPointSize(6) bgl.glBegin(bgl.GL_POINTS) for x, y in self.position2_vertices: bgl.glVertex2f(x, y) bgl.glEnd()
def drawCallback(self): if self.running and bpy.context.mode == 'EDIT_MESH' and not self.flag: glEnable(GL_BLEND) if self.depth_test: glEnable(GL_DEPTH_TEST) else: glDisable(GL_DEPTH_TEST) if self.select_faces and self.face_opacity and self.draw_face is not None: glBegin(GL_POLYGON) self.set_glColor_face() for vertex in self.draw_face: glVertex3f(*vertex) glEnd() if ((self.select_edges or self.select_faces) and self.edge_opacity and self.draw_edges): glLineWidth(self.edge_width) glBegin(GL_LINES) self.set_glColor_edge() for edge in self.draw_edges: glVertex3f(*edge[0]) glVertex3f(*edge[1]) glEnd() if self.select_verts and self.vert_opacity and self.draw_verts: glPointSize(self.vert_radius) glBegin(GL_POINTS) self.set_glColor_vert() for vertex in self.draw_verts: glVertex3f(*vertex) glEnd() glLineWidth(1.0) glPointSize(1.0) # if multiple redraws without modal running inbetween # -> face could have been changed/... (i.e. other modal running) # so avoid drawing outdated data self.flag = True
def draw_callback_view(): pointclouds = [ob for ob in bpy.context.visible_objects if "is_pointcloud" in ob and ob["is_pointcloud"]] if not pointclouds: return from bgl import glPointSize, glEnable, GL_BLEND, glBegin, GL_POINTS, \ glColor3f, glColor4f, glColor3ub, glColor4ub, glVertex3f, glEnd, glDisable point_size = bpy.context.user_preferences.addons[__name__].preferences.point_size glPointSize(point_size) glEnable(GL_BLEND) glBegin(GL_POINTS) for ob in pointclouds: matrix_world = ob.matrix_world color = tuple(ob.color) alpha = color[3] use_alpha = ob.show_transparent if "pointcloud_has_rgba" in ob and ob["pointcloud_has_rgba"]: # draw individual vertex color bm = bmesh.new() bm.from_mesh(ob.data) # Get the custom data layer by its name r = bm.verts.layers.float['r'] g = bm.verts.layers.float['g'] b = bm.verts.layers.float['b'] if use_alpha: a = bm.verts.layers.float['a'] for vert in bm.verts: glColor4f(vert[r], vert[g], vert[b], vert[a] * alpha) glVertex3f(*(matrix_world * vert.co)) else: for vert in bm.verts: glColor3f(vert[r], vert[g], vert[b]) glVertex3f(*(matrix_world * vert.co)) del bm else: # draw same color for all vertices if use_alpha: glColor4f(*color) else: glColor3f(*color[0:3]) for vert in ob.data.vertices: glVertex3f(*(matrix_world * vert.co)) glEnd() glDisable(GL_BLEND) glPointSize(1.0)
def draw_point(position, size=2, color=(1.0, 0.2, 0.2, 1.0)): """Draw single red point""" bgl.glEnable(bgl.GL_POINT_SMOOTH) bgl.glPointSize(size) bgl.glColor4f(*color) vec2d = to_screen_coord(position) if vec2d: bgl.glBegin(bgl.GL_POINTS) bgl.glVertex2f(*vec2d) bgl.glEnd() bgl.glDisable(bgl.GL_POINT_SMOOTH)
def draw_postview(self, context): ''' Place drawing code in here ''' # Setup bgl.glEnable(bgl.GL_POINT_SMOOTH) bgl.glPointSize(5) # Setup control point lines for key in self.extrudePoints: aList = self.extrudePoints[key] self.linkPoints(aList[:2]) self.linkPoints(aList[2:4]) self.drawCurvePoints() self.calculateCurveExtrudeLines()
def mi_draw_2d_point(point_x, point_y, p_size=4, p_col=(1.0, 1.0, 1.0, 1.0)): bgl.glEnable(bgl.GL_BLEND) # bgl.glColor4f(1.0, 1.0, 1.0, 0.5) # bgl.glLineWidth(2) bgl.glPointSize(p_size) # bgl.glBegin(bgl.GL_LINE_LOOP) bgl.glBegin(bgl.GL_POINTS) # bgl.glBegin(bgl.GL_POLYGON) bgl.glColor4f(p_col[0], p_col[1], p_col[2], p_col[3]) bgl.glVertex2f(point_x, point_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_points(context, points, color, size): ''' draw a bunch of dots args: points: a list of tuples representing x,y SCREEN coordinate eg [(10,30),(11,31),...] color: tuple (r,g,b,a) size: integer? maybe a float ''' bgl.glColor4f(*color) bgl.glPointSize(size) bgl.glBegin(bgl.GL_POINTS) for coord in points: bgl.glVertex2f(*coord) bgl.glEnd() return
def draw_brush_influence(self, brush, coordinate_map): if not self.is_enabled: return bgl.glPointSize( bpy.context.user_preferences.themes['Default'].view_3d.vertex_size) # Draw each vertex using its corresponding color map value. brush_indices = brush.indices brush_color_map = brush.color_map bgl.glBegin(bgl.GL_POINTS) for index in brush_indices: bgl.glColor3f(*brush_color_map[index]) bgl.glVertex3f(*coordinate_map[index]) bgl.glEnd() self.restore_opengl()
def render_opengl_image(image_name, cam, point_size): draw_manager = DrawManager.get_singleton() coords, colors = draw_manager.get_coords_and_colors() scene = bpy.context.scene render = bpy.context.scene.render width = render.resolution_x height = render.resolution_y # TODO Provide an option to render from the 3D view perspective # width = bpy.context.region.width # height = bpy.context.region.height offscreen = gpu.types.GPUOffScreen(width, height) with offscreen.bind(): bgl.glPointSize(point_size) bgl.glEnable(bgl.GL_DEPTH_TEST) # bgl.glClear(bgl.GL_COLOR_BUFFER_BIT) # bgl.glClear(bgl.GL_DEPTH_BUFFER_BIT) view_matrix = cam.matrix_world.inverted() projection_matrix = cam.calc_matrix_camera( bpy.context.evaluated_depsgraph_get(), x=width, y=height) perspective_matrix = projection_matrix @ view_matrix gpu.matrix.load_matrix(perspective_matrix) gpu.matrix.load_projection_matrix(Matrix.Identity(4)) shader = gpu.shader.from_builtin("3D_FLAT_COLOR") shader.bind() batch = batch_for_shader(shader, "POINTS", { "pos": coords, "color": colors }) batch.draw(shader) buffer = bgl.Buffer(bgl.GL_BYTE, width * height * 4) bgl.glReadPixels(0, 0, width, height, bgl.GL_RGBA, bgl.GL_UNSIGNED_BYTE, buffer) offscreen.free() image = create_image_lazy(image_name, width, height) copy_buffer_to_pixel(buffer, image)
def drawPivotRed(): if bpy.context.scene.pivot_pro_enabled: oldPivot = bpy.data.objects.get("PivotPro", None) if oldPivot is not None: bgl.glEnable(bgl.GL_BLEND) bgl.glColor3f(1, 0, 0) bgl.glPointSize(10) bgl.glBegin(bgl.GL_POINTS) bgl.glVertex3f(*oldPivot.location) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) # restore defaults bgl.glPointSize(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor3f(0.0, 0.0, 0.0)
def draw_3d_points(context, points, color, size): ''' draw a bunch of dots args: points: a list of tuples representing x,y SCREEN coordinate eg [(10,30),(11,31),...] color: tuple (r,g,b,a) size: integer? maybe a float ''' points_2d = [location_3d_to_region_2d(context.region, context.space_data.region_3d, loc) for loc in points] bgl.glColor4f(*color) bgl.glPointSize(size) bgl.glBegin(bgl.GL_POINTS) for coord in points_2d: bgl.glVertex2f(*coord) bgl.glEnd() return
def drawPivotRed(): if bpy.context.scene.pivot_pro_enabled: oldPivot = bpy.data.objects.get('PivotPro', None) if oldPivot is not None: bgl.glEnable(bgl.GL_BLEND) bgl.glColor3f(1, 0, 0) bgl.glPointSize(10) bgl.glBegin(bgl.GL_POINTS) bgl.glVertex3f(*oldPivot.location) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND) # restore defaults bgl.glPointSize(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor3f(0.0, 0.0, 0.0)
def draw_brush_influence(self, brush, coordinate_map): if not self.is_enabled: return bgl.glPointSize( bpy.context.user_preferences.themes['Default'].view_3d.vertex_size ) # Draw each vertex using its corresponding color map value. brush_indices = brush.indices brush_color_map = brush.color_map bgl.glBegin(bgl.GL_POINTS) for index in brush_indices: bgl.glColor3f(*brush_color_map[index]) bgl.glVertex3f(*coordinate_map[index]) bgl.glEnd() self.restore_opengl()
def draw_callback_3d(cameras): # bgl.glDisable(bgl.GL_DEPTH_TEST) bgl.glEnable(bgl.GL_BLEND) bgl.glPointSize(4) bgl.glLineWidth(3) bgl.glBegin(bgl.GL_POINTS) for cam in cameras: bgl.glColor4f(*cam["color"], 0.5) for co in cam["co"]: bgl.glVertex3f(*co) bgl.glEnd() # Restore opengl defaults bgl.glPointSize(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_custom_3d_elements(mode): """Get's updated custom 3D elements and draws them :param mode: drawing mode for custom elements (can be: 'Normal' or 'X-ray') :type mode: str """ if mode == "Normal": glEnable(GL_DEPTH_TEST) glClear(GL_DEPTH_BUFFER_BIT) else: # X-ray mode disable_depth_test() context = bpy.context (prefab_locators, collision_locators, model_locators) = _get_custom_visual_elements() # PREFAB LOCATORS if context.scene.scs_props.display_locators: if prefab_locators: for obj in prefab_locators.values(): _locators.prefab.draw_prefab_locator(obj, context.scene.scs_props) # reset point size to 1.0 and set line width to 2.0 before drawing curves and lines glPointSize(1.0) glLineWidth(2.0) # CURVES AND LINES if context.scene.scs_props.display_connections: _connections_group_wrapper.draw(prefab_locators) # reset line width to 1.0 after drawing curves and lines glLineWidth(1.0) # COLLISION LOCATORS if context.scene.scs_props.display_locators: if collision_locators: for obj in collision_locators.values(): _locators.collider.draw_collision_locator(obj, context.scene.scs_props) # MODEL LOCATORS if context.scene.scs_props.display_locators: if model_locators: for obj in model_locators.values(): _locators.model.draw_model_locator(obj, context.scene.scs_props)
def draw_callback_2d(self, context): clear_draw = False try: if self._modal_running == False: clear_draw = True if context.area == self.area: bgl.glLineWidth(2) self.shader_2d.bind() self.shader_2d.uniform_float("color", (0.05, 0.05, 0.05, 1)) self.batch_rotate_screen_lines.draw(self.shader_2d) bgl.glLineWidth(1) self.shader_2d.bind() self.shader_2d.uniform_float("color", (1.0, 1.0, 1.0, 1)) self.batch_boxsel_screen_lines.draw(self.shader_2d) bgl.glLineWidth(1) self.shader_2d.bind() self.shader_2d.uniform_float("color", (1.0, 1.0, 1.0, 1)) self.batch_circlesel_screen_lines.draw(self.shader_2d) bgl.glLineWidth(1) self.shader_2d.bind() self.shader_2d.uniform_float("color", (1.0, 1.0, 1.0, 1)) self.batch_lassosel_screen_lines.draw(self.shader_2d) self._window.draw() bgl.glPointSize(2) self.batch_po = batch_for_shader(self.shader_2d, 'POINTS', {"pos": self._temp_po_draw}) self.shader_2d.bind() self.shader_2d.uniform_float("color", (1.0, 0.0, 0.0, 1)) self.batch_po.draw(self.shader_2d) except: clear_draw = True if clear_draw: print('Something is wrong clear out 2D Draw Handler') dns = bpy.app.driver_namespace dc = dns.get("dh2d") bpy.types.SpaceView3D.draw_handler_remove(dc, 'WINDOW') return
def draw_callback_bezier_3d(self, context): bgl.glEnable(bgl.GL_BLEND) bgl.glDepthFunc(bgl.GL_ALWAYS) bezier = self.beziers[self.spline_id][self.bezier_id] split = bezier.split(self.at) points = bezier.points bgl.glLineWidth(1.0) shader.bind() shader.uniform_float("color", (1, 1, 1, 0.5)) batch = batch_for_shader(shader, 'LINES', {"pos": points}) batch.draw(shader) bgl.glPointSize(6) shader.uniform_float("color", (1, 1, 1, 1)) batch = batch_for_shader(shader, 'POINTS', {"pos": [points[0], points[3]]}) batch.draw(shader) bgl.glPointSize(2) batch = batch_for_shader(shader, 'POINTS', {"pos": [points[1], points[2]]}) batch.draw(shader) # draw new bezier anchor bgl.glLineWidth(2) shader.uniform_float("color", (0.8, 1.0, 0.0, 0.5)) batch = batch_for_shader(shader, 'LINE_STRIP', {"pos": [split[2], split[3], split[4]]}) batch.draw(shader) bgl.glPointSize(10) shader.uniform_float("color", (0.2, 1, 0.0, 1.0)) batch = batch_for_shader(shader, 'POINTS', {"pos": [split[3]]}) batch.draw(shader) bgl.glPointSize(6) batch = batch_for_shader(shader, 'POINTS', {"pos": [split[2], split[4]]}) batch.draw(shader) # gl end and restore bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glEnable(bgl.GL_DEPTH_TEST) bgl.glPointSize(1)
def mi_curve_draw_3d_polyline(points, p_size=4, p_col=(1.0,1.0,1.0,1.0)): bgl.glEnable(bgl.GL_BLEND) bgl.glLineWidth(1) 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]) 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_points(context, points, size, gl_col): region = context.region rv3d = context.space_data.region_3d bgl.glEnable(bgl.GL_POINT_SMOOTH) bgl.glPointSize(size) bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA) bgl.glBegin(bgl.GL_POINTS) bgl.glColor4f(*gl_col) for coord in points: vector3d = (coord.x, coord.y, coord.z) vector2d = loc3d2d(region, rv3d, vector3d) bgl.glVertex2f(*vector2d) bgl.glEnd() bgl.glDisable(bgl.GL_POINT_SMOOTH) bgl.glDisable(bgl.GL_POINTS) return
def draw_2d_point(point_x, point_y, p_size=4, p_col=(1.0, 1.0, 1.0, 1.0)): bgl.glEnable(bgl.GL_BLEND) #bgl.glColor4f(1.0, 1.0, 1.0, 0.5) #bgl.glLineWidth(2) bgl.glPointSize(p_size) coords = ((point_x, point_y), (point_x, point_y)) batch = batch_for_shader(shader2d, 'POINTS', {"pos": coords}) shader2d.bind() shader2d.uniform_float("color", (p_col[0], p_col[1], p_col[2], p_col[3])) batch.draw(shader2d) # bgl.glBegin(bgl.GL_POINTS) # bgl.glColor4f(p_col[0], p_col[1], p_col[2], p_col[3]) # bgl.glVertex2f(point_x, point_y) # bgl.glEnd() # restore opengl defaults bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND)
def draw_lw(context, lw, cross_up_dir, draw_faloff): region = context.region rv3d = context.region_data start_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, lw.start_point.position) end_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, lw.end_point.position) middle_2d = view3d_utils.location_3d_to_region_2d(region, rv3d, lw.middle_point.position) dist_ends = ((lw.start_point.position - lw.end_point.position).length * 0.1) * cross_up_dir end_p1 = view3d_utils.location_3d_to_region_2d(region, rv3d, lw.end_point.position + dist_ends) end_p2 = view3d_utils.location_3d_to_region_2d(region, rv3d, lw.end_point.position - dist_ends) if start_2d and end_2d and end_p1 and end_p2: bgl.glEnable(bgl.GL_BLEND) bgl.glLineWidth(1) bgl.glPointSize(6) bgl.glBegin(bgl.GL_LINE_STRIP) bgl.glColor4f(0.99, 0.5, 0.99, 1.0) bgl.glVertex2f(start_2d[0], start_2d[1]) bgl.glVertex2f(end_2d[0], end_2d[1]) bgl.glEnd() if draw_faloff: bgl.glBegin(bgl.GL_LINE_LOOP) bgl.glColor4f(0.99, 0.5, 0.99, 1.0) bgl.glVertex2f(start_2d[0], start_2d[1]) bgl.glVertex2f(end_p1[0], end_p1[1]) bgl.glVertex2f(end_p2[0], end_p2[1]) bgl.glEnd() bgl.glBegin(bgl.GL_POINTS) # bgl.glBegin(bgl.GL_POLYGON) bgl.glColor4f(0.99, 0.8, 0.5, 1.0) bgl.glVertex2f(start_2d[0], start_2d[1]) bgl.glVertex2f(middle_2d[0], middle_2d[1]) bgl.glVertex2f(end_2d[0], end_2d[1]) bgl.glEnd() # restore opengl defaults bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_callback_view(self, context): bgl.glPointSize(8) #print('draw view!') if context.area.x == self.area_align.x: if not self.align_shader: return self.align_shader.bind() self.align_shader.uniform_float("color", (1, 0, 1, 1)) self.align_batch.draw(self.align_shader) else: if not self.base_shader: return self.base_shader.bind() self.base_shader.uniform_float("color", (1, 1, 0, 1)) self.base_batch.draw(self.base_shader) bgl.glPointSize(1) pass
def draw_postview(self): if not self.points_shader: return bgl.glDepthMask(bgl.GL_TRUE) bgl.glPointSize(8) bgl.glDepthFunc(bgl.GL_LEQUAL) self.points_shader.bind() self.points_shader.uniform_float("color", (1, 1, 1, 1)) self.points_batch.draw(self.points_shader) bgl.glDepthFunc(bgl.GL_LEQUAL) bgl.glDepthMask(bgl.GL_TRUE) bgl.glDepthRange(0, 1) #bgl.glDisable(bgl.GL_POINT_SMOOTH) #bgl.glDisable(bgl.GL_POINTS) bgl.glPointSize(1)
def draw_circle(center, radius): bgl.glPointSize(1) bgl.glColor4f(0, 0, 0, 1) bgl.glEnable(bgl.GL_BLEND) bgl.glBegin(bgl.GL_LINE_STRIP) r = radius t = 0 x0 = center.x y0 = center.y dt = math.pi * 2 / 20 while t < math.pi * 2: bgl.glVertex2f(x0 + r * math.cos(t), y0 + r * math.sin(t)) t += dt t = math.pi * 2 bgl.glVertex2f(x0 + r * math.cos(t), y0 + r * math.sin(t)) bgl.glEnd() restore_bgl()
def draw(self): bgl.glEnable(bgl.GL_BLEND) bgl.glLineWidth(self.handle_thickness) self.shader.bind() self.shader.uniform_float("color", self.color_handles) self.batch_handles.draw(self.shader) bgl.glDisable(bgl.GL_BLEND) bgl.glEnable(bgl.GL_BLEND) bgl.glPointSize(self.point_size) self.shader.bind() if self.select: self.shader.uniform_float("color", self.color_select) else: self.shader.uniform_float("color", self.color) self.batch.draw(self.shader) bgl.glDisable(bgl.GL_BLEND) return
def mi_curve_draw_3d_polyline(points, p_size=4, p_col=(1.0, 1.0, 1.0, 1.0)): bgl.glEnable(bgl.GL_BLEND) bgl.glLineWidth(1) 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]) bgl.glEnd() # restore opengl defaults bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def _start_drawing(self): # This handles all the settings of the renderer before starting the draw stuff if self.blend_mode == BLEND: bgl.glEnable(bgl.GL_BLEND) elif self.blend_mode == MULTIPLY_BLEND: bgl.glEnable(bgl.GL_BLEND) bgl.glBlendFunc(bgl.GL_DST_COLOR, bgl.GL_ZERO) elif self.blend_mode == ADDITIVE_BLEND: bgl.glEnable(bgl.GL_BLEND) bgl.glBlendFunc(bgl.GL_ONE, bgl.GL_ONE) if not self.draw_on_top: bgl.glEnable(bgl.GL_DEPTH_TEST) bgl.glLineWidth(self.line_width) bgl.glPointSize(self.point_size)
def draw_scale_line(self, context, event): wm = context.window_manager region = bpy.context.region rv3d = bpy.context.space_data.region_3d self.circle_color = [0.102758, 0.643065, 1.000000, 1.000000] if event.ctrl and not self.f_key and event.type != "MIDDLEMOUSE" and not self.scale_stroke: self.circle_color = [1.000000, 0.202489, 0.401234, 1.000000] bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(self.circle_color[0], self.circle_color[1], self.circle_color[2], self.circle_color[3]) bgl.glLineWidth(3) ### draw line code here p1 = self.stroke_start_pos p2 = self.stroke_start_pos + ( self.stroke_direction * (self.stroke_start_pos - self.mouse_on_plane).length) p1_2d = bpy_extras.view3d_utils.location_3d_to_region_2d(region, rv3d, p1) p2_2d = bpy_extras.view3d_utils.location_3d_to_region_2d(region, rv3d, p2) if self.scale_stroke: bgl.glBegin(bgl.GL_LINE_STRIP) if p1_2d != None and p2_2d != None: bgl.glVertex2f(p1_2d[0], p1_2d[1]) bgl.glVertex2f(p2_2d[0], p2_2d[1]) bgl.glEnd() bgl.glPointSize(5) p = bpy_extras.view3d_utils.location_3d_to_region_2d( region, rv3d, self.projected_mouse) if self.scale_stroke: bgl.glPointSize(14) p = p2_2d bgl.glBegin(bgl.GL_POINTS) if p != None: bgl.glVertex2f(p[0], p[1]) bgl.glEnd() ### restore_opengl_defaults()
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_bezier_3d(self, context): bgl.glEnable(bgl.GL_BLEND) bgl.glDepthFunc(bgl.GL_ALWAYS) bezier = self.beziers[self.at[0]][self.at[1]] split = bezier.split(self.at[2]) points = bezier.points bgl.glColor4f(1, 1, 1, 0.5) bgl.glLineWidth(1.0) bgl.glBegin(bgl.GL_LINES) bgl.glVertex3f(*points[0]) bgl.glVertex3f(*points[1]) bgl.glVertex3f(*points[2]) bgl.glVertex3f(*points[3]) bgl.glEnd() bgl.glColor4f(1, 1, 1, 1) bgl.glPointSize(6) bgl.glBegin(bgl.GL_POINTS) bgl.glVertex3f(*points[0]) bgl.glVertex3f(*points[3]) bgl.glEnd() bgl.glPointSize(2) bgl.glBegin(bgl.GL_POINTS) bgl.glVertex3f(*points[1]) bgl.glVertex3f(*points[2]) bgl.glEnd() # draw new bezier anchor bgl.glColor4f(0.8, 1.0, 0.0, 0.5) bgl.glLineWidth(2) bgl.glBegin(bgl.GL_LINE_STRIP) bgl.glVertex3f(*split[2]) bgl.glVertex3f(*split[3]) bgl.glVertex3f(*split[4]) bgl.glEnd() bgl.glColor4f(0.2, 1, 0.0, 1.0) bgl.glPointSize(10) bgl.glBegin(bgl.GL_POINTS) bgl.glVertex3f(*split[3]) bgl.glEnd() bgl.glPointSize(6) bgl.glBegin(bgl.GL_POINTS) bgl.glVertex3f(*split[2]) bgl.glVertex3f(*split[4]) bgl.glEnd() gl_end_and_restore()
def draw_opengl(self, context): region = self._window_region(context) if self.placed_first_point: help_text = "Command Help:\nLEFT CLICK: Place Second Point\nRIGHT CLICK: Cancel Command" else: help_text = "Command Help:\nLEFT CLICK: Place First Point\nRIGHT CLICK: Cancel Command" if self.found_snap_point: help_text += "\n SNAP TO VERTEX" help_box = TextBox(x=0, y=0, width=500, height=0, border=10, margin=100, message=help_text) help_box.x = (self.mouse_x + (help_box.width) / 2 + 10) - region.x help_box.y = (self.mouse_y - 10) - region.y help_box.draw() # SNAP POINT bgl.glPushAttrib(bgl.GL_ENABLE_BIT) bgl.glColor4f(255, 0.0, 0.0, 1.0) bgl.glEnable(bgl.GL_BLEND) bgl.glPointSize(10) bgl.glBegin(bgl.GL_POINTS) if self.snapping_point_2d: bgl.glVertex2f(self.snapping_point_2d[0], self.snapping_point_2d[1]) bgl.glEnd() bgl.glPopAttrib() # restore opengl defaults bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_points_callback(self, draw_manager, object_anchor, positions, colors): handle_is_valid = True try: # Check if object still exists object_anchor_name = object_anchor.name except: handle_is_valid = False if handle_is_valid: if object_anchor_name in bpy.data.objects: # Use the visibility of the object to enable / # disable the drawing of the point cloud if bpy.data.objects[object_anchor_name].visible_get(): # Update the batch depending on the anchor pose (only if necessary) object_anchor_has_changed = not np.array_equal( self.object_anchor_pose_previous, object_anchor.matrix_world) if self.batch_cached is None or object_anchor_has_changed: self.object_anchor_pose_previous = np.copy(object_anchor.matrix_world) transf_pos_list = compute_transformed_coords( object_anchor.matrix_world, positions) self.batch_cached = batch_for_shader( self.shader, "POINTS", {"pos": transf_pos_list, "color": colors}) self.shader.bind() bgl.glPointSize(self.point_size) bgl.glEnable(bgl.GL_DEPTH_TEST) bgl.glDepthMask(bgl.GL_TRUE) self.batch_cached.draw(self.shader) else: log_report('INFO', 'Removing draw handler of deleted point cloud handle') if self.draw_handler_handle is not None: bpy.types.SpaceView3D.draw_handler_remove( self.draw_handler_handle, 'WINDOW') self.draw_handler_handle = None draw_manager.delete_anchor(object_anchor)
def draw_points(context, points, size, gl_col): region = context.region rv3d = context.space_data.region_3d # needed for adjusting the size of gl_points bgl.glEnable(bgl.GL_POINT_SMOOTH) bgl.glPointSize(size) bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA) bgl.glBegin(bgl.GL_POINTS) bgl.glColor4f(*gl_col) for coord in points: vector3d = (coord.x, coord.y, coord.z) vector2d = loc3d2d(region, rv3d, vector3d) bgl.glVertex2f(*vector2d) bgl.glEnd() bgl.glDisable(bgl.GL_POINT_SMOOTH) bgl.glDisable(bgl.GL_POINTS) return
def draw_circle3d(p, u, v, radius, half=False): bgl.glPointSize(1) bgl.glBegin(bgl.GL_LINE_STRIP) bgl.glColor4f(0, 0, 0, 1) u = u.normalized() v = v.normalized() r = radius t = 0 last = math.pi * 2 if not half else math.pi dt = last / 40 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()
def draw_pivots3D(poss, radius, color=(1, 1, 1, 1)): bgl.glEnable(bgl.GL_BLEND) bgl.glDisable(bgl.GL_LINE_SMOOTH) bgl.glPointSize(radius * dpm() * 2) bgl.glDisable(bgl.GL_DEPTH_TEST) bgl.glDepthMask(bgl.GL_FALSE) bgl.glEnable(bgl.GL_POLYGON_OFFSET_POINT) bgl.glPolygonOffset(1.0, 1.0) shader3D.bind() shader3D.uniform_float("color", color) batch_draw(shader3D, 'POINTS', {"pos": poss}) bgl.glPointSize(1) bgl.glDisable(bgl.GL_POLYGON_OFFSET_POINT) bgl.glEnable(bgl.GL_BLEND) bgl.glDisable(bgl.GL_DEPTH_TEST) bgl.glDepthMask(bgl.GL_FALSE)
def gen_limit_circle(rotate, radius, num_segments, fconsumer, color, min_limit, max_limit): def gen_arc_vary(radius, start, end): num_segs = math.ceil(num_segments * abs(end - start) / (math.pi * 2.0)) if num_segs: gen_arc(radius, start, end, num_segs, fconsumer, close=True) bgl.glLineWidth(2) bgl.glBegin(bgl.GL_LINE_STRIP) bgl.glColor4f(*color) gen_arc_vary(radius, min_limit, max_limit) bgl.glColor4f(*settings.GREY_COLOR) gen_arc_vary(radius, max_limit, 2.0 * math.pi + min_limit) bgl.glEnd() bgl.glPointSize(settings.POINT_SIZE) bgl.glColor4f(*color) bgl.glBegin(bgl.GL_POINTS) gen_arc(radius, rotate, rotate + 1, 1, fconsumer) bgl.glEnd()
def draw_callback_3d(self, op, context): # Draw lines bgl.glEnable(bgl.GL_LINE_SMOOTH) self.shader.bind() self.shader.uniform_float("color", (0.2, 0.5, 0.8, 1.0)) bgl.glLineWidth(2) self.batch_extruded.draw(self.shader) bgl.glLineWidth(1) self.batch_lines_extruded.draw(self.shader) bgl.glLineWidth(3) self.shader.uniform_float("color", (0.1, 0.3, 0.7, 1.0)) self.batch.draw(self.shader) if self.shape.draw_points(): bgl.glPointSize(10) self.batch_points.draw(self.shader)
def draw_callback_wc_view(context): gta_tools = bpy.context.scene.gta_tools global wc_state if wc_state.check_suspend(): return bgl.glEnable(bgl.GL_BLEND) bgl.glShadeModel(bgl.GL_SMOOTH) # Mark Active VG Position if gta_tools.weight_props.mark_bone: active_bone_pos = get_acive_bone() bgl.glPointSize(10.0) bgl.glBegin(bgl.GL_POINTS) bgl.glColor4f(1.0, 1.0, 1.0, 1.0) bgl.glVertex3f(*active_bone_pos) bgl.glEnd() # Show Weight Color if gta_tools.weight_props.weight_color or gta_tools.weight_props.mark_unweighted: #if ditect_update(): update_vw() # maybe removed, later #wc_state.check_update() check_update() bgl.glPointSize(gta_tools.weight_props.weight_size) bgl.glBegin(bgl.GL_POINTS) for vw in wc_state.vws: if (gta_tools.weight_props.weight_calc_margin < vw[1]): if gta_tools.weight_props.weight_color: bgl.glColor4f(*get_heat4f( vw[1], gta_tools.weight_props.weight_alpha)) bgl.glVertex3f(*vw[0]) elif gta_tools.weight_props.weight_calc_margin < -vw[1]: if gta_tools.weight_props.mark_unweighted: bgl.glColor4f(1.0, 0.0, 1.0, gta_tools.weight_props.weight_alpha) bgl.glVertex3f(*vw[0]) bgl.glEnd() # restore opengl defaults bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_callback_3d(self, context): dprops = context.scene.flip_fluid.get_domain_properties() if dprops is None: return pdata = dprops.mesh_cache.gl_particles.get_point_cache_data() if pdata is None or len(pdata['particles']) == 0: return bbox_obj = bpy.data.objects.get(dprops.debug.particle_draw_aabb) bbox = None if bbox_obj is None else AABB.from_blender_object(bbox_obj) min_color = dprops.debug.low_speed_particle_color max_color = dprops.debug.high_speed_particle_color color_ranges = self.get_color_ranges(pdata, self.num_gradient_colors) bgl.glPointSize(dprops.debug.particle_size) bgl.glBegin(bgl.GL_POINTS) particles = pdata['particles'] for cidx in range(len(color_ranges)): start_idx = 0 if cidx == 0 else color_ranges[cidx - 1] end_idx = color_ranges[cidx] if end_idx - start_idx == 0: continue color_factor = cidx / (len(color_ranges) - 1) gmode = 'HSV' if dprops.debug.fluid_particle_gradient_mode == 'GRADIENT_HSV' else 'RGB' color = self.lerp_rgb(min_color, max_color, color_factor, mode=gmode) bgl.glColor4f(color[0], color[1], color[2], 1.0) if bbox is None: for pidx in range(start_idx, end_idx): bgl.glVertex3f(*(particles[pidx])) else: for pidx in range(start_idx, end_idx): if bbox.contains_point(particles[pidx]): bgl.glVertex3f(*(particles[pidx])) bgl.glEnd() bgl.glPointSize(1) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def drawRegionOfPoints(regionofpoints, color, size=3.0, enable_depth=True, ugly=False): if (enable_depth): bgl.glEnable(bgl.GL_DEPTH_TEST) bgl.glColor4f(*color) bgl.glPointSize(size) bgl.glBegin(bgl.GL_POINTS) for region in regionofpoints: if (ugly): points = region['borders'] else: points = region['points'] for co in points: bgl.glVertex3f(*co) bgl.glEnd() if (enable_depth): bgl.glDisable(bgl.GL_DEPTH_TEST)