Mesh generator plug-ins

Mesh generator plug-ins generate a polygonal mesh given a set of input parameters. The plug-in's job is to act as a black box that defines and accepts a list of parameters of various types and outputs a PolygonMesh3 object.

Geometry

For example, consider the following function:

PolygonMesh3 MyMeshGenerator( float width, float height, bool flag )
{
	return new PolygonMesh3();
}

This function generates a new PolygonMesh3 object given three parameters: width, height, and a flag. Coden will automatically classify this function as a mesh generator plug-in because its output type is a PolygonMesh3.

Writing mesh generators

As with the rest of Coden there are two main ways to define a mesh generator plugin: through the use of a function or a class. The choice is left up to you based on your needs.

Texture Coordinates

If you wish to accept texture coordinates of an input mesh or generate texture coordinates with an output mesh you will have to construct a separate "texture mesh" and output it inside the same port group as the geometry mesh. Consider this example:

[Output( Group = "output" )]
public static PolygonMesh3 MyMeshGenerator( float width, float height, 
	[Output( Group = "output", Tags = CommonTags.TextureCoordinates )] out PolygonMesh3 resultTexCoords )
{
	// Generate and return result, generate result UV coordinates into resultTexCoords
}

The function now has an Output custom attribute which specifies a group "output". This is necessary so that we can pair the resulting PolygonMesh3 with another PolygonMesh3, which will contain the texture coordinates. We also add a parameter resultTexCoords. This is an output parameter which we mark to also belong to the group "output" and also contains the TextureCoordinates tag. This tag lets Coden know that your intention is to put UV coordinates for the generated mesh into this mesh. As stated before, resultTexCoords mesh must have exactly the same number of polygons each with the same number of vertices as the resulting mesh.

Note that the group name in this case can be arbitrary (doesn't have to be "output") as long as both Output attributes use the same one.

Please refer to the samples project TexturedPlane class to see how to output texture coordinates when defining your plug-in through a class instead of a function.

You may also wish to accept other meshes which contain texture coordinates as inputs for your mesh generator. Consider this example:

public static PolygonMesh3 MyMeshGenerator( float width, float length,
	[Input( Group = "mesh1" )] PolygonMesh3 meshInput,
	[Input( Group = "mesh1", Tags = CommonTags.TextureCoordinates )] PolygonMesh3 meshInputTexCoords )
{
	// meshInputTexCoords will contain UV coordinates for the meshInput parameter (if they are available)
}

This is very similar to the previous example, except we now take an input parameter and use Input attribute to mark the group for each polygon mesh. We also use the TextureCoordinates tag to mark the second polygon mesh parameter as the texture coordinates for the preceding mesh input. Coden will, in this case, pass UV coordinates of meshInput in the meshInputTexCoords parameter.

Examples

For examples of mesh generator plug-ins, see Cube.cs, Plane.cs, Pyramid.cs, Sphere.cs, and TexturedPlane.cs files available in the samples project.