# Mesh line renderer - line segments camera align

I have simple line renderer, that create line as mesh. That generate separated line segments (line segment = 1 quad = 2 triangle faces). The inputs are two Vector3 points.

Here is part of code which generates verticies for final segment mesh:

``````Vector3[] MakeQuad(Vector3 s, Vector3 e, float w) {
// s ... start point
// e ... endpoint
// w ... width of line segment
w = w / 2;
Vector3[] q = new Vector3[4];

Vector3 n = Vector3.Cross(s, e);
Vector3 l = Vector3.Cross(n, e-s);

l.Normalize();

q[0] = transform.InverseTransformPoint(s + l * w);
q[1] = transform.InverseTransformPoint(s + l * -w);
q[2] = transform.InverseTransformPoint(e + l * w);
q[3] = transform.InverseTransformPoint(e + l * -w);

// here need rotate short sides of segment and align vericies
// parallel with camera.Up (billboarding)

return q;
}

``````

I need generate q[0..3] to be rotated facing to camera (like particle billboarding). I need some mesh modifier, that provide calculation. I need rotate verticies on left side of the line according to start point and rotate them. The right side verticies must be rotatet around end point.

Anchor point are start ponint and endpoint. I know there will be some perspective distortion, but will be better than native Line Renderer .

I cant use LookAt and similar functions, becouse that functions rotate whole object. I cant use that becouse need to align every single segment of line.

I need help with rotation of verticies, becouse Im not math guru. Can anybody help me?

Solved myself. Simply add camera reference to the class

``````public Camera cam;

``````

and here is final method:

``````Vector3[] MakeQuad(Vector3 s, Vector3 e, float w) {
w = w / 2;
Vector3[] q = new Vector3[4];

//standard normal based on points
//Vector3 n = Vector3.Cross(s, e);
//Vector3 l = Vector3.Cross(n, e-s);

//camera forward based normal
Vector3 l = Vector3.Cross(cam.transform.forward, e-s);

l.Normalize();
q[0] = transform.InverseTransformPoint(s + l * w );
q[1] = transform.InverseTransformPoint(s + l * -w);
q[2] = transform.InverseTransformPoint(e + l * w);
q[3] = transform.InverseTransformPoint(e + l * -w);

return q;
}

``````