Example #1
0
    public void Dump(string name, UvSet uvSet)
    {
        DirectoryInfo uvSetDirectory = uvSetsDirectory.Subdirectory(name);

        if (uvSetDirectory.Exists)
        {
            return;
        }

        Console.WriteLine($"Dumping uv-set {name}...");

        MultisurfaceQuadTopology spatialTopology         = figure.Geometry.AsTopology();
        MultisurfaceQuadTopology texturedControlTopology = ExtractTexturedTopology(spatialTopology, uvSet);
        var texturedRefinementResult = texturedControlTopology.Refine(surfaceProperties.SubdivisionLevel);
        var texturedTopology         = texturedRefinementResult.Mesh.Topology;
        var texturedTopologyInfo     = texturedRefinementResult.TopologyInfo;
        var derivStencils            = texturedRefinementResult.Mesh.Stencils;

        var stencils   = derivStencils.Map(stencil => new WeightedIndex(stencil.Index, stencil.Weight));
        var duStencils = derivStencils.Map(stencil => new WeightedIndex(stencil.Index, stencil.DuWeight));
        var dvStencils = derivStencils.Map(stencil => new WeightedIndex(stencil.Index, stencil.DvWeight));

        Vector2[] controlTextureCoords = uvSet.Uvs;
        Vector2[] textureCoords        = new Subdivider(stencils).Refine(controlTextureCoords, new Vector2Operators());
        Vector2[] textureCoordDus      = new Subdivider(duStencils).Refine(controlTextureCoords, new Vector2Operators());
        Vector2[] textureCoordDvs      = new Subdivider(dvStencils).Refine(controlTextureCoords, new Vector2Operators());

        int[] spatialIdxMap = CalculateTextureToSpatialIndexMap(texturedTopology, spatialFaces);

        TexturedVertexInfo[] texturedVertexInfos = Enumerable.Range(0, textureCoords.Length)
                                                   .Select(idx => {
            int spatialVertexIdx = spatialIdxMap[idx];
            Vector2 textureCoord = textureCoords[idx];
            Vector2 du           = textureCoordDus[idx];
            Vector2 dv           = textureCoordDvs[idx];

            List <int> spatialNeighbours = spatialTopologyInfo.AdjacentVertices.GetElements(spatialVertexIdx).ToList();
            var spatialVertexRule        = spatialTopologyInfo.VertexRules[spatialVertexIdx];

            List <int> neighbours = texturedTopologyInfo.AdjacentVertices.GetElements(idx).Select(i => spatialIdxMap[i]).ToList();
            var vertexRule        = texturedTopologyInfo.VertexRules[idx];

            Tuple <Vector2, Vector2> remappedTangents = RemapTangents(spatialNeighbours, spatialVertexRule, neighbours, vertexRule, du, dv);

            return(new TexturedVertexInfo(
                       spatialVertexIdx,
                       textureCoord,
                       remappedTangents.Item1,
                       remappedTangents.Item2));
        })
                                                   .ToArray();

        uvSetDirectory.CreateWithParents();
        uvSetDirectory.File("textured-faces.array").WriteArray(texturedTopology.Faces);
        uvSetDirectory.File("textured-vertex-infos.array").WriteArray(texturedVertexInfos);
    }
Example #2
0
    private void DumpRefinementLevel(int level)
    {
        var targetDirectory = refinementDirectory.Subdirectory("level-" + level);

        if (targetDirectory.Exists)
        {
            return;
        }

        Console.WriteLine("Dumping refined geometry level {0}...", level);

        MultisurfaceQuadTopology topology = figure.Geometry.AsTopology();

        var refinementResult = topology.Refine(level);

        targetDirectory.Create();
        SubdivisionMeshPersistance.Save(targetDirectory, refinementResult.Mesh);
        targetDirectory.File("control-face-map.array").WriteArray(refinementResult.ControlFaceMap);
    }