import bpy

def fix_seams_and_transfer_data():
    source_name = "Body"
    target_names = ["BodyTop", "bodyBottom", "BodyFeet"]
    
    source_obj = bpy.data.objects.get(source_name)
    if not source_obj:
        print(f"Error: '{source_name}' not found.")
        return

    for t_name in target_names:
        target_obj = bpy.data.objects.get(t_name)
        if not target_obj:
            continue

        # 1. PREP TARGET
        # In 3.6, Auto Smooth must be True to see custom normals
        target_obj.data.use_auto_smooth = True
        bpy.context.view_layer.objects.active = target_obj

        # 2. TRANSFER WEIGHTS & NORMALS (Data Transfer Mod)
        dt_mod = target_obj.modifiers.new(name="SeamFix", type='DATA_TRANSFER')
        dt_mod.object = source_obj
        
        # Vertex Data (Weights)
        dt_mod.use_vert_data = True
        dt_mod.data_types_verts = {'VGROUP_WEIGHTS'}
        
        # Face Corner Data (Normals)
        dt_mod.use_loop_data = True
        dt_mod.data_types_loops = {'CUSTOM_NORMAL'}
        dt_mod.loop_mapping = 'NEAREST_POLYNOR'
        
        # Apply the modifier to bake the data
        bpy.ops.object.modifier_apply(modifier=dt_mod.name)

        # 3. TRANSFER SHAPE KEYS
        if source_obj.data.shape_keys:
            # Clear selection and set up: Source must be Active, Target Selected
            bpy.ops.object.select_all(action='DESELECT')
            target_obj.select_set(True)
            source_obj.select_set(True)
            bpy.context.view_layer.objects.active = source_obj
            
            # Transfer shape keys based on vertex position
            # Note: This creates keys on the Target object
            bpy.ops.object.shape_key_transfer()
            
    print("Process complete for Blender 3.6.")

fix_seams_and_transfer_data()

