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.
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.
-
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.
-
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.
-
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.
-
The fourth level adds information about the boundary curves of a mesh, representing each boundary curve with a half-edge.
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".
⚠⚠⚠
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
})
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);
})
You can find documentation and examples at our wiki
You can see che.js in action on this demo
You can find more info about the data structure on the following links