当前位置: 首页>>代码示例>>Python>>正文


Python Matrix.resize4x4方法代码示例

本文整理汇总了Python中mathutils.Matrix.resize4x4方法的典型用法代码示例。如果您正苦于以下问题:Python Matrix.resize4x4方法的具体用法?Python Matrix.resize4x4怎么用?Python Matrix.resize4x4使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mathutils.Matrix的用法示例。


在下文中一共展示了Matrix.resize4x4方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: buildANM

# 需要导入模块: from mathutils import Matrix [as 别名]
# 或者: from mathutils.Matrix import resize4x4 [as 别名]
def buildANM(filename=None, armObj=None):
    import bpy
    from mathutils import Quaternion, Vector, Matrix
    from time import sleep
    armObj = bpy.data.objects['lolArmature']
    filename =\
    '/var/tmp/downloads/lol/Characters/Wolfman/Animations/Wolfman_Attack1.anm'
    #'/Users/zac/Desktop/LoL Modeling/Characters/Wolfman/Animations/Wolfman_attack1.anm'
    header, animation = importANM(filename)
    #bpy.ops.object.mode_set(mode='EDIT')
    #bpy.ops.object.select_all()
    #bpy.ops.armature.parent_clear('DISCONNECT')
    #Generate keyframes
    #for f in range(header['numFrames']):
        
        #bpy.ops.anim.change_frame(frame = f)

        #set frame = f
        #create keyframe

    #generate boneIdx:{name, pos} dictionary
    #Animations appear to be prerotated -90x?
    restPose = {}
    for bone in armObj.data.bones:
        rotationMatrix = bone.matrix.rotation_part()
        quat = rotationMatrix.to_quat()
        rotationMatrixInv = Matrix(rotationMatrix)
        rotationMatrixInv = rotationMatrixInv.invert()
        restPose[bone.name] = {'pos':bone.tail, 
                'rotMatrix':rotationMatrix.resize4x4(),
                'rotMatrixInv':rotationMatrixInv.resize4x4(),
                'quat':quat}

    #redo animation list

    #Go into pose mode
    bpy.ops.object.mode_set(mode='POSE', toggle=False)

    #For each frame, loop through bones:
    #for f in range(header['numFrames']):

    #Create heirarchy
    rootBone = armObj.data.bones[0]
    boneLevelHeirary = buildBoneHeirarchy(rootBone)

    #for f in range(header['numFrames']):
    for f in range(1):
        #Change to frame # f
        bpy.ops.anim.change_frame(frame=f)
        k=0
        for boneLevel in boneLevelHeirary:#[:1]:

            for bone in boneLevel:
                boneName = bone.name
                pBone = armObj.pose.bones[boneName]
                aBone = armObj.data.bones[boneName]

                #Check if this bone has animation data for it, skip if it
                #doesn't
                if boneName not in animation.keys():
                    print('Couldn\'t find bone %s in animation data'%
                            (boneName,))
                    continue
                
                #Get new location
                newLoc = Vector(animation[boneName]['pos'][f])# - \
                    #restPose[boneName]['pos']
                
                #Get new Quaternion
                '''
                newQ = Quaternion()
                newQ.x = animation[boneName]['quat'][f][1]
                newQ.y = animation[boneName]['quat'][f][2]
                newQ.z = animation[boneName]['quat'][f][3]
                newQ.angle = animation[boneName]['quat'][f][0]# * 3.14159/180.0
                '''
                w,x,y,z = animation[boneName]['quat'][f][:]
                frameQ = Quaternion((w,x,y,z))
                #oldQ = pBone.rotation_quaternion
                oldQ = aBone.matrix.to_quat()
                print(oldQ)
                #newQ = oldQ.inverse() * frameQ*oldQ
                newQ = frameQ

                #newQ   = Quaternion(animation[boneName]['quat'][f]) #- \
                #        restPose[boneName]['quat']
                if boneName == 'ROOT':
                    print(restPose[boneName]['quat'])
                    print(animation[boneName]['quat'][f])
                    print(newQ)
                    print('\n')
                    print(restPose[boneName]['pos'])
                    print(newLoc)
                    print('\n')
                    
                '''
                #From io_anim_bvh.py
                frameLoc = Vector(animation[boneName]['pos'][f])
                transVec = frameLoc - restPose[boneName]['pos']

#.........这里部分代码省略.........
开发者ID:Norbinn,项目名称:lolblender,代码行数:103,代码来源:lolAnimation.py


注:本文中的mathutils.Matrix.resize4x4方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。