//Last edited on 2019-12-12 05:11:21 by jstolfi #include "double_closet_section.inc" // GLOBAL DECLARATIONS #declare empty = sphere{ < 0, 0, 0 >, 0.00001 } #declare eps = 0.01; // Perturbation to avoid coincident surfaces. #declare eps3 = < eps, eps, eps >; #fopen pieces "out/double_closet_pieces.txt" write // For {write_pieces}. #macro double_closet ( space_dim, closet_dim, sec_rear_dp, sec_gap, shf_N, shf_ht, walls_side_th, walls_rear_th, walls_face_th, walls_bot_th, walls_top_th, shf_face_th, shf_bot_th, handle_dim, max_open, tx_walls_in, tx_walls_out, tx_shelf, tx_handle, tagg, what, isd, ishf, dim_only ) // A closet of shelves for the workshop, with shelves on doors too. // The X axis is back to front. // The Y axis is across the closet, left to right. // The Z axis is up. // The origin is at the back left bottom corner of the nominal dimensions. // {space_dim} is the dimensions of the available space. // {closet_dim} is the nominal dimensions of the closet, excl. handles. // {sec_rear_dp} is the depth (X dimension) of the rear (fixed) section. // {sec_gap} is the gap to leave between sections when closed. // {shf_N} is the number of shelves. // {shf_ht} is an array of {shf_N} elems with the shelf heights, bottom to top. // {handle_dim} is the dimensions of a box that encloses the handle, nominally. // {walls_side_th} is the thickness of left and right walls. // {walls_rear_th, walls_face_th, walls_face_th, walls_face_th} is the thickness of rear wall. // {walls_bot_th} is the thickness of bottom wall. // {walls_top_th} is the thickness of top wall // {shf_face_th} is the thickness of the front wall (face plate) of shelves. // {shf_bot_th} is the thickness of the bottom wall of shelves. // The doors are swung open by various angles up to {maxopen} (degrees). // If {what=7} returns the whole closet. // If {what=6} returns section {isd} of the closet (0 = back, 1 = left door, 2 = right door). // If {what=5} returns only the walls of that section. // If {what=4} returns only the cavity within the walls of that section. // If {what=3} returns only the shelves of that section. // If {what=2} returns only shelf {ishf} of that section. // If {what=1} returns only the ??? (minus the face plate). // If {what=0} returns the useful cavity of that shelf (minus walls and clearances). // If {what=-1} returns the handle of that section. // If {what=-2} returns that handle's mounting's hole (to be subtracted from the front wall). // If {dim_only} is true returns only the nominal bounding box of the (sub)object, // (closed, unexploded) instead of the object itself. For the whole object, // the lower corner of the nominal box will be at the origin. // The nominal box of any sub-object will be positioned relative to // that of the whole object. Its position (but not its size) takes // explosion into account. // The nominal bounding box of the whole closet does not include the door // handles. Its low corner will be at the origin. // Unused space: #local skosh = space_dim - closet_dim; // Total unused space around closet. #debug concat("\n!! unused space around closet = ") #debug concat(str(skosh.x,0,1), " ", str(skosh.y,0,1), " ", str(skosh.z,0,1), "\n") #local whole = 7; // Value of {what} for whole closet. #if ((what = whole) & dim_only) #local res = box{ < 0, 0, 0 >, closet_dim texture{ tx_space } } #else #local res = union{ #for(ksd, 0, 2, 1) #if ((what = whole) || (ksd = isd)) #local taggk = concat(tagg, str(ksd,1,0)) // {sec_dispa} puts pivot axis on Z axis, {sec_dispb} places it on closet: #if (ksd = 0) // Rear (fixed) section: #local sec_dim = < sec_rear_dx, closet_dim.y, closet_dim.z>; #local sec_hinges = 3; // Hinges on both sides. #local sec_dispa = < 0, 0, 0 >; #local sec_rot = 0; #local sec_dispb = < 0, 0, 0 >; #local dexp = < 0, 0, 0 >; #elseif (ksd = 1) // Left door section: #local sec_dim = < closet_dim.x - sec_rear_dx - sec_gap, closet_dim.y - sec_gap/2, closet_dim.z>; #local sec_hinges = 2; // Hinges on right side only. #local sec_dispa = < - sec_dim.x, - sec_dim.y, 0 >; // Pivot on right front edge. #local sec_rot = + 180 - maxopen; #local sec_disp = < sec_rear_dx + sec_gap, 0, 0>; #local dexp = < xplode, - xplode, 0 >; #elseif (ksd = 2) // Right door section: #local sec_dim = < closet_dim.x - sec_rear_dx - sec_gap, closet_dim.y - sec_gap/2, closet_dim.z>; #local sec_hinges = 1; // Hinges on left side only. #local sec_dispa = < - sec_dim.x, 0, 0 >; // Pivot on left front edge. #local sec_rot = - 180 + maxopen; #local sec_disp = < sec_rear_dx + sec_gap, closet_dim.y, 0>; #local dexp = < xplode, + xplode, 0 >; #end object{ double_closet_section ( space_dim, sec_dim, shf_N, shf_ht, walls_side_th, walls_rear_th, walls_face_th, walls_bot_th, walls_top_th, shf_face_th, shf_bot_th, sec_hinges, handle_dim, tx_walls_in, tx_walls_out, tx_shelf, tx_handle, taggk, what, isd, ishf, dim_only ) #if (what = whole) // Here {dim_only} should be false. translate sec_dispa rotate sec_rot translate sec_dispb #end } #end #end #end res #end