public void Run()
    {
        int controlVertexCount = 6;

        Quad[] controlFaces = new [] {
            new Quad(0, 1, 2, 3),
            new Quad(1, 4, 5, 2)
        };
        QuadTopology controlTopology = new QuadTopology(controlVertexCount, controlFaces);

        int refinementLevel = 1;

        using (Refinement refinement = new Refinement(controlTopology, refinementLevel)) {
            QuadTopology topology = refinement.GetTopology();
            int[]        faceMap  = refinement.GetFaceMap();

            for (int faceIdx = 0; faceIdx < topology.Faces.Length; ++faceIdx)
            {
                Console.WriteLine(topology.Faces[faceIdx] + " -> " + faceMap[faceIdx]);
            }
            Console.WriteLine();

            PackedLists <int> adjacentVertices = refinement.GetAdjacentVertices();
            VertexRule[]      vertexRules      = refinement.GetVertexRules();
            Console.WriteLine("adjacent vertices and rules: ");
            for (int vertexIdx = 0; vertexIdx < topology.VertexCount; ++vertexIdx)
            {
                VertexRule vertexRule = vertexRules[vertexIdx];

                Console.WriteLine("\t" + vertexIdx + $": [{vertexRule}] " + String.Join(", ", adjacentVertices.GetElements(vertexIdx)));
            }
            Console.WriteLine();

            PackedLists <WeightedIndex> stencils = refinement.GetStencils(StencilKind.LimitStencils);
            Console.WriteLine("stencils: ");
            for (int vertexIdx = 0; vertexIdx < stencils.Count; ++vertexIdx)
            {
                Console.WriteLine(vertexIdx + ":");
                foreach (WeightedIndex weightedIndex in stencils.GetElements(vertexIdx))
                {
                    Console.WriteLine("\t" + weightedIndex.Index + " -> " + weightedIndex.Weight);
                }
            }
        }
    }
Example #2
0
    private static Tuple <Vector2, Vector2> RemapTangents(
        List <int> spatialNeighbours, VertexRule spatialVertexRule,
        List <int> neighbours, VertexRule vertexRule,
        Vector2 ds, Vector2 dt)
    {
        int spatialValence = spatialNeighbours.Count;
        int valence        = neighbours.Count;

        if (spatialVertexRule == vertexRule && spatialNeighbours.SequenceEqual(neighbours))
        {
            //no remapping required
            return(Tuple.Create(ds, dt));
        }

        if (neighbours.Count == 0)
        {
            //disconnected vertex, so no tangents
            return(Tuple.Create(Vector2.Zero, Vector2.Zero));
        }


        /*
         * if (vertexRule != VertexRule.Crease) {
         *      throw new InvalidOperationException("only texture creases should need remapping");
         * }
         *
         * if (spatialValence <= 2) {
         *      throw new InvalidOperationException("spatial corners should never remapping");
         * }
         */

        if (spatialValence == 4 && spatialVertexRule == VertexRule.Smooth && valence == 3)
        {
            int leadingNeighbourSpatialIdx = spatialNeighbours.IndexOf(neighbours[0]);

            if (leadingNeighbourSpatialIdx == 0)
            {
                return(Tuple.Create(ds, dt));
            }
            else if (leadingNeighbourSpatialIdx == 1)
            {
                return(Tuple.Create(-dt, ds));
            }
            else if (leadingNeighbourSpatialIdx == 2)
            {
                return(Tuple.Create(-ds, -dt));
            }
            else if (leadingNeighbourSpatialIdx == 3)
            {
                return(Tuple.Create(dt, -ds));
            }
            else
            {
                throw new InvalidOperationException("impossible");
            }
        }
        else
        {
            return(Tuple.Create(Vector2.Zero, Vector2.Zero));
        }
    }