Пример #1
0
 def build_rigs(self):
     """Get all items that require a rig and build them."""
     blend_utils.scene_refresh()
     parts = self.get_all_parts(exclude_presets=True)
     for part in parts:
         builder_object = self.get_builder_object_from_bpy_object(part)
         if hasattr(builder_object, "build_rig"):
             builder_object.build_rig()
Пример #2
0
    def optimise_control_points(self):
        """Find all control points that share the same location and combine them."""
        blend_utils.scene_refresh()

        # First build a dictionary of controls that match.
        power_control_objects = [
            obj for obj in bpy.data.objects if "rig_item" in obj
        ]
        power_control_reference = defaultdict(list)
        for power_control in power_control_objects:
            # Create a key that will group the controls based on their location.
            # I am rounding the decimal point to 4 as the accuracy means items
            # in the same location have slightly different values.
            key = ",".join([
                str(round(loc, 3))
                for loc in power_control.matrix_world.decompose()[0]
            ])
            # Append the control to the key.
            power_control_reference[key].append(power_control)

        # Swap any duplicate controls with the first instance.
        for key, value in power_control_reference.items():
            unique_control = value[0]
            other_controls = value[1:]

            if not other_controls:
                continue

            for control in other_controls:
                power_line = blend_utils.get_item_by_name(
                    control["power_line"])
                power_line_obj = self.get_builder_object_from_bpy_object(
                    power_line)
                prev_start_control = bpy.data.objects[
                    power_line_obj.start_control]
                prev_end_control = bpy.data.objects[power_line_obj.end_control]

                # Assign new controls.
                if control == prev_start_control:
                    power_line_obj.build_rig(unique_control, prev_end_control)
                else:
                    power_line_obj.build_rig(prev_start_control,
                                             unique_control)

                # Hide away control.
                blend_utils.remove_object(control.name)