Skip to content

Implementation of the Compact Half-Edge (CHE) topological data-structure in JavaScript.

License

Notifications You must be signed in to change notification settings

Prograf-UFF/che.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

77 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPM Package NPM Downloads

What is che.js?

che.js is an implementation of the Compact Half-Edge(CHE) data structure for triangular meshes in Javascript. It is an upgrade on the half-edge data structure, which representes each edge as two twin-edges, each part of a triangle.

Why use che.js?

The main goal of che.js is to provide a scalable structure for meshes, so you can scale your memory usage according to your needs.

che.js is split in 4 levels, each of them increasing the amount of information you have.

Levels

  1. The first level of che.js is the minimal representation of a triangle, all it storages is the geometry informations about the vertices, and which vertices form each triangles. It does that by storing references to vertices in a table called _tableVertices, each triangle of the mesh is represented by 3 vertice references on this table.

  2. The second level of che.js stores the opposites of each half-edge in the mesh, which allows for fast computation of adjacency between triangles.

  3. The third level of the structure chooses an half-edge to represent each vertex and edge. It allows for fast discovery of adjacency with vertices, and a simple way to draw independent edges if needed.

  4. The fourth level adds information about the boundary curves of a mesh, representing each boundary curve with a half-edge.

Getting Started

npm install @che.js/che.js

⚠⚠⚠

Warning: Since che.js uses es6 modules, you have to either name your file with .mjs or explicitly state in your package.json that your project type is "module".

⚠⚠⚠

Loading a mesh

Currently che.js only have loaders available for objects in .ply format with x,y,z coordinates, you can find a few examples at the ply folder available on the root of this repository. In this example, we will use sphere.ply.

import Che from '@che.js/che.js';
import fs from 'fs'

//Load ply file

let plyFile = fs.readFileSync('sphere.ply', 'utf-8');

let cheMesh = new Che()

cheMesh.loadPly(plyFile).then(() => {
  //do whatever you want
})

Finding the vertex star of an vertex

cheMesh.loadPly(plyFile).then(() => {
  let start = performance.now()
  let vertexStarOfVertex3 = cheMesh.relation00(3);
  let end = performance.now()
  console.log(`L0 R00: ${end - start}`)
  console.log(vertexStarOfVertex3);

  cheMesh.loadCheL1();
  start = performance.now()
  vertexStarOfVertex3 = cheMesh.relation00(3);
  end = performance.now()
  console.log(`L1 R00: ${end - start}`)
  console.log(vertexStarOfVertex3);


  cheMesh.loadCheL2();
  start = performance.now()
  vertexStarOfVertex3 = cheMesh.relation00(3);
  end = performance.now()
  console.log(`L2 R00: ${end - start}`)
  console.log(vertexStarOfVertex3);
})

Wiki

You can find documentation and examples at our wiki

Demo

You can see che.js in action on this demo

More info

You can find more info about the data structure on the following links

Change log

Releases

About

Implementation of the Compact Half-Edge (CHE) topological data-structure in JavaScript.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •