Ejemplo n.º 1
0
 def draw_one(u):
     c = PCVCache.cache[u]
     # update matrix, every frame for now, it should be done better.. but it works well..
     m = c['object'].matrix_world
     matrix = []
     for v in m.transposed():
         matrix.extend(list(v.to_tuple()))
     matrix_buffer = bgl.Buffer(bgl.GL_FLOAT, len(matrix), matrix)
     c['matrix'] = m
     c['matrix_buffer'] = matrix_buffer
     
     bgl.glPushMatrix()
     bgl.glMultMatrixf(c['matrix_buffer'])
     
     bgl.glEnable(bgl.GL_DEPTH_TEST)
     bgl.glEnableClientState(bgl.GL_VERTEX_ARRAY)
     bgl.glVertexPointer(3, bgl.GL_FLOAT, 0, c['vertex_buffer'])
     bgl.glEnableClientState(bgl.GL_COLOR_ARRAY)
     bgl.glColorPointer(3, bgl.GL_FLOAT, 0, c['color_buffer'])
     
     if(PCVCache.cache[u]['smooth']):
         bgl.glEnable(bgl.GL_POINT_SMOOTH)
     
     l = int((c['length'] / 100) * c['display_percent'])
     bgl.glDrawArrays(bgl.GL_POINTS, 0, l)
     
     bgl.glDisableClientState(bgl.GL_VERTEX_ARRAY)
     bgl.glDisableClientState(bgl.GL_COLOR_ARRAY)
     
     if(c['smooth']):
         bgl.glDisable(bgl.GL_POINT_SMOOTH)
     bgl.glDisable(bgl.GL_DEPTH_TEST)
     
     bgl.glPopMatrix()
Ejemplo n.º 2
0
    def draw_one(u):
        c = PCVCache.cache[u]
        # update matrix, every frame for now, it should be done better.. but it works well..
        m = c['object'].matrix_world
        matrix = []
        for v in m.transposed():
            matrix.extend(list(v.to_tuple()))
        matrix_buffer = bgl.Buffer(bgl.GL_FLOAT, len(matrix), matrix)
        c['matrix'] = m
        c['matrix_buffer'] = matrix_buffer

        bgl.glPushMatrix()
        bgl.glMultMatrixf(c['matrix_buffer'])

        bgl.glEnable(bgl.GL_DEPTH_TEST)
        bgl.glEnableClientState(bgl.GL_VERTEX_ARRAY)
        bgl.glVertexPointer(3, bgl.GL_FLOAT, 0, c['vertex_buffer'])
        bgl.glEnableClientState(bgl.GL_COLOR_ARRAY)
        bgl.glColorPointer(3, bgl.GL_FLOAT, 0, c['color_buffer'])

        if (PCVCache.cache[u]['smooth']):
            bgl.glEnable(bgl.GL_POINT_SMOOTH)

        l = int((c['length'] / 100) * c['display_percent'])
        bgl.glDrawArrays(bgl.GL_POINTS, 0, l)

        bgl.glDisableClientState(bgl.GL_VERTEX_ARRAY)
        bgl.glDisableClientState(bgl.GL_COLOR_ARRAY)

        if (c['smooth']):
            bgl.glDisable(bgl.GL_POINT_SMOOTH)
        bgl.glDisable(bgl.GL_DEPTH_TEST)

        bgl.glPopMatrix()
Ejemplo n.º 3
0
    def clean(self, opts=None):
        if not self.is_dirty: return

        # make not dirty first in case bad things happen while drawing
        self.is_dirty = False

        if self.src_bvh:
            # normal_update() will destroy normals of verts not connected to faces :(
            self.tar_bmesh.normal_update()
            for bmv in self.tar_bmesh.verts:
                if len(bmv.link_faces) != 0: continue
                _, n, _, _ = self.src_bvh.find_nearest(self.src_imx * bmv.co)
                bmv.normal = (self.src_mxnorm * n).normalized()

        bgl.glNewList(self.calllist, bgl.GL_COMPILE)
        # do not change attribs if they're not set
        glSetDefaultOptions(opts=opts)
        bgl.glPushMatrix()
        bgl.glMultMatrixf(self.bglMatrix)
        glDrawBMFaces(self.tar_bmesh.faces, opts=opts, enableShader=False)
        glDrawBMEdges(self.tar_bmesh.edges, opts=opts, enableShader=False)
        glDrawBMVerts(self.tar_bmesh.verts, opts=opts, enableShader=False)
        bgl.glDepthRange(0, 1)
        bgl.glPopMatrix()
        bgl.glEndList()
Ejemplo n.º 4
0
    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])
Ejemplo n.º 5
0
    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()
Ejemplo n.º 6
0
	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()
Ejemplo n.º 7
0
    def draw(self, opts=None):
        if self.is_dirty:
            # make not dirty first in case bad things happen while drawing
            self.is_dirty = False

            bgl.glNewList(self.calllist, bgl.GL_COMPILE)
            # do not change attribs if they're not set
            glSetDefaultOptions(opts=opts)
            if self.mx:
                bgl.glPushMatrix()
                bgl.glMultMatrixf(self.bglMatrix)
            glDrawBMFaces(self.bmesh.faces, opts=opts)
            glDrawBMEdges(self.bmesh.edges, opts=opts)
            glDrawBMVerts(self.bmesh.verts, opts=opts)
            bgl.glDepthRange(0, 1)
            if self.mx:
                bgl.glPopMatrix()
            bgl.glEndList()

        bgl.glCallList(self.calllist)
Ejemplo n.º 8
0
 def draw(self, opts=None):
     if self.is_dirty:
         # make not dirty first in case bad things happen while drawing
         self.is_dirty = False
         
         bgl.glNewList(self.calllist, bgl.GL_COMPILE)
         # do not change attribs if they're not set
         glSetDefaultOptions(opts=opts)
         if self.mx:
             bgl.glPushMatrix()
             bgl.glMultMatrixf(self.bglMatrix)
         glDrawBMFaces(self.bmesh.faces, opts=opts)
         glDrawBMEdges(self.bmesh.edges, opts=opts)
         glDrawBMVerts(self.bmesh.verts, opts=opts)
         bgl.glDepthRange(0, 1)
         if self.mx:
             bgl.glPopMatrix()
         bgl.glEndList()
     
     bgl.glCallList(self.calllist)
Ejemplo n.º 9
0
    def draw(self, renderer, obj):
        if self.update:
            self.cache(renderer, obj)

        data = obj.data
        if data:
            mesh = renderer.mesh_cache.get(hash(obj.data))
            if mesh is None:
                mesh = LineMeshCache()
                renderer.mesh_cache[hash(obj.data)] = mesh

            if obj.select:
                bgl.glLineWidth(2)
                bgl.glLineStipple(1, 0xAAAA)
                bgl.glEnable(bgl.GL_LINE_STIPPLE)

            bgl.glPushMatrix()
            bgl.glMultMatrixf(self.m)

            mesh.draw(renderer, obj)

            bgl.glPopMatrix()
Ejemplo n.º 10
0
def draw_callback_view():
    context = bpy.context
    if context.mode != "EDIT_MESH":
        return
    ob = context.active_object
    if ob is None:
        return
    if ob.type != "MESH":
        return
    if ob.mode != "EDIT":
        return
    if False:
        # Respects modifiers, but not hidden edges
        ob.update_from_editmode()
        bm = bmesh.new()
        bm.from_object(ob, context.scene)
    else:
        # Faster bmesh access, but doesn't respect modifiers
        bm = bmesh.from_edit_mesh(ob.data)
    layer = get_edgecolor_layer(bm)
    if layer is None:
        return
    bgl.glLineWidth(3.0)
    bgl.glPushMatrix()
    b = bgl.Buffer(GL_FLOAT, [16], list(itertools.chain(*ob.matrix_world.col)))
    bgl.glMultMatrixf(b)
    for edge in bm.edges:
        if edge.hide: continue
        color_int = edge[layer]
        if color_int == 0: continue
        bgl.glColor3f(*colors[color_int])
        bgl.glBegin(GL_LINES)
        for v in edge.verts:
            bgl.glVertex3f(*v.co)
        bgl.glEnd()
    bgl.glPointSize(1.0)
    bgl.glLineWidth(1.0)
    bgl.glPopMatrix()
Ejemplo n.º 11
0
def draw_callback_view():
    context = bpy.context
    if context.mode != "EDIT_MESH":
        return
    ob = context.active_object
    if ob is None:
        return
    if ob.type != "MESH":
        return
    if ob.mode != "EDIT":
        return
    if False:
        # Respects modifiers, but not hidden edges
        ob.update_from_editmode()
        bm = bmesh.new()
        bm.from_object(ob, context.scene)
    else:
        # Faster bmesh access, but doesn't respect modifiers
        bm = bmesh.from_edit_mesh(ob.data)
    layer = get_edgecolor_layer(bm)
    if layer is None:
        return
    bgl.glLineWidth(3.0)
    bgl.glPushMatrix()
    b = bgl.Buffer(GL_FLOAT, [16], list(itertools.chain(*ob.matrix_world.col)))
    bgl.glMultMatrixf(b)
    for edge in bm.edges:
        if edge.hide: continue
        color_int = edge[layer]
        if color_int == 0: continue
        bgl.glColor3f(*colors[color_int])
        bgl.glBegin(GL_LINES)
        for v in edge.verts:
            bgl.glVertex3f(*v.co)
        bgl.glEnd()
    bgl.glPointSize(1.0)
    bgl.glLineWidth(1.0)
    bgl.glPopMatrix()
Ejemplo n.º 12
0
    def ondraw_postview(self, obj_arm, bone):
        if obj_arm.hide or not obj_arm.data.xray.display_bone_shapes:
            return

        from .gl_utils import matrix_to_buffer, draw_wire_cube, draw_wire_sphere, draw_wire_cylinder

        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:
            m = obj_arm.matrix_world * obj_arm.pose.bones[
                bone.name].matrix * mathutils.Matrix.Scale(-1, 4, (0, 0, 1))
            bgl.glLineWidth(2)
            if shape.type == '1':  # box
                rt = shape.box_rot
                mr = mathutils.Matrix((rt[0:3], rt[3:6], rt[6:9])).transposed()
                m *= mathutils.Matrix.Translation(shape.box_trn) * mr.to_4x4()
                bgl.glMultMatrixf(matrix_to_buffer(m.transposed()))
                draw_wire_cube(*shape.box_hsz)
            if shape.type == '2':  # sphere
                m *= mathutils.Matrix.Translation(shape.sph_pos)
                bgl.glMultMatrixf(matrix_to_buffer(m.transposed()))
                draw_wire_sphere(shape.sph_rad, 16)
            if shape.type == '3':  # cylinder
                m *= mathutils.Matrix.Translation(shape.cyl_pos)
                bgl.glMultMatrixf(matrix_to_buffer(m.transposed()))
                v_dir = mathutils.Vector(shape.cyl_dir)
                q_rot = v_dir.rotation_difference((0, 1, 0))
                bgl.glMultMatrixf(matrix_to_buffer(q_rot.to_matrix().to_4x4()))
                draw_wire_cylinder(shape.cyl_rad, shape.cyl_hgh * 0.5, 16)
        finally:
            bgl.glPopMatrix()
            bgl.glLineWidth(prev_line_width[0])
Ejemplo n.º 13
0
    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])
Ejemplo n.º 14
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])