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)); } }); }
private void ExecuteScaleCommand() { BusyIndicatorService.Run(dispatcher => { var opt = this.OptModel.File; var size = opt.SpanSize.Scale(OptFile.ScaleFactor, OptFile.ScaleFactor, OptFile.ScaleFactor); var message = Messenger.Instance.Notify( new ScaleFactorMessage { SizeX = size.X, SizeY = size.Y, SizeZ = size.Z }); if (!message.Changed) { return; } BusyIndicatorService.Notify(string.Concat(message.ScaleType, "...")); opt.Scale(message.ScaleX, message.ScaleY, message.ScaleZ); dispatcher(() => this.OptModel.File = opt); }); }
private void ExecuteSaveCommand() { if (this.OptModel.File == null) { return; } if (string.IsNullOrEmpty(this.OptModel.File.FileName)) { this.ExecuteSaveAsCommand(); return; } BusyIndicatorService.Run(dispatcher => { var opt = this.OptModel.File; BusyIndicatorService.Notify(string.Concat("Saving ", System.IO.Path.GetFileName(this.OptModel.File.FileName), "...")); try { opt.Save(opt.FileName); dispatcher(() => this.OptModel.File = this.OptModel.File); dispatcher(() => this.OptModel.UndoStackPush("save " + System.IO.Path.GetFileNameWithoutExtension(opt.FileName))); } catch (Exception ex) { Messenger.Instance.Notify(new MessageBoxMessage(opt.FileName, ex)); } }); }
private void ExecuteExportRhinoCommand() { BusyIndicatorService.Run(dispatcher => { string fileName = FileDialogService.GetSaveRhinoFileName(System.IO.Path.ChangeExtension(this.OptModel.File.FileName, "3dm")); if (fileName == null) { return; } BusyIndicatorService.Notify(string.Concat("Exporting ", System.IO.Path.GetFileName(fileName), "...")); var opt = this.OptModel.File; bool scale = this.IsImportExportScaleEnabled; try { OptRhinoConverter.Converter.OptToRhino(opt, fileName, scale); } catch (Exception ex) { Messenger.Instance.Notify(new MessageBoxMessage(fileName, ex)); } }); }
private void ExecuteRotateMeshCommand(Mesh mesh) { BusyIndicatorService.Run(dispatcher => { var message = new RotateFactorMessage(); if (mesh.Descriptor != null) { var center = mesh.Descriptor.Center; message.CenterX = center.X; message.CenterY = center.Y; } Messenger.Instance.Notify(message); if (!message.Changed) { return; } BusyIndicatorService.Notify("Rotating ..."); mesh.RotateXY(message.Angle, message.CenterX, message.CenterY); dispatcher(() => this.UpdateModel()); dispatcher(() => this.CurrentMeshes.SetSelection(mesh)); dispatcher(() => this.OptModel.UndoStackPush("rotate mesh")); }); }
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 void ExecuteDuplicateMeshesCommand(IList <Mesh> meshes) { BusyIndicatorService.Run(dispatcher => { BusyIndicatorService.Notify("Duplicating ..."); foreach (var mesh in meshes) { this.OptModel.File.Meshes.Add(mesh.Duplicate()); } dispatcher(() => this.UpdateModel()); dispatcher(() => this.CurrentMeshes.SetSelection(meshes)); }); }
private void ExecuteConvertAllTo32BitsCommand() { BusyIndicatorService.Run(dispatcher => { try { BusyIndicatorService.Notify("Converting textures to 32 bits..."); this.OptModel.File.ConvertTextures8To32(); dispatcher(() => this.OptModel.File = this.OptModel.File); } catch (Exception ex) { Messenger.Instance.Notify(new MessageBoxMessage("Convert textures to 32 bits.", ex)); } }); }
private void ExecuteGenerateNamesCommand() { BusyIndicatorService.Run(dispatcher => { try { BusyIndicatorService.Notify("Generating textures names..."); this.OptModel.File.GenerateTexturesNames(); dispatcher(() => this.OptModel.File = this.OptModel.File); } catch (Exception ex) { Messenger.Instance.Notify(new MessageBoxMessage("Generate textures names.", ex)); } }); }
private void ExecuteCompactCommand() { BusyIndicatorService.Run(dispatcher => { try { BusyIndicatorService.Notify("Compacting textures..."); this.OptModel.File.CompactTextures(); dispatcher(() => this.OptModel.File = this.OptModel.File); dispatcher(() => this.OptModel.UndoStackPush("compact textures")); } catch (Exception ex) { Messenger.Instance.Notify(new MessageBoxMessage("Compact textures.", ex)); } }); }
private void ExecuteGenerateAllMipmapsCommand() { BusyIndicatorService.Run(dispatcher => { try { BusyIndicatorService.Notify("Generating all mipmaps..."); this.OptModel.File.GenerateTexturesMipmaps(); dispatcher(() => this.OptModel.File = this.OptModel.File); dispatcher(() => this.OptModel.UndoStackPush("generate mipmaps")); } catch (Exception ex) { Messenger.Instance.Notify(new MessageBoxMessage("Generate all mipmaps.", ex)); } }); }
private void ExecuteChangeAxesCommand() { BusyIndicatorService.Run(dispatcher => { var message = Messenger.Instance.Notify(new ChangeAxesMessage()); if (!message.Changed) { return; } BusyIndicatorService.Notify("Changes axes..."); var opt = this.OptModel.File; opt.ChangeAxes(message.AxisX, message.AxisY, message.AxisZ); dispatcher(() => this.OptModel.File = opt); }); }
private void ExecuteImportAn8Command() { BusyIndicatorService.Run(dispatcher => { string fileName = FileDialogService.GetOpenAn8FileName(); if (fileName == null) { return; } BusyIndicatorService.Notify(string.Concat("Importing ", System.IO.Path.GetFileName(fileName), "...")); var opt = this.OptModel.File; bool scale = this.IsImportExportScaleEnabled; try { dispatcher(() => this.OptModel.File = null); var import = OptAn8Converter.Converter.An8ToOpt(fileName, scale); 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 ExecuteCheckFlatTexturesCommand() { var flatTextures = this.OptModel.File.CheckFlatTextures(false); if (flatTextures.Count == 0) { return; } string text = string.Join("\n", flatTextures); var message = Messenger.Instance.Notify(new MessageBoxMessage("This opt contains flat textures.\nDo you want to remove them?\n\n" + text, "Check Flat Textures", MessageBoxButton.YesNo, MessageBoxImage.Warning)); if (message.Result != MessageBoxResult.Yes) { return; } BusyIndicatorService.Run(dispatcher => { BusyIndicatorService.Notify("Removing flat textures ..."); var opt = this.OptModel.File; try { dispatcher(() => this.OptModel.File = null); opt.CheckFlatTextures(true); } catch (Exception ex) { Messenger.Instance.Notify(new MessageBoxMessage(ex)); } dispatcher(() => this.OptModel.File = opt); dispatcher(() => this.OptModel.UndoStackPush("remove flat textures")); }); }
private void ExecuteMoveMeshesCommand(IList <Mesh> meshes) { BusyIndicatorService.Run(dispatcher => { var message = Messenger.Instance.Notify(new MoveFactorMessage()); if (!message.Changed) { return; } BusyIndicatorService.Notify("Moving ..."); foreach (var mesh in meshes) { mesh.Move(message.MoveX, message.MoveY, message.MoveZ); } dispatcher(() => this.UpdateModel()); dispatcher(() => this.CurrentMeshes.SetSelection(meshes)); }); }
private void ExecuteSaveAsCommand() { if (this.OptModel.File == null) { return; } BusyIndicatorService.Run(dispatcher => { string fileName = FileDialogService.GetSaveOptFileName(this.OptModel.File.FileName); if (fileName == null) { return; } BusyIndicatorService.Notify(string.Concat("Saving ", System.IO.Path.GetFileName(fileName), "...")); var opt = this.OptModel.File; try { opt.Save(fileName); dispatcher(() => this.OptModel.File = this.OptModel.File); 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)); } }); }
private void ExecuteConvertAllTo8BitsCommand() { BusyIndicatorService.Run(dispatcher => { bool doConvertion = this.OptModel.File.CanTexturesBeConvertedWithoutLoss(); if (!doConvertion) { var result = Messenger.Instance.Notify(new MessageBoxMessage( "All textures can not be converted without loss. Do you want to continue?", "Convert textures to 8 bits", MessageBoxButton.YesNo, MessageBoxImage.Warning)); doConvertion = result.Result == MessageBoxResult.Yes; } if (!doConvertion) { return; } try { BusyIndicatorService.Notify("Converting textures to 8 bits..."); this.OptModel.File.ConvertTextures32To8(); dispatcher(() => this.OptModel.File = this.OptModel.File); dispatcher(() => this.OptModel.UndoStackPush("convert to 8 bpp")); } catch (Exception ex) { Messenger.Instance.Notify(new MessageBoxMessage("Convert textures to 8 bits.", ex)); } }); }