Class: Polyhedron

polyhedron.Polyhedron(fix)

Class for creating the model of a sphere by continuously subdividing a convex regular polyhedron.

Mercator coordinates are created and returned as a polyData's property, vertexMercatorCoords, and Three.js polyhedra texture coordinates are rotated by 180°, because their original coordinates reversed the places of the prime and anti meridians.

Constructor

new Polyhedron(fix)

Parameters:
Name Type Default Description
fix Boolean false whether to fix uv coordinates.
Source:
See:

Members

fix :Boolean

Whether texture coordinates should be fixed.

Type:
  • Boolean
Deprecated:
  • in face of Tarini's method executed in the fragment shader.

Source:

index :Number

Number of vertices.
Type:
  • Number
Source:

maxSubdivisions :Number

Maximum number of subdivisions.
Type:
  • Number
Source:

mercCoords :Array.<Number>

Vertex mercator texture coordinate array.
Type:
  • Array.<Number>
Source:

name :String

Name (type) of the subdivided polyhedron.
Type:
  • String
Source:

nfaces :Number

Initial number of triangles.
Type:
  • Number
Source:

normalsArray :Array.<Number>

Vertex normal array.
Type:
  • Array.<Number>
Source:

pointsArray :Array.<Number>

Vertex coordinate array.
Type:
  • Array.<Number>
Source:

pointsIndices :Array.<Number>

Index array (triangular face indices).
Type:
  • Array.<Number>
Source:

texCoords :Array.<Number>

Vertex texture coordinate array.
Type:
  • Array.<Number>
Source:

Methods

divideTriangle(a, b, c, count)

Recursively subdivides a triangle.
Parameters:
Name Type Description
a vec3 first vertex.
b vec3 second vertex.
c vec3 third vertex.
count Number subdivision counter.
Source:

dodecahedron(poly) → {module:polyhedron~polyData}

Subdivides an initial dodecahedron.

Generates:
  • 36(n² + 2n + 1)
  • n = 0: 36 triangles, 20 vertices
  • n = 1: 144 triangles, 74 vertices
  • n = 2: 324 triangles, 164 vertices
  • n = 3: 576 triangles, 290 vertices
  • n = 4: 900 triangles, 452 vertices
  • n = 5: 1296 triangles, 650 vertices
Parameters:
Name Type Description
poly Object dodecahedron.
Properties:
Name Type Default Description
poly.radius Number 1 radius of the dodecahedron.
poly.n Number limit.dod number of subdivisions.
Source:
See:
Returns:
Type
module:polyhedron~polyData

dodecahedronHWS(poly) → {module:polyhedron~polyData}

Subdivides an initial dodecahedron.

WebGL's vertex index buffers are limited to 16-bit (0-65535) right now: Uint16Array

Generates:
  • 36 * 4n triangles
  • 36 * 3 * 4n vertices
  • maximum level = 4 (9216 triangles)
  • 36 * 3 * 4**5 = 110592 vertices → buffer overflow
Parameters:
Name Type Description
poly Object dodecahedron.
Properties:
Name Type Default Description
poly.vtx Array.<vec3> initialDod vertices of initial dodecahedron.
poly.n Number limit.dod_hws number of subdivisions.
Source:
Returns:
Type
module:polyhedron~polyData

fixUVCoordinates(sc)

Equirectangular mapping (also called latitude/longitude or spherical coordinates) is non-linear.
That means normal UV mapping can only approximate it - quite badly at the poles, in fact.

To fix this, we can calculate our own texture coordinate per fragment,
by using the direction to the fragment being drawn, resulting in a perfect match.

As a last resource, we can try to adjust uv texture coordinates, when two vertices of a triangle are on one side,
and the third on the other side of the discontinuity created, when the 0 coordinate is stitched together with the 1 coordinate.
Parameters:
Name Type Description
sc Array.<Object.<{s:Number, t:Number}>> triangle given by its spherical coordinates.
Deprecated:
  • in face of Tarini's method executed in the fragment shader.

Source:
See:

icosahedron(poly) → {module:polyhedron~polyData}

Subdivides an initial icosahedron.

Generates:
  • 20(n² + 2n + 1)
  • n = 0: 20 triangles, 12 vertices
  • n = 1: 80 triangles, 42 vertices
  • n = 2: 180 triangles, 92 vertices
  • n = 3: 320 triangles, 162 vertices
  • n = 4: 500 triangles, 252 vertices
  • n = 5: 720 triangles, 362 vertices
Parameters:
Name Type Description
poly Object icosahedron.
Properties:
Name Type Default Description
poly.radius Number 1 radius of the icosahedron.
poly.n Number limit.ico number of subdivisions.
Source:
See:
Returns:
Type
module:polyhedron~polyData

