ExtrusionBuilder

Creates a 3D shape from a 2D shape (or many 2D shapes).

You build a 3D shape by travelling along a path, and anywhere along that path you can specify a 2D cross-section using the crossSection method. This will be joined to the previous and next cross sections to form a tube. Initially, the path starts at the origin, heading upwards (along the Z axis). To change the direction of travel, use turnX and turnY. These turns are relative to our current direction of travel. To move forwards, use forward. Alternatively, you can use moveTo if you want to move to an absolute point ignoring the current position and direction of travel) Or instead use moveBy which uses the current position, but ignores the direction of travel.

It is common to use the same Shape2d for every call to crossSection, but you are free to use different shapes. In particular, you can use a single 'base' shape, and transform it, such as rotating, and scaling, or deforming it in other ways, such as rounding corners by various amounts. Get creative!

When you use different crossSection shapes, note that the 1st point is always joined to the other shape's first point. A heuristic determines how successive points are matched up.

At the end of the journey, complete the process using build. Alternatively, use buildClosed which will join the last cross section with the very first one to form a closed, torus shape.

If you wish to start or end the extrusion in a point, use the point method instead of crossSection.

The result of build and buildClosed is a Polyhedron, which is a huge mess of points and faces! The scad file will be practically unreadable! The nitty gritty of how it was created (including the shapes passed to crossSection) are lost.

Currently all of the crossSections must be simple shapes with no holes (only one path in Shape2d.paths). So if you want an extrusion with a hole in it, create two extrusions, and use Shape3d.difference. If you want a hollow extrusion with a base (such as a cup, or a bowl), then use a simple cross section without a hole. Extrude upwards, shrink the cross section a little and head back down. See the goblet in Examples/ExtrudeEtc.foocad.

The simplest shapes you can create using ExtrusionBuilder are cones and drums, so there are simple to use static methods cone and drum.

See ExtrudeEtc.foocad for example uses (from the Help menu in the GUI or in src/dist/examples directory).

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
object Companion
Link copied to clipboard
inner class ExtrusionPoint(val point: Vector3, val original: Vector2, val pointIndex: Int, val averageAngle: Double)

Properties

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun build(convexity: Int?): Polyhedron
Link copied to clipboard
Link copied to clipboard
fun crossSection(offset: Double)

Add a new segment to the extrusion.

fun crossSection(profile: Shape2d, transform: Matrix2d?): ExtrusionBuilder

Add a new segment to the extrusion. If transform is not null, then all of the profile's points are transformed by the transform matrix.

Link copied to clipboard

Note, this does NOT ensure that the Z axis twist is taken into account. Most of the time you will want to use direction (Vector3,Vector3) instead, which DOES adjust the z axis twist.

fun direction(normal: Vector3, along: Vector3)

Rotates according to normal, but the z Axis twist is also adjusted according to direction along.

Link copied to clipboard

Move forward by the z component of vector in the direction of the normal, and also shift across by the x and y components of vector (using the normal's direction as our coordinated system).

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Appends a single point. This is usually the first or last item, and will create a cone-like effect.

Link copied to clipboard

Calculates the amount that the profile should be scaled by to keep the cross section of the extrusion constant when it turns sharply.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

This has a similar effect as rotating the 2D shape passed into crossSection, but it also changes the coordinate system on further calls to turnX, turnY.