three-mesh-halfedge
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

three-mesh-halfedge

npm release build Documentation License

A typescript implementation of the Halfedge structure for three.js geometries.

Supports multiple topologies:

  • Multiple edges between the same vertices
  • Isolated polygons
  • Isolated edges
  • Isolated vertices
  • Mixed wireframe and polygons
  • Polygons with an arbitrary number of vertices and edges
  • Polygons meeting only at one vertex

Examples

Installation

npm install three-mesh-halfedge

Documentation

Documentation

Documentation is in progress.

Code snippets

Example 1: Build the Halfedge structure
import * as THREE from 'three';
import { HalfedgeDS } from 'three-mesh-halfedge';

// Build the Halfedge structure from a BoxGeometry
const geometry = new THREE.BoxGeometry();
const struct = new HalfedgeDS();
struct.setFromGeometry(geometry, 1e-10);
Example 2: Extract the boundary halfedges of a mesh
const struct = new HalfedgeDS();
struct.setFromGeometry(mesh.geometry);

// Get the boundary edges (keep only one halfedge for each pair)
const boundaries = new Set<Halfedge>();
for (const halfedge of struct.halfedges) {
	if (!boundaries.has(halfedge.twin) && !halfedge.face) {
		boundaries.add(halfedge);
	}
}
console.log("Boundary halfedges", boundaries);
Example 3: Get the front faces of a mesh
const struct = new HalfedgeDS();
struct.setFromGeometry(mesh.geometry);

// Get the camera position in mesh's space
const localCameraPos = mesh.worldToLocal(camera.position.clone());

//  Get the front faces
const array = [];
for (const face of struct.faces) {
	// /!\ Attention: position is considered in geometry local system
	if (face.isFront(localCameraPos)) { 
		array.push(face);
	}
}
console.log("Front faces", array);

Useful links and references

Kalle Rutanen Homepage - Halfedge data structures

Package Sidebar

Install

npm i three-mesh-halfedge

Weekly Downloads

13

Version

1.0.3

License

MIT

Unpacked Size

209 kB

Total Files

76

Last publish

Collaborators

  • esquisse