Exemplo n.º 1
0
        public Mesh generateMesh()
        {
            ROTMeshBuilder builder        = new ROTMeshBuilder();
            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);
        }
Exemplo n.º 2
0
        private void generatePanelSegment(ROTMeshBuilder 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);
        }
Exemplo n.º 3
0
        private void generateSidewalls(ROTMeshBuilder 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);
        }