2.0.0 • Published 2 months ago

geom-sweep v2.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
2 months ago

geom-sweep

Extrudes a shape along a path.

npm.io

Installation

npm install geom-sweep

Usage

import sweep from "geom-sweep";

// Create a circle
const path = [];
for (let i = 0; i < 50; i++) {
  path.push([
    Math.cos((i / 50) * 2 * Math.PI),
    Math.sin((i / 50) * 2 * Math.PI),
    0,
  ]);
}
// Create a square
const shape = [
  [1, 1, 0],
  [-1, 1, 0],
  [-1, -1, 0],
  [1, -1, 0],
];

const geometry = sweep({ positions: path }, shape, {
  radius: 0.5,
  closed: true,
  initialNormal: [0, 0, 1],
  withFrames: true,
});
// => {
//   positions: Float32Array(756),
//   normals: Float32Array(756),
//   uvs: Float32Array(504),
//   cells: Uint32Array(1512),
//   tangents?: Float32Array(756),
//   binormals?: Float32Array(756),
// }

API

sweep(geometry, shape, options, out?): geometry

Parameters

  • geometry: { positions: TypedArray | Array | Array<[x, y, z]>, normals?: TypedArray | Array | Array<[x, y, z]>, tangents?: TypedArray | Array | Array<[x, y, z]>, binormals?: TypedArray | Array | Array<[x, y, z]> } – a geometry object with positions defining the path to extrude along.

  • shape: TypedArray | Array | Array<[x, y, z]> – positions defining the swept shape.

  • options.radius: number | [x, y] | Array<[x, y]> (default: 1) - extruded geometry radius, or separate x/y radii, or array of separate x/y radii for every path position (ie. taper).

  • options.closed: boolean (default: false) - is the path closed.
  • options.closedShape: boolean (default: true) - is the shape path closed.
  • options.caps: boolean (default: false) - add caps at the end.
  • options.initialNormal: Array (default: null) - provide a starting normal for the frames. Default to the direction of the minimum tangent component.
  • options.withFrames: boolean (default: false) - compute tangents and binormals.

  • out: { positions: TypedArray, normals?: TypedArray, tangents?: TypedArray, binormals?: TypedArray } (default: {}) – a geometry object with pre-allocated typed array with each attributes being a multiple of shape length * path vertices count + (caps ? 2 : 0).

Returns

geometry: { positions: TypedArray, normals: TypedArray, uvs: TypedArray, cells: TypedArray, tangents?: TypedArray, binormals: TypedArray } - the extruded geometry with optional tangents and binormals.

License

MIT. See license file.

2.0.0

2 months ago

1.0.0

1 year ago

0.3.2

1 year ago

0.3.1

6 years ago

0.3.0

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago