Geometries for 3D rendering, including normals, UVs and cell indices (faces). Perfect if you want to supercharge your dependency folder... with 30KB of geometries.
npm install primitive-geometry
Float32Array
for geometry data and Uint8Array|Uint16Array|Uint32Array
for cells)See difference with v1 here.
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], ... ]
// }
Re-export all geometries and utils.
Object
Geometry definition without normals and UVs.
Object
Geometry definition.
Re-export all geometries and utils.
BasicSimplicialComplex
⏏
Object
BasicSimplicialComplex
⏏Kind: Exported function
Param | Type | Default |
---|---|---|
[options] | BoxOptions |
{} |
Object
Kind: inner typedef of box
Properties
Name | Type | Default |
---|---|---|
[sx] | number |
1 |
[sy] | number |
sx |
[sz] | number |
sx |
SimplicialComplex
⏏
Object
SimplicialComplex
⏏Kind: Exported function
Param | Type | Default |
---|---|---|
[options] | CapsuleOptions |
{} |
Object
Kind: inner typedef of capsule
Properties
Name | Type | Default |
---|---|---|
[height] | number |
1 |
[radius] | number |
0.25 |
[nx] | number |
16 |
[ny] | number |
32 |
BasicSimplicialComplex
⏏
Object
BasicSimplicialComplex
⏏Kind: Exported function
Param | Type | Default |
---|---|---|
[options] | BoxOptions |
{} |
Object
Kind: inner typedef of circle
Properties
Name | Type | Default |
---|---|---|
[radius] | number |
0.5 |
[segments] | number |
32 |
SimplicialComplex
⏏
Object
SimplicialComplex
⏏Kind: Exported function
Param | Type | Default |
---|---|---|
[options] | 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 |
SimplicialComplex
⏏
Object
SimplicialComplex
⏏Kind: Exported function
Param | Type | Default |
---|---|---|
[options] | 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 |
SimplicialComplex
⏏
Object
SimplicialComplex
⏏Kind: Exported function
Param | Type | Default |
---|---|---|
[options] | 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 |
SimplicialComplex
⏏
Object
SimplicialComplex
⏏Default to an oblate spheroid.
Kind: Exported function
Param | Type | Default |
---|---|---|
[options] | 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 |
SimplicialComplex
⏏
Object
SimplicialComplex
⏏Kind: Exported function
Param | Type | Default |
---|---|---|
[options] | IcosphereOptions |
{} |
Object
Kind: inner typedef of icosphere
Properties
Name | Type | Default |
---|---|---|
[radius] | number |
0.5 |
[subdivisions] | number |
2 |
SimplicialComplex
⏏
Object
SimplicialComplex
⏏Kind: Exported function
Param | Type | Default |
---|---|---|
[options] | PlaneOptions |
{} |
Object
Kind: inner typedef of plane
Properties
Name | Type | Default |
---|---|---|
[sx] | number |
1 |
[sy] | number |
sx |
[nx] | number |
1 |
[ny] | number |
nx |
SimplicialComplex
⏏
Object
SimplicialComplex
⏏Kind: Exported function
Param | Type | Default |
---|---|---|
[options] | QuadOptions |
{} |
Object
Kind: inner typedef of quad
Properties
Name | Type | Default |
---|---|---|
[scale] | number |
0.5 |
SimplicialComplex
⏏Kind: Exported function
Param | Type | Default |
---|---|---|
[options] | module:rounded~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 |
SimplicialComplex
⏏
Object
SimplicialComplex
⏏Kind: Exported function
Param | Type | Default |
---|---|---|
[options] | SphereOptions |
{} |
Object
Kind: inner typedef of sphere
Properties
Name | Type | Default |
---|---|---|
[radius] | number |
0.5 |
[nx] | number |
32 |
[ny] | number |
16 |
SimplicialComplex
⏏
Object
SimplicialComplex
⏏Kind: Exported function
Param | Type | Default |
---|---|---|
[options] | 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 |
number
Uint8Array
| Uint16Array
| Uint32Array
Array.<number>
number
Two times PI.
Kind: static constant of utils
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 |
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 |
Ensure first argument passed to the primitive functions is an object
Kind: static method of utils
Param | Type |
---|---|
...args | * |
Enforce a typed array constructor for cells
Kind: static method of utils
Param | Type |
---|---|
type | Class.<Uint8Array> | Class.<Uint16Array> | Class.<Uint32Array> |
Object
Geometry definition without normals and UVs.
Kind: global typedef
Properties
Name | Type |
---|---|
positions | Float32Array |
cells | Uint8Array | Uint16Array | Uint32Array |
Object
Geometry definition.
Kind: global typedef
Properties
Name | Type |
---|---|
positions | Float32Array |
normals | Float32Array |
uvs | Float32Array |
cells | Uint8Array | Uint16Array | Uint32Array |
See original packages used in v1:
Differences with v1:
MIT. See license file.