import math, os, sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import bpy
import bmesh
from mathutils import Vector
import v4lib as v4

v4.reset()

# Materials carry over the polished, classic kitchen-tool finish.
chrome = v4.metal("polished_nickel", color=(0.77, 0.81, 0.84), roughness=0.19, brushed=False)
satin = v4.metal("satin_cast_zinc", color=(0.48, 0.54, 0.58), roughness=0.31, brushed=True)
edge = v4.metal("darkened_steel", color=(0.20, 0.24, 0.26), roughness=0.32, brushed=False)
wood = v4.wood("turned_beech", light=(0.72, 0.50, 0.29), dark=(0.43, 0.26, 0.13), grain_scale=7)
black = v4.plastic("black_phenolic", (0.055, 0.065, 0.07), roughness=0.25, texture=0.04)
brass = v4.metal("warm_bevel_gear_bronze", color=(0.62, 0.39, 0.16), roughness=0.27, brushed=True)

# Compact, clean round profiles keep the detailed product efficient to check.
def cyl(*args, **kwargs):
    kwargs.setdefault("segments", 48)
    return v4.cylinder(*args, **kwargs)

def tube(*args, **kwargs):
    kwargs.setdefault("resolution", 12)
    return v4.tube(*args, **kwargs)

def ring(*args, **kwargs):
    kwargs.setdefault("segments", 48)
    kwargs.setdefault("ring_segments", 12)
    return v4.torus(*args, **kwargs)

# Upright tool: a 70 mm vertical drive wheel with two vertical output shafts.
WHEEL_Z = 0.300
WHEEL_Y = 0.0
WHEEL_R = 0.035
PINION_R = 0.0085
PIN_X = 0.026  # Preserve the accepted shaft and joint centers.
PIN_Y = -0.012
PIN_Z = WHEEL_Z - 0.024
BEARING_Z = PIN_Z - 0.013
BEATER_BOTTOM = 0.075
BEATER_TOP = 0.150

frame = v4.body("frame")
crank = v4.body("crank")
left = v4.body("beater_left")
right = v4.body("beater_right")

# ---- cast strap frame, centred over the beaters ------------------------------------
# A rounded stamped yoke follows the wheel perimeter, then forks into two shaft
# bushings. Its open center leaves the crown wheel and mesh visible from the back.
def strap_frame(name, path, width=0.006, depth=0.003):
    verts=[]; faces=[]; half=width/2
    # Path is a polyline in XZ. Offset it in its local normal to make a flat band.
    edges=[]
    for i,(x,z) in enumerate(path):
        prev=Vector(path[max(i-1,0)]); nxt=Vector(path[min(i+1,len(path)-1)])
        tangent=(nxt-prev).normalized()
        normal=Vector((-tangent.y,tangent.x))
        edges.append(((x+normal.x*half,z+normal.y*half),
                      (x-normal.x*half,z-normal.y*half)))
    n=len(path); y0=0.014-depth/2; y1=0.014+depth/2
    for y in (y0,y1):
        for outer,inner in edges:
            verts.extend(((outer[0],y,outer[1]),(inner[0],y,inner[1])))
    # Faces on each side plus perimeter walls; close the strap ends.
    for i in range(n-1):
        a=2*i; b=a+1; c=2*(i+1); d=c+1
        faces.extend(((a,c,d,b),(2*n+a,2*n+b,2*n+d,2*n+c),
                      (a,2*n+a,2*n+c,c),(b,d,2*n+d,2*n+b)))
    faces.extend(((0,1,2*n+1,2*n),(2*n-2,4*n-2,4*n-1,2*n-1)))
    mesh=bpy.data.meshes.new(name+"_mesh"); mesh.from_pydata(verts,[],faces); mesh.update()
    obj=bpy.data.objects.new(name,mesh); bpy.context.scene.collection.children.get("Asset").objects.link(obj)
    v4.part(obj,frame)
    bevel=obj.modifiers.new("soft_stamped_edges","BEVEL"); bevel.width=0.0008; bevel.segments=2
    return obj

arc=[]
for i in range(41):
    a=-2.30+4.60*i/40
    arc.append((0.042*math.sin(a),WHEEL_Z+0.042*math.cos(a)))
strap_frame("cast_crown_yoke",arc,width=0.010,depth=0.006)
# A slim center rib backs the axle boss and provides a real attachment for the
# opposite-side palm grip; the perimeter stays open around the wheel.
strap_frame("axle_backstrap",[(0,0.278),(0,0.348)],width=0.015,depth=0.006)
# The arch ends meet two small bearing ears directly above the pinions.
for side,x in (("left",-PIN_X),("right",PIN_X)):
    # Start each fork 5 mm inside the arc, then taper into the bearing boss.
    strap_frame(side+"_fork_strap",[(math.copysign(0.042*math.sin(2.02),x),
                                    WHEEL_Z+0.042*math.cos(2.02)),(x,BEARING_Z)],width=0.012,depth=0.006)

def annular_sleeve(name,x,y,z,height=0.028,outer=0.0055,inner=0.0048):
    count=32; z0=z-height/2; z1=z+height/2; verts=[]; faces=[]
    for zz,rr in ((z0,outer),(z0,inner),(z1,outer),(z1,inner)):
        for i in range(count):
            a=2*math.pi*i/count; verts.append((x+rr*math.cos(a),y+rr*math.sin(a),zz))
    for i in range(count):
        j=(i+1)%count
        faces.extend(((i,j,2*count+j,2*count+i),
                      (count+i,3*count+i,3*count+j,count+j),
                      (2*count+i,2*count+j,3*count+j,3*count+i),
                      (i,count+i,count+j,j)))
    mesh=bpy.data.meshes.new(name+"_mesh"); mesh.from_pydata(verts,[],faces); mesh.materials.append(chrome); mesh.update()
    obj=bpy.data.objects.new(name,mesh); bpy.context.scene.collection.children.get("Asset").objects.link(obj)
    v4.part(obj,frame)
    return obj

# Recessed short sockets grip each shaft below the bevel pinions.
for side,x in (("left",-PIN_X),("right",PIN_X)):
    # Solid boss is fused into the cast frame first; its shaft bore is cut after
    # the frame remesh so the bearing remains connected and has true clearance.
    cyl(side+"_beater_bearing_sleeve",0.0055,0.012,(x,PIN_Y,BEARING_Z),
            bevel=0.0004,material=chrome,body=frame)
    # Twin side webs reach around the sleeve's outer wall while leaving its bore open.
    outward=math.copysign(0.0080,x)
    v4.rod(side+"_bearing_web",(x+outward,0.022,BEARING_Z),(x+outward,PIN_Y,BEARING_Z),
           0.0040,material=satin,body=frame)
# Axle bearing is a real ring around the horizontal input shaft, joined to the spine.
ring("drive_axle_bearing", 0.0064, 0.0020, loc=(0, 0.014, WHEEL_Z),
         rot=(math.pi/2, 0, 0), material=chrome, body=frame)
# Narrow fork shoulders above the wheel form the yoke and lead into the grip ferrule.
v4.rod("yoke_left_cheek", (-0.010,0.014,WHEEL_Z+0.006), (-0.010,0.014,0.344),
       0.0020, material=chrome, body=frame)
v4.rod("yoke_right_cheek", (0.010,0.014,WHEEL_Z+0.006), (0.010,0.014,0.344),
       0.0020, material=chrome, body=frame)
v4.rod("yoke_top_crossbar", (-0.010,0.014,0.344), (0.010,0.014,0.344),
       0.0020, material=chrome, body=frame)
# Opposite-side fixed palm grip balances the crank and gives the classic two-hand hold.
cyl("opposite_grip_stem",0.0040,0.030,(0,0.029,WHEEL_Z+0.015),
            rot=(math.pi/2,0,0),bevel=0.0006,material=chrome,body=frame)
v4.lathe("opposite_frame_grip",[(0,0),(0.006,0),(0.009,0.003),(0.010,0.009),
                                  (0.009,0.017),(0.006,0.021),(0,0.021)],
         loc=(0,0.043,WHEEL_Z+0.015),rot=(math.pi/2,0,0),material=black,body=frame)
# Top handle is directly in line with the twin beater shafts.
cyl("handle_ferrule", 0.0105, 0.010, (0,0.014,0.347), bevel=0.001, material=chrome, body=frame)
v4.lathe("wood_handle_grip", [(0,0),(0.008,0),(0.010,0.004),(0.011,0.012),
                               (0.0105,0.022),(0.011,0.035),(0.009,0.047),(0,0.047)],
         loc=(0,0.014,0.351), material=wood, body=frame)
