Exemplo n.º 1
0
    def split(self):
        # Middle control.
        middle_control_a = self.create_point(self.builder,
                                             "_".join([self.name, "MID_A"]))
        middle_control_b = self.create_point(self.builder,
                                             "_".join([self.name, "MID_B"]))
        # Snap the middle locations to the middle of power line.
        world_pos = copy(self.matrix_world)
        world_loc = world_pos.decompose()[0]
        mid_a_pos = mathutils.Vector([
            world_pos[0][2] * 0.4, world_pos[1][2] * 0.4, world_pos[2][2] * 0.4
        ])
        middle_a_location = world_loc + mid_a_pos
        middle_control_a.location = middle_a_location

        mid_b_pos = mathutils.Vector([
            world_pos[0][2] * 0.6, world_pos[1][2] * 0.6, world_pos[2][2] * 0.6
        ])
        middle_b_location = world_loc + mid_b_pos
        middle_control_b.location = middle_b_location
        # Create new powerline.
        new_powerline = self.builder.add_part(self.object_id, build_rigs=False)
        # Create additional controls.
        prev_start_control_name = self.object["start_control"]
        prev_end_control_name = self.object["end_control"]
        prev_start_control = blend_utils.get_item_by_name(
            prev_start_control_name)
        prev_end_control = blend_utils.get_item_by_name(prev_end_control_name)
        # Remove constraints of the original power line.
        self.remove_constraints()
        # Assign new controls to the power lines.
        self.build_rig(prev_start_control, middle_control_a)
        new_powerline.build_rig(middle_control_b, prev_end_control)
        # Select the middle controller.
        blend_utils.select([middle_control_a, middle_control_b])
Exemplo n.º 2
0
 def divide(self):
     # Middle control.
     middle_control = self.create_point(self.builder,
                                        "_".join([self.name, "MID"]))
     # Snap the middle location to the middle of power line.
     world_pos = copy(self.matrix_world)
     world_loc = world_pos.decompose()[0]
     at_vec = mathutils.Vector(
         [world_pos[0][2] / 2, world_pos[1][2] / 2, world_pos[2][2] / 2])
     middle_location = world_loc + at_vec
     middle_control.location = middle_location
     # Create new powerline.
     new_powerline = self.builder.add_part(self.object_id, build_rigs=False)
     # Create additional controls.
     prev_start_control_name = self.object["start_control"]
     prev_end_control_name = self.object["end_control"]
     prev_start_control = blend_utils.get_item_by_name(
         prev_start_control_name)
     prev_end_control = blend_utils.get_item_by_name(prev_end_control_name)
     # Remove constraints of the original power line.
     self.remove_constraints()
     # Assign new controls to the power lines.
     self.build_rig(prev_start_control, middle_control)
     new_powerline.build_rig(middle_control, prev_end_control)
     # Select the middle controller.
     blend_utils.select(middle_control)
Exemplo n.º 3
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)