import bpy # import Blender import math # from Blender.Scene import Render from Libs.Libs_py import * from Libs.Libs_py import LibPosePadrao, LibConfigMaoDir, LibPontoArticulacaoDir, LibOrientacaoDir, LibConfigMaoEsq, LibPontoArticulacaoEsq, LibOrientacaoEsq, LibExpFacial class Armadura: def __init__(self,nameArmature): self.armadura = bpy.context.scene.objects.get(nameArmature) # bpy.data.objects['Armature.001'] # bpy.context.object # self.armadura = Blender.Object.Get(nameArmature) self.pose = self.armadura.pose # self.armadura.getPose() self.act = bpy.context.scene.animation_data_create() #self.act = Armature.NLA.NewAction(nameAction) # bpy.context.scene.objects.active = self.armadura # self.act.setActive(self.armadura) class BasePose (object): def setPose(self, default_pose): for cfg in default_pose: if cfg['name'] in self.parameters: for bone in cfg['bones']: pose_bone = self.armature.pose.bones[bone['name']] # pose_bone = self.armature.armadura.pose.bones[bone['name']] pose_bone.location = bone['loc'] for l in range(0,len(self.positionFrames['loc'])): pose_bone.keyframe_insert(data_path = 'location',frame = self.positionFrames['loc'][l], index = -1) pose_bone.rotation_euler = math.radians(bone['rot'][0]),math.radians(bone['rot'][1]),math.radians(bone['rot'][2]) pose_bone.rotation_quaternion = pose_bone.rotation_euler.to_quaternion() for r in range(0,len(self.positionFrames['rot'])): pose_bone.keyframe_insert(data_path ='rotation_quaternion',frame = self.positionFrames['rot'][r], index = -1) # pose_bone.insertKey(self.armature.armadura, self.positionFrames['rot'][r], Object.Pose.ROT,True) #bpy.context.object.rotation_mode = rot_mode class Mao(BasePose): def __init__(self,handParam,posFrames,armadura): self.parameters = handParam self.positionFrames = posFrames self.armature = armadura def genConf(self,default_pose,posFrames = None): if(posFrames != None): self.positionFrames = posFrames default_pose = default_pose self.setPose(default_pose) def genArtPoint(self,default_pose,posFrames = None): if(posFrames != None): self.positionFrames = posFrames default_pose = default_pose self.setPose(default_pose) def genOri(self,default_pose,posFrames = None): if(posFrames != None): self.positionFrames = posFrames default_pose = default_pose self.setPose(default_pose) def rotationCircular(self,center, radius, i_axis, j_axis, k_axis,pose, initialPosition, laps, frameJump = 5, initialFrame = 15, turn = None): const = radius * math.sqrt(2) / 2 const1 = (radius/2) currentFrame = initialFrame for l in range(initialPosition, initialPosition + math.floor(8 * laps) + 1): if ((l % 8) == 0 ): pose.location[i_axis] = center[i_axis] + radius pose.location[j_axis] = center[j_axis] pose.location[k_axis] = center[k_axis] pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') currentFrame += frameJump if ((l % 8) == 1): pose.location[i_axis] = center[i_axis] + const pose.location[j_axis] = center[j_axis] + const pose.location[k_axis] = center[k_axis] if(turn == 1): pose.location[i_axis] = center[i_axis] + const pose.location[j_axis] = center[j_axis] + const1 pose.location[k_axis] = center[k_axis] - const1 elif(turn == -1): pose.location[i_axis] = center[i_axis] + const pose.location[j_axis] = center[j_axis] + const1 pose.location[k_axis] = center[k_axis] + const1 pose.keyframe_insert(frame = initialPosition, index = -1, data_path = 'location') currentFrame += frameJump if ((l % 8) == 2): pose.location[i_axis] = center[i_axis] pose.location[j_axis] = center[j_axis] + radius pose.location[k_axis] = center[k_axis] if(turn == 1): pose.location[j_axis] = center[j_axis] + const pose.location[k_axis] = center[k_axis] - const elif(turn == -1): pose.location[j_axis] = center[j_axis] + const pose.location[k_axis] = center[k_axis] + const pose.keyframe_insert(frame = initialPosition, index = -1, data_path = 'location') currentFrame += frameJump if ((l % 8) == 3): pose.location[i_axis] = center[i_axis] - const pose.location[j_axis] = center[j_axis] + const pose.location[k_axis] = center[k_axis] if(turn == 1): pose.location[i_axis] = center[i_axis] - const pose.location[j_axis] = center[j_axis] + const1 pose.location[k_axis] = center[k_axis] - const1 elif(turn == -1): pose.location[i_axis] = center[i_axis] - const pose.location[j_axis] = center[j_axis] + const1 pose.location[k_axis] = center[k_axis] + const1 pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') currentFrame += frameJump if ((l % 8) == 4): pose.location[i_axis] = center[i_axis] - radius pose.location[j_axis] = center[j_axis] pose.location[k_axis] = center[k_axis] pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') currentFrame += frameJump if ((l % 8) == 5): pose.location[i_axis] = center[i_axis] - const pose.location[j_axis] = center[j_axis] - const pose.location[k_axis] = center[k_axis] if(turn == 1): pose.location[i_axis] = center[i_axis] - const pose.location[j_axis] = center[j_axis] - const1 pose.location[k_axis] = center[k_axis] + const1 elif(turn == -1): pose.location[i_axis] = center[i_axis] - const pose.location[j_axis] = center[j_axis] - const1 pose.location[k_axis] = center[k_axis] - const1 pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') currentFrame += frameJump if ((l % 8) == 6): pose.location[i_axis] = center[i_axis] pose.location[j_axis] = center[j_axis] - radius pose.location[k_axis] = center[k_axis] if(turn == 1): pose.location[j_axis] = center[j_axis] - const pose.location[k_axis] = center[k_axis] + const elif(turn == -1): pose.location[j_axis] = center[j_axis] - const pose.location[k_axis] = center[k_axis] - const pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') currentFrame += frameJump if ((l % 8) == 7): pose.location[i_axis] = center[i_axis] + const pose.location[j_axis] = center[j_axis] - const pose.location[k_axis] = center[k_axis] if(turn == 1): pose.location[i_axis] = center[i_axis] + const pose.location[j_axis] = center[j_axis] - const1 pose.location[k_axis] = center[k_axis] + const1 elif(turn == -1): pose.location[i_axis] = center[i_axis] + const pose.location[j_axis] = center[j_axis] - const1 pose.location[k_axis] = center[k_axis] - const1 pose.keyframe_insert(frame = currentFrame, index = -1, data_path = 'location') currentFrame += frameJump currentFrame -= frameJump return currentFrame def genMov(self,pose,frames,calculos): for i in range(0, len(frames)): pose.location[:] = calculos[i][0], calculos[i][1], calculos[i][2] pose.keyframe_insert(data_path = 'location',frame = frames[i],index= -1) class MaoDireita(Mao): def __init__(self, handParam, posFrames, armadura): super(self.__class__, self).__init__(handParam,posFrames,armadura) self.genConf() self.genOri() self.genArtPoint() def genConf(self,posFrames = None,param = None): default_pose = LibConfigMaoDir.lib if(param != None): self.parameters = param super(self.__class__, self).genConf(default_pose,posFrames) def genOri(self,posFrames = None,param = None): default_pose = LibOrientacaoDir.lib if(param != None): self.parameters = param super(self.__class__, self).genOri(default_pose,posFrames) def genArtPoint(self,posFrames = None,param = None): default_pose = LibPontoArticulacaoDir.lib if(param != None): self.parameters = param super(self.__class__, self).genArtPoint(default_pose,posFrames) class MaoEsquerda(Mao): def __init__(self,handParam,posFrames,armadura): super(self.__class__,self).__init__(handParam,posFrames,armadura) self.genConf() self.genOri() self.genArtPoint() def genConf(self,posFrames = None,param = None): default_pose = LibConfigMaoEsq.lib if(param != None): self.parameters = param super(self.__class__, self).genConf(default_pose,posFrames) def genOri(self,posFrames = None,param = None): default_pose = LibOrientacaoEsq.lib if(param != None): self.parameters = param super(self.__class__, self).genOri(default_pose,posFrames) def genArtPoint(self, posFrames = None,param = None): default_pose = LibPontoArticulacaoEsq.lib if(param != None): self.parameters = param super(self.__class__, self).genArtPoint(default_pose,posFrames) class Face(BasePose): def __init__(self,faceParam, armadura, endFram): self.parameters = ("Exp_9", faceParam, "Exp_9") self.armature = armadura self.endFrame = endFram self.genFace() def genFace(self): default_pose = LibExpFacial.lib self.setPose(default_pose) def setPose(self,default_pose): for h in range(0,len(self.parameters)): for cfg in default_pose: if cfg['name'] == self.parameters[h]: for bone in cfg['bones']: pose_bone = self.armature.pose.bones[bone['name']] pose_bone.location = bone['loc'] pose_bone.keyframe_insert(data_path = 'location',frame = h*(self.endFrame/2) + 1 + h*3, index = -1) pose_bone.rotation_euler = math.radians(bone['rot'][0]),math.radians(bone['rot'][1]),math.radians(bone['rot'][2]) pose_bone.rotation_quaternion = pose_bone.rotation_euler.to_quaternion() pose_bone.keyframe_insert(data_path ='rotation_quaternion',frame = h*(self.endFrame/2) + 1, index = -1) class Pose(BasePose): parameters = ["Pose_1", "Pose_2"] def __init__ (self, posFrames, armadura): self.armature = armadura self.positionFrames = posFrames self.genPose() def genPose(self): default_pose = LibPosePadrao.lib self.setPose(default_pose)