public RawImageInfo ExtractImage(string channelName) { string imageUrl = (string)GetValue(channelName, "image_file"); if (imageUrl == null) { return(null); } if (!imagesByUrl.TryGetValue(imageUrl, out var image)) { //use a default setting image = new DsonTypes.Image { map_gamma = 0 }; } string texturePath = Uri.UnescapeDataString(imageUrl); FileInfo textureFile = fileLocator.Locate(texturePath).File; return(new RawImageInfo { file = textureFile, gamma = image.map_gamma }); }
private string ExtractHdUrl(string rawUrl) { if (String.IsNullOrEmpty(rawUrl)) { return(null); } var url = Uri.UnescapeDataString(rawUrl).Replace("//", "/"); fileLocator.Locate(url); //confirm the file exists return(url); }
private FragmentCollection LocateCollection(string documentPath, bool throwIfMissing = true) { if (!documentCache.TryGetValue(documentPath, out FragmentCollection fragments)) { var contentFile = fileLocator.Locate(documentPath, throwIfMissing); if (contentFile == null) { return(null); } DsonDocument root = DsonDocument.LoadFromFile(this, contentFile, documentPath); fragments = FragmentCollection.FillFrom(root); documentCache[documentPath] = fragments; } return(fragments); }
public void Run() { var loader = new FigureRecipeLoader(fileLocator, objectLocator, pathManager); FigureRecipe genesis3FemaleRecipe = loader.LoadFigureRecipe("genesis-3-female", null); FigureRecipe genitaliaRecipe = loader.LoadFigureRecipe("genesis-3-female-genitalia", genesis3FemaleRecipe); FigureRecipe genesis3FemaleWithGenitaliaRecipe = new FigureRecipeMerger(genesis3FemaleRecipe, genitaliaRecipe).Merge(); Figure genesis3FemaleWithGenitalia = genesis3FemaleWithGenitaliaRecipe.Bake(fileLocator, null); Figure parentFigure = genesis3FemaleWithGenitalia; FigureRecipe livHairRecipe = loader.LoadFigureRecipe("liv-hair", null); var livHairFigure = livHairRecipe.Bake(fileLocator, parentFigure); var surfaceProperties = SurfacePropertiesJson.Load(pathManager, livHairFigure); var processor = new FaceTransparencyProcessor(device, shaderCache, livHairFigure, surfaceProperties); for (int surfaceIdx = 0; surfaceIdx < livHairFigure.Geometry.SurfaceCount; ++surfaceIdx) { string surfaceName = livHairFigure.Geometry.SurfaceNames[surfaceIdx]; FileInfo textureFile; if (surfaceName == "Hairband") { continue; } else if (surfaceName == "Cap") { textureFile = fileLocator.Locate("/Runtime/Textures/outoftouch/!hair/OOTHairblending2/Liv/OOTUtilityLivCapT.jpg").File; } else { textureFile = fileLocator.Locate("/Runtime/Textures/outoftouch/!hair/OOTHairblending2/Liv/OOTUtilityLivHairT.png").File; } RawFloatTexture opacityTexture = new RawFloatTexture { value = 1, image = new RawImageInfo { file = textureFile, gamma = 1 } }; processor.ProcessSurface(surfaceIdx, livHairFigure.DefaultUvSet.Name, opacityTexture); } var transparencies = processor.FaceTransparencies; for (int i = 0; i < 10; ++i) { int faceIdx = i * 3000; int surfaceIdx = livHairFigure.Geometry.SurfaceMap[faceIdx]; string surfaceName = livHairFigure.Geometry.SurfaceNames[surfaceIdx]; var uvSet = livHairFigure.DefaultUvSet; Quad face = uvSet.Faces[faceIdx]; Console.WriteLine("face {0}: ", faceIdx); Console.WriteLine(" transparency: " + transparencies[faceIdx]); Console.WriteLine(" surface: " + surfaceName); Console.WriteLine(" uv 0: {0}", uvSet.Uvs[face.Index0]); Console.WriteLine(" uv 1: {0}", uvSet.Uvs[face.Index1]); Console.WriteLine(" uv 2: {0}", uvSet.Uvs[face.Index2]); Console.WriteLine(" uv 3: {0}", uvSet.Uvs[face.Index3]); Console.WriteLine(); } Console.WriteLine("min = " + transparencies.Min()); Console.WriteLine("avg = " + transparencies.Average()); Console.WriteLine("max = " + transparencies.Max()); }
public Morph Bake(ContentFileLocator fileLocator, Dictionary <string, Channel> channels) { var hdFile = HdUrl != null?fileLocator.Locate(HdUrl).File : null; return(new Morph(channels[Channel], Deltas, hdFile)); }
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); }); }