private string ExtractImage(RawImageInfo imageInfo, TextureProcessingType type) { if (imageInfo == null) { return(null); } bool isLinear = IsLinear(imageInfo, type); return(textureProcessor.RegisterForProcessing(imageInfo.file, type, isLinear, mask)); }
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); }); }