How do i calculate the outer bounds???
Hello so i have a script on duplicating Vector3[](newVerts) but i would like to know how can i only duplicate the outer bounds vertices(newVerts) of the object, like this in the picture below?
Would anyone know how to do this, i'll be very pleased if some could help me out with this?
Here is my duplication code.
public class Extruder : MonoBehaviour
{
public float rotAngle;
public int stretch = 5;
public MeshFilter mf;
private Vector3[] origVerts;
private Vector3[] newVerts;
float xStretchDistance = 0f;
float zStretchDistance = 1f;
float yStretchDistance = 0f;
void Start()
{
mf = GetComponent<MeshFilter>();
Generate();
}
void Generate()
{
origVerts = mf.mesh.vertices;
newVerts = new Vector3[origVerts.Length * stretch];
for (int i = 0; i < origVerts.Length; i++)
{
for (int j = 0; j < stretch; j++)
{
float newX = origVerts[i].x + xStretchDistance * j;
float newY = origVerts[i].y + yStretchDistance * j;
float newZ = origVerts[i].z + zStretchDistance * j;
Vector3 pos = new Vector3(this.transform.position.x + newX, this.transform.position.y + newY, this.transform.position.z + newZ);
newVerts[j + i * stretch] = pos;
}
}
Mesh newMesh = new Mesh();
newMesh.vertices = newVerts;
mf.mesh = newMesh;
}
void OnDrawGizmos()
{
Gizmos.color = Color.white;
for (int i = 0; i < newVerts.Length; i++)
{
Gizmos.DrawSphere(newVerts[i], 0.1f);
}
Gizmos.color = Color.green;
for (int i = 0; i < origVerts.Length; i++)
{
Gizmos.DrawSphere(origVerts[i], 0.2f);
}
}
}
I havent generated meshes with vertices in a while so I am having trouble remembering the order the verts are generated, however....
you could get the border verts inside your forloops I believe.
if (i == origVerts.Length - 1) {
//Border vert
}
if (i == 0) {
//Border vert
}
That would give you at least 2 sides of your mesh. you would need the other forloop (for you the "stretch" length) to generate the other 2 sides. I will try to explain my thought process...
If you have a 5x5 square made up of 25 vertices, with x being horizontal and y being vertical [x,y] , the borders would be:
bottom: [0,0] [0,1] [0,2] [0,3] [0,4]
left: [0,0] [1,0] [2,0] [3,0] [4,0]
top: [0,4] [1,4] [2,4] [3,4] [4,4]
right: [4,0] [4,1] [4,2] [4,3] [4,4]
Thanks but i have already done that, iv'e been looking for a way that works with any mesh.
There are a few answers out there that relate to triangles sharing vertices. They are explained more in depth in these answers.
http://answers.unity3d.com/questions/1019436/get-outeredge-vertices-c.html
http://answers.unity3d.com/questions/443633/finding-the-vertices-of-each-edge-on-mesh.html
http://answers.unity3d.com/questions/566779/how-to-find-the-vertices-of-each-edge-on-mesh.html
Thanks, i will now "LEARN!" about the mysterious mesh.
Your answer
Follow this Question
Related Questions
How to add manual generated color ? 0 Answers
Hiding part of mesh 0 Answers
How do i use lines to calculate triangles on mesh?? 0 Answers
Can someone please help me with mesh extrusion 0 Answers
How do i calculate mesh on a spline?? 0 Answers