I found a “reasonable” solution, where I use the opposite sides, create a direction vector, and multiple by my intended “width” of the frame I want. It is slightly to big width-wise, but it should work for now. My complication was trying to create a function that creates the inner vertices FROM the outer ones, without using coordinates.
public static Vector3 TranslateDistanceBetweenPoints(this Vector3 start, Vector3 end, float distance)
{
Vector3 dir = end - start;
Vector3 finalPos = start + (dir.normalized * distance);
return finalPos;
}
public void generateMesh()
{
//this assumes the "result" structure contains the outer vertices
innerResult.UpperLeft = result.UpperLeft.TranslateDistanceBetweenPoints(result.LowerRight,widthOfFrame);
innerResult.UpperRight = result.UpperRight.TranslateDistanceBetweenPoints(result.LowerLeft,widthOfFrame);
innerResult.LowerLeft = result.LowerLeft.TranslateDistanceBetweenPoints(result.UpperRight,widthOfFrame);
innerResult.LowerRight = result.LowerRight.TranslateDistanceBetweenPoints(result.UpperLeft,widthOfFrame);
//now use these points to create a mesh from the inner and outer points
//UL
//UR
//LL
//LR
Vector3[] vertices = new Vector3[]
{
//outer
result.UpperLeft,//0
result.UpperRight,//1
result.LowerLeft,//2
result.LowerRight,//3
//inner
innerResult.UpperLeft,//4
innerResult.UpperRight,//5
innerResult.LowerLeft,//6
innerResult.LowerRight//7
};
Vector3[] normals =
{
-Vector3.forward,
-Vector3.forward,
-Vector3.forward,
-Vector3.forward,
-Vector3.forward,
-Vector3.forward,
-Vector3.forward,
-Vector3.forward
};
Vector2[] uv = new Vector2[]
{
new Vector2(1, 1),
new Vector2(1, 0),
new Vector2(0, 1),
new Vector2(0, 0),
new Vector2(1, 1),
new Vector2(1, 0),
new Vector2(0, 1),
new Vector2(0, 0)
};
int[] triangles = new int[]
{
//upper
0, 1, 4,
4, 1, 5,
//lower
2, 6, 7,
2, 7, 3,
//left
2, 0, 4,
2, 4, 6,
//right
7, 5, 1,
7, 1, 3
};
meshFilter.mesh.Clear();
meshFilter.mesh.MarkDynamic();
meshFilter.mesh.vertices = vertices;
meshFilter.mesh.triangles = triangles;
meshFilter.mesh.normals = normals;
meshFilter.mesh.uv = uv;
}
It seems like you're trying to make a miter joint. The math behind it is discussed in one of the posts [here][1]. (Scroll down until you see the post with diagrams.) It's a bit difficult to understand what you mean when you say "the triangles
– _Gkxdfliparound and face the wrong direction" without code or screenshots of how it messes up. [1]: https://forum.libcinder.org/topic/smooth-thick-lines-using-geometry-shaderYou are probably setting the triangles clockwise, not counter clock wise(might be the other way around) You should flip the order in which you are adding the vertecies
– OrbitGamesThe last image wouldnt attach to the prior post -_- [51320-screen-shot-2015-07-30-at-34416-pm.png|51320]
– 1337GameDev