示例#1
0
    public void MakePlane()
    {
        PairFloat floor   = floorValues[0];
        int       rows    = floor.divisions;
        int       columns = baseNumber;

        List <Vector3> vertices = new List <Vector3>();
        float          radius   = floor.radius;

        for (int i = 0; i <= rows; i++)
        {
            for (int j = 0; j <= columns; j++)
            {
                vertices.Add(new Vector3(j * radius / columns, 0f, i * radius / rows));
            }
        }
        List <int> tris = MakeTrianglesWithNextAndUp(rows, columns);

        ApplyToMesh(vertices, tris);
    }
示例#2
0
 public PairFloat CopyFrom(PairFloat target)
 {
     return(new PairFloat(target.pivot, target.sharpEdge, target.radius,
                          target.position, target.rotation,
                          target.freezeAxisX, target.freezeAxisY, target.freezeAxisZ));
 }
示例#3
0
    public void MakePrism()
    {
        if (baseNumber < 3)
        {
            baseNumber = 3;
        }
        List <Vector3> vertices = new List <Vector3>();
        //duplicate sharp floors
        List <PairFloat> floors = new List <PairFloat>();

        foreach (PairFloat floor in floorValues)
        {
            floors.Add(floor);

            if (floor.divisions > 0)
            {
                for (int i = 0; i < floor.divisions; i++)
                {
                }
            }

            if (floor.sharpEdge)
            {
                PairFloat cpy = floor.CopyThis();
                //disable so we can track only original floor with sharpEdge ==true and skip it
                cpy.sharpEdge = false;
                floors.Add(cpy);
            }
        }

        foreach (PairFloat floor in floors)
        {
            float radius = floor.radius;
            if (useIncircle)
            {
                float a = 180f / baseNumber;
                radius = radius * Mathf.Sin(Mathf.PI / baseNumber) / (Mathf.Tan(a * Mathf.Deg2Rad));
            }
            List <Vector3> baseVerts = BaseVertices(baseNumber, radius, floor.position);
            if (floor.rotation != Vector3.zero)
            {
                for (int i = 0; i < baseVerts.Count; i++)
                {
                    baseVerts[i] -= floor.GetPivot(baseNumber);

                    Quaternion rotation    = Quaternion.Euler(floor.rotation);
                    Vector3    newRotation = rotation * baseVerts[i];

                    float x = baseVerts[i].x;
                    float y = baseVerts[i].y;
                    float z = baseVerts[i].z;
                    if (floor.freezeAxisX == false)
                    {
                        x = newRotation.x;
                    }
                    if (floor.freezeAxisY == false)
                    {
                        y = newRotation.y;
                    }
                    if (floor.freezeAxisZ == false)
                    {
                        z = newRotation.z;
                    }

                    baseVerts[i] = new Vector3(x, y, z);

                    baseVerts[i] += floor.GetPivot(baseNumber);
                }
            }
            vertices.AddRange(baseVerts);
        }

        List <int> tris = MakeTrianglesWithNextAndUpClosed(vertices, floors);

        ApplyToMesh(vertices, tris);
    }
示例#4
0
    public void MakeDome()
    {
        PairFloat floor = floorValues[0];

        if (floor.divisions < 2)
        {
            floor.divisions = 2;
        }
        int rows = floor.divisions;

        if (baseNumber < 3)
        {
            baseNumber = 3;
        }
        int            columns    = baseNumber;
        List <Vector3> verts      = new List <Vector3>();
        float          radius     = floor.radius;
        float          circlePart = 360f - piOffset / 2f * 360f;

        if (mirrorDome)
        {
            //rows -1 we skip the last since it is the first for upper part of dome
            for (int i = 0; i < rows - 1; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    if (j / (columns - 1f) >= circlePart)
                    {
                        break;
                    }

                    int ii = rows - 1 - i;

                    float radians = j * 360f / columns * Mathf.Deg2Rad;
                    float offset  = Mathf.PI * piOffset;

                    float currentRadius = radius * Mathf.Cos(Mathf.PI / 2f * (ii / (rows - 1f)));
                    float x             = Mathf.Cos(radians + offset) * currentRadius;
                    float z             = Mathf.Sin(radians + offset) * currentRadius;

                    float   y    = -floor.position.y * Mathf.Sin(Mathf.PI / 2f * ii / (rows - 1f));
                    Vector3 vert = new Vector3(x, y, z);
                    //Color col = new Color(ii/(rows-1f), 0f, j/(columns-1f));
                    //Debug.DrawRay(vert, Vector3.forward*0.01f, col);
                    verts.Add(vert);
                }
            }
        }
        for (int i = 0; i < rows; i++)
        {
            for (int j = 0; j < columns; j++)
            {
                int   ii      = i;
                float radians = j * 360f / columns * Mathf.Deg2Rad;
                float offset  = Mathf.PI * piOffset;

                float currentRadius = radius * Mathf.Cos(Mathf.PI / 2f * (ii / (rows - 1f)));
                float x             = Mathf.Cos(radians + offset) * currentRadius;
                float z             = Mathf.Sin(radians + offset) * currentRadius;

                float   y    = floor.position.y * Mathf.Sin(Mathf.PI / 2f * ii / (rows - 1f));
                Vector3 vert = new Vector3(x, y, z);
                //Color col = new Color(ii/(rows-1f), 0f, j/(columns-1f));
                //Debug.DrawRay(vert, Vector3.forward*0.01f, col);
                verts.Add(vert);
            }
        }
        if (mirrorDome)
        {
            rows = 2 * rows - 1;
        }
        //rows -1 since last will get connected to first
        List <int> tris = MakeTrianglesWithNextAndUp(rows - 1, columns - 1, true, true);

        ApplyToMesh(verts, tris);
    }