GetForwardVector() public static method

public static GetForwardVector ( Quaternion q ) : Vector3
q Quaternion
return Vector3
示例#1
0
    //Setup all the papi lights.
    private void SetupPapiLights(ref List <SpriteLights.LightData> lightData, RunwayData runwayData, bool randomBrightness)
    {
        for (int side = 0; side < 2; side++)
        {
            if (runwayData.papiType[side] != PapiType.NONE)
            {
                //Calculate the offset direction.
                Vector3 lengthOffsetDir     = Math3d.GetForwardVector(runwayData.rotation[side]);
                Vector3 sideOffsetDir       = Math3d.GetRightVector(runwayData.rotation[side]);
                Vector3 lengthEdgeOffsetVec = Math3d.SetVectorLength(lengthOffsetDir, 337f);

                if ((runwayData.papiType[side] == PapiType.PAPIRIGHT) || (runwayData.papiType[side] == PapiType.PAPIBOTH))
                {
                    Vector3 startOffsetVec  = lengthEdgeOffsetVec + Math3d.SetVectorLength(sideOffsetDir, (runwayData.width * 0.5f) + 15f);
                    Vector3 startPosition   = runwayData.thresholdPosition[side] + startOffsetVec;
                    Vector3 currentPosition = startPosition;

                    Vector3 sideOffsetVec = Math3d.SetVectorLength(sideOffsetDir, 9f);

                    for (int i = 0; i < 4; i++)
                    {
                        SpriteLights.LightData data = new SpriteLights.LightData();

                        float angle = GetPapiAngle(i);

                        data.position = currentPosition;
                        data.rotation = runwayData.rotation[side] * Quaternion.Euler(Vector3.right * angle);
                        lightData.Add(data);

                        currentPosition += sideOffsetVec;
                    }
                }

                if ((runwayData.papiType[side] == PapiType.PAPILEFT) || (runwayData.papiType[side] == PapiType.PAPIBOTH))
                {
                    sideOffsetDir *= -1;

                    Vector3 startOffsetVec  = lengthEdgeOffsetVec + Math3d.SetVectorLength(sideOffsetDir, (runwayData.width * 0.5f) + 15f);
                    Vector3 startPosition   = runwayData.thresholdPosition[side] + startOffsetVec;
                    Vector3 currentPosition = startPosition;

                    Vector3 sideOffsetVec = Math3d.SetVectorLength(sideOffsetDir, 9f);

                    for (int i = 0; i < 4; i++)
                    {
                        SpriteLights.LightData data = new SpriteLights.LightData();

                        float angle = GetPapiAngle(i);

                        data.position = currentPosition;
                        data.rotation = runwayData.rotation[side] * Quaternion.Euler(Vector3.right * angle);
                        lightData.Add(data);

                        currentPosition += sideOffsetVec;
                    }
                }
            }
        }
    }
示例#2
0
        public void SetThresholdPosition(Vector3 position, float lengthIn)
        {
            //Set the length
            length = lengthIn;

            //Set the first threshold position.
            thresholdPosition[0] = position;

            //Set the other side threshold position.
            Vector3 forwardOffsetDir = Math3d.GetForwardVector(rotation[0]);
            Vector3 thresholdAtoBVec = Math3d.SetVectorLength(forwardOffsetDir, length);

            thresholdPosition[1] = thresholdPosition[0] + thresholdAtoBVec;
        }
示例#3
0
    // All axes are in degrees
    public void setAxes(float set_rotor, float set_lower, float set_upper, float set_wrist, float set_seat)
    {
        Vector3 localForward = Math3d.GetForwardVector(transform.rotation);
        Vector3 localRight   = Vector3.Cross(localForward, Vector3.down);

        RobotArm_main_rotor.transform.localPosition     = Vector3.zero;
        RobotArm_main_rotor.transform.localRotation     = Quaternion.AngleAxis(set_rotor, Vector3.up);
        RobotArm_lower_arm.transform.localPosition      = segment1;
        RobotArm_lower_arm.transform.localRotation      = Quaternion.AngleAxis(set_lower, localForward);
        RobotArm_upper_arm_back.transform.localPosition = segment2;
        RobotArm_upper_arm_back.transform.localRotation = Quaternion.AngleAxis(set_upper, localForward);
        RobotArm_wrist_peice.transform.localPosition    = segment3;
        RobotArm_wrist_peice.transform.localRotation    = Quaternion.AngleAxis(180 - set_wrist, localForward);
        RobotArm_seat.transform.localPosition           = segment4;
        RobotArm_seat.transform.localRotation           = Quaternion.AngleAxis(180 + set_seat, localRight);
    }
示例#4
0
    //Create a light mesh object. Cram as much lights as you can into the LightData array. If there are too many lights for one GameObject, it will
    //automatically be split into multiple objects.
    public static GameObject[] CreateLights(string name, LightData[] lightData, Material material)
    {
        int transformAmount = lightData.Length;
        int lightsInThisBatch;

        //The triangle limit is 21844 (65534 vertices) per mesh, so split the objects up if needed.
        int meshAmount = (int)Mathf.Ceil(transformAmount / (float)maxTriangleAmount);

        GameObject[] lightObjects = new GameObject[meshAmount];

        //Get the remainder.
        int remainder = (int)(transformAmount % (float)maxTriangleAmount);

        //Loop through the mesh batches.
        for (int l = 0; l < meshAmount; l++)
        {
            //Get the amount of lights in this mesh batch.
            if (meshAmount == 1)
            {
                lightsInThisBatch = transformAmount;
            }

            else
            {
                //Last mesh batch.
                if (l == (meshAmount - 1))
                {
                    if (remainder == 0)
                    {
                        lightsInThisBatch = maxTriangleAmount;
                    }

                    else
                    {
                        lightsInThisBatch = remainder;
                    }
                }

                else
                {
                    lightsInThisBatch = maxTriangleAmount;
                }
            }

            int vertexCount = lightsInThisBatch * 3;

            Vector4[] corners         = new Vector4[vertexCount];
            Vector2[] uvs             = new Vector2[vertexCount];
            Vector4[] triangleCorners = new Vector4[3];
            Vector2[] triangleUvs     = new Vector2[3];
            bool      directional     = false;
            bool      omnidirectional = false;
            bool      strobe          = false;
            bool      papi            = false;
            Vector3   normal          = Vector3.one;
            Vector3   right           = Vector3.one;
            Vector3   up = Vector3.one;

            //Create temporary arrays.
            Vector3[] centers   = new Vector3[vertexCount];
            Vector3[] normals   = new Vector3[vertexCount];
            int[]     triangles = new int[vertexCount];
            int[]     indices   = new int[vertexCount];

            //What is stored in here, depends on the shader.
            Vector2[] uv3Channel   = new Vector2[vertexCount];
            Vector2[] uv2Channel   = new Vector2[vertexCount];
            Vector2[] uv4Channel   = new Vector2[vertexCount];
            Color[]   colorChannel = new Color[vertexCount];

            if (material.shader.name.Contains("Directional"))
            {
                directional = true;
            }

            if (material.shader.name.Contains("Omnidirectional"))
            {
                omnidirectional = true;
            }

            if (material.shader.name.Contains("Strobe"))
            {
                strobe = true;
            }

            if (material.shader.name.Contains("PAPI"))
            {
                papi = true;
            }

            //Loop through all the lights and set them up.
            for (int i = 0; i < lightsInThisBatch; i++)
            {
                int e     = i * 3;
                int e1    = e + 1;
                int e2    = e + 2;
                int index = (l * maxTriangleAmount) + i;

                //Generate a triangle which fits over a quad.
                GenerateTriangle(out triangleCorners, out triangleUvs, lightData[index].size, Quaternion.identity);

                centers[e]  = lightData[index].position;
                centers[e1] = lightData[index].position;
                centers[e2] = lightData[index].position;

                //Get the rotation vectors.
                normal = -Math3d.GetForwardVector(lightData[index].rotation);
                right  = Math3d.GetRightVector(lightData[index].rotation);
                up     = Math3d.GetUpVector(lightData[index].rotation);

                //Store the scale offset in the w component of the triangle corner.
                triangleCorners[0] = new Vector4(triangleCorners[0].x, triangleCorners[0].y, triangleCorners[0].z, lightData[index].size);
                triangleCorners[1] = new Vector4(triangleCorners[1].x, triangleCorners[1].y, triangleCorners[1].z, lightData[index].size);
                triangleCorners[2] = new Vector4(triangleCorners[2].x, triangleCorners[2].y, triangleCorners[2].z, lightData[index].size);

                corners[e]  = triangleCorners[0];
                corners[e1] = triangleCorners[1];
                corners[e2] = triangleCorners[2];

                uvs[e]  = triangleUvs[0];
                uvs[e1] = triangleUvs[1];
                uvs[e2] = triangleUvs[2];

                normals[e]  = normal;
                normals[e1] = normal;
                normals[e2] = normal;

                if (papi)
                {
                    uv2Channel[e]  = right;
                    uv2Channel[e1] = right;
                    uv2Channel[e2] = right;

                    uv3Channel[e]  = up;
                    uv3Channel[e1] = up;
                    uv3Channel[e2] = up;

                    //Compose the z vector.
                    Vector2 zVector = new Vector2(right.z, up.z);
                    uv4Channel[e]  = zVector;
                    uv4Channel[e1] = zVector;
                    uv4Channel[e2] = zVector;
                }

                if (directional)
                {
                    //Create the back color.
                    Vector2 RG = new Vector2(lightData[index].backColor.r, lightData[index].backColor.g);
                    Vector2 BA = new Vector2(lightData[index].backColor.b, lightData[index].backColor.a);

                    uv2Channel[e]  = RG;
                    uv2Channel[e1] = RG;
                    uv2Channel[e2] = RG;

                    uv3Channel[e]  = BA;
                    uv3Channel[e1] = BA;
                    uv3Channel[e2] = BA;
                }

                if (omnidirectional)
                {
                    //Create the back color.
                    Vector2 RG = new Vector2(lightData[index].backColor.r, lightData[index].backColor.g);

                    uv2Channel[e]  = RG;
                    uv2Channel[e1] = RG;
                    uv2Channel[e2] = RG;

                    uv3Channel[e]  = up;
                    uv3Channel[e1] = up;
                    uv3Channel[e2] = up;

                    //Compose the z vector. The x component is used for the blue component of the back color.
                    Vector2 zVector = new Vector2(lightData[index].backColor.b, up.z);
                    uv4Channel[e]  = zVector;
                    uv4Channel[e1] = zVector;
                    uv4Channel[e2] = zVector;
                }

                if (strobe)
                {
                    //Store the light and group id in the color channel.
                    Color id = new Color(lightData[index].strobeID, lightData[index].strobeGroupID, 0, 0);

                    colorChannel[e]  = id;
                    colorChannel[e1] = id;
                    colorChannel[e2] = id;
                }

                if (directional || omnidirectional)
                {
                    //Create the front color. Note that the light brightness value is stored in the alpha channel.
                    Color frontColor = new Color(lightData[index].frontColor.r, lightData[index].frontColor.g, lightData[index].frontColor.b, lightData[index].brightness);

                    colorChannel[e]  = frontColor;
                    colorChannel[e1] = frontColor;
                    colorChannel[e2] = frontColor;
                }

                triangles[e]  = e;
                triangles[e1] = e1;
                triangles[e2] = e2;

                indices[e]  = e;
                indices[e1] = e1;
                indices[e2] = e2;
            }

            //Create a new gameObject.
            GameObject lightObject = new GameObject(name + " " + l);
            lightObjects[l] = lightObject;

            //Add the required components to the game object.
            MeshFilter   meshFilter   = lightObject.AddComponent <MeshFilter>();
            MeshRenderer meshRenderer = lightObject.AddComponent <MeshRenderer>();

            //Create a new mesh.
            meshFilter.sharedMesh = new Mesh();

            //Apply the mesh properties
            meshFilter.sharedMesh.vertices  = centers;
            meshFilter.sharedMesh.tangents  = corners;            //The mesh corner is stored in the tangent channel. The scale is stored in the w component.
            meshFilter.sharedMesh.normals   = normals;
            meshFilter.sharedMesh.uv        = uvs;
            meshFilter.sharedMesh.triangles = triangles;
            meshFilter.sharedMesh.colors    = colorChannel;     //Front color for directional lights. Alpha is the brightness reduction. //ID for strobe lights.
            meshFilter.sharedMesh.uv2       = uv2Channel;       //RG(BA) back color for directional lights. //Rotation vector for omnidirectional lights and PAPIs.
            meshFilter.sharedMesh.uv3       = uv3Channel;       //(RG)BA back color for directional lights. Alpha is for invisibility. //Rotation vector for omnidirectional lights and PAPIS.
            meshFilter.sharedMesh.uv4       = uv4Channel;       //The UV channels only hold two floats, so use a third UV channel to store the Z components of the vectors.

            //Set the indices.
            meshFilter.sharedMesh.SetIndices(indices, MeshTopology.Triangles, 0);

            //Set the gameObject properties;
            meshRenderer.sharedMaterial       = material;
            meshRenderer.shadowCastingMode    = UnityEngine.Rendering.ShadowCastingMode.Off;
            meshRenderer.receiveShadows       = false;
            meshRenderer.useLightProbes       = false;
            meshRenderer.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
        }

        return(lightObjects);
    }
