/// <summary> /// Creates a renderable object from the specified WMO object, and the specified package group it belongs to. /// NOTE: This method *must* be called in the UI thread after the OpenGL context has been made current. /// /// The <see cref="IRenderable"/> constructors commonly make extensive use of OpenGL methods. /// </summary> /// <param name="worldModel">The model object.</param> /// <param name="fileReference">The package group it belongs to.</param> /// <returns>An encapsulated renderable OpenGL object.</returns> public static IRenderable CreateRenderableWorldModel(WMO worldModel, FileReference fileReference) { if (worldModel == null) { return(null); } IRenderable renderableWorldModel = new RenderableWorldModel(worldModel, fileReference.PackageGroup); return(renderableWorldModel); }
/// <summary> /// Creates a renderable object from the specified WMO object, and the specified package group it belongs to. /// NOTE: This method *must* be called in the UI thread after the OpenGL context has been made current. /// The <see cref="IRenderable"/> constructors commonly make extensive use of OpenGL methods. /// </summary> /// <param name="worldModel">The model object.</param> /// <param name="fileReference">The package group it belongs to.</param> /// <param name="version">The contextually relevant version.</param> /// <returns>An encapsulated renderable OpenGL object.</returns> public static IRenderable CreateRenderableWorldModel(WMO worldModel, FileReference fileReference, WarcraftVersion version) { if (worldModel == null) { return(null); } IRenderable renderableWorldModel = new RenderableWorldModel(worldModel, fileReference.PackageGroup, version); return(renderableWorldModel); }
/// <summary> /// Creates a renderable object from the specified WMO object, and the specified package group it belongs to. /// NOTE: This method *must* be called in the UI thread after the OpenGL context has been made current. /// The <see cref="IRenderable"/> constructors commonly make extensive use of OpenGL methods. /// </summary> /// <param name="worldModel">The model object.</param> /// <param name="fileReference">The reference it was constructed from.</param> /// <returns>An encapsulated renderable OpenGL object.</returns> public static IRenderable CreateRenderableWorldModel(WMO worldModel, FileReference fileReference) { var warcraftContext = fileReference.Context as WarcraftGameContext; if (warcraftContext == null) { // TODO: This is bad practice. Refactor throw new ArgumentException("The given context must be a warcraft-typed context.", nameof(fileReference.Context)); } RenderableWorldModel renderableWorldModel = new RenderableWorldModel(worldModel, warcraftContext); renderableWorldModel.LoadDoodads(); return(renderableWorldModel); }
/// <summary> /// Enables the specified control page and brings it to the front. If the <paramref name="pageToEnable"/> /// parameter is <see cref="ControlPage.None"/>, this is interpreted as disabling all pages. /// </summary> /// <param name="pageToEnable">pageToEnable.</param> private void EnableControlPage(ControlPage pageToEnable) { if (pageToEnable == ControlPage.None) { foreach (ControlPage otherPage in Enum.GetValues(typeof(ControlPage))) { DisableControlPage(otherPage); } return; } if (Enum.IsDefined(typeof(ControlPage), pageToEnable)) { // Set the page this.ItemControlNotebook.Page = (int)pageToEnable; // Disable the other pages foreach (ControlPage otherPage in Enum.GetValues(typeof(ControlPage))) { if (otherPage == pageToEnable) { continue; } DisableControlPage(otherPage); } switch (pageToEnable) { case ControlPage.Image: { RenderableImage image = this.RenderingEngine.RenderTarget as RenderableImage; if (image == null) { return; } this.MipCountLabel.Text = image.MipCount.ToString(); this.RenderAlphaCheckButton.Sensitive = true; this.RenderRedCheckButton.Sensitive = true; this.RenderGreenCheckButton.Sensitive = true; this.RenderBlueCheckButton.Sensitive = true; image.RenderAlphaChannel = this.RenderAlphaCheckButton.Active; image.RenderRedChannel = this.RenderRedCheckButton.Active; image.RenderGreenChannel = this.RenderGreenCheckButton.Active; image.RenderBlueChannel = this.RenderBlueCheckButton.Active; break; } case ControlPage.Model: { this.RenderBoundsCheckButton.Sensitive = true; this.RenderWireframeCheckButton.Sensitive = true; RenderableWorldModel wmo = this.RenderingEngine.RenderTarget as RenderableWorldModel; if (wmo != null) { wmo.ShouldRenderBounds = this.RenderBoundsCheckButton.Active; wmo.ShouldRenderWireframe = this.RenderWireframeCheckButton.Active; } RenderableGameModel mdx = this.RenderingEngine.RenderTarget as RenderableGameModel; if (mdx != null) { mdx.ShouldRenderBounds = this.RenderBoundsCheckButton.Active; } break; } case ControlPage.Animation: { break; } case ControlPage.Audio: { break; } } } }
/// <summary> /// Initializes a new instance of the <see cref="MainWindow"/> class. /// </summary> /// <param name="builder">Builder.</param> /// <param name="handle">Handle.</param> private MainWindow(Builder builder, IntPtr handle) : base(handle) { builder.Autoconnect(this); this.DeleteEvent += OnDeleteEvent; this.Shown += OnMainWindowShown; this.WindowStateEvent += OnWindowStateChanged; this.UiThreadScheduler = TaskScheduler.FromCurrentSynchronizationContext(); this.FileLoadingCancellationSource = new CancellationTokenSource(); this.ViewportWidget = new GLWidget { CanFocus = true, SingleBuffer = false, ColorBPP = 24, DepthBPP = 24, AccumulatorBPP = 24, Samples = 4, GlVersionMajor = 3, GlVersionMinor = 3, GraphicsContextFlags = GraphicsContextFlags.Default, }; this.ViewportWidget.Events |= EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.EnterNotifyMask | EventMask.LeaveNotifyMask | EventMask.KeyPressMask | EventMask.KeyReleaseMask; this.ViewportWidget.Initialized += (sender, args) => { // Initialize all OpenGL rendering parameters this.RenderingEngine.Initialize(); Idle.Add(OnIdleRenderFrame); }; this.ViewportWidget.ButtonPressEvent += OnViewportButtonPressed; this.ViewportWidget.ButtonReleaseEvent += OnViewportButtonReleased; this.ViewportWidget.EnterNotifyEvent += OnViewportMouseEnter; this.ViewportWidget.LeaveNotifyEvent += OnViewportMouseLeave; this.ViewportWidget.ConfigureEvent += OnViewportConfigured; this.RenderingEngine = new ViewportRenderer(this.ViewportWidget); this.ViewportAlignment.Add(this.ViewportWidget); this.ViewportAlignment.ShowAll(); this.AboutButton.Clicked += OnAboutButtonClicked; this.PreferencesButton.Clicked += OnPreferencesButtonClicked; this.GameTabNotebook.ClearPages(); this.ExportQueueTreeView.ButtonPressEvent += OnExportQueueButtonPressed; this.ExportQueueTreeView.GetColumn(0).SetCellDataFunc ( this.ExportQueueTreeView.GetColumn(0).Cells[0], RenderExportQueueReferenceIcon ); this.ExportQueueTreeView.GetColumn(0).Expand = true; this.ExportQueueTreeView.GetColumn(0).SetCellDataFunc ( this.ExportQueueTreeView.GetColumn(0).Cells[1], RenderExportQueueReferenceName ); this.RemoveQueueItem.Activated += OnQueueRemoveContextItemActivated; this.FileFilterComboBox.Changed += OnFilterChanged; /* * Set up item control sections to default states */ EnableControlPage(ControlPage.None); /* * Bind item control events */ this.RenderAlphaCheckButton.Toggled += (sender, args) => { RenderableImage image = this.RenderingEngine.RenderTarget as RenderableImage; if (image == null) { return; } image.RenderAlphaChannel = this.RenderAlphaCheckButton.Active; }; this.RenderRedCheckButton.Toggled += (sender, args) => { RenderableImage image = this.RenderingEngine.RenderTarget as RenderableImage; if (image == null) { return; } image.RenderRedChannel = this.RenderRedCheckButton.Active; }; this.RenderGreenCheckButton.Toggled += (sender, args) => { RenderableImage image = this.RenderingEngine.RenderTarget as RenderableImage; if (image == null) { return; } image.RenderGreenChannel = this.RenderGreenCheckButton.Active; }; this.RenderBlueCheckButton.Toggled += (sender, args) => { RenderableImage image = this.RenderingEngine.RenderTarget as RenderableImage; if (image == null) { return; } image.RenderBlueChannel = this.RenderBlueCheckButton.Active; }; this.RenderBoundsCheckButton.Toggled += (sender, args) => { RenderableWorldModel wmo = this.RenderingEngine.RenderTarget as RenderableWorldModel; if (wmo != null) { wmo.ShouldRenderBounds = this.RenderBoundsCheckButton.Active; } RenderableGameModel mdx = this.RenderingEngine.RenderTarget as RenderableGameModel; if (mdx != null) { mdx.ShouldRenderBounds = this.RenderBoundsCheckButton.Active; } }; this.RenderWireframeCheckButton.Toggled += (sender, args) => { RenderableWorldModel wmo = this.RenderingEngine.RenderTarget as RenderableWorldModel; if (wmo != null) { wmo.ShouldRenderWireframe = this.RenderWireframeCheckButton.Active; } }; }
/// <summary> /// Enables the specified control page and brings it to the front. If the <paramref name="pageToEnable"/> /// parameter is <see cref="ControlPage.None"/>, this is interpreted as disabling all pages. /// </summary> /// <param name="pageToEnable">pageToEnable.</param> private void EnableControlPage(ControlPage pageToEnable) { if (pageToEnable == ControlPage.None) { foreach (ControlPage otherPage in Enum.GetValues(typeof(ControlPage))) { DisableControlPage(otherPage); } return; } // Set the page this.ItemControlNotebook.Page = (int)pageToEnable; // Disable the other pages foreach (ControlPage otherPage in Enum.GetValues(typeof(ControlPage))) { if (otherPage == pageToEnable) { continue; } DisableControlPage(otherPage); } switch (pageToEnable) { case ControlPage.Image: { RenderableImage image = this.RenderingEngine.RenderTarget as RenderableImage; if (image == null) { return; } this.MipCountLabel.Text = image.MipCount.ToString(); this.RenderAlphaCheckButton.Sensitive = true; this.RenderRedCheckButton.Sensitive = true; this.RenderGreenCheckButton.Sensitive = true; this.RenderBlueCheckButton.Sensitive = true; image.RenderAlphaChannel = this.RenderAlphaCheckButton.Active; image.RenderRedChannel = this.RenderRedCheckButton.Active; image.RenderGreenChannel = this.RenderGreenCheckButton.Active; image.RenderBlueChannel = this.RenderBlueCheckButton.Active; break; } case ControlPage.Model: { this.RenderBoundsCheckButton.Sensitive = true; this.RenderWireframeCheckButton.Sensitive = true; this.RenderDoodadsCheckButton.Sensitive = true; this.ModelVariationComboBox.Sensitive = true; RenderableWorldModel wmo = this.RenderingEngine.RenderTarget as RenderableWorldModel; if (wmo != null) { wmo.ShouldRenderBounds = this.RenderBoundsCheckButton.Active; wmo.ShouldRenderWireframe = this.RenderWireframeCheckButton.Active; wmo.ShouldRenderDoodads = this.RenderDoodadsCheckButton.Active; var doodadSetNames = wmo.GetDoodadSetNames().ToList(); this.ModelVariationListStore.Clear(); for (int i = 0; i < doodadSetNames.Count; ++i) { this.ModelVariationListStore.AppendValues(doodadSetNames[i], i); } this.ModelVariationComboBox.Active = 0; this.ModelVariationComboBox.Sensitive = this.RenderDoodadsCheckButton.Active; this.RenderDoodadsCheckButton.Sensitive = true; } RenderableGameModel mdx = this.RenderingEngine.RenderTarget as RenderableGameModel; if (mdx != null) { mdx.ShouldRenderBounds = this.RenderBoundsCheckButton.Active; mdx.ShouldRenderWireframe = this.RenderWireframeCheckButton.Active; var skinVariations = mdx.GetSkinVariations().ToList(); this.ModelVariationListStore.Clear(); foreach (var variation in skinVariations) { var firstTextureName = variation.TextureVariation1.Value; if (!string.IsNullOrEmpty(firstTextureName)) { this.ModelVariationListStore.AppendValues(variation.TextureVariation1.Value, variation.ID); } } this.ModelVariationComboBox.Active = 0; this.ModelVariationComboBox.Sensitive = true; this.RenderDoodadsCheckButton.Sensitive = false; } break; } case ControlPage.Animation: { break; } case ControlPage.Audio: { break; } case ControlPage.None: { break; } default: { throw new ArgumentOutOfRangeException(nameof(pageToEnable)); } } }