Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

geom-normals

vorg40MIT2.1.0TypeScript support: included

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

geom, normals, simplicial, complex, 3d, pex, geometry, webgl

readme

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.

changelog

Changelog

All notable changes to this project will be documented in this file. See commit-and-tag-version for commit guidelines.

2.1.0 (2024-03-14)

Features

  • add support for flat arrays (1ed5976)

2.0.1 (2023-07-20)

Performance Improvements

  • enhance typed array code branch (9b59b82)

2.0.0 (2023-02-02)

Features

  • add support for typed array geometries (87b97f8)

BREAKING CHANGES

  • use ESM