Surface constructor

Surface(
  1. List<Vertex> vertices,
  2. List<int> indices, [
  3. Material? material
])

Base surface Resource, it describes a single surface to be rendered.

Implementation

Surface(
  List<Vertex> vertices,
  List<int> indices, [
  this.material,
]) : super(null) {
  // `TODO`(bdero): This should have an attribute map instead and be fully SoA
  // but vertex attributes in Impeller aren't flexible enough yet.
  // See also https://github.com/flutter/flutter/issues/116168.
  _vertices = Float32List.fromList(
    vertices.fold([], (p, v) => p..addAll(v.storage)),
  ).buffer;
  _vertexCount = _vertices.lengthInBytes ~/ (vertices.length * 9);

  _indices = Uint16List.fromList(indices).buffer;
  _indexCount = _indices.lengthInBytes ~/ 2;

  _calculateAabb(vertices);
}