private void ExecuteOpenCommand() { BusyIndicatorService.Run(dispatcher => { string fileName = FileDialogService.GetOpenOptFileName(); if (fileName == null) { return; } BusyIndicatorService.Notify(string.Concat("Opening ", System.IO.Path.GetFileName(fileName), "...")); try { dispatcher(() => this.OptModel.File = null); var opt = OptFile.FromFile(fileName); dispatcher(() => this.OptModel.File = opt); dispatcher(() => this.OptModel.UndoStackPush("open " + System.IO.Path.GetFileNameWithoutExtension(fileName))); if (!this.OptModel.IsPlayable) { Messenger.Instance.Notify(new MainViewSelectorMessage("PlayabilityMessages")); Messenger.Instance.Notify(new MessageBoxMessage(fileName + "\n\n" + "This opt will not be fully playable.", "Check Opt Playability", MessageBoxButton.OK, MessageBoxImage.Warning)); } } catch (Exception ex) { Messenger.Instance.Notify(new MessageBoxMessage(fileName, ex)); } }); }
public static int ReadOptFunction([MarshalAs(UnmanagedType.LPStr)] string optFilename) { _tempOptFile = null; _tempOptFileSize = 0; if (!File.Exists(optFilename)) { return(0); } string optName = Path.GetFileNameWithoutExtension(optFilename); IList <string> objectLines = GetCustomFileLines("Skins"); IList <string> baseSkins = XwaHooksConfig.Tokennize(XwaHooksConfig.GetFileKeyValue(objectLines, optName)); bool hasDefaultSkin = GetSkinDirectoryLocatorPath(optName, "Default") != null; int fgCount = GetFlightgroupsCount(objectLines, optName); bool hasSkins = hasDefaultSkin || baseSkins.Count != 0 || fgCount != 0; if (hasSkins) { var opt = OptFile.FromFile(optFilename); fgCount = Math.Max(fgCount, opt.MaxTextureVersion); UpdateOptFile(optName, opt, objectLines, baseSkins, fgCount, hasDefaultSkin); //opt.Save("temp.opt", false); _tempOptFile = opt; _tempOptFileSize = opt.GetSaveRequiredFileSize(false); } return(hasSkins ? _tempOptFileSize : 0); }
private Tuple <OptFile, OptCache> GetOptModel(string name) { OptFile file; if (!this.optFiles.TryGetValue(name, out file)) { string fileName = AppSettings.WorkingDirectory + "FLIGHTMODELS\\" + name + ".opt"; if (!System.IO.File.Exists(fileName)) { return(null); } file = OptFile.FromFile(fileName); this.optFiles.Add(name, file); } OptCache cache; if (!this.optCaches.TryGetValue(name, out cache)) { cache = new OptCache(file); this.optCaches.Add(name, cache); } return(new Tuple <OptFile, OptCache>(file, cache)); }
public static int ReadOptFunction([MarshalAs(UnmanagedType.LPStr)] string optFilename) { if (!File.Exists(optFilename)) { return(0); } string optName = Path.GetFileNameWithoutExtension(optFilename); IList <string> objectLines = GetCustomFileLines("Skins"); IList <string> baseSkins = XwaHooksConfig.Tokennize(XwaHooksConfig.GetFileKeyValue(objectLines, optName)); var baseDefaultSkinDirectory = new DirectoryInfo($"FlightModels\\Skins\\{optName}\\Default"); bool baseDefaultSkinExists = baseDefaultSkinDirectory.Exists && baseDefaultSkinDirectory.EnumerateFiles().Any(); int fgCount = GetFlightgroupsCount(objectLines, optName); bool hasSkins = baseDefaultSkinExists || baseSkins.Count != 0 || fgCount != 0; if (hasSkins) { var opt = OptFile.FromFile(optFilename); fgCount = Math.Max(fgCount, opt.MaxTextureVersion); UpdateOptFile(optName, opt, objectLines, baseSkins, fgCount); opt.Save("temp.opt"); } return(hasSkins ? 1 : 0); }
private void ExecuteImportOptCommand() { BusyIndicatorService.Run(dispatcher => { string fileName = FileDialogService.GetOpenOptFileName(); if (fileName == null) { return; } BusyIndicatorService.Notify(string.Concat("Importing ", System.IO.Path.GetFileName(fileName), "...")); var opt = this.OptModel.File; try { dispatcher(() => this.OptModel.File = null); var import = OptFile.FromFile(fileName); string importName = System.IO.Path.GetFileNameWithoutExtension(fileName) + "_"; foreach (var faceGroup in import.Meshes.SelectMany(t => t.Lods).SelectMany(t => t.FaceGroups)) { var textures = faceGroup.Textures.ToList(); faceGroup.Textures.Clear(); foreach (var texture in textures) { faceGroup.Textures.Add(texture.StartsWith(importName, StringComparison.Ordinal) ? texture : (importName + texture)); } } foreach (var texture in import.Textures.Values) { texture.Name = texture.Name.StartsWith(importName, StringComparison.Ordinal) ? texture.Name : (importName + texture.Name); } foreach (var texture in import.Textures.Values) { opt.Textures[texture.Name] = texture; } foreach (var mesh in import.Meshes) { opt.Meshes.Add(mesh); } } catch (Exception ex) { Messenger.Instance.Notify(new MessageBoxMessage(fileName, ex)); } dispatcher(() => this.OptModel.File = opt); dispatcher(() => this.OptModel.UndoStackPush("import " + System.IO.Path.GetFileName(fileName))); }); }
private void ExecuteConvertAllTexturesTo8BppCommand() { BusyIndicatorService.Run(dispatcher => { string fileName = FileDialogService.GetOpenOptFileName(); if (fileName == null) { return; } string directory = System.IO.Path.GetDirectoryName(fileName); BusyIndicatorService.Notify("Converting all textures to 8 bpp..."); var message = Messenger.Instance.Notify(new MessageBoxMessage(string.Concat("The textures of all OPTs in \"", directory, "\" will be converted to 8 bpp.\nDo you want to continue?"), "Converting textures", MessageBoxButton.YesNo, MessageBoxImage.Warning)); if (message.Result != MessageBoxResult.Yes) { return; } foreach (string file in System.IO.Directory.GetFiles(directory, "*.opt")) { BusyIndicatorService.Notify(string.Concat("Converting ", System.IO.Path.GetFileName(file), " to 8 bpp...")); OptFile opt = null; try { opt = OptFile.FromFile(file); } catch (System.IO.InvalidDataException) { continue; } if (opt.TexturesBitsPerPixel == 8) { continue; } opt.ConvertTextures32To8(); opt.Save(opt.FileName); } BusyIndicatorService.Notify("Converting all textures to 8 bpp completed."); Messenger.Instance.Notify(new MessageBoxMessage("Converting all textures to 8 bpp completed.", "Converting textures")); }); }
private static void ContentChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) { var opt = (OptVisual3D)obj; switch (args.Property.Name) { case "FileName": opt.File = null; if (!string.IsNullOrEmpty(opt.FileName)) { try { opt.File = OptFile.FromFile(opt.FileName); } catch (InvalidDataException) { } } break; case "File": opt.Cache = null; if (opt.File != null) { opt.Cache = new OptCache(opt.File); } break; case "Cache": case "Mesh": case "Lod": case "Distance": case "Version": case "IsSolid": case "IsWireframe": if (opt.Distance == null) { opt.LoadOpt(opt.Mesh, opt.Lod, opt.Version); } else { opt.LoadOpt(opt.Mesh, opt.Distance.Value, opt.Version); } break; } opt.Changed?.Invoke(opt, EventArgs.Empty); switch (args.Property.Name) { case "Cache": case "Mesh": case "Lod": case "Distance": opt.ModelChanged?.Invoke(opt, EventArgs.Empty); break; case "Version": case "IsSolid": case "IsWireframe": opt.AppearanceChanged?.Invoke(opt, EventArgs.Empty); break; } }
public OptModel(string fileName) { this.File = OptFile.FromFile(fileName); this.Cache = new OptCache(this.File); this.SpanSize = this.File.SpanSize; }
public void CreateDeviceDependentResources(DeviceResources resources) { this.deviceResources = resources; //string fileName = Path.GetDirectoryName(this.OptFileName) + "\\" + Path.GetFileNameWithoutExtension(this.OptFileName) + "Exterior.opt"; //OptFile opt; //if (File.Exists(fileName)) //{ // opt = OptFile.FromFile(fileName); //} //else //{ // opt = OptFile.FromFile(this.OptFileName); //} OptFile opt = OptFile.FromFile(this.OptFileName); this.OptSize = opt.Size * OptFile.ScaleFactor; this.OptSpanSize = opt.SpanSize.Scale(OptFile.ScaleFactor, OptFile.ScaleFactor, OptFile.ScaleFactor); Vector max = opt.MaxSize; Vector min = opt.MinSize; this.OptCenter = new Vector() { X = (max.X + min.X) / 2, Y = (max.Y + min.Y) / 2, Z = (max.Z + min.Z) / 2 }.Scale(OptFile.ScaleFactor, OptFile.ScaleFactor, OptFile.ScaleFactor); this.CreateTextures(opt); this.CreateMeshes(opt); byte[] vertexShaderBytecode = File.ReadAllBytes("VertexShader.cso"); this.vertexShader = this.deviceResources.D3DDevice.CreateVertexShader(vertexShaderBytecode, null); D3D11InputElementDesc[] basicVertexLayoutDesc = new D3D11InputElementDesc[] { new D3D11InputElementDesc { SemanticName = "POSITION", SemanticIndex = 0, Format = DxgiFormat.R32G32B32Float, InputSlot = 0, AlignedByteOffset = 0, InputSlotClass = D3D11InputClassification.PerVertexData, InstanceDataStepRate = 0 }, new D3D11InputElementDesc { SemanticName = "NORMAL", SemanticIndex = 0, Format = DxgiFormat.R32G32B32Float, InputSlot = 0, AlignedByteOffset = 12, InputSlotClass = D3D11InputClassification.PerVertexData, InstanceDataStepRate = 0 }, new D3D11InputElementDesc { SemanticName = "TEXCOORD", SemanticIndex = 0, Format = DxgiFormat.R32G32Float, InputSlot = 0, AlignedByteOffset = 24, InputSlotClass = D3D11InputClassification.PerVertexData, InstanceDataStepRate = 0 } }; this.inputLayout = this.deviceResources.D3DDevice.CreateInputLayout(basicVertexLayoutDesc, vertexShaderBytecode); byte[] pixelShaderBytecode = File.ReadAllBytes("PixelShader.cso"); this.pixelShader = this.deviceResources.D3DDevice.CreatePixelShader(pixelShaderBytecode, null); var constantBufferDesc = new D3D11BufferDesc(ConstantBufferData.Size, D3D11BindOptions.ConstantBuffer); this.constantBuffer = this.deviceResources.D3DDevice.CreateBuffer(constantBufferDesc); D3D11SamplerDesc samplerDesc = new D3D11SamplerDesc( D3D11Filter.Anisotropic, D3D11TextureAddressMode.Wrap, D3D11TextureAddressMode.Wrap, D3D11TextureAddressMode.Wrap, 0.0f, this.deviceResources.D3DFeatureLevel > D3D11FeatureLevel.FeatureLevel91 ? D3D11Constants.DefaultMaxAnisotropy : D3D11Constants.FeatureLevel91DefaultMaxAnisotropy, D3D11ComparisonFunction.Never, new float[] { 0.0f, 0.0f, 0.0f, 0.0f }, 0.0f, float.MaxValue); this.sampler = this.deviceResources.D3DDevice.CreateSamplerState(samplerDesc); D3D11RasterizerDesc rasterizerDesc = D3D11RasterizerDesc.Default; rasterizerDesc.CullMode = D3D11CullMode.None; this.rasterizerState = this.deviceResources.D3DDevice.CreateRasterizerState(rasterizerDesc); this.depthStencilState0 = this.deviceResources.D3DDevice.CreateDepthStencilState(D3D11DepthStencilDesc.Default); D3D11DepthStencilDesc depthStencilDesc = D3D11DepthStencilDesc.Default; depthStencilDesc.DepthWriteMask = D3D11DepthWriteMask.Zero; this.depthStencilState1 = this.deviceResources.D3DDevice.CreateDepthStencilState(depthStencilDesc); this.blendState0 = this.deviceResources.D3DDevice.CreateBlendState(D3D11BlendDesc.Default); D3D11BlendDesc blendDesc = D3D11BlendDesc.Default; D3D11RenderTargetBlendDesc[] blendDescRenderTargets = blendDesc.GetRenderTargets(); blendDescRenderTargets[0].IsBlendEnabled = true; blendDescRenderTargets[0].SourceBlend = D3D11BlendValue.SourceAlpha; blendDescRenderTargets[0].DestinationBlend = D3D11BlendValue.InverseSourceAlpha; blendDescRenderTargets[0].BlendOperation = D3D11BlendOperation.Add; blendDescRenderTargets[0].SourceBlendAlpha = D3D11BlendValue.One; blendDescRenderTargets[0].DestinationBlendAlpha = D3D11BlendValue.InverseSourceAlpha; blendDescRenderTargets[0].BlendOperationAlpha = D3D11BlendOperation.Add; blendDescRenderTargets[0].RenderTargetWriteMask = D3D11ColorWriteEnables.All; blendDesc.SetRenderTargets(blendDescRenderTargets); this.blendState1 = this.deviceResources.D3DDevice.CreateBlendState(blendDesc); }
static void Main(string[] args) { try { Console.WriteLine("Opt Fix 2.2"); string openFileName = GetOpenFile(); if (string.IsNullOrEmpty(openFileName)) { return; } var opt = OptFile.FromFile(openFileName); string optName = Path.GetFileNameWithoutExtension(opt.FileName); string optType; if (optName.EndsWith("exterior", StringComparison.OrdinalIgnoreCase)) { optType = "Exterior"; optName = optName.Substring(0, optName.Length - optType.Length); } else if (optName.EndsWith("cockpit", StringComparison.OrdinalIgnoreCase)) { optType = "Cockpit"; optName = optName.Substring(0, optName.Length - optType.Length); } else { optType = string.Empty; } Console.WriteLine("{0} [{1}]", optName, optType); Console.WriteLine(); int mmeshIndex = -1; string mmeshIndexString = Microsoft.VisualBasic.Interaction.InputBox("Mesh index:\n-1 means whole OPT", "Mesh index", mmeshIndex.ToString(CultureInfo.InvariantCulture)); if (!string.IsNullOrEmpty(mmeshIndexString)) { mmeshIndex = int.Parse(mmeshIndexString, CultureInfo.InvariantCulture); } Console.WriteLine("Mesh index = " + (mmeshIndex < 0 ? "whole OPT" : mmeshIndex.ToString(CultureInfo.InvariantCulture))); Console.WriteLine(); Console.WriteLine("Checking..."); int facesCount = XwOptChecking(opt, mmeshIndex); Console.WriteLine("Checked {0} faces", facesCount); Console.WriteLine(); double threshold = 51.428571428571431; string thresholdString = Microsoft.VisualBasic.Interaction.InputBox("Normals threshold in degrees:", "Normals threshold", threshold.ToString(CultureInfo.InvariantCulture)); if (!string.IsNullOrEmpty(thresholdString)) { threshold = double.Parse(thresholdString, CultureInfo.InvariantCulture); } Console.WriteLine("Normals threshold = " + threshold.ToString(CultureInfo.InvariantCulture) + "°"); Console.WriteLine(); Console.WriteLine("Computing..."); XwOptComputing(opt, mmeshIndex, threshold); Console.WriteLine("Computed"); Console.WriteLine(); string saveFileName = Path.Combine(Path.GetDirectoryName(openFileName), optName + "9" + optType + ".opt"); saveFileName = GetSaveAsFile(saveFileName); if (string.IsNullOrEmpty(saveFileName)) { return; } opt.Save(saveFileName); } catch (Exception ex) { Console.WriteLine(ex); } }