https://github.com/dmnsgn/primitive-geometry
Geometries for 3D rendering, including normals, UVs and cell indices (faces). Perfect if you want to supercharge your dependency folder... with 30KB of geometries.
https://github.com/dmnsgn/primitive-geometry
box capsule circle cone cube cylinder ellipsoid geometry gl glsl icosphere mesh plane primitive quad simplicial-complex sphere stackgl torus webgl
Last synced: about 2 months ago
JSON representation
Geometries for 3D rendering, including normals, UVs and cell indices (faces). Perfect if you want to supercharge your dependency folder... with 30KB of geometries.
- Host: GitHub
- URL: https://github.com/dmnsgn/primitive-geometry
- Owner: dmnsgn
- License: mit
- Created: 2018-10-21T14:41:48.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-06-20T10:30:42.000Z (12 months ago)
- Last Synced: 2025-04-09T19:18:40.897Z (about 2 months ago)
- Topics: box, capsule, circle, cone, cube, cylinder, ellipsoid, geometry, gl, glsl, icosphere, mesh, plane, primitive, quad, simplicial-complex, sphere, stackgl, torus, webgl
- Language: JavaScript
- Homepage: https://dmnsgn.github.io/primitive-geometry/
- Size: 46.9 MB
- Stars: 100
- Watchers: 2
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# primitive-geometry
[](https://www.npmjs.com/package/primitive-geometry)
[](https://www.npmjs.com/package/primitive-geometry)
[](https://bundlephobia.com/package/primitive-geometry)
[](https://github.com/dmnsgn/primitive-geometry/blob/main/package.json)
[](https://github.com/microsoft/TypeScript)
[](https://conventionalcommits.org)
[](https://github.com/prettier/prettier)
[](https://github.com/eslint/eslint)
[](https://github.com/dmnsgn/primitive-geometry/blob/main/LICENSE.md)Geometries for 3D rendering, including normals, UVs and cell indices (faces). Perfect if you want to supercharge your dependency folder... with 30KB of geometries.
[](https://paypal.me/dmnsgn)
[](https://commerce.coinbase.com/checkout/56cbdf28-e323-48d8-9c98-7019e72c97f3)
[](https://twitter.com/dmnsgn)
## Installation
```bash
npm install primitive-geometry
```## Features
- Common API: options object in, simplicial complex out
- Outputs TypedArray (`Float32Array` for geometry data and `Uint8Array|Uint16Array|Uint32Array` for cells)
- Zero dependency
- Same parameters naming: radius (or rx/ry/rz), scale (or height/sx/sy/sz), segments (or nx/ny/nz) and a few specific parameters for icosphere/cylinder/cone/torus.
- Different **Elliptical mappings**: see the [comparison images](examples/elliptical-mapping/elliptical-mapping.md) and the [demo](https://dmnsgn.github.io/primitive-geometry/?id=elliptical-mapping).See difference with v1 [here](#License).
## Usage
See the [example](https://dmnsgn.github.io/primitive-geometry/) and its [source](examples/index.js).
```js
import Primitives from "primitive-geometry";const quadGeometry = Primitives.quad({
scale: 0.5,
});
console.log(quadGeometry);
// {
// positions: Float32Array [x, y, z, x, y, z, ...],
// normals: Float32Array [x, y, z, x, y, z, ...]
// uvs: Float32Array [u, v, u, v, ...],
// cells: Uint8/16/32/Array [a, b, c, a, b, c, ...],
// }
const planeGeometry = Primitives.plane({
sx: 1,
sy: 1,
nx: 1,
ny: 1,
direction: "z",
quads: false,
});
const roundedRectangleGeometry = Primitives.roundedRectangle({
sx: 1,
sy: 1,
nx: 1,
ny: 1,
radius: 0.25,
roundSegments: 8,
edgeSegments: 1,
});
const stadiumGeometry = Primitives.stadium({
sx: 1,
sy: 0.5,
nx: 1,
ny: 1,
roundSegments: 8,
edgeSegments: 1,
});const ellipseGeometry = Primitives.ellipse({
sx: 1,
sy: 0.5,
radius: 0.5,
segments: 32,
innerSegments: 16,
theta: Math.PI * 2,
thetaOffset: 0,
mapping: mappings.elliptical,
});
const disc = Primitives.disc({
radius: 0.5,
segments: 32,
innerSegments: 16,
theta: Math.PI * 2,
thetaOffset: 0,
mapping: mappings.concentric,
});
const superellipse = Primitives.superellipse({
sx: 1,
sy: 0.5,
radius: 0.5,
segments: 32,
innerSegments: 16,
theta: Math.PI * 2,
thetaOffset: 0,
mapping: mappings.lamé,
m: 2,
n: 2,
});
const squircle = Primitives.squircle({
sx: 1,
sy: 1,
radius: 0.5,
segments: 128,
innerSegments: 16,
theta: Math.PI * 2,
thetaOffset: 0,
mapping: mappings.fgSquircular,
squareness: 0.95,
});
const annulus = Primitives.annulus({
radius: 0.5,
segments: 32,
innerSegments: 16,
theta: Math.PI * 2,
thetaOffset: 0,
innerRadius: 0.25,
mapping: mappings.concentric,
});
const reuleux = Primitives.reuleux({
radius: 0.5,
segments: 32,
innerSegments: 16,
theta: Math.PI * 2,
thetaOffset: 0,
mapping: mappings.concentric,
n: 3,
});const cubeGeometry = Primitives.cube({
sx: 1,
sy: 1,
sz: 1,
nx: 1,
ny: 1,
nz: 1,
});
const roundedCubeGeometry = Primitives.roundedCube({
sx: 1,
sy: 1,
sz: 1,
nx: 1,
ny: 1,
nz: 1,
radius: 0.25,
roundSegments: 8,
edgeSegments: 1,
});const sphereGeometry = Primitives.sphere({
radius: 0.5,
nx: 32,
ny: 16,
theta: Math.PI,
thetaOffset: 0,
phi: Math.PI * 2,
phiOffset: 0,
});
const icosphereGeometry = Primitives.icosphere({
radius: 0.5,
subdivisions: 2,
});
const ellipsoidGeometry = Primitives.ellipsoid({
radius: 1,
nx: 32,
ny: 16,
rx: 0.5,
ry: 0.25,
rz: 0.25,
theta: Math.PI,
thetaOffset: 0,
phi: Math.PI * 2,
phiOffset: 0,
});const cylinderGeometry = Primitives.cylinder({
height: 1,
radius: 0.25,
nx: 16,
ny: 1,
radiusApex: 0.25,
capSegments: 1,
capApex: true,
capBase: true,
capBaseSegments: 1,
phi: Math.PI * 2,
});
const coneGeometry = Primitives.cone({
height: 1,
radius: 0.25,
nx: 16,
ny: 1,
capSegments: 1,
capBase: true,
theta: Math.PI * 2,
});
const capsuleGeometry = Primitives.capsule({
height: 0.5,
radius: 0.25,
nx: 16,
ny: 1,
roundSegments: 16,
theta: Math.PI * 2,
});
const torusGeometry = Primitives.torus({
radius: 0.4,
segments: 64,
minorRadius: 0.1,
minorSegments: 32,
theta: Math.PI * 2,
thetaOffset: 0,
phi: Math.PI * 2,
phiOffset: 0,
});const tetrahedron = Primitives.tetrahedron({
radius: 0.5,
});
const icosahedron = Primitives.icosahedron({
radius: 0.5,
});// without normals/uvs
const boxGeometry = Primitives.box({
sx: 1,
sy: 1,
sz: 1,
});
const circleGeometry = Primitives.circle({
radius: 0.5,
segments: 32,
closed: false,
theta: Math.PI * 2,
thetaOffset: 0,
});
```## API
## Modules
- index
-
Re-export all geometries, UV mappings functions and utils.
- annulus
- box
- capsule
- circle
- cone
- cube
- cylinder
- disc
- ellipse
- ellipsoid
- icosahedron
- icosphere
- mappings
- plane
- quad
- reuleux
- roundedCube
- roundedRectangle
- sphere
- squircle
- stadium
- superellipse
- tetrahedron
- torus
- utils
## Typedefs
-
BasicSimplicialComplex :object
-
Geometry definition without normals and UVs.
-
SimplicialComplex :object
-
Geometry definition.
## index
Re-export all geometries, UV mappings functions and utils.
## annulus
- [annulus](#module_annulus)
- [annulus([options])](#exp_module_annulus--annulus) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~AnnulusOptions](#module_annulus--annulus..AnnulusOptions) : object
### annulus([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
**Kind**: Exported function
| Param | Type | Default |
| --------- | ----------------------------------------------------------------------- | --------------- |
| [options] | [AnnulusOptions
](#module_annulus--annulus..AnnulusOptions) | {}
|
#### annulus~AnnulusOptions : object
**Kind**: inner typedef of [annulus
](#exp_module_annulus--annulus)
**Properties**
| Name | Type | Default |
| --------------- | --------------------- | -------------------------------- |
| [radius] | number
| 0.5
|
| [segments] | number
| 32
|
| [innerSegments] | number
| 16
|
| [theta] | number
| TAU
|
| [thetaOffset] | number
| 0
|
| [innerRadius] | number
| radius \* 0.5
|
| [mapping] | function
| mappings.concentric
|
## box
- [box](#module_box)
- [box([options])](#exp_module_box--box) ⇒ [BasicSimplicialComplex
](#BasicSimplicialComplex) ⏏
- [~BoxOptions](#module_box--box..BoxOptions) : object
### box([options]) ⇒ [BasicSimplicialComplex
](#BasicSimplicialComplex) ⏏
**Kind**: Exported function
| Param | Type | Default |
| --------- | ------------------------------------------------------- | --------------- |
| [options] | [BoxOptions
](#module_box--box..BoxOptions) | {}
|
#### box~BoxOptions : object
**Kind**: inner typedef of [box
](#exp_module_box--box)
**Properties**
| Name | Type | Default |
| ---- | ------------------- | --------------- |
| [sx] | number
| 1
|
| [sy] | number
| sx
|
| [sz] | number
| sx
|
## capsule
- [capsule](#module_capsule)
- [capsule([options])](#exp_module_capsule--capsule) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~CapsuleOptions](#module_capsule--capsule..CapsuleOptions) : object
### capsule([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
**Kind**: Exported function
| Param | Type | Default |
| --------- | ----------------------------------------------------------------------- | --------------- |
| [options] | [CapsuleOptions
](#module_capsule--capsule..CapsuleOptions) | {}
|
#### capsule~CapsuleOptions : object
**Kind**: inner typedef of [capsule
](#exp_module_capsule--capsule)
**Properties**
| Name | Type | Default |
| --------------- | ------------------- | ----------------- |
| [height] | number
| 0.5
|
| [radius] | number
| 0.25
|
| [nx] | number
| 16
|
| [ny] | number
| 1
|
| [roundSegments] | number
| 32
|
| [phi] | number
| TAU
|
## circle
- [circle](#module_circle)
- [circle([options])](#exp_module_circle--circle) ⇒ [BasicSimplicialComplex
](#BasicSimplicialComplex) ⏏
- [~CircleOptions](#module_circle--circle..CircleOptions) : object
### circle([options]) ⇒ [BasicSimplicialComplex
](#BasicSimplicialComplex) ⏏
**Kind**: Exported function
| Param | Type | Default |
| --------- | ------------------------------------------------------------------- | --------------- |
| [options] | [CircleOptions
](#module_circle--circle..CircleOptions) | {}
|
#### circle~CircleOptions : object
**Kind**: inner typedef of [circle
](#exp_module_circle--circle)
**Properties**
| Name | Type | Default |
| ------------- | -------------------- | ------------------ |
| [radius] | number
| 0.5
|
| [segments] | number
| 32
|
| [theta] | number
| TAU
|
| [thetaOffset] | number
| 0
|
| [closed] | boolean
| false
|
## cone
- [cone](#module_cone)
- [cone([options])](#exp_module_cone--cone) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~ConeOptions](#module_cone--cone..ConeOptions) : object
### cone([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
**Kind**: Exported function
| Param | Type | Default |
| --------- | ----------------------------------------------------------- | --------------- |
| [options] | [ConeOptions
](#module_cone--cone..ConeOptions) | {}
|
#### cone~ConeOptions : object
**Kind**: inner typedef of [cone
](#exp_module_cone--cone)
**Properties**
| Name | Type | Default |
| ------------- | -------------------- | ----------------- |
| [height] | number
| 1
|
| [radius] | number
| 0.25
|
| [nx] | number
| 16
|
| [ny] | number
| 1
|
| [capSegments] | number
| 1
|
| [capBase] | boolean
| true
|
| [phi] | number
| TAU
|
## cube
- [cube](#module_cube)
- [cube([options])](#exp_module_cube--cube) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~CubeOptions](#module_cube--cube..CubeOptions) : object
### cube([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
**Kind**: Exported function
| Param | Type | Default |
| --------- | ----------------------------------------------------------- | --------------- |
| [options] | [CubeOptions
](#module_cube--cube..CubeOptions) | {}
|
#### cube~CubeOptions : object
**Kind**: inner typedef of [cube
](#exp_module_cube--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](#module_cylinder)
- [cylinder([options])](#exp_module_cylinder--cylinder) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~CylinderOptions](#module_cylinder--cylinder..CylinderOptions) : object
### cylinder([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
**Kind**: Exported function
| Param | Type | Default |
| --------- | --------------------------------------------------------------------------- | --------------- |
| [options] | [CylinderOptions
](#module_cylinder--cylinder..CylinderOptions) | {}
|
#### cylinder~CylinderOptions : object
**Kind**: inner typedef of [cylinder
](#exp_module_cylinder--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
|
| [phi] | number
| TAU
|
## disc
- [disc](#module_disc)
- [disc([options])](#exp_module_disc--disc) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~DiscOptions](#module_disc--disc..DiscOptions) : object
### disc([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
**Kind**: Exported function
| Param | Type | Default |
| --------- | ----------------------------------------------------------- | --------------- |
| [options] | [DiscOptions
](#module_disc--disc..DiscOptions) | {}
|
#### disc~DiscOptions : object
**Kind**: inner typedef of [disc
](#exp_module_disc--disc)
**Properties**
| Name | Type | Default |
| --------------- | --------------------- | -------------------------------- |
| [radius] | number
| 0.5
|
| [segments] | number
| 32
|
| [innerSegments] | number
| 16
|
| [theta] | number
| TAU
|
| [thetaOffset] | number
| 0
|
| [mapping] | function
| mappings.concentric
|
## ellipse
- [ellipse](#module_ellipse)
- [ellipse([options])](#exp_module_ellipse--ellipse) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~EllipseOptions](#module_ellipse--ellipse..EllipseOptions) : object
### ellipse([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
**Kind**: Exported function
| Param | Type | Default |
| --------- | ----------------------------------------------------------------------- | --------------- |
| [options] | [EllipseOptions
](#module_ellipse--ellipse..EllipseOptions) | {}
|
#### ellipse~EllipseOptions : object
**Kind**: inner typedef of [ellipse
](#exp_module_ellipse--ellipse)
**Properties**
| Name | Type | Default |
| --------------- | --------------------- | -------------------------------- |
| [sx] | number
| 1
|
| [sy] | number
| 0.5
|
| [radius] | number
| 0.5
|
| [segments] | number
| 32
|
| [innerSegments] | number
| 16
|
| [theta] | number
| TAU
|
| [thetaOffset] | number
| 0
|
| [mapping] | function
| mappings.elliptical
|
## ellipsoid
- [ellipsoid](#module_ellipsoid)
- [ellipsoid([options])](#exp_module_ellipsoid--ellipsoid) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~EllipsoidOptions](#module_ellipsoid--ellipsoid..EllipsoidOptions) : object
### ellipsoid([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
Default to an oblate spheroid.
**Kind**: Exported function
| Param | Type | Default |
| --------- | ------------------------------------------------------------------------------- | --------------- |
| [options] | [EllipsoidOptions
](#module_ellipsoid--ellipsoid..EllipsoidOptions) | {}
|
#### ellipsoid~EllipsoidOptions : object
**Kind**: inner typedef of [ellipsoid
](#exp_module_ellipsoid--ellipsoid)
**Properties**
| Name | Type | Default |
| ------------- | ------------------- | -------------------- |
| [radius] | number
| 0.5
|
| [nx] | number
| 32
|
| [ny] | number
| 16
|
| [rx] | number
| 1
|
| [ry] | number
| 0.5
|
| [rz] | number
| ry
|
| [theta] | number
| Math.PI
|
| [thetaOffset] | number
| 0
|
| [phi] | number
| TAU
|
| [phiOffset] | number
| 0
|
## icosahedron
- [icosahedron](#module_icosahedron)
- [icosahedron([options])](#exp_module_icosahedron--icosahedron) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~IcosahedronOptions](#module_icosahedron--icosahedron..IcosahedronOptions) : object
### icosahedron([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
**Kind**: Exported function
| Param | Type | Default |
| --------- | --------------------------------------------------------------------------------------- | --------------- |
| [options] | [IcosahedronOptions
](#module_icosahedron--icosahedron..IcosahedronOptions) | {}
|
#### icosahedron~IcosahedronOptions : object
**Kind**: inner typedef of [icosahedron
](#exp_module_icosahedron--icosahedron)
**Properties**
| Name | Type | Default |
| -------- | ------------------- | ---------------- |
| [radius] | number
| 0.5
|
## icosphere
- [icosphere](#module_icosphere)
- [icosphere([options])](#exp_module_icosphere--icosphere) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~IcosphereOptions](#module_icosphere--icosphere..IcosphereOptions) : object
### icosphere([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
**Kind**: Exported function
| Param | Type | Default |
| --------- | ------------------------------------------------------------------------------- | --------------- |
| [options] | [IcosphereOptions
](#module_icosphere--icosphere..IcosphereOptions) | {}
|
#### icosphere~IcosphereOptions : object
**Kind**: inner typedef of [icosphere
](#exp_module_icosphere--icosphere)
**Properties**
| Name | Type | Default |
| -------------- | ------------------- | ---------------- |
| [radius] | number
| 0.5
|
| [subdivisions] | number
| 2
|
## mappings
## plane
- [plane](#module_plane)
- [plane([options])](#exp_module_plane--plane) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~PlaneOptions](#module_plane--plane..PlaneOptions) : object
- [~PlaneDirection](#module_plane--plane..PlaneDirection) : "x"
\| "-x"
\| "y"
\| "-y"
\| "z"
\| "-z"
### plane([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
**Kind**: Exported function
| Param | Type | Default |
| --------- | --------------------------------------------------------------- | --------------- |
| [options] | [PlaneOptions
](#module_plane--plane..PlaneOptions) | {}
|
#### plane~PlaneOptions : object
**Kind**: inner typedef of [plane
](#exp_module_plane--plane)
**Properties**
| Name | Type | Default |
| ----------- | ------------------------------------------------------------------- | -------------------------- |
| [sx] | number
| 1
|
| [sy] | number
| sx
|
| [nx] | number
| 1
|
| [ny] | number
| nx
|
| [direction] | [PlaneDirection
](#module_plane--plane..PlaneDirection) | "z"
|
| [quads] | boolean
| false
|
#### plane~PlaneDirection : "x"
\| "-x"
\| "y"
\| "-y"
\| "z"
\| "-z"
**Kind**: inner typedef of [plane
](#exp_module_plane--plane)
## quad
- [quad](#module_quad)
- [quad([options])](#exp_module_quad--quad) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~QuadOptions](#module_quad--quad..QuadOptions) : object
### quad([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
**Kind**: Exported function
| Param | Type | Default |
| --------- | ----------------------------------------------------------- | --------------- |
| [options] | [QuadOptions
](#module_quad--quad..QuadOptions) | {}
|
#### quad~QuadOptions : object
**Kind**: inner typedef of [quad
](#exp_module_quad--quad)
**Properties**
| Name | Type | Default |
| ------- | ------------------- | ---------------- |
| [scale] | number
| 0.5
|
## reuleux
- [reuleux](#module_reuleux)
- [reuleux([options])](#exp_module_reuleux--reuleux) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~ReuleuxOptions](#module_reuleux--reuleux..ReuleuxOptions) : object
### reuleux([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
**Kind**: Exported function
**See**: [Parametric equations for regular and Reuleaux polygons](https://tpfto.wordpress.com/2011/09/15/parametric-equations-for-regular-and-reuleaux-polygons/)
| Param | Type | Default |
| --------- | ----------------------------------------------------------------------- | --------------- |
| [options] | [ReuleuxOptions
](#module_reuleux--reuleux..ReuleuxOptions) | {}
|
#### reuleux~ReuleuxOptions : object
**Kind**: inner typedef of [reuleux
](#exp_module_reuleux--reuleux)
**Properties**
| Name | Type | Default |
| --------------- | --------------------- | -------------------------------- |
| [radius] | number
| 0.5
|
| [segments] | number
| 32
|
| [innerSegments] | number
| 16
|
| [theta] | number
| TAU
|
| [thetaOffset] | number
| 0
|
| [mapping] | function
| mappings.concentric
|
| [n] | number
| 3
|
## roundedCube
- [roundedCube](#module_roundedCube)
- [roundedCube([options])](#exp_module_roundedCube--roundedCube) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~RoundedCubeOptions](#module_roundedCube--roundedCube..RoundedCubeOptions) : object
### roundedCube([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
**Kind**: Exported function
| Param | Type | Default |
| --------- | --------------------------------------------------------------------------------------- | --------------- |
| [options] | [RoundedCubeOptions
](#module_roundedCube--roundedCube..RoundedCubeOptions) | {}
|
#### roundedCube~RoundedCubeOptions : object
**Kind**: inner typedef of [roundedCube
](#exp_module_roundedCube--roundedCube)
**Properties**
| Name | Type | Default |
| --------------- | ------------------- | ----------------------- |
| [sx] | number
| 1
|
| [sy] | number
| sx
|
| [sz] | number
| sx
|
| [nx] | number
| 1
|
| [ny] | number
| nx
|
| [nz] | number
| nx
|
| [radius] | number
| sx \* 0.25
|
| [roundSegments] | number
| 8
|
| [edgeSegments] | number
| 1
|
## roundedRectangle
- [roundedRectangle](#module_roundedRectangle)
- [roundedRectangle([options])](#exp_module_roundedRectangle--roundedRectangle) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~RoundedCubeOptions](#module_roundedRectangle--roundedRectangle..RoundedCubeOptions) : object
### roundedRectangle([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
**Kind**: Exported function
| Param | Type | Default |
| --------- | ------------------------------------------------------------------------------------------------- | --------------- |
| [options] | [RoundedCubeOptions
](#module_roundedRectangle--roundedRectangle..RoundedCubeOptions) | {}
|
#### roundedRectangle~RoundedCubeOptions : object
**Kind**: inner typedef of [roundedRectangle
](#exp_module_roundedRectangle--roundedRectangle)
**Properties**
| Name | Type | Default |
| --------------- | ------------------- | ----------------------- |
| [sx] | number
| 1
|
| [sy] | number
| sx
|
| [nx] | number
| 1
|
| [ny] | number
| nx
|
| [radius] | number
| sx \* 0.25
|
| [roundSegments] | number
| 8
|
| [edgeSegments] | number
| 1
|
## sphere
- [sphere](#module_sphere)
- [sphere([options])](#exp_module_sphere--sphere) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~SphereOptions](#module_sphere--sphere..SphereOptions) : object
### sphere([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
**Kind**: Exported function
| Param | Type | Default |
| --------- | ------------------------------------------------------------------- | --------------- |
| [options] | [SphereOptions
](#module_sphere--sphere..SphereOptions) | {}
|
#### sphere~SphereOptions : object
**Kind**: inner typedef of [sphere
](#exp_module_sphere--sphere)
**Properties**
| Name | Type | Default |
| ------------- | ------------------- | -------------------- |
| [radius] | number
| 0.5
|
| [nx] | number
| 32
|
| [ny] | number
| 16
|
| [theta] | number
| Math.PI
|
| [thetaOffset] | number
| 0
|
| [phi] | number
| TAU
|
| [phiOffset] | number
| 0
|
## squircle
- [squircle](#module_squircle)
- [squircle([options])](#exp_module_squircle--squircle) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~SquircleOptions](#module_squircle--squircle..SquircleOptions) : object
### squircle([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
Fernández-Guasti squircle
**Kind**: Exported function
**See**: [Squircular Calculations – Chamberlain Fong](https://arxiv.org/vc/arxiv/papers/1604/1604.02174v1.pdf)
| Param | Type | Default |
| --------- | --------------------------------------------------------------------------- | --------------- |
| [options] | [SquircleOptions
](#module_squircle--squircle..SquircleOptions) | {}
|
#### squircle~SquircleOptions : object
**Kind**: inner typedef of [squircle
](#exp_module_squircle--squircle)
**Properties**
| Name | Type | Default | Description |
| --------------- | --------------------- | ---------------------------------- | ----------------------- |
| [sx] | number
| 1
| |
| [sy] | number
| 1
| |
| [radius] | number
| 0.5
| |
| [segments] | number
| 128
| |
| [innerSegments] | number
| 16
| |
| [theta] | number
| TAU
| |
| [thetaOffset] | number
| 0
| |
| [mapping] | function
| mappings.fgSquircular
| |
| [squareness] | number
| 0.95
| Squareness (0 < s <= 1) |
## stadium
- [stadium](#module_stadium)
- [stadium([options])](#exp_module_stadium--stadium) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~StadiumOptions](#module_stadium--stadium..StadiumOptions) : object
### stadium([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
**Kind**: Exported function
| Param | Type | Default |
| --------- | ----------------------------------------------------------------------- | --------------- |
| [options] | [StadiumOptions
](#module_stadium--stadium..StadiumOptions) | {}
|
#### stadium~StadiumOptions : object
**Kind**: inner typedef of [stadium
](#exp_module_stadium--stadium)
**Properties**
| Name | Type | Default |
| --------------- | ------------------- | --------------- |
| [sx] | number
| 1
|
| [sy] | number
| sx
|
| [nx] | number
| 1
|
| [ny] | number
| nx
|
| [roundSegments] | number
| 8
|
| [edgeSegments] | number
| 1
|
## superellipse
- [superellipse](#module_superellipse)
- [superellipse([options])](#exp_module_superellipse--superellipse) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~SuperellipseOptions](#module_superellipse--superellipse..SuperellipseOptions) : object
### superellipse([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
Lamé curve
See elliptical-mapping example for a few special cases
**Kind**: Exported function
**See**
- [Wolfram MathWorld – Superellipse](https://mathworld.wolfram.com/Superellipse.html)
- [Wikipedia – Superellipse](https://en.wikipedia.org/wiki/Superellipse)
| Param | Type | Default |
| --------- | ------------------------------------------------------------------------------------------- | --------------- |
| [options] | [SuperellipseOptions
](#module_superellipse--superellipse..SuperellipseOptions) | {}
|
#### superellipse~SuperellipseOptions : object
**Kind**: inner typedef of [superellipse
](#exp_module_superellipse--superellipse)
**Properties**
| Name | Type | Default |
| --------------- | --------------------- | -------------------------- |
| [sx] | number
| 1
|
| [sy] | number
| 0.5
|
| [radius] | number
| 0.5
|
| [segments] | number
| 32
|
| [innerSegments] | number
| 16
|
| [theta] | number
| TAU
|
| [thetaOffset] | number
| 0
|
| [mapping] | function
| mappings.lamé
|
| [m] | number
| 2
|
| [n] | number
| m
|
## tetrahedron
- [tetrahedron](#module_tetrahedron)
- [tetrahedron([options])](#exp_module_tetrahedron--tetrahedron) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~TetrahedronOptions](#module_tetrahedron--tetrahedron..TetrahedronOptions) : object
### tetrahedron([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
**Kind**: Exported function
| Param | Type | Default |
| --------- | --------------------------------------------------------------------------------------- | --------------- |
| [options] | [TetrahedronOptions
](#module_tetrahedron--tetrahedron..TetrahedronOptions) | {}
|
#### tetrahedron~TetrahedronOptions : object
**Kind**: inner typedef of [tetrahedron
](#exp_module_tetrahedron--tetrahedron)
**Properties**
| Name | Type | Default |
| -------- | ------------------- | ---------------- |
| [radius] | number
| 0.5
|
## torus
- [torus](#module_torus)
- [torus([options])](#exp_module_torus--torus) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
- [~TorusOptions](#module_torus--torus..TorusOptions) : object
### torus([options]) ⇒ [SimplicialComplex
](#SimplicialComplex) ⏏
**Kind**: Exported function
| Param | Type | Default |
| --------- | --------------------------------------------------------------- | --------------- |
| [options] | [TorusOptions
](#module_torus--torus..TorusOptions) | {}
|
#### torus~TorusOptions : object
**Kind**: inner typedef of [torus
](#exp_module_torus--torus)
**Properties**
| Name | Type | Default |
| --------------- | ------------------- | ---------------- |
| [radius] | number
| 0.4
|
| [segments] | number
| 64
|
| [minorRadius] | number
| 0.1
|
| [minorSegments] | number
| 32
|
| [theta] | number
| TAU
|
| [thetaOffset] | number
| 0
|
| [phi] | number
| TAU
|
| [phiOffset] | number
| 0
|
## utils
- [utils](#module_utils)
- [.TAU](#module_utils.TAU) : number
- [.HALF_PI](#module_utils.HALF_PI) : number
- [.SQRT2](#module_utils.SQRT2) : number
- [.getCellsTypedArray](#module_utils.getCellsTypedArray) ⇒ Uint8Array
\| Uint16Array
\| Uint32Array
- [.normalize(v)](#module_utils.normalize) ⇒ Array.<number>
- [.checkArguments(...args)](#module_utils.checkArguments)
- [.setTypedArrayType(type)](#module_utils.setTypedArrayType)
### utils.TAU : number
Two times PI.
**Kind**: static constant of [utils
](#module_utils)
### utils.HALF_PI : number
Two times PI.
**Kind**: static constant of [utils
](#module_utils)
### utils.SQRT2 : number
Square root of 2.
**Kind**: static constant of [utils
](#module_utils)
### utils.getCellsTypedArray ⇒ Uint8Array
\| Uint16Array
\| Uint32Array
Select cells typed array from a size determined by amount of vertices.
**Kind**: static constant of [utils
](#module_utils)
**See**: [MDN TypedArray objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#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
](#module_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
](#module_utils)
| Param | Type |
| ------- | --------------- |
| ...args | \*
|
### utils.setTypedArrayType(type)
Enforce a typed array constructor for cells
**Kind**: static method of [utils
](#module_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:
- [primitive-quad](https://npmjs.com/package/primitive-quad)
- [primitive-plane](https://npmjs.com/package/primitive-plane)
- [primitive-cube](https://npmjs.com/package/primitive-cube)
- [primitive-rounded-cube](https://npmjs.com/package/primitive-rounded-cube)
- [primitive-capsule](https://npmjs.com/package/primitive-capsule)
- [primitive-sphere](https://npmjs.com/package/primitive-sphere)
- [primitive-icosphere](https://npmjs.com/package/primitive-icosphere)
- [primitive-ellipsoid](https://npmjs.com/package/primitive-ellipsoid)
- [primitive-torus](https://npmjs.com/package/primitive-torus)
- [primitive-cylinder](https://npmjs.com/package/primitive-cylinder)
- [primitive-box](https://npmjs.com/package/primitive-box)
- [primitive-circle](https://npmjs.com/package/primitive-circle)
Differences with v1:
- [x] use 3D positions for circle
- [x] base disc on ellispse and add inner segments
- [x] fix cylinder orientation and uvs
- [x] fix icosphere uvs (based on: https://github.com/mourner/icomesh)
- [x] fix quad normal to +z
- [x] fix subdivision for rounded geometries (rounded-cube and capsule)
- [x] uniformise api and internal names
- [x] use options object
- [x] remove gl-matrix/pex-math and icosphere dependencies
- [x] use only trigonometric operation, no matrix transformation
- [x] base sphere on ellispsoid
- [x] add cone based on cylinder
- [x] use flat typed arrays
- [x] defaults produce geometries contained in a unit bbox
- [x] add jsdoc, prettier, eslint via [snowdev](https://github.com/dmnsgn/snowdev/)
MIT. See [license file](https://github.com/dmnsgn/primitive-geometry/blob/main/LICENSE.md).