createGeometry method

MeshGeometry createGeometry ({GeometryGeneratorFlags flags, List<GeometryFilter> filters })

Implementation

MeshGeometry createGeometry(
    {GeometryGeneratorFlags flags, List<GeometryFilter> filters}) {
  flags ??= new GeometryGeneratorFlags();

  VertexAttrib positionAttrib;
  VertexAttrib texCoordAttrib;
  VertexAttrib normalAttrib;
  VertexAttrib tangentAttrib;

  Vector2List texCoordView;
  Vector3List positionView;
  Vector3List normalView;
  Vector4List tangentView;

  final List<VertexAttrib> attribs = <VertexAttrib>[];

  positionAttrib = new VertexAttrib('POSITION', 3, 'float');
  attribs.add(positionAttrib);

  if (flags.texCoords || flags.tangents) {
    texCoordAttrib = new VertexAttrib('TEXCOORD0', 2, 'float');
    attribs.add(texCoordAttrib);
  }

  if (flags.normals || flags.tangents) {
    normalAttrib = new VertexAttrib('NORMAL', 3, 'float');
    attribs.add(normalAttrib);
  }

  if (flags.tangents) {
    tangentAttrib = new VertexAttrib('TANGENT', 4, 'float');
    attribs.add(tangentAttrib);
  }

  MeshGeometry mesh = new MeshGeometry(vertexCount, attribs)
    ..indices = new Uint16List(indexCount);
  generateIndices(mesh.indices);

  VectorList<Vector> view = mesh.getViewForAttrib('POSITION');
  if (view is Vector3List) {
    positionView = view;
    generateVertexPositions(positionView, mesh.indices);
  }

  if (flags.texCoords || flags.tangents) {
    view = mesh.getViewForAttrib('TEXCOORD0');
    if (view is Vector2List) {
      texCoordView = view;
      generateVertexTexCoords(texCoordView, positionView, mesh.indices);
    }
  }

  if (flags.normals || flags.tangents) {
    view = mesh.getViewForAttrib('NORMAL');
    if (view is Vector3List) {
      normalView = view;
      generateVertexNormals(normalView, positionView, mesh.indices);
    }
  }

  if (flags.tangents) {
    view = mesh.getViewForAttrib('TANGENT');
    if (view is Vector4List) {
      tangentView = view;
      generateVertexTangents(
          tangentView, positionView, normalView, texCoordView, mesh.indices);
    }
  }

  if (filters != null) {
    for (GeometryFilter filter in filters) {
      if (filter.inplace && filter is InplaceGeometryFilter) {
        filter.filterInplace(mesh);
      } else {
        mesh = filter.filter(mesh);
      }
    }
  }

  return mesh;
}