C# Extend Mesh Ngon Class


I would like to ask how can I extend Mesh Ngons Class?

What I would like to do is when I write MyWonderfullMesh.Ngons. here I would like to have more methods.

Currently I am writing public static method for Mesh, but it became too messy, since it mixes up with normal mesh methods.

1 Like

Do you mean you are creating extension methods?

Yes, but annoying part is that extension methods is written like this:

public static void WonderfullMethod (this Mesh mesh){

so these methods appear on MyWonderfullMesh.WonderfullMethod .
but not on MyWonderfullMesh.Ngons.WonderfullMethod

The thing is that I need to have access of mesh itself in that method, but from user persective I would like to keep it under NGons name.

Is it possible?

Create an extension method on MeshNgonList instead:


public static void EvenWonderfullerMethod(this MeshNgonList ngons) {

Thanks Nathan, but MeshNGonList does not have any information about Mesh itself so I cannot now its mesh vertices positions, edge id and etc. I think I am doing something wrong.

You could always work around that by having an extra parameter to the function that takes the Mesh too.

This would look like this then:

MyMesh.Ngons(MyMesh), thanks Nathan for help, I will change the naming, as going to Ngons collections makes it a bit more messier.


I see three ways how to handle:

  1. Don’t care, just continue as you did before
  2. Give your methods clear names: NgonsWonderfulOperation(), continue otherwise as you did before
  3. Do the extension on the collection and pass in the Mesh as well.

I guess you’re going for 2. now?

Yup, Thanks:)