Skip to content

prolincur/three-triangle-iterator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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, Geometry (in version prior to r125 of three.js) or BufferGeometry objects. It also supports the instanced buffer geometry. This library can work cross platfrom and with your version three.js. 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

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

About

Make traversal of triangles of three.js's Mesh, BufferGeometry and Geometry object(s) easy

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published