import uk.co.nickthecoder.foocad.screws.v3.* import uk.co.nickthecoder.foocad.smartextrusion.v1.* import static uk.co.nickthecoder.foocad.smartextrusion.v1.SmartExtrusion.* class Bumper : Model { @Custom var length = 40 @Custom var width = 40 @Custom var thickness = 4 @Custom( about="Width of the overlap on corner bumpers. Special value 0 : triangular overlap" ) var overlap = 9 @Piece meth edgeBumper() = edgeBumper( length, width, thickness ) meth edgeBumper( length : double, width : double, thickness : double ) : Shape3d { val shape = Square( width ).roundAllCorners(thickness) - Square( width ).translate(thickness, thickness) val baseShape = Hull2d( shape ) val main = baseShape.smartExtrude( length ) .edges( Chamfer( thickness/4 ) ) val remove = Cube( width, width, length+0.2 ).translate( thickness, thickness, -0.1 ) return (main - remove).margin( -thickness, -thickness, 0 ) } @Piece meth screwEdgeBumper() = screwEdgeBumper( length, width, thickness ) meth screwEdgeBumper(length : double, width : double, thickness : double) : Shape3d { val main = edgeBumper( length, width, thickness ) val screwHoles = Countersink() .rotateX(90) .rightTo( main.right - 5 ) .translateZ( 10 ).translateZ( main.size.z - 20 ).also() .rotateZ(90).mirrorX().also(2) return main - screwHoles } @Piece meth cornerBumper() = cornerBumper( length, width, thickness, overlap ) meth cornerBumper( length : double, width : double, thickness : double, overlap : double ) : Shape3d { var baseShape : Shape2d = Square( width ).roundAllCorners(thickness) - Square( width ).translate( thickness + overlap-0.5, thickness + overlap-0.5 ) if ( overlap == 0 ) { baseShape = Hull2d( baseShape ) } val base = baseShape.smartExtrude( thickness ) .bottom( Chamfer( thickness/4 ) ) val main = baseShape.smartExtrude( length - thickness ) .top( Chamfer( thickness/4 ) ) .bottomTo( thickness ) val remove = Cube( width, width, length ).translate( thickness, thickness, thickness ) return (base + main - remove).margin( -thickness ) } override fun build() : Shape3d { val box = Cube( 300, 200, 200 ).previewOnly().centerXY() val corners = cornerBumper() .leftTo(box.left).frontTo(box.front) .mirrorX().also().mirrorY().also() .mirrorZ().topTo(box.top).also(2) val edgesA = edgeBumper() .leftTo(box.left).frontTo(box.front) .centerZTo( box.middle.z ) .mirrorX().also().mirrorY().also() val edgesB = screwEdgeBumper() .rotateY(-90).centerX().bottomTo(0) .frontTo( box.front ).mirrorY().also() val edgesC = screwEdgeBumper() .rotateX(90).centerY().bottomTo(0) .leftTo(box.left).mirrorX().also() return box + corners + edgesA + edgesB + edgesC } }