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

def smooth_tube(name, points, radius, material, body):
    cu=bpy.data.curves.new(name,'CURVE'); cu.dimensions='3D'; cu.resolution_u=20
    cu.bevel_depth=radius; cu.bevel_resolution=5; cu.resolution_u=16
    sp=cu.splines.new('BEZIER'); sp.bezier_points.add(len(points)-1)
    for bp,co in zip(sp.bezier_points,points):
        bp.co=co; bp.handle_left_type='AUTO'; bp.handle_right_type='AUTO'
    obj=bpy.data.objects.new(name,cu); v4._link(obj); cu.materials.append(material); v4.part(obj,body)
    return obj

def open_cylinder(name, radius, depth, loc, material, body, thickness=0.004, segments=96):
    # Thin annular wall and bottom rim, deliberately open across its top.
    bm=bmesh.new(); rings=[]
    for r,z in ((radius,-depth/2),(radius,depth/2),(radius-thickness,depth/2),(radius-thickness,-depth/2)):
        rings.append([bm.verts.new((r*math.cos(2*math.pi*i/segments),r*math.sin(2*math.pi*i/segments),z)) for i in range(segments)])
    for i in range(segments):
        j=(i+1)%segments
        for a,b in ((0,1),(2,3),(3,0)):
            try: bm.faces.new((rings[a][i],rings[a][j],rings[b][j],rings[b][i]))
            except ValueError: pass
    bmesh.ops.recalc_face_normals(bm,faces=bm.faces)
    obj=v4._place(v4._mesh_obj(name,bm),loc,(0,0,0))
    return v4._finish(obj,body,material,bevel=0.0006,segments=2,smooth=True)

# Finishes
white = v4.painted('porcelain_white_enamel', (0.83, 0.85, 0.84), roughness=0.26, coat=0.72)
white_plastic = v4.plastic('warm_white_molded_polymer', (0.89, 0.90, 0.87), roughness=0.32)
gray = v4.plastic('console_graphite', (0.105, 0.125, 0.135), roughness=0.29)
black = v4.rubber('charcoal_gasket', (0.025, 0.032, 0.034))
steel = v4.metal('satin_stainless_steel', (0.72, 0.75, 0.76), roughness=0.34, brushed=True)
chrome = v4.metal('selector_chrome', (0.77, 0.79, 0.80), roughness=0.22, brushed=True)
darksteel = v4.metal('darkened_steel', (0.22, 0.25, 0.26), roughness=0.38, brushed=False)
glass = v4.glass('smoked_lid_glass', color=(0.38, 0.53, 0.57), roughness=0.14)
glass_bsdf=glass.node_tree.nodes.get('Principled BSDF')
glass_bsdf.inputs['Transmission Weight'].default_value=0.32
glass_bsdf.inputs['Alpha'].default_value=0.92
glass.surface_render_method='DITHERED'
transparent_node=glass.node_tree.nodes.new('ShaderNodeBsdfTransparent')
mix_node=glass.node_tree.nodes.new('ShaderNodeMixShader')
mix_node.inputs[0].default_value=0.24
glass.node_tree.links.new(transparent_node.outputs['BSDF'],mix_node.inputs[1])
glass.node_tree.links.new(glass_bsdf.outputs['BSDF'],mix_node.inputs[2])
glass.node_tree.links.new(mix_node.outputs['Shader'],glass.node_tree.nodes['Material Output'].inputs['Surface'])
led = v4.emissive('cool_white_led', (0.62, 0.88, 1.0), strength=2.2)
ink = v4.mat('soft_white_ink', (0.78, 0.83, 0.82), roughness=0.4)
red = v4.mat('hot_water_red', (0.75, 0.08, 0.055), roughness=0.3)
blue = v4.mat('cold_water_blue', (0.035, 0.24, 0.72), roughness=0.3)
softener = v4.plastic('softener_cup_translucent_blue', (0.08, 0.42, 0.62), roughness=0.2)
agitator_mat = v4.plastic('graphite_washplate_accents', (0.17, 0.22, 0.23), roughness=0.32)

cab = v4.body('cabinet')
# Main shell: standard 27-inch-class square cabinet, rounded sheet-metal edges.
W, D = 0.69, 0.72
zbot, ztop = 0.095, 0.985
# Front face and sides, subtle seam breaks at their edges
front_panel_bottom=zbot+0.015
front_panel_top=1.006
v4.box('front_enamel_panel', (W-0.012, 0.018, front_panel_top-front_panel_bottom), (0, -D/2+0.015, (front_panel_bottom+front_panel_top)/2), bevel=0.012, material=white, body=cab)
for sx in (-1,1):
    side_panel_bottom=zbot+0.006
    side_panel_top=1.006
    v4.box('side_enamel_L' if sx<0 else 'side_enamel_R', (0.018, 0.725, side_panel_top-side_panel_bottom), (sx*(W/2-0.009), 0.008, (side_panel_bottom+side_panel_top)/2), bevel=0.012, material=white, body=cab)
rear_panel_bottom=zbot+0.01
rear_panel_top=1.006
v4.box('rear_enamel_panel', (W-0.02, 0.018, rear_panel_top-rear_panel_bottom), (0, D/2-0.009, (rear_panel_bottom+rear_panel_top)/2), bevel=0.009, material=white, body=cab)
# Continuous quarter-round corner rolls close the panel seams and soften the cabinet silhouette.
for sx in (-1,1):
    for sy in (-1,1):
        v4.cylinder('rounded_cabinet_corner_%s_%s'%(sx,sy),0.020,0.89,(sx*0.325,sy*0.340,0.551),segments=48,bevel=0.003,material=white,body=cab)
# Integrated lower plinth and bottom pan; panel ends overlap the pan to form one grounded shell.
v4.box('cabinet_bottom_pan',(0.68,0.70,0.04),(0,0,0.098),bevel=0.004,material=white_plastic,body=cab)
v4.box('toe_kick_shadow',(W-0.04,D-0.055,0.095),(0,0.004,0.105),bevel=0.012,material=black,body=cab)
# Recessed front toe-kick panel visible under the enamel shell lip.
v4.box('recessed_toe_kick_front',(0.60,0.018,0.060),(0,-0.335,0.082),bevel=0.008,material=black,body=cab)
v4.box('toe_kick_upper_reveal',(0.58,0.012,0.006),(0,-0.337,0.111),bevel=0.002,material=darksteel,body=cab)
# Adjustable elastomer leveling feet with steel collars, seated into the bottom pan.
for i,(sx,sy) in enumerate([(-1,-1),(1,-1),(-1,1),(1,1)]):
    x,y=sx*0.292,sy*0.30
    v4.lathe('leveling_foot_%d'%i,[(0,0),(0.027,0),(0.030,0.006),(0.029,0.018),(0.021,0.030),(0.018,0.070),(0.022,0.085),(0.022,0.102),(0,0.102)],loc=(x,y,0),material=black,body=cab)
# Narrow vertical reveal lines emphasize the formed front corners; a small appliance badge anchors the face.
front_y=-D/2+0.006
for sx in (-1,1):
    v4.box('front_corner_reveal_%s'%sx,(0.0025,0.0035,0.68),(sx*0.329,front_y-0.001,0.57),bevel=0.001,material=gray,body=cab)
v4.box('front_brand_badge',(0.095,0.005,0.030),(0.245,front_y-0.002,0.904),bevel=0.004,material=gray,body=cab)
v4.box('badge_mark',(0.013,0.002,0.013),(0.216,front_y-0.0045,0.904),bevel=0.003,material=chrome,body=cab)
for j in range(3):
    v4.box('badge_wordmark_bar_%d'%j,(0.034-0.004*j,0.002,0.002),(0.259,front_y-0.0045,0.910-0.006*j),bevel=0.0005,material=ink,body=cab)
# top deck: edge rails leave a real, recessed central laundry opening
# deck surface top at 0.995; forward and side rails surround removable lid
v4.box('top_deck_left_rail', (0.038, 0.655, 0.026), (-0.326, -0.015, 1.014), bevel=0.012, material=white_plastic, body=cab)
v4.box('top_deck_right_rail', (0.038, 0.655, 0.026), (0.326, -0.015, 1.014), bevel=0.012, material=white_plastic, body=cab)
v4.box('top_deck_front_rail', (0.615, 0.045, 0.026), (0, -0.365, 1.014), bevel=0.012, material=white_plastic, body=cab)
v4.box('top_deck_rear_rail', (0.615, 0.045, 0.026), (0, 0.293, 1.014), bevel=0.012, material=white_plastic, body=cab)
# Flush filler shoulders continue the molded frame to the lid edge, eliminating dark side slots.
for sx in (-1,1):
    v4.box('deck_lid_shoulder_%s'%sx,(0.027,0.57,0.026),(sx*0.2935,-0.0565,1.014),bevel=0.012,material=white_plastic,body=cab)
# Molded splash guard ring is suspended from the underside of the deck by four short ribs.
v4.torus('inner_tub_splash_guard',0.278,0.012,(0,0.002,0.954),material=white_plastic,body=cab)
for sx in (-1,1):
    v4.rod('splash_guard_side_stay_%s'%sx,(sx*0.285,0.002,0.954),(sx*0.312,0.002,1.004),0.006,material=white_plastic,body=cab)
v4.rod('splash_guard_front_stay',(0,-0.285,0.954),(0,-0.342,1.004),0.006,material=white_plastic,body=cab)
v4.rod('splash_guard_rear_stay',(0,0.285,0.954),(0,0.270,1.004),0.006,material=white_plastic,body=cab)
# Central basket drive support beneath the laundry opening.
v4.cylinder('basket_drive_shaft',0.035,0.385,(0,0.002,0.30),material=darksteel,bevel=0.002,body=cab)
# Rear control console, sloped face toward operator
console_loc=(0,0.341,1.049); console_rot=(-0.24,0,0)
def fascia_face_y(z):
    return 0.269+(z-1.061)*math.tan(0.24)-0.0045
v4.box('control_console_housing',(0.72,0.145,0.157),console_loc,rot=console_rot,bevel=0.025,material=white_plastic,body=cab)
# dark inset fascia is placed on front face, with same slope
v4.box('control_fascia',(0.704,0.009,0.108),(0,0.269,1.061),rot=console_rot,bevel=0.012,material=gray,body=cab)
# A satin-aluminum lower pinstripe softens the console and separates the fascia from its shell.
v4.box('console_silver_accent_band',(0.66,0.006,0.009),(0,fascia_face_y(1.012)-0.001,1.012),rot=console_rot,bevel=0.003,material=steel,body=cab)
# Small raised brand plate on the right-hand console shoulder.
v4.box('console_brand_plate',(0.060,0.004,0.020),(0.292,fascia_face_y(1.095)-0.001,1.095),rot=console_rot,bevel=0.003,material=darksteel,body=cab)
v4.box('console_brand_mark',(0.025,0.0015,0.003),(0.292,fascia_face_y(1.095)-0.004,1.095),rot=console_rot,bevel=0.0008,material=ink,body=cab)
# Display window and bright digits
v4.box('cycle_display_window',(0.112,0.004,0.046),(-0.12,0.262,1.065),rot=console_rot,bevel=0.006,material=black,body=cab)
# Selector bezel and markings; selector axle normal to tilted fascia
knobpos=(-0.321,0.260,1.066)
v4.cylinder('selector_bezel',0.046,0.009,knobpos,rot=(math.pi/2-0.24,0,0),material=darksteel,body=cab)
# Printed dial scale on the fascia, with tapered major ticks and cycle names along the open arc.
for i,ang in enumerate([math.radians(a) for a in range(-55,56,11)]):
    r=0.055
    x=knobpos[0]+r*math.cos(ang)
    z=knobpos[2]+r*math.sin(ang)
    major=(i in (0,3,6,9,10))
    tick_rot=(Matrix.Rotation(-0.24,4,'X') @ Matrix.Rotation(ang,4,'Y')).to_euler()
    v4.box('selector_tick_%02d'%i,(0.0025 if major else 0.0017,0.0025,0.008 if major else 0.0055),(x,fascia_face_y(z)-0.0005,z),rot=tuple(tick_rot),bevel=0.0005,material=ink,body=cab)
for nm,x,z in [('NORMAL',-0.262,1.105),('HEAVY',-0.245,1.066),('DELICATE',-0.260,1.027)]:
    v4.text('selector_cycle_'+nm,nm,0.012,(x,fascia_face_y(z)+0.001,z),rot=(math.pi/2-0.24,0,0),extrude_depth=0.003,material=ink,body=cab)
# Four option keys, with raised geometric icons directly above each switch.
for idx,(x,label) in enumerate([(-0.02,'COTTON'),(0.075,'RINSE'),(0.17,'SPIN'),(0.27,'DELAY')]):
    v4.cylinder('option_key_%d'%idx,0.009,0.005,(x,0.259,1.045),rot=(math.pi/2-0.24,0,0),segments=24,material=chrome,bevel=0.001,body=cab)
    # Each raised pictogram is one connected embossed silhouette in the fascia.
    cy=0.269; cz=1.080; outline=[]
    if idx==0:
        for j in range(24):
            a=2*math.pi*j/24
            r=0.006+0.0015*math.cos(5*a)
            outline.append((r*math.cos(a),r*math.sin(a)))
    elif idx==1:
        outline=[(-.008,-.002),(-.006,0),(-.004,.002),(-.002,0),(0,-.002),(.002,0),(.004,.002),(.006,0),(.008,-.002),(.008,-.004),(.006,-.002),(.004,0),(.002,-.002),(0,-.004),(-.002,-.002),(-.004,0),(-.006,-.002),(-.008,-.004)]
    elif idx==2:
        for j in range(12):
            a=math.pi/2+j*math.pi/6
            r=0.007 if j%2==0 else 0.0024
            outline.append((r*math.cos(a),r*math.sin(a)))
    else:
        for j in range(24):
            a=2*math.pi*j/24
            outline.append((0.006*math.cos(a),0.006*math.sin(a)))
    v4.extrude('control_icon_%d'%idx,outline,0.010,loc=(x,cy,cz),rot=(math.pi/2-0.24,0,0),bevel=0.0004,material=led if idx==1 else ink,body=cab)
    # Small, legible cycle labels below each key on the sloped fascia.
    v4.text('control_label_%d'%idx,label,0.014,(x,fascia_face_y(1.018)+0.001,1.018),rot=(math.pi/2-0.24,0,0),extrude_depth=0.003,material=ink,body=cab)
# Back console seam and side end caps
for sx in (-1,1):
    v4.box('console_endcap_%s'%sx,(0.012,0.12,0.13),(sx*0.337,0.341,1.049),rot=console_rot,bevel=0.005,material=white,body=cab)

# Rear service details: inlet couplings, vent slots, drain hose and grounded power lead.
for sx,col,nm in [(-1,blue,'cold'),(1,red,'hot')]:
    x=sx*0.225
    v4.cylinder(nm+'_inlet_grommet',0.031,0.008,(x,0.363,0.815),rot=(-math.pi/2,0,0),material=black,body=cab)
    v4.cylinder(nm+'_water_inlet',0.022,0.032,(x,0.377,0.815),rot=(-math.pi/2,0,0),material=darksteel,body=cab)
    v4.torus(nm+'_coded_ring',0.020,0.003,(x,0.395,0.815),rot=(-math.pi/2,0,0),material=col,body=cab)
    v4.cylinder(nm+'_threaded_nose',0.014,0.018,(x,0.394,0.815),rot=(-math.pi/2,0,0),material=chrome,body=cab)
# Five narrow stamped ventilation slots, recessed dark and flush to the back panel.
for row in range(4):
    for col in range(5):
        x=-0.25+col*0.125
        z=0.61+row*0.027
        v4.box('rear_vent_%d_%d'%(row,col),(0.075,0.004,0.009),(x,0.3605,z),bevel=0.003,material=black,body=cab)
# Flexible corrugated drain and mains lead routed to the rear without free ends.
drain_pts=[]
for j in range(13):
    t=j/12
    if t<0.25:
        q=t/0.25; drain_pts.append((0.19+0.07*q,0.362+0.008*q,0.43-0.015*q))
    else:
        q=(t-0.25)/0.75; drain_pts.append((0.26+0.012*math.sin(math.pi*q),0.370+0.006*math.sin(math.pi*q),0.415-0.19*q))
smooth_tube('drain_hose',drain_pts,0.014,black,cab)
v4.cylinder('drain_hose_cuff',0.018,0.035,(0.26,0.389,0.225),rot=(-math.pi/2,0,0),material=darksteel,body=cab)
power_pts=[(-0.22,0.358,0.28),(-0.24,0.37,0.275),(-0.27,0.38,0.255),(-0.29,0.39,0.225),(-0.30,0.395,0.19),(-0.29,0.40,0.16),(-0.265,0.405,0.14),(-0.24,0.41,0.135)]
smooth_tube('power_cord',power_pts,0.008,black,cab)
v4.box('cord_strain_relief',(0.028,0.018,0.028),(-0.22,0.361,0.28),bevel=0.006,material=darksteel,body=cab)
v4.box('grounded_power_plug',(0.044,0.040,0.027),(-0.24,0.425,0.135),bevel=0.007,material=darksteel,body=cab)
# Two small brass prongs are flush-mounted on the grounded plug's end.
for j in (-1,1):
    v4.rod('plug_prong_%s'%j,(-0.24+j*0.009,0.443,0.131),(-0.24+j*0.009,0.451,0.131),0.0025,material=chrome,body=cab)

# Lid body: hinged on back edge with continuous gasket, smoked inset window and front finger pull.
lid=v4.body('lid')
hx,hy,hz=0.0,0.228,1.015
lidcenter=(0,-0.045,1.015)
v4.box('lid_molded_shell',(0.56,0.57,0.034),(0,-0.0565,1.015),bevel=0.018,material=white_plastic,body=lid)
# Raised perimeter lip arranged as touching edge pieces around a dark window
v4.box('lid_window_gasket',(0.425,0.397,0.008),(0,-0.0565,1.034),bevel=0.025,material=black,body=lid)
v4.box('lid_glass_insert',(0.397,0.359,0.006),(0,-0.0565,1.039),bevel=0.024,material=glass,body=lid)
# Slim polished glass frame sits on the black gasket and gives the window a raised, sealed edge.
for sy in (-1,1):
    v4.box('lid_glass_frame_frontback_%s'%sy,(0.392,0.004,0.004),(0,-0.0565+sy*0.185,1.040),bevel=0.0018,material=steel,body=lid)
for sx in (-1,1):
    v4.box('lid_glass_frame_sides_%s'%sx,(0.004,0.350,0.004),(sx*0.202,-0.0565,1.040),bevel=0.0018,material=steel,body=lid)
# Broad molded finger pocket at the leading edge with a raised, rounded grasp lip.
v4.box('front_grip_recess',(0.17,0.034,0.009),(0,-0.322,1.0315),bevel=0.010,material=black,body=lid)
v4.rod('front_molded_grip_lip',(-0.060,-0.327,1.031),(0.060,-0.327,1.031),0.005,material=white_plastic,body=lid)
# hinge barrels at ends
for x in (-0.245,0.245):
    v4.cylinder('lid_hinge_barrel',0.012,0.052,(x,hy,hz),rot=(0,math.pi/2,0),material=chrome,body=lid)
    v4.cylinder('hinge_cap',0.014,0.004,(x*1.12,hy,hz),rot=(0,math.pi/2,0),material=darksteel,body=lid)
    # Fixed leaf bridges each moving knuckle to the rear deck rail; the pivot stays unchanged.
    v4.box('cabinet_hinge_leaf',(0.060,0.060,0.012),(x,0.249,1.002),bevel=0.004,material=darksteel,body=cab)
    for j in (-1,1):
        v4.cylinder('hinge_leaf_screw',0.0035,0.002,(x+j*0.020,0.257,1.010),rot=(math.pi/2,0,0),segments=20,material=chrome,body=cab)
v4.joint('lid_hinge','revolute',cab,lid,origin=(hx,hy,hz),axis=(1,0,0),limits=(-math.radians(78),0))
# Control dial is its own continuous body; the grip pointer rotates with it.
knob=v4.body('cycle_knob')
# axle along tilted face normal (-Y,+Z)
axis=(0,-math.cos(0.24),math.sin(0.24))
# lathe along local Z, orient its axis to match face normal
rot=(math.pi/2-0.24,0,0)
v4.cylinder('knob_stem',0.014,0.04,(knobpos[0],knobpos[1]-0.014,knobpos[2]+0.003),rot=rot,material=darksteel,body=knob)
v4.lathe('selector_dial',[(0,0),(0.028,0),(0.034,0.004),(0.035,0.012),(0.033,0.020),(0.029,0.027),(0.020,0.032),(0,0.032)],loc=(knobpos[0],knobpos[1]-0.032,knobpos[2]+0.010),rot=rot,material=chrome,body=knob)
# A dark, stepped grip skirt is visible beneath the chrome face and turns with the dial.
v4.lathe('selector_grip_skirt',[(0,0),(0.037,0),(0.041,0.004),(0.041,0.014),(0.037,0.018),(0,0.018)],loc=(knobpos[0],knobpos[1]-0.016,knobpos[2]),rot=rot,material=darksteel,body=knob)
# radial pointer ridge mounted flush at dial top face
v4.box('selector_pointer',(0.007,0.004,0.024),(knobpos[0],knobpos[1]-0.058,knobpos[2]+0.016),rot=rot,bevel=0.001,material=red,body=knob)
v4.torus('dial_grip_skirt_ring',0.034,0.0015,(knobpos[0],knobpos[1]-0.047,knobpos[2]+0.014),rot=rot,material=darksteel,body=knob)
v4.joint('cycle_selector','continuous',cab,knob,origin=knobpos,axis=axis)

# Stainless spin basket, independently rotating inside the opening.
basket=v4.body('basket')
basket_wall=v4.cylinder('perforated_basket_wall',0.248,0.385,(0,0.002,0.665),material=steel,bevel=0.002,body=basket)
clear_cap=bpy.data.materials.new('open_basket_top_transparency'); clear_cap.use_nodes=True
clear_nodes=clear_cap.node_tree.nodes; clear_nodes.clear()
clear_out=clear_nodes.new('ShaderNodeOutputMaterial'); clear_trans=clear_nodes.new('ShaderNodeBsdfTransparent')
clear_cap.node_tree.links.new(clear_trans.outputs['BSDF'],clear_out.inputs['Surface'])
basket_wall.data.materials.append(clear_cap)
for face in basket_wall.data.polygons:
    if face.normal.z > 0.9: face.material_index=1
# A broad circular opening in the basket top gives a clear sightline down to the agitator and cup.
basket_top_cutter=v4.cylinder('temporary_basket_opening_cutter',0.212,0.035,(0,0.002,0.86),bevel=0)
v4.boolean(basket_wall,basket_top_cutter)
# Remove the boolean's remaining center disk to expose the interior mechanism through the basket mouth.
bm=bmesh.new(); bm.from_mesh(basket_wall.data)
for face in list(bm.faces):
    if face.normal.z > 0.9 and face.calc_area() > 0.10 and face.calc_center_median().z > 0.16:
        bm.faces.remove(face)
bmesh.ops.recalc_face_normals(bm,faces=bm.faces)
bm.to_mesh(basket_wall.data); bm.free()
for face in basket_wall.data.polygons:
    if face.normal.z > 0.9 and face.center.z > 0.16:
        face.material_index=0
v4.cylinder('basket_inner_dark_floor',0.232,0.009,(0,0.002,0.472),material=darksteel,bevel=0.003,body=basket)
v4.torus('basket_balance_ring',0.246,0.014,(0,0.002,0.863),material=steel,body=basket)
# Sculpted washplate in the bottom with radial ribs
v4.cylinder('washplate_hub',0.055,0.024,(0,0.002,0.493),material=white_plastic,bevel=0.009,body=basket)
v4.cylinder('washplate_disc',0.188,0.018,(0,0.002,0.478),material=steel,bevel=0.009,body=basket)
for i in range(8):
    a=2*math.pi*i/8
    p0=(0.045*math.cos(a),0.002+0.045*math.sin(a),0.49)
    p1=(0.17*math.cos(a),0.002+0.17*math.sin(a),0.49)
    v4.rod('washplate_rib_%02d'%i,p0,p1,0.004,material=white,body=basket)
# Three raised swept impeller vanes give the basket floor a distinct working mechanism.
for i in range(3):
    v4.extrude('washplate_impeller_vane_%d'%i,[(0.030,-0.020),(0.135,-0.034),(0.168,0),(0.135,0.034),(0.030,0.020)],0.044,loc=(0,0.002,0.480),rot=(0,0,2*math.pi*i/3),bevel=0.003,material=white_plastic,body=basket)
# Central low-profile agitator with three molded, swept vanes; all fixed to the rotating basket.
v4.lathe('central_agitator',[(0,0),(0.046,0),(0.052,0.014),(0.046,0.030),(0.039,0.315),(0.047,0.350),(0.038,0.400),(0,0.400)],loc=(0,0.002,0.488),material=white_plastic,body=basket)
v4.cylinder('agitator_blue_crown',0.050,0.018,(0,0.002,0.876),material=blue,bevel=0.005,body=basket)
# Three broad raised ribs on the agitator create a recognizable molded wash column.
for i in range(3):
    a=2*math.pi*i/3
    v4.rod('agitator_spline_%d'%i,(0.031*math.cos(a),0.002+0.031*math.sin(a),0.555),(0.043*math.cos(a),0.002+0.043*math.sin(a),0.855),0.010,material=agitator_mat,body=basket)
# Clipped translucent softener cup nested against the basket wall, with lid rim and dosing cap.
v4.box('softener_cup_mount',(0.10,0.018,0.065),(0.19,-0.09,0.815),bevel=0.008,material=white_plastic,body=basket)
v4.cylinder('softener_cup',0.036,0.066,(0.142,-0.09,0.823),material=softener,bevel=0.006,body=basket)
v4.torus('softener_cup_lip',0.030,0.003,(0.142,-0.09,0.857),material=white_plastic,body=basket)
v4.cylinder('softener_cup_cap',0.020,0.008,(0.142,-0.09,0.860),material=white_plastic,bevel=0.003,body=basket)
# Small black perforation marks on the inner basket wall in regular circumferential rows
for row,z in enumerate((0.535,0.59,0.645,0.70,0.755,0.81)):
    for i in range(32):
        a=2*math.pi*i/32 + (row%2)*math.pi/32
        x=0.249*math.cos(a); y=0.002+0.249*math.sin(a)
        v4.rod('basket_perforation_%d_%02d'%(row,i),(x*0.985,0.002+(y-0.002)*0.985,z),(x, y,z),0.0032,segments=12,material=black,bevel=0,body=basket)
v4.joint('basket_spin','continuous',cab,basket,origin=(0,0.002,0.49),axis=(0,0,1))

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



















