public void SaveFile(string rootBrowsingFolder = null, string fileExtension = FileExtensionFilterTemplate)
 {
     if (string.IsNullOrEmpty(_persistanceScript.LastFileName))
     {
         SaveAsFile(rootBrowsingFolder, fileExtension);
     }
     else
     {
         _persistanceScript.Save(null);
     }
 }
Example #2
0
    private void DumpParentOverrides(DirectoryInfo shapeDirectory, ShapeImportConfiguration configuration)
    {
        if (configuration.parentOverrides.Count == 0)
        {
            return;
        }

        FileInfo parentOverridesFile = shapeDirectory.File("parent-overrides.dat");

        if (parentOverridesFile.Exists)
        {
            return;
        }

        //persist
        var parentChannelSystem   = figure.Parent.ChannelSystem;
        var parentOverridesByName = configuration.parentOverrides
                                    .ToDictionary(entry => {
            //look up the channel to confirm it exists
            var channel = parentChannelSystem.ChannelsByName[entry.Key];
            return(channel.Name);
        },
                                                  entry => entry.Value);

        shapeDirectory.CreateWithParents();
        Persistance.Save(parentOverridesFile, parentOverridesByName);
    }
Example #3
0
    private void DumpInputs(DirectoryInfo shapeDirectory, ChannelInputs shapeInputs)
    {
        FileInfo shapeFile = shapeDirectory.File("channel-inputs.dat");

        if (shapeFile.Exists)
        {
            return;
        }

        //persist
        Dictionary <string, double> shapeInputsByName = new Dictionary <string, double>();

        foreach (var channel in figure.Channels)
        {
            double defaultValue = channel.InitialValue;
            double value        = channel.GetInputValue(shapeInputs);
            if (value != defaultValue)
            {
                shapeInputsByName.Add(channel.Name, value);
            }
        }

        shapeDirectory.CreateWithParents();
        Persistance.Save(shapeFile, shapeInputsByName);
    }
    public FigureRecipe LoadFigureRecipe(string figureName, FigureRecipe parentRecipe)
    {
        var importProperties = ImportProperties.Load(pathManager, figureName);

        var figureRecipesDirectory = CommonPaths.WorkDir.Subdirectory("recipes/figures");

        figureRecipesDirectory.Create();

        var figureRecipeFile = figureRecipesDirectory.File($"{figureName}.dat");

        if (!figureRecipeFile.Exists)
        {
            Console.WriteLine($"Reimporting {figureName}...");
            FigureRecipe recipeToPersist = FigureImporter.ImportFor(
                figureName,
                fileLocator,
                objectLocator,
                importProperties.Uris,
                parentRecipe,
                importProperties.HdCorrectionInitialValue,
                importProperties.VisibleProducts);

            Persistance.Save(figureRecipeFile, recipeToPersist);
        }

        Console.WriteLine($"Loading {figureName}...");
        FigureRecipe recipe = Persistance.Load <FigureRecipe>(figureRecipeFile);

        return(recipe);
    }
Example #5
0
    private void Dump <T>(string filename, Func <T> factoryFunc)
    {
        var fileInfo = targetDirectory.File(filename);

        if (fileInfo.Exists)
        {
            return;
        }

        T obj = factoryFunc();

        targetDirectory.CreateWithParents();
        Persistance.Save(fileInfo, obj);
    }
Example #6
0
    public void Dump(string name, FileInfo sourceFile)
    {
        FileInfo animationFile = animationsDirectory.File(name + ".dat");

        if (animationFile.Exists)
        {
            return;
        }

        var frameInputs = LoadPoses(sourceFile);

        //persist
        animationFile.Directory.CreateWithParents();
        Persistance.Save(animationFile, frameInputs);
    }
Example #7
0
        public void Execute()
        {
            var persistance = new Persistance();

            var addSourceTmConfiguration = persistance.Load();

            if (addSourceTmConfiguration != null)
            {
                return;
            }

            persistance.Save(new AddSourceTmConfigurations()
            {
                Configurations = new List <AddSourceTmConfiguration>()
            });
        }
Example #8
0
    public static void ImportAll()
    {
        var outfitsDir = CommonPaths.WorkDir.Subdirectory("outfits");

        outfitsDir.CreateWithParents();

        foreach (var outfitFile in CommonPaths.OutfitsDir.GetFiles())
        {
            string name            = outfitFile.GetNameWithoutExtension();
            var    destinationFile = outfitsDir.File(name + ".dat");
            if (destinationFile.Exists)
            {
                continue;
            }

            string json  = outfitFile.ReadAllText();
            var    proxy = JsonConvert.DeserializeObject <OutfitJsonProxy>(json);

            var items = proxy.items
                        .Select(itemProxy => {
                ImportProperties.Load(itemProxy.figure);                         //verify that that a figure with this name exists
                return(new Outfit.Item(itemProxy.figure, itemProxy.label, itemProxy.isInitiallyVisible));
            })
                        .ToList();

            List <Outfit.Fabric> fabrics = proxy.fabrics?.Select(entry => {
                var label = entry.Key;
                var materialSetsByFigureName = entry.Value;

                //verify that the material set for each figure exists
                foreach (var entry2 in materialSetsByFigureName)
                {
                    var figureName        = entry2.Key;
                    var materialSetName   = entry2.Value;
                    var materialSetsConfs = MaterialSetImportConfiguration.Load(figureName);
                    materialSetsConfs.Where(conf => conf.name == materialSetName).Single();
                }

                return(new Outfit.Fabric(label, materialSetsByFigureName));
            })
                                           .ToList();

            var outfit = new Outfit(proxy.label, items, fabrics);

            Persistance.Save(destinationFile, outfit);
        }
    }
    public void DumpAll()
    {
        figureDestDir.CreateWithParents();
        Persistance.Save(figureDestDir.File("surface-properties.dat"), surfaceProperties);

        Dump("shaper-parameters.dat", () => figure.MakeShaperParameters(channelsToInclude));
        Dump("channel-system-recipe.dat", () => figure.MakeChannelSystemRecipe());

        if (figure.Parent == null)
        {
            ValidateBoneSystemAssumptions(figure);
            Dump("bone-system-recipe.dat", () => figure.MakeBoneSystemRecipe());
            Dump("inverter-parameters.dat", () => figure.MakeInverterParameters());
        }
        else
        {
            Dump("child-to-parent-bind-pose-transforms.dat", () => figure.ChildToParentBindPoseTransforms);
        }
    }
Example #10
0
    public static void Import(ImporterPathManager pathManager, FileInfo characterConfFile, DirectoryInfo contentDestDirectory)
    {
        string name = characterConfFile.GetNameWithoutExtension();

        var charactersDir   = contentDestDirectory.Subdirectory("characters");
        var destinationFile = charactersDir.File(name + ".dat");

        if (destinationFile.Exists)
        {
            return;
        }

        string json      = characterConfFile.ReadAllText();
        var    proxy     = JsonConvert.DeserializeObject <CharacterJsonProxy>(json);
        var    character = new Character(proxy.label, proxy.shape, proxy.materialSet);

        charactersDir.CreateWithParents();
        Persistance.Save(destinationFile, character);
    }
Example #11
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();
        Persistance.Save(targetDirectory.File("topology-info.dat"), refinementResult.TopologyInfo);
        SubdivisionMeshPersistance.Save(targetDirectory, refinementResult.Mesh);
        targetDirectory.File("control-face-map.array").WriteArray(refinementResult.ControlFaceMap);
    }
Example #12
0
    private void DumpOccluderParameters(DirectoryInfo shapeDirectory, ChannelInputs shapeInputs, float[] faceTransparencies)
    {
        FileInfo occluderParametersFile = shapeDirectory.File("occluder-parameters.dat");

        if (occluderParametersFile.Exists)
        {
            return;
        }

        Console.WriteLine("Dumping occlusion system...");

        OccluderParameters parameters;

        using (var calculator = new OccluderParametersCalculator(fileLocator, device, shaderCache, figure, faceTransparencies, shapeInputs)) {
            parameters = calculator.CalculateOccluderParameters();
        }

        //persist
        shapeDirectory.CreateWithParents();
        Persistance.Save(occluderParametersFile, parameters);
    }
Example #13
0
 public void createUser()
 {
     Debug.Log(Persistance.Save(new User(username, password)));
 }
    private static MultiMaterialSettings DumpMaterialSet(ImportSettings settings, Device device, ShaderCache shaderCache, ContentFileLocator fileLocator, DsonObjectLocator objectLocator, Figure figure, SurfaceProperties surfaceProperties, MaterialSetImportConfiguration baseConfiguration, DirectoryInfo figureDestDir, MaterialSetImportConfiguration configuration, TextureProcessor textureProcessor)
    {
        DirectoryInfo materialsSetsDirectory     = figureDestDir.Subdirectory("material-sets");
        DirectoryInfo materialSetDirectory       = materialsSetsDirectory.Subdirectory(configuration.name);
        FileInfo      materialSettingsFileInfo   = materialSetDirectory.File("material-settings.dat");
        FileInfo      faceTransparenciesFileInfo = materialSetDirectory.File("face-transparencies.array");

        if (materialSettingsFileInfo.Exists && faceTransparenciesFileInfo.Exists)
        {
            return(Persistance.Load <MultiMaterialSettings>(UnpackedArchiveFile.Make(materialSettingsFileInfo)));
        }

        var aggregator = new DsonMaterialAggregator(fileLocator, objectLocator);
        IEnumerable <string> dufPaths = Enumerable.Concat(baseConfiguration.materialsDufPaths, configuration.materialsDufPaths);

        foreach (string path in dufPaths)
        {
            DsonTypes.DsonDocument doc = objectLocator.LocateRoot(path);
            aggregator.IncludeDuf(doc.Root);
        }

        var faceTransparencyProcessor = new FaceTransparencyProcessor(device, shaderCache, figure, surfaceProperties);

        IMaterialImporter materialImporter;

        if (figure.Name.EndsWith("-hair"))
        {
            materialImporter = new HairMaterialImporter(figure, textureProcessor, faceTransparencyProcessor);
        }
        else
        {
            materialImporter = new UberMaterialImporter(figure, textureProcessor, faceTransparencyProcessor);
        }

        string[] surfaceNames = figure.Geometry.SurfaceNames;
        Dictionary <string, int> surfaceNameToIdx = Enumerable.Range(0, surfaceNames.Length)
                                                    .ToDictionary(idx => surfaceNames[idx], idx => idx);

        var perMaterialSettings = Enumerable.Range(0, figure.Geometry.SurfaceCount)
                                  .Select(surfaceIdx => {
            string surfaceName   = figure.Geometry.SurfaceNames[surfaceIdx];
            var bag              = aggregator.GetBag(surfaceName);
            var materialSettings = materialImporter.Import(surfaceIdx, bag);
            return(materialSettings);
        })
                                  .ToArray();

        var variantCategories = configuration.variantCategories
                                .Select(variantCategoryConf => {
            int[] surfaceIdxs = variantCategoryConf.surfaces
                                .Select(surfaceName => surfaceNameToIdx[surfaceName])
                                .ToArray();

            var variants = variantCategoryConf.variants
                           .Select(variantConf => {
                var variantAggregator = aggregator.Branch();
                foreach (string path in variantConf.materialsDufPaths)
                {
                    DsonTypes.DsonDocument doc = objectLocator.LocateRoot(path);
                    variantAggregator.IncludeDuf(doc.Root);
                }

                var settingsBySurface = variantCategoryConf.surfaces
                                        .Select(surfaceName => {
                    int surfaceIdx       = surfaceNameToIdx[surfaceName];
                    var bag              = variantAggregator.GetBag(surfaceName);
                    var materialSettings = materialImporter.Import(surfaceIdx, bag);
                    return(materialSettings);
                })
                                        .ToArray();

                return(new MultiMaterialSettings.Variant(variantConf.name, settingsBySurface));
            })
                           .ToArray();

            return(new MultiMaterialSettings.VariantCategory(variantCategoryConf.name, surfaceIdxs, variants));
        })
                                .ToArray();

        var multiMaterialSettings = new MultiMaterialSettings(perMaterialSettings, variantCategories);

        materialSetDirectory.CreateWithParents();

        textureProcessor.RegisterAction(() => {
            Persistance.Save(materialSettingsFileInfo, multiMaterialSettings);
        });

        var faceTranparencies = faceTransparencyProcessor.FaceTransparencies;

        faceTransparenciesFileInfo.WriteArray(faceTranparencies);

        faceTransparencyProcessor.Dispose();

        return(multiMaterialSettings);
    }
Example #15
0
    private void DumpNormals(TextureProcessor textureProcessor, DirectoryInfo shapeDirectory, ShapeImportConfiguration shapeImportConfiguration, ChannelInputs shapeInputs)
    {
        var normalsConf     = shapeImportConfiguration?.normals;
        var baseNormalsConf = baseConfiguration?.normals;

        if (normalsConf == null && baseNormalsConf == null)
        {
            return;
        }

        var recipeFile = shapeDirectory.File("shape-normals.dat");

        if (recipeFile.Exists)
        {
            return;
        }

        var surfaceGroups = normalsConf?.surfaceGroups ?? baseNormalsConf?.surfaceGroups;

        var uvSetName = normalsConf?.uvSet ?? baseNormalsConf?.uvSet ?? figure.DefaultUvSet.Name;
        var uvSet     = figure.UvSets[uvSetName];

        var surfaceNames = figure.Geometry.SurfaceNames;
        Dictionary <string, int> surfaceNameToIdx = Enumerable.Range(0, surfaceNames.Length)
                                                    .ToDictionary(idx => surfaceNames[idx], idx => idx);

        bool generateFromHd                 = normalsConf?.generatedFromHd ?? false;
        var  generatedTextureDirectory      = CommonPaths.WorkDir.Subdirectory("generated-textures");
        NormalMapRenderer normalMapRenderer = null;

        string[] textureNamesBySurface = Enumerable.Repeat(ShapeNormalsRecipe.DefaultTextureName, surfaceNames.Length).ToArray();

        for (int groupIdx = 0; groupIdx < surfaceGroups.Count; ++groupIdx)
        {
            var surfaceIdxs = surfaceGroups[groupIdx]
                              .Select(surfaceName => surfaceNameToIdx[surfaceName])
                              .ToList();

            FileInfo textureFile;
            if (!generateFromHd)
            {
                var texturePath = normalsConf?.textures?[groupIdx];
                if (texturePath == null)
                {
                    continue;
                }

                textureFile = fileLocator.Locate(texturePath).File;
            }
            else
            {
                textureFile = generatedTextureDirectory.File($"normal-map-{shapeImportConfiguration.name}-{groupIdx}.png");
                if (!textureFile.Exists)
                {
                    if (normalMapRenderer == null)
                    {
                        Console.WriteLine($"Generating normals for shape '{shapeImportConfiguration.name}'...");
                        normalMapRenderer = hdMorphToNormalMapConverter.MakeNormalMapRenderer(figure, uvSet, shapeInputs);
                    }

                    var normalMap = normalMapRenderer.Render(new HashSet <int>(surfaceIdxs));
                    generatedTextureDirectory.CreateWithParents();
                    normalMap.Save(textureFile);
                    normalMap.Dispose();
                }
            }

            foreach (int surfaceIdx in surfaceIdxs)
            {
                var mask        = TextureMask.Make(uvSet, figure.Geometry.SurfaceMap, surfaceIdx);
                var textureName = textureProcessor.RegisterForProcessing(textureFile, TextureProcessingType.Normal, true, mask);
                textureNamesBySurface[surfaceIdx] = textureName;
            }
        }

        normalMapRenderer?.Dispose();

        var recipe = new ShapeNormalsRecipe(uvSetName, textureNamesBySurface);

        textureProcessor.RegisterAction(() => {
            shapeDirectory.CreateWithParents();
            Persistance.Save(recipeFile, recipe);
        });
    }
    private static MultiMaterialSettings DumpMaterialSet(ImportSettings settings, Device device, ShaderCache shaderCache, ContentFileLocator fileLocator, DsonObjectLocator objectLocator, Figure figure, MaterialSetImportConfiguration baseConfiguration, MaterialSetImportConfiguration configuration, TextureProcessor sharedTextureProcessor)
    {
        DirectoryInfo figuresDirectory           = CommonPaths.WorkDir.Subdirectory("figures");
        DirectoryInfo figureDirectory            = figuresDirectory.Subdirectory(figure.Name);
        DirectoryInfo materialsSetsDirectory     = figureDirectory.Subdirectory("material-sets");
        DirectoryInfo materialSetDirectory       = materialsSetsDirectory.Subdirectory(configuration.name);
        FileInfo      materialSettingsFileInfo   = materialSetDirectory.File("material-settings.dat");
        FileInfo      faceTransparenciesFileInfo = materialSetDirectory.File("face-transparencies.array");

        if (materialSettingsFileInfo.Exists && faceTransparenciesFileInfo.Exists)
        {
            return(Persistance.Load <MultiMaterialSettings>(UnpackedArchiveFile.Make(materialSettingsFileInfo)));
        }

        var aggregator = new DsonMaterialAggregator(fileLocator, objectLocator);
        IEnumerable <string> dufPaths = Enumerable.Concat(baseConfiguration.materialsDufPaths, configuration.materialsDufPaths);

        foreach (string path in dufPaths)
        {
            DsonTypes.DsonDocument doc = objectLocator.LocateRoot(path);
            aggregator.IncludeDuf(doc.Root);
        }

        TextureProcessor localTextureProcessor;

        if (sharedTextureProcessor == null)
        {
            localTextureProcessor = new TextureProcessor(device, shaderCache, materialSetDirectory, settings.CompressTextures);
        }
        else
        {
            localTextureProcessor = null;
        }

        var textureProcessor = sharedTextureProcessor ?? localTextureProcessor;

        var faceTransparencyProcessor = new FaceTransparencyProcessor(device, shaderCache, figure);

        IMaterialImporter materialImporter;

        if (figure.Name.EndsWith("-hair"))
        {
            materialImporter = new HairMaterialImporter(figure, textureProcessor, faceTransparencyProcessor);
        }
        else
        {
            materialImporter = new UberMaterialImporter(figure, textureProcessor, faceTransparencyProcessor);
        }

        var perMaterialSettings = Enumerable.Range(0, figure.Geometry.SurfaceCount)
                                  .Select(surfaceIdx => {
            string surfaceName   = figure.Geometry.SurfaceNames[surfaceIdx];
            var bag              = aggregator.GetBag(surfaceName);
            var materialSettings = materialImporter.Import(surfaceIdx, bag);
            return(materialSettings);
        })
                                  .ToArray();

        var multiMaterialSettings = new MultiMaterialSettings(perMaterialSettings);

        materialSetDirectory.CreateWithParents();

        textureProcessor.RegisterAction(() => {
            Persistance.Save(materialSettingsFileInfo, multiMaterialSettings);
        });

        localTextureProcessor?.ImportAll();

        var faceTranparencies = faceTransparencyProcessor.FaceTransparencies;

        faceTransparenciesFileInfo.WriteArray(faceTranparencies);

        faceTransparencyProcessor.Dispose();

        return(multiMaterialSettings);
    }