flat static method

dynamic flat(
  1. BufferGeometry geometry, [
  2. LoopParameters? params
])

Applies one iteration of Loop (flat) subdivision (1 triangle split into 4 triangles)

Implementation

static flat(BufferGeometry geometry, [LoopParameters? params]) {
  params ??= LoopParameters();

  ///// Geometries
  if (! verifyGeometry(geometry)) return geometry;
  final existing = (geometry.index != null) ? geometry.toNonIndexed() : geometry.clone();
  final loop = BufferGeometry();

  ///// Attributes
  final attributeList = gatherAttributes(existing);
  final vertexCount = existing.attributes['position'].count;

  ///// Build Geometry
  attributeList.forEach((attributeName){
    final attribute = existing.getAttributeFromString(attributeName);
    if (attribute == null) return;
    loop.setAttributeFromString(attributeName, LoopSubdivision.flatAttribute(attribute, vertexCount, params));
  });

  ///// Morph Attributes
  final morphAttributes = existing.morphAttributes;
  for (final attributeName in morphAttributes.keys) {
    final List<BufferAttribute>array = [];
    final morphAttribute = morphAttributes[attributeName]!;

      // Process Array of Float32BufferAttributes
    for (int i = 0, l = morphAttribute.length; i < l; i++) {
      if (morphAttribute[i].count != vertexCount) continue;
      array.add(LoopSubdivision.flatAttribute(morphAttribute[i], vertexCount, params));
    }
    loop.morphAttributes[attributeName] = array;
  }
  loop.morphTargetsRelative = existing.morphTargetsRelative;

  ///// Clean Up
  existing.dispose();
  return loop;
}