Question by
Raviraja190 · Nov 11, 2016 at 12:44 PM ·
c#meshscript.
Want to Make Mesh with script in an Egg Shape
void CreateMesh() { vertexCount = (width + 1) * (height + 1);
int trianglesCount = width * height * 6;
vertices = new Vector3[vertexCount];
triangles = new int[trianglesCount];
uv = new Vector2[vertexCount];
int t;
for (int y = 0; y <= height; y++) {
for (int x = 0; x <= width; x++) {
int v = (width + 1) * y + x;
vertices[v] = new Vector3(x / (float)width - 0.5f,
y / (float)height - 0.5f, 0);
uv[v] = new Vector2(x / (float)width, y / (float)height);
if (x < width && y < height) {
t = 3 * (2 * width * y + 2 * x);
triangles[t] = v;
triangles[++t] = v + width + 1;
triangles[++t] = v + width + 2;
triangles[++t] = v;
triangles[++t] = v + width + 2;
triangles[++t] = v + 1;
}
}
}
Mesh mesh = GetComponent<MeshFilter>().mesh;
mesh.vertices = vertices;
mesh.uv = uv;
mesh.triangles = triangles;
}
Comment