/// <summary> /// Deletes *.dds in an opc directory. /// </summary> public static int DeleteNormals(OpcPaths opcPaths, IProgress <float> progress = null) { var files = StorageConfig.GetDirectories(opcPaths.PatchesSubDir) .SelectMany(x => StorageConfig.GetFiles(x)) .Where(fileWpath => fileWpath.EndsWith("Normals.aara", StringComparison.OrdinalIgnoreCase)); if (files.IsEmptyOrNull()) { if (progress != null) { progress.Report(1f); } return(0); } var inc = 1f / files.Count(); foreach (var f in files) { File.Delete(f); if (progress != null) { progress.Report(inc); } } return(files.Count()); }
/// <summary> /// Creates normals for the OPC in opcBasePath and saves them as Normals.aara. /// </summary> public static void BuildNormals(OpcPaths opcPaths, bool overrideExisting = false, IObserver <Tup <float, string> > progress = null, CancellationToken cancelToken = default(CancellationToken)) { var normalFileName = "Normals.aara"; var posFiles = StorageConfig.GetDirectories(opcPaths.PatchesSubDir) .SelectMany(x => StorageConfig.GetFiles(x)) .Where(fileWpath => fileWpath.EndsWith("Positions.aara", StringComparison.OrdinalIgnoreCase)); foreach (var file in posFiles) { if (cancelToken.IsCancellationRequested) { if (progress != null) { progress.OnNext(Tup.Create(0f, "Building normals cancelled.")); progress.OnCompleted(); } cancelToken.ThrowIfCancellationRequested(); } var normalsFilePath = Path.Combine(Path.GetDirectoryName(file), normalFileName); if (overrideExisting || !StorageConfig.FileExists(normalsFilePath)) { var posAara = AaraData.FromFile(file); var tileSize = new V2i(posAara.Size[0], posAara.Size[1]); var posArray = AaraData.ConvertArrayToV3ds[posAara.DataTypeAsSymbol](posAara.LoadElements()); var invalidPoints = OpcIndices.GetInvalidPositions(posArray); var indices = OpcIndices.ComputeIndexArray(tileSize, invalidPoints); var normals = OpcIndices.GenerateVertexNormals(indices, posArray) .Select(p => p.ToV3f()).ToArray(); WriteV3fArrayAsAara(normalsFilePath, normals, tileSize); } if (progress != null) { progress.OnNext(Tup.Create(1f / posFiles.Count(), "")); } } if (progress != null) { progress.OnCompleted(); } }
/// <summary> /// Deletes *.dds in an opc directory (if *.tif exists). /// </summary> public static int DeleteDDSs(OpcPaths opcPaths, IProgress <Tup <float, string> > progress = null) { int deleteCounter = 0; var files = StorageConfig.GetDirectories(opcPaths.ImagesSubDir) .SelectMany(x => StorageConfig.GetFiles(x)) .Where(x => Path.GetExtension(x) == ".dds"); if (files.IsEmptyOrNull()) { if (progress != null) { progress.Report(Tup.Create(1f, "No dds images found.")); } return(0); } var inc = 1f / files.Count(); foreach (var f in files) { string tifPath = Path.ChangeExtension(f, ".tif"); var msg = ""; if (StorageConfig.FileExists(tifPath)) { File.Delete(f); deleteCounter++; } else { msg = "dds file not deleted, because it doesn't have a coresponding tif file (" + f + ")"; } if (progress != null) { progress.Report(Tup.Create(inc, msg)); } } return(deleteCounter); }
/// <summary> /// Converts .tif to .dds files in an opc directory for straight to gpu uploads of textures. /// tiffs are convert asynchrounos in parallel /// </summary> public static Task <int> ConvertTiffsToDDSsAsync(OpcPaths opcPaths, bool overrideExisting = false, IProgress <float> progress = null, CancellationToken cancelToken = default(CancellationToken)) { var taskSource = new TaskCompletionSource <int>(); var tiffs = StorageConfig.GetDirectories(opcPaths.ImagesSubDir) .SelectMany(x => StorageConfig.GetFiles(x)) .Where(x => Path.GetExtension(x) == ".tif"); if (tiffs.IsEmptyOrNull()) { if (progress != null) { progress.Report(1f); } taskSource.SetResult(0); return(taskSource.Task); } var inc = 1f / tiffs.Count(); var tasks = new List <Task>(); foreach (var f in tiffs) { cancelToken.ThrowIfCancellationRequested(); var task = Task.Run(() => { ConvertTiffToDDS3(f, overrideExisting); if (progress != null) { progress.Report(inc); } }); tasks.Add(task); } Task.WhenAll(tasks).ContinueWith(_ => taskSource.SetResult(tiffs.Count())); return(taskSource.Task); }
//private static SlimDX.Direct3D11.Device d = new SlimDX.Direct3D11.Device(SlimDX.Direct3D11.DriverType.Reference, SlimDX.Direct3D11.DeviceCreationFlags.None, new SlimDX.Direct3D11.FeatureLevel[] { SlimDX.Direct3D11.FeatureLevel.Level_9_1 }); /// <summary> /// Converts .tif to .dds files in an opc directory for straight to gpu uploads of textures. /// </summary> public static int ConvertTiffsToDDSs(OpcPaths opcPaths, bool overrideExisting = false, IObserver <float> progress = null, CancellationToken cancelToken = default(CancellationToken)) { var tiffs = StorageConfig.GetDirectories(opcPaths.ImagesSubDir) .SelectMany(x => StorageConfig.GetFiles(x)) .Where(x => Path.GetExtension(x) == ".tif"); if (tiffs.IsEmptyOrNull()) { if (progress != null) { progress.OnNext(1f); progress.OnCompleted(); } return(0); } var inc = 1f / tiffs.Count(); foreach (var f in tiffs) { cancelToken.ThrowIfCancellationRequested(); // ConvertTiffToDDS2(f, overrideExisting); // ConvertTiffToDDS(f, overrideExisting); ConvertTiffToDDS3(f, overrideExisting); if (progress != null) { progress.OnNext(inc); } } if (progress != null) { progress.OnCompleted(); } return(tiffs.Count()); }