def execute(self): BlenderSceneManipulator().clear_scene() home_transform = TransformNode() first_keyframe = 0 second_keyframe = 5 test_armature_obj, test_armature_tree_hierarchy = \ BlenderArmatureBuilder() \ .with_armature_name(armature_name="TEST_ARMATURE") \ .with_bone(name="BONE_A", transform=home_transform) \ .with_bone(name="BONE_B", transform=home_transform) \ .build() animated_armature_tree_hierarchies = BlenderArmatureAnimator \ .for_armature(test_armature_obj, test_armature_tree_hierarchy) \ .animate_bone(name="BONE_A", local_transform= TransformNode.construct_with( position=Vector3d(0.3, 0.5, 0.7), rotation=Quaternion(), scale=Vector3d(0.2, 0.4, 0.6) ), keyframe_number=first_keyframe) \ .animate_bone(name="BONE_A", local_transform= TransformNode.construct_with( position=Vector3d(0.9, 0.1, 0.3), rotation=Quaternion(), scale=Vector3d(0.6, 1.6, 1.3) ), keyframe_number=second_keyframe) \ .commit() calculated_bone_animation_world_matrix_a = BoneMatrixHelper.get_world_matrix_for_bone( "BONE_A", animated_armature_tree_hierarchies[0]) # type: Matrix4x4 calculated_bone_animation_world_matrix_b = BoneMatrixHelper.get_world_matrix_for_bone( "BONE_A", animated_armature_tree_hierarchies[1]) # type: Matrix4x4 BlenderArmatureAnimator \ .for_armature(test_armature_obj, test_armature_tree_hierarchy) \ .animate_bone( name="BONE_B", local_transform=TransformNode.from_matrix4x4(calculated_bone_animation_world_matrix_a), keyframe_number=first_keyframe) \ .animate_bone( name="BONE_B", local_transform=TransformNode.from_matrix4x4(calculated_bone_animation_world_matrix_b), keyframe_number=second_keyframe) \ .commit()
def from_matrix4x4(bone_name: str, matrix: Matrix4x4, is_keyframe: bool = False) -> 'BoneTransformNode': result = BoneTransformNode() result.bone_name = bone_name result.bone_transform = TransformNode.from_matrix4x4(matrix) result.is_keyframe = is_keyframe return result
def _synthetic_transformation_verification_example(self): BlenderSceneManipulator().clear_scene() home_transform = TransformNode() first_keyframe = 0 second_keyframe = 10 chained_armature_chained_bones_transforms = \ ChainedBonesTransformsFactory.get_armature_chained_bones_transforms_for( bones_count=7 ) # type: List[TransformNode] blender_flat_armature_obj, blender_flat_armature_tree_hierarchy = \ BlenderArmatureBuilder() \ .with_armature_name("SYNTHETIC_EXAMPLE_FLAT_ARMATURE") \ .with_bone(name="E1_BONE_TOP", transform=home_transform) \ .with_bone(name="E1_BONE_BOTTOM", transform=chained_armature_chained_bones_transforms[6]) \ .parent_bones(child="E1_BONE_BOTTOM", parent="E1_BONE_TOP") \ .build() blender_parented_armature_obj, blender_parented_armature_tree_hierarchy = \ BlenderArmatureBuilder() \ .with_armature_name("SYNTHETIC_EXAMPLE_PARENTED_ARMATURE") \ .with_bone(name="E2_BONE_TOP", transform=home_transform) \ .with_bone(name="E2_BONE_CHAIN_1", transform=chained_armature_chained_bones_transforms[1]) \ .with_bone(name="E2_BONE_CHAIN_2", transform=chained_armature_chained_bones_transforms[2]) \ .with_bone(name="E2_BONE_CHAIN_3", transform=chained_armature_chained_bones_transforms[3]) \ .with_bone(name="E2_BONE_CHAIN_4", transform=chained_armature_chained_bones_transforms[4]) \ .with_bone(name="E2_BONE_CHAIN_5", transform=chained_armature_chained_bones_transforms[5]) \ .with_bone(name="E2_BONE_BOTTOM", transform=chained_armature_chained_bones_transforms[6]) \ .parent_bones(child="E2_BONE_BOTTOM", parent="E2_BONE_CHAIN_5") \ .parent_bones(child="E2_BONE_CHAIN_5", parent="E2_BONE_CHAIN_4") \ .parent_bones(child="E2_BONE_CHAIN_4", parent="E2_BONE_CHAIN_3") \ .parent_bones(child="E2_BONE_CHAIN_3", parent="E2_BONE_CHAIN_2") \ .parent_bones(child="E2_BONE_CHAIN_2", parent="E2_BONE_CHAIN_1") \ .parent_bones(child="E2_BONE_CHAIN_1", parent="E2_BONE_TOP") \ .build() displaced_chained_bones_transforms_first_keyframe = DisplacedChainedBonesTransformsFactory.get_displaced_transforms_for( bones_count=7, seed=1 ) displaced_chained_bones_transforms_second_keyframe = DisplacedChainedBonesTransformsFactory.get_displaced_transforms_for( bones_count=7, seed=2 ) animated_armature_tree_hierarchies = BlenderArmatureAnimator \ .for_armature(blender_parented_armature_obj, blender_parented_armature_tree_hierarchy) \ .animate_bone(name="E2_BONE_TOP", local_transform=displaced_chained_bones_transforms_first_keyframe[0], keyframe_number=first_keyframe) \ .animate_bone(name="E2_BONE_CHAIN_1", local_transform=displaced_chained_bones_transforms_first_keyframe[1], keyframe_number=first_keyframe) \ .animate_bone(name="E2_BONE_CHAIN_2", local_transform=displaced_chained_bones_transforms_first_keyframe[2], keyframe_number=first_keyframe) \ .animate_bone(name="E2_BONE_CHAIN_3", local_transform=displaced_chained_bones_transforms_first_keyframe[3], keyframe_number=first_keyframe) \ .animate_bone(name="E2_BONE_CHAIN_4", local_transform=displaced_chained_bones_transforms_first_keyframe[4], keyframe_number=first_keyframe) \ .animate_bone(name="E2_BONE_CHAIN_5", local_transform=displaced_chained_bones_transforms_first_keyframe[5], keyframe_number=first_keyframe) \ .animate_bone(name="E2_BONE_BOTTOM", local_transform=displaced_chained_bones_transforms_first_keyframe[6], keyframe_number=first_keyframe) \ \ \ .animate_bone(name="E2_BONE_TOP", local_transform=displaced_chained_bones_transforms_second_keyframe[0], keyframe_number=second_keyframe) \ .animate_bone(name="E2_BONE_CHAIN_1", local_transform=displaced_chained_bones_transforms_second_keyframe[1], keyframe_number=second_keyframe) \ .animate_bone(name="E2_BONE_CHAIN_2", local_transform=displaced_chained_bones_transforms_second_keyframe[2], keyframe_number=second_keyframe) \ .animate_bone(name="E2_BONE_CHAIN_3", local_transform=displaced_chained_bones_transforms_second_keyframe[3], keyframe_number=second_keyframe) \ .animate_bone(name="E2_BONE_CHAIN_4", local_transform=displaced_chained_bones_transforms_second_keyframe[4], keyframe_number=second_keyframe) \ .animate_bone(name="E2_BONE_CHAIN_5", local_transform=displaced_chained_bones_transforms_second_keyframe[5], keyframe_number=second_keyframe) \ .animate_bone(name="E2_BONE_BOTTOM", local_transform=displaced_chained_bones_transforms_second_keyframe[6], keyframe_number=second_keyframe) \ .commit() #bone_animation_local_matrix_a = BlenderArmatureBoneCurrentAnimationDataHelper \ # .get_bone_local_matrix( # armature=blender_parented_armature_obj, bone_name="E2_BONE_BOTTOM", frame_number=first_keyframe) #bone_animation_local_matrix_b = BlenderArmatureBoneCurrentAnimationDataHelper \ # .get_bone_local_matrix( # armature=blender_parented_armature_obj, bone_name="E2_BONE_BOTTOM", frame_number=second_keyframe) calculated_bone_animation_world_matrix_a = BoneMatrixHelper.get_world_matrix_for_bone( "E2_BONE_BOTTOM", animated_armature_tree_hierarchies[0]) # type: Matrix4x4 calculated_bone_animation_world_matrix_b = BoneMatrixHelper.get_world_matrix_for_bone( "E2_BONE_BOTTOM", animated_armature_tree_hierarchies[1]) # type: Matrix4x4 BlenderArmatureAnimator \ .for_armature(blender_flat_armature_obj, blender_flat_armature_tree_hierarchy) \ .animate_bone( name="E1_BONE_BOTTOM", local_transform=TransformNode.from_matrix4x4(calculated_bone_animation_world_matrix_a), keyframe_number=first_keyframe) \ .animate_bone( name="E1_BONE_BOTTOM", local_transform=TransformNode.from_matrix4x4(calculated_bone_animation_world_matrix_b), keyframe_number=second_keyframe) \ .commit()