public FigureRenderer Load(IArchiveDirectory figureDir, string materialSetName)
    {
        SurfaceProperties surfaceProperties = Persistance.Load <SurfaceProperties>(figureDir.File("surface-properties.dat"));

        var refinementDirectory = figureDir.Subdirectory("refinement");

        var controlMeshDirectory = refinementDirectory.Subdirectory("control");

        int[] surfaceMap = controlMeshDirectory.File("surface-map.array").ReadArray <int>();

        var             refinedMeshDirectory = refinementDirectory.Subdirectory("level-" + surfaceProperties.SubdivisionLevel);
        SubdivisionMesh mesh = SubdivisionMeshPersistance.Load(refinedMeshDirectory);

        int[] controlFaceMap = refinedMeshDirectory.File("control-face-map.array").ReadArray <int>();

        var materialSet = MaterialSet.LoadActive(device, shaderCache, textureCache, dataDir, figureDir, materialSetName, surfaceProperties);
        var materials   = materialSet.Materials;

        Scatterer scatterer = surfaceProperties.PrecomputeScattering ? Scatterer.Load(device, shaderCache, figureDir, materialSetName) : null;

        var uvSetName = materials[0].UvSet;
        IArchiveDirectory uvSetDirectory = figureDir.Subdirectory("uv-sets").Subdirectory(uvSetName);

        var texturedVertexInfos = uvSetDirectory.File("textured-vertex-infos.array").ReadArray <TexturedVertexInfo>();

        Quad[] texturedFaces = uvSetDirectory.File("textured-faces.array").ReadArray <Quad>();

        var vertexRefiner = new VertexRefiner(device, shaderCache, mesh, texturedVertexInfos);

        FigureSurface[] surfaces = FigureSurface.MakeSurfaces(device, materials.Length, texturedFaces, controlFaceMap, surfaceMap, materialSet.FaceTransparencies);

        HashSet <int> visitedSurfaceIndices = new HashSet <int>();
        List <int>    surfaceOrder          = new List <int>(surfaces.Length);

        bool[] areUnorderedTransparent = new bool[surfaces.Length];

        //first add surfaces with an explicity-set render order
        foreach (int surfaceIdx in surfaceProperties.RenderOrder)
        {
            visitedSurfaceIndices.Add(surfaceIdx);
            surfaceOrder.Add(surfaceIdx);
            areUnorderedTransparent[surfaceIdx] = false;
        }

        //then add any remaining surfaces
        for (int surfaceIdx = 0; surfaceIdx < surfaces.Length; ++surfaceIdx)
        {
            if (visitedSurfaceIndices.Contains(surfaceIdx))
            {
                continue;
            }
            surfaceOrder.Add(surfaceIdx);
            areUnorderedTransparent[surfaceIdx] = true;
        }

        var isOneSided = figureDir.Name == "genesis-3-female";         //hack

        return(new FigureRenderer(device, shaderCache, scatterer, vertexRefiner, materialSet, surfaces, isOneSided, surfaceOrder.ToArray(), areUnorderedTransparent));
    }
예제 #2
0
    public static Scatterer Load(Device device, ShaderCache shaderCache, IArchiveDirectory figureDir, String materialSetName)
    {
        var             l0GeometryDir = figureDir.Subdirectory("refinement").Subdirectory("level-0");
        SubdivisionMesh level0Mesh    = SubdivisionMeshPersistance.Load(l0GeometryDir);

        var scatteringDir      = figureDir.Subdirectory("scattering").Subdirectory(materialSetName);
        var formFactorSegments = scatteringDir.File(FormFactorSegmentsFilename).ReadArray <ArraySegment>();
        var formFactorElements = scatteringDir.File(FormFactoryElementsFilename).ReadArray <Vector3WeightedIndex>();
        var formFactors        = new PackedLists <Vector3WeightedIndex>(formFactorSegments, formFactorElements);

        return(new Scatterer(device, shaderCache, level0Mesh, formFactors));
    }
예제 #3
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);
    }