How can i change the center point of the mesh? (SOLVED)

Hi,
In the “custom geometry tutorial” or the “projected grid” project I’m working on, the center point of the object is always the corner of the object.


How can I center it? There is an option called “Center Geometry” in the model import window. Is there a way to do this for a realtime generated mesh/model with code?
centergeometry

Thanks in advance.

Okay, in the custom geometry tutorial the problem is solved with vertex shifting. I solved the problem by making the vertex positions -50, 50 instead of 0, 100. But I don’t know how to do this in projected grid.

Can someone tell me how to shift vertexes in these codes?

public Mesh CreateQuad(int numVertsX, int numVertsY)
{
	Vector3[] vertices = new Vector3[numVertsX * numVertsY];
	Vector2[] texcoords = new Vector2[numVertsX * numVertsY];
	int[] indices = new int[numVertsX * numVertsY * 6];

	for (int x = 0; x < numVertsX; x++)
	{
		for (int y = 0; y < numVertsY; y++)
		{
			Vector2 uv = new Vector3(x / (numVertsX - 1.0f), y / (numVertsY - 1.0f));

			texcoords[x + y * numVertsX] = uv;
			vertices[x + y * numVertsX] = new Vector3(uv.x, uv.y, 0.0f);
		}
	}

	int num = 0;
	for (int x = 0; x < numVertsX - 1; x++)
	{
		for (int y = 0; y < numVertsY - 1; y++)
		{
			indices[num++] = x + y * numVertsX;
			indices[num++] = x + (y + 1) * numVertsX;
			indices[num++] = (x + 1) + y * numVertsX;
			
			indices[num++] = x + (y + 1) * numVertsX;
			indices[num++] = (x + 1) + (y + 1) * numVertsX;
			indices[num++] = (x + 1) + y * numVertsX;
		}
	}
	//mesh.UpdateMesh here 
}

EDIT: Here is the solution: :sweat_smile:

vertices[x + y * numVertsX].X -= 0.5f;
vertices[x + y * numVertsX].Y -= 0.5f;