JSPM

primitive-torus

1.0.4
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 618
  • Score
    100M100P100Q105031F
  • License MIT

creates a 3D torus mesh

Package Exports

  • primitive-torus

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (primitive-torus) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

primitive-torus

stable

screen

(demo)

A minimal 3D torus geometry for 3D rendering, including normals, UVs, and cell indices.

Example

var torus = require('primitive-torus')
var mesh = torus()

// the simplicial complex
console.log(mesh.positions, mesh.cells)

// rendering attributes
console.log(mesh.uvs)
console.log(mesh.normals)

Usage

NPM

mesh = torus([opt])

Creates a new torus with options:

  • majorRadius the radius of the major ring R, default 1.0
  • minorRadius the radius of the minor ring r, default 0.25
  • majorSegments the number of segments for the major ring, default 32
  • minorSegments the number of segments for the minor ring, defualt 64
  • arc the arc to draw, default Math.PI * 2 (full circle)

The returned mesh is an object with the following data:

{
  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], ... ]
}

Credits

The algorithm here is from ThreeJS TorusGeometry.

License

MIT. See LICENSE.md for details.