- Home /

# Extrude mesh in vertices normal direction (using MeshExtrusion.cs example)

Hi

I'm attempting to extrude a mesh by duplicating the vertices in a mesh and moving them in their normal direction.

I have been using the MeshExtrusion.cs from the Procedural Examples asset.

Here is the original: MeshExtrusion.cs

And here is how I'm pushing the new vertices in their normal direction

```
Vector3[] inputNormals = srcMesh.normals;
// Build extruded vertices
int v = 0;
for (int i=0;i<extrusion.Length;i++)
{
Matrix4x4 matrix = extrusion[i];
float vcoord = (float)i / (extrusion.Length -1);
foreach (Edge e in edges)
{
//vertices[v+0] = matrix.MultiplyPoint(inputVertices[e.vertexIndex[0]]);
//vertices[v+1] = matrix.MultiplyPoint(inputVertices[e.vertexIndex[1]]);
//Push in normal direction
vertices[v+0] = inputVertices[e.vertexIndex[0]] + (inputNormals[e.vertexIndex[0]].normalized * (float)i);
vertices[v+1] = inputVertices[e.vertexIndex[1]] + (inputNormals[e.vertexIndex[1]].normalized * (float)i);
uvs[v+0] = new Vector2 (inputUV[e.vertexIndex[0]].x, vcoord);
uvs[v+1] = new Vector2 (inputUV[e.vertexIndex[1]].x, vcoord);
v += 2;
}
}
// Build cap vertices
// * The bottom mesh we scale along it's negative extrusion direction. This way extruding a half sphere results in a capsule.
for (int c=0;c<2;c++)
{
Matrix4x4 matrix = extrusion[c == 0 ? 0 : extrusion.Length-1];
int firstCapVertex = c == 0 ? extrudedVertexCount : extrudedVertexCount + inputVertices.Length;
for (int i=0;i<inputVertices.Length;i++)
{
//vertices[firstCapVertex + i] = matrix.MultiplyPoint(inputVertices[i]);
//Push in normal direction
//vertices[firstCapVertex + i] = inputVertices[i] + (inputNormals[i].normalized * 1.0f);
uvs[firstCapVertex + i] = inputUV[i];
}
}
```

But it doesn't work as intended. The mesh seems inside out (even when I flip the faces) and the ends don't have faces at all

(Cube, extruded 4 times)

(Quad, extruded 4 times)

Using the original MeshExtrusion.cs script how do I extrude a mesh in the directions of its normals?

Any help would be greatly appreciated,

Thanks

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

Smooth Extruded Mesh? 1 Answer

Recalculate Normals? 3 Answers

Dividing Extruded Object into Manageable Pieces? 0 Answers

How do i Achieve mesh Extrusion? 2 Answers

Fix ugly extrusions (Quaternions)? 0 Answers