Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Parametric Arduino Box Builder
- function getParameterDefinitions( )
- {
- return [
- { name: 'type', type: 'choice', initial: 0, values: [ 0, 1, 2 ], captions: [ 'Box', 'Lid', 'Base' ], caption: "Part to generate:" },
- { name: 's_length', type: 'float', initial: 79.0, caption: "Shield Length:" },
- { name: 'w_thickness', type: 'float', initial: 2.0, caption: "Wall Thickness:" },
- { name: 'w_height', type: 'float', initial: 21.0, caption: "Wall Height:" },
- { name: 'b_thickness', type: 'float', initial: 3, caption: "Bottom Thickness:" },
- { name: 'b_offset', type: 'float', initial: 1, caption: "Bottom Offset:" },
- { name: 'x_gap', type: 'float', initial: 0.6, caption: "Tolerance for lid and base" },
- { name: 'a_width', type: 'float', initial: 54, caption: "Arduino Width:" },
- { name: 'a_length', type: 'float', initial: 69, caption: "Arduino Length:" },
- { name: 'u_width', type: 'float', initial: 13, caption: "USB Width:" },
- { name: 'u_height', type: 'float', initial: 15, caption: "USB Height:" },
- { name: 'u_offset', type: 'float', initial: 9.5, caption: "USB Offset:" },
- { name: 'p_width', type: 'float', initial: 9.5, caption: "Power Width:" },
- { name: 'p_height', type: 'float', initial: 15, caption: "Power Height:" },
- { name: 'p_offset', type: 'float', initial: 3.5, caption: "Power Offset:" },
- ];
- }
- function main( p )
- {
- // Will hold the result of the function
- var result;
- // Dimensions of the box (should be migrated to functions)
- var bw = p.a_width + p.w_thickness * 2;
- var bl = ( p.s_length <= p.a_length ? p.a_length : p.s_length ) + p.w_thickness * 2;
- var bh = p.w_height + p.b_thickness;
- if ( p.type == 0 )
- {
- result = difference(
- // Main box
- cube( { size: [ bw, bl, bh ] } ),
- // Arduino
- cube( { size: [ p.a_width, p.a_length, p.w_height ] } ).translate( [ p.w_thickness, p.w_thickness, p.b_thickness ] ),
- // Power
- cube( { size: [ p.p_width, p.w_thickness, p.p_height ] } ).translate( [ bw - p.w_thickness - p.p_offset - p.p_width, 0, p.b_thickness ] ),
- // USB
- cube( { size: [ p.u_width, p.w_thickness, p.u_height ] } ).translate( [ p.w_thickness + p.u_offset, 0, p.b_thickness ] ),
- // Base
- cube( { size: [ p.a_width - p.b_offset * 2, p.a_length - p.b_offset * 2, p.b_thickness ] } ).translate( [ p.b_offset + p.w_thickness, p.b_offset + p.w_thickness, 0 ] )
- );
- if ( p.s_length > p.a_length )
- {
- result = difference(
- // Derived result which we'll modify here
- result,
- // Clear the space for the shield
- cube( { size: [ p.a_width, p.s_length - p.a_length, p.w_height ] } ).translate( [ p.w_thickness, p.w_thickness + p.a_length, p.b_thickness ] )
- );
- }
- }
- else if ( p.type == 1 )
- {
- result = difference(
- // Slightly larger than the main box
- cube( { size: [ bw + p.w_thickness * 2 + p.x_gap * 2, bl + p.w_thickness * 2 + p.x_gap * 2, p.b_thickness + p.w_thickness ] } ),
- cube( { size: [ bw + p.x_gap, bl + p.x_gap, p.b_thickness ] } ).translate( [ p.w_thickness + p.x_gap / 2, p.w_thickness + p.x_gap / 2, p.w_thickness ] ),
- cube( { size: [ p.a_width - p.b_offset * 2, p.a_length - p.b_offset * 2, p.b_thickness ] } ).translate( [ p.b_offset + p.w_thickness * 2 + p.x_gap, p.b_offset + p.w_thickness * 2 + p.x_gap, 0 ] )
- );
- }
- else if ( p.type == 2 )
- {
- result = difference(
- // Slightly larger than the main box
- cube( { size: [ bw + p.w_thickness * 2 + p.x_gap * 2, bl + p.w_thickness * 2 + p.x_gap * 2, p.b_thickness + p.w_thickness ] } ),
- cube( { size: [ bw + p.x_gap, bl + p.x_gap, p.b_thickness ] } ).translate( [ p.w_thickness + p.x_gap / 2, p.w_thickness + p.x_gap / 2, p.w_thickness ] )
- );
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement