Will Geometry be deprecated or maintained along BufferGeometry?

You want the position of each vertex in a particular face, then? You’ll need to know whether the geometry is indexed, by checking if geometry.index exists.

indexed geometry

for ( var i = 0; i < geometry.index.count; i += 3 ) {

  var a = new THREE.Vector3(
    geometry.attributes.position.getX( geometry.index.getX( i ) ),
    geometry.attributes.position.getY( geometry.index.getX( i ) ),
    geometry.attributes.position.getZ( geometry.index.getX( i ) ),
  );
  var b = new THREE.Vector3(
    geometry.attributes.position.getX( geometry.index.getX( i + 1 ) ),
    geometry.attributes.position.getY( geometry.index.getX( i + 1 ) ),
    geometry.attributes.position.getZ( geometry.index.getX( i + 1 ) ),
  );
  var c = new THREE.Vector3(
    geometry.attributes.position.getX( geometry.index.getX( i + 2 ) ),
    geometry.attributes.position.getY( geometry.index.getX( i + 2 ) ),
    geometry.attributes.position.getZ( geometry.index.getX( i + 2 ) ),
  );

}

non-indexed geometry

for ( var i = 0; i < geometry.attributes.position.count; i += 3 ) {

  var a = new THREE.Vector3(
    geometry.attributes.position.getX( i ),
    geometry.attributes.position.getY( i ),
    geometry.attributes.position.getZ( i ),
  );
  var b = new THREE.Vector3(
    geometry.attributes.position.getX( i + 1 ),
    geometry.attributes.position.getY( i + 1 ),
    geometry.attributes.position.getZ( i + 1 ),
  );
  var c = new THREE.Vector3(
    geometry.attributes.position.getX( i + 2 ),
    geometry.attributes.position.getY( i + 2 ),
    geometry.attributes.position.getZ( i + 2 ),
  );

}

But note that creating so many Vector3 objects is not very efficient either (that’s part of why Geometry is deprecated…). It would be better to reuse the same Vector3 objects and call .set() on them, if you need to do this while rendering.

And all this is assuming you want the Vector3 objects at all. You can also access geometry.attributes.position directly, see BufferAttribute.

2 Likes