filterInplace method Null safety

  1. @override
void filterInplace(
  1. MeshGeometry mesh
)
override

Applies the filter to the mesh.

Implementation

@override
void filterInplace(MeshGeometry mesh) {
  // TODO: Do the tangents need to be inverted? Maybe just the W component?
  // TODO: Should modify in-place be allowed, or should it be required
  // to return a new geometry?

  // Swap all the triangle indices
  final indicies = mesh.indices!;

  for (var i = 0; i < indicies.length; i += 3) {
    final tmp = indicies[i];
    indicies[i] = indicies[i + 2];
    indicies[i + 2] = tmp;
  }

  final normals = mesh.getViewForAttrib('NORMAL');
  if (normals is Vector3List) {
    for (var i = 0; i < normals.length; ++i) {
      normals[i] = -normals[i];
    }
  }
}