geom-normals
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

geom-normals

Compute normals for a simplicial complex geometry based on faces/cells information.

Installation

npm install geom-normals

Usage

import normals from "geom-normals";
import { plane } from "primitive-geometry";

const geometry = plane();

// Modify geometry.positions
// ...

// Recompute normals
normals(geometry.positions, geometry.cells, geometry.normals);

API

normals(positions, cells, [out]): normals

Parameters

  • positions: TypedArray | Array | Array<[x, y, z]> – simplicial complex geometry positions (eg. new Float32Array([x, y, z, x, y, z, ...])/new Array(x, y, z, x, y, z, ...) or new Array([x, y, z], [x, y, z], ...))
  • cells: TypedArray | Array | Array<[x, y, z]> – simplicial complex geometry cells (eg. new Uint32Array([a, b, c, a, b, c, ...])/new Array(a, b, c, a, b, c, ...) or new Array([a, b, c], [a, b, c], ...))
  • out (optional): TypedArray | Array | Array<[x, y, z]> – simplicial complex geometry normals to write to (eg. new Float32Array([x, y, z, x, y, z, ...])/new Array(x, y, z, x, y, z, ...) or new Array([x, y, z], [x, y, z], ...))

Returns

  • normals: TypedArray | Array | Array<[x, y, z]> – The normals parameter array updated (or created) with per vertex computed normals.

Note: If there are two vertices with the same position but different index there will be discontinuity (hard edge)

License

MIT. See license file.

Package Sidebar

Install

npm i geom-normals

Weekly Downloads

8

Version

2.1.0

License

MIT

Unpacked Size

6.95 kB

Total Files

6

Last publish

Collaborators

  • vorg