Home

Awesome

extrude-polyline

unstable

img

Extrudes a 2D polyline with a given line thickness and the desired join/cap types. Tries to maintain visual consistency with HTML5 2D context stroking.

var polyline = [ [25, 25], [15, 60] ]
var stroke = require('extrude-polyline')({ 
    thickness: 20, 
    cap: 'square',
    join: 'bevel',
    miterLimit: 10
})

//builds a triangulated mesh from a polyline
var mesh = stroke.build(polyline)

The returned mesh is a simplicial complex.

{
    positions: [ [x,y], [x,y] ],
    cells: [ [a,b,c], [a,b,c] ]
}

variable thickness

Currently, to achieve variable thickness you can provide a mapThickness function to the stroke instance before building. By default, it will simply return the current thickness.

//create a falloff, so the thickness tapers toward the start of the path
stroke.mapThickness = function(point, index, points) {
    return this.thickness * index/(points.length-1)
}.bind(stroke)

demo

Git clone, npm install, then npm run test

Usage

NPM

stroke = Extrusion([opt])

Creates a new path builder with the given settings:

mesh = stroke.build(points)

Builds a stroke with the specified list of 2D points. Returns a simplicial complex.

Roadmap

Some features that could be useful to add at a later point. PRs welcome.

License

MIT, see LICENSE.md for details.