import sand3d as s3d
def toaster():
root = s3d.at(body(), x=2)
knob = s3d.at(dial(), x=2, y=130, z=33)
button = s3d.at(cancel_button(), x=-29.5, y=135.5, z=39)
tab = s3d.at(lever(), x=2, y=135.5, z=140)
s3d.joint(class="tok-string">"joint_dial_joint_00", knob, s3d.local(root, x=0, y=138, z=48), kind=class="tok-string">"continuous", axis=class="tok-string">"+Y")
s3d.joint(class="tok-string">"joint_cancel_button_joint_00", button, s3d.local(root, x=-31, y=136, z=42), kind=class="tok-string">"prismatic", axis=class="tok-string">"+Y", range=(-3, 0))
s3d.joint(class="tok-string">"joint_lever_joint_00", tab, s3d.local(root, x=0, y=149, z=146), kind=class="tok-string">"prismatic", axis=class="tok-string">"+Z", range=(-59, 0))
return s3d.assembly(class="tok-string">"toaster", root, knob, button, tab)
def body(w=154, d=280, h=179, floor=8, t=2, cavity_w=103, slot_w=44, slot_d=158, slot_y=-8, pitch=52, bottom=30, wire_d=2, wire_pitch=26, tray_w=68, tray_d=194, channel_h=99, mid_z=68):
levels = [(floor, w-6, d-6), (25, w, d), (mid_z, w-2*t, d-3), (137, 143, 271), (162, 140, 255), (175, 120, 224), (h, cavity_w, 205)]
skin = s3d.loft(class="tok-string">"housing", *[s3d.station(z=z, w=width, d=depth, n=8) for z, width, depth in levels])
cavity = s3d.scale(s3d.copy(skin), s=(h-t)/h)
mask = s3d.at(s3d.box(class="tok-string">"cavity_width", w=cavity_w, d=d, h=h), z=floor+t)
s3d.intersect(cavity, mask)
s3d.cut(skin, cavity)
base = s3d.at(s3d.box(class="tok-string">"base_floor", w=cavity_w, d=d-2*t, h=2*t), z=bottom-floor-t)
tray = s3d.at(s3d.extrude(class="tok-string">"bottom_tray", s3d.rect(w=tray_w, d=tray_d, r=floor), h=bottom-2*floor), z=floor)
for y in (-pitch, pitch):
s3d.pocket(tray, s3d.slot(l=bottom-t, d=2*t), depth=3*t, on=s3d.grid(nx=2, ny=floor, px=tray_w/2, py=floor, on=tray.face(class="tok-string">"bottom")).move(y=y))
guide = s3d.at(s3d.box(class="tok-string">"lever_guide", w=3*t, d=(d-slot_d)/2, h=channel_h-3*t), y=(d+slot_d)/4, z=channel_h-bottom)
s3d.material(base, class="tok-string">"steel", color=class="tok-string">"class="tok-comment">#656565")
s3d.material(tray, class="tok-string">"steel", color=class="tok-string">"class="tok-comment">#656565")
s3d.material(guide, class="tok-string">"steel", color=class="tok-string">"class="tok-comment">#656565")
liners = []
wires = []
for x in (-pitch/2, pitch/2):
liner = s3d.at(s3d.box(class="tok-string">"slot_liner", w=slot_w+t, d=slot_d, h=h-bottom), x=x, y=slot_y, z=bottom)
opening = s3d.at(s3d.extrude(class="tok-string">"slot_opening", s3d.rect(w=slot_w-t, d=slot_d-6*t, r=t), h=h), x=x, y=slot_y, z=bottom+t)
s3d.cut(skin, s3d.copy(opening))
s3d.cut(liner, opening)
s3d.material(liner, class="tok-string">"steel", color=class="tok-string">"class="tok-comment">#55575a")
liners.append(liner)
support = s3d.wire(class="tok-string">"bread_support", path=[(0, 0, bottom), (0, 0, h-16), (2*t, 0, h-10)], d=wire_d)
supports = s3d.at(support, on=s3d.grid(nx=2, ny=5, px=bottom, py=wire_pitch))
for item in supports:
item = s3d.transform(item, x=x, y=slot_y)
s3d.material(item, class="tok-string">"chrome", color=class="tok-string">"class="tok-comment">#9a9a9a")
wires.append(item)
feet = s3d.at(s3d.cylinder(class="tok-string">"foot", d=14, h=floor+t), on=s3d.grid(nx=2, ny=2, px=116, py=219))
for foot in feet:
s3d.material(foot, class="tok-string">"rubber", color=class="tok-string">"class="tok-comment">#252525")
s3d.material(skin, class="tok-string">"brushed_steel", color=class="tok-string">"class="tok-comment">#b9babc")
return s3d.group(class="tok-string">"body", skin, liners, feet, wires, base, tray, guide)
def dial(w=31, d=26, h=31, rim=3):
knob = s3d.at(s3d.cylinder(class="tok-string">"dial_rim", d=w, h=d/2), y=0, z=h/2, rx=-90)
grip = s3d.at(s3d.extrude(class="tok-string">"dial_grip", s3d.rect(w=w-rim, d=h/3, r=rim), h=d/2+rim), y=d/2-rim, z=h/2, rx=-90, ry=0)
s3d.join(knob, grip)
s3d.material(knob, class="tok-string">"plastic", color=class="tok-string">"class="tok-comment">#45474a")
return s3d.group(class="tok-string">"dial", knob)
def cancel_button(w=17, d=13, h=6):
button = s3d.extrude(class="tok-string">"cancel_button", s3d.rect(w=w, d=d, r=h/3), h=h)
s3d.material(button, class="tok-string">"plastic", color=class="tok-string">"class="tok-comment">#45474a")
return s3d.group(class="tok-string">"cancel_button", button)
def lever(w=44, d=61, h=12, tab_d=29, bevel=5, stem_w=6, recess=1):
tab = s3d.extrude(class="tok-string">"lever_tab", s3d.rect(w=w, d=tab_d, r=bevel+recess), h=h)
s3d.chamfer(tab, d=bevel, edges=class="tok-string">"top")
s3d.pocket(tab, s3d.rect(w=w-2*bevel, d=tab_d-2*bevel, r=recess), depth=recess, on=tab.face(class="tok-string">"top"))
tab = s3d.at(tab, y=(d-tab_d)/2)
stem = s3d.at(s3d.box(class="tok-string">"lever_stem", w=stem_w, d=d-tab_d+bevel, h=h), y=-tab_d/2+bevel/2)
s3d.join(tab, stem)
s3d.material(tab, class="tok-string">"plastic", color=class="tok-string">"class="tok-comment">#414346")
return s3d.group(class="tok-string">"lever", tab)