Exemple #1
0
    def setup_pose_keyframe_in_animation_clip(
            cls, pose_armature_hierarchy: TreeHierarchy,
            blender_armature_obj: Object):
        blender_objects_manipulator = BlenderObjectsManipulator()

        # we have a problem here that PoseBones' collection size does not match actual
        # armature bones' collection size - probably we might need to select all bones of armature
        # explicitly at first when going to Pose Mode - maybe that could help - to investigate

        blender_objects_manipulator.select_all_pose_objects()
        for animation_frame_bone_transform_node_iter in pose_armature_hierarchy.iterate_nodes(
        ):
            # setup only keyframed bones actually in particular frame number,
            # don't care 'bout the rest, as it should be
            if animation_frame_bone_transform_node_iter.node.is_keyframe:
                BlenderArmatureBonePoseSetterFacade.transform_bone_in_animation_frame(
                    blender_armature_obj,
                    animation_frame_bone_transform_node_iter.node)

                # in pose mode select only the bone currently being transformed and lock its rotation, scale and position (LocRotScale)

                blender_objects_manipulator.deselect_all_pose_objects()
                BlenderArmatureBonePoseSetterFacade.select_pose_bone(
                    animation_frame_bone_transform_node_iter.node.bone_name,
                    blender_armature_obj)

                # raise NotImplementedError
                BlenderArmatureBonePoseSetterFacade.lock_rotation_scale_position(
                )
                blender_objects_manipulator.deselect_all_pose_objects()
Exemple #2
0
    def parent_blender_object_to_armature_with_bones_vertex_groups(
        cls,
        armature_obj: Object,
        blender_mesh_obj: Object,
        bones_vertex_groups: Dict[str, Dict[int, float]],
    ):
        blender_objects_manipulator = BlenderObjectsManipulator()
        blender_objects_manipulator.parent_object_to(child=blender_mesh_obj,
                                                     parent=armature_obj)

        for vertex_group_name in bones_vertex_groups:
            vertex_group = bones_vertex_groups[vertex_group_name]
            blender_vertex_group = blender_mesh_obj.vertex_groups.new(
                name=vertex_group_name)  # type: VertexGroup
            for vertex_in_group_index in vertex_group:
                vertex_in_group_weight = vertex_group[vertex_in_group_index]
                blender_vertex_group.add(index=[vertex_in_group_index],
                                         weight=vertex_in_group_weight,
                                         type='ADD')

        cls._add_armature_modifier(armature_obj, blender_mesh_obj)
Exemple #3
0
 def enter_edit_mode_for_object_as_active_from_object_mode(
         self, object: Object):
     blender_objects_manipulator = BlenderObjectsManipulator()
     # blender_objects_manipulator.deselect_all_objects()
     blender_objects_manipulator.set_active_object_to(object)
     blender_objects_manipulator.select_active_object(object)
     self.enter_edit_mode()
    def commit(self) -> List[TreeHierarchy]:
        result_keyframes_local_bone_transforms_tree_hierarchies = []  # type: List[TreeHierarchy]
        blender_editor_manipulator = BlenderEditorManipulator()
        blender_objects_manipulator = BlenderObjectsManipulator()
        blender_editor_manipulator.enter_pose_mode_for_object_as_active_from_object_mode(self.blender_armature_obj)
        for keyframe_number in self.bones_keyframes:
            current_pose_hierarchy = \
                TreeHierarchyBonesPoseLocalTransformsConstructionHelper.construct_bones_keyframes_transforms_tree_hierarchy_for(
                    self.bones_keyframes[keyframe_number],
                    self.armature_hierarchy
                )

            blender_editor_manipulator.enter_frame_number(frame_number=keyframe_number)

            BlenderArmaturePoseApplier.setup_pose_keyframe_in_animation_clip(
                current_pose_hierarchy,
                self.blender_armature_obj
            )

            result_keyframes_local_bone_transforms_tree_hierarchies.append(current_pose_hierarchy)

        blender_editor_manipulator.enter_object_mode()
        return result_keyframes_local_bone_transforms_tree_hierarchies
Exemple #5
0
 def create_armature(self, name: str) -> Tuple[Armature, Object]:
     blender_objects_manipulator = BlenderObjectsManipulator()
     armature = bpy.data.armatures.new(name=name)
     armature_obj = blender_objects_manipulator.create_new_object_with_linked_datablock(
         object_name=name + "_OBJECT", data_block=armature
     )
     blender_objects_manipulator.link_object_to_the_scene(armature_obj)
     blender_objects_manipulator.deselect_all_objects()
     blender_objects_manipulator.set_active_object_to(armature_obj)
     blender_objects_manipulator.select_active_object(armature_obj)
     return armature, armature_obj
Exemple #6
0
    def create_from_subobject_desc(cls, visual_data: VisualData,
                                   visual_data_holder: VisualDataHolder,
                                   subobject_number: int,
                                   subobject: Subobject) -> Object:
        blender_objects_manipulator = BlenderObjectsManipulator()

        subobject_core_name = SubobjectsRelatedDataNamingHelper.get_subobject_name(
            subobject_number)  # type: str

        mesh_data_block = bpy.data.meshes.new(
            name=subobject_core_name)  # type: Mesh
        mesh_object = blender_objects_manipulator.create_new_object_with_linked_datablock(
            object_name="OBJECT_" + subobject_core_name,
            data_block=mesh_data_block)  # type: Object
        blender_objects_manipulator.link_object_to_the_scene(mesh_object)

        blender_objects_manipulator.deselect_all_objects()
        blender_objects_manipulator.set_active_object_to(mesh_object)
        blender_objects_manipulator.select_active_object(mesh_object)

        mesh_geometry = subobject.geometric_object  # type: GeometricObject
        vertices, edges, faces = BlenderMeshGeometryFactory.get_from_geometric_object(
            mesh_geometry)

        mesh_object.data.from_pydata(vertices, edges, faces)
        cls._apply_normals(subobject, mesh_object)
        cls._apply_mesh_materials(visual_data=visual_data,
                                  visual_data_holder=visual_data_holder,
                                  subobject=subobject,
                                  mesh_object=mesh_object)
        return mesh_object