Exit Full View
ZipUp

/Bottles/FullWidthBottleTop.foocad

FullWidthBottleTop
FooCAD Source Code
import uk.co.nickthecoder.foocad.smartextrusion.v1.*
import static uk.co.nickthecoder.foocad.smartextrusion.v1.SmartExtrusion.*
import static uk.co.nickthecoder.foocad.chamferedextrude.v1.ChamferedExtrude.*
import static uk.co.nickthecoder.foocad.circular.v1.Circular.*

class BootsBottleTop : AbstractModel() {
    
    @Custom
    var capHeight = 3

    @Custom
    var capRadius = 30/2

    @Custom
    var extraHeight = 37

    @Custom
    var bottleRadius = 56/2

    @Custom
    var thickness = 2

    @Custom
    var chamfer = 1.5

    @Custom( lines=3 )
    var text = "SLOE  GIN"

    @Custom
    var fontSize = 24

    fun exterior() : Shape2d {
        return Circle(capRadius + thickness)
    }

    fun around( str : String ) :Shape3d {
        Quality.decrease(2)
        val text = Text( str, BOLD, fontSize).center()
        val extrudedText = text.offset(1).smartExtrude(2).bottom( Chamfer(2) )

        val result = extrudedText.mirrorX()
            .rotateX(90)
            .aroundCylinder( bottleRadius  + thickness )
            .rotateX(-90)
            .color("Red")

        return result.rotateX(90)
    }

    override fun build() : Shape3d {

        val smallest = Circle(capRadius)
        val mid = Circle( bottleRadius - thickness )
        val cham = Circle( bottleRadius - chamfer )
        val outside = Circle( bottleRadius )

        val cap = ExtrusionBuilder().apply {
            forward(capHeight + extraHeight)
            crossSection( smallest ) // Top of cap
            forward( -capHeight )
            crossSection() // Bottom of cap
            crossSection( mid ) // Interior
            forward( -extraHeight )
            crossSection()
            crossSection(cham)
            forward(chamfer)
            crossSection(outside)
            forward(capHeight+extraHeight-chamfer+thickness)
            crossSection() // Top pre-chamfer
            forward(chamfer)
            crossSection(cham) // Top post chamfer
        }.build()

        val text3d = around(text).translateZ((capHeight+thickness+extraHeight)/2)

        // Flip it upside down, so that the top of the cap is on the print bed.
        return (cap + text3d).rotateX(180).toOriginZ()
    }
}