def reload_avatar(): global mAvt mAvt.load_shape_model() mAvt.eyes = bpy.data.objects["Avatar:High-poly"] mAvt.body = bpy.data.objects["Avatar:Body"] mAvt.skel = bpy.data.objects["Avatar"] mAvt.armature = bpy.data.armatures["Avatar"] mAvt.skel_ref = motion_utils.get_rest_pose(mAvt.skel, mAvt.list_bones) mAvt.hips_pos = (mAvt.skel.matrix_world @ Matrix.Translation(mAvt.skel.pose.bones["Hips"].head)).to_translation() # Info to be used to compute body rotations is a faster manner list_matrices2 = [] for bone in mAvt.skel.pose.bones: list_matrices2.append(bone.matrix_basis.copy()) mAvt.list_matrices_basis = list_matrices2 list_matrices3 = [] for bone in mAvt.skel.data.bones: list_matrices3.append(bone.matrix_local.copy()) mAvt.list_matrices_local = list_matrices3 bvh_file = "%s/body/Reference.bvh" % avt_path bvh_nodes, _, _ = bvh_utils.read_bvh(bpy.context, bvh_file) mAvt.list_nodes = bvh_utils.sorted_nodes(bvh_nodes) # Info to compute deformation of clothes in fast manner size = len(mAvt.body.data.vertices) mAvt.body_kdtree = mathutils.kdtree.KDTree(size) for i, v in enumerate (mAvt.body.data.vertices): mAvt.body_kdtree.insert(v.co, i) mAvt.body_kdtree.balance()
def execute(self, context): global mAvt global avt_path scn = context.scene obj = context.active_object # load makehuman model # model_file = "%s/body/models/standard.mhx2" % avt_path # bpy.ops.import_scene.makehuman_mhx2(filepath=model_file) model_file = "%s/body/models/avatar.blend" % avt_path load_model_from_blend_file(model_file) mAvt.load_shape_model() mAvt.eyes = bpy.data.objects["Avatar:High-poly"] mAvt.body = bpy.data.objects["Avatar:Body"] mAvt.skel = bpy.data.objects["Avatar"] mAvt.armature = bpy.data.armatures["Avatar"] mAvt.skel_ref = motion_utils.get_rest_pose(mAvt.skel, mAvt.list_bones) mAvt.hips_pos = (mAvt.skel.matrix_world @ Matrix.Translation(mAvt.skel.pose.bones["Hips"].head)).to_translation() # Info to be used to compute body rotations is a faster manner list_matrices2 = [] for bone in mAvt.skel.pose.bones: list_matrices2.append(bone.matrix_basis.copy()) mAvt.list_matrices_basis = list_matrices2 list_matrices3 = [] for bone in mAvt.skel.data.bones: list_matrices3.append(bone.matrix_local.copy()) mAvt.list_matrices_local = list_matrices3 bvh_file = "%s/body/Reference.bvh" % avt_path bvh_nodes, _, _ = bvh_utils.read_bvh(bpy.context, bvh_file) mAvt.list_nodes = bvh_utils.sorted_nodes(bvh_nodes) # Info to compute deformation of clothes in fast manner size = len(mAvt.body.data.vertices) mAvt.body_kdtree = mathutils.kdtree.KDTree(size) for i, v in enumerate (mAvt.body.data.vertices): mAvt.body_kdtree.insert(v.co, i) mAvt.body_kdtree.balance() # Set collision body bpy.context.view_layer.objects.active = mAvt.body bpy.ops.object.mode_set(mode='OBJECT') bpy.ops.object.modifier_add(type='COLLISION') # Create skin material: eyes material should be created too skin_material = importlib.import_module('skin_material') importlib.reload(skin_material) skin_mat = skin_material.create_material('skin', 0, 1) tex_img, tex_norm, tex_spec = dressing.read_file_textures(avt_path, 'skin') skin_material.assign_textures(mAvt.body, skin_mat, tex_img, tex_norm, tex_spec) eyes_material = importlib.import_module('eyes_material') importlib.reload(eyes_material) eyes_mat = eyes_material.create_material('eyes', 0, 1) tex_img, tex_norm, tex_spec = dressing.read_file_textures(avt_path, 'eyes') eyes_material.assign_textures(mAvt.eyes, eyes_mat, tex_img, tex_norm, tex_spec) return {'FINISHED'}
importlib.reload(bvh_utils) frames_folder = "/home/jsanchez/Software/gitprojects/avatar/motion/frames" skel = bpy.data.objects["Standard"] list_bones = [ "Hips", "LHipJoint", "LeftUpLeg", "LeftLeg", "LeftFoot", "LeftToeBase", "LowerBack", "Spine", "Spine1", "LeftShoulder", "LeftArm", "LeftForeArm", "LeftHand", "LThumb", "LeftFingerBase", "LeftHandFinger1", "Neck", "Neck1", "Head", "RightShoulder", "RightArm", "RightForeArm", "RightHand", "RThumb", "RightFingerBase", "RightHandFinger1", "RHipJoint", "RightUpLeg", "RightLeg", "RightFoot", "RightToeBase" ] skel_ref = motion_utils.get_rest_pose(skel, list_bones) #movement_280.get_rest_pose2(skel, list_bones) point_files = [f for f in os.listdir(frames_folder) if f.endswith('.txt')] point_files.sort() num_packg = 0 bvh_file = "/home/jsanchez/Software/gitprojects/avatar/motion/sequences/Destroy.bvh" # poseBone = skel.pose.bones["Neck"] # print(poseBone.rotation_quaternion) # #q2 = Quaternion([1,0.1,0.3,0]) # q1 = Quaternion([1,0,0,0]) # q2 = Quaternion([0.5931, 0.7688, 0.0000, 0.2392])