modify static method

BufferGeometry modify(
  1. BufferGeometry bufferGeometry, [
  2. int iterations = 1,
  3. LoopParameters? params
])

Applies Loop subdivision modifier to geometry

@param {Object} bufferGeometry - Three.js geometry to be subdivided @param {Number} iterations - How many times to run subdividion @param {Object} params - Optional parameters object, see below @returns {Object} Returns new, subdivided, three.js BufferGeometry object

Optional Parameters Object @param {Boolean} split - Should coplanar faces be divided along shared edges before running Loop subdivision? @param {Boolean} uvSmooth - Should UV values be averaged during subdivision? @param {Boolean} preserveEdges - Should edges / breaks in geometry be ignored during subdivision? @param {Boolean} flatOnly - If true, subdivision generates triangles, but does not modify positions @param {Number} maxTriangles - If geometry contains more than this many triangles, subdivision will not continue @param {Number} weight - How much to weigh favoring heavy corners vs favoring Loop's formula

Implementation

static BufferGeometry modify(BufferGeometry bufferGeometry, [int iterations = 1, LoopParameters? params]) {
  params ??= LoopParameters();
  ///// Parameters
  params.weight = math.max(0, (math.min(1, params.weight)));

  ///// Geometries
  if (! verifyGeometry(bufferGeometry)) return bufferGeometry;
  BufferGeometry modifiedGeometry = bufferGeometry.clone();

  ///// Presplit
  if (params.split) {
    final splitGeometry = LoopSubdivision.edgeSplit(modifiedGeometry);
    modifiedGeometry.dispose();
    modifiedGeometry = splitGeometry;
  }

  ///// Apply Subdivision
  for (int i = 0; i < iterations; i++) {
    int currentTriangles = modifiedGeometry.attributes['position'].count ~/ 3;
    if (currentTriangles < params.maxTriangles) {
      late final BufferGeometry subdividedGeometry;

      // Subdivide
      if (params.flatOnly) {
        subdividedGeometry = LoopSubdivision.flat(modifiedGeometry, params);
      } else {
        subdividedGeometry = LoopSubdivision.smooth(modifiedGeometry, params);
      }

      // Copy and Resize Groups
      modifiedGeometry.groups.forEach((group){
        subdividedGeometry.addGroup(group['start'] * 4, group['count'] * 4, group['materialIndex']);
      });

      // Clean Up
      modifiedGeometry.dispose();
      modifiedGeometry = subdividedGeometry;
    }
  }

  ///// Return New Geometry
  return modifiedGeometry;
}