ring("handle_grip_lower_ring", 0.0095, 0.0008, loc=(0,0.014,0.358), material=chrome, body=frame)
ring("handle_grip_upper_ring", 0.0088, 0.0007, loc=(0,0.014,0.394), material=chrome, body=frame)
# Fuse the fixed yoke, bearing, ferrule, grip, and small frame details into one
# watertight frame shell. Region-based materials retain the wood hand grip.
frame_parts=[]
for obj in list(v4.asset_objects()):
    p=obj.parent
    owner=None
    while p is not None:
        if p.get("v4_kind")=="body": owner=p; break
        p=p.parent
    if owner==frame:
        if obj.type!="MESH":
            bpy.ops.object.select_all(action="DESELECT")
            obj.select_set(True); bpy.context.view_layer.objects.active=obj
            bpy.ops.object.convert(target="MESH")
            obj=bpy.context.object
        frame_parts.append(obj)
bpy.ops.object.select_all(action="DESELECT")
for obj in frame_parts: obj.select_set(True)
frame_shell=bpy.data.objects["cast_crown_yoke"]
bpy.context.view_layer.objects.active=frame_shell
bpy.ops.object.join()
frame_shell.name="upright_frame_shell"
rem=frame_shell.modifiers.new("fused_frame_shell","REMESH")
rem.mode="VOXEL"; rem.voxel_size=0.0025; rem.use_smooth_shade=True
bpy.context.view_layer.objects.active=frame_shell
bpy.ops.object.modifier_apply(modifier=rem.name)
frame_shell.data.materials.clear()
for material in (satin,chrome,wood): frame_shell.data.materials.append(material)
for poly in frame_shell.data.polygons:
    center=sum((frame_shell.matrix_world @ frame_shell.data.vertices[i].co for i in poly.vertices), start=Vector((0,0,0)))/len(poly.vertices)
    if center.z >= 0.355 and center.z < 0.401: poly.material_index=2
    elif 0.340 <= center.z < 0.355: poly.material_index=1
    else: poly.material_index=0
# Bored bearing passage through the fused yoke around the rotating horizontal axle.
shaft_bore=cyl("frame_axle_bore_tool",0.0050,0.060,(0,0.014,WHEEL_Z),
                        rot=(math.pi/2,0,0),bevel=0)
v4.boolean(frame_shell,shaft_bore)
# Two small punched lightening holes in the exposed shoulders of the cast arch.
for side,x in (("left",-0.028),("right",0.028)):
    punch=cyl(side+"_frame_lightening_punch",0.0021,0.030,
                      (x,0.014,0.332),rot=(math.pi/2,0,0),bevel=0)
    v4.boolean(frame_shell,punch)
# Precision bores leave a running clearance around both rotating output shafts.
for side,x in (("left",-PIN_X),("right",PIN_X)):
    bore=cyl(side+"_bearing_bore_tool",0.0044,0.030,(x,PIN_Y,BEARING_Z),bevel=0)
    v4.boolean(frame_shell,bore)

# ---- main wheel and pinion geometry --------------------------------------------------
def tooth_outline_2d(cx, cy, radius_root, radius_tip, teeth, phase=0.0):
    pts=[]
    step=2*math.pi/teeth
    for i in range(teeth):
        a=phase+i*step
        for off,r in ((-0.50,radius_root),(-0.30,radius_root),(-0.20,radius_tip),
                      (-0.04,radius_tip),(0.04,radius_tip),(0.20,radius_tip),
                      (0.30,radius_root),(0.50,radius_root)):
            ang=a+off*step
            pts.append((cx+r*math.cos(ang),cy+r*math.sin(ang)))
    return pts

def vertical_crown_wheel(name, center_z, body, teeth=32, root=0.031, tip=0.037, thick=0.010):
    # A true crown-style wheel: tooth tips flare forward and each tooth is slightly
    # skewed through the face thickness toward the two vertical-shaft pinions.
    n=teeth*8; verts=[]; faces=[]
    for yy,root_y,tip_y,phase in ((-thick/2,root,tip,0.028),(thick/2,root-0.002,tip-0.004,0.0)):
        outline=tooth_outline_2d(0,center_z,root_y,tip_y,teeth,phase=phase)
        verts.extend([(x,yy,z) for x,z in outline])
    faces.append(tuple(range(n-1,-1,-1)))
    faces.append(tuple(range(n,2*n)))
    for j in range(n):
        k=(j+1)%n
        faces.append((j,k,n+k,n+j))
    mesh=bpy.data.meshes.new(name+"_mesh")
    mesh.from_pydata(verts,[],faces); mesh.materials.append(chrome); mesh.update()
    bm=bmesh.new(); bm.from_mesh(mesh); bmesh.ops.recalc_face_normals(bm,faces=bm.faces); bm.to_mesh(mesh); bm.free()
    obj=bpy.data.objects.new(name,mesh)
    bpy.context.scene.collection.children.get("Asset").objects.link(obj)
    v4.part(obj,body)
    # The smooth root disk and raised radial ribs give the large wheel a classic spoked face.
    cyl(name+"_root_disk", root*0.985, thick*0.72, (0,0,center_z),
                rot=(math.pi/2,0,0), bevel=0.0006, material=satin, body=body)
    for i in range(6):
        a=2*math.pi*i/6
        p0=(0.006*math.cos(a),-thick*0.48,center_z+0.006*math.sin(a))
        p1=(0.027*math.cos(a),-thick*0.48,center_z+0.027*math.sin(a))
        v4.rod(name+"_spoke_%d"%i,p0,p1,0.0018,material=chrome,body=body)
    # Hub and axle are integral to the wheel body.
    cyl(name+"_hub",0.008,0.018,(0,-0.004,center_z),rot=(math.pi/2,0,0),
                bevel=0.0007,material=edge,body=body)
    ring(name+"_hub_cap_seam",0.0062,0.0007,loc=(0,-0.0135,center_z),
             rot=(math.pi/2,0,0),material=chrome,body=body)
    return obj

def spur_gear(name, center, z, body, teeth=16, root=0.0067, tip=0.0085, thick=0.006, bevel=False):
    outline=tooth_outline_2d(center[0],center[1],root,tip,teeth)
    n=len(outline); verts=[]; faces=[]
    for layer,zz in enumerate((z-thick/2,z+thick/2)):
        taper = (0.68 if layer == 1 else 1.0) if bevel else 1.0
        verts.extend([(center[0]+(x-center[0])*taper,
                       center[1]+(y-center[1])*taper,zz) for x,y in outline])
    faces.extend((tuple(range(n-1,-1,-1)),tuple(range(n,2*n))))
    for j in range(n):
        k=(j+1)%n; faces.append((j,k,n+k,n+j))
    mesh=bpy.data.meshes.new(name+"_mesh")
    mesh.from_pydata(verts,[],faces); mesh.materials.append(chrome); mesh.update()
    bm=bmesh.new(); bm.from_mesh(mesh); bmesh.ops.recalc_face_normals(bm,faces=bm.faces); bm.to_mesh(mesh); bm.free()
    obj=bpy.data.objects.new(name,mesh)
    bpy.context.scene.collection.children.get("Asset").objects.link(obj)
    v4.part(obj,body)
    if bevel:
        cyl(name+"_bevel_cone",0.0065,thick*0.88,(center[0],center[1],z-thick*0.06),
                radius_top=0.0038,bevel=0.00035,material=satin,body=body)
    cyl(name+"_hub",0.0042,thick+0.001,(center[0],center[1],z),
                bevel=0.0005,material=satin,body=body)
    cyl(name+"_index_pin",0.0013,0.001,
                (center[0]+0.0052,center[1],z+thick/2+0.0004),
                bevel=0.0002,material=edge,body=body)
    return obj

vertical_crown_wheel("crown_drive_wheel",WHEEL_Z,crank)
# Horizontal-axis input axle; its exposed end carries the side-mounted crank arm.
cyl("drive_axle",0.0040,0.053,(0,-0.004,WHEEL_Z),rot=(math.pi/2,0,0),
            bevel=0.0004,material=chrome,body=crank)
cyl("outer_axle_cap",0.0062,0.004,(0,-0.029,WHEEL_Z),rot=(math.pi/2,0,0),
            bevel=0.0005,material=satin,body=crank)
