Che.js
Implementation of the Compact Half-Edge (CHE) topological data-structure in JavaScript.
Install / Use
/learn @Prograf-UFF/Che.jsREADME
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
-
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.
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
- CHE: A scalable topological data structure for triangular meshes
- ESTRUTURAS DE DADOS TOPOLÓGICAS ESCALONÁVEIS PARA VARIEDADES DE DIMENSÃO 2 E 3 (chapter 4, in portuguese)
Change log
Related Skills
node-connect
349.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
