import sand3d as s3d
def crate():
base = s3d.at(basket_base(), z=0)
wall = s3d.at(long_lattice_wall(), x=118.5, z=22)
twin = s3d.transform(s3d.copy(wall), mirror=class="tok-string">"x")
end = s3d.at(end_handle_wall(), y=161, z=12)
other = s3d.at(opposite_handle_wall(), y=-161, z=12)
s3d.joint(class="tok-string">"joint_wall_02_joint_00", wall, on=s3d.local(base, x=123, y=0, z=24), kind=class="tok-string">"revolute", axis=class="tok-string">"+Y", range=(0,90))
s3d.joint(class="tok-string">"joint_wall_04_joint_00", twin, on=s3d.local(base, x=-123, y=0, z=24), kind=class="tok-string">"revolute", axis=class="tok-string">"+Y", range=(-90,0))
s3d.joint(class="tok-string">"joint_wall_01_joint_00", end, on=s3d.local(base, x=0, y=161, z=15), kind=class="tok-string">"revolute", axis=class="tok-string">"+X", range=(0,90))
s3d.joint(class="tok-string">"joint_wall_03_joint_00", other, on=s3d.local(base, x=0, y=-161, z=15), kind=class="tok-string">"revolute", axis=class="tok-string">"+X", range=(-90,0))
return s3d.assembly(class="tok-string">"crate", base, wall, twin, end, other)
def basket_base(w=254, d=331, h=18, rim=3, floor_t=1.8, floor_z=6, pitch_x=20.2, pitch_y=19.6, slot_l=17, slot_d=5, side_h=27):
band = s3d.box(class="tok-string">"bottom_band", w=w, d=d, h=h)
band = s3d.cut(band, s3d.at(s3d.box(class="tok-string">"inside", w=w-2*rim, d=d-2*rim, h=h+rim), z=-rim/2))
floor = perforated_sheet(w=w-2*rim, depth=d-2*rim, t=floor_t, nx=12, ny=16, px=pitch_x, py=pitch_y, length=slot_l, diameter=slot_d)
floor = s3d.at(floor, z=floor_z)
ribs = s3d.at(s3d.box(class="tok-string">"under_rib", w=rim, d=d-rim, h=floor_z+floor_t), on=s3d.grid(nx=2, px=80))
cross = s3d.at(s3d.box(class="tok-string">"cross_rib", w=w-rim, d=rim, h=floor_z+floor_t), on=s3d.grid(nx=1, ny=3, py=78))
sides = s3d.at(s3d.box(class="tok-string">"side_band", w=rim, d=d, h=side_h), on=s3d.grid(nx=2, px=w-rim))
obj = s3d.group(class="tok-string">"base", band, floor, ribs, cross, sides)
s3d.material(obj, class="tok-string">"plastic", color=class="tok-string">"class="tok-comment">#646765")
return obj
def perforated_sheet(w, depth, t, nx, ny, px, py, length, diameter):
panel = s3d.box(class="tok-string">"perforated_sheet", w=w, d=depth, h=t)
tools = []
for row in range(ny):
tool = s3d.extrude(class="tok-string">"slot_tool", s3d.slot(l=length, d=diameter), h=t*3)
for parity in range(2):
frames = s3d.grid(nx=(nx+1-parity)class="tok-comment">//2, px=px*2).move(x=(parity-0.5)*px if nx%2==0 else 0, y=(row-(ny-1)/2)*py, z=-t)
tools.extend(s3d.at(s3d.copy(tool), on=frames, rz=45 if (row+parity)%2 else -45))
s3d.delete(tool)
return s3d.cut(panel, s3d.merge(*tools))
def long_lattice_wall(w=19, d=332, h=106, t=1.7, rail=6, frame_d=8, panel_x=5.5, rib_pitch=126, pitch=21, rise=19.5, slot_l=17, slot_d=5, end_pitch=289, return_pitch=313, hinge_d=5, hinge_l=16, hinge_pitch=123):
panel = perforated_sheet(w=d-frame_d*2, depth=h-rail*2, t=t, nx=15, ny=4, px=pitch, py=rise, length=slot_l, diameter=slot_d)
panel = s3d.at(panel, x=panel_x, z=h/2, rx=90, rz=90)
top = s3d.at(s3d.box(class="tok-string">"top_rail", w=frame_d, d=d, h=rail), x=w/2-frame_d/2, z=h-rail)
bottom = s3d.at(s3d.box(class="tok-string">"lower_rail", w=frame_d, d=d, h=rail), x=w/2-frame_d/2, z=rail)
flange = s3d.at(s3d.box(class="tok-string">"inner_lower_rail", w=t, d=d-frame_d*2, h=rail), z=rail)
hinges = s3d.at(s3d.cylinder(class="tok-string">"hinge_sleeve", d=hinge_d, h=hinge_l), on=s3d.grid(nx=1, ny=3, py=hinge_pitch).move(x=w/2-rail+t/2, y=hinge_l/2, z=hinge_d/2), rx=90)
posts = s3d.at(s3d.box(class="tok-string">"corner_post", w=t, d=frame_d, h=h), on=s3d.grid(nx=1, ny=2, py=d-frame_d), x=t/2)
ribs = s3d.at(s3d.box(class="tok-string">"panel_divider", w=frame_d-t, d=rail, h=h), on=s3d.grid(nx=1, ny=2, py=rib_pitch), x=w/2-frame_d/2-t/2)
returns = s3d.at(s3d.box(class="tok-string">"corner_return", w=w-t, d=t, h=h), on=s3d.grid(nx=1, ny=2, py=return_pitch))
webs = s3d.at(s3d.box(class="tok-string">"corner_web", w=frame_d-t, d=t, h=h), on=s3d.grid(nx=1, ny=2, py=end_pitch), x=w/2-frame_d/2-t/2)
shelves = []
for level in range(5):
shelves.append(s3d.at(s3d.box(class="tok-string">"corner_cross_web", w=w-t, d=frame_d, h=t), on=s3d.grid(nx=1, ny=2, py=d-frame_d), z=level*(h-t)/4))
obj = s3d.group(class="tok-string">"long_wall", panel, top, bottom, flange, hinges, posts, ribs, returns, webs, shelves)
s3d.material(obj, class="tok-string">"plastic", color=class="tok-string">"class="tok-comment">#646765")
return obj
def end_handle_wall(w=240, d=10, h=121):
solid = handle_panel(w=w, d=d, h=h)
return s3d.group(class="tok-string">"end_wall", solid)
def handle_panel(w, d, h, t=1.7, rail=7, pitch=18.3, rise=19.5, slot_l=17, slot_d=5, handle_w=104, handle_h=35):
panel = perforated_sheet(w=w-rail*2, depth=h-rail*2, t=t, nx=12, ny=5, px=pitch, py=rise, length=slot_l, diameter=slot_d)
panel = s3d.at(panel, y=t/2, z=h/2, rx=90)
top = s3d.at(s3d.box(class="tok-string">"end_top", w=w, d=d, h=rail), z=h-rail*2)
bottom = s3d.box(class="tok-string">"end_bottom", w=w, d=d, h=rail)
posts = s3d.at(s3d.box(class="tok-string">"end_post", w=rail, d=d, h=h), on=s3d.grid(nx=2, px=w-rail))
bar = s3d.at(s3d.box(class="tok-string">"handle_sill", w=w, d=d, h=rail/2), z=h-rail*2-handle_h)
obj = s3d.join(panel, top, bottom, posts, bar)
opening = s3d.extrude(class="tok-string">"hand_opening", s3d.rect(w=handle_w, d=handle_h, r=rail), h=d*2)
opening = s3d.at(opening, y=d, z=h-rail*2-handle_h/2, rx=90)
obj = s3d.cut(obj, opening)
s3d.material(obj, class="tok-string">"plastic", color=class="tok-string">"class="tok-comment">#646765")
return obj
def opposite_handle_wall(w=240, d=10, h=121):
solid = handle_panel(w=w, d=d, h=h)
return s3d.group(class="tok-string">"opposite_end_wall", solid)