示例#5
0
    //Setup all the centerline lights.
    private void SetupCenterlineLights(ref List <SpriteLights.LightData> lightData, RunwayData runwayData, bool randomBrightness, float brightness, float size)
    {
        if (runwayData.centerlineLights)
        {
            //Calculate the amount of lights.
            int lightAmountInRow = (int)Mathf.Floor(runwayData.length / runwayData.centerlineLightsSpacing);

            //Calculate the offset direction.
            Vector3 lengthOffsetDir = Math3d.GetForwardVector(runwayData.rotation[0]);

            //Calculate the start position.
            float rowLength  = (lightAmountInRow - 1) * runwayData.centerlineLightsSpacing;
            float edgeOffset = (runwayData.length - rowLength) * 0.5f;

            Vector3 startOffsetVec  = Math3d.SetVectorLength(lengthOffsetDir, edgeOffset);
            Vector3 startPosition   = runwayData.thresholdPosition[0] + startOffsetVec;
            Vector3 currentPosition = startPosition;

            Vector3 lengthOffsetVec = Math3d.SetVectorLength(lengthOffsetDir, runwayData.centerlineLightsSpacing);

            //Calculate the point where the lights should change color.
            float redA       = 300f + runwayData.centerlineLightsSpacing;
            float redB       = (runwayData.length - (300f + runwayData.centerlineLightsSpacing));
            float alternateA = 900f + runwayData.centerlineLightsSpacing;
            float alternateB = (runwayData.length - (900f + runwayData.centerlineLightsSpacing));

            for (int i = 0; i < lightAmountInRow; i++)
            {
                bool passedRedA       = false;
                bool passedAlternateA = false;
                bool passedRedB       = false;
                bool passedAlternateB = false;

                SpriteLights.LightData data = new SpriteLights.LightData();

                //Is the current light index even or odd?
                bool even = IsEven(i);

                data.position = currentPosition;
                data.rotation = runwayData.rotation[0];

                //Calculate the distance to the threshold.
                float currentDistance = (i * runwayData.centerlineLightsSpacing) + edgeOffset;

                //The last 900 meter of the runway has alternating red and white lights.
                if (currentDistance <= alternateA)
                {
                    passedAlternateA = true;
                }

                //The last 900 meter of the runway has alternating red and white lights.
                if (currentDistance >= alternateB)
                {
                    passedAlternateB = true;
                }

                //The last 300 meter of the runway has red centerline lights.
                if (currentDistance <= redA)
                {
                    data.frontColor = whiteLight;
                    data.brightness = SetBrightness(randomBrightness, brightness);
                    data.backColor  = redLight;

                    passedRedA = true;
                }

                //The last 300 meter of the runway has red centerline lights.
                if (currentDistance >= redB)
                {
                    passedRedB = true;

                    data.frontColor = redLight;
                    data.brightness = SetBrightness(randomBrightness, brightness);
                    data.backColor  = whiteLight;
                }

                //The last 900 meter of the runway has alternating red and white lights.
                if (passedAlternateA && !passedRedA)
                {
                    if (even)
                    {
                        data.frontColor = whiteLight;
                        data.brightness = SetBrightness(randomBrightness, brightness);
                        data.backColor  = redLight;
                    }

                    else
                    {
                        data.frontColor = whiteLight;
                        data.brightness = SetBrightness(randomBrightness, brightness);
                        data.backColor  = whiteLight;
                    }
                }

                //The last 900 meter of the runway has alternating red and white lights.
                if (passedAlternateB && !passedRedB)
                {
                    if (even)
                    {
                        data.frontColor = redLight;
                        data.brightness = SetBrightness(randomBrightness, brightness);
                        data.backColor  = whiteLight;
                    }

                    else
                    {
                        data.frontColor = whiteLight;
                        data.brightness = SetBrightness(randomBrightness, brightness);
                        data.backColor  = whiteLight;
                    }
                }

                //Middle of the runway
                if (!passedRedA && !passedRedB && !passedAlternateA && !passedAlternateB)
                {
                    data.frontColor = whiteLight;
                    data.brightness = SetBrightness(randomBrightness, brightness);
                    data.backColor  = whiteLight;
                }

                data.size = size;

                lightData.Add(data);

                currentPosition += lengthOffsetVec;
            }
        }
    }
示例#6
0
    //Setup all the edge lights.
    private void SetupEdgeLights(ref List <SpriteLights.LightData> lightData, RunwayData runwayData, bool randomBrightness, float brightness, float size)
    {
        float sideFactor = 0;

        //Calculate the amount of lights.
        int lightAmountInRow = (int)Mathf.Floor(runwayData.length / runwayData.edgeLightsSpacing);

        //Calculate the offset direction.
        Vector3 lengthOffsetDir = Math3d.GetForwardVector(runwayData.rotation[0]);
        Vector3 sideOffsetDir   = Math3d.GetRightVector(runwayData.rotation[0]);

        //Calculate the start position.
        float rowLength         = (lightAmountInRow - 1) * runwayData.edgeLightsSpacing;
        float edgeForwardOffset = (runwayData.length - rowLength) * 0.5f;

        Vector3 lengthEdgeOffsetVec = Math3d.SetVectorLength(lengthOffsetDir, edgeForwardOffset);
        Vector3 startOffsetVec      = lengthEdgeOffsetVec + Math3d.SetVectorLength(sideOffsetDir, runwayData.width * 0.5f);
        Vector3 startPosition       = runwayData.thresholdPosition[0] + startOffsetVec;
        Vector3 currentPosition     = startPosition;

        Vector3 lengthOffsetVec = Math3d.SetVectorLength(lengthOffsetDir, runwayData.edgeLightsSpacing);

        //Calculate the point where the lights should change color.
        float amberA = 600f + runwayData.edgeLightsSpacing;
        float amberB = (runwayData.length - (600f + runwayData.edgeLightsSpacing));

        int doubleLightAmountInRow = lightAmountInRow * 2;

        for (int i = 0; i < doubleLightAmountInRow; i++)
        {
            bool passedAmberA = false;
            bool passedAmberB = false;

            SpriteLights.LightData data = new SpriteLights.LightData();

            //Shift the current position for the other side.
            if (i == lightAmountInRow)
            {
                startOffsetVec  = lengthEdgeOffsetVec + Math3d.SetVectorLength(-sideOffsetDir, runwayData.width * 0.5f);
                currentPosition = runwayData.thresholdPosition[0] + startOffsetVec;

                //Reset flags.
                passedAmberA = false;
                passedAmberB = false;
                sideFactor   = lightAmountInRow;
            }

            data.position = currentPosition;
            data.rotation = runwayData.rotation[0];

            //Calculate the distance to the threshold.
            float currentDistance = ((i - sideFactor) * runwayData.edgeLightsSpacing) + edgeForwardOffset;

            //The last 600 meter of the runway has red centerline lights.
            if (currentDistance <= amberA)
            {
                data.frontColor = whiteLight;
                data.brightness = SetBrightness(randomBrightness, brightness);
                data.backColor  = amberLight;

                passedAmberA = true;
            }

            //The last 300 meter of the runway has red centerline lights.
            if (currentDistance >= amberB)
            {
                passedAmberB = true;

                data.frontColor = amberLight;
                data.brightness = SetBrightness(randomBrightness, brightness);
                data.backColor  = whiteLight;
            }

            //Middle of the runway
            if (!passedAmberA && !passedAmberB)
            {
                data.frontColor = whiteLight;
                data.brightness = SetBrightness(randomBrightness, brightness);
                data.backColor  = whiteLight;
            }

            data.size = size;

            lightData.Add(data);

            currentPosition += lengthOffsetVec;
        }
    }
    //Create a light mesh object. Cram as much lights as you can into the LightData array. If there are too many lights for one GameObject, it will
    //automatically be split into multiple objects.
    //When creating city lights, use the function overload which takes a position array instead of a lightData array.
    private static GameObject[] CreateLightsAll(string name, LightData[] lightData, Vector3[] positions, float simpleShaderLightSize, Material material, UnityEngine.Rendering.IndexFormat meshIndexFormat)
    {
        int transformAmount = 0;

        if (lightData != null)
        {
            transformAmount = lightData.Length;
        }

        else
        {
            transformAmount = positions.Length;
        }

        int lightsInThisBatch;
        int maxTriangles;

        if (meshIndexFormat == UnityEngine.Rendering.IndexFormat.UInt32)
        {
            maxTriangles = maxTriangls32;
        }

        else
        {
            maxTriangles = maxTriangls16;
        }

        //The triangle limit is 21844 (16 bit) or 1431655765 (32 bit) per mesh, so split the objects up if needed.
        int meshAmount = (int)Mathf.Ceil(transformAmount / (float)maxTriangles);

        GameObject[] lightObjects = new GameObject[meshAmount];

        //Get the remainder.
        int remainder = (int)(transformAmount % (float)maxTriangles);

        //Loop through the mesh batches.
        for (int l = 0; l < meshAmount; l++)
        {
            //Get the amount of lights in this mesh batch.
            if (meshAmount == 1)
            {
                lightsInThisBatch = transformAmount;
            }

            else
            {
                //Last mesh batch.
                if (l == (meshAmount - 1))
                {
                    if (remainder == 0)
                    {
                        lightsInThisBatch = maxTriangles;
                    }

                    else
                    {
                        lightsInThisBatch = remainder;
                    }
                }

                else
                {
                    lightsInThisBatch = maxTriangles;
                }
            }

            bool directional     = false;
            bool omnidirectional = false;
            bool strobe          = false;
            bool papi            = false;
            bool simple          = false;

            int vertexCount = lightsInThisBatch * 3;

            Vector4[] corners         = new Vector4[vertexCount];
            Vector2[] uvs             = new Vector2[vertexCount];
            Vector4[] triangleCorners = new Vector4[3];
            Vector2[] triangleUvs     = new Vector2[3];
            Vector3[] normals         = null;

            Vector3 normal = Vector3.one;
            Vector3 right  = Vector3.one;
            Vector3 up     = Vector3.one;

            //Create temporary arrays.
            Vector3[] centers   = new Vector3[vertexCount];
            int[]     triangles = new int[vertexCount];
            int[]     indices   = new int[vertexCount];

            Vector2[] uv2Channel   = null;
            Vector2[] uv3Channel   = null;
            Vector2[] uv4Channel   = null;
            Color[]   colorChannel = null;

            Vector4 corner0 = Vector4.zero;
            Vector4 corner1 = Vector4.zero;
            Vector4 corner2 = Vector4.zero;

            //Generate a triangle which fits over a quad.
            //Taken out of the function for performance.
            //GenerateTriangle(out triangleCorners, out triangleUvs);

            //Set the points, counter clockwise as an upright triangle, with the left
            //corner as point 0, right corner point 1, and top is point 2.
            //X and Y are computed like this:
            //x = (1f / Mathf.Tan(60f * Mathf.Deg2Rad)) + 0.5f;
            //y = // (0.5f / Mathf.Tan(30f * Mathf.Deg2Rad)) + 0.5f;
            triangleCorners[0] = new Vector4(-1.07735f, -0.5f, 0.0f, 1.0f);
            triangleCorners[1] = new Vector4(1.07735f, -0.5f, 0.0f, 1.0f);
            triangleCorners[2] = new Vector4(0.0f, 1.366025f, 0.0f, 1.0f);

            //Computed like this:
            //float u = Math3d.NormalizeComplex(localPoints[i].x, -0.5f, 0.5f);
            //float v = Math3d.NormalizeComplex(localPoints[i].y, -0.5f, 0.5f);
            triangleUvs[0].x = -0.57735f;
            triangleUvs[0].y = 0f;
            triangleUvs[1].x = 1.57735f;
            triangleUvs[1].y = 0f;
            triangleUvs[2].x = 0.5f;
            triangleUvs[2].y = 1.866025f;

            if (lightData != null)
            {
                normals = new Vector3[vertexCount];

                //What is stored in here, depends on the shader.
                uv2Channel   = new Vector2[vertexCount];
                uv3Channel   = new Vector2[vertexCount];
                uv4Channel   = new Vector2[vertexCount];
                colorChannel = new Color[vertexCount];

                if (material.shader.name.Contains("Directional"))
                {
                    directional = true;
                }

                if (material.shader.name.Contains("Omnidirectional"))
                {
                    omnidirectional = true;
                }

                if (material.shader.name.Contains("Strobe"))
                {
                    strobe = true;
                }

                if (material.shader.name.Contains("PAPI"))
                {
                    papi = true;
                }
            }

            else
            {
                simple = true;

                corner0 = new Vector4(triangleCorners[0].x, triangleCorners[0].y, triangleCorners[0].z, simpleShaderLightSize);
                corner1 = new Vector4(triangleCorners[1].x, triangleCorners[1].y, triangleCorners[1].z, simpleShaderLightSize);
                corner2 = new Vector4(triangleCorners[2].x, triangleCorners[2].y, triangleCorners[2].z, simpleShaderLightSize);
            }

            //Loop through all the lights and set them up.
            for (int i = 0; i < lightsInThisBatch; i++)
            {
                float size  = 0;
                int   e     = i * 3;
                int   e1    = e + 1;
                int   e2    = e + 2;
                int   index = (l * maxTriangles) + i;

                if (lightData != null)
                {
                    size = lightData[index].size;

                    centers[e]  = lightData[index].position;
                    centers[e1] = lightData[index].position;
                    centers[e2] = lightData[index].position;

                    corners[e]  = new Vector4(triangleCorners[0].x, triangleCorners[0].y, triangleCorners[0].z, size);
                    corners[e1] = new Vector4(triangleCorners[1].x, triangleCorners[1].y, triangleCorners[1].z, size);
                    corners[e2] = new Vector4(triangleCorners[2].x, triangleCorners[2].y, triangleCorners[2].z, size);
                }

                else
                {
                    size = simpleShaderLightSize;

                    centers[e]  = positions[index];
                    centers[e1] = positions[index];
                    centers[e2] = positions[index];

                    corners[e]  = corner0;
                    corners[e1] = corner1;
                    corners[e2] = corner2;
                }

                uvs[e]  = triangleUvs[0];
                uvs[e1] = triangleUvs[1];
                uvs[e2] = triangleUvs[2];

                if (lightData != null)
                {
                    if (papi || omnidirectional)
                    {
                        up = Math3d.GetUpVector(lightData[index].rotation);
                    }

                    if (!simple)
                    {
                        normal      = -Math3d.GetForwardVector(lightData[index].rotation);
                        normals[e]  = normal;
                        normals[e1] = normal;
                        normals[e2] = normal;
                    }

                    if (papi)
                    {
                        right          = Math3d.GetRightVector(lightData[index].rotation);
                        uv2Channel[e]  = right;
                        uv2Channel[e1] = right;
                        uv2Channel[e2] = right;

                        uv3Channel[e]  = up;
                        uv3Channel[e1] = up;
                        uv3Channel[e2] = up;

                        //Compose the z vector.
                        Vector2 zVector = new Vector2(right.z, up.z);
                        uv4Channel[e]  = zVector;
                        uv4Channel[e1] = zVector;
                        uv4Channel[e2] = zVector;
                    }

                    if (directional)
                    {
                        //Create the back color.
                        Vector2 RG = new Vector2(lightData[index].backColor.r, lightData[index].backColor.g);
                        Vector2 BA = new Vector2(lightData[index].backColor.b, lightData[index].backColor.a);

                        uv2Channel[e]  = RG;
                        uv2Channel[e1] = RG;
                        uv2Channel[e2] = RG;

                        uv3Channel[e]  = BA;
                        uv3Channel[e1] = BA;
                        uv3Channel[e2] = BA;
                    }

                    if (omnidirectional)
                    {
                        //Create the back color.
                        Vector2 RG = new Vector2(lightData[index].backColor.r, lightData[index].backColor.g);

                        uv2Channel[e]  = RG;
                        uv2Channel[e1] = RG;
                        uv2Channel[e2] = RG;

                        uv3Channel[e]  = up;
                        uv3Channel[e1] = up;
                        uv3Channel[e2] = up;

                        //Compose the z vector. The x component is used for the blue component of the back color.
                        Vector2 zVector = new Vector2(lightData[index].backColor.b, up.z);
                        uv4Channel[e]  = zVector;
                        uv4Channel[e1] = zVector;
                        uv4Channel[e2] = zVector;
                    }

                    if (strobe)
                    {
                        //Store the light and group id in the color channel.
                        Color id = new Color(lightData[index].strobeID, lightData[index].strobeGroupID, 0, 0);

                        colorChannel[e]  = id;
                        colorChannel[e1] = id;
                        colorChannel[e2] = id;
                    }

                    if (directional || omnidirectional)
                    {
                        //Create the front color. Note that the light brightness value is stored in the alpha channel.
                        Color frontColor = new Color(lightData[index].frontColor.r, lightData[index].frontColor.g, lightData[index].frontColor.b, lightData[index].brightness);

                        colorChannel[e]  = frontColor;
                        colorChannel[e1] = frontColor;
                        colorChannel[e2] = frontColor;
                    }
                }

                triangles[e]  = e;
                triangles[e1] = e1;
                triangles[e2] = e2;

                indices[e]  = e;
                indices[e1] = e1;
                indices[e2] = e2;
            }

            //Create a new gameObject.
            GameObject lightObject = new GameObject(name + " " + l);
            lightObjects[l] = lightObject;

            //Add the required components to the game object.
            MeshFilter   meshFilter   = lightObject.AddComponent <MeshFilter>();
            MeshRenderer meshRenderer = lightObject.AddComponent <MeshRenderer>();

            //Create a new mesh.
            meshFilter.sharedMesh = new Mesh();

            //Apply the mesh properties.
            meshFilter.sharedMesh.indexFormat = meshIndexFormat;
            meshFilter.sharedMesh.vertices    = centers;
            meshFilter.sharedMesh.tangents    = corners;          //The mesh corner is stored in the tangent channel. The scale is stored in the w component.
            meshFilter.sharedMesh.uv          = uvs;
            meshFilter.sharedMesh.triangles   = triangles;

            if (!simple)
            {
                meshFilter.sharedMesh.normals = normals;
                meshFilter.sharedMesh.colors  = colorChannel;           //Front color for directional lights. Alpha is the brightness reduction. //ID for strobe lights.
                meshFilter.sharedMesh.uv2     = uv2Channel;             //RG(BA) back color for directional lights. //Rotation vector for omnidirectional lights and PAPIs.
                meshFilter.sharedMesh.uv3     = uv3Channel;             //(RG)BA back color for directional lights. Alpha is for invisibility. //Rotation vector for omnidirectional lights and PAPIS.
                meshFilter.sharedMesh.uv4     = uv4Channel;             //The UV channels only hold two floats, so use a third UV channel to store the Z components of the vectors.
            }

            //Set the indices.
            meshFilter.sharedMesh.SetIndices(indices, MeshTopology.Triangles, 0);

            //Set the gameObject properties;
            meshRenderer.sharedMaterial       = material;
            meshRenderer.shadowCastingMode    = UnityEngine.Rendering.ShadowCastingMode.Off;
            meshRenderer.receiveShadows       = false;
            meshRenderer.lightProbeUsage      = UnityEngine.Rendering.LightProbeUsage.Off;
            meshRenderer.reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off;
        }

        return(lightObjects);
    }