def draw_callback(self, context): # polling if context.mode == 'EDIT_MESH': return # retrieving ID property data try: #print(context.scene['GamePropsVisualiser']) texts = context.scene['GamePropsVisualiser'] except: return if not texts: return # draw i=0 blf.size(0, 12, 72) bgl.glColor3f(1.0,1.0,1.0) for ob in bpy.context.selected_objects: for pi,p in enumerate(ob.game.properties): blf.position(0, texts[i], texts[i+1]-(pi+1)*14, 0) if p.type=='FLOAT': t=p.name+': '+ str('%g'% p.value) else: t=p.name+': '+ str(p.value) blf.draw(0, t) i+=2
def display_face(options, pol, data_vector, data_matrix, k, i): colo = options['face_colors'] shade = options['shading'] forced_tessellation = options['forced_tessellation'] num_verts = len(pol) dvk = data_vector[k] if shade: vectorlight = options['light_direction'] face_color = get_color_from_normal(dvk, pol, num_verts, vectorlight, colo) else: face_color = colo[:] glColor3f(*face_color) if (num_verts in {3, 4}) or (not forced_tessellation): glBegin(GL_POLYGON) for point in pol: vec = data_matrix[i] * dvk[point] glVertex3f(*vec) glEnd() else: ''' ngons, we tessellate ''' glBegin(GL_TRIANGLES) v = [dvk[i] for i in pol] for pol in tessellate([v]): for point in pol: vec = data_matrix[i] * v[point] glVertex3f(*vec) glEnd()
def draw_callback(self, context): if context.region.as_pointer() != self.region: return glsettings = vagl.GLSettings(context) glsettings.push() cursor_2d = project(context.region, context.region_data, self.get_cursor_location(context)) unit_settings = context.scene.unit_settings text_lines = [] for i in range(3): if unit_settings.system == 'NONE': text = '{:.5f}'.format(self.cursor_location[i]) else: text = bpy.utils.units.to_string( unit_settings.system, 'LENGTH', self.cursor_location[i], 5, split_unit=unit_settings.use_separate ) text_lines.append(text) col = context.user_preferences.themes['Default'].view_3d.space.text_hi bgl.glColor3f(*col) blf.size(0, 12, context.user_preferences.system.dpi) tw_max = max(blf.dimensions(0, t)[0] for t in text_lines) if 0: p = [cursor_2d[0] - tw_max - 5, cursor_2d[1] - 40, 0] else: p = [self.mco[0] - tw_max - 5, self.mco[1] - 40, 0] th = blf.dimensions(0, '-.0123456789')[1] lf = th * 1.2 for i, text in enumerate(text_lines): tw, _ = blf.dimensions(0, text) blf.position(0, p[0] + tw_max - tw, p[1], p[2]) vagl.blf_draw(0, text) p[1] -= lf if 0: p = [cursor_2d[0] + 5, cursor_2d[1] - 40, 0] else: p = [self.mco[0] + 5, self.mco[1] - 40, 0] if self.use_snap: blf.position(0, *p) vagl.blf_draw(0, 'Snap') p[1] -= lf if self.use_precision: blf.position(0, *p) vagl.blf_draw(0, 'Precision') p[1] -= lf if self.use_depth: blf.position(0, *p) vagl.blf_draw(0, 'Depth') p[1] -= lf glsettings.pop()
def draw_callback_px(n_id, data): space = bpy.context.space_data ng_view = space.edit_tree # ng_view can be None if not ng_view: return ng_name = space.edit_tree.name if not (data['tree_name'] == ng_name): return if not isinstance(ng_view, node_tree.SverchCustomTree): return lines = data.get('content', 'no data') x, y = data.get('location', (120, 120)) color = data.get('color', (0.1, 0.1, 0.1)) font_id = 0 text_height = 13 # why does the text look so jagged? blf.size(font_id, text_height, 72) # should check prefs.dpi bgl.glColor3f(*color) # x = 30 # region.width # y = region.height - 40 ypos = y for line in lines: blf.position(0, x, ypos, 0) blf.draw(0, line) ypos -= (text_height * 1.3)
def draw_shape_sign(mat, scs_globals): """ Draws shape for "Locator" of "Sign" type. :param mat: :param scs_globals: :return: """ glLineWidth(2.0) glBegin(GL_LINES) glColor3f(scs_globals.locator_prefab_wire_color.r, scs_globals.locator_prefab_wire_color.g, scs_globals.locator_prefab_wire_color.b) glVertex3f(*(mat * Vector((0.0, 0.0, scs_globals.locator_empty_size)))) glVertex3f(*(mat * Vector((0.0, 0.0, 0.45)))) glEnd() glBegin(GL_LINE_STRIP) glVertex3f(*(mat * Vector((0.0, 0.0, 0.75)))) glVertex3f(*(mat * Vector((0.1299, 0.0, 0.675)))) glVertex3f(*(mat * Vector((0.1299, 0.0, 0.525)))) glVertex3f(*(mat * Vector((0.0, 0.0, 0.45)))) glVertex3f(*(mat * Vector((-0.1299, 0.0, 0.525)))) glVertex3f(*(mat * Vector((-0.1299, 0.0, 0.675)))) glVertex3f(*(mat * Vector((0.0, 0.0, 0.75)))) glEnd() glLineWidth(1.0)
def draw_callback_px(self, context): from bgl import glColor3f font_id = 0 # XXX, need to find out how best to get this. blf.size(font_id, 12, 72) data_matrix, data_quat, data_euler, data_vector, data_vector_array = utils.console_math_data() if not data_matrix and not data_quat and not data_euler and not data_vector and not data_vector_array: # draw some text glColor3f(1.0, 0.0, 0.0) blf.position(font_id, 180, 10, 0) blf.draw(font_id, "Python Console has no mathutils definitions") return glColor3f(1.0, 1.0, 1.0) region = context.region region3d = context.space_data.region_3d region_mid_width = region.width / 2.0 region_mid_height = region.height / 2.0 # vars for projection perspective_matrix = region3d.perspective_matrix.copy() def draw_text(text, vec): vec_4d = vec.to_4d() vec_4d *= perspective_matrix if vec_4d.w > 0.0: x = region_mid_width + region_mid_width * (vec_4d.x / vec_4d.w) y = region_mid_height + region_mid_height * (vec_4d.y / vec_4d.w) blf.position(font_id, x + 3.0, y - 4.0, 0.0) blf.draw(font_id, text) # points if data_vector: for key, vec in data_vector.items(): draw_text(key, vec) # lines if data_vector_array: for key, vec in data_vector_array.items(): draw_text(key, vec[0]) # matrix if data_matrix: for key, mat in data_matrix.items(): draw_text(key, mat[3]) if data_quat: loc = context.scene.cursor_location.copy() for key, mat in data_quat.items(): draw_text(key, loc) if data_euler: loc = context.scene.cursor_location.copy() for key, mat in data_euler.items(): draw_text(key, loc)
def redraw(self): drawregion = bpy.context.region rv3d = self.rv3ds[drawregion] vec = self.originvert.co.copy() vec.rotate(self.selobj.matrix_world) vec.rotate(self.selobj.matrix_world) self.space3d.cursor_location = vec * self.selobj.matrix_world + self.selobj.matrix_world.to_translation() bgl.glColor3f(1.0, 1.0, 0) bgl.glBegin(bgl.GL_POLYGON) x, y = self.getscreencoords(Vector(self.originvert.co), drawregion, rv3d) bgl.glVertex2f(x-2, y-2) bgl.glVertex2f(x-2, y+2) bgl.glVertex2f(x+2, y+2) bgl.glVertex2f(x+2, y-2) bgl.glEnd() bgl.glColor3f(1, 1, 0.7) bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glLoadIdentity() bgl.gluOrtho2D(0, self.region.width, 0, self.region.height) bgl.glMatrixMode(bgl.GL_MODELVIEW) bgl.glLoadIdentity() blf.position(0, self.region.width/2 - 80, self.region.height - 20, 0) blf.size(0, 12, 72) blf.draw(0, "FastOrigin : Enter confirms - ESC cancels")
def draw_callback_px(self, context): wm = context.window_manager sc = context.scene if not wm.polycount_run: return font_size = sc.polycount_font_size pos_x, pos_y = get_display_location(context) # draw text in the 3d-view # ======================== blf.size(0, sc.polycount_font_size, 72) r, g, b = sc.polycount_font_color bgl.glColor3f(r, g, b) view3dId = get_space_id(context.space_data) visible_tri_count = PolyCountOperator.visible_triangle_count.get(view3dId, -1) if visible_tri_count > -1: text = "All: " + format(visible_tri_count, 'd') + "triangles" text1height = blf.dimensions(0, text)[1] blf.position(0, pos_x, pos_y - text1height, 0) blf.draw(0, text) selection_tri_count = PolyCountOperator.selection_triangle_count.get(view3dId, -1); if selection_tri_count > 0: text = "Selection: " + format(selection_tri_count, ',d') + " triangles" text2height = blf.dimensions(0, text)[1] blf.position(0, pos_x, pos_y - text1height - text2height - 5, 0) blf.draw(0, text)
def drawX(self, xa, xb, ya, yb): bgl.glColor3f(*self.COLOR_X) r = xb - xa bgl.glVertex3f(xa + r*self.EMPTY_FACTOR, ya + r*self.EMPTY_FACTOR, 0.0) bgl.glVertex3f(xb - r*self.EMPTY_FACTOR, yb - r*self.EMPTY_FACTOR, 0.0) bgl.glVertex3f(xa + r*self.EMPTY_FACTOR, yb - r*self.EMPTY_FACTOR, 0.0) bgl.glVertex3f(xb - r*self.EMPTY_FACTOR, ya + r*self.EMPTY_FACTOR, 0.0)
def draw_callback(self, context): # polling if context.mode == "EDIT_MESH": return """ # retrieving ID property data try: texts = context.scene['GamePropsVisualizer'] except: return if not texts: return """ texts = context.scene["GamePropsVisualizer"] # draw i = 0 blf.size(0, 12, 72) bgl.glColor3f(1.0, 1.0, 1.0) for ob in bpy.context.selected_objects: for pi, p in enumerate(ob.game.properties): blf.position(0, texts[i], texts[i + 1] - (pi + 1) * 14, 0) if p.type == "FLOAT": t = p.name + ": " + str("%g" % p.value) else: t = p.name + ": " + str(p.value) blf.draw(0, t) i += 2
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 text( self, text, arg1=0, arg2=0, arg3=0 ): x = 0 y = 0 z = 0 rx = 0 ry = 0 rz = 0 if type( arg1 ) is mathutils.Vector(): x = arg1.x y = arg1.y z = arg1.z if type( arg2 ) is mathutils.Vector(): rx = arg2.x ry = arg2.y rz = arg2.z elif type( arg1 ) is bge.types.KX_GameObject or type( arg1 ) is str: if type( arg1 ) is str: arg1 = self.getObjectByName( arg1 ) if arg1 is not 0: o = self.getPosition( arg1 ) x = o.x y = o.y z = o.z # translation vector if type( arg2 ) is mathutils.Vector(): x += arg2.x y += arg2.y z += arg2.z # rotation vector if type( arg3 ) is mathutils.Vector(): rx = arg3.x ry = arg3.y rz = arg3.z elif type( arg1 ) is float and type( arg2 ) is float and type( arg3 ) is float: x = arg1 y = arg2 z = arg3 elif type( arg1 ) is int and type( arg2 ) is int and type( arg3 ) is int: x = arg1 y = arg2 z = arg3 width = bge.render.getWindowWidth() height = bge.render.getWindowHeight() ratiow = 1./width ratioh = 1./height bgl.glPushMatrix() bgl.glTranslatef( x,y,z ) #TODO transform angles to matrix! # bgl.glRotate( rx,ry,rz ) bgl.glScalef( ratiow, ratioh, 0 ) blf.position( self.font, 0,0,0 ) blf.size( self.font, self.tsize, 300 ) bgl.glColor3f( self.tcolor.x, self.tcolor.y, self.tcolor.z ) blf.draw( self.font, text ) bgl.glPopMatrix()
def draw_shape_traffic_light(mat, scene_scs_props): """ Draws shape for "Locator" of "Traffic Semaphore" type. :param mat: :return: """ glLineWidth(2.0) glBegin(GL_LINE_STRIP) glColor3f(scene_scs_props.locator_prefab_wire_color.r, scene_scs_props.locator_prefab_wire_color.g, scene_scs_props.locator_prefab_wire_color.b) glVertex3f(*(mat * Vector((0.0, 0.0, scene_scs_props.locator_empty_size)))) glVertex3f(*(mat * Vector((0.0, 0.0, 0.45)))) glVertex3f(*(mat * Vector((-0.0866, 0.0, 0.5)))) glVertex3f(*(mat * Vector((-0.0866, 0.0, 0.84)))) glVertex3f(*(mat * Vector((0.0, 0.0, 0.89)))) glVertex3f(*(mat * Vector((0.0866, 0.0, 0.84)))) glVertex3f(*(mat * Vector((0.0866, 0.0, 0.5)))) glVertex3f(*(mat * Vector((0.0, 0.0, 0.45)))) glEnd() for val in (0.5, 0.62, 0.74): glBegin(GL_LINE_LOOP) glVertex3f(*(mat * Vector((0.0, 0.0, val)))) glVertex3f(*(mat * Vector((-0.0433, 0.0, 0.025 + val)))) glVertex3f(*(mat * Vector((-0.0433, 0.0, 0.075 + val)))) glVertex3f(*(mat * Vector((0.0, 0.0, 0.1 + val)))) glVertex3f(*(mat * Vector((0.0433, 0.0, 0.075 + val)))) glVertex3f(*(mat * Vector((0.0433, 0.0, 0.025 + val)))) glEnd() glLineWidth(1.0)
def draw_index(rgb, index, vec): vec_4d = perspective_matrix * vec.to_4d() if vec_4d.w <= 0.0: return x = region_mid_width + region_mid_width * (vec_4d.x / vec_4d.w) y = region_mid_height + region_mid_height * (vec_4d.y / vec_4d.w) index = str(index) if draw_bg: polyline = get_points(index) ''' draw polygon ''' bgl.glColor4f(0.103, 0.2, 0.2, 0.2) bgl.glBegin(bgl.GL_POLYGON) for pointx, pointy in polyline: bgl.glVertex2f(pointx+x, pointy+y) bgl.glEnd() ''' draw text ''' txt_width, txt_height = blf.dimensions(0, index) bgl.glColor3f(*rgb) blf.position(0, x - (txt_width / 2), y - (txt_height / 2), 0) blf.draw(0, index)
def post_view_callback(self, context): start = self.vertex_co normal_size = context.tool_settings.normal_size view_3d_theme = context.user_preferences.themes['Default'].view_3d default_color = view_3d_theme.split_normal highlight_color = [0.25, 1.0, 0.56] # Draw all normals of selected vertex. bgl.glBegin(bgl.GL_LINES) bgl.glColor3f(*default_color) bgl.glLineWidth(1) for n in self.normals: end = start + Vector(n) * normal_size bgl.glVertex3f(*start) bgl.glVertex3f(*end) bgl.glEnd() # Highlight selected normal. bgl.glColor3f(*highlight_color) bgl.glLineWidth(2) bgl.glBegin(bgl.GL_LINES) end = start + Vector(self.normals[self.normals_idx]) * normal_size bgl.glVertex3f(*start) bgl.glVertex3f(*end) bgl.glEnd()
def drawPoint(x, y, main=True): r = 6 if main else 3 bgl.glBegin(bgl.GL_LINES) bgl.glColor3f(1.0, 1.0, 1.0) bgl.glVertex2i(x - r, y) bgl.glVertex2i(x - r, y + r) bgl.glVertex2i(x - r, y + r) bgl.glVertex2i(x, y + r) bgl.glVertex2i(x + r, y) bgl.glVertex2i(x + r, y - r) bgl.glVertex2i(x + r, y - r) bgl.glVertex2i(x, y - r) bgl.glColor3f(0.0, 0.0, 0.0) bgl.glVertex2i(x, y + r) bgl.glVertex2i(x + r, y + r) bgl.glVertex2i(x + r, y + r) bgl.glVertex2i(x + r, y) bgl.glVertex2i(x, y - r) bgl.glVertex2i(x - r, y - r) bgl.glVertex2i(x - r, y - r) bgl.glVertex2i(x - r, y) bgl.glEnd()
def draw_callback_px(self, context): wm = context.window_manager sc = context.scene if not wm.polycount_run: return font_size = sc.polycount_font_size pos_x, pos_y = get_display_location(context) # draw text in the 3d-view # ======================== blf.size(0, sc.polycount_font_size, 72) r, g, b = sc.polycount_font_color bgl.glColor3f(r, g, b) view3dId = get_space_id(context.space_data) # text = "All Obj Sel" # blf.position(0, pos_x + 15, pos_y, 0) # blf.draw(0, text) # ######## vertex Drawing if sc.show_vertex_count == True: text = "V" blf.position(0, pos_x , pos_y, 0) blf.draw(0, text) if vert_count_all == True: all_vert_count = polyCountOperator.all_edge_count.get(view3dId, -1) if all_vert_count > 0: text = format(all_tri_count, ',d') text3width = blf.dimensions(0, text)[0] blf.position(0, pos_x + 135 , pos_y , 0) blf.draw(0, text) else: text = "0" blf.position(0, pos_x + 135, pos_y , 0) blf.draw(0, text) else: text = "X" blf.position(0, pos_X, pos_y - 20, 0) blf.draw(o,text) if vert_count_obj == True: obj_vert_count = polyCountOperator.all_edge_count.get(view3dId, -1) if obj_vert_count > 0: text = format(obj_vert_count, ',d') text3width = blf.dimensions(0, text)[0] blf.position(0, pos_x + 135 , pos_y , 0) blf.draw(0, text) else: text = "0" blf.position(0, pos_x + 135, pos_y , 0) blf.draw(0, text)
def draw_vectorfield(self, context): bgl.glEnable(bgl.GL_BLEND) bgl.glColor3f(0.0,1.0,0.0) for i in range(len(vf_vdata.particle_velocitieslist)): draw_line(vf_vdata.particle_startlocs[i],vf_vdata.particle_velocitieslist[i]) bgl.glDisable(bgl.GL_BLEND)
def draw_line(v1, v2, width=1, color=(0,1,0)): glColor3f(*color) glLineWidth(width) glBegin(GL_LINE_STRIP) glVertex3f(*v1) glVertex3f(*v2) glEnd() glLineWidth(1)
def vicon_edit_draw(x, y, w, h, alpha=1.0): pts = ((x + 3, y + 3), (x + w - 3, y + 3), (x + w - 3, y + h - 3), (x + 3, y + h - 3)) bgl.glColor4f(0.0, 0.0, 0.0, alpha) viconutil_draw_lineloop(pts) bgl.glColor3f(1, 1, 0.0); viconutil_draw_points(pts, 1)
def display_laser(self): sr = self._ray # shorcut in expressions bgl.glColor3f(sr['color'][0], sr['color'][1], sr['color'][2]) bgl.glLineWidth(1.0) bgl.glBegin(bgl.GL_LINES) bgl.glVertex3f(sr['origin'].x, sr['origin'].y, sr['origin'].z) bgl.glVertex3f(sr['destin'].x, sr['destin'].y, sr['destin'].z) bgl.glEnd()
def draw_text(text): col = prefs.color_shadow bgl.glColor4f(*col[:3], col[3] * 20) blf.blur(font_id, 5) blf.draw(font_id, text) blf.blur(font_id, 0) bgl.glColor3f(*prefs.color) blf.draw(font_id, text)
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 vicon_editmode_dehlt_draw(x, y, w, h, alpha=1.0): pts = ((x + w / 2, y + h - 2), (x + 3, y + 4), (x + w - 3, y + 4)) bgl.glColor4f(0.0, 0.0, 0.0, 1) viconutil_draw_lineloop_smooth(pts) bgl.glColor3f(0.9, 0.9, 0.9) viconutil_draw_points(pts, 1)
def draw_shape_line(line, stipple, is_map_line, scs_globals): """Draw line from loc_0 to loc_1 with specified colors of the ends ("line_colorX"). There is also middle point loc_btw which separates color sides :param line: with entries: ("line_color0" : (float, float, float)), "(line_color1" : (float, float, float)), ("loc_0" : (float, float, float)), ("loc_1" : (float, float, float)), ("loc_btw" : (float, float, float)) :type line: dict :param stipple: flag indicating if line should be stipple or not :type stipple: bool :param is_map_line: boolean indicating if line is map line; if false it means it's trigger line :type is_map_line: bool :param scs_globals: SCS globals :type scs_globals: io_scs_tools.properties.world.GlobalSCSProps :return: :rtype: """ if 'line_color0' in line: color0 = line['line_color0'] else: if is_map_line: color0 = (scs_globals.mp_connection_base_color.r, scs_globals.mp_connection_base_color.g, scs_globals.mp_connection_base_color.b) else: color0 = (scs_globals.tp_connection_base_color.r, scs_globals.tp_connection_base_color.g, scs_globals.tp_connection_base_color.b) if 'line_color1' in line: color1 = line['line_color1'] else: if is_map_line: color1 = (scs_globals.mp_connection_base_color.r, scs_globals.mp_connection_base_color.g, scs_globals.mp_connection_base_color.b) else: color1 = (scs_globals.tp_connection_base_color.r, scs_globals.tp_connection_base_color.g, scs_globals.tp_connection_base_color.b) if stipple: glEnable(GL_LINE_STIPPLE) glBegin(GL_LINES) glColor3f(color0[0], color0[1], color0[2]) glVertex3f(*line['loc_0']) glVertex3f(*line['loc_btw']) glColor3f(color1[0], color1[1], color1[2]) glVertex3f(*line['loc_btw']) glVertex3f(*line['loc_1']) glEnd() if stipple: glDisable(GL_LINE_STIPPLE)
def draw_index(r, g, b, index, center): vec = total_mat * center # order is important # dehomogenise vec = mathutils.Vector((vec[0] / vec[3], vec[1] / vec[3], vec[2] / vec[3])) x = int(mid_x + vec[0] * width / 2) y = int(mid_y + vec[1] * height / 2) bgl.glColor3f(r, g, b) blf.position(0, x, y, 0) blf.draw(0, str(index))
def draw_vectorfield(self, context): bgl.glEnable(bgl.GL_BLEND) bgl.glColor3f(0.0,1.0,0.0) for i in range(len(vf_vdata.particle_velocitieslist)): bgl.glBegin(bgl.GL_LINES) bgl.glVertex3f(vf_vdata.particle_startlocs[i][0],vf_vdata.particle_startlocs[i][1],vf_vdata.particle_startlocs[i][2]) bgl.glVertex3f(vf_vdata.particle_velocitieslist[i][0] + vf_vdata.particle_startlocs[i][0],vf_vdata.particle_velocitieslist[i][1] + vf_vdata.particle_startlocs[i][1],vf_vdata.particle_velocitieslist[i][2] + vf_vdata.particle_startlocs[i][2]) bgl.glEnd() bgl.glDisable(bgl.GL_BLEND)
def drawO(self, xa, xb, ya, yb): bgl.glColor3f(*self.COLOR_O) r = xb - xa bgl.glVertex3f(xa + r*self.EMPTY_FACTOR, (ya + yb)/2.0, 0.0) bgl.glVertex3f((xa + xb)/2.0, yb - r*self.EMPTY_FACTOR, 0.0) bgl.glVertex3f((xa + xb)/2.0, yb - r*self.EMPTY_FACTOR, 0.0) bgl.glVertex3f(xb - r*self.EMPTY_FACTOR, (ya + yb)/2.0, 0.0) bgl.glVertex3f(xb - r*self.EMPTY_FACTOR, (ya + yb)/2.0, 0.0) bgl.glVertex3f((xa + xb)/2.0, ya + r*self.EMPTY_FACTOR, 0.0) bgl.glVertex3f((xa + xb)/2.0, ya + r*self.EMPTY_FACTOR, 0.0) bgl.glVertex3f(xa + r*self.EMPTY_FACTOR, (ya + yb)/2.0, 0.0)
def toolmode_draw_callback(self, context): # polling if context.mode != 'PAINT_TEXTURE': return # draw if context.region: main_y = context.region.height - 32 else: return blend_dic = {"MIX": "Mix", "ADD": "Add", "SUB": "Subtract", "MUL": "Multiply", "LIGHTEN": "Lighten", "DARKEN": "Darken", "ERASE_ALPHA": "Erase Alpha", "ADD_ALPHA": "Add Alpha", "OVERLAY": "Overlay", "HARDLIGHT": "Hard light", "COLORBURN": "Color burn", "LINEARBURN": "Linear burn", "COLORDODGE": "Color dodge", "SCREEN": "Screen", "SOFTLIGHT": "Soft light", "PINLIGHT": "Pin light", "VIVIDLIGHT": "Vivid light", "LINEARLIGHT": "Linear light", "DIFFERENCE": "Difference", "EXCLUSION": "Exclusion", "HUE": "Hue", "SATURATION": "Saturation", "LUMINOSITY": "Luminosity", "COLOR": "Color" } brush = context.tool_settings.image_paint.brush text = brush.name + " - " + blend_dic[brush.blend] # text in top-left corner bgl.glColor3f(0.6, 0.6, 0.6) blf.position(0, 21, main_y, 0) blf.draw(0, text) # text above brush dt = time.time() - context.window_manager["tpp_toolmode_time"] if dt < 1: if "tpp_toolmode_brushloc" not in context.window_manager: return brush_x, brush_y = context.window_manager["tpp_toolmode_brushloc"] brush_x -= blf.dimensions(0, text)[0] / 2 bgl.glColor4f(0.6, 0.6, 0.6, min(1.0, (1.0 - dt) * 2)) blf.position(0, brush_x, brush_y, 0) blf.draw(0, text)
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_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_viewUV(area, UV_TO_VIEW, id): # print(id, area.spaces[0].image, area.spaces[0].show_uvedit ) settings = bpy.context.scene.uv_highlight prefs = bpy.context.user_preferences.addons[__package__].preferences mode = bpy.context.scene.tool_settings.uv_select_mode # remove closed areas if len(area.regions) == 0 or area.type != "IMAGE_EDITOR": bpy.types.SpaceImageEditor.draw_handler_remove(IMAGE_EDITORS[area], 'WINDOW') IMAGE_EDITORS.pop(area, None) # print("removing Image_Editor from drawing: %s" % id) return # dont show this if the area is in Image mode :D if not main.isEditingUVs() or area.spaces[0].mode != "VIEW" or not area.spaces[0].show_uvedit: # print("skipping Image_Editor from drawing: %s" % id) return sync_mode = bpy.context.scene.tool_settings.use_uv_select_sync viewport_info = bgl.Buffer(bgl.GL_INT, 4) bgl.glGetIntegerv(bgl.GL_VIEWPORT, viewport_info) for region in area.regions: if region.type == "WINDOW": width = region.width height = region.height region_x = region.x region_y = region.y bgl.glViewport(region_x, region_y, width, height) bgl.glMatrixMode(bgl.GL_MODELVIEW) bgl.glPushMatrix() # bgl.glLoadIdentity() origin = UV_TO_VIEW(0, 0, False) axis = UV_TO_VIEW(1.0, 0, False)[0] - origin[0] M = (axis, 0, 0, 0, 0, axis, 0, 0, 0, 0, 1.0, 0, origin[0], origin[1], 0, 1.0) m = bgl.Buffer(bgl.GL_FLOAT, 16, M) bgl.glLoadMatrixf(m) if settings.show_hidden_faces and not sync_mode: bgl.glBlendFunc(bgl.GL_ONE, bgl.GL_ONE) draw_vertex_array("hidden_edges", bgl.GL_LINES, 2, prefs.uv_hidden_faces) if settings.show_udim_indices: draw_udim_tiles(M, prefs.udim_markers) # PRE HIGHLIGHT VERTS if settings.show_preselection and main.UV_MOUSE and UV_TO_VIEW and not sync_mode: if mode == 'VERTEX' and main.closest_vert and main.closest_vert[1]: bgl.glLoadIdentity() bgl.glPointSize(5.0) bgl.glBegin(bgl.GL_POINTS) bgl.glColor4f(*prefs.uv_preselection_color_verts_edges) if main.other_vert: bgl.glVertex2i(*UV_TO_VIEW(*main.other_vert)) bgl.glVertex2i(*UV_TO_VIEW(main.closest_vert[1][0], main.closest_vert[1][1], False)) bgl.glEnd() # print("MOUSE: %s, ClosestVert: %s - %s" % (UV_MOUSE, closestVert[1], view)) elif mode == 'EDGE': # draw dark first, then overpaint with brighter colour bgl.glLoadIdentity() bgl.glLineWidth(3.5) bgl.glEnable(bgl.GL_LINE_SMOOTH) bgl.glEnable(bgl.GL_BLEND) bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA) bgl.glBegin(bgl.GL_LINES) # edge if main.closest_edge and main.closest_edge[1][0] and main.closest_edge[1][1]: bgl.glColor3f(*COLOR_BLACK) bgl.glVertex2i(*(UV_TO_VIEW(*main.closest_edge[1][0], False))) bgl.glVertex2i(*(UV_TO_VIEW(*main.closest_edge[1][1], False))) # matching edge if main.other_edge and main.other_edge[1][0] and main.other_edge[1][1]: bgl.glColor3f(*COLOR_BLACK) bgl.glVertex2i(*(UV_TO_VIEW(*main.other_edge[1][0], False))) bgl.glVertex2i(*(UV_TO_VIEW(*main.other_edge[1][1], False))) bgl.glEnd() bgl.glLineWidth(2) bgl.glBegin(bgl.GL_LINES) # edge if main.closest_edge and main.closest_edge[1][0] and main.closest_edge[1][1]: bgl.glColor4f(*prefs.uv_preselection_color_verts_edges) bgl.glVertex2i(*(UV_TO_VIEW(*main.closest_edge[1][0], False))) bgl.glVertex2i(*(UV_TO_VIEW(*main.closest_edge[1][1], False))) # matching edge if main.other_edge and main.other_edge[1][0] and main.other_edge[1][1]: bgl.glColor4f(*prefs.uv_preselection_color_verts_edges) bgl.glVertex2i(*(UV_TO_VIEW(*main.other_edge[1][0], False))) bgl.glVertex2i(*(UV_TO_VIEW(*main.other_edge[1][1], False))) bgl.glEnd() else: bgl.glDisable((bgl.GL_CULL_FACE)) bgl.glEnable(bgl.GL_BLEND) bgl.glBlendFunc(bgl.GL_ONE, bgl.GL_ONE) draw_vertex_array("closest_face_uvs", bgl.GL_TRIANGLES, 2, prefs.uv_preselection_color_faces) bgl.glViewport(*tuple(viewport_info)) bgl.glMatrixMode(bgl.GL_MODELVIEW) bgl.glPopMatrix() bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPopMatrix() restore_opengl_defaults()
def draw_callback_mode(self, context): settings = context.scene.OASettings if self.ctrl and not settings.shift: mode_title(context, "Replace") bgl.glLineWidth(1) tool_shelf_width = get_tool_shelf_width(bpy.context) # add the offset-width and offset-height for the first time if self.menu_offset['first_iteration']: for icon in self.menu: # iterate over icon, frame and hover for i in (1, 2, 3): # iterate over lower left and upper right corner for j in (0, 2): icon[i][0 + j] += tool_shelf_width icon[i][1 + j] += bpy.context.region.height self.menu_offset['first_iteration'] = False # add current offset-region-height and offset-tool-shelf-width # when the user altered the size of the 3d-view or toggled region_overlap elif any(( self.menu_offset['width'] != tool_shelf_width, self.menu_offset['height'] != bpy.context.region.height, self.menu_offset['region_overlap'] != bool( bpy.context.user_preferences.system.use_region_overlap), )): for icon in self.menu: # iterate over icon, frame and hover for i in (1, 2, 3): # iterate over lower left and upper right corner for j in (0, 2): icon[i][0 + j] += (tool_shelf_width - self.menu_offset['width']) icon[i][1 + j] += (bpy.context.region.height - self.menu_offset['height']) self.menu_offset['width'] = tool_shelf_width self.menu_offset['height'] = bpy.context.region.height self.menu_offset['region_overlap'] = bool( bpy.context.user_preferences.system.use_region_overlap) # draw frame bgl.glColor3f(0.1, 0.1, 0.1) for icon in self.menu: bgl.glRecti(icon[2][0], icon[2][1], icon[2][2], icon[2][3]) # draw icons if settings.valid_icon_file: bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.img.bindcode) bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_NEAREST) bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_NEAREST) for icon in self.menu: bgl.glEnable(bgl.GL_TEXTURE_2D) bgl.glTexEnvf(bgl.GL_TEXTURE_ENV, bgl.GL_TEXTURE_ENV_MODE, bgl.GL_REPLACE) bgl.glBegin(bgl.GL_QUADS) bgl.glTexCoord2f(icon[4][0][0], icon[4][0][1]) bgl.glVertex2f(icon[1][0], icon[1][1]) bgl.glTexCoord2f(icon[4][1][0], icon[4][1][1]) bgl.glVertex2f(icon[1][0], icon[1][3]) bgl.glTexCoord2f(icon[4][2][0], icon[4][2][1]) bgl.glVertex2f(icon[1][2], icon[1][3]) bgl.glTexCoord2f(icon[4][3][0], icon[4][3][1]) bgl.glVertex2f(icon[1][2], icon[1][1]) bgl.glEnd() bgl.glDisable(bgl.GL_TEXTURE_2D) else: # draw category and model_id if no icon file is provided # draw background bgl.glColor3f(0.2, 0.2, 0.2) for icon in self.menu: bgl.glRecti(icon[2][0] + 2, icon[2][1] + 2, icon[2][2] - 2, icon[2][3] - 2) font_id = 0 bgl.glColor4f(1, 1, 1, 1) for icon in self.menu: blf.position(font_id, icon[1][0] + 1, icon[1][1] + 8, 0) blf.size(font_id, int(settings.menu_icon_display_size / 3), 72) blf.draw( font_id, "{0: >2}".format(icon[0][1]) + "," + "{0: >2}".format(icon[0][2])) # draw hover effekt for icon in self.menu: # mouse hover icon if mouse_over_icon(icon[1], self.mouse): bgl.glColor3f(0.6, 0.6, 0.6) bgl.glLineWidth(2) rect_round_corners(icon[3][0], icon[3][1], icon[3][2], icon[3][3]) # restore opengl defaults bgl.glLineWidth(1) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def drawObjTextArray(text, corner, pos_x, pos_y): show_text = bpy.context.window_manager.show_text mode = bpy.context.object.mode font_id = 0 height = bpy.context.region.height width = bpy.context.region.width txt_width = [] list_line_width = [] blf.size(font_id, show_text.text_font_size, 72) x_offset = 0 y_offset = 0 line_height = (blf.dimensions(font_id, "M")[1] * 1.45) x = 0 y = 0 for command in text: if len(command) == 2: Text, Color = command text_width, text_height = blf.dimensions(font_id, Text) txt_width.append(text_width) if corner == '1' or corner == '3': x = pos_x else: if mode == 'OBJECT' and show_text.obj_use and show_text.multi_obj_enabled and ( len(bpy.context.selected_objects) >= 2): count_obj = len(bpy.context.selected_objects) len_list = len(txt_width) # count of item in the list count_item = int(len_list / count_obj) # count of item by object i = 0 start = 0 end = count_item list_text = [] for item in txt_width: while i < count_obj: list_text.append(txt_width[start:start + end]) start += end i += 1 for item in list_text: list_line_width.append(sum(item[:])) x = width - (max(list_line_width) + pos_x) else: for label, value in zip(txt_width[0::2], txt_width[1::2]): l_width = label + value list_line_width.append(l_width) x = width - (max(list_line_width) + pos_x) if corner == '1' or corner == '2': y = height - pos_y else: if mode == 'OBJECT' and show_text.obj_use and show_text.multi_obj_enabled and ( len(bpy.context.selected_objects) >= 2): line_count = len(bpy.context.selected_objects) y = pos_y + (line_height * line_count) else: line_count = text.count("Carriage return") y = pos_y + (line_height * line_count) for command in text: if len(command) == 2: Text, Color = command bgl.glColor3f(*Color) text_width, text_height = blf.dimensions(font_id, Text) blf.position(font_id, (x + x_offset), (y + y_offset), 0) blf.draw(font_id, Text) x_offset += text_width else: x_offset = 0 y_offset -= line_height
def draw_vert(v1, width=5.0, color=(1, 0, 0)): glColor3f(*color) glBegin(GL_POINTS) glPointSize(width) glVertex3f(*v1) glEnd()
def draw(self, parent, context): #grab the biggest text dimensions that we already calced previously biggestdimensionX = self.biggest_dim_x biggestdimensionY = self.biggest_dim_y for it in self.sliders: #draw some text above it. blf.size(0, self.text_size, self.text_dpi) dimension = blf.dimensions(0, it.id) x = it.x - dimension[0] * .5 y = it.y + (it.height + dimension[1]) * 0.5 + 3 # Draw text blf.enable(0, blf.SHADOW) blf.shadow_offset(0, 0, 0) blf.shadow(0, 5, 0.0, 0.0, 0.0, 1.0) bgl.glColor3f(self.rt, self.gt, self.bt) blf.position(0, x, y, 0) blf.draw(0, it.id) blf.disable(0, blf.SHADOW) #draw left side one color bgl.glColor4f(self.rsSelected, self.gsSelected, self.bsSelected, 1.0) pmu.draw_outline_or_region(bgl.GL_TRIANGLE_FAN, it.screen_left) #draw the right side another color bgl.glColor4f(self.rsInner, self.gsInner, self.bsInner, 1.0) pmu.draw_outline_or_region(bgl.GL_TRIANGLE_FAN, it.screen_right) #Draw box outline bgl.glColor4f(self.rsOutline, self.gsOutline, self.bsOutline, 1.0) pmu.draw_outline_or_region(bgl.GL_LINE_LOOP, it.screen_left) pmu.draw_outline_or_region(bgl.GL_LINE_LOOP, it.screen_right) for it in self.menu_items: sel = (it == parent.current) it_poll = it.poll(context) # center item on the circle #x = (self.menu_x + it.x) - (dimension[0] * 0.5) #y = (self.menu_y + it.y) - (dimension[1] * 0.5) blf.size(0, self.text_size, self.text_dpi) dimension = blf.dimensions(0, it.id) #needed for box centering x = (it.x) - (biggestdimensionX * 0.5) y = (it.y) - (biggestdimensionY * 0.5) #needed offset for text centering blf.size(0, self.text_size, self.text_dpi) dimension = blf.dimensions(0, it.id) xt = ((biggestdimensionX - dimension[0]) * 0.5) yt = ((biggestdimensionY - dimension[1]) * 0.5) # Draw background buttons if sel and it_poll: bgl.glColor4f(self.ris, self.gis, self.bis, self.ais) else: bgl.glColor4f(self.ri, self.gi, self.bi, self.ai) #self.gl_pie_slice(bgl.GL_POLYGON, 8, it, x,y,30,90) #*** #http://www.opengl.org/archives/resources/faq/technical/rasterization.htm#rast0120 #self._round_box(bgl.GL_POLYGON, x - 20, y - 5, x + biggestdimensionX + 20, y + biggestdimensionY + 5) if it.screen_poly_bound: shape = it.screen_poly_bound pmu.draw_outline_or_region(bgl.GL_TRIANGLE_FAN, shape) bgl.glColor4f(self.ro, self.go, self.bo, 1.0) pmu.draw_outline_or_region(bgl.GL_LINE_LOOP, shape) bgl.glColor4f(self.ri, self.gi, self.bi, self.ai) #draw the circle if bpy.data.scenes[0].piemenus.clockBool: self._circle_(bgl.GL_TRIANGLE_FAN, (self.menu_x), (self.menu_y), 20) #draw the circle outline bgl.glColor4f(self.ro, self.go, self.bo, 1.0) self._circle_(bgl.GL_LINE_LOOP, (self.menu_x), (self.menu_y), 20) self._pointer_(bgl.GL_TRIANGLE_STRIP, (self.menu_x), (self.menu_y), self.pointerangle) # Draw text blf.enable(0, blf.SHADOW) blf.shadow_offset(0, 0, 0) blf.shadow(0, 5, 0.0, 0.0, 0.0, 1.0) if it_poll: bgl.glColor3f(self.rt, self.gt, self.bt) else: # grayed out bgl.glColor3f(0.5, 0.5, 0.5) blf.position(0, x + xt, y + yt, 0) blf.draw(0, it.id) blf.disable(0, blf.SHADOW) #bind the named texure to GL_TEXTURE_2D #http://stackoverflow.com/questions/11217121/how-to-manage-memory-with-texture-in-opengl bgl.glBindTexture(bgl.GL_TEXTURE_2D, context.scene.piemenus.pieIconBindcode) bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_NEAREST) bgl.glEnable(bgl.GL_TEXTURE_2D) bgl.glEnable(bgl.GL_BLEND) for it in self.menu_items: bgl.glColor4f(1, 1, 1, 1) if it.icon: #place the icon quad verts = it.screen_icon_quad bgl.glBegin(bgl.GL_QUADS) bgl.glTexCoord2f(it.tex_coords[0][0], it.tex_coords[0][1]) bgl.glVertex2f(verts[0][0], verts[0][1]) bgl.glTexCoord2f(it.tex_coords[1][0], it.tex_coords[1][1]) bgl.glVertex2f(verts[1][0], verts[1][1]) bgl.glTexCoord2f(it.tex_coords[2][0], it.tex_coords[2][1]) bgl.glVertex2f(verts[2][0], verts[2][1]) bgl.glTexCoord2f(it.tex_coords[3][0], it.tex_coords[3][1]) bgl.glVertex2f(verts[3][0], verts[3][1]) bgl.glEnd() #TODO #text value in center? #labe over top? bgl.glDisable(bgl.GL_BLEND) bgl.glDisable(bgl.GL_TEXTURE_2D)
def drawedges(self, vert, edge): def getedge(vert, edge): # get the next edge in list of edges rotating from/around vert at seelection END (for cursor choice) for loop in vert.link_loops: if loop.edge == edge: edge = loop.link_loop_prev.edge if edge == self.startedge: break self.sortlist.append(edge) getedge(vert, edge) break # get sorted list of possible cursor choices self.sortlist = [] self.startedge = edge getedge(vert, edge) if len(vert.link_edges) - len(self.sortlist) > 1: for e in vert.link_edges: if e != self.startedge: if not (e in self.sortlist): self.sortlist.append(e) # calculate new cursor position in sortlist if changed if self.change: if len(self.sortlist) == 2 and ( len(self.sortlist[0].link_faces) == 1 or len(self.sortlist[1].link_faces) == 1): for f in self.startedge.link_faces: for e in self.sortlist: tel = 0 if e.verts[0] in f.verts: tel += 1 vfound = e.verts[1] if e.verts[1] in f.verts: tel += 1 vfound = e.verts[0] if tel == 1: break for e in self.sortlist: if vfound in e.verts: cnt = self.sortlist.index(e) else: # standard middle edge is cursor cnt = int((len(self.sortlist) - 1) / 2) self.counter = cnt else: # do revert to START when past END and other way around if self.counter >= len(self.sortlist): cnt = self.counter - (int(self.counter / len(self.sortlist)) * len(self.sortlist)) elif self.counter < 0: cnt = self.counter while cnt < 0: cnt += len(self.sortlist) else: cnt = self.counter # draw cursor possibilities in blue, current in red for edge in self.sortlist: if self.sortlist.index(edge) == cnt: self.tempcur = edge glColor3f(1.0, 0, 0) else: glColor3f(0.2, 0.2, 1.0) glBegin(GL_LINES) x, y = self.getscreencoords(edge.verts[0].co) glVertex2f(x, y) x, y = self.getscreencoords(edge.verts[1].co) glVertex2f(x, y) glEnd()
def draw_postview(self, context, mesh, isBaseMesh): #mesh = self.mesh #temporary in case we decide it should be named differently a1 = 1.0 a2 = 1.0 if isBaseMesh and self.sublvl > 0: a1 = 0.5 a2 = .75 bgl.glEnable(bgl.GL_POINT_SMOOTH) bgl.glEnable(bgl.GL_BLEND) #draw the vertices for v in mesh.vertices: if v in self.selected: bgl.glColor4d(0.9, 0.5, 0, a2) bgl.glPointSize(4) else: bgl.glColor4d(1, 1, 0, a1) bgl.glPointSize(2) bgl.glBegin(bgl.GL_POINTS) bgl.glVertex3f(*v.co.to_tuple()) bgl.glEnd() bgl.glDepthRange(0.0, 0.9999) #draw the edges for e in mesh.edges: if e in self.selected: bgl.glColor4d(0.9, 0.5, 0, a2) bgl.glLineWidth(2) else: bgl.glColor4d(0.5, 0.5, 0, a1) bgl.glLineWidth(1) bgl.glBegin(bgl.GL_LINES) bgl.glVertex3f(*e.v0.co.to_tuple()) bgl.glVertex3f(*e.v1.co.to_tuple()) bgl.glEnd() bgl.glDepthRange(0.0, 1.0) #draw the faces bgl.glBegin(bgl.GL_TRIANGLES) for f in mesh.faces: if f in self.selected: bgl.glColor4d(0.6, 0.2, 0, a2) else: bgl.glColor4d(0.3, 0.3, 0.3, a1) a = 0 b = 1 c = 2 for i in range(len(f.lvertices) - 2): bgl.glVertex3f(*f.lvertices[a].co.to_tuple()) bgl.glVertex3f(*f.lvertices[b].co.to_tuple()) bgl.glVertex3f(*f.lvertices[c].co.to_tuple()) b += 1 c += 1 bgl.glEnd() if False: bgl.glColor3f(0, 1, 1) bgl.glBegin(bgl.GL_LINES) for f in mesh.faces: p0 = Vector() for v in f.lvertices: p0 += v.co p0 /= len(f.lvertices) p1 = p0 + f.normal * 0.2 bgl.glVertex3f(*p0) bgl.glVertex3f(*p1) bgl.glEnd()
def draw_callback_px(): context = bpy.context from bgl import glColor3f font_id = 0 # XXX, need to find out how best to get this. blf.size(font_id, 12, 72) data_matrix, data_quat, data_euler, data_vector, data_vector_array = utils.console_math_data( ) name_hide = context.window_manager.MathVisProp.name_hide if name_hide: return if not data_matrix and not data_quat and not data_euler and not data_vector and not data_vector_array: ''' # draw some text glColor3f(1.0, 0.0, 0.0) blf.position(font_id, 180, 10, 0) blf.draw(font_id, "Python Console has no mathutils definitions") ''' return glColor3f(1.0, 1.0, 1.0) region = context.region region3d = context.space_data.region_3d region_mid_width = region.width / 2.0 region_mid_height = region.height / 2.0 # vars for projection perspective_matrix = region3d.perspective_matrix.copy() def draw_text(text, vec, dx=3.0, dy=-4.0): vec_4d = perspective_matrix * vec.to_4d() if vec_4d.w > 0.0: x = region_mid_width + region_mid_width * (vec_4d.x / vec_4d.w) y = region_mid_height + region_mid_height * (vec_4d.y / vec_4d.w) blf.position(font_id, x + dx, y + dy, 0.0) blf.draw(font_id, text) # points if data_vector: for key, vec in data_vector.items(): draw_text(key, vec) # lines if data_vector_array: for key, vec in data_vector_array.items(): draw_text(key, vec[0]) # matrix if data_matrix: for key, mat in data_matrix.items(): loc = Vector((mat[0][3], mat[1][3], mat[2][3])) draw_text(key, loc, dx=10, dy=-20) line = 20 if data_quat: loc = context.scene.cursor_location.copy() for key, mat in data_quat.items(): draw_text(key, loc, dy=-line) line += 20 if data_euler: loc = context.scene.cursor_location.copy() for key, mat in data_euler.items(): draw_text(key, loc, dy=-line) line += 20
def draw_prefab_locator(obj, scs_globals): """ Draw Prefab locator. :param obj: :return: """ size = scs_globals.locator_size empty_size = scs_globals.locator_empty_size mat_sca = Matrix.Scale(size, 4) mat_orig = obj.matrix_world mat = mat_orig * mat_sca if obj.scs_props.locator_prefab_type == 'Control Node': _primitive.draw_shape_x_axis(mat, empty_size) _primitive.draw_shape_y_axis_neg(mat, empty_size) _primitive.draw_shape_z_axis(mat, empty_size) draw_shape_control_node(mat, scs_globals) glPointSize(12.0) glBegin(GL_POINTS) if obj.scs_props.locator_prefab_con_node_index == '0': glColor3f(1, 0, 0) else: glColor3f(0, 1, 0) glVertex3f(*(mat * Vector((0.0, 0.0, 0.0)))) glEnd() glPointSize(1.0) elif obj.scs_props.locator_prefab_type == 'Sign': _primitive.draw_shape_x_axis(mat, empty_size) _primitive.draw_shape_y_axis(mat, empty_size) _primitive.draw_shape_z_axis_neg(mat, empty_size) if not obj.scs_props.locator_preview_model_present or not scs_globals.show_preview_models: draw_shape_sign(mat, scs_globals) elif obj.scs_props.locator_prefab_type == 'Spawn Point': _primitive.draw_shape_x_axis(mat, empty_size) _primitive.draw_shape_y_axis(mat, empty_size) _primitive.draw_shape_z_axis_neg(mat, empty_size) if not obj.scs_props.locator_preview_model_present or not scs_globals.show_preview_models: draw_shape_spawn_point(mat, scs_globals) elif obj.scs_props.locator_prefab_type == 'Traffic Semaphore': _primitive.draw_shape_x_axis(mat, empty_size) _primitive.draw_shape_y_axis(mat, empty_size) _primitive.draw_shape_z_axis_neg(mat, empty_size) if not obj.scs_props.locator_preview_model_present or not scs_globals.show_preview_models: draw_shape_traffic_light(mat, scs_globals) elif obj.scs_props.locator_prefab_type == 'Navigation Point': _primitive.draw_shape_x_axis(mat, empty_size) _primitive.draw_shape_y_axis_neg(mat, empty_size) _primitive.draw_shape_z_axis(mat, empty_size) draw_shape_control_node(mat, scs_globals) elif obj.scs_props.locator_prefab_type == 'Map Point': _primitive.draw_shape_x_axis(mat, empty_size) _primitive.draw_shape_y_axis(mat, empty_size) _primitive.draw_shape_z_axis(mat, empty_size) draw_shape_map_point(mat, scs_globals) elif obj.scs_props.locator_prefab_type == 'Trigger Point': _primitive.draw_shape_x_axis(mat, empty_size) _primitive.draw_shape_y_axis(mat, empty_size) _primitive.draw_shape_z_axis(mat, empty_size) is_sphere = obj.scs_props.locator_prefab_tp_sphere_trigger draw_shape_trigger_point(mat, mat_orig, obj.scs_props.locator_prefab_tp_range, scs_globals, is_sphere)
def draw_callback_view(handle, sl1, sl2, sl3, vs, colo, tran, shade): context = bpy.context from bgl import glEnable, glDisable, glColor3f, glVertex3f, glPointSize, glLineWidth, glBegin, glEnd, glLineStipple, GL_POINTS, GL_LINE_STRIP, GL_LINES, GL_LINE, GL_LINE_STIPPLE, GL_POLYGON, GL_POLYGON_STIPPLE, GL_POLYGON_SMOOTH, glPolygonStipple from bgl import GL_TRIANGLES, GL_QUADS, glColor4f # define globals, separate edgs from pols if tran: polyholy = GL_POLYGON_STIPPLE else: polyholy = GL_POLYGON if sl1: data_vector = Vector_generate(sl1) verlen = len(data_vector) - 1 else: data_vector = [] verlen = 0 if sl2: if len(sl2[0][0]) == 2: data_edges = sl2 data_polygons = [] elif len(sl2[0][0]) > 2: data_polygons = sl2 data_edges = [] else: data_edges, data_polygons = [], [] if sl3: data_matrix = Matrix_generate(sl3) else: data_matrix = [Matrix() for i in range(verlen + 1)] coloa = colo[0] colob = colo[1] coloc = colo[2] if (data_vector, data_polygons, data_matrix, data_edges) == (0, 0, 0, 0): callback_disable(handle) #print ('вход', sl1, sl2, sl3) #print ('преобраз', data_vector) # draw_matrix vars zero = Vector((0.0, 0.0, 0.0)) x_p = Vector((0.5, 0.0, 0.0)) x_n = Vector((-0.5, 0.0, 0.0)) y_p = Vector((0.0, 0.5, 0.0)) y_n = Vector((0.0, -0.5, 0.0)) z_p = Vector((0.0, 0.0, 0.5)) z_n = Vector((0.0, 0.0, -0.5)) bb = [Vector() for i in range(24)] 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() ######## # points if vs: if data_vector: glPointSize(3.0) glColor3f(0.8, 0.9, 1.0) for i, matrix in enumerate(data_matrix): glBegin(GL_POINTS) k = i if i > verlen: k = verlen for vert in data_vector[k]: vec_corrected = data_matrix[i] * vert glVertex3f(*vec_corrected) #print ('рисовальня', matrix, vec_corrected) glEnd() glPointSize(3.0) ####### # lines if data_edges and data_vector: glColor3f(coloa, colob, coloc) glLineWidth(1.0) glEnable(GL_LINES) for i, matrix in enumerate(data_matrix): # object k = i if i > verlen: k = verlen for line in data_edges[k]: # line glBegin(GL_LINES) for point in line: # point vec_corrected = data_matrix[i] * data_vector[k][int(point)] glVertex3f(*vec_corrected) glEnd() glPointSize(1.75) glLineWidth(1.0) glDisable(GL_LINES) ####### # polygons vectorlight = Vector((-0.66, -0.66, -0.66)) if data_polygons and data_vector: glLineWidth(1.0) glEnable(polyholy) for i, matrix in enumerate(data_matrix): # object k = i if i > verlen: k = verlen oblen = len(data_polygons[k]) for j, pol in enumerate(data_polygons[k]): if shade: normal_no_ = mathutils.geometry.normal( data_vector[k][pol[0]], data_vector[k][pol[1]], data_vector[k][pol[2]]) normal_no = (normal_no_.angle(vectorlight, 0)) / math.pi randa = (normal_no * coloa) - 0.1 randb = (normal_no * colob) - 0.1 randc = (normal_no * coloc) - 0.1 else: randa = ((j / oblen) + coloa) / 2.5 randb = ((j / oblen) + colob) / 2.5 randc = ((j / oblen) + coloc) / 2.5 if len(pol) > 4: glBegin(GL_TRIANGLES) glColor4f(randa + 0.2, randb + 0.2, randc + 0.2, 0.5) #glColor3f(randa+0.2, randb+0.2, randc+0.2) v = [data_vector[k][i] for i in pol] tess_poly = mathutils.geometry.tessellate_polygon([v]) for a, b, c in tess_poly: glVertex3f(*(data_matrix[i] * v[a])) glVertex3f(*(data_matrix[i] * v[b])) glVertex3f(*(data_matrix[i] * v[c])) elif len(pol) == 4: glBegin(GL_POLYGON) glColor3f(randa + 0.2, randb + 0.2, randc + 0.2) for point in pol: vec_corrected = data_matrix[i] * data_vector[k][int( point)] glVertex3f(*vec_corrected) else: glBegin(GL_TRIANGLES) glColor3f(randa + 0.2, randb + 0.2, randc + 0.2) for point in pol: vec_corrected = data_matrix[i] * data_vector[k][int( point)] glVertex3f(*vec_corrected) glEnd() glPointSize(1.75) glLineWidth(1.0) glDisable(polyholy) # for future bezier drawing - to remake #if data_edges and data_vector and bezier: # here 3 lines that i must understand #from bpy_extras.view3d_utils import location_3d_to_region_2d #region = context.region #region_data = context.region_data #glEnable(GL_BLEND) #glColor4f(1, 0, 0, 0.5) #glLineWidth(1.0) #glBegin(GL_LINE_STRIP) #for i in range(current_frame): #glVertex2f(*location_3d_to_region_2d(region, region_data, (math.sin(i / 10), 0, i / 10)).to_tuple()) #glEnd() #glDisable(GL_BLEND) ####### # matrix if data_matrix and not data_vector: for mat in data_matrix: draw_matrix(mat)
def text(self, text, arg1=0, arg2=0, arg3=0): x = 0 y = 0 z = 0 rx = 0 ry = 0 rz = 0 if type(arg1) is mathutils.Vector(): x = arg1.x y = arg1.y z = arg1.z if type(arg2) is mathutils.Vector(): rx = arg2.x ry = arg2.y rz = arg2.z elif type(arg1) is bge.types.KX_GameObject or type(arg1) is str: if type(arg1) is str: arg1 = self.getObjectByName(arg1) if arg1 is not 0: o = self.getPosition(arg1) x = o.x y = o.y z = o.z # translation vector if type(arg2) is mathutils.Vector(): x += arg2.x y += arg2.y z += arg2.z # rotation vector if type(arg3) is mathutils.Vector(): rx = arg3.x ry = arg3.y rz = arg3.z elif type(arg1) is float and type(arg2) is float and type( arg3) is float: x = arg1 y = arg2 z = arg3 elif type(arg1) is int and type(arg2) is int and type(arg3) is int: x = arg1 y = arg2 z = arg3 width = bge.render.getWindowWidth() height = bge.render.getWindowHeight() ratiow = 1. / width ratioh = 1. / height bgl.glPushMatrix() bgl.glTranslatef(x, y, z) #TODO transform angles to matrix! # bgl.glRotate( rx,ry,rz ) bgl.glScalef(ratiow, ratioh, 0) blf.position(self.font, 0, 0, 0) blf.size(self.font, self.tsize, 300) bgl.glColor3f(self.tcolor.x, self.tcolor.y, self.tcolor.z) blf.draw(self.font, text) bgl.glPopMatrix()
def draw_polygon_object(mat, vertices, faces, face_color, draw_faces, draw_wires, wire_lines=None, wire_color=(0, 0, 0), face_transforms=None, wire_transforms=None): """ Draw a collider polygon object. It takes matrix, vertices (coordinates), faces (vertex index references), face color (RGB), faces drawing state (bool), wires drawing state (bool) and optional values wire lines (list of lists of vertex positions resulting in closed lines), wire color (RGB), face transformations (list of vertex indices) and wire transformations (list of vertex indices). :param mat: :param vertices: :param faces: :param face_color: :param draw_faces: :param draw_wires: :param wire_lines: :param wire_color: :param face_transforms: :param wire_transforms: :return: """ if draw_faces: for face in faces: glBegin(GL_POLYGON) glColor3f(face_color[0], face_color[1], face_color[2]) for vert in face: if face_transforms: trans = mat for transformation in face_transforms: if vert in transformation[1]: trans = trans * transformation[0] glVertex3f(*(trans * Vector(vertices[vert]))) else: glVertex3f(*(mat * Vector(vertices[vert]))) glEnd() if draw_wires: if wire_lines: # DRAW CUSTOM LINES vert_i_global = 0 for line in wire_lines: # glLineWidth(2.0) glEnable(GL_LINE_STIPPLE) glBegin(GL_LINES) glColor3f(wire_color[0], wire_color[1], wire_color[2]) for vert_i, vert1 in enumerate(line): if vert_i + 1 < len(line): vert2 = line[vert_i + 1] else: continue # SEPARATE PART TRANSFORMATIONS if wire_transforms: trans1 = trans2 = mat for transformation in wire_transforms: if vert_i_global in transformation[1]: trans1 = trans1 * transformation[0] if vert_i_global + 1 in transformation[1]: trans2 = trans2 * transformation[0] glVertex3f(*(trans1 * Vector(vert1))) glVertex3f(*(trans2 * Vector(vert2))) else: glVertex3f(*(mat * Vector(vert1))) glVertex3f(*(mat * Vector(vert2))) vert_i_global += 1 vert_i_global += 1 glEnd() glDisable(GL_LINE_STIPPLE) # glLineWidth(1.0) else: for face in faces: # glLineWidth(2.0) glEnable(GL_LINE_STIPPLE) glBegin(GL_LINES) glColor3f(wire_color[0], wire_color[1], wire_color[2]) for vert_i, vert1 in enumerate(face): if vert_i + 1 == len(face): vert2 = face[0] else: vert2 = face[vert_i + 1] if face_transforms: trans1 = mat trans2 = mat vec1 = Vector(vertices[vert1]) vec2 = Vector(vertices[vert2]) for transformation in face_transforms: if vert1 in transformation[1]: trans1 = trans1 * transformation[0] if vert2 in transformation[1]: trans2 = trans2 * transformation[0] glVertex3f(*(trans1 * vec1)) glVertex3f(*(trans2 * vec2)) else: glVertex3f(*(mat * Vector(vertices[vert1]))) glVertex3f(*(mat * Vector(vertices[vert2]))) glEnd() glDisable(GL_LINE_STIPPLE) # glLineWidth(1.0) if 0: # DEBUG: draw points from faces geometry glPointSize(3.0) glBegin(GL_POINTS) glColor3f(0.5, 0.5, 1) for vertex_i, vertex in enumerate(vertices): vec = Vector(vertex) if face_transforms: trans = mat for transformation in face_transforms: if vertex_i in transformation[1]: trans = trans * transformation[0] glVertex3f(*(trans * vec)) else: glVertex3f(*(mat * vec.to_3d())) glEnd() glPointSize(1.0) if 0: # DEBUG: draw points from lines geometry if wire_lines: glPointSize(3.0) glBegin(GL_POINTS) glColor3f(1, 0, 0.5) vert_i_global = 0 for line in wire_lines: for vert_i, vertex in enumerate(line): if vert_i + 1 < len(line): vec = Vector(vertex) else: continue if wire_transforms: trans = mat for transformation in wire_transforms: if vert_i_global in transformation[1]: trans = trans * transformation[0] glVertex3f(*(trans * vec.to_3d())) else: glVertex3f(*(mat * vec.to_3d())) vert_i_global += 1 vert_i_global += 1 glEnd() glPointSize(1.0)
def draw_edge(coords, mode, lt): bgl.glColor3f(*line_colors[mode]) draw_gl_strip(coords, lt)
def draw_callback(cls, context): # FIXME: 起動中にaddonを無効にした場合,get_instance()が例外を吐く prefs = ScreenCastKeysPreferences.get_instance() """:type: ScreenCastKeysPreferences""" if context.window.as_pointer() != cls.origin['window']: return rect = cls.calc_draw_rectangle(context) if not rect: return xmin, ymin, xmax, ymax = rect win, _area, _region, x, y = cls.get_origin(context) w = xmax - x h = ymax - y if w == h == 0: return region = context.region area = context.area if region.type == 'WINDOW': r_xmin, r_ymin, r_xmax, r_ymax = region_window_rectangle(area) else: r_xmin, r_ymin, r_xmax, r_ymax = (region.x, region.y, region.x + region.width - 1, region.y + region.height - 1) if not intersect_aabb((r_xmin, r_ymin), (r_xmax, r_ymax), (xmin + 1, ymin + 1), (xmax - 1, ymax - 1)): return current_time = time.time() draw_any = False font_size = prefs.font_size font_id = 0 dpi = context.user_preferences.system.dpi blf.size(font_id, font_size, dpi) def draw_text(text): col = prefs.color_shadow bgl.glColor4f(*col[:3], col[3] * 20) blf.blur(font_id, 5) blf.draw(font_id, text) blf.blur(font_id, 0) bgl.glColor3f(*prefs.color) blf.draw(font_id, text) def draw_line(p1, p2): bgl.glEnable(bgl.GL_BLEND) bgl.glEnable(bgl.GL_LINE_SMOOTH) bgl.glLineWidth(3.0) bgl.glColor4f(*prefs.color_shadow) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(*p1) bgl.glVertex2f(*p2) bgl.glEnd() bgl.glLineWidth(1.0 if prefs.color_shadow[-1] == 0.0 else 1.5) bgl.glColor3f(*prefs.color) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(*p1) bgl.glVertex2f(*p2) bgl.glEnd() bgl.glLineWidth(1.0) bgl.glDisable(bgl.GL_LINE_SMOOTH) # user_preferences.system.use_region_overlapが真の場合に、 # 二重に描画されるのを防ぐ glscissorbox = bgl.Buffer(bgl.GL_INT, 4) bgl.glGetIntegerv(bgl.GL_SCISSOR_BOX, glscissorbox) if context.area.type == 'VIEW_3D' and region.type == 'WINDOW': xmin, ymin, xmax, ymax = region_rectangle_v3d(context) bgl.glScissor(xmin, ymin, xmax - xmin + 1, ymax - ymin + 1) th = blf.dimensions(0, string.printable)[1] px = x - region.x py = y - region.y operator_log = cls.removed_old_operator_log() if prefs.show_last_operator and operator_log: t, name, idname_py, addr = operator_log[-1] if current_time - t <= prefs.display_time: color = prefs.color bgl.glColor3f(*color) text = bpy.app.translations.pgettext_iface(name, 'Operator') text += " ('{}')".format(idname_py) blf.position(font_id, px, py, 0) draw_text(text) py += th + th * cls.SEPARATOR_HEIGHT * 0.2 tw = blf.dimensions(font_id, 'Left Mouse')[0] # 適当 draw_line((px, py), (px + tw, py)) py += th * cls.SEPARATOR_HEIGHT * 0.8 draw_any = True else: py += th + th * cls.SEPARATOR_HEIGHT bgl.glColor3f(*prefs.color) margin = th * 0.2 if cls.hold_keys or mhm.is_rendering(): col = prefs.color_shadow[:3] + (prefs.color_shadow[3] * 2, ) mod_names = cls.sorted_modifiers(cls.hold_keys) if mhm.is_rendering(): if 0: text = '- - -' else: text = '' else: text = ' + '.join(mod_names) ofsy = -th * 0.0 box_h = th + margin * 2 blf.position(font_id, px, py + margin, 0) draw_text(text) w, h = blf.dimensions(font_id, text) vagl.draw_rounded_box(px - margin, py - margin + ofsy, w + margin * 2, box_h, box_h * 0.2) draw_any = True py += th + margin * 2 event_log = cls.removed_old_event_log() py += th * cls.SEPARATOR_HEIGHT for event_time, event_type, modifiers, count in event_log[::-1]: color = prefs.color bgl.glColor3f(*color) text = event_type.names[event_type.name] if modifiers: mod_names = cls.sorted_modifiers(modifiers) text = ' + '.join(mod_names) + ' + ' + text if count > 1: text += ' x' + str(count) blf.position(font_id, px, py, 0) # blf.draw(font_id, text) draw_text(text) py += th draw_any = True bgl.glDisable(bgl.GL_BLEND) bgl.glScissor(*glscissorbox) bgl.glLineWidth(1.0) # blf.disable(font_id, blf.SHADOW) if draw_any: cls.draw_regions_prev.add(region.as_pointer())
def draw_geometry(n_id, options, data_vector, data_polygons, data_matrix, data_edges): show_verts = options['show_verts'] show_edges = options['show_edges'] show_faces = options['show_faces'] vertex_colors = options['vertex_colors'] edge_colors = options['edge_colors'] edge_width = options['edge_width'] tran = options['transparent'] shade = options['shading'] verlen = options['verlen'] max_verts_ = [len(d) for d in data_vector] if tran: polyholy = GL_POLYGON_STIPPLE edgeholy = GL_LINE_STIPPLE edgeline = GL_LINE_STRIP else: polyholy = GL_POLYGON edgeholy = GL_LINE edgeline = GL_LINES def get_max_k(i, verlen): k = i if i > verlen: k = verlen return k ''' vertices ''' glEnable(GL_POINT_SIZE) glEnable(GL_POINT_SMOOTH) glHint(GL_POINT_SMOOTH_HINT, GL_NICEST) # glHint(GL_POINT_SMOOTH_HINT, GL_FASTEST) vsize = options['vertex_size'] if show_verts and data_vector: glPointSize(vsize) glColor3f(*vertex_colors) glBegin(GL_POINTS) for i, matrix in enumerate(data_matrix): k = get_max_k(i, verlen) for vert in data_vector[k]: vec = data_matrix[i] * vert glVertex3f(*vec) glEnd() glDisable(GL_POINT_SIZE) glDisable(GL_POINT_SMOOTH) ''' polygons ''' if data_polygons and data_vector: num_datapolygon_lists = len(data_polygons) glEnable(polyholy) for i, matrix in enumerate(data_matrix): k = get_max_k(i, verlen) mesh_edges = set() if k >= num_datapolygon_lists: k = (num_datapolygon_lists - 1) #break for j, pol in enumerate(data_polygons[k]): if max(pol) >= max_verts_[k]: continue if show_faces: display_face(options, pol, data_vector, data_matrix, k, i) # collect raw edges, sort by index, use set to prevent dupes. if show_edges: er = list(pol) + [pol[0]] kb = { tuple(sorted((e, er[i + 1]))) for i, e in enumerate(er[:-1]) } mesh_edges.update(kb) if show_edges and mesh_edges: # glHint(GL_LINE_SMOOTH_HINT, GL_NICEST) glEnable(edgeholy) glLineWidth(edge_width) glColor3f(*edge_colors) glBegin(GL_LINES) for edge in mesh_edges: for p in edge: vec = data_matrix[i] * data_vector[k][p] glVertex3f(*vec) glEnd() glDisable(edgeholy) glDisable(polyholy) ''' edges ''' if data_edges and data_vector and show_edges: glColor3f(*edge_colors) glLineWidth(edge_width) glEnable(edgeholy) for i, matrix in enumerate(data_matrix): k = get_max_k(i, verlen) if k >= len(data_edges): continue for line in data_edges[k]: # i think this catches edges which refer to indices not present in # the accompanying vertex list. if max(line) >= max_verts_[k]: continue glBegin(edgeline) for p in line: vec = data_matrix[i] * data_vector[k][p] glVertex3f(*vec) glEnd() glDisable(edgeholy) ''' matrix ''' if data_matrix and not data_vector: md = MatrixDraw() for mat in data_matrix: md.draw_matrix(mat)
def draw_text(color, xpos, ypos, line): bgl.glColor3f(*color) blf.position(0, xpos, ypos, 0) blf.draw(font_id, line) return blf.dimensions(font_id, line)
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_postview(self, context): ''' Place drawing code in here ''' t111 = self.cntrlList[0].to_tuple() # sample code to draw corners of cube bgl.glEnable(bgl.GL_POINT_SMOOTH) bgl.glColor3d(0, 0, 0) bgl.glPointSize(3) bgl.glBegin(bgl.GL_POINTS) bgl.glVertex3f( *t111 ) # Note: *t111 expands elements of tuple as individual parameters bgl.glVertex3f(1, -1, 1) bgl.glVertex3f(-1, -1, 1) bgl.glVertex3f(-1, 1, 1) bgl.glVertex3f(1, 1, -1) bgl.glVertex3f(1, -1, -1) bgl.glVertex3f(-1, -1, -1) bgl.glVertex3f(-1, 1, -1) bgl.glEnd() # sample code to draw top and bottom edges of cube bgl.glLineWidth(1) bgl.glColor3f(0, 0, 0) bgl.glBegin(bgl.GL_LINES) bgl.glVertex3f(*t111) bgl.glVertex3f(-1, 1, 1) bgl.glVertex3f(-1, 1, 1) bgl.glVertex3f(-1, -1, 1) bgl.glVertex3f(-1, -1, 1) bgl.glVertex3f(1, -1, 1) bgl.glVertex3f(1, -1, 1) bgl.glVertex3f(*t111) bgl.glVertex3f(1, 1, -1) bgl.glVertex3f(-1, 1, -1) bgl.glVertex3f(-1, 1, -1) bgl.glVertex3f(-1, -1, -1) bgl.glVertex3f(-1, -1, -1) bgl.glVertex3f(1, -1, -1) bgl.glVertex3f(1, -1, -1) bgl.glVertex3f(1, 1, -1) bgl.glVertex3f(*t111) bgl.glVertex3f(1, 1, -1) bgl.glEnd() # sample code to show highlighting picked geometry if len(self.selectCntrl): cntrlLength = len(self.selectCntrl) for x in range(0, cntrlLength): # assuming that we have only one control point, so if # anything is selected it would be the only point p111 = self.selectCntrl[x] t111 = p111.to_tuple() vrot = context.space_data.region_3d.view_rotation dx = (vrot * Vector( (1, 0, 0))).normalized() # compute right dir relative to view dy = (vrot * Vector( (0, 1, 0))).normalized() # compute up dir relative to view px = tuple(p111 + dx * 0.5) py = tuple(p111 + dy * 0.5) # highlight the point bgl.glColor3f(1, 1, 0) bgl.glBegin(bgl.GL_POINTS) bgl.glVertex3f(*t111) bgl.glEnd() # draw lines to indicate right (red) and up (green) bgl.glBegin(bgl.GL_LINES) bgl.glColor3f(1, 0, 0) bgl.glVertex3f(*t111) bgl.glVertex3f(*px) bgl.glColor3f(0, 1, 0) bgl.glVertex3f(*t111) bgl.glVertex3f(*py) bgl.glEnd()
def drawCallback(): if bpy.context.mode == 'EDIT_MESH': obj = bpy.context.object bl = obj.border_lines if obj and obj.type == 'MESH' and obj.data: if bl.borderlines_use: mesh = obj.data matrix_world = obj.matrix_world settings = bpy.context.user_preferences.themes[0].view_3d transform = settings.transform edge_select = settings.edge_select wire_edit = settings.wire_edit wire = settings.wire object_active = settings.object_active glLineWidth(bl.borderlines_width) draw_with_test = True if bm_old[0] is None or not bm_old[0].is_valid: bm = bm_old[0] = bmesh.from_edit_mesh(mesh) else: bm = bm_old[0] no_depth = not bpy.context.space_data.use_occlude_geometry if no_depth: glDisable(GL_DEPTH_TEST) draw_with_test = False if bl.finer_lines_behind_use: glLineWidth(bl.borderlines_width / 4.0) draw_with_test = True glBegin(GL_LINES) if bl.custom_color_use: glColor3f(*bl.custom_color) for edge in bm.edges: if edge.is_valid and edge.is_boundary: coords = [ matrix_world * vert.co for vert in edge.verts ] for coord in coords: glVertex3f(*coord) else: active = bm.select_history.active for edge in bm.edges: if edge.is_valid and edge.is_boundary and not edge.hide: coords = [ matrix_world * vert.co for vert in edge.verts ] if active == edge: drawColorSize(coords, transform) elif edge.select: drawColorSize(coords, edge_select) else: drawColorSize(coords, wire_edit) glEnd() glLineWidth(bl.borderlines_width) glEnable(GL_DEPTH_TEST) if draw_with_test: glBegin(GL_LINES) if bl.custom_color_use: glColor3f(*bl.custom_color) for edge in bm.edges: if edge.is_valid and edge.is_boundary: coords = [ matrix_world * vert.co for vert in edge.verts ] for coord in coords: glVertex3f(*coord) else: active = bm.select_history.active for edge in bm.edges: if edge.is_valid and edge.is_boundary: coords = [ matrix_world * vert.co for vert in edge.verts ] if active == edge: drawColorSize(coords, transform) elif edge.select: drawColorSize(coords, edge_select) else: drawColorSize(coords, wire_edit) glEnd() elif bpy.context.mode == 'OBJECT': for obj in bpy.context.visible_objects: if obj and obj.type == 'MESH' and obj.data: if (obj.show_wire or bpy.context.space_data.viewport_shade == 'WIREFRAME'): bl = obj.border_lines if bl.borderlines_use: mesh = obj.data matrix_world = obj.matrix_world settings = bpy.context.user_preferences.themes[ 0].view_3d wire = settings.wire object_selected = settings.object_selected counts = edge_face_count(mesh) glLineWidth(bl.borderlines_width) glBegin(GL_LINES) if bl.custom_color_use: glColor3f(*bl.custom_color) elif obj == bpy.context.active_object and obj.select: glColor3f(*settings.object_active) elif obj.select: glColor3f(*settings.object_selected) else: glColor3f(*settings.wire) for edge, count in zip(mesh.edges, counts): # border edges if count == 1: coords = [ matrix_world * Vector(mesh.vertices[i].co) for i in edge.key ] for coord in coords: glVertex3f(*coord) glEnd() glLineWidth(1.0)
def drawColorSize(coords, color): glColor3f(*color[:3]) for coord in coords: glVertex3f(*coord)
def draw_callback_px_text(self, context): scene = bpy.context.scene panel_prefs = bpy.context.user_preferences.addons[__package__].preferences font_path = blf.load(panel_prefs.filepath_all) font_path_0 = blf.load(panel_prefs.filepath_0) font_path_1 = blf.load(panel_prefs.filepath_1) font_path_2 = blf.load(panel_prefs.filepath_2) font_path_3 = blf.load(panel_prefs.filepath_3) font_path_4 = blf.load(panel_prefs.filepath_4) font_path_5 = blf.load(panel_prefs.filepath_5) font_path_6 = blf.load(panel_prefs.filepath_6) font_path_7 = blf.load(panel_prefs.filepath_7) text_width_title = panel_prefs.text_width_title text_height_title = panel_prefs.text_height_title text_pos_x = panel_prefs.text_pos_x text_pos_y = panel_prefs.text_pos_y # HEADER AND SHELFS # hheader = context.area.regions[0].height # 26px tpanel = context.area.regions[1].width npanel = context.area.regions[3].width # zero out tpanel width, if region overlap it turned on if context.user_preferences.system.use_region_overlap: tpanel = 0 # fetch real space in between self.REALx = context.area.width - npanel - tpanel self.REALy = context.area.height + hheader text_shadow = panel_prefs.text_shadow text_shadow_color = panel_prefs.text_shadow_color text_shadow_alpha = panel_prefs.text_shadow_alpha text_shadow_x = panel_prefs.text_shadow_x text_shadow_y = panel_prefs.text_shadow_y # TITLE 0 # if panel_prefs.dodraw == "ZERO": # POSITION # if context.user_preferences.addons[ __package__].preferences.tab_pos_link == True: text_0_pos_x = panel_prefs.text_0_pos_x text_0_pos_y = panel_prefs.text_0_pos_y else: text_0_pos_x = panel_prefs.text_pos_x text_0_pos_y = panel_prefs.text_pos_y # SCALE # if context.user_preferences.addons[ __package__].preferences.tab_scal_link == True: text_0_width_title = panel_prefs.text_0_width_title text_0_height_title = panel_prefs.text_0_height_title else: text_0_width_title = panel_prefs.text_width_title text_0_height_title = panel_prefs.text_height_title # COLOR # if context.user_preferences.addons[ __package__].preferences.tab_color_link == False: text_color = panel_prefs.text_color bgl.glColor3f(*text_color) else: text_0_color = panel_prefs.text_0_color bgl.glColor3f(*text_0_color) # FONT # if context.user_preferences.addons[ __package__].preferences.tab_font_external == False: if context.user_preferences.addons[ __package__].preferences.tab_font_unit == False: font_id_0 = font_path else: font_id_0 = font_path_0 else: font_id_0 = 0 # FILEPATH FIELD # text_0_text = panel_prefs.text_0_text # length of the text line line_width, line_height = blf.dimensions(font_id_0, text_0_text) self.line_0_width = line_width self.line_0_height = line_height # APPLY PREFERENCES # if context.user_preferences.addons[ __package__].preferences.tab_center == 'middle': blf.position( font_id_0, (self.REALx / 2 - self.line_0_width / 2 + text_0_pos_x), (self.REALy / 2 - self.line_0_height + text_0_pos_y), 0) else: blf.position(font_id_0, (text_0_pos_x + 20), (self.REALy / 2 - self.line_0_height + text_0_pos_y), 0) blf.size(font_id_0, text_0_width_title, text_0_height_title + 10) blf.draw(font_id_0, text_0_text) # DROPSHADOW # if context.user_preferences.addons[ __package__].preferences.text_shadow == True: blf.enable(font_id_0, blf.SHADOW) blf.shadow_offset(font_id_0, text_shadow_x, text_shadow_y) blf.shadow(font_id_0, 5, text_shadow_color[0], text_shadow_color[1], text_shadow_color[2], text_shadow_alpha) else: blf.disable(font_id_0, blf.SHADOW) # TITLE 1 # if panel_prefs.dodraw == "ONE": # POSITION # if context.user_preferences.addons[ __package__].preferences.tab_pos_link == True: text_1_pos_x = panel_prefs.text_1_pos_x text_1_pos_y = panel_prefs.text_1_pos_y else: text_1_pos_x = panel_prefs.text_pos_x text_1_pos_y = panel_prefs.text_pos_y # SCALE # if context.user_preferences.addons[ __package__].preferences.tab_scal_link == True: text_1_width_title = panel_prefs.text_1_width_title text_1_height_title = panel_prefs.text_1_height_title else: text_1_width_title = panel_prefs.text_width_title text_1_height_title = panel_prefs.text_height_title # COLOR # if context.user_preferences.addons[ __package__].preferences.tab_color_link == False: text_color = panel_prefs.text_color bgl.glColor3f(*text_color) else: text_1_color = panel_prefs.text_1_color bgl.glColor3f(*text_1_color) # FONT # if context.user_preferences.addons[ __package__].preferences.tab_font_external == False: if context.user_preferences.addons[ __package__].preferences.tab_font_unit == False: font_id_1 = font_path else: font_id_1 = font_path_1 else: font_id_1 = 0 # FILEPATH FIELD # text_1_text = panel_prefs.text_1_text # length of the text line line_width, line_height = blf.dimensions(font_id_1, text_1_text) self.line_1_width = line_width self.line_1_height = line_height # APPLY PREFERENCES # if context.user_preferences.addons[ __package__].preferences.tab_center == 'middle': blf.position( font_id_1, (self.REALx / 2 - self.line_1_width / 2 + text_1_pos_x), (self.REALy / 2 - self.line_1_height + text_1_pos_y), 0) else: blf.position(font_id_1, (text_1_pos_x + 20), (self.REALy / 2 - self.line_1_height + text_1_pos_y), 0) blf.size(font_id_1, text_1_width_title, text_1_height_title + 10) blf.draw(font_id_1, text_1_text) # DROPSHADOW # if context.user_preferences.addons[ __package__].preferences.text_shadow == True: blf.enable(font_id_1, blf.SHADOW) blf.shadow_offset(font_id_1, text_shadow_x, text_shadow_y) blf.shadow(font_id_1, 5, text_shadow_color[0], text_shadow_color[1], text_shadow_color[2], text_shadow_alpha) else: blf.disable(font_id_1, blf.SHADOW) # TITLE 2 # if panel_prefs.dodraw == "TWO": # POSITION # if context.user_preferences.addons[ __package__].preferences.tab_pos_link == True: text_2_pos_x = panel_prefs.text_2_pos_x text_2_pos_y = panel_prefs.text_2_pos_y else: text_2_pos_x = panel_prefs.text_pos_x text_2_pos_y = panel_prefs.text_pos_y # SCALE # if context.user_preferences.addons[ __package__].preferences.tab_scal_link == True: text_2_width_title = panel_prefs.text_2_width_title text_2_height_title = panel_prefs.text_2_height_title else: text_2_width_title = panel_prefs.text_width_title text_2_height_title = panel_prefs.text_height_title # COLOR # if context.user_preferences.addons[ __package__].preferences.tab_color_link == False: text_color = panel_prefs.text_color bgl.glColor3f(*text_color) else: text_2_color = panel_prefs.text_2_color bgl.glColor3f(*text_2_color) # FONT # if context.user_preferences.addons[ __package__].preferences.tab_font_external == False: if context.user_preferences.addons[ __package__].preferences.tab_font_unit == False: font_id_2 = font_path else: font_id_2 = font_path_2 else: font_id_2 = 0 # FILEPATH FIELD # text_2_text = panel_prefs.text_2_text # length of the text line line_width, line_height = blf.dimensions(font_id_2, text_2_text) self.line_2_width = line_width self.line_2_height = line_height # APPLY PREFERENCES # if context.user_preferences.addons[ __package__].preferences.tab_center == 'middle': blf.position( font_id_2, (self.REALx / 2 - self.line_2_width / 2 + text_2_pos_x), (self.REALy / 2 - self.line_2_height + text_2_pos_y), 0) else: blf.position(font_id_2, (text_2_pos_x + 20), (self.REALy / 2 - self.line_2_height + text_2_pos_y), 0) blf.size(font_id_2, text_2_width_title, text_2_height_title + 10) blf.draw(font_id_2, text_2_text) # DROPSHADOW # if context.user_preferences.addons[ __package__].preferences.text_shadow == True: blf.enable(font_id_2, blf.SHADOW) blf.shadow_offset(font_id_2, text_shadow_x, text_shadow_y) blf.shadow(font_id_2, 5, text_shadow_color[0], text_shadow_color[1], text_shadow_color[2], text_shadow_alpha) else: blf.disable(font_id_2, blf.SHADOW) # TITLE 3 # if panel_prefs.dodraw == "THREE": # POSITION # if context.user_preferences.addons[ __package__].preferences.tab_pos_link == True: text_3_pos_x = panel_prefs.text_3_pos_x text_3_pos_y = panel_prefs.text_3_pos_y else: text_3_pos_x = panel_prefs.text_pos_x text_3_pos_y = panel_prefs.text_pos_y # SCALE # if context.user_preferences.addons[ __package__].preferences.tab_scal_link == True: text_3_width_title = panel_prefs.text_3_width_title text_3_height_title = panel_prefs.text_3_height_title else: text_3_width_title = panel_prefs.text_width_title text_3_height_title = panel_prefs.text_height_title # COLOR # if context.user_preferences.addons[ __package__].preferences.tab_color_link == False: text_color = panel_prefs.text_color bgl.glColor3f(*text_color) else: text_3_color = panel_prefs.text_3_color bgl.glColor3f(*text_3_color) # FONT # if context.user_preferences.addons[ __package__].preferences.tab_font_external == False: if context.user_preferences.addons[ __package__].preferences.tab_font_unit == False: font_id_3 = font_path else: font_id_3 = font_path_3 else: font_id_3 = 0 # FILEPATH FIELD # text_3_text = panel_prefs.text_3_text # length of the text line line_width, line_height = blf.dimensions(font_id_3, text_3_text) self.line_3_width = line_width self.line_3_height = line_height # APPLY PREFERENCES # if context.user_preferences.addons[ __package__].preferences.tab_center == 'middle': blf.position( font_id_3, (self.REALx / 2 - self.line_3_width / 2 + text_3_pos_x), (self.REALy / 2 - self.line_3_height + text_3_pos_y), 0) else: blf.position(font_id_3, (text_3_pos_x + 20), (self.REALy / 2 - self.line_3_height + text_3_pos_y), 0) blf.size(font_id_3, text_3_width_title, text_3_height_title + 10) blf.draw(font_id_3, text_3_text) # DROPSHADOW # if context.user_preferences.addons[ __package__].preferences.text_shadow == True: blf.enable(font_id_3, blf.SHADOW) blf.shadow_offset(font_id_3, text_shadow_x, text_shadow_y) blf.shadow(font_id_3, 5, text_shadow_color[0], text_shadow_color[1], text_shadow_color[2], text_shadow_alpha) else: blf.disable(font_id_3, blf.SHADOW) # TITLE 4 # if panel_prefs.dodraw == "FOUR": # POSITION # if context.user_preferences.addons[ __package__].preferences.tab_pos_link == True: text_4_pos_x = panel_prefs.text_4_pos_x text_4_pos_y = panel_prefs.text_4_pos_y else: text_4_pos_x = panel_prefs.text_pos_x text_4_pos_y = panel_prefs.text_pos_y # SCALE # if context.user_preferences.addons[ __package__].preferences.tab_scal_link == True: text_4_width_title = panel_prefs.text_4_width_title text_4_height_title = panel_prefs.text_4_height_title else: text_4_width_title = panel_prefs.text_width_title text_4_height_title = panel_prefs.text_height_title # COLOR # if context.user_preferences.addons[ __package__].preferences.tab_color_link == False: text_color = panel_prefs.text_color bgl.glColor3f(*text_color) else: text_4_color = panel_prefs.text_4_color bgl.glColor3f(*text_4_color) # FONT # if context.user_preferences.addons[ __package__].preferences.tab_font_external == False: if context.user_preferences.addons[ __package__].preferences.tab_font_unit == False: font_id_4 = font_path else: font_id_4 = font_path_4 else: font_id_4 = 0 # FILEPATH FIELD # text_4_text = panel_prefs.text_4_text # length of the text line line_width, line_height = blf.dimensions(font_id_4, text_4_text) self.line_4_width = line_width self.line_4_height = line_height # APPLY PREFERENCES # if context.user_preferences.addons[ __package__].preferences.tab_center == 'middle': blf.position( font_id_4, (self.REALx / 2 - self.line_4_width / 2 + text_4_pos_x), (self.REALy / 2 - self.line_4_height + text_4_pos_y), 0) else: blf.position(font_id_4, (text_4_pos_x + 20), (self.REALy / 2 - self.line_4_height + text_4_pos_y), 0) blf.size(font_id_4, text_4_width_title, text_4_height_title + 10) blf.draw(font_id_4, text_4_text) # DROPSHADOW # if context.user_preferences.addons[ __package__].preferences.text_shadow == True: blf.enable(font_id_4, blf.SHADOW) blf.shadow_offset(font_id_4, text_shadow_x, text_shadow_y) blf.shadow(font_id_4, 5, text_shadow_color[0], text_shadow_color[1], text_shadow_color[2], text_shadow_alpha) else: blf.disable(font_id_4, blf.SHADOW) # TITLE 5 # if panel_prefs.dodraw == "FIVE": # POSITION # if context.user_preferences.addons[ __package__].preferences.tab_pos_link == True: text_5_pos_x = panel_prefs.text_5_pos_x text_5_pos_y = panel_prefs.text_5_pos_y else: text_5_pos_x = panel_prefs.text_pos_x text_5_pos_y = panel_prefs.text_pos_y # SCALE # if context.user_preferences.addons[ __package__].preferences.tab_scal_link == True: text_5_width_title = panel_prefs.text_5_width_title text_5_height_title = panel_prefs.text_5_height_title else: text_5_width_title = panel_prefs.text_width_title text_5_height_title = panel_prefs.text_height_title # COLOR # if context.user_preferences.addons[ __package__].preferences.tab_color_link == False: text_color = panel_prefs.text_color bgl.glColor3f(*text_color) else: text_5_color = panel_prefs.text_5_color bgl.glColor3f(*text_5_color) # FONT # if context.user_preferences.addons[ __package__].preferences.tab_font_external == False: if context.user_preferences.addons[ __package__].preferences.tab_font_unit == False: font_id_5 = font_path else: font_id_5 = font_path_5 else: font_id_5 = 0 # FILEPATH FIELD # text_5_text = panel_prefs.text_5_text # length of the text line line_width, line_height = blf.dimensions(font_id_5, text_5_text) self.line_5_width = line_width self.line_5_height = line_height # APPLY PREFERENCES # if context.user_preferences.addons[ __package__].preferences.tab_center == 'middle': blf.position( font_id_5, (self.REALx / 2 - self.line_5_width / 2 + text_5_pos_x), (self.REALy / 2 - self.line_5_height + text_5_pos_y), 0) else: blf.position(font_id_5, (text_5_pos_x + 20), (self.REALy / 2 - self.line_5_height + text_5_pos_y), 0) blf.size(font_id_5, text_5_width_title, text_5_height_title + 10) blf.draw(font_id_5, text_5_text) # DROPSHADOW # if context.user_preferences.addons[ __package__].preferences.text_shadow == True: blf.enable(font_id_5, blf.SHADOW) blf.shadow_offset(font_id_5, text_shadow_x, text_shadow_y) blf.shadow(font_id_5, 5, text_shadow_color[0], text_shadow_color[1], text_shadow_color[2], text_shadow_alpha) else: blf.disable(font_id_5, blf.SHADOW) # TITLE 6 # if panel_prefs.dodraw == "SIX": # POSITION # if context.user_preferences.addons[ __package__].preferences.tab_pos_link == True: text_6_pos_x = panel_prefs.text_6_pos_x text_6_pos_y = panel_prefs.text_6_pos_y else: text_6_pos_x = panel_prefs.text_pos_x text_6_pos_y = panel_prefs.text_pos_y # SCALE # if context.user_preferences.addons[ __package__].preferences.tab_scal_link == True: text_6_width_title = panel_prefs.text_6_width_title text_6_height_title = panel_prefs.text_6_height_title else: text_6_width_title = panel_prefs.text_width_title text_6_height_title = panel_prefs.text_height_title # COLOR # if context.user_preferences.addons[ __package__].preferences.tab_color_link == False: text_color = panel_prefs.text_color bgl.glColor3f(*text_color) else: text_6_color = panel_prefs.text_6_color bgl.glColor3f(*text_6_color) # FONT # if context.user_preferences.addons[ __package__].preferences.tab_font_external == False: if context.user_preferences.addons[ __package__].preferences.tab_font_unit == False: font_id_6 = font_path else: font_id_6 = font_path_6 else: font_id_6 = 0 # FILEPATH FIELD # text_6_text = panel_prefs.text_6_text # length of the text line line_width, line_height = blf.dimensions(font_id_6, text_6_text) self.line_6_width = line_width self.line_6_height = line_height # APPLY PREFERENCES # if context.user_preferences.addons[ __package__].preferences.tab_center == 'middle': blf.position( font_id_6, (self.REALx / 2 - self.line_6_width / 2 + text_6_pos_x), (self.REALy / 2 - self.line_6_height + text_6_pos_y), 0) else: blf.position(font_id_6, (text_6_pos_x + 20), (self.REALy / 2 - self.line_6_height + text_6_pos_y), 0) blf.size(font_id_6, text_6_width_title, text_6_height_title + 10) blf.draw(font_id_6, text_6_text) # DROPSHADOW # if context.user_preferences.addons[ __package__].preferences.text_shadow == True: blf.enable(font_id_6, blf.SHADOW) blf.shadow_offset(font_id_6, text_shadow_x, text_shadow_y) blf.shadow(font_id_6, 5, text_shadow_color[0], text_shadow_color[1], text_shadow_color[2], text_shadow_alpha) else: blf.disable(font_id_6, blf.SHADOW) # TITLE 7 # if panel_prefs.dodraw == "SEVEN": # POSITION # if context.user_preferences.addons[ __package__].preferences.tab_pos_link == True: text_7_pos_x = panel_prefs.text_7_pos_x text_7_pos_y = panel_prefs.text_7_pos_y else: text_7_pos_x = panel_prefs.text_pos_x text_7_pos_y = panel_prefs.text_pos_y # SCALE # if context.user_preferences.addons[ __package__].preferences.tab_scal_link == True: text_7_width_title = panel_prefs.text_7_width_title text_7_height_title = panel_prefs.text_7_height_title else: text_7_width_title = panel_prefs.text_width_title text_7_height_title = panel_prefs.text_height_title # COLOR # if context.user_preferences.addons[ __package__].preferences.tab_color_link == False: text_color = panel_prefs.text_color bgl.glColor3f(*text_color) else: text_7_color = panel_prefs.text_7_color bgl.glColor3f(*text_7_color) # FONT # if context.user_preferences.addons[ __package__].preferences.tab_font_external == False: if context.user_preferences.addons[ __package__].preferences.tab_font_unit == False: font_id_7 = font_path else: font_id_7 = font_path_7 else: font_id_7 = 0 # FILEPATH FIELD # text_7_text = panel_prefs.text_7_text # length of the text line line_width, line_height = blf.dimensions(font_id_7, text_7_text) self.line_7_width = line_width self.line_7_height = line_height # APPLY PREFERENCES # if context.user_preferences.addons[ __package__].preferences.tab_center == 'middle': blf.position( font_id_7, (self.REALx / 2 - self.line_7_width / 2 + text_7_pos_x), (self.REALy / 2 - self.line_7_height + text_7_pos_y), 0) else: blf.position(font_id_7, (text_7_pos_x + 20), (self.REALy / 2 - self.line_7_height + text_7_pos_y), 0) blf.size(font_id_7, text_7_width_title, text_7_height_title + 10) blf.draw(font_id_7, text_7_text) # DROPSHADOW # if context.user_preferences.addons[ __package__].preferences.text_shadow == True: blf.enable(font_id_7, blf.SHADOW) blf.shadow_offset(font_id_7, text_shadow_x, text_shadow_y) blf.shadow(font_id_7, 5, text_shadow_color[0], text_shadow_color[1], text_shadow_color[2], text_shadow_alpha) else: blf.disable(font_id_7, blf.SHADOW) # restore opengl defaults bgl.glDisable(bgl.GL_BLEND) bgl.glColor3f(0.0, 0.0, 0.0)
def draw_callback_view(self, context): from bgl import glEnable, glDisable, glColor3f, glVertex3f, glPointSize, glLineWidth, glBegin, glEnd, glLineStipple, GL_POINTS, GL_LINE_STRIP, GL_LINES, GL_LINE_STIPPLE data_matrix, data_quat, data_euler, data_vector, data_vector_array = utils.console_math_data() # draw_matrix vars zero = Vector((0.0, 0.0, 0.0)) x_p = Vector((1.0, 0.0, 0.0)) x_n = Vector((-1.0, 0.0, 0.0)) y_p = Vector((0.0, 1.0, 0.0)) y_n = Vector((0.0, -1.0, 0.0)) z_p = Vector((0.0, 0.0, 1.0)) z_n = Vector((0.0, 0.0, -1.0)) bb = [Vector() for i in range(8)] 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) ######## # points if data_vector: glPointSize(3.0) glBegin(GL_POINTS) glColor3f(0.5, 0.5, 1) for key, vec in data_vector.items(): glVertex3f(*vec.to_3d()) glEnd() glPointSize(1.0) ####### # lines if data_vector_array: glColor3f(0.5, 0.5, 1) glLineWidth(2.0) for line in data_vector_array.values(): glBegin(GL_LINE_STRIP) for vec in line: glVertex3f(*vec) glEnd() glPointSize(1.0) glLineWidth(1.0) # matrix if data_matrix: for mat in data_matrix.values(): draw_matrix(mat) if data_quat: loc = context.scene.cursor_location.copy() for quat in data_quat.values(): mat = quat.to_matrix().to_4x4() mat.translation = loc draw_matrix(mat) if data_euler: loc = context.scene.cursor_location.copy() for eul in data_euler.values(): mat = eul.to_matrix().to_4x4() mat.translation = loc draw_matrix(mat)
def draw_callback_px(self, context): wm = context.window_manager sc = context.scene if not wm.polycount_run: return font_size = sc.polycount_font_size pos_x, pos_y = get_display_location(context) # draw text in the 3d-view # ======================== blf.size(0, sc.polycount_font_size, 72) r, g, b = sc.polycount_font_color bgl.glColor3f(r, g, b) view3dId = get_space_id(context.space_data) # text = "All Obj Sel" # blf.position(0, pos_x + 15, pos_y, 0) # blf.draw(0, text) # ######## vertex Drawing if sc.show_vertex_count == True: text = "V" blf.position(0, pos_x , pos_y, 0) blf.draw(0, text) if vert_count_all == True: all_vert_count = polyCountOperator.all_edge_count.get(view3dId, -1) if all_vert_count > 0: text = format(all_tri_count, ',d') text3width = blf.dimensions(0, text)[0] blf.position(0, pos_x + 135 , pos_y , 0) blf.draw(0, text) else: text = "0" blf.position(0, pos_x + 135, pos_y , 0) blf.draw(0, text) else: text = "X" blf.position(0, pos_X, pos_y - 20, 0) blf.draw(o,text) if vert_count_obj == True: obj_vert_count = polyCountOperator.all_edge_count.get(view3dId, -1) if obj_vert_count > 0: text = format(obj_vert_count, ',d') text3width = blf.dimensions(0, text)[0] blf.position(0, pos_x + 135 , pos_y , 0) blf.draw(0, text) else: text = "0" blf.position(0, pos_x + 135, pos_y , 0) blf.draw(0, text) else: text = "X" blf.position(0, pos_X, pos_y - 20, 0) blf.draw(o,text) if vert_count_sel == True: sel_vert_count = polyCountOperator.all_edge_count.get(view3dId, -1) if sel_vert_count > 0: text = format(sel_vert_count, ',d') text3width = blf.dimensions(0, text)[0] blf.position(0, pos_x + 135 , pos_y , 0) blf.draw(0, text) else: text = "0" blf.position(0, pos_x + 135, pos_y , 0) blf.draw(0, text) else: text = "X" blf.position(0, pos_X, pos_y - 20, 0) blf.draw(o,text)
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 generate_icon(name, verts=None, faces=None, coll="shape_types"): pcoll = preview_collections[coll] if name in pcoll: thumb = pcoll.get(name) else: thumb = pcoll.new(name) thumb.image_size = (200, 200) if verts is not None: import bgl polygon_color = bpy.context.user_preferences.themes[0].view_3d.edge_facesel edge_color = bpy.context.user_preferences.themes[0].view_3d.edge_select vertex_color = bpy.context.user_preferences.themes[0].view_3d.vertex_select clear_color = bpy.context.user_preferences.themes[0].user_interface.wcol_menu.inner viewport_info = bgl.Buffer(bgl.GL_INT, 4) bgl.glGetIntegerv(bgl.GL_VIEWPORT, viewport_info) buffer = bgl.Buffer(bgl.GL_FLOAT, 200 * 200 * 4) bgl.glDisable(bgl.GL_SCISSOR_TEST) bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA) bgl.glEnable(bgl.GL_LINE_SMOOTH) bgl.glEnable(bgl.GL_POINT_SMOOTH) bgl.glViewport(0, 0, 200, 200) bgl.glMatrixMode(bgl.GL_MODELVIEW) bgl.glPushMatrix() bgl.glLoadIdentity() bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPushMatrix() bgl.glLoadIdentity() bgl.gluOrtho2D(0, 0, 0, 0) bgl.glLineWidth(4.0) bgl.glPointSize(10.0) bgl.glClearColor(*clear_color) bgl.glClear(bgl.GL_COLOR_BUFFER_BIT | bgl.GL_DEPTH_BUFFER_BIT) if faces is None: bgl.glBegin(bgl.GL_POLYGON) bgl.glColor3f(*polygon_color) for vert in verts: bgl.glVertex2f(*vert) bgl.glEnd() else: bgl.glBegin(bgl.GL_TRIANGLES) bgl.glColor3f(*polygon_color) for face in faces: bgl.glVertex2f(*verts[face[0]]) bgl.glVertex2f(*verts[face[1]]) bgl.glVertex2f(*verts[face[2]]) bgl.glEnd() bgl.glBegin(bgl.GL_LINE_LOOP) bgl.glColor3f(*edge_color) for vert in verts: bgl.glVertex2f(*vert) bgl.glEnd() bgl.glBegin(bgl.GL_POINTS) bgl.glColor3f(*vertex_color) for vert in verts: bgl.glVertex2f(*vert) bgl.glEnd() bgl.glReadPixels(0, 0, 200, 200, bgl.GL_RGBA, bgl.GL_FLOAT, buffer) bgl.glEnable(bgl.GL_SCISSOR_TEST) bgl.glLineWidth(1.0) bgl.glPointSize(1.0) buffer = buffer[:] for idx in range(0, 200 * 200 * 4, 4): if buffer[idx] == clear_color[0] and \ buffer[idx + 1] == clear_color[1] and buffer[idx + 2] == clear_color[2]: buffer[idx + 3] = 0.0 thumb.image_pixels_float = buffer
def glColor(color): if len(color) == 3: bgl.glColor3f(*color) else: bgl.glColor4f(*color)
def draw_custom_2d_elements(): context = bpy.context font_id = 0 # TODO: Need to find out how best to get this. blf.size(font_id, 12, 72) (prefab_locators, collision_locators, model_locators) = _get_custom_visual_elements() if not prefab_locators and \ not collision_locators and \ not model_locators: return glColor3f( context.scene.scs_props.info_text_color[0], context.scene.scs_props.info_text_color[1], context.scene.scs_props.info_text_color[2], ) region = context.region region3d = context.space_data.region_3d region_mid_width = region.width / 2.0 region_mid_height = region.height / 2.0 # VARS FOR PROJECTION perspective_matrix = region3d.perspective_matrix.copy() region_data = (perspective_matrix, region_mid_width, region_mid_height) # LOCATOR NAMES if context.scene.scs_props.display_info == 'locnames': if prefab_locators: for key, obj in prefab_locators.items(): mat = obj.matrix_world _primitive.draw_text(key, font_id, Vector((mat[0][3], mat[1][3], mat[2][3])), region_data) if collision_locators: for key, obj in collision_locators.items(): mat = obj.matrix_world _primitive.draw_text(key, font_id, Vector((mat[0][3], mat[1][3], mat[2][3])), region_data) if model_locators: for key, obj in model_locators.items(): mat = obj.matrix_world _primitive.draw_text(key, font_id, Vector((mat[0][3], mat[1][3], mat[2][3])), region_data) # LOCATOR COMPREHENSIVE INFO elif context.scene.scs_props.display_info == 'locinfo': if prefab_locators: for key, obj in prefab_locators.items(): mat = obj.matrix_world textlines = [ '"' + key + '"', str(obj.scs_props.locator_type + " - " + obj.scs_props.locator_prefab_type) ] if obj.scs_props.locator_prefab_type == 'Control Node': textlines.append( str("Node Index: " + str(obj.scs_props.locator_prefab_con_node_index))) if 1: # TODO textlines.append(str("Assigned Points: " + str(0))) elif obj.scs_props.locator_prefab_type == 'Spawn Point': textlines.append( str("Type: " + str(obj.scs_props.locator_prefab_spawn_type))) elif obj.scs_props.locator_prefab_type == 'Traffic Semaphore': textlines.append( str("ID: " + str(obj.scs_props.locator_prefab_tsem_id))) # if obj.scs_props.locator_prefab_tsem_model != '': # textlines.append(str("Model: " + str(obj.scs_props.locator_prefab_tsem_model))) if obj.scs_props.locator_prefab_tsem_profile != '': textlines.append( str("Profile: " + str(obj.scs_props.locator_prefab_tsem_profile)) ) if obj.scs_props.locator_prefab_tsem_type != '0': textlines.append( str("Type: " + str(obj.scs_props.locator_prefab_tsem_type))) textlines.append( str("G: " + str(obj.scs_props.locator_prefab_tsem_gm) + " - O: " + str(obj.scs_props.locator_prefab_tsem_om1) + " - R: " + str(obj.scs_props.locator_prefab_tsem_rm))) if obj.scs_props.locator_prefab_tsem_cyc_delay != 0: textlines.append( str("Cycle Delay: " + str( obj.scs_props.locator_prefab_tsem_cyc_delay))) textlines.append( str("Activation: " + str(obj.scs_props.locator_prefab_tsem_activation))) if obj.scs_props.locator_prefab_tsem_ai_only: textlines.append("AI Only") elif obj.scs_props.locator_prefab_type == 'Navigation Point': # if obj.scs_props.locator_prefab_np_speed_limit != 0: # textlines.append(str(str(obj.scs_props.locator_prefab_np_speed_limit) + " km/h")) if obj.scs_props.locator_prefab_np_boundary != 'no': textlines.append( str("Lane " + str(obj.scs_props.locator_prefab_np_boundary))) textlines.append( str("B. Node: " + str(obj.scs_props.locator_prefab_np_boundary_node)) ) if obj.scs_props.locator_prefab_np_traffic_light != '-1': textlines.append( str("T. Light ID: " + str(obj.scs_props. locator_prefab_np_traffic_light))) elif obj.scs_props.locator_prefab_type == 'Map Point': if obj.scs_props.locator_prefab_mp_road_over: textlines.append("Road Over") if obj.scs_props.locator_prefab_mp_no_outline: textlines.append("No Outline") if obj.scs_props.locator_prefab_mp_no_arrow: textlines.append("No Arrow") if obj.scs_props.locator_prefab_mp_prefab_exit: textlines.append("Prefab Exit") textlines.append( str("Road Size: " + str(obj.scs_props.locator_prefab_mp_road_size))) if obj.scs_props.locator_prefab_mp_road_offset != '0m': textlines.append( str("Offset: " + str( obj.scs_props.locator_prefab_mp_road_offset))) if obj.scs_props.locator_prefab_mp_custom_color != 'none': textlines.append( str("Color: " + str( obj.scs_props.locator_prefab_mp_custom_color))) if obj.scs_props.locator_prefab_mp_assigned_node != 'none': textlines.append( str("Node: " + str(obj.scs_props. locator_prefab_mp_assigned_node))) des_nodes = "Destination Nodes:" if obj.scs_props.locator_prefab_mp_des_nodes_0: des_nodes += " 0" if obj.scs_props.locator_prefab_mp_des_nodes_1: des_nodes += " 1" if obj.scs_props.locator_prefab_mp_des_nodes_2: des_nodes += " 2" if obj.scs_props.locator_prefab_mp_des_nodes_3: des_nodes += " 3" if des_nodes != "Destination Nodes:": textlines.append(des_nodes) if obj.scs_props.locator_prefab_mp_des_nodes_ct: textlines.append("Custom Target") elif obj.scs_props.locator_prefab_type == 'Trigger Point': if obj.scs_props.locator_prefab_tp_action != '': textlines.append( str("Action: " + str(obj.scs_props.locator_prefab_tp_action))) textlines.append( str("Range: " + str(obj.scs_props.locator_prefab_tp_range))) if obj.scs_props.locator_prefab_tp_reset_delay != 0: textlines.append( str("Reset Delay: " + str( obj.scs_props.locator_prefab_tp_reset_delay))) if obj.scs_props.locator_prefab_tp_sphere_trigger: textlines.append("Sphere Trigger") if obj.scs_props.locator_prefab_tp_partial_activ: textlines.append("Partial Activation") if obj.scs_props.locator_prefab_tp_onetime_activ: textlines.append("One-Time Activation") if obj.scs_props.locator_prefab_tp_manual_activ: textlines.append("Manual Activation") for textline_i, textline in enumerate(textlines): y_pos = ( (len(textlines) * 15) / 2) + (textline_i * -15) - 7 _primitive.draw_text( textline, font_id, Vector((mat[0][3], mat[1][3], mat[2][3])), region_data, 0, y_pos) if collision_locators: for key, obj in collision_locators.items(): mat = obj.matrix_world textlines = [ '"' + key + '"', str(obj.scs_props.locator_type + " - " + obj.scs_props.locator_collider_type), str("Mass: " + str(obj.scs_props.locator_collider_mass)) ] # if obj.scs_props.locator_collider_centered: # textlines.append("Locator Centered") if obj.scs_props.locator_collider_margin != 0: textlines.append( str("Margin: " + str(obj.scs_props.locator_collider_margin))) for textline_i, textline in enumerate(textlines): y_pos = ( (len(textlines) * 15) / 2) + (textline_i * -15) - 7 _primitive.draw_text( textline, font_id, Vector((mat[0][3], mat[1][3], mat[2][3])), region_data, 0, y_pos) if model_locators: for key, obj in model_locators.items(): mat = obj.matrix_world textlines = [ '"' + key + '"', str(obj.scs_props.locator_type), str(obj.scs_props.locator_model_hookup) ] if obj.scs_props.locator_show_preview_model: textlines.append( str(obj.scs_props.locator_preview_model_path)) for textline_i, textline in enumerate(textlines): y_pos = ( (len(textlines) * 15) / 2) + (textline_i * -15) - 7 _primitive.draw_text( textline, font_id, Vector((mat[0][3], mat[1][3], mat[2][3])), region_data, 0, y_pos) # LOCATOR SPEED LIMITS elif context.scene.scs_props.display_info == 'locspeed': if prefab_locators: for key, obj in prefab_locators.items(): if obj.scs_props.locator_prefab_type == 'Navigation Point': if obj.scs_props.locator_prefab_np_speed_limit != 0: mat = obj.matrix_world _primitive.draw_text( str( str(obj.scs_props.locator_prefab_np_speed_limit ) + " km/h"), font_id, Vector((mat[0][3], mat[1][3], mat[2][3])), region_data) # LOCATOR BOUNDARY NODES elif context.scene.scs_props.display_info == 'locnodes': if prefab_locators: for key, obj in prefab_locators.items(): if obj.scs_props.locator_prefab_type == 'Navigation Point': mat = obj.matrix_world _primitive.draw_text( str(obj.scs_props.locator_prefab_np_boundary_node), font_id, Vector( (mat[0][3], mat[1][3], mat[2][3])), region_data) # LOCATOR BOUNDARY LANES elif context.scene.scs_props.display_info == 'loclanes': if prefab_locators: for key, obj in prefab_locators.items(): if obj.scs_props.locator_prefab_type == 'Navigation Point': if obj.scs_props.locator_prefab_np_boundary != 'no': mat = obj.matrix_world _primitive.draw_text( str(obj.scs_props.locator_prefab_np_boundary), font_id, Vector((mat[0][3], mat[1][3], mat[2][3])), region_data)
def render_main(self, context, animation=False): # noinspection PyBroadException,PyBroadException # Save old info settings = bpy.context.scene.render.image_settings depth = settings.color_depth settings.color_depth = '8' # noinspection PyBroadException try: # Get visible layers layers = [] scene = context.scene for x in range(0, 20): if scene.layers[x] is True: layers.extend([x]) # Get object list objlist = context.scene.objects # -------------------- # Get resolution # -------------------- scene = bpy.context.scene render_scale = scene.render.resolution_percentage / 100 width = int(scene.render.resolution_x * render_scale) height = int(scene.render.resolution_y * render_scale) # --------------------------------------- # Get output path # --------------------------------------- temp_path = path.realpath(bpy.app.tempdir) if len(temp_path) > 0: outpath = path.join(temp_path, "measureit_tmp_render.png") else: self.report({ 'ERROR' }, "MeasureIt: Unable to save temporary render image. Define a valid temp path" ) settings.color_depth = depth return False # Get Render Image img = get_render_image(outpath) if img is None: self.report({ 'ERROR' }, "MeasureIt: Unable to save temporary render image. Define a valid temp path" ) settings.color_depth = depth return False # ----------------------------- # Calculate rows and columns # ----------------------------- tile_x = 240 tile_y = 216 row_num = ceil(height / tile_y) col_num = ceil(width / tile_x) print("MeasureIt: Image divided in " + str(row_num) + "x" + str(col_num) + " tiles") # pixels out of visible area cut4 = (col_num * tile_x * 4) - width * 4 # pixels aout of drawing area totpixel4 = width * height * 4 # total pixels RGBA viewport_info = bgl.Buffer(bgl.GL_INT, 4) bgl.glGetIntegerv(bgl.GL_VIEWPORT, viewport_info) # Load image on memory img.gl_load(0, bgl.GL_NEAREST, bgl.GL_NEAREST) tex = img.bindcode[0] # -------------------------------------------- # Create output image (to apply texture) # -------------------------------------------- if "measureit_output" in bpy.data.images: out_img = bpy.data.images["measureit_output"] if out_img is not None: bpy.data.images.remove(out_img) out = bpy.data.images.new("measureit_output", width, height) tmp_pixels = [1] * totpixel4 # -------------------------------- # Loop for all tiles # -------------------------------- for row in range(0, row_num): for col in range(0, col_num): buffer = bgl.Buffer(bgl.GL_FLOAT, width * height * 4) bgl.glDisable( bgl.GL_SCISSOR_TEST ) # if remove this line, get blender screenshot not image bgl.glViewport(0, 0, tile_x, tile_y) bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glLoadIdentity() # defines ortographic view for single tile x1 = tile_x * col y1 = tile_y * row bgl.gluOrtho2D(x1, x1 + tile_x, y1, y1 + tile_y) # Clear bgl.glClearColor(0.0, 0.0, 0.0, 0.0) bgl.glClear(bgl.GL_COLOR_BUFFER_BIT | bgl.GL_DEPTH_BUFFER_BIT) bgl.glEnable(bgl.GL_TEXTURE_2D) bgl.glBindTexture(bgl.GL_TEXTURE_2D, tex) # defines drawing area bgl.glBegin(bgl.GL_QUADS) bgl.glColor3f(1.0, 1.0, 1.0) bgl.glTexCoord2f(0.0, 0.0) bgl.glVertex2f(0.0, 0.0) bgl.glTexCoord2f(1.0, 0.0) bgl.glVertex2f(width, 0.0) bgl.glTexCoord2f(1.0, 1.0) bgl.glVertex2f(width, height) bgl.glTexCoord2f(0.0, 1.0) bgl.glVertex2f(0.0, height) bgl.glEnd() # ----------------------------- # Loop to draw all lines # ----------------------------- for myobj in objlist: if myobj.hide is False: if 'MeasureGenerator' in myobj: # verify visible layer for x in range(0, 20): if myobj.layers[x] is True: if x in layers: op = myobj.MeasureGenerator[0] draw_segments(context, myobj, op, None, None) break # ----------------------------- # Loop to draw all debug # ----------------------------- if scene.measureit_debug is True: selobj = bpy.context.selected_objects for myobj in selobj: if scene.measureit_debug_objects is True: draw_object(context, myobj, None, None) elif scene.measureit_debug_object_loc is True: draw_object(context, myobj, None, None) if scene.measureit_debug_vertices is True: draw_vertices(context, myobj, None, None) elif scene.measureit_debug_vert_loc is True: draw_vertices(context, myobj, None, None) if scene.measureit_debug_edges is True: draw_edges(context, myobj, None, None) if scene.measureit_debug_faces is True or scene.measureit_debug_normals is True: draw_faces(context, myobj, None, None) if scene.measureit_rf is True: bgl.glColor3f(1.0, 1.0, 1.0) rfcolor = scene.measureit_rf_color rfborder = scene.measureit_rf_border rfline = scene.measureit_rf_line bgl.glLineWidth(rfline) bgl.glColor4f(rfcolor[0], rfcolor[1], rfcolor[2], rfcolor[3]) x1 = rfborder x2 = width - rfborder y1 = int(ceil(rfborder / (width / height))) y2 = height - y1 draw_rectangle((x1, y1), (x2, y2)) # -------------------------------- # copy pixels to temporary area # -------------------------------- bgl.glFinish() bgl.glReadPixels(0, 0, width, height, bgl.GL_RGBA, bgl.GL_FLOAT, buffer) # read image data for y in range(0, tile_y): # final image pixels position p1 = (y * width * 4) + (row * tile_y * width * 4) + (col * tile_x * 4) p2 = p1 + (tile_x * 4) # buffer pixels position b1 = y * width * 4 b2 = b1 + (tile_x * 4) if p1 < totpixel4: # avoid pixel row out of area if col == col_num - 1: # avoid pixel columns out of area p2 -= cut4 b2 -= cut4 tmp_pixels[p1:p2] = buffer[b1:b2] # ----------------------- # Copy temporary to final # ----------------------- out.pixels = tmp_pixels[:] # Assign image data img.gl_free() # free opengl image memory # delete image bpy.data.images.remove(img) # remove temp file remove(outpath) # reset bgl.glEnable(bgl.GL_SCISSOR_TEST) # ----------------------- # restore opengl defaults # ----------------------- bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0) # Saves image if out is not None and (scene.measureit_render is True or animation is True): ren_path = bpy.context.scene.render.filepath filename = "mit_frame" if len(ren_path) > 0: if ren_path.endswith(path.sep): initpath = path.realpath(ren_path) + path.sep else: (initpath, filename) = path.split(ren_path) ftxt = "%04d" % scene.frame_current outpath = path.realpath( path.join(initpath, filename + ftxt + ".png")) save_image(self, outpath, out) settings.color_depth = depth return True except: settings.color_depth = depth print("Unexpected error:" + str(exc_info())) self.report({ 'ERROR' }, "MeasureIt: Unable to create render image. Be sure the output render path is correct" ) return False
def render(self, context): # needed??? if context.region.id == self.region_id: # just hide the cursor... context.space_data.cursor_location = [0.0, 0.0, 10.0] context.space_data.region_3d.view_matrix = Matrix.Identity(4) w = context.region.width h = context.region.height x1, x2, x3, x4, y1, y2, y3, y4 = self.grid(w, h) bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glLoadIdentity() bgl.gluOrtho2D(0, w, 0, h) bgl.glMatrixMode(bgl.GL_MODELVIEW) bgl.glLoadIdentity() bgl.glColor3f(*self.COLOR_BOARD) bgl.glLineWidth(2.0) bgl.glBegin(bgl.GL_LINES) for x in (x1, x2, x3, x4): bgl.glVertex3f(x, y1, 0.0) bgl.glVertex3f(x, y4, 0.0) for y in (y1, y2, y3, y4): bgl.glVertex3f(x1, y, 0.0) bgl.glVertex3f(x4, y, 0.0) bgl.glEnd() xs = (x1, x2, x3, x4) ys = (y1, y2, y3, y4) bgl.glLineWidth(8.0) bgl.glBegin(bgl.GL_LINES) for i in range(3): for j in range(3): c = self.board[i][j] xa = xs[i] xb = xs[i + 1] ya = ys[j] yb = ys[j + 1] if c == self.PLAYER: if self.computer_has_x: self.drawO(xa, xb, ya, yb) else: self.drawX(xa, xb, ya, yb) elif c == self.COMPUTER: if self.computer_has_x: self.drawX(xa, xb, ya, yb) else: self.drawO(xa, xb, ya, yb) bgl.glEnd() bgl.glLineWidth(1.0) bgl.glColor3f(*self.COLOR_FONT) xp, yp = self.fontPosition(w, h) blf.position(0, xp, yp, 0) blf.size(0, 50, 72) if self.winner == self.COMPUTER: blf.draw(0, "You loose!") elif self.winner == self.PLAYER: blf.draw(0, "You win!") elif self.round == self.NONE: blf.draw(0, "Draw.")