npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

hexagon-geo

v1.0.0

Published

A 3D hexagon vertices generator with segment

Downloads

16

Readme

hexagon-geo

This is a 3D hexagon plane generator. You may input the size, segment, rotation and texture fitting strategy. It will finally generate a set of vertices (3D coord), with origin at [0,0,0].

Installation

npm install hexagon-geo --save

Usage

Basic

We use three.js as the 3D rendering library for this example.

import hexagonGeoGenerator from 'hexagon-geo';

const HEX_SIZE = 10;
const HEX_SEGMENT = 3;

export default class HexagonGeo extends THREE.BufferGeometry {
  constructor(){
    super();

    let {vertices, indices, uvs, invertedIndices, normals} = hexagonGeoGenerator(HEX_SIZE, HEX_SEGMENT);
    this.setAttribute('position', new THREE.BufferAttribute(new Float32Array(vertices), 3));
    this.setAttribute('normal', new THREE.BufferAttribute(new Float32Array(normals), 3));
    this.setAttribute('uv', new THREE.BufferAttribute(new Float32Array(uvs), 2));
    this.setIndex(indices);
  }
}

Segment = 3

BasicSegement3

Segment = 10

BasicSegement10

Rotation

You may rotate the hexagon to get vertical hexagon or whatever you want.

hexagonGeoGenerator(HEX_SIZE, HEX_SEGMENT, Math.PI/4);

Rotation

Texture Fitting Strategy

There are three strategy for texture fitting (UVs).

Texture (512 x 512)

Texture

hexagonGeoGenerator(HEX_SIZE, HEX_SEGMENT, 0, "COVER");				// Default

TextureCover

hexagonGeoGenerator(HEX_SIZE, HEX_SEGMENT, 0, "CONTAIN");

TextureContain

hexagonGeoGenerator(HEX_SIZE, HEX_SEGMENT, 0, "FILL");

TextureFill

Texture with rotation

You may figure out that the texture won't follow the rotation, as we rotate the hexagon before calculate the UVs. If you wish to achieve other effect, you may rotate it afterward as the Advance Usage.

hexagonGeoGenerator(HEX_SIZE, HEX_SEGMENT, Math.PI/4);

TextureRotation

API

  • hexagonGeoGenerator ( size, segment, rotateAngle, textureFit )

Param | Type | Description | Default ------------ | ----------|----------------------------------------------------------------|---------- size | number | Edge length of the hexagon | 10 segment | integer | The level of subdivision | 1 rotateAngle | number | Rotation | 0 textureFit | string | Texture fitting strategy, COVER, CONTAIN or FILL only | COVER

Returns | Type | Description
------------ | ----------|----------------------------- vertices | number[] | The 3D coord of vertices
indices | integer[] | The index of front faces
invertIndices| integer[] | The index of back faces
normals | number[] | Normals uvs | number[] | UVs for texture mapping

  • rotateAll ( vertices, angle )

Param | Type | Description
------------ | ----------|----------------------------- vertices | number[] | The 3D coord of vertices, which will be manipulated angle | number | Rotation angle in radian

  • computeUV ( vertices, textureFit ) : UVs

Param | Type | Description
------------ | ----------|----------------------------- vertices | number[] | The 3D coord of vertices textureFit | string | Texture fitting strategy, COVER, CONTAIN or FILL only

  • computeInvertedIndices ( indices ) : invertedIndices

Param | Type | Description
------------ | ----------|----------------------------- indices | number[] | The indexing of vertices for faces

Advance Usage

Texture with rotation

You may rotate the hexagon to achieve other texture pattern.

import  hexagonGeoGenerator, {rotateAll} from  './node_modules/hexagon-geo/index.js';
...

let {vertices, indices, uvs, normals} = hexagonGeoGenerator(HEX_SIZE, HEX_SEGMENT, -Math.PI/7);
rotateAll(vertices, Math.PI/7);

TextureAdvanceRotation

2D Rendering

Although it designed for 3D plane, it also can be used for 2D.

const OFFSET = [150,150];
let {vertices, indices} = hexagonGeoGenerator(120, 3);

for (let  i=0; i<indices.length; i+=3){
  let points = [indices[i], indices[i+1], indices[i+2]];	// 3 point for a triangle
  points = points.map( pointIndex  => [ 
    vertices[pointIndex*3] + OFFSET[0], 		// x
    vertices[pointIndex*3+1] + OFFSET[1]		// y
  ]); 

  ctx.moveTo(...points[0]);
  ctx.beginPath();
  points.forEach(point  => ctx.lineTo(...point))
  ctx.closePath();
  ctx.fillStyle = i%6===0? '#fff' : '#000';
  ctx.fill();
}

2D

License

  • MIT License