# Crank sweeps in the vertical XZ plane, outside the wheel face.
CRANK_RADIUS=0.050
crank_path=[(0,-0.031,WHEEL_Z),(0.003,-0.031,WHEEL_Z-0.012),
            (0.0045,-0.031,WHEEL_Z-0.030),(0.002,-0.031,WHEEL_Z-0.043),
            (0,-0.031,WHEEL_Z-CRANK_RADIUS)]
tube("curved_crank_arm",crank_path,0.0034,material=chrome,body=crank)
cyl("crank_arm_end",0.005,0.004,(0,-0.031,WHEEL_Z-CRANK_RADIUS),
            rot=(math.pi/2,0,0),bevel=0.0005,material=edge,body=crank)
cyl("crank_spinner_pin",0.003,0.024,(0,-0.043,WHEEL_Z-CRANK_RADIUS),
            rot=(math.pi/2,0,0),bevel=0.0004,material=chrome,body=crank)
v4.lathe("crank_palm_knob",[(0,0),(0.006,0),(0.008,0.003),(0.0085,0.010),
                              (0.0075,0.019),(0.0045,0.025),(0,0.025)],
         loc=(0,-0.050,WHEEL_Z-CRANK_RADIUS),rot=(math.pi/2,0,0),material=black,body=crank)
ring("crank_knob_trim",0.0078,0.0006,loc=(0,-0.053,WHEEL_Z-CRANK_RADIUS),
         rot=(math.pi/2,0,0),material=chrome,body=crank)

# Bevel-style pinions sit at the lower flanks of the crown wheel and terminate the vertical shafts.
left_pin=( -PIN_X, PIN_Y )
right_pin=( PIN_X, PIN_Y )
spur_gear("left_beater_pinion",left_pin,PIN_Z,left,teeth=16,bevel=True)
spur_gear("right_beater_pinion",right_pin,PIN_Z,right,teeth=16,bevel=True)

def oval_loop(cx,cy0,z_top,z_bottom,plane,body,label,radius=0.021):
    pts=[]; mid=(z_top+z_bottom)/2; half=(z_top-z_bottom)/2
    for j in range(48):
        a=2*math.pi*j/48
        rad=radius*(0.72+0.28*math.cos(a))
        if plane=="xz": pts.append((cx+rad*math.sin(a),cy0,mid+half*math.cos(a)))
        else: pts.append((cx,cy0+rad*math.sin(a),mid+half*math.cos(a)))
    tube(label,pts,0.0012,material=chrome,body=body,cyclic=True)

def dasher_wire(name, x, y, body, angle):
    # Bent stainless loop rib: it grows from the spindle, bows to a 53 mm
    # sweep envelope, twists gently, then returns to the bottom hub.
    pts=[]; radius=0.0265
    for i in range(25):
        t=i/24
        z=BEATER_BOTTOM+(BEATER_TOP-BEATER_BOTTOM)*t
        r=radius*math.sin(math.pi*t)**0.72
        twist=0.11*math.sin(2*math.pi*t+angle)
        a=angle+twist
        pts.append((x+r*math.cos(a),y+r*math.sin(a),z))
    tube(name,pts,0.00115,material=chrome,body=body,resolution=16)

for side,x,body in (("left",-PIN_X,left),("right",PIN_X,right)):
    # Raise the dasher heads to shorten the exposed shafts by about 35 percent.
    shaft_len=PIN_Z-BEATER_TOP
    shaft_mid=(PIN_Z+BEATER_TOP)/2
    cyl(side+"_beater_shaft",0.0031,shaft_len,(x,PIN_Y,shaft_mid),
                bevel=0.00035,material=chrome,body=body)
    cyl(side+"_shaft_collar",0.0058,0.006,(x,PIN_Y,BEATER_TOP+0.001),
                bevel=0.0006,material=satin,body=body)
    ring(side+"_collar_seam",0.0049,0.0006,loc=(x,PIN_Y,BEATER_TOP-0.002),material=edge,body=body)
    # Four offset wire ribs form the classic loop dasher. The right head is
    # phase-shifted by 45 degrees so the overlapping sweep envelopes interleave.
    phase=0.0 if side=="left" else math.pi/4
    for blade in range(4):
        dasher_wire(side+"_dasher_wire_%d"%blade,x,PIN_Y,body,phase+blade*math.pi/2)
    # The loop ribs terminate inside the top collar and rounded bottom boss.
    v4.sphere(side+"_shaft_tip",0.0032,loc=(x,PIN_Y,BEATER_BOTTOM),segments=40,material=satin,body=body)

# Continuous physical pivots.  The input is horizontal; the two output shafts are vertical.
crank_joint=v4.joint("crank_spin","continuous",frame,crank,
                      origin=(0,0,WHEEL_Z),axis=(0,1,0))
left_joint=v4.joint("left_beater_spin","continuous",frame,left,
                     origin=(-PIN_X,PIN_Y,PIN_Z),axis=(0,0,1))
right_joint=v4.joint("right_beater_spin","continuous",frame,right,
                      origin=(PIN_X,PIN_Y,PIN_Z),axis=(0,0,1))

# Crown wheel transmission: 3:1 speed increase, mirrored pinion direction on each side.
# The crank axis is local joint Z aligned with world Y; extract its angle relative to the
# saved rest quaternion so the driver also works when v4.pose changes the joint frame.
crank_joint.rotation_mode="QUATERNION"
def gear_drive(joint_obj, ratio):
    fcurve=joint_obj.driver_add("rotation_euler",2)
    driver=fcurve.driver; driver.type="SCRIPTED"
    for i,name in enumerate(("qw","qx","qy","qz")):
        variable=driver.variables.new(); variable.name=name; variable.type="SINGLE_PROP"
        variable.targets[0].id=crank_joint
        variable.targets[0].data_path=f"rotation_quaternion[{i}]"
    theta="2*atan2((qz+qy),(qw-qx))"
    driver.expression=f"{ratio}*({theta})"
    joint_obj["v4_gear_input"]="crank_spin"
    joint_obj["v4_gear_ratio"]=ratio

gear_drive(left_joint,3.0)
gear_drive(right_joint,-3.0)

# Join each rotating assembly into one connected, watertight body. Fine voxel
# resolution preserves the thin dasher paddles and the separate gear tooth shapes.
def fuse_rotating_body(body, label):
    parts=[]
    for obj in list(v4.asset_objects()):
        p=obj.parent; owner=None
        while p is not None:
            if p.get("v4_kind")=="body": owner=p; break
            p=p.parent
        if owner==body:
            if obj.type!="MESH":
                bpy.ops.object.select_all(action="DESELECT")
                obj.select_set(True); bpy.context.view_layer.objects.active=obj
                bpy.ops.object.convert(target="MESH"); obj=bpy.context.object
            parts.append(obj)
    bpy.ops.object.select_all(action="DESELECT")
    for obj in parts: obj.select_set(True)
    shell=parts[0]; bpy.context.view_layer.objects.active=shell
    bpy.ops.object.join(); shell.name=label+"_connected_shell"
    rem=shell.modifiers.new("fused_rotating_parts","REMESH")
    rem.mode="VOXEL"; rem.voxel_size=0.0012; rem.use_smooth_shade=True
    bpy.context.view_layer.objects.active=shell
    bpy.ops.object.modifier_apply(modifier=rem.name)
    shell.data.materials.clear()
    for material in (chrome,satin,edge,black,brass): shell.data.materials.append(material)
    for poly in shell.data.polygons:
        c=shell.matrix_world @ sum((shell.data.vertices[i].co for i in poly.vertices),start=Vector((0,0,0)))/len(poly.vertices)
        if body==crank:
            if c.y < -0.045 and c.z < WHEEL_Z-0.030: poly.material_index=3
            elif c.x*c.x+(c.z-WHEEL_Z)**2 < 0.00009 and c.y < -0.008: poly.material_index=2
            elif c.y > -0.010 and c.x*c.x+(c.z-WHEEL_Z)**2 < 0.00065: poly.material_index=1
            else: poly.material_index=0
        else:
            if c.z > PIN_Z-0.007 and c.z < PIN_Z+0.004 and abs(c.x) < PIN_X+0.010:
                poly.material_index=4
            elif BEATER_BOTTOM-0.0015 <= c.z <= BEATER_TOP+0.0015: poly.material_index=0
            elif c.z > PIN_Z-0.008: poly.material_index=2
            else: poly.material_index=0

fuse_rotating_body(crank,"crank")
fuse_rotating_body(left,"left_beater")
fuse_rotating_body(right,"right_beater")

v4.save(os.path.join(os.getcwd(),"asset.blend"))
print("saved asset.blend")
