Skip to content

Examples

Tomas Franzén edited this page Jul 3, 2025 · 14 revisions

Chamfer

image

await Model("chamfer") {
    Circle(diameter: 12)
        .clonedAt(x: 8)
        .rounded(insideRadius: 2)
        .extruded(height: 7, topEdge: .chamfer(depth: 2))
}

Colors and materials

image

await Model("stack-materials") {
    Stack(.x, spacing: 2, alignment: .center, .bottom) {
        Sphere(diameter: 10)
            .colored(.darkOrange)
        Cylinder(diameter: 8, height: 12)
            .withMaterial(.glossyPlastic(.mediumSeaGreen))
        Box(x: 12, y: 8, z: 15)
            .withMaterial(.steel)
    }
}

Swept text

image

await Model("swept-text") {
    Text("Cadova")
        .withFont("Futura", style: "Condensed Medium", size: 10)
        .wrappedAroundCircle(spanning: 230°..<310°)
        .aligned(at: .centerX, .bottom)
        .swept(along: BezierPath {
            curve(controlX: 20, controlY: 10, controlZ: 3, endX: 20, endY: 30, endZ: 12)
        })
}

Loft

image

await Model("loft") {
    Loft(.resampled(.easeInOut)) {
        layer(z: 0) {
            Ring(outerDiameter: 20, innerDiameter: 12)
        }
        layer(z: 30) {
            Rectangle(x: 25, y: 6)
                .aligned(at: .center)
                .cloned { $0.rotated(90°) }
                .subtracting {
                    RegularPolygon(sideCount: 8, circumradius: 2)
                }
        }
        layer(z: 35) {
            Ring(outerDiameter: 12, innerDiameter: 10)
        }
    }
}

Circular overhang

image

Using overhangSafe(_:) makes a circle or cylinder extend its shape to work better with FDM 3D printing. The shapes are extended in the right direction automatically, using the geometry's world transform, pointing downward for additive geometry and upward for subtractive geometry (holes).

await Model("circular-overhang") {
    Stack(.x, spacing: 5) {
        Box(20)
            .aligned(at: .centerXY)
            .subtracting {
                Cylinder(diameter: 10, height: 20)
                    .overhangSafe(.teardrop)
            }
            .rotated(x: -90°)

        Circle(diameter: 20)
            .overhangSafe(.bridge)
            .extruded(height: 20)
            .rotated(x: -90°)
    }
    .aligned(at: .minZ)
}

Clone this wiki locally