Esempio n. 1
0
    bool PolysMesh(ref int numVertsCreated)
    {
        float scale;

        Vector3[] normals = new Vector3[2];
        Color32   color   = new Color32(255, 255, 255, 255);

        /*
         * Vector3 farSideNormal = new Vector3();
         * Vector3 topNormal = new Vector3();
         * Vector3 farTopNormal, sideNormal, partialTopNormal, farPartialSideNormal;*/

        int i;

        //Debug.Log("Building Poly");
        for (i = 0; i < data.wallA.Count; i++)
        {
            scale = materials.GetWallScale(data.wallMaterial[i]);
            int firstVert = numVertsCreated;
            normals[0] = Vector3.Cross
                         (
                ((Vector3)data.points[data.wallB[i]] - data.points[data.wallA[i]]).normalized,
                ((Vector3)data.points[data.wallC[i]] - data.points[data.wallA[i]]).normalized
                         ).normalized *scale;
            normals[1] = Vector3.Cross
                         (
                ((Vector3)data.points[data.wallC[i]] - data.points[data.wallA[i]]).normalized,
                ((Vector3)data.points[data.wallB[i]] - data.points[data.wallA[i]]).normalized
                         ).normalized *scale;

            if (data.wallD[i] != -1)
            {
                //FACES
                verts[numVertsCreated++] = normals[0] + data.points[data.wallA[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallB[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallC[i]];

                verts[numVertsCreated++] = normals[1] + data.points[data.wallA[i]];
                verts[numVertsCreated++] = normals[1] + data.points[data.wallC[i]];
                verts[numVertsCreated++] = normals[1] + data.points[data.wallB[i]];

                verts[numVertsCreated++] = normals[0] + data.points[data.wallD[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallC[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallB[i]];

                verts[numVertsCreated++] = normals[1] + data.points[data.wallD[i]];
                verts[numVertsCreated++] = normals[1] + data.points[data.wallB[i]];
                verts[numVertsCreated++] = normals[1] + data.points[data.wallC[i]];

                //EDGES
                //ONE
                verts[numVertsCreated++] = normals[1] + data.points[data.wallA[i]];
                verts[numVertsCreated++] = normals[1] + data.points[data.wallB[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallA[i]];

                verts[numVertsCreated++] = normals[1] + data.points[data.wallB[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallB[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallA[i]];

                //TWO
                verts[numVertsCreated++] = normals[1] + data.points[data.wallB[i]];
                verts[numVertsCreated++] = normals[1] + data.points[data.wallD[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallB[i]];

                verts[numVertsCreated++] = normals[1] + data.points[data.wallD[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallD[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallB[i]];

                //THREE
                verts[numVertsCreated++] = normals[1] + data.points[data.wallC[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallC[i]];
                verts[numVertsCreated++] = normals[1] + data.points[data.wallD[i]];

                verts[numVertsCreated++] = normals[1] + data.points[data.wallD[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallC[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallD[i]];

                //FOUR
                verts[numVertsCreated++] = normals[1] + data.points[data.wallC[i]];
                verts[numVertsCreated++] = normals[1] + data.points[data.wallA[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallC[i]];

                verts[numVertsCreated++] = normals[1] + data.points[data.wallA[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallA[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallC[i]];
            }
            else
            {
                //FACES
                verts[numVertsCreated++] = normals[0] + data.points[data.wallA[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallB[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallC[i]];

                verts[numVertsCreated++] = normals[1] + data.points[data.wallA[i]];
                verts[numVertsCreated++] = normals[1] + data.points[data.wallC[i]];
                verts[numVertsCreated++] = normals[1] + data.points[data.wallB[i]];

                //EDGES
                //ONE
                verts[numVertsCreated++] = normals[1] + data.points[data.wallA[i]];
                verts[numVertsCreated++] = normals[1] + data.points[data.wallB[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallA[i]];

                verts[numVertsCreated++] = normals[1] + data.points[data.wallB[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallB[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallA[i]];

                //TWO
                verts[numVertsCreated++] = normals[1] + data.points[data.wallB[i]];
                verts[numVertsCreated++] = normals[1] + data.points[data.wallC[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallB[i]];

                verts[numVertsCreated++] = normals[1] + data.points[data.wallC[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallC[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallB[i]];

                //THREE
                verts[numVertsCreated++] = normals[1] + data.points[data.wallC[i]];
                verts[numVertsCreated++] = normals[1] + data.points[data.wallA[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallC[i]];

                verts[numVertsCreated++] = normals[1] + data.points[data.wallA[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallA[i]];
                verts[numVertsCreated++] = normals[0] + data.points[data.wallC[i]];

                numVertsCreated += 12;
            }
            Color32 thisColor = materials.GetColor(data.wallMaterial[i]);
            for (int iColor = firstVert; iColor < numVertsCreated; iColor++)
            {
                vertColors[iColor] = thisColor;
            }
        }
        return(true);
    }