Is it possible to iterate the segments of your geometry?

Usually when i iterate the vertices to apply a tweak i do something like geometry.vertices.forEach(v => {});

However i’d like to just iterate the segments of the geometry, like so:

for segment in geometry:
for vertex in segment:

does this seem possible at all?

The main reason i want to do this is to get the center point at a segment of given height in a geometry.

Thanks for any tips

Do you mean to iterate through faces?

1 Like

Hey! I’m not sure it would be faces, i am trying to get entire slices of the cylinder, trying to convert this openGL code into three.js into

In their C++ code they iterate up the ‘slices’ of the cylinder, they declare their geometry like this:

const int   ca= 20;     // points per slice
const int   cb=100;     // slices
const float r0=  0.3;   // minor screw radius
const float r1=  0.35;  // major screw radius
const float l1=  4.0;   // tube length
const float nz= 10.0;   // screws

// straight mesh
vec3 pnt0[ca][cb];  // vertex
vec3 nor0[ca][cb];  // normal
vec2 txr0[ca][cb];  // texcoord
vec3 mid0[cb];      // slice center
vec3 dir0[cb];      // slice central axis (normalized)
float len0[cb];     // slice arclength position

so i’m trying to get that slice center, slice central axis, slice arclength position with the three.js geometry

A data structure like this does not exist. You should also notice that your are using with Geometry a legacy geometry format. It’s much future-proof to use BufferGeometry instead.