icosahedronHWS(poly) → {module:polyhedron~polyData}

Subdivides an initial icosahedron.

WebGL's vertex index buffers are limited to 16-bit (0-65535) right now: Uint16Array

Generates:
  • 20 * 4n triangles
  • 20 * 3 * 4n vertices
  • maximum level = 5 (20480 triangles)
  • 20 * 3 * 4**6 = 245760 vertices → buffer overflow
Parameters:
Name Type Description
poly Object icosahedron.
Properties:
Name Type Default Description
poly.vtx Array.<vec3> initialIco vertices of initial octahedron.
poly.n Number limit.ico_hws number of subdivisions.
Source:
Returns:
Type
module:polyhedron~polyData

level(t) → {Number}

Return the subdivision level given a number of triangles.
Parameters:
Name Type Description
t Number number of triangles.
Source:
Returns:
level of detail n: n² + 2n + 1 - t = 0.
Type
Number

levelHWS(t) → {Number}

Return the subdivision level given a number of triangles.
Parameters:
Name Type Description
t Number number of triangles.
Source:
Returns:
level of detail: log₄(t / nfaces).
Type
Number

ntri(n) → {Number}

Return the number of triangles at a given subdivision level.
Parameters:
Name Type Description
n Number level of detail.
Source:
Returns:
number of triangles: nfaces * (n² + 2n + 1).
Type
Number

ntriHWS(n) → {Number}

Return the number of triangles at a given subdivision level.
Parameters:
Name Type Description
n Number level of detail.
Source:
Returns:
number of triangles: nfaces * 4n.
Type
Number

octahedron(poly) → {module:polyhedron~polyData}

Subdivides an initial octhedron.

Generates:
  • 8(n² + 2n + 1)
  • n = 0: 8 triangles, 6 vertices
  • n = 1: 32 triangles, 18 vertices
  • n = 2: 72 triangles, 38 vertices
  • n = 3: 192 triangles, 66 vertices
  • n = 4: 200 triangles, 102 vertices
  • n = 5: 288 triangles, 146 vertices
Parameters:
Name Type Description
poly Object octahedron.
Properties:
Name Type Default Description
poly.radius Number 1 radius for three.js.
poly.n Number limit.oct number of subdivisions.
Source:
See:
Returns:
Type
module:polyhedron~polyData

octahedronHWS(poly) → {module:polyhedron~polyData}

Subdivides an initial octahedron.

WebGL's vertex index buffers are limited to 16-bit (0-65535) right now: Uint16Array

Generates:
  • 8 * 4n triangles
  • 8 * 3 * 4n vertices
  • maximum level = 5 (8192 triangles)
  • 8 * 3 * 4**6 = 98304 vertices → buffer overflow
Parameters:
Name Type Description
poly Object octahedron.
Properties:
Name Type Default Description
poly.vtx Array.<vec3> initialOcta vertices of initial octahedron.
poly.n Number limit.oct_hws number of subdivisions.
Source:
Returns:
Type
module:polyhedron~polyData

resetBuffers()

Start with empty buffers.
Source:

tetrahedron(poly) → {module:polyhedron~polyData}

Subdivides an initial tetrahedron.

Generates:
  • 4(n² + 2n + 1)
  • n = 0: 4 triangles, 4 vertices
  • n = 1: 16 triangles, 10 vertices
  • n = 2: 36 triangles, 20 vertices
  • n = 3: 64 triangles, 34 vertices
  • n = 4: 100 triangles, 52 vertices
  • n = 5: 144 triangles, 74 vertices
Parameters:
Name Type Description
poly Object tetrahedron.
Properties:
Name Type Default Description
poly.radius Number 1 radius for three.js.
poly.n Number limit.tet number of subdivisions.
Source:
See:
Returns:
Type
module:polyhedron~polyData

tetrahedronHWS(poly) → {module:polyhedron~polyData}

Subdivides an initial tetrahedron.

WebGL's vertex index buffers are limited to 16-bit (0-65535) right now: Uint16Array

Generates:
  • 4 * 4n triangles
  • 4 * 3 * 4n vertices
  • maximum level = 6 (16384 triangles)
  • 4 * 3 * 4**7 = 196608 vertices → buffer overflow
Parameters:
Name Type Description
poly Object tetrahedron.
Properties:
Name Type Default Description
poly.vtx Array.<vec3> initialTet.cube vertices of initial tetrahedron.
poly.n Number limit.tet_hws number of subdivisions.
Source:
Returns:
Type
module:polyhedron~polyData

triangle(a, b, c)

Adds a new triangle.

Mercator texture coordinates are also set.
Parameters:
Name Type Description
a vec3 first vertex.
b vec3 second vertex.
c vec3 third vertex.
Source: