Example #1
0
    public static void AddFlatQuad <TVertex>(
        this IMutableDivisibleMesh <TVertex> builder,
        TVertex topLeft,
        TVertex topRight,
        TVertex bottomLeft,
        TVertex bottomRight,
        QuadDiagonal diagonal)
        where TVertex : struct
    {
        Contracts.Requires.That(builder != null);

        using (var group = builder.AddTriangleGroup(new TriangleGroup(triangles: 2, vertices: 4)))
        {
            byte offTL = group.AddVertex(topLeft);
            byte offTR = group.AddVertex(topRight);
            byte offBL = group.AddVertex(bottomLeft);
            byte offBR = group.AddVertex(bottomRight);

            // vertices are added in clockwise winding order
            switch (diagonal)
            {
            case QuadDiagonal.Ascending:
                group.AddTriangleOffsets(offTL, offTR, offBL).AddTriangleOffsets(offBL, offTR, offBR);
                return;

            case QuadDiagonal.Descending:
                group.AddTriangleOffsets(offTL, offBR, offBL).AddTriangleOffsets(offTL, offTR, offBR);
                return;

            default: throw InvalidEnumArgument.CreateException(nameof(diagonal), diagonal);
            }
        }
    }
Example #2
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);
        }
 public static void Contour <TVoxel, TSurfaceData, TVertex>(
     IDualContourable <TVoxel, TSurfaceData> contourable, IMutableDivisibleMesh <TVertex> meshBuilder)
     where TVoxel : struct
     where TSurfaceData : class
     where TVertex : struct
 {
     Contracts.Requires.That(contourable != null);
     Contracts.Requires.That(meshBuilder != null);
 }
Example #5
0
    // always specify the vertices in clockwise order!
    public static void AddTriangle <TVertex>(
        this IMutableDivisibleMesh <TVertex> builder, TVertex a, TVertex b, TVertex c)
        where TVertex : struct
    {
        Contracts.Requires.That(builder != null);

        using (var group = builder.AddTriangleGroup(new TriangleGroup(triangles: 1, vertices: 3)))
        {
            byte offA = group.AddVertex(a);
            byte offB = group.AddVertex(b);
            byte offC = group.AddVertex(c);
            group.AddTriangleOffsets(offA, offB, offC);
        }
    }