addVertex() public method

public addVertex ( Vector3 vert, Vector3 norm, Vector2 uv ) : Vertex
vert Vector3
norm Vector3
uv Vector2
return Vertex
Beispiel #1
0
        private Mesh generatePanelCollider(Vector3 center, float startAngle, float endAngle, float height, float bottomRadius, float topRadius, float thickness)
        {
            MeshBuilder builder = new MeshBuilder();

            float bottomInnerRadius = bottomRadius - thickness;
            float topInnerRadius = topRadius - thickness;
            float startRads = Mathf.Deg2Rad * startAngle;
            float endRads = Mathf.Deg2Rad * endAngle;
            float startXSin = -Mathf.Sin(startRads);
            float startZCos = Mathf.Cos(startRads);
            float endXSin = -Mathf.Sin(endRads);
            float endZCos = Mathf.Cos(endRads);

            Vector3 frontBottomLeft = new Vector3(center.x + bottomRadius * startXSin, center.y, center.z + bottomRadius * startZCos);
            Vector3 frontBottomRight = new Vector3(center.x + bottomRadius * endXSin, center.y, center.z + bottomRadius * endZCos);
            Vector3 frontTopLeft = new Vector3(center.x + topRadius * startXSin, center.y + height, center.z + topRadius * startZCos);
            Vector3 frontTopRight = new Vector3(center.x + topRadius * endXSin, center.y + height, center.z + topRadius * endZCos);

            Vector3 rearBottomLeft = new Vector3(center.x + bottomInnerRadius * startXSin, center.y, center.z + bottomInnerRadius * startZCos);
            Vector3 rearBottomRight = new Vector3(center.x + bottomInnerRadius * endXSin, center.y, center.z + bottomInnerRadius * endZCos);
            Vector3 rearTopLeft = new Vector3(center.x + topInnerRadius * startXSin, center.y + height, center.z + topInnerRadius * startZCos);
            Vector3 rearTopRight = new Vector3(center.x + topInnerRadius * endXSin, center.y + height, center.z + topInnerRadius * endZCos);

            Vector3 normFront = Vector3.forward;
            Vector3 normRear = Vector3.back;
            Vector3 normLeft = Vector3.left;
            Vector3 normRight = Vector3.right;
            Vector3 normUp = Vector3.up;
            Vector3 normDown = Vector3.down;

            Vector2 uv1 = new Vector2(0, 0);
            Vector2 uv2 = new Vector2(1, 0);
            Vector2 uv3 = new Vector2(0, 1);
            Vector2 uv4 = new Vector2(1, 1);

            List<Vertex> v1 = new List<Vertex>();
            List<Vertex> v2 = new List<Vertex>();

            //generate front face
            v1.Add(builder.addVertex(frontBottomLeft, normFront, uv1));
            v1.Add(builder.addVertex(frontBottomRight, normFront, uv2));
            v2.Add(builder.addVertex(frontTopLeft, normFront, uv3));
            v2.Add(builder.addVertex(frontTopRight, normFront, uv4));
            builder.generateQuads(v1, v2, false);
            v1.Clear();
            v2.Clear();

            //generate rear face
            v1.Add(builder.addVertex(rearBottomLeft, normRear, uv2));
            v1.Add(builder.addVertex(rearBottomRight, normRear, uv1));
            v2.Add(builder.addVertex(rearTopLeft, normRear, uv4));
            v2.Add(builder.addVertex(rearTopRight, normRear, uv3));
            builder.generateQuads(v1, v2, true);
            v1.Clear();
            v2.Clear();

            //generate left face
            v1.Add(builder.addVertex(frontBottomLeft, normLeft, uv2));
            v1.Add(builder.addVertex(rearBottomLeft, normLeft, uv1));
            v2.Add(builder.addVertex(frontTopLeft, normLeft, uv4));
            v2.Add(builder.addVertex(rearTopLeft, normLeft, uv3));
            builder.generateQuads(v1, v2, true);
            v1.Clear();
            v2.Clear();

            //generate right face
            v1.Add(builder.addVertex(frontBottomRight, normRight, uv1));
            v1.Add(builder.addVertex(rearBottomRight, normRight, uv2));
            v2.Add(builder.addVertex(frontTopRight, normRight, uv3));
            v2.Add(builder.addVertex(rearTopRight, normRight, uv4));
            builder.generateQuads(v1, v2, false);
            v1.Clear();
            v2.Clear();

            //generate top face
            v1.Add(builder.addVertex(frontTopRight, normUp, uv2));
            v1.Add(builder.addVertex(frontTopLeft, normUp, uv1));
            v2.Add(builder.addVertex(rearTopRight, normUp, uv4));
            v2.Add(builder.addVertex(rearTopLeft, normUp, uv3));
            builder.generateQuads(v1, v2, true);
            v1.Clear();
            v2.Clear();

            //generate bottom face
            v1.Add(builder.addVertex(frontBottomRight, normUp, uv1));
            v1.Add(builder.addVertex(frontBottomLeft, normUp, uv2));
            v2.Add(builder.addVertex(rearBottomRight, normUp, uv3));
            v2.Add(builder.addVertex(rearBottomLeft, normUp, uv4));
            builder.generateQuads(v1, v2, false);
            v1.Clear();
            v2.Clear();

            return builder.buildMesh();
        }
        private void generateSidewalls(MeshBuilder builder, UVArea caps)
        {
            int len = outerArcs.Count;
            float[] distances = new float[len];
            float[] us = new float[len];
            float totalLength = 0;
            float length;
            Vector3 a, b;
            for (int i = 0; i < len - 1; i++)
            {
                a = outerArcs[i].startVector;
                b = outerArcs[i + 1].startVector;
                length = Vector3.Distance(a, b);
                totalLength += length;
                distances[i + 1] = length;
            }

            length = 0;
            float percent;
            float uDelta = caps.u2 - caps.u1;
            for (int i = 0; i < len; i++)
            {
                length += distances[i];
                percent = length / totalLength;
                us[i] = caps.u1 + percent * uDelta;
            }

            Vector3 leftNorm = new Vector3();
            leftNorm.x = outerArcs[0].startVector.z;
            leftNorm.z = -outerArcs[0].startVector.x;
            leftNorm.Normalize();
            Vector3 rightNorm = new Vector3();
            rightNorm.x = outerArcs[0].endVector.z;
            rightNorm.z = -outerArcs[0].endVector.x;
            rightNorm.Normalize();
            rightNorm = -rightNorm;//as faces get inverted for this side, so norms get inverted as well

            //left
            List<Vertex> outerStartVerts = new List<Vertex>();
            List<Vertex> innerStartVerts = new List<Vertex>();

            //right
            List<Vertex> outerEndVerts = new List<Vertex>();
            List<Vertex> innerEndVerts = new List<Vertex>();

            len = outerArcs.Count;
            Vector3 outer, inner;
            Vector2 uv;
            for (int i = 0; i < len; i++)
            {
                outer = outerArcs[i].startVector;
                uv = new Vector2(us[i], caps.v1);
                outerStartVerts.Add(builder.addVertex(outer, leftNorm, uv));
                inner = innerArcs[i].startVector;
                uv = new Vector2(us[i], caps.v2);
                innerStartVerts.Add(builder.addVertex(inner, leftNorm, uv));

                outer = outerArcs[i].endVector;
                uv = new Vector2(us[i], caps.v1);
                outerEndVerts.Add(builder.addVertex(outer, rightNorm, uv));
                inner = innerArcs[i].endVector;
                uv = new Vector2(us[i], caps.v2);
                innerEndVerts.Add(builder.addVertex(inner, rightNorm, uv));
            }
            builder.generateQuads(outerStartVerts, innerStartVerts, false);
            builder.generateQuads(outerEndVerts, innerEndVerts, true);
        }
        private void generateSidewalls(MeshBuilder builder, UVArea caps)
        {
            int len = outerArcs.Count;

            float[] distances   = new float[len];
            float[] us          = new float[len];
            float   totalLength = 0;
            float   length;
            Vector3 a, b;

            for (int i = 0; i < len - 1; i++)
            {
                a                = outerArcs[i].startVector;
                b                = outerArcs[i + 1].startVector;
                length           = Vector3.Distance(a, b);
                totalLength     += length;
                distances[i + 1] = length;
            }

            length = 0;
            float percent;
            float uDelta = caps.u2 - caps.u1;

            for (int i = 0; i < len; i++)
            {
                length += distances[i];
                percent = length / totalLength;
                us[i]   = caps.u1 + percent * uDelta;
            }

            Vector3 leftNorm = new Vector3();

            leftNorm.x = outerArcs[0].startVector.z;
            leftNorm.z = -outerArcs[0].startVector.x;
            leftNorm.Normalize();
            Vector3 rightNorm = new Vector3();

            rightNorm.x = outerArcs[0].endVector.z;
            rightNorm.z = -outerArcs[0].endVector.x;
            rightNorm.Normalize();
            rightNorm = -rightNorm;//as faces get inverted for this side, so norms get inverted as well

            //left
            List <Vertex> outerStartVerts = new List <Vertex>();
            List <Vertex> innerStartVerts = new List <Vertex>();

            //right
            List <Vertex> outerEndVerts = new List <Vertex>();
            List <Vertex> innerEndVerts = new List <Vertex>();

            len = outerArcs.Count;
            Vector3 outer, inner;
            Vector2 uv;

            for (int i = 0; i < len; i++)
            {
                outer = outerArcs[i].startVector;
                uv    = new Vector2(us[i], caps.v1);
                outerStartVerts.Add(builder.addVertex(outer, leftNorm, uv));
                inner = innerArcs[i].startVector;
                uv    = new Vector2(us[i], caps.v2);
                innerStartVerts.Add(builder.addVertex(inner, leftNorm, uv));

                outer = outerArcs[i].endVector;
                uv    = new Vector2(us[i], caps.v1);
                outerEndVerts.Add(builder.addVertex(outer, rightNorm, uv));
                inner = innerArcs[i].endVector;
                uv    = new Vector2(us[i], caps.v2);
                innerEndVerts.Add(builder.addVertex(inner, rightNorm, uv));
            }
            builder.generateQuads(outerStartVerts, innerStartVerts, false);
            builder.generateQuads(outerEndVerts, innerEndVerts, true);
        }