https://github.com/prolincur/three-triangle-iterator
Make traversal of triangles of three.js's Mesh, BufferGeometry and Geometry object(s) easy
https://github.com/prolincur/three-triangle-iterator
Last synced: about 2 months ago
JSON representation
Make traversal of triangles of three.js's Mesh, BufferGeometry and Geometry object(s) easy
- Host: GitHub
- URL: https://github.com/prolincur/three-triangle-iterator
- Owner: prolincur
- License: mit
- Created: 2021-03-03T05:36:02.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2025-02-03T12:13:34.000Z (4 months ago)
- Last Synced: 2025-04-08T07:41:13.577Z (about 2 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/three-triangle-iterator
- Size: 2.35 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# three-triangle-iterator
**three-triangle-iterator** is a simple utility which make it easy to iterate over all the triangular geometry faces of a [Mesh](https://threejs.org/docs/#api/en/objects/Mesh), Geometry (in version prior to r125 of three.js) or [BufferGeometry](https://threejs.org/docs/#api/en/core/BufferGeometry) objects. It also supports the instanced buffer geometry. This library can work cross platfrom and with your version [three.js](https://threejs.org). This library is backward-compatible with the versions prior to r125 or later.
#### Install
```
yarn add three-triangle-iterator three
```
or
```
npm i three-triangle-iterator three
```#### Usage
```javascript
import * as THREE from 'three';
import forEachTriangle from 'three-triangle-iterator';forEachTriangle(object, (triangle) => {
//... do something with each triangle
// Traverse vertices
triangle.forEach((vertex) => {
//... do something with the vertex
})
// Traverse edges
for (let i = 0; i < 3; i++) {
// get the first and next vertex making up the edge
const iNext = (i + 1) % 3;
const edge = {
start: triangle[i],
end: triangle[iNext],
};
//... do something with the edge
}
})```
### Author
[Prolincur Technologies](https://prolincur.com)