示例#1
0
        private void BuildOffsetShape(TerrainMeshData meshData, MeshRegion region, GradientWrapper gradient,
                                      Rectangle2d rect, float colorNoiseFreq, float deepLevel)
        {
            foreach (var contour in region.Contours)
            {
                var length = contour.Count;
                for (int i = 0; i < length; i++)
                {
                    var v2DIndex = i == (length - 1) ? 0 : i + 1;
                    var p1       = new Vector2d((float)contour[i].X, (float)contour[i].Y);
                    var p2       = new Vector2d((float)contour[v2DIndex].X, (float)contour[v2DIndex].Y);

                    // check whether two points are on cell rect
                    if (rect.IsOnBorder(p1) && rect.IsOnBorder(p2))
                    {
                        continue;
                    }

                    var ele1 = _elevationProvider.GetElevation(p1);
                    var ele2 = _elevationProvider.GetElevation(p2);

                    var firstColor = GradientUtils.GetColor(gradient,
                                                            new Vector3((float)p1.X, ele1, (float)p1.Y), colorNoiseFreq);

                    var secondColor = GradientUtils.GetColor(gradient,
                                                             new Vector3((float)p2.X, ele1 - deepLevel, (float)p2.Y), colorNoiseFreq);

                    meshData.AddTriangle(
                        new Vector3((float)p1.X, ele1, (float)p1.Y),
                        new Vector3((float)p2.X, ele2 - deepLevel, (float)p2.Y),
                        new Vector3((float)p2.X, ele2, (float)p2.Y),
                        firstColor);

                    meshData.AddTriangle(
                        new Vector3((float)p1.X, ele1 - deepLevel, (float)p1.Y),
                        new Vector3((float)p2.X, ele2 - deepLevel, (float)p2.Y),
                        new Vector3((float)p1.X, ele1, (float)p1.Y),
                        secondColor);
                }
            }
        }
示例#2
0
        private void AddTriangle(Rule rule, TerrainMeshData meshData, Triangle triangle, GradientWrapper gradient,
                                 float eleNoiseFreq, float colorNoiseFreq, float yOffset = 0)
        {
            var useEleNoise = Math.Abs(eleNoiseFreq) > 0.0001;

            var v0 = GetVertex(triangle.GetVertex(0), eleNoiseFreq, useEleNoise, yOffset);
            var v1 = GetVertex(triangle.GetVertex(1), eleNoiseFreq, useEleNoise, yOffset);
            var v2 = GetVertex(triangle.GetVertex(2), eleNoiseFreq, useEleNoise, yOffset);

            var triangleColor = GradientUtils.GetColor(gradient, v0, colorNoiseFreq);

            meshData.AddTriangle(v0, v1, v2, triangleColor);
        }