Example #1
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 #2
0
    public static void DumpAllForFigure(ImportSettings settings, ContentFileLocator fileLocator, Device device, ShaderCache shaderCache, Figure parentFigure, Figure figure)
    {
        ShapeImportConfiguration[] configurations = ShapeImportConfiguration.Load(figure.Name);
        var baseConf = configurations.SingleOrDefault(conf => conf.name == "Base");

        ShapeDumper dumper = new ShapeDumper(fileLocator, device, shaderCache, parentFigure, figure, baseConf);

        foreach (var conf in configurations)
        {
            if (!settings.ShouldImportShape(figure.Name, conf.name))
            {
                continue;
            }

            dumper.Dump(conf);
        }

        dumper.DumpUnmorphed();

        MaterialSetImportConfiguration[] materialSetImportConfigurations = MaterialSetImportConfiguration.Load(figure.Name);
        foreach (var materialSetConf in materialSetImportConfigurations)
        {
            if (!settings.ShouldImportMaterialSet(figure.Name, materialSetConf.name))
            {
                continue;
            }

            if (!materialSetConf.useCustomOcclusion)
            {
                continue;
            }

            dumper.DumpOcclusionForMaterialSet(materialSetConf.name);
        }
    }
Example #3
0
 public ShapeDumper(ContentFileLocator fileLocator, Device device, ShaderCache shaderCache, Figure parentFigure, Figure figure, ShapeImportConfiguration baseConfiguration)
 {
     this.fileLocator       = fileLocator;
     this.device            = device;
     this.shaderCache       = shaderCache;
     this.parentFigure      = parentFigure;
     this.figure            = figure;
     this.baseConfiguration = baseConfiguration;
     this.figureDirectory   = CommonPaths.WorkDir.Subdirectory("figures").Subdirectory(figure.Name);
 }
Example #4
0
 public ShapeDumper(ContentFileLocator fileLocator, Device device, ShaderCache shaderCache, Figure parentFigure, float[] parentFaceTransparencies, Figure figure, SurfaceProperties surfaceProperties, ShapeImportConfiguration baseConfiguration)
 {
     this.fileLocator              = fileLocator;
     this.device                   = device;
     this.shaderCache              = shaderCache;
     this.parentFigure             = parentFigure;
     this.parentFaceTransparencies = parentFaceTransparencies;
     this.figure                   = figure;
     this.surfaceProperties        = surfaceProperties;
     this.baseConfiguration        = baseConfiguration;
 }
Example #5
0
 public FigureDumper(ContentFileLocator fileLocator, DsonObjectLocator objectLocator, Device device, ShaderCache shaderCache, Figure parentFigure, Figure figure, SurfaceProperties surfaceProperties, MaterialSetImportConfiguration baseMaterialSetImportConfiguration, ShapeImportConfiguration baseShapeImportConfiguration, ShapeDumper shapeDumper)
 {
     this.device            = device;
     this.shaderCache       = shaderCache;
     this.fileLocator       = fileLocator;
     this.objectLocator     = objectLocator;
     this.parentFigure      = parentFigure;
     this.figure            = figure;
     this.surfaceProperties = surfaceProperties;
     this.baseMaterialSetImportConfiguration = baseMaterialSetImportConfiguration;
     this.baseShapeImportConfiguration       = baseShapeImportConfiguration;
     this.shapeDumper = shapeDumper;
 }
Example #6
0
    public FigureDumper LoadDumper(string figureName)
    {
        var figure = figureName == parentFigure.Name ?
                     parentFigure :
                     figureRecipeLoader.LoadFigureRecipe(figureName, parentFigureRecipe).Bake(parentFigure);

        var figureConfDir = pathManager.GetConfDirForFigure(figure.Name);
        MaterialSetImportConfiguration baseMaterialSetConfiguration = MaterialSetImportConfiguration.Load(figureConfDir).Single(conf => conf.name == "Base");
        ShapeImportConfiguration       baseShapeImportConfiguration = ShapeImportConfiguration.Load(figureConfDir).SingleOrDefault(conf => conf.name == "Base");
        SurfaceProperties surfaceProperties = SurfacePropertiesJson.Load(pathManager, figure);

        ShapeDumper shapeDumper = new ShapeDumper(fileLocator, device, shaderCache, parentFigure, parentFaceTransparencies, figure, surfaceProperties, baseShapeImportConfiguration);

        return(new FigureDumper(fileLocator, objectLocator, device, shaderCache, parentFigure, figure, surfaceProperties, baseMaterialSetConfiguration, baseShapeImportConfiguration, shapeDumper));
    }
Example #7
0
    public static ChannelShaker InitializeFromShapes(Figure figure)
    {
        var shaker = new ChannelShaker(figure.ChannelSystem);

        ShapeImportConfiguration[] shapeConfigurations = ShapeImportConfiguration.Load(figure.Name);
        foreach (var conf in shapeConfigurations)
        {
            foreach (var entry in conf.morphs)
            {
                string channelName = entry.Key + "?value";
                var    channel     = figure.ChannelsByName[channelName];
                shaker.TagDirectUse(channel);
            }
        }

        return(shaker);
    }
Example #8
0
    public void Dump(ShapeImportConfiguration shapeImportConfiguration)
    {
        DirectoryInfo shapeDirectory = GetShapeDirectory(shapeImportConfiguration.name);

        //generate inputs
        var shapeInputs = MakeShapeInputs(shapeImportConfiguration);

        DumpInputs(shapeDirectory, shapeInputs);
        DumpParentOverrides(shapeDirectory, shapeImportConfiguration);

        if (figure == parentFigure)
        {
            DumpOccluderParameters(shapeDirectory, shapeInputs);
        }
        else
        {
            DumpSimpleOcclusion(shapeDirectory, shapeInputs, null);
        }
    }
Example #9
0
    public void DumpShape(DirectoryInfo figureDestDir, ShapeImportConfiguration shapeImportConfiguration)
    {
        DirectoryInfo shapeDirectory = figureDestDir.Subdirectory("shapes").Subdirectory(shapeImportConfiguration.name);

        //generate inputs
        var shapeInputs = MakeShapeInputs(shapeImportConfiguration);

        DumpInputs(shapeDirectory, shapeInputs);
        DumpParentOverrides(shapeDirectory, shapeImportConfiguration);

        var faceTransparencies = FaceTransparencies.For(figure, surfaceProperties, figureDestDir);

        if (figure == parentFigure)
        {
            DumpOccluderParameters(shapeDirectory, shapeInputs, faceTransparencies);
        }
        else
        {
            DumpSimpleOcclusion(shapeDirectory, shapeInputs, faceTransparencies);
        }
    }
Example #10
0
    private ChannelInputs MakeShapeInputs(ShapeImportConfiguration shapeImportConfiguration)
    {
        ChannelInputs inputs = figure.MakeDefaultChannelInputs();

        if (baseConfiguration != null)
        {
            foreach (var entry in baseConfiguration.morphs)
            {
                string channelName = entry.Key + "?value";
                figure.ChannelsByName[channelName].SetValue(inputs, entry.Value);
            }
        }

        if (shapeImportConfiguration != null)
        {
            foreach (var entry in shapeImportConfiguration.morphs)
            {
                string channelName = entry.Key + "?value";
                figure.ChannelsByName[channelName].SetValue(inputs, entry.Value);
            }
        }

        return(inputs);
    }
Example #11
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);
        });
    }
Example #12
0
 public void DumpShape(DirectoryInfo figureDestDir, ShapeImportConfiguration conf)
 {
     shapeDumper.DumpShape(figureDestDir, conf);
 }
Example #13
0
    private void Run(string[] args)
    {
        ImportSettings settings;

        if (args.Length > 0 && args[0] == "release")
        {
            settings = ImportSettings.MakeReleaseSettings();
        }
        else
        {
            settings = ImportSettings.MakeFromViewerInitialSettings();
        }

        var contentDestDir = CommonPaths.WorkDir.Subdirectory("content");

        var contentPackConfs = ContentPackImportConfiguration.LoadAll(CommonPaths.ConfDir);
        var pathManager      = ImporterPathManager.Make(contentPackConfs);

        var figureDumperLoader = new FigureDumperLoader(fileLocator, objectLocator, pathManager, device, shaderCache);

        foreach (var contentPackConf in contentPackConfs)
        {
            var destDir = contentDestDir.Subdirectory(contentPackConf.Name);

            if (contentPackConf.IsCore)
            {
                new UiImporter(destDir).Run();
                new EnvironmentCubeGenerator().Run(settings, destDir);
            }

            var texturesDir      = destDir.Subdirectory("textures").Subdirectory(contentPackConf.Name);
            var textureProcessor = new TextureProcessor(device, shaderCache, texturesDir, contentPackConf.Name, settings.CompressTextures);

            bool shouldImportAnything = false;

            foreach (var figureConf in contentPackConf.Figures)
            {
                string figureName = figureConf.Name;

                if (!settings.FiguresToImport.Contains(figureName))
                {
                    continue;
                }

                var figureDumper = figureDumperLoader.LoadDumper(figureName);

                MaterialSetImportConfiguration[] materialSetConfigurations = MaterialSetImportConfiguration.Load(figureConf.Directory);
                ShapeImportConfiguration[]       shapeImportConfigurations = ShapeImportConfiguration.Load(figureConf.Directory);

                var figureDestDir = destDir.Subdirectory("figures").Subdirectory(figureName);

                if (figureConf.IsPrimary)
                {
                    shouldImportAnything = true;
                    figureDumper.DumpFigure(shapeImportConfigurations, figureDestDir);
                }

                foreach (var materialSetConf in materialSetConfigurations)
                {
                    if (!settings.ShouldImportMaterialSet(figureConf.Name, materialSetConf.name))
                    {
                        continue;
                    }

                    shouldImportAnything = true;
                    figureDumper.DumpMaterialSet(settings, textureProcessor, figureDestDir, materialSetConf);
                }

                if (figureConf.IsPrimary)
                {
                    shouldImportAnything = true;
                    figureDumper.DumpBaseShape(figureDestDir);
                }

                foreach (var shapeConf in shapeImportConfigurations)
                {
                    if (!settings.ShouldImportShape(figureConf.Name, shapeConf.name))
                    {
                        continue;
                    }

                    shouldImportAnything = true;
                    figureDumper.DumpShape(textureProcessor, figureDestDir, shapeConf);
                }
            }

            if (shouldImportAnything)
            {
                foreach (var characterConf in contentPackConf.Characters)
                {
                    CharacterImporter.Import(pathManager, characterConf.File, destDir);
                }

                foreach (var outfitConf in contentPackConf.Outfits)
                {
                    OutfitImporter.Import(pathManager, outfitConf.File, destDir);
                }
            }

            textureProcessor.ImportAll();
        }
    }
Example #14
0
 public void DumpShape(TextureProcessor textureProcessor, DirectoryInfo figureDestDir, ShapeImportConfiguration conf)
 {
     shapeDumper.DumpShape(textureProcessor, figureDestDir, conf);
 }