Ejemplo n.º 1
0
        /// <inheritdoc />
        public void Contour(
            IDualContourable <TVoxel, TSurfaceData> contourable,
            IMutableDivisibleMesh <NormalColorTextureVertex> meshBuilder)
        {
            IDualContourerContracts.Contour(contourable, meshBuilder);

            foreach (var projection in contourable.GetContourableProjections(this.contourDeterminer))
            {
                Vector3 topLeftVertex, topRightVertex, botLeftVertex, botRightVertex;
                this.positioner.GenerateValues(
                    projection,
                    out topLeftVertex,
                    out topRightVertex,
                    out botLeftVertex,
                    out botRightVertex);

                Vector3      normal;
                QuadDiagonal diagonal;

                if (projection.AbsoluteIndexOfOrigin.SumCoordinatesLong().IsEven())
                {
                    diagonal = QuadDiagonal.Ascending;
                    normal   = PolyMath.GetNormalizedAverage(
                        PolyMath.GetSurfaceNormal(topLeftVertex, botLeftVertex, topRightVertex),
                        PolyMath.GetSurfaceNormal(botLeftVertex, botRightVertex, topRightVertex));
                }
                else
                {
                    diagonal = QuadDiagonal.Descending;
                    normal   = PolyMath.GetNormalizedAverage(
                        PolyMath.GetSurfaceNormal(topLeftVertex, botLeftVertex, botRightVertex),
                        PolyMath.GetSurfaceNormal(topLeftVertex, botRightVertex, topRightVertex));
                }

                projection.SurfaceData.Diagonal = diagonal;

                Color topLeftColor, topRightColor, botLeftColor, botRightColor;
                this.colorer.GenerateValues(
                    projection,
                    out topLeftColor,
                    out topRightColor,
                    out botLeftColor,
                    out botRightColor);

                Vector2 topLeftTexture, topRightTexture, botLeftTexture, botRightTexture;
                this.texturer.GenerateValues(
                    projection,
                    out topLeftTexture,
                    out topRightTexture,
                    out botLeftTexture,
                    out botRightTexture);

                meshBuilder.AddFlatQuad(
                    topLeft: new NormalColorTextureVertex(topLeftVertex, normal, topLeftColor, topLeftTexture),
                    topRight: new NormalColorTextureVertex(topRightVertex, normal, topRightColor, topRightTexture),
                    bottomLeft: new NormalColorTextureVertex(botLeftVertex, normal, botLeftColor, botLeftTexture),
                    bottomRight: new NormalColorTextureVertex(botRightVertex, normal, botRightColor, botRightTexture),
                    diagonal: diagonal);
            }
        }
        /// <inheritdoc />
        public void Contour(
            IDualContourable <TerrainVoxel, TSurfaceData> contourable,
            IMutableDivisibleMesh <NormalColorTextureVertex> meshBuilder)
        {
            IDualContourerContracts.Contour(contourable, meshBuilder);

            this.dualContourer.Contour(contourable, meshBuilder);
        }