def render_offscreen(self, context, width, height, imgname=''): assert context.area.type == 'NODE_EDITOR' and context.space_data.tree_type == 'CompositorNodeTree' gos = gpu.offscreen.new(width,height) gos.bind(True) try: bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glLoadIdentity() bgl.glScalef(1/width*2,1/height*2,1.0) bgl.glTranslatef(-width/2,-height/2,0) draw_callback(self, context, { 'center': Vector((width/2, height/2)) , 'zoom': 1.0 , 'back_image_alpha': 1.0 , 'image_size': (width, height) }) buffer = bgl.Buffer(bgl.GL_FLOAT, width * height * 4) x,y = 0,0 bgl.glReadPixels(x, y, width, height , bgl.GL_RGBA, bgl.GL_FLOAT, buffer) out = prepare_blimage(width, height, imgname or Pref.default_output_image_name) out.pixels = buffer[:] finally: gos.unbind(True)
def draw_mouse(context, shape, style, alpha): # shape and position wm = context.window_manager size = wm.display_font_size * 3 offset_x = context.region.width - wm.display_pos_x - (size*0.535) offset_y = wm.display_pos_y shape_data = get_shape_data(shape) bgl.glTranslatef(offset_x, offset_y, 0) # color r, g, b = wm.display_color bgl.glEnable(bgl.GL_BLEND) #bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA) #bgl.glColor4f(r, g, b, alpha) # inner shape for filled style if style == "filled": inner_shape = [] for i in shape_data: inner_shape.append(i[0]) # outer shape for i in shape_data: shape_segment = i shape_segment[0] = [size * k for k in shape_segment[0]] shape_segment[1] = [size * k for k in shape_segment[1]] shape_segment[2] = [size * k for k in shape_segment[2]] shape_segment[3] = [size * k for k in shape_segment[3]] # create the buffer shape_buffer = bgl.Buffer(bgl.GL_FLOAT, [4, 3], shape_segment) # create the map and draw the triangle fan bgl.glMap1f(bgl.GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, shape_buffer) bgl.glEnable(bgl.GL_MAP1_VERTEX_3) bgl.glColor4f(r, g, b, alpha) if style == "outline": bgl.glBegin(bgl.GL_LINE_STRIP) else: # style == "filled" bgl.glBegin(bgl.GL_TRIANGLE_FAN) for j in range(10): bgl.glEvalCoord1f(j / 10.0) x, y, z = shape_segment[3] # make sure the last vertex is indeed the last one, to avoid gaps bgl.glVertex3f(x, y, z) bgl.glEnd() bgl.glDisable(bgl.GL_MAP1_VERTEX_3) # draw interior if style == "filled": bgl.glColor4f(r, g, b, alpha) bgl.glBegin(bgl.GL_TRIANGLE_FAN) for i in inner_shape: j = [size * k for k in i] x, y, z = j bgl.glVertex3f(x, y, z) bgl.glEnd() bgl.glTranslatef(-offset_x, -offset_y, 0)
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_px_point(self, context): """ Draws the handle seen when rotating or scaling """ vx = Vector([1, 0]) try: math.degrees(self.vec_act.angle_signed(vx)) math.degrees(self.vec_act.angle_signed(vx)) except ValueError: return bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(1.0, 0.5, 0.0, 1.0) bgl.glLineStipple(4, 0x5555) bgl.glEnable(bgl.GL_LINE_STIPPLE) bgl.glPushMatrix() bgl.glTranslatef(self.center_area.x, self.center_area.y, 0) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(0, 0) bgl.glVertex2f(self.vec_act.x, self.vec_act.y) bgl.glEnd() bgl.glPopMatrix() bgl.glDisable(bgl.GL_LINE_STIPPLE) bgl.glLineWidth(3) bgl.glPushMatrix() bgl.glTranslatef(self.center_area.x + self.vec_act.x, self.center_area.y + self.vec_act.y, 0) if self.bl_idname == 'VSE_TRANSFORM_TOOLS_OT_scale': bgl.glRotatef(math.degrees(self.vec_act.angle_signed(vx)), 0, 0, 1) if self.bl_idname == 'VSE_TRANSFORM_TOOLS_OT_rotate': bgl.glRotatef( math.degrees(self.vec_act.angle_signed(vx)) + 90, 0, 0, 1) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(5, 0) bgl.glVertex2f(15, 0) bgl.glVertex2f(15, 0) bgl.glVertex2f(10, -7) bgl.glVertex2f(15, 0) bgl.glVertex2f(10, 7) bgl.glVertex2f(-5, 0) bgl.glVertex2f(-15, 0) bgl.glVertex2f(-15, 0) bgl.glVertex2f(-10, -7) bgl.glVertex2f(-15, 0) bgl.glVertex2f(-10, 7) bgl.glEnd() bgl.glPopMatrix() bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_snap(self, loc, orientation): """ Draws the purple snap lines """ bgl.glEnable(bgl.GL_BLEND) bgl.glLineWidth(2) bgl.glPushMatrix() r = 1.0 g = 0.0 b = 1.0 a = 0.5 bgl.glColor4f(r, g, b, a) if orientation == "VERTICAL": bgl.glTranslatef(loc, 0, 0) start = Vector([0, -10000]) end = Vector([0, 10000]) draw_line(start, end) elif orientation == "HORIZONTAL": bgl.glTranslatef(0, loc, 0) start = Vector([-10000, 0]) end = Vector([10000, 0]) draw_line(start, end) bgl.glPopMatrix() bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw(self): self.allocate( Rect(self.margin.x, self.margin.y, self._render.getWindowWidth() - self.margin.sx, self._render.getWindowHeight() - self.margin.sy)) self.layout() bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glLoadIdentity() bgl.gluOrtho2D(0, self._render.getWindowWidth(), 0, self._render.getWindowHeight()) bgl.glMatrixMode(bgl.GL_MODELVIEW) bgl.glLoadIdentity() bgl.glPushMatrix() bgl.glTranslatef(self.margin.x, self.margin.h, 0) bgl.glEnable(bgl.GL_TEXTURE_2D) bgl.glEnable(bgl.GL_BLEND) bgl.glDisable(bgl.GL_DEPTH) bgl.glDisable(bgl.GL_LIGHTING) Widget.draw(self) bgl.glPopMatrix()
def bind(self): bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.glid[0]) if not self.region is None: bgl.glMatrixMode(bgl.GL_TEXTURE) bgl.glLoadIdentity() bgl.glTranslatef(self.region.x, self.region.y, 0) bgl.glScalef(self.region.w, self.region.h, 1) bgl.glMatrixMode(bgl.GL_MODELVIEW)
def ondraw_postview(self, obj_arm, bone): if obj_arm.hide_viewport or not obj_arm.data.xray.display_bone_shapes or not bone.xray.exportable: return if not obj_arm.name in bpy.context.scene.objects: return visible_armature_object = False for layer_index, layer in enumerate(obj_arm.layers): scene_layer = bpy.context.scene.layers[layer_index] if scene_layer and layer: visible_armature_object = True break if not visible_armature_object: return from .gl_utils import matrix_to_buffer, \ draw_wire_cube, draw_wire_sphere, draw_wire_cylinder, draw_cross shape = self.shape if shape.type == '0': return bgl.glEnable(bgl.GL_BLEND) if bpy.context.active_bone \ and (bpy.context.active_bone.id_data == obj_arm.data) \ and (bpy.context.active_bone.name == bone.name): bgl.glColor4f(1.0, 0.0, 0.0, 0.7) else: bgl.glColor4f(0.0, 0.0, 1.0, 0.5) prev_line_width = bgl.Buffer(bgl.GL_FLOAT, [1]) bgl.glGetFloatv(bgl.GL_LINE_WIDTH, prev_line_width) bgl.glPushMatrix() try: mat = obj_arm.matrix_world * obj_arm.pose.bones[bone.name].matrix \ * mathutils.Matrix.Scale(-1, 4, (0, 0, 1)) bmat = mat bgl.glLineWidth(2) mat *= shape.get_matrix_basis() bgl.glMultMatrixf(matrix_to_buffer(mat.transposed())) if shape.type == '1': # box draw_wire_cube(*shape.box_hsz) if shape.type == '2': # sphere draw_wire_sphere(shape.sph_rad, 16) if shape.type == '3': # cylinder draw_wire_cylinder(shape.cyl_rad, shape.cyl_hgh * 0.5, 16) bgl.glPopMatrix() bgl.glPushMatrix() ctr = self.mass.center trn = bmat * mathutils.Vector((ctr[0], ctr[2], ctr[1])) bgl.glTranslatef(*trn) draw_cross(0.05) finally: bgl.glPopMatrix() bgl.glLineWidth(prev_line_width[0])
def draw(self): if self.visible == False: return module.post_draw_step += 1 height = render.getWindowHeight() width = render.getWindowWidth() bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glLoadIdentity() bgl.gluOrtho2D(0, width, 0, height) bgl.glMatrixMode(bgl.GL_MODELVIEW) bgl.glLoadIdentity() # Enable textures bgl.glEnable(bgl.GL_TEXTURE_2D) # Enable alpha blending bgl.glEnable(bgl.GL_BLEND) bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA) bgl.glAlphaFunc(bgl.GL_SRC_ALPHA, 1) # Bind the texture bgl.glBindTexture(bgl.GL_TEXTURE_2D, self._tex_id) # Fix position w, h = self._size bgl.glTranslatef(0, -h, 1) #MipLevel bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_BASE_LEVEL, 0) bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAX_LEVEL, 0) bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_LINEAR) bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_LINEAR) # Draw the textured quad bgl.glColor4f(*self.color) bgl.glBegin(bgl.GL_QUADS) self.calculate_glposition() for i in range(4): bgl.glTexCoord2f(self.texco[i][0], self.texco[i][1]) bgl.glVertex2f(self.gl_position[i][0], self.gl_position[i][1]) bgl.glEnd() bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0) bgl.glDisable(bgl.GL_BLEND) bgl.glDisable(bgl.GL_TEXTURE_2D) bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPopMatrix() bgl.glMatrixMode(bgl.GL_MODELVIEW)
def draw(self): if self.visible == False: return module.post_draw_step += 1 height = render.getWindowHeight() width = render.getWindowWidth() bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glLoadIdentity() bgl.gluOrtho2D(0, width, 0, height) bgl.glMatrixMode(bgl.GL_MODELVIEW) bgl.glLoadIdentity() # Enable textures bgl.glEnable(bgl.GL_TEXTURE_2D) # Enable alpha blending bgl.glEnable(bgl.GL_BLEND) bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA) bgl.glAlphaFunc(bgl.GL_SRC_ALPHA, 1) # Bind the texture bgl.glBindTexture(bgl.GL_TEXTURE_2D, self._tex_id) # Fix position w, h = self._size bgl.glTranslatef(0, -h, 1) #MipLevel bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_BASE_LEVEL, 0); bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAX_LEVEL, 0); bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_LINEAR); bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MAG_FILTER, bgl.GL_LINEAR); # Draw the textured quad bgl.glColor4f(*self.color) bgl.glBegin(bgl.GL_QUADS) self.calculate_glposition() for i in range(4): bgl.glTexCoord2f(self.texco[i][0], self.texco[i][1]) bgl.glVertex2f(self.gl_position[i][0], self.gl_position[i][1]) bgl.glEnd() bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0) bgl.glDisable(bgl.GL_BLEND) bgl.glDisable(bgl.GL_TEXTURE_2D) bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glPopMatrix() bgl.glMatrixMode(bgl.GL_MODELVIEW)
def draw_callback_px_2d_cursor(self, context): c2d = context.region.view2d.view_to_region( context.scene.seq_cursor2d_loc[0], context.scene.seq_cursor2d_loc[1], clip=False) bgl.glEnable(bgl.GL_BLEND) bgl.glLineWidth(1) bgl.glColor4f(0.7, 0.7, 0.7, 1.0) bgl.glPushMatrix() bgl.glTranslatef(c2d[0], c2d[1], 0) bgl.glBegin(bgl.GL_LINES) bgl.glVertex2i(0, -15) bgl.glVertex2i(0, -5) bgl.glVertex2i(0, 15) bgl.glVertex2i(0, 5) bgl.glVertex2i(-15, 0) bgl.glVertex2i(-5, 0) bgl.glVertex2i(15, 0) bgl.glVertex2i(5, 0) bgl.glEnd() size = 10 c = [] s = [] for i in range(16): c.append(math.cos(i * math.pi / 8)) s.append(math.sin(i * math.pi / 8)) bgl.glColor4f(1.0, 1.0, 1.0, 1.0) bgl.glBegin(bgl.GL_LINE_LOOP) for i in range(16): bgl.glVertex2f(size * c[i], size * s[i]) bgl.glEnd() bgl.glEnable(bgl.GL_LINE_STIPPLE) bgl.glLineStipple(4, 0x5555) bgl.glColor4f(1.0, 0.0, 0.0, 1.0) bgl.glBegin(bgl.GL_LINE_LOOP) for i in range(16): bgl.glVertex2f(size * c[i], size * s[i]) bgl.glEnd() bgl.glPopMatrix() bgl.glDisable(bgl.GL_LINE_STIPPLE) bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def drawText(context, text, location, text_scale_value=TEXT_SCALE_VALUE, *, enable_depth=False, constant_scale=False): if (enable_depth): bgl.glEnable(bgl.GL_DEPTH_TEST) v3d = context.space_data rv3d = v3d.region_3d text_scale = text_scale_value * ( (max(min(MAX_ZOOM_DISTANCE, rv3d.view_distance), MIN_ZOOM_DISTANCE)) / FRIENDLY_ZOOM_DISTANCE) font_id = 0 axis, angle = getScreenLookAxis(context, location) bgl.glPushMatrix() bgl.glTranslatef(location.x, location.y, location.z) bgl.glPushMatrix() bgl.glRotatef(angle, axis.x, axis.y, axis.z) bgl.glPushMatrix() if (not constant_scale): bgl.glScalef(text_scale, text_scale, text_scale) else: bgl.glScalef(text_scale_value, text_scale_value, text_scale_value) bgl.glPushMatrix() bgl.glRotatef(90.0, 1.0, 0.0, 0.0) blf.position(font_id, 0.0, 0.0, 0.0) blf.size(font_id, 72, 72) bgl.glColor4f(0.0, 0.0, 0.0, 1.0) blf.draw(0, text) # blf.rotation(0, 1.57); bgl.glPopMatrix() bgl.glPopMatrix() bgl.glPopMatrix() bgl.glPopMatrix() if (enable_depth): bgl.glDisable(bgl.GL_DEPTH_TEST)
def draw(self): if not self.background is None: self.background.draw(self.allocation.w, self.allocation.h) if self.debug: self.draw_debug() for child in self.children: bgl.glPushMatrix() bgl.glTranslatef(child.allocation.x, child.allocation.y, 0) child.draw() bgl.glPopMatrix()
def info(self, text, arg1=0, y=0, z=0): if self.configured is True and self.view_orientation is not 0: x = arg1 if type(arg1) is mathutils.Vector(): x = arg1.x y = arg1.y z = arg1.z elif type(arg1) is bge.types.KX_GameObject: o = self.getPosition(arg1) x = o.x y = o.y z = o.z width = bge.render.getWindowWidth() height = bge.render.getWindowHeight() ratiow = 1. / width ratioh = 1. / height ratios = mathutils.Vector( (self.view_orientation[0][3], self.view_orientation[1][3], self.view_orientation[2][3])).length bgl.glPushMatrix() bgl.glTranslatef(x, y, z) buf = bgl.Buffer(bgl.GL_FLOAT, [16]) buf[0] = self.view_orientation[0][0] buf[1] = self.view_orientation[0][1] buf[2] = self.view_orientation[0][2] buf[3] = 0 buf[4] = self.view_orientation[1][0] buf[5] = self.view_orientation[1][1] buf[6] = self.view_orientation[1][2] buf[7] = 0 buf[8] = self.view_orientation[2][0] buf[9] = self.view_orientation[2][1] buf[10] = self.view_orientation[2][2] buf[11] = 0 buf[12] = 0 buf[13] = 0 buf[14] = 0 buf[15] = 1 bgl.glMultMatrixf(buf) 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 info( self, text, arg1=0, y=0, z=0 ): if self.configured is True and self.view_orientation is not 0: x = arg1 if type( arg1 ) is mathutils.Vector(): x = arg1.x y = arg1.y z = arg1.z elif type( arg1 ) is bge.types.KX_GameObject: o = self.getPosition( arg1 ) x = o.x y = o.y z = o.z width = bge.render.getWindowWidth() height = bge.render.getWindowHeight() ratiow = 1./width ratioh = 1./height ratios = mathutils.Vector( ( self.view_orientation[0][3], self.view_orientation[1][3], self.view_orientation[2][3] ) ).length bgl.glPushMatrix() bgl.glTranslatef( x,y,z ) buf = bgl.Buffer( bgl.GL_FLOAT, [16] ) buf[0] = self.view_orientation[0][0] buf[1] = self.view_orientation[0][1] buf[2] = self.view_orientation[0][2] buf[3] = 0 buf[4] = self.view_orientation[1][0] buf[5] = self.view_orientation[1][1] buf[6] = self.view_orientation[1][2] buf[7] = 0 buf[8] = self.view_orientation[2][0] buf[9] = self.view_orientation[2][1] buf[10] = self.view_orientation[2][2] buf[11] = 0 buf[12] = 0 buf[13] = 0 buf[14] = 0 buf[15] = 1 bgl.glMultMatrixf( buf ) 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_axes(self, context, angle): bgl.glEnable(bgl.GL_BLEND) bgl.glLineWidth(2) bgl.glPushMatrix() transforms = [] strips = bpy.context.selected_sequences for strip in strips: if strip.type == 'TRANSFORM': transforms.append(strip) group_box = get_group_box(transforms) min_left, max_right, min_bottom, max_top = group_box group_width = max_right - min_left group_height = max_top - min_bottom group_pos_x = min_left + (group_width / 2) group_pos_y = min_bottom + (group_height / 2) offset_x, offset_y, fac, preview_zoom = get_preview_offset() x = (group_pos_x * fac * preview_zoom) + offset_x y = (group_pos_y * fac * preview_zoom) + offset_y bgl.glTranslatef(x, y, 0) bgl.glRotatef(angle, 0, 0, 1) bgl.glBegin(bgl.GL_LINES) bgl.glColor4f(1.0, 0.0, 0.0, 0.2 * self.choose_axis + self.axis_x * 0.8) bgl.glVertex2f(-10000, 0) bgl.glVertex2f(10000, 0) bgl.glColor4f(0.0, 1.0, 0.0, 0.2 * self.choose_axis + self.axis_y * 0.8) bgl.glVertex2f(0, -10000) bgl.glVertex2f(0, 10000) bgl.glEnd() bgl.glPopMatrix() bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def afficher(self): """Affiche l'image""" VT = __class__.VT gl = __class__.gl bgl = __class__.bgl math = __class__.math if self.ok: id = self.VT_img.bindId if id: bgl.glMatrixMode(bgl.GL_PROJECTION) bgl.glLoadIdentity() vp = self.viewport bgl.glOrtho(vp[0], vp[1], vp[2], vp[3], -1.0, 1.0) bgl.glMatrixMode(bgl.GL_MODELVIEW) bgl.glLoadIdentity() bgl.glEnable(bgl.GL_TEXTURE_2D) bgl.glEnable(bgl.GL_BLEND) bgl.glBindTexture(bgl.GL_TEXTURE_2D, id) bgl.glTranslatef(self.bary[0], self.bary[1], 0) bgl.glRotatef(math.degrees(self.angle), 0.0, 0.0, 1.0) bgl.glTranslatef(-self.bary[0], -self.bary[1], 0) bgl.glBegin(bgl.GL_QUADS) col = self.couleur for i in range(len(self.texco)): bgl.glColor4f(col[0], col[1], col[2], col[3]) bgl.glTexCoord2f(self.texco[i][0], self.texco[i][1]) bgl.glVertex2f(self.verco[i][0], self.verco[i][1]) bgl.glEnd() bgl.glBindTexture(bgl.GL_TEXTURE_2D, 0) else: self.ok = False return
def drawHollowCircleBillBoard(context, location, radius, resolution=20): fl_resolution = float(resolution) #Marker Highlight axis, angle = getScreenLookAxis(context, location) bgl.glPushMatrix() bgl.glTranslatef(location.x, location.y, location.z) bgl.glPushMatrix() bgl.glRotatef(angle + 90.0, axis.x, axis.y, axis.z) bgl.glPushMatrix() # bgl.glBegin(bgl.GL_TRIANGLE_FAN); bgl.glLineWidth(5.0) bgl.glBegin(bgl.GL_LINE_LOOP) x, y = 0.0, 0.0 for i in range(resolution): factor = (float(i) / fl_resolution) * TWOPI xpos = x + (radius * math.cos(factor)) ypos = y + (radius * math.sin(factor)) bgl.glVertex2f(xpos, ypos) bgl.glEnd() bgl.glPopMatrix() bgl.glPopMatrix() bgl.glPopMatrix()
def drawText(context, text, location): v3d = context.space_data; rv3d = v3d.region_3d; text_scale = TEXT_SCALE_VALUE * ((max(min(MAX_ZOOM_DISTANCE, rv3d.view_distance), MIN_ZOOM_DISTANCE)) / FRIENDLY_ZOOM_DISTANCE); # print("RV3D PARAMETERS ::: " , rv3d.view_location, rv3d.view_distance); # print('TEXT SCALE USED :::: ', text_scale); font_id = 0; axis, angle = getScreenLookAxis(context); bgl.glPushMatrix(); bgl.glTranslatef(location.x, location.y , location.z); bgl.glPushMatrix(); bgl.glRotatef(angle, axis.x, axis.y, axis.z); bgl.glPushMatrix(); bgl.glScalef(text_scale,text_scale,text_scale); bgl.glPushMatrix(); bgl.glRotatef(90.0, 1.0, 0.0, 0.0); blf.position(font_id, 0.0, 0.0 , 0.0); blf.size(font_id, 72, 72); bgl.glColor4f(0.0, 0.0, 0.0, 1.0); blf.draw(0, text); # blf.rotation(0, 1.57); bgl.glPopMatrix(); bgl.glPopMatrix(); bgl.glPopMatrix(); bgl.glPopMatrix();
def ondraw_postview(self, obj_arm, bone): # draw limits arm_xray = obj_arm.data.xray if version_utils.IS_28: hide_global = obj_arm.hide_viewport view_layer = bpy.context.view_layer hide_viewport = obj_arm.hide_get(view_layer=view_layer) hide = hide_global or hide_viewport else: hide = obj_arm.hide multiply = version_utils.get_multiply() prev_line_width = bgl.Buffer(bgl.GL_FLOAT, [1]) bgl.glGetFloatv(bgl.GL_LINE_WIDTH, prev_line_width) bgl.glLineWidth(viewport.settings.LINE_WIDTH) bgl.glEnable(bgl.GL_BLEND) hide_bone = bone.hide hided = hide or hide_bone is_pose = obj_arm.mode == 'POSE' exportable = bone.xray.exportable draw_overlays = not hided and is_pose and exportable preferences = version_utils.get_preferences() # set color if is_pose: active_bone = bpy.context.active_bone color = None if active_bone: if active_bone.id_data == obj_arm.data: if active_bone.name == bone.name: color = preferences.gl_active_shape_color if color is None: if bone.select: color = preferences.gl_select_shape_color else: color = preferences.gl_shape_color else: color = preferences.gl_object_mode_shape_color if draw_overlays and arm_xray.display_bone_limits: context_obj = bpy.context.object if context_obj: is_active_object = context_obj.name == obj_arm.name else: is_active_object = False has_limits = bone.xray.ikjoint.type in {'2', '3', '5'} if bone.select and has_limits and is_active_object: draw_joint_limits = viewport.get_draw_joint_limits() if version_utils.IS_28: gpu.matrix.push() else: bgl.glPushMatrix() translate = obj_arm.pose.bones[bone.name].matrix.to_translation() mat_translate = mathutils.Matrix.Translation(translate) mat_rotate = obj_arm.data.bones[bone.name].matrix_local.to_euler().to_matrix().to_4x4() if bone.parent: mat_rotate_parent = obj_arm.pose.bones[bone.parent.name].matrix_basis.to_euler().to_matrix().to_4x4() else: mat_rotate_parent = mathutils.Matrix() mat = multiply( obj_arm.matrix_world, mat_translate, multiply(mat_rotate, mat_rotate_parent), mathutils.Matrix.Scale(-1, 4, (0, 0, 1)) ) if version_utils.IS_28: gpu.matrix.multiply_matrix(mat) else: bgl.glMultMatrixf( viewport.gl_utils.matrix_to_buffer(mat.transposed()) ) pose_bone = obj_arm.pose.bones[bone.name] if pose_bone.rotation_mode == 'QUATERNION': rotate = pose_bone.rotation_quaternion.to_euler('XYZ') else: rotate = obj_arm.pose.bones[bone.name].rotation_euler if arm_xray.joint_limits_type == 'IK': limits = ( pose_bone.ik_min_x, pose_bone.ik_max_x, pose_bone.ik_min_y, pose_bone.ik_max_y, pose_bone.ik_min_z, pose_bone.ik_max_z ) else: ik = bone.xray.ikjoint limits = ( ik.lim_x_min, ik.lim_x_max, ik.lim_y_min, ik.lim_y_max, ik.lim_z_min, ik.lim_z_max ) is_joint = bone.xray.ikjoint.type == '2' is_wheel = bone.xray.ikjoint.type == '3' is_slider = bone.xray.ikjoint.type == '5' if arm_xray.display_bone_limit_x and (is_joint or is_wheel): draw_joint_limits( rotate.x, limits[0], limits[1], 'X', arm_xray.display_bone_limits_radius ) if arm_xray.display_bone_limit_y and is_joint: draw_joint_limits( rotate.y, limits[2], limits[3], 'Y', arm_xray.display_bone_limits_radius ) if arm_xray.display_bone_limit_z and is_joint: draw_joint_limits( rotate.z, limits[4], limits[5], 'Z', arm_xray.display_bone_limits_radius ) # slider limits if arm_xray.display_bone_limit_z and is_slider: draw_slider_rotation_limits = viewport.get_draw_slider_rotation_limits() draw_slider_rotation_limits( rotate.z, limits[2], limits[3], arm_xray.display_bone_limits_radius ) bone_matrix = obj_arm.data.bones[bone.name].matrix_local.to_4x4() slider_mat = multiply( obj_arm.matrix_world, bone_matrix ) if version_utils.IS_28: gpu.matrix.pop() gpu.matrix.push() gpu.matrix.multiply_matrix(slider_mat) else: bgl.glPopMatrix() bgl.glPushMatrix() bgl.glMultMatrixf( viewport.gl_utils.matrix_to_buffer(slider_mat.transposed()) ) draw_slider_slide_limits = viewport.get_draw_slider_slide_limits() draw_slider_slide_limits(limits[0], limits[1], color) if version_utils.IS_28: gpu.matrix.pop() else: bgl.glPopMatrix() mat = multiply( obj_arm.matrix_world, obj_arm.pose.bones[bone.name].matrix, mathutils.Matrix.Scale(-1, 4, (0, 0, 1)) ) bmat = mat if not version_utils.IS_28: bgl.glColor4f(*color) shape = self.shape if shape.type == '0': bgl.glLineWidth(prev_line_width[0]) return # draw mass centers is_edit = obj_arm.mode == 'EDIT' draw_mass = obj_arm.data.xray.display_bone_mass_centers if draw_mass and exportable and not hided and not is_edit: ctr = self.mass.center trn = multiply( bmat, mathutils.Vector((ctr[0], ctr[2], ctr[1])) ) cross_size = obj_arm.data.xray.bone_mass_center_cross_size if version_utils.IS_28: gpu.matrix.push() gpu.matrix.translate(trn) viewport.draw_cross(cross_size, color=color) gpu.matrix.pop() else: bgl.glPopMatrix() bgl.glPushMatrix() bgl.glTranslatef(*trn) viewport.draw_cross(cross_size) bgl.glPopMatrix() # draw shapes draw_shapes = obj_arm.data.xray.display_bone_shapes if hided or not draw_shapes or not exportable or is_edit: bgl.glLineWidth(prev_line_width[0]) return if version_utils.IS_28: if not obj_arm.name in bpy.context.view_layer.objects: bgl.glLineWidth(prev_line_width[0]) return else: if not obj_arm.name in bpy.context.scene.objects: bgl.glLineWidth(prev_line_width[0]) return visible_armature_object = False for layer_index, layer in enumerate(obj_arm.layers): scene_layer = bpy.context.scene.layers[layer_index] if scene_layer and layer: visible_armature_object = True break if not visible_armature_object: bgl.glLineWidth(prev_line_width[0]) return if version_utils.IS_28: gpu.matrix.push() try: mat = multiply(mat, shape.get_matrix_basis()) gpu.matrix.multiply_matrix(mat) if shape.type == '1': # box viewport.draw_cube(*shape.box_hsz, color=color) if shape.type == '2': # sphere viewport.draw_sphere( shape.sph_rad, viewport.settings.BONE_SHAPE_SPHERE_SEGMENTS_COUNT, color=color ) if shape.type == '3': # cylinder viewport.draw_cylinder( shape.cyl_rad, shape.cyl_hgh * 0.5, viewport.settings.BONE_SHAPE_CYLINDER_SEGMENTS_COUNT, color ) finally: gpu.matrix.pop() else: bgl.glPopMatrix() bgl.glPushMatrix() try: mat = multiply(mat, shape.get_matrix_basis()) bgl.glMultMatrixf( viewport.gl_utils.matrix_to_buffer(mat.transposed()) ) if shape.type == '1': # box viewport.draw_cube(*shape.box_hsz) if shape.type == '2': # sphere viewport.draw_sphere( shape.sph_rad, viewport.settings.BONE_SHAPE_SPHERE_SEGMENTS_COUNT ) if shape.type == '3': # cylinder viewport.draw_cylinder( shape.cyl_rad, shape.cyl_hgh * 0.5, viewport.settings.BONE_SHAPE_CYLINDER_SEGMENTS_COUNT ) finally: bgl.glPopMatrix() bgl.glLineWidth(prev_line_width[0])
def draw_mouse(context, shape, style, alpha): # shape and position sc = context.scene mouse_size = sc.screencast_keys_mouse_size font_size = sc.screencast_keys_font_size link = sc.screencast_keys_link pos_x, pos_y = getDisplayLocation(context) if link: offset_x = pos_x else: offset_x = context.region.width - pos_x - (mouse_size * MOUSE_RATIO) offset_y = pos_y if font_size > mouse_size: offset_y += (font_size - mouse_size) / 2 shape_data = get_shape_data(shape) bgl.glTranslatef(offset_x, offset_y, 0) # color r, g, b = sc.screencast_keys_color bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(r, g, b, alpha) # inner shape for filled style if style == "filled": inner_shape = [] for i in shape_data: inner_shape.append(i[0]) # outer shape for i in shape_data: shape_segment = i shape_segment[0] = [mouse_size * k for k in shape_segment[0]] shape_segment[1] = [mouse_size * k for k in shape_segment[1]] shape_segment[2] = [mouse_size * k for k in shape_segment[2]] shape_segment[3] = [mouse_size * k for k in shape_segment[3]] # create the buffer shape_buffer = bgl.Buffer(bgl.GL_FLOAT, [4, 3], shape_segment) # create the map and draw the triangle fan bgl.glMap1f(bgl.GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, shape_buffer) bgl.glEnable(bgl.GL_MAP1_VERTEX_3) if style == "outline": bgl.glBegin(bgl.GL_LINE_STRIP) else: # style == "filled" bgl.glBegin(bgl.GL_TRIANGLE_FAN) for j in range(10): bgl.glEvalCoord1f(j / 10.0) x, y, z = shape_segment[3] # make sure the last vertex is indeed the last one, to avoid gaps bgl.glVertex3f(x, y, z) bgl.glEnd() bgl.glDisable(bgl.GL_MAP1_VERTEX_3) # draw interior if style == "filled": bgl.glBegin(bgl.GL_TRIANGLE_FAN) for i in inner_shape: j = [mouse_size * k for k in i] x, y, z = j bgl.glVertex3f(x, y, z) bgl.glEnd() bgl.glTranslatef(-offset_x, -offset_y, 0)
def draw(self, context): """ Draw vector icon on position of shared object """ if self.locked is True: # When object is locked by current client, then visualize it by green color. # Otherwise visualize it by red color if self.locked_by_me is True: color = (0.0, 1.0, 0.0, 1.0) else: color = (1.0, 0.0, 0.0, 1.0) else: color = (0.0, 1.0, 1.0, 1.0) # Store Line width line_width_prev = bgl.Buffer(bgl.GL_FLOAT, [1]) bgl.glGetFloatv(bgl.GL_LINE_WIDTH, line_width_prev) line_width_prev = line_width_prev[0] # Store glColor4f col_prev = bgl.Buffer(bgl.GL_FLOAT, [4]) bgl.glGetFloatv(bgl.GL_COLOR, col_prev) pos = self.transform.pos.value if pos is not None: new_pos = location_3d_to_region_2d( context.region, context.space_data.region_3d, pos) else: # When position of object is not set atm, then draw # icon with stipple line new_pos = mathutils.Vector((0.0, 0.0, 0.0, 1.0)) bgl.glEnable(bgl.GL_LINE_STIPPLE) verts = ( (0.20000000298023224, 0.0), (0.19318519532680511, 0.051763709634542465), (0.17320513725280762, 0.09999989718198776), (0.14142143726348877, 0.14142127335071564), (0.10000012069940567, 0.17320501804351807), (0.13000015914440155, 0.22516652941703796), (0.06729313731193542, 0.25114068388938904), (0.0, 0.2600000202655792), (-0.0672929584980011, 0.2511407434940338), (-0.1300000101327896, 0.22516663372516632), (-0.1000000014901161, 0.17320509254932404), (-0.1414213627576828, 0.1414213627576828), (-0.1732050925493240, 0.09999999403953552), (-0.1931851655244827, 0.05176381394267082), (-0.2000000029802322, 0.0), (-0.2600000202655792, 0.0), (-0.2511407434940338, -0.06729292124509811), (-0.2251666486263275, -0.12999996542930603), (-0.1838478147983551, -0.18384772539138794), (-0.1300000697374344, -0.22516658902168274), (-0.1000000461935997, -0.17320506274700165), (-0.0517638735473156, -0.19318515062332153), (0.0, -0.20000000298023224), (0.05176372453570366, -0.19318519532680511), (0.09999991953372955, -0.17320513725280762), (0.12999990582466125, -0.2251666933298111), (0.18384768068790436, -0.18384787440299988), (0.22516657412052155, -0.13000008463859558), (0.25114068388938904, -0.06729305535554886), (0.26000002026557920, 0.0) ) bgl.glLineWidth(1) bgl.glColor4f(color[0], color[1], color[2], color[3]) bgl.glPushMatrix() bgl.glTranslatef(new_pos[0], new_pos[1], 0) # TODO: Rotate this icon, when some other user change something (tranformation, mesh) # bgl.glRotatef(self.icon_angle, 0, 0, 1) # Draw icon bgl.glBegin(bgl.GL_LINE_LOOP) for vert in verts: bgl.glVertex2f(100.0 * vert[0], 100.0 * vert[1]) bgl.glEnd() # When object is locked by someone else or it can not be selected, then draw cross over icon if self.locked is True and self.locked_by_me is False or \ self.can_be_selected is False: bgl.glBegin(bgl.GL_LINES) bgl.glVertex2f(100.0 * verts[3][0], 100.0 * verts[3][1]) bgl.glVertex2f(100.0 * verts[18][0], 100.0 * verts[18][1]) bgl.glVertex2f(100.0 * verts[11][0], 100.0 * verts[11][1]) bgl.glVertex2f(100.0 * verts[27][0], 100.0 * verts[27][1]) bgl.glEnd() bgl.glPopMatrix() bgl.glDisable(bgl.GL_LINE_STIPPLE) bgl.glLineWidth(line_width_prev) bgl.glColor4f(col_prev[0], col_prev[1], col_prev[2], col_prev[3]) # # Try to draw mesh IDs # if self.mesh_node is not None: # self.mesh_node.draw_IDs(context, self.obj)
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_pixelate_controls(self, context): """ Draws the line, 2 boxes, and the control square """ w = context.region.width h = context.region.height line_width = 2 * (w / 10) offset_x = (line_width / 2) - (line_width * self.pixel_factor) x = self.first_mouse.x + offset_x y = self.first_mouse.y + self.pos.y bgl.glEnable(bgl.GL_BLEND) bgl.glLineWidth(1) bgl.glColor4f(0, 1, 1, 1) # Numbers bgl.glPushMatrix() bgl.glTranslatef(x - (w / 10) + self.pos.x, y, 0) font_id = 0 blf.position(font_id, 0, 10, 0) blf.size(font_id, 20, 72) blf.draw(font_id, str(self.fac)) bgl.glPopMatrix() # The Line bgl.glPushMatrix() bgl.glTranslatef(x, y, 0) bgl.glBegin(bgl.GL_LINE_LOOP) bgl.glVertex2f(-w / 10, 0) bgl.glVertex2f(w / 10, 0) bgl.glEnd() bgl.glPopMatrix() bgl.glEnable(bgl.GL_POINT_SMOOTH) bgl.glPointSize(10) # End Squares bgl.glPushMatrix() bgl.glTranslatef(x, y, 0) bgl.glBegin(bgl.GL_POINTS) bgl.glVertex2f(-w / 10, 0) bgl.glVertex2f(w / 10, 0) bgl.glEnd() bgl.glPopMatrix() # Control Square bgl.glColor4f(1, 0, 0, 1) bgl.glPushMatrix() bgl.glTranslatef(x - (w / 10) + self.pos.x, y, 0) bgl.glBegin(bgl.GL_POINTS) bgl.glVertex2f(0, 0) bgl.glEnd() bgl.glPopMatrix() bgl.glDisable(bgl.GL_POINT_SMOOTH) bgl.glPointSize(1) bgl.glLineWidth(1) bgl.glDisable(bgl.GL_BLEND) bgl.glColor4f(0.0, 0.0, 0.0, 1.0)
def draw_mouse(context, shape, style, alpha): # shape and position sc = context.scene mouse_size = sc.screencast_keys_mouse_size font_size = sc.screencast_keys_font_size box_draw = sc.screencast_keys_box_draw pos_x, pos_y = getDisplayLocation(context) if sc.screencast_keys_mouse_position == 'left': offset_x = pos_x if sc.screencast_keys_mouse_position == 'right': offset_x = context.region.width - pos_x - (mouse_size * MOUSE_RATIO) offset_y = pos_y if font_size > mouse_size: offset_y += (font_size - mouse_size) / 2 shape_data = get_shape_data(shape) bgl.glTranslatef(offset_x, offset_y, 0) # color r, g, b, a = sc.screencast_keys_text_color bgl.glEnable(bgl.GL_BLEND) bgl.glColor4f(r, g, b, alpha) # inner shape for filled style if style == "filled": inner_shape = [] for i in shape_data: inner_shape.append(i[0]) # outer shape for i in shape_data: shape_segment = i shape_segment[0] = [mouse_size * k for k in shape_segment[0]] shape_segment[1] = [mouse_size * k for k in shape_segment[1]] shape_segment[2] = [mouse_size * k for k in shape_segment[2]] shape_segment[3] = [mouse_size * k for k in shape_segment[3]] # create the buffer shape_buffer = bgl.Buffer(bgl.GL_FLOAT, [4, 3], shape_segment) # create the map and draw the triangle fan bgl.glMap1f(bgl.GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, shape_buffer) bgl.glEnable(bgl.GL_MAP1_VERTEX_3) if style == "outline": bgl.glBegin(bgl.GL_LINE_STRIP) else: # style == "filled" bgl.glBegin(bgl.GL_TRIANGLE_FAN) for j in range(10): bgl.glEvalCoord1f(j / 10.0) x, y, z = shape_segment[3] # make sure the last vertex is indeed the last one, to avoid gaps bgl.glVertex3f(x, y, z) bgl.glEnd() bgl.glDisable(bgl.GL_MAP1_VERTEX_3) # draw interior if style == "filled": bgl.glBegin(bgl.GL_TRIANGLE_FAN) for i in inner_shape: j = [mouse_size * k for k in i] x, y, z = j bgl.glVertex3f(x, y, z) bgl.glEnd() bgl.glTranslatef(-offset_x, -offset_y, 0)
def ondraw_postview(self, obj_arm, bone): # draw limits arm_xray = obj_arm.data.xray if IS_28: hide = obj_arm.hide_viewport else: hide = obj_arm.hide if not hide and arm_xray.display_bone_limits and \ bone.xray.exportable and obj_arm.mode == 'POSE': if bone.select and bone.xray.ikjoint.type in {'2', '3', '5'} and \ bpy.context.object.name == obj_arm.name: if IS_28: from ..gpu_utils import draw_joint_limits gpu.matrix.push() else: from ..gl_utils import draw_joint_limits, matrix_to_buffer bgl.glPushMatrix() bgl.glEnable(bgl.GL_BLEND) mat_translate = mathutils.Matrix.Translation( obj_arm.pose.bones[bone.name].matrix.to_translation()) mat_rotate = obj_arm.data.bones[ bone.name].matrix_local.to_euler().to_matrix().to_4x4() if bone.parent: mat_rotate_parent = obj_arm.pose.bones[ bone.parent.name].matrix_basis.to_euler().to_matrix( ).to_4x4() else: mat_rotate_parent = mathutils.Matrix() mat = multiply(obj_arm.matrix_world, mat_translate, multiply(mat_rotate, mat_rotate_parent), mathutils.Matrix.Scale(-1, 4, (0, 0, 1))) if IS_28: gpu.matrix.multiply_matrix(mat) else: bgl.glMultMatrixf(matrix_to_buffer(mat.transposed())) pose_bone = obj_arm.pose.bones[bone.name] if pose_bone.rotation_mode == 'QUATERNION': rotate = pose_bone.rotation_quaternion.to_euler('XYZ') else: rotate = obj_arm.pose.bones[bone.name].rotation_euler ik = bone.xray.ikjoint if arm_xray.display_bone_limit_x: draw_joint_limits(rotate.x, ik.lim_x_min, ik.lim_x_max, 'X', arm_xray.display_bone_limits_radius) if arm_xray.display_bone_limit_y: draw_joint_limits(rotate.y, ik.lim_y_min, ik.lim_y_max, 'Y', arm_xray.display_bone_limits_radius) if arm_xray.display_bone_limit_z: draw_joint_limits(rotate.z, ik.lim_z_min, ik.lim_z_max, 'Z', arm_xray.display_bone_limits_radius) if IS_28: gpu.matrix.pop() else: bgl.glPopMatrix() # draw shapes if IS_28: arm_hide = obj_arm.hide_viewport else: arm_hide = obj_arm.hide if arm_hide or not obj_arm.data.xray.display_bone_shapes or \ not bone.xray.exportable or obj_arm.mode == 'EDIT': return if IS_28: if not obj_arm.name in bpy.context.view_layer.objects: return else: if not obj_arm.name in bpy.context.scene.objects: return visible_armature_object = False for layer_index, layer in enumerate(obj_arm.layers): scene_layer = bpy.context.scene.layers[layer_index] if scene_layer and layer: visible_armature_object = True break if not visible_armature_object: return from ..gl_utils import matrix_to_buffer, \ draw_wire_cube, draw_wire_sphere, draw_wire_cylinder, draw_cross shape = self.shape if shape.type == '0': return if IS_28: from ..gpu_utils import draw_wire_cube, draw_wire_sphere, \ draw_wire_cylinder, draw_cross if bpy.context.active_bone \ and (bpy.context.active_bone.id_data == obj_arm.data) \ and (bpy.context.active_bone.name == bone.name): color = (1.0, 0.0, 0.0, 0.7) else: color = (0.0, 0.0, 1.0, 0.5) gpu.matrix.push() try: mat = multiply(obj_arm.matrix_world, obj_arm.pose.bones[bone.name].matrix, mathutils.Matrix.Scale(-1, 4, (0, 0, 1))) bmat = mat mat = multiply(mat, shape.get_matrix_basis()) gpu.matrix.multiply_matrix(mat) if shape.type == '1': # box draw_wire_cube(*shape.box_hsz, color) if shape.type == '2': # sphere draw_wire_sphere(shape.sph_rad, 16, color) if shape.type == '3': # cylinder draw_wire_cylinder(shape.cyl_rad, shape.cyl_hgh * 0.5, 16, color) gpu.matrix.pop() gpu.matrix.push() ctr = self.mass.center trn = multiply(bmat, mathutils.Vector( (ctr[0], ctr[2], ctr[1]))) gpu.matrix.translate(trn) draw_cross(0.05, color) finally: gpu.matrix.pop() else: bgl.glEnable(bgl.GL_BLEND) if bpy.context.active_bone \ and (bpy.context.active_bone.id_data == obj_arm.data) \ and (bpy.context.active_bone.name == bone.name): bgl.glColor4f(1.0, 0.0, 0.0, 0.7) else: bgl.glColor4f(0.0, 0.0, 1.0, 0.5) prev_line_width = bgl.Buffer(bgl.GL_FLOAT, [1]) bgl.glGetFloatv(bgl.GL_LINE_WIDTH, prev_line_width) bgl.glPushMatrix() try: mat = multiply(obj_arm.matrix_world, obj_arm.pose.bones[bone.name].matrix, mathutils.Matrix.Scale(-1, 4, (0, 0, 1))) bmat = mat bgl.glLineWidth(2) mat = multiply(mat, shape.get_matrix_basis()) bgl.glMultMatrixf(matrix_to_buffer(mat.transposed())) if shape.type == '1': # box draw_wire_cube(*shape.box_hsz) if shape.type == '2': # sphere draw_wire_sphere(shape.sph_rad, 16) if shape.type == '3': # cylinder draw_wire_cylinder(shape.cyl_rad, shape.cyl_hgh * 0.5, 16) bgl.glPopMatrix() bgl.glPushMatrix() ctr = self.mass.center trn = multiply(bmat, mathutils.Vector( (ctr[0], ctr[2], ctr[1]))) bgl.glTranslatef(*trn) draw_cross(0.05) finally: bgl.glPopMatrix() bgl.glLineWidth(prev_line_width[0])