コード例 #1
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 construct_with(position: Vector3d, rotation: Quaternion,
                    scale: Vector3d) -> 'TransformNode':
     result = TransformNode()
     result.position = position.copy()
     result.rotation = rotation.copy()
     result.scale = scale.copy()
     return result
 def lerp(transform_a: 'TransformNode', transform_b: 'TransformNode',
          interpolation: float) -> 'TransformNode':
     result = TransformNode()
     result.position = Vector3d.lerp(transform_a.position,
                                     transform_b.position, interpolation)
     result.rotation = Quaternion.lerp(transform_a.rotation,
                                       transform_b.rotation, interpolation)
     result.scale = Vector3d.lerp(transform_a.scale, transform_b.scale,
                                  interpolation)
     return result
    def get_head_and_tail_position_from(
            cls, transform_node: TransformNode) -> Tuple[Vector3d, Vector3d]:
        # screw the bone's orientation, who cares at the moment? :P just put something in here, we will worry later

        head_position = transform_node.position + Vector3d(
            x=0.1, y=0.0, z=0.0)  # type: Vector3d
        tail_position = transform_node.position + Vector3d(
            x=-0.1, y=0.0, z=0.0)  # type: Vector3d

        return head_position, tail_position
    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 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
コード例 #7
0
    def get_quaternion_rotate_angle_axis(
            cls, angle_radians: float,
            rotation_axis_arg: Vector3d) -> Quaternion:
        rotation_axis = rotation_axis_arg.normalized()

        qx = rotation_axis.x * math.sin(angle_radians / 2.0)
        qy = rotation_axis.y * math.sin(angle_radians / 2.0)
        qz = rotation_axis.z * math.sin(angle_radians / 2.0)
        qw = math.cos(angle_radians / 2.0)
        return Quaternion(w=qw, x=qx, y=qy, z=qz).normalized()
    def zero_out_not_used_subobjects_bones_transformations_adding_them_to_pose_hierarchy(
            cls, pose_hierarchy: TreeHierarchy,
            all_actual_armature_bones_names: List[str]):
        for armature_bone_name in all_actual_armature_bones_names:
            if not pose_hierarchy.contains_node_key(armature_bone_name):
                effectively_zeroed_scale_out_transform_node = TransformNode()
                effectively_zeroed_scale_out_transform_node.scale = Vector3d(
                    0.0, 0.0, 0.0)

                pose_hierarchy.add_node(
                    parent_key=UnifiedArmatureWithDeformSetsBonesNamingHelper.
                    get_bone_name_for_root_channel(),
                    node_key=armature_bone_name,
                    node=BoneTransformNode.from_transform_node(
                        bone_name=armature_bone_name,
                        transform_node=
                        effectively_zeroed_scale_out_transform_node,
                        is_keyframe=True))
 def construct_from_json_dict(self, vector3d_json_dict) -> Vector3d:
     result = Vector3d()
     result.x = vector3d_json_dict["x"]
     result.y = vector3d_json_dict["y"]
     result.z = vector3d_json_dict["z"]
     return result
 def __init__(self):
     self.position = Vector3d()
     self.rotation = Quaternion()
     self.scale = Vector3d(1.0, 1.0, 1.0)
 def __init__(self):
     self.bone_name = None  # type: str
     self.head_position = Vector3d()
     self.tail_position = Vector3d()
コード例 #12
0
 def decompose(self) -> Tuple[Vector3d, Quaternion, Vector3d]:
     bl_position, bl_rotation, bl_scale = self.to_blender_matrix(
     ).decompose()
     return Vector3d.from_blender_vector(bl_position), \
         Quaternion.from_blender_quaternion(bl_rotation), Vector3d.from_blender_vector(bl_scale)