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()
예제 #2
0
    def get_displaced_transforms_for(cls, bones_count: int,
                                     seed: int) -> List[TransformNode]:
        random.seed(seed)
        displaced_coordinates = [
            random.uniform(-1.0, 1.0) for _ in range(bones_count)
        ]
        displaced_scale_coordinates = [
            random.uniform(0.5, 1.2) for _ in range(bones_count)
        ]

        result = []  # type: List[TransformNode]
        home_rotation = Quaternion()

        for index in range(bones_count):
            result.append(
                TransformNode.construct_with(
                    position=Vector3d(displaced_coordinates[index],
                                      displaced_coordinates[index],
                                      displaced_coordinates[index]),
                    rotation=home_rotation,
                    scale=Vector3d(displaced_scale_coordinates[index],
                                   displaced_scale_coordinates[index],
                                   displaced_scale_coordinates[index])))

        return result
    def get_armature_chained_bones_transforms_for(
        cls, bones_count: int) -> List[TransformNode]:

        result = []  # type: List[TransformNode]

        current_position = Vector3d()
        home_rotation = Quaternion()
        home_scale = Vector3d(1.0, 1.0, 1.0)
        for _ in range(bones_count):
            current_position += Vector3d(x=0.0, y=1.0, z=0.0)
            result.append(TransformNode.construct_with(
                position=current_position, rotation=home_rotation, scale=home_scale))
        
        return result