FooCAD Source Codeimport static uk.co.nickthecoder.foocad.chamferedextrude.v1.ChamferedExtrude.*
import uk.co.nickthecoder.foocad.drawerclip.v1.DrawerClip
/**
A torch which uses a 9V battery, and a COB LED.
Customise the "ledBase" piece for particular LED, and also use it to
hold a buck or boost module to drive the COB LED at the correct voltage.
*/
class NineVolter : Model {
var thickness = 1.8
// Internal dimensions of the body
// Note, mmust be bigger than the battery to account for the lip, slack
// and the switch.
var width = 21
var height = 32
var frontLength = 35
var backLength = 50
var buttonD = 12.8
var ledZ = 3.5
var lip = 9
var lipT = 2
var openingD = 7
//var openingX = 10
//var openingY = 10
var chamfer = 2
var slack= 0.1
fun clip() = DrawerClip().apply {
thin = 0
span = 20
}
@Piece
fun back() : Shape3d {
val internalChamfer = chamfer / Math.sqrt(2)
val profile = Square(
width + thickness*2,
height + thickness *2
).center().roundAllCorners( chamfer )
val solid = ExtrusionBuilder().apply {
crossSection( profile.offset( -chamfer ) )
forward( chamfer )
crossSection( profile )
forward( backLength - chamfer )
crossSection()
crossSection( -thickness )
forward( -backLength + thickness + internalChamfer )
crossSection()
forward( -internalChamfer )
crossSection( - internalChamfer )
}.build()
return solid
}
@Piece
fun front() : Shape3d {
val internalChamfer = chamfer / Math.sqrt(2)
val profile = Square(
width + thickness*2,
height + thickness *2
).center().roundAllCorners( chamfer )
val outerLip = Square(
width - slack,
height -slack
).center().roundAllCorners( chamfer )
val solid = ExtrusionBuilder().apply {
crossSection( profile.offset( -chamfer ) )
forward( chamfer )
crossSection( profile )
forward( frontLength - chamfer )
crossSection()
crossSection( outerLip )
// Lip
forward( lip )
crossSection()
crossSection( -lipT )
forward( -lip-lipT )
crossSection()
forward( -lipT )
crossSection( profile.offset(-thickness) )
forward( -frontLength + lipT*2 + thickness + internalChamfer )
crossSection()
forward( -internalChamfer )
crossSection( - internalChamfer )
}.build()
val shelf = Cube( width, 6, thickness ).centerX()
.backTo( height/2 - 2 )
.topTo( frontLength - 6 )
val wireSlot = Cube( 4, lipT+slack, frontLength ).centerX()
.backTo( height/2 -0.01 )
.translateZ(10)
val opening = Circle( openingD/2 ).sides(24)
.internalChamferedExtrude( thickness, chamfer, 0 )
//val opening = Square( openingX, openingY ).center()
// .roundAllCorners(chamfer)
// .internalChamferedExtrude( thickness, chamfer, 0 )
val buttonHole = Cylinder( height, buttonD/2 ).centerX()
.rotateX(90).translateZ(thickness*2 + buttonD/2 +ledZ + 7)
return (solid+ shelf).color("Green") - wireSlot - opening - buttonHole
}
// Glue the LED to this base, and then glue this into the body.
// Drill holes as needed for the wires.
@Piece
fun ledBase() : Shape3d {
val profile = Square( width-6, height-0.5 )
.center() -
Square( 2,5 ).centerY().translate(-width/2+3, 12)
.rotate(180).also()
val floor = profile.extrude(thickness)
val spacer = Cube( 10, thickness*3, ledZ+thickness )
.centerX()
.translateY(-height/2+thickness)
.mirrorY().also()
return (floor+spacer).color("Violet")
}
fun battery() : Shape3d {
val body = Square( 26.5, 17.5 ).center().roundAllCorners(2)
.extrude(45.5)
val connectors = Cylinder(3,4).translateX(6)
.mirrorX().also()
.translateZ(45.5)
return body + connectors
}
override fun build() : Shape3d {
return front() +
back().mirrorZ().translateZ(86) +
ledBase().mirrorZ().bottomTo(thickness*2) +
battery().rotateZ(90).translateZ(30).previewOnly()
}
}