Code Monkey home page Code Monkey logo

geom-sweep's Introduction

geom-sweep

Extrudes a shape along a path.

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(path, shape, options);
// => {
//   positions: Float32Array(756),
//   normals: Float32Array(756),
//   uvs: Float32Array(504),
//   cells: Uint32Array(1512),
//   tangents: Float32Array(756),
//   frames: [{...}, {...}]
// }

API

sweep(path, shape, options): geometry

Parameters

  • path: Array<[x, y, z]> โ€“ positions defining the path to extrude along

  • shape: Array<[x, y, z]> โ€“ positions defining the swept shape

  • options.radius: number (default: 1) - extruded geometry radius.

  • 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.pathTangents: Array (default: undefined) - pass pre-computed path tangents.

  • options.frames: Array<{ normal, tangent, bitangent }> (default: undefined) - pass pre-computed frenet serret frames.

Returns

geometry: { positions: TypedArray|Array, normals: TypedArray|Array, uvs: TypedArray|Array, cells: TypedArray|Array, tangents: TypedArray|Array, frames: Array<{ normal, tangent, bitangent }> } - the extruded geometry with tangents and frenet serret frames.

License

MIT. See license file.

geom-sweep's People

Contributors

vorg avatar dmnsgn avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.