primitive-geometry

npm version stability-stable npm minzipped size dependencies types Conventional Commits styled with prettier linted with eslint license

Geometries for 3D rendering, including normals, UVs and cell indices (faces). Perfect if you want to supercharge your dependency folder... with 30KB of geometries.

paypal coinbase twitter

Installation

npm install primitive-geometry

Features

See difference with v1 here.

Usage

See the example and its source.

import Primitives from "primitive-geometry";

const quadGeometry = Primitives.quad();
const planeGeometry = Primitives.plane();

const cubeGeometry = Primitives.cube();
const roundedCubeGeometry = Primitives.roundedCube();

const cylinderGeometry = Primitives.cylinder();
const coneGeometry = Primitives.cone();
const capsuleGeometry = Primitives.capsule();

const sphereGeometry = Primitives.sphere();
const icosphereGeometry = Primitives.icosphere();
const ellipsoidGeometry = Primitives.ellipsoid();
const torusGeometry = Primitives.torus();

// without normals/uvs
const boxGeometry = Primitives.box();
const circleGeometry = Primitives.circle();

console.log(quadGeometry);
// {
//   positions: [ [x, y, z], [x, y, z], ... ],
//   cells: [ [a, b, c], [a, b, c], ... ],
//   uvs: [ [u, v], [u, v], ... ],
//   normals: [ [x, y, z], [x, y, z], ... ]
// }

API

Modules

index

Re-export all geometries and utils.

box
capsule
circle
cone
cube
cylinder
ellipsoid
icosphere
plane
quad
rounded-cube
sphere
torus
utils

Typedefs

BasicSimplicialComplex : Object

Geometry definition without normals and UVs.

SimplicialComplex : Object

Geometry definition.

index

Re-export all geometries and utils.

box

box([options]) ⇒ BasicSimplicialComplex

Kind: Exported function

Param Type Default
[options] BoxOptions {}

box~BoxOptions : Object

Kind: inner typedef of box
Properties

Name Type Default
[sx] number 1
[sy] number sx
[sz] number sx

capsule

capsule([options]) ⇒ SimplicialComplex

Kind: Exported function

Param Type Default
[options] CapsuleOptions {}

capsule~CapsuleOptions : Object

Kind: inner typedef of capsule
Properties

Name Type Default
[height] number 1
[radius] number 0.25
[nx] number 16
[ny] number 32

circle

circle([options]) ⇒ BasicSimplicialComplex

Kind: Exported function

Param Type Default
[options] BoxOptions {}

circle~BoxOptions : Object

Kind: inner typedef of circle
Properties

Name Type Default
[radius] number 0.5
[segments] number 32

cone

cone([options]) ⇒ SimplicialComplex

Kind: Exported function

Param Type Default
[options] ConeOptions {}

cone~ConeOptions : Object

Kind: inner typedef of cone
Properties

Name Type Default
[height] number 1
[radius] number 0.25
[nx] number 16
[ny] number 1
[capSegments] number 1
[capBase] boolean true

cube

cube([options]) ⇒ SimplicialComplex

Kind: Exported function

Param Type Default
[options] CubeOptions {}

cube~CubeOptions : Object

Kind: inner typedef of cube
Properties

Name Type Default
[sx] number 1
[sy] number sx
[sz] number sx
[nx] number 1
[ny] number nx
[nz] number nx

cylinder

cylinder([options]) ⇒ SimplicialComplex

Kind: Exported function

Param Type Default
[options] CylinderOptions {}

cylinder~CylinderOptions : Object

Kind: inner typedef of cylinder
Properties

Name Type Default
[height] number 1
[radius] number 0.25
[nx] number 16
[ny] number 1
[radiusApex] number radius
[capSegments] number 1
[capApex] boolean true
[capBase] boolean true

ellipsoid

ellipsoid([options]) ⇒ SimplicialComplex

Default to an oblate spheroid.

Kind: Exported function

Param Type Default
[options] EllipsoidOptions {}

ellipsoid~EllipsoidOptions : Object

Kind: inner typedef of ellipsoid
Properties

Name Type Default
[radius] number 0.5
[nx] number 32
[ny] number 16
[rx] number 1
[rx] number 0.5
[rz] number ry

icosphere

icosphere([options]) ⇒ SimplicialComplex

Kind: Exported function

Param Type Default
[options] IcosphereOptions {}

icosphere~IcosphereOptions : Object

Kind: inner typedef of icosphere
Properties

Name Type Default
[radius] number 0.5
[subdivisions] number 2

plane

plane([options]) ⇒ SimplicialComplex

Kind: Exported function

Param Type Default
[options] PlaneOptions {}

plane~PlaneOptions : Object

Kind: inner typedef of plane
Properties

Name Type Default
[sx] number 1
[sy] number sx
[nx] number 1
[ny] number nx

quad

quad([options]) ⇒ SimplicialComplex

Kind: Exported function

Param Type Default
[options] QuadOptions {}

quad~QuadOptions : Object

Kind: inner typedef of quad
Properties

Name Type Default
[scale] number 0.5

rounded-cube

roundedCube([options]) ⇒ SimplicialComplex

Kind: Exported function

Param Type Default
[options] module:rounded~RoundedCubeOptions {}

roundedCube~RoundedCubeOptions : Object

Kind: inner typedef of roundedCube
Properties

Name Type Default
[sx] number 1
[sy] number sx
[sz] number sx
[nx] number 16
[ny] number nx
[nz] number nx
[radius] number sx * 0.25

sphere

sphere([options]) ⇒ SimplicialComplex

Kind: Exported function

Param Type Default
[options] SphereOptions {}

sphere~SphereOptions : Object

Kind: inner typedef of sphere
Properties

Name Type Default
[radius] number 0.5
[nx] number 32
[ny] number 16

torus

torus([options]) ⇒ SimplicialComplex

Kind: Exported function

Param Type Default
[options] TorusOptions {}

torus~TorusOptions : Object

Kind: inner typedef of torus
Properties

Name Type Default
[radius] number 0.5
[segments] number 64
[minorRadius] number 0.1
[minorSegments] number 16
[arc] number 2 * Math.PI

utils

utils.TAU : number

Two times PI.

Kind: static constant of utils

utils.getCellsTypedArray ⇒ Uint8Array | Uint16Array | Uint32Array

Select cells typed array from a size determined by amount of vertices.

Kind: static constant of utils
See: MDN TypedArray objects

Param Type Description
size number The max value expected

utils.normalize(v) ⇒ Array.<number>

Normalize a vector 3.

Kind: static method of utils
Returns: Array.<number> - Normalized vector

Param Type Description
v Array.<number> Vector 3 array

utils.checkArguments(...args)

Ensure first argument passed to the primitive functions is an object

Kind: static method of utils

Param Type
...args *

utils.setTypedArrayType(type)

Enforce a typed array constructor for cells

Kind: static method of utils

Param Type
type Class.<Uint8Array> | Class.<Uint16Array> | Class.<Uint32Array>

BasicSimplicialComplex : Object

Geometry definition without normals and UVs.

Kind: global typedef
Properties

Name Type
positions Float32Array
cells Uint8Array | Uint16Array | Uint32Array

SimplicialComplex : Object

Geometry definition.

Kind: global typedef
Properties

Name Type
positions Float32Array
normals Float32Array
uvs Float32Array
cells Uint8Array | Uint16Array | Uint32Array

License

See original packages used in v1:

Differences with v1:

MIT. See license file.