Пример #1
0
    def picked(self, ctx, source, subsource, target, subtarget):
        obj = source[0]
        """ Set Curve pivot same as Object """
        #TODO temprary solution for fix this read the #TODO_01
        set_origen(ctx, target, obj.location)
        bpy.ops.object.select_all(action='DESELECT')
        obj.select_set(state=True)
        ctx.view_layer.objects.active = obj
        """ Make ready for working on """
        self.check_modifier(obj)
        bpy.ops.particle.edited_clear()
        """ Collect data """
        hair = obj.particle_systems.active.particles.data.settings
        hair.count = len(target.data.splines)
        hair.hair_length = self.get_max_lenght(target)
        hair.hair_step = max(
            [len(spline.bezier_points) for spline in target.data.splines])
        """ Make the Brush ready """
        bpy.ops.object.mode_set(mode='PARTICLE_EDIT', toggle=False)
        bpy.ops.wm.tool_set_by_id(name='builtin_brush.Comb')

        version = bpy.app.version
        if version[0] == 2 and version[1] <= 90:
            bpy.ops.particle.brush_edit(stroke=[{
                'name': '',
                'location': (0, 0, 0),
                'mouse': (0, 0),
                'pressure': 0,
                'size': 0,
                'pen_flip': False,
                'time': 0,
                'is_start': True
            }])
        else:
            bpy.ops.particle.brush_edit(stroke=[{
                'name': '',
                'location': (0, 0, 0),
                'mouse': (0, 0),
                'mouse_event': (0, 0),
                'pressure': 0,
                'size': 0,
                'pen_flip': False,
                'x_tilt': 0,
                'y_tilt': 0,
                'time': 0,
                'is_start': False
            }])

        bpy.ops.particle.disconnect_hair()
        depsgraph = ctx.evaluated_depsgraph_get()
        obj = obj.evaluated_get(depsgraph)
        """ Comb The Hair """
        for i in range(hair.count):
            self.comb_the_hair(obj.particle_systems.active.particles[i],
                               target, i)
        """ Commit Brush """
        bpy.ops.particle.connect_hair()
        bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
        self.report({'OPERATOR'}, 'bpy.ops.particle.hair_guides_from_curve()')
Пример #2
0
def create_joystic(ctx, frame, mode):
    width = frame.data.primitivedata.width
    length = frame.data.primitivedata.length
    orient = get_joystic_mode(width, length)
    radius = get_joy_radius(width, length, orient)
    frame.data.primitivedata.chamfer1 = radius

    if mode in [1, 4, 7]:
        x_offset = width / 2 - radius
    elif mode in [3, 6, 9]:
        x_offset = -(width / 2 - radius)
    else:
        x_offset = 0
    if mode in [1, 2, 3]:
        y_offset = -(length / 2 - radius)
    elif mode in [7, 8, 9]:
        y_offset = length / 2 - radius
    else:
        y_offset = 0

    location = frame.location - Vector((x_offset, 0, y_offset))
    set_origen(ctx, frame, location)

    bpy.ops.object.empty_add(type='CIRCLE', location=(0, 0, 0))
    joy = ctx.active_object
    joy.empty_display_size = radius
    joy.scale = frame.scale
    joy.parent = frame
    joy.rotation_quaternion = frame.rotation_quaternion
    joy.delta_rotation_euler = Vector(joy.delta_rotation_euler) + Vector(
        (1.5708, 0, 0))
    #joy.rotation_euler = Vector(joy.rotation_euler) + Vector((1.5708,0,0))

    cons = joy.constraints.new('LIMIT_LOCATION')
    cons.use_transform_limit = True
    cons.owner_space = 'LOCAL'

    cons.use_min_x = True
    cons.use_max_x = True
    cons.use_min_y = True
    cons.use_max_y = True
    cons.use_min_z = True
    cons.use_max_z = True

    if orient in ['j', 'h']:
        cons.min_x = -(width / 2 - radius) + x_offset
        cons.max_x = width / 2 - radius + x_offset
    if orient in ['j', 'v']:
        cons.min_y = -(length / 2 - radius) + y_offset
        cons.max_y = length / 2 - radius + y_offset
Пример #3
0
 def pivot_to_buttom_center(self, ctx, obj):
     """ TODO bound_box return value in local coordinate """
     """ need a fast method to get bound box in world space """
     b = [obj.matrix_world @ Vector(v) for v in obj.bound_box]
     min_x = min(b[0][0], b[1][0], b[2][0], b[3][0], b[4][0], b[5][0],
                 b[6][0])
     max_x = max(b[0][0], b[1][0], b[2][0], b[3][0], b[4][0], b[5][0],
                 b[6][0])
     min_y = min(b[0][1], b[1][1], b[2][1], b[3][1], b[4][1], b[5][1],
                 b[6][1])
     max_y = max(b[0][1], b[1][1], b[2][1], b[3][1], b[4][1], b[5][1],
                 b[6][1])
     min_z = min(b[0][2], b[1][2], b[2][2], b[3][2], b[4][2], b[5][2],
                 b[6][2])
     center_x = (min_x + max_x) / 2
     center_y = (min_y + max_y) / 2
     location = Vector((center_x, center_y, min_z))
     set_origen(ctx, obj, location)
Пример #4
0
def create_joystic(ctx, rectangle, mode):
    width = rectangle.data.primitivedata.width
    length = rectangle.data.primitivedata.length
    orient = get_joystic_mode(width, length)
    radius = get_joy_radius(width, length, orient)
    rectangle.data.primitivedata.chamfer1 = radius

    if mode in [1, 4, 7]:
        x_offset = width / 2 - radius
    elif mode in [3, 6, 9]:
        x_offset = -(width / 2 - radius)
    else:
        x_offset = 0
    if mode in [1, 2, 3]:
        y_offset = -(length / 2 - radius)
    elif mode in [7, 8, 9]:
        y_offset = length / 2 - radius
    else:
        y_offset = 0

    location = rectangle.location - Vector((x_offset, 0, y_offset))
    set_origen(ctx, rectangle, location)
    """ fix orient """
    bpy.ops.transform.rotate(value=-1.5708,
                             orient_axis='X',
                             orient_type='LOCAL',
                             orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)),
                             orient_matrix_type='LOCAL',
                             constraint_axis=(True, False, False),
                             mirror=True,
                             use_proportional_edit=False,
                             proportional_edit_falloff='SMOOTH',
                             proportional_size=1,
                             use_proportional_connected=False,
                             use_proportional_projected=False,
                             release_confirm=True)
    """ convert the frame to mesh """
    bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
    bpy.ops.object.select_all(action='DESELECT')
    rectangle.data.resolution_u = 8
    rectangle.select_set(state=True)
    bpy.ops.object.convert(target='MESH')
    """  """
    bpy.ops.mesh.primitive_circle_add(radius=radius, vertices=16)
    circle = ctx.active_object
    bpy.ops.object.mode_set(mode='EDIT', toggle=False)
    bpy.ops.mesh.select_all(action='SELECT')
    bpy.ops.mesh.edge_face_add()
    bpy.ops.object.mode_set(mode='OBJECT', toggle=False)

    bpy.ops.object.armature_add(location=(0, 0, 0))
    joystick = ctx.active_object
    joystick.name = "Joystick"
    bpy.ops.object.mode_set(mode='EDIT', toggle=False)
    bpy.ops.armature.select_all(action='SELECT')
    bpy.ops.armature.duplicate('INVOKE_DEFAULT')
    bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
    joystick.location = location
    frame = joystick.data.bones[0]
    joy = joystick.data.bones[1]
    frame.name, joy.name = "Frame", "Joy"
    """ disable for diformation """
    frame.use_deform = False
    joy.use_deform = False
    """ Set Transform """
    joystick.scale = rectangle.scale
    joystick.rotation_euler.x = rectangle.rotation_euler.x
    joystick.rotation_euler.y = rectangle.rotation_euler.y
    joystick.rotation_euler.z = rectangle.rotation_euler.z
    """ Set Parent """
    bpy.ops.object.mode_set(mode='EDIT', toggle=False)
    joystick.data.edit_bones['Joy'].parent = joystick.data.edit_bones['Frame']
    """ setup constraints """
    bpy.ops.object.mode_set(mode='POSE', toggle=False)
    frame = joystick.pose.bones['Frame']
    joy = joystick.pose.bones['Joy']

    cons = joy.constraints.new('LIMIT_LOCATION')
    cons.use_transform_limit = True
    cons.owner_space = 'LOCAL'

    cons.use_min_x = cons.use_max_x = True
    cons.use_min_y = cons.use_max_y = True
    cons.use_min_z = cons.use_max_z = True

    if orient in ['j', 'h']:
        cons.min_x = -(width / 2 - radius) + x_offset
        cons.max_x = width / 2 - radius + x_offset
    if orient in ['j', 'v']:
        cons.min_y = -(length / 2 - radius) + y_offset
        cons.max_y = length / 2 - radius + y_offset
    """ Setup Display """
    frame.custom_shape = rectangle
    joy.custom_shape = circle
    """ Clear Scene """
    bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
    objs = [rectangle, circle]
    bpy.ops.object.delete({"selected_objects": objs})