import uk.co.nickthecoder.foocad.smartextrusion.v1.* import static uk.co.nickthecoder.foocad.smartextrusion.v1.SmartExtrusion.* import uk.co.nickthecoder.foocad.cup.v1.* import static uk.co.nickthecoder.foocad.cup.v1.Cup.* class CutleryDrawer : Model { var baseThickness = 0.8 var thickness = 3 var wallThickness = 1.6 var defaultHeight = 50.0 val defaultWidth = 60 var drawerSize = Vector3( 430, 480, 110 ) var backDepth = 50 var knifeSize = Vector2( defaultWidth, 250 ) var forkSize = Vector2( defaultWidth, 220 ) var extraSize = Vector2( defaultWidth + thickness+wallThickness, drawerSize.y - backDepth - knifeSize.y - thickness * 4 ) var teaSize = Vector2( defaultWidth + thickness*2 - wallThickness, drawerSize.y -backDepth - knifeSize.y - thickness * 4) var miscSize = Vector2( defaultWidth * 2 - thickness*0 + wallThickness, drawerSize.y - backDepth - forkSize.y - thickness * 4) var sharpSize = Vector2( defaultWidth, knifeSize.y ) var bigSize = Vector3( 60, drawerSize.y - thickness * 2, defaultHeight ) meth inside() = Cube( drawerSize ).centerXY() meth outside( shape : Shape2d ) = outside( shape, defaultHeight ) meth outside( shape : Shape2d, height : double ) : Shape3d { var combined : Shape2d = null for ( path in shape.paths ) { combined = Polygon( path ).offset(wallThickness*2) + combined } val topStep = ProfileEdge.combine( ProfileEdge.chamferedStep(thickness-wallThickness, 4).reverse(), ProfileEdge.chamfer(1) ) val bottomStep = ProfileEdge.combine( ProfileEdge.chamferedStep(thickness-wallThickness, 3).reverse(), ProfileEdge.chamfer(0.5) ) return combined.toPolygon().offset(-wallThickness).roundAllCorners(1) .smartExtrude( height ) .top(topStep) .bottom( bottomStep ) } meth cutout( shapes : Shape2d ) = cutout( shapes, defaultHeight ) meth cutout( shapes : Shape2d, height : double ) : Shape3d { return shapes .roundAllCorners(10) .smartExtrude( height - baseThickness+ 0.1 ) .top( Chamfer(0.3).reverse() ) .bottom(Fillet(10)) .bottomTo( baseThickness ) } meth section( shape : Shape2d ) = section( shape, defaultHeight ) meth section( shape : Shape2d, height : double ) : Shape3d { return outside( shape, height ) - cutout( shape, height ) } @Piece meth back() : Shape3d { val inside = inside() val width = backRight().size.x - thickness*2 val back = Square( width, backDepth - thickness*2 ) return section( back ).centerXY() } @Piece meth backRight() : Shape3d { val knife = Square( knifeSize ) val fork = Square( forkSize ).leftTo( knife.right + wallThickness ).backTo( knife.back ) val spoon = Square( forkSize ).leftTo( fork.right + wallThickness ).backTo( knife.back ) val extra = Square( extraSize ).leftTo( spoon.right + wallThickness ).backTo( knife.back ) return section( knife + fork + spoon + extra ).centerXY() } @Piece meth frontRight() : Shape3d { val tea = Square( teaSize ) val misc = Square( miscSize ).leftTo( tea.right + wallThickness ) val sharp = Square( sharpSize ).leftTo( misc.right + wallThickness ) return section( tea + misc + sharp ).centerXY() } @Piece meth bigHalf() : Shape3d { val shape = Square( bigSize.x, bigSize.y ).centerY() val plain = section(shape, bigSize.z) val envelope = Square( bigSize.z, bigSize.y + 4 ) .roundCorner(1, bigSize.z - 1) .smartExtrude( bigSize.x + thickness*4 ) .rotateY(-90) .bottomTo(-1).leftTo( plain.left-1 ) // Doesn't work :-( val transform = BigTransform( 0.005 ) return plain.intersection( envelope ).transform( transform ) return plain.intersection( envelope ) } @Piece( about="Glue to the inside of the drawer to keep the pots in place. TPU" ) meth bumper() : Shape3d { return Square( 30, 6 ).roundAllCorners(2) .smartExtrude( 6 ) .top( Fillet( 3 ) ) } override fun build() : Shape3d { val inside = inside() val drawer = Square(drawerSize.x,drawerSize.y).offset(20).center() .cup(drawerSize.z + 20, 20) .bottomTo(-20) .previewOnly() val back = back().color( "Yellow" ).backTo( inside.back ).rightTo( inside.right ) val backRight = backRight().color( "Green" ).backTo( back.front ).rightTo( inside.right ) val frontRight = frontRight().color( "Orange" ).frontTo( inside.front ).rightTo( inside.right ) val big = bigHalf().mirrorY().also().rightTo( back.left ).color( "Red" ) return drawer + back + backRight + frontRight + big } } class BigTransform( val foo : double ) : Transform3d { override meth transform( from : Vector3 ) = Vector3( from.x, from.y, from.z - foo * from.x * from.z ) }