Vector3[] GetVertices()
        {
            int numWallVertices = totalVertsPerCorner * outlines.Sum(outline => outline.Length);
            var vertices        = new Vector3[numWallVertices];

            int vertexIndex = 0;

            foreach (Vector3[] outline in outlines)
            {
                for (int i = 0; i < outline.Length; i++)
                {
                    Vector3 vertex             = outline[i];
                    Vector3 normal             = ComputeNormal(outline, i);
                    float   x                  = vertex.x;
                    float   z                  = vertex.z;
                    float   floorHeight        = floorHeightMap.GetHeight(x, z);
                    float   ceilingHeight      = ceilingHeightMap.GetHeight(x, z);
                    float   interpolationScale = 1 / (totalVertsPerCorner - 1f);

                    Vector3 ceilingVertex = new Vector3(x, ceilingHeight, z);
                    if (wallModule.AdjustCeilingCorners)
                    {
                        ceilingVertex = wallModule.GetAdjustedCorner(ceilingVertex, normal, floorHeight, ceilingHeight);
                        if (wallModule.AutoCorrectCornerHeights)
                        {
                            ceilingVertex.y = ceilingHeightMap.GetHeight(ceilingVertex.x, ceilingVertex.z);
                        }
                    }
                    vertices[vertexIndex++] = ceilingVertex;

                    for (int j = 0; j < extraVertsPerCorner; j++)
                    {
                        float interpolation = (j + 1) * interpolationScale;
                        vertex.y = Mathf.Lerp(ceilingHeight, floorHeight, interpolation);
                        vertex.y = interpolation * floorHeight + (1 - interpolation) * ceilingHeight;
                        vertices[vertexIndex++] = wallModule.GetAdjustedCorner(vertex, normal, floorHeight, ceilingHeight);
                    }

                    Vector3 floorVertex = new Vector3(x, floorHeight, z);
                    if (wallModule.AdjustFloorCorners)
                    {
                        floorVertex = wallModule.GetAdjustedCorner(floorVertex, normal, floorHeight, ceilingHeight);
                        if (wallModule.AutoCorrectCornerHeights)
                        {
                            floorVertex.y = floorHeightMap.GetHeight(floorVertex.x, floorVertex.z);
                        }
                    }
                    vertices[vertexIndex++] = floorVertex;
                }
            }
            return(vertices);
        }
Beispiel #2
0
        Vector3[] GetVertices()
        {
            int numWallVertices = totalVertsPerCorner * outlines.Sum(outline => outline.Length);
            var vertices        = new Vector3[numWallVertices];
            var context         = new VertexContext(floorHeightMap, ceilingHeightMap, totalVertsPerCorner);

            int vertexIndex = 0;

            foreach (Vector3[] outline in outlines)
            {
                for (int i = 0; i < outline.Length; i++)
                {
                    Vector3 vertex             = outline[i];
                    Vector3 normal             = ComputeNormal(outline, i);
                    float   x                  = vertex.x;
                    float   z                  = vertex.z;
                    float   floorHeight        = floorHeightMap.GetHeight(x, z);
                    float   ceilingHeight      = ceilingHeightMap.GetHeight(x, z);
                    float   interpolationScale = 1 / (totalVertsPerCorner - 1f);

                    for (int j = 0; j < totalVertsPerCorner; j++)
                    {
                        float interpolation = j * interpolationScale;
                        vertex.y = Mathf.Lerp(ceilingHeight, floorHeight, interpolation);
                        vertex.y = interpolation * floorHeight + (1 - interpolation) * ceilingHeight;
                        context.Update(vertex, normal, j);
                        vertices[vertexIndex++] = wallModule.GetAdjustedCorner(context);
                    }
                }
            }
            return(vertices);
        }