import math 
import random 
import bpy 
import bmesh 
tk = bpy.data.texts["bco602tk.py"].as_module()
#tk.mode("OBJECT")
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()

area_box_bound = 300
max_radius = 0.5
def create_bottom_plane():
   
    bpy.ops.mesh.primitive_cube_add(size=1, location=(0, 0, -area_box_bound/2 - max_radius)) #en fazla area + max_radius asagida olabilir
    bpy.ops.transform.resize(value=(area_box_bound*1.5, area_box_bound*1.5, 0.1))
    bpy.context.active_object.name = 'Pivot' # rename
    bpy.ops.rigidbody.object_add()
    bpy.context.object.rigid_body.type = 'PASSIVE'
    bpy.context.object.rigid_body.collision_shape = 'MESH'
    bpy.context.object.rigid_body.mesh_source = 'BASE'
    bpy.context.object.rigid_body.friction = 0.1
    bpy.context.object.rigid_body.restitution = 1 #ziplatma


def detect_collision(a, b): 
    distance = math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2 + (a[2] - b[2]) ** 2) 
    return distance <= a[3] + b[3] 
def create_sphere_list(): 
    sphere_list = [] 
    while len(sphere_list) != 100: 
        x = random.randint(1, 101) 
        y = random.randint(1, 101) 
        z = random.randint(1, 101) 
        r = random.randint(6, 16) 
        is_collision = False 
        for i in sphere_list: 
            if detect_collision(i, (x, y, z, r)): 
                is_collision = True 
                break 
        if not is_collision: 
            sphere_list.append((x, y, z, r)) 
    return sphere_list 
def add_spheres(sphere_list): 
    for sphere in sphere_list: 
        tk.create.sphere("sphere")
        bpy.ops.rigidbody.object_add()
        bpy.context.object.rigid_body.type = 'ACTIVE'
        bpy.context.object.rigid_body.collision_shape = 'SPHERE'

        edit_sphere(bpy.context.object, sphere, convert_billiard_ball) 
   
        
        #bpy.context.object.location = (sphere[0], sphere[1], sphere[2]) 
        #bpy.context.object.scale = (sphere[3], sphere[3], sphere[3]) 
def edit_sphere(object, sphere_data, cb): 
    cb(object, sphere_data) 
     
def convert_billiard_ball(sphere, sphere_data): 
    obj = sphere 
    mesh = obj.data 
    white_color = create_material("white") 
    random_color = create_material("random_color_1", diffuse = (random.random(),random.random(),random.random(),1)) 
    setMaterial(obj, random_color) 
    bpy.ops.object.mode_set(mode='EDIT') 
    tk.act.select_by_loc((-2, -2, -2), (1, 1, -0.5), 'FACE', 'GLOBAL') 
    setMaterial(obj, white_color) 
    obj.active_material_index = 1 
    bpy.ops.object.material_slot_assign() 
    tk.mode("OBJECT") 
    tk.sel.rotate_y(math.radians(180)) 
    bpy.ops.object.mode_set(mode='EDIT') 
    bpy.ops.mesh.select_all(action = "DESELECT") 
    tk.act.select_by_loc((-2, -2, -2), (1, 1, -0.5), 'FACE', 'GLOBAL') 
    setMaterial(obj,random_color) 
    obj.active_material_index = 1 
    bpy.ops.object.material_slot_assign()   
    bpy.ops.object.mode_set(mode='OBJECT')  
     
    obj.location = (sphere_data[0], sphere_data[1], sphere_data[2]) 
    obj.scale = (sphere_data[3], sphere_data[3], sphere_data[3]) 
     
    random_rotation = random.uniform(0, 2 * math.pi) 
    obj.rotation_euler[1] = random_rotation 
    obj.rotation_euler[0] = random_rotation 
     
     
     
def camera(origin, target=None, lens=35, clip_start=0.1, clip_end=200, type='PERSP', ortho_scale=6):
        # Create object and camera
        bpy.ops.object.camera_add(location=origin)        
        obj = bpy.context.object
        obj.data.lens = lens
        obj.data.clip_start = clip_start
        obj.data.clip_end = clip_end
        # 'PERSP', 'ORTHO', 'PANO'
        obj.data.type = type 
        if type == 'ORTHO':
            obj.data.ortho_scale = ortho_scale            
        if target:
            trackToConstraint(obj, target)        
        return obj 
        
def create_material(name, diffuse = (1,1,1,1) , metallic = 0.0, specular = 0.8, roughness = 0.2): 
    mat = bpy.data.materials.new(name) 
    mat.diffuse_color = diffuse 
    mat.specular_intensity = specular 
    mat.metallic = metallic 
    mat.roughness = roughness 
     
    return mat 
def setMaterial(ob, mat): 
     me = ob.data 
     me.materials.append(mat) 
add_spheres(create_sphere_list())
create_bottom_plane()
Can you write a soft boddy version of the same code for blender 3.6 lts version?