generateQuads() public méthode

public generateQuads ( List verts1, List verts2, bool invertFaces ) : void
verts1 List
verts2 List
invertFaces bool
Résultat void
        public Mesh generateMesh()
        {
            MeshBuilder   builder        = new MeshBuilder();
            Arc           bottomOuterArc = new Arc(bottomRadius, 0, 0, 360, faces);
            Arc           topOuterArc    = new Arc(topRadius, height, 0, 360, faces);
            List <Vertex> verts1         = bottomOuterArc.generateVertices(builder, offset, outsideUV, outsideUV.v1, 1, 0);
            List <Vertex> verts2         = topOuterArc.generateVertices(builder, offset, outsideUV, outsideUV.v2, 1, 0);

            builder.generateQuads(verts1, verts2, false);
            if (bottomInnerRadius != 0 || topInnerRadius != 0)
            {
                Arc   bottomInnerArc = new Arc(bottomInnerRadius, 0, 0, 360, faces);
                Arc   topInnerArc    = new Arc(topInnerRadius, height, 0, 360, faces);
                float heightDiff     = topInnerArc.height - bottomInnerArc.height;
                float radiusDiff     = bottomInnerArc.radius - topInnerArc.radius;
                float sideRadians    = Mathf.Atan2(heightDiff, radiusDiff) - 90 * Mathf.Deg2Rad;
                float yCos           = Mathf.Cos(sideRadians);
                float ySin           = Mathf.Sin(sideRadians);
                verts1 = bottomInnerArc.generateVertices(builder, offset, insideUV, insideUV.v1, -yCos, ySin);
                verts2 = topInnerArc.generateVertices(builder, offset, insideUV, insideUV.v2, -yCos, ySin);
                builder.generateQuads(verts1, verts2, true);
            }
            builder.generateCylinderCap(offset, faces, bottomRadius, bottomInnerRadius, 0, 0, 360, bottomUV, true);
            builder.generateCylinderCap(offset, faces, topRadius, topInnerRadius, height, 0, 360, topUV, false);

            Mesh mesh = builder.buildMesh();

            mesh.name = "ProceduralCylinderMesh";
            return(mesh);
        }
Exemple #2
0
        public Mesh generateMesh()
        {
            MeshBuilder builder = new MeshBuilder();
            Arc bottomOuterArc = new Arc(bottomRadius, 0, 0, 360, faces);
            Arc topOuterArc = new Arc(topRadius, height, 0, 360, faces);
            List<Vertex> verts1 = bottomOuterArc.generateVertices(builder, offset, outsideUV, outsideUV.v1, 1, 0);
            List<Vertex> verts2 = topOuterArc.generateVertices(builder, offset, outsideUV, outsideUV.v2, 1, 0);
            builder.generateQuads(verts1, verts2, false);
            if (bottomInnerRadius != 0 || topInnerRadius != 0)
            {
                Arc bottomInnerArc = new Arc(bottomInnerRadius, 0, 0, 360, faces);
                Arc topInnerArc = new Arc(topInnerRadius, height, 0, 360, faces);
                float heightDiff = topInnerArc.height - bottomInnerArc.height;
                float radiusDiff = bottomInnerArc.radius - topInnerArc.radius;
                float sideRadians = Mathf.Atan2(heightDiff, radiusDiff) - 90 * Mathf.Deg2Rad;
                float yCos = Mathf.Cos(sideRadians);
                float ySin = Mathf.Sin(sideRadians);
                verts1 = bottomInnerArc.generateVertices(builder, offset, insideUV, insideUV.v1, -yCos, ySin);
                verts2 = topInnerArc.generateVertices(builder, offset, insideUV, insideUV.v2, -yCos, ySin);
                builder.generateQuads(verts1, verts2, true);
            }
            builder.generateCylinderCap(offset, faces, bottomRadius, bottomInnerRadius, 0, 0, 360, bottomUV, true);
            builder.generateCylinderCap(offset, faces, topRadius, topInnerRadius, height, 0, 360, topUV, false);

            Mesh mesh = builder.buildMesh();
            mesh.name = "ProceduralCylinderMesh";
            return mesh;
        }
        private void generatePanelSegment(MeshBuilder builder, Vector3 pos, Arc arcA, Arc arcB, UVArea area, bool invertFaces, bool invertNormalY, bool invertNormalXZ)
        {
            float heightDiff  = arcB.height - arcA.height;
            float offset      = arcA.radius - arcB.radius;
            float sideRadians = Mathf.Atan2(heightDiff, offset) - 90 * Mathf.Deg2Rad;
            float yCos        = Mathf.Cos(sideRadians);
            float ySin        = Mathf.Sin(sideRadians);

            if (invertNormalY)
            {
                ySin *= -1;
            }
            if (invertNormalXZ)
            {
                yCos *= -1;
            }
            List <Vertex> verts1 = new List <Vertex>();
            List <Vertex> verts2 = new List <Vertex>();

            verts1.AddRange(arcA.generateVertices(builder, pos, area, area.v1, yCos, ySin));
            verts2.AddRange(arcB.generateVertices(builder, pos, area, area.v2, yCos, ySin));
            builder.generateQuads(verts1, verts2, invertFaces);
        }
        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 generatePanelSegment(MeshBuilder builder, Vector3 pos, Arc arcA, Arc arcB, UVArea area, bool invertFaces, bool invertNormalY, bool invertNormalXZ)
 {
     float heightDiff = arcB.height - arcA.height;
     float offset = arcA.radius - arcB.radius;
     float sideRadians = Mathf.Atan2(heightDiff, offset) - 90 * Mathf.Deg2Rad;
     float yCos = Mathf.Cos(sideRadians);
     float ySin = Mathf.Sin(sideRadians);
     if (invertNormalY) { ySin *= -1; }
     if (invertNormalXZ) { yCos *= -1; }
     List<Vertex> verts1 = new List<Vertex>();
     List<Vertex> verts2 = new List<Vertex>();
     verts1.AddRange(arcA.generateVertices(builder, pos, area, area.v1, yCos, ySin));
     verts2.AddRange(arcB.generateVertices(builder, pos, area, area.v2, yCos, ySin));
     builder.generateQuads(verts1, verts2, invertFaces);
 }
Exemple #6
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);
        }
Exemple #8
0
        //TODO
        private Mesh generatePanelCollider(Vector3 pos, float start, float end, float bottomRad, float topRad, float y1, float y2)
        {
            MeshBuilder builder = new MeshBuilder();
            List<Vertex> verts1 = new List<Vertex>();
            List<Vertex> verts2 = new List<Vertex>();
            Vector3 outerBottomStart;


            throw new NotImplementedException();
            builder.generateQuads(verts1, verts2, false);
            return builder.buildMesh();
        }