private void OnUnload(object sender, RoutedEventArgs e) { _visualsObserver?.Dispose(); ViewportRenderer?.Dispose(); ViewportRenderer = null; Camera.PropertyChanged -= OnCameraChanged; Camera.Space.GetRoot().Changed -= OnCameraChanged; }
public static void RenderModels(ViewportRenderer renderer) { if (!FileTools.TryOpenFolderDialog(out string folderPath, "Select Source Directory")) { return; } if (!FileTools.TryOpenFolderDialog(out string outputPath, "Select PNG Output Directory")) { return; } var viewportWasRendering = renderer.IsRendering; renderer.PauseRendering(); isBatchRendering = true; var saveImages = Task.Run(SaveImagesFromQueue); foreach (var file in Directory.EnumerateFiles(folderPath, "*model.numdlb", SearchOption.AllDirectories)) { string sourceFolder = Directory.GetParent(file).FullName; try { var nodes = GetRenderableNodes(sourceFolder); RenderModel(renderer, nodes); // Screenshots will be saved and disposed later to improve performance. imagesToSave.Enqueue(new SaveImageWorkItem(renderer.GetScreenshot(), folderPath, file, outputPath)); } catch (Exception) { continue; } finally { renderer.ClearRenderableNodes(); } } isBatchRendering = false; saveImages.Wait(); // Clear the viewport. renderer.RenderNodes(); renderer.SwapBuffers(); if (viewportWasRendering) { renderer.RestartRendering(); } }
public Viewport() { SnapsToDevicePixels = true; UseLayoutRounding = true; RenderOptions.SetBitmapScalingMode(this, BitmapScalingMode.NearestNeighbor); ViewportRenderer = new ViewportRenderer(); InteractorRight = new ZoomInteractor(); Unloaded += OnUnload; Loaded += OnLoad; Dispatcher.ShutdownStarted += ShutdownStarted; }
private static void RenderModel(ViewportRenderer renderer, List <IRenderableNode> nodes) { if (nodes.Count == 0) { return; } var rnumdl = nodes[0] as RNumdl; if (rnumdl?.RenderModel != null) { renderer.Camera.FrameBoundingSphere(rnumdl.RenderModel.BoundingSphere); } renderer.ItemToRender = nodes[0].Renderable.Value; renderer.RenderNodes(); renderer.SwapBuffers(); }
/// <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> /// 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.UIThreadScheduler = TaskScheduler.FromCurrentSynchronizationContext(); 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.KeyPressMask | EventMask.KeyReleaseMask; this.ViewportWidget.Initialized += delegate { // Initialize all OpenGL rendering parameters this.RenderingEngine.Initialize(); Idle.Add(OnIdleRenderFrame); }; this.ViewportWidget.ButtonPressEvent += OnViewportButtonPressed; this.ViewportWidget.ButtonReleaseEvent += OnViewportButtonReleased; this.ViewportWidget.ConfigureEvent += OnViewportConfigured; this.RenderingEngine = new ViewportRenderer(this.ViewportWidget); this.ViewportAlignment.Add(this.ViewportWidget); this.ViewportAlignment.ShowAll(); // Add a staggered idle handler for adding enumerated items to the interface //Timeout.Add(1, OnIdle, Priority.DefaultIdle); Idle.Add(OnIdle, Priority.DefaultIdle); this.AboutButton.Clicked += OnAboutButtonClicked; this.PreferencesButton.Clicked += OnPreferencesButtonClicked; this.GameExplorerTreeView.RowExpanded += OnGameExplorerRowExpanded; this.GameExplorerTreeView.RowActivated += OnGameExplorerRowActivated; this.GameExplorerTreeView.Selection.Changed += OnGameExplorerSelectionChanged; this.GameExplorerTreeView.ButtonPressEvent += OnGameExplorerButtonPressed; this.GameExplorerTreeSorter.SetSortFunc(1, SortGameExplorerRow); this.GameExplorerTreeSorter.SetSortColumnId(1, SortType.Descending); this.ExportQueueTreeView.ButtonPressEvent += OnExportQueueButtonPressed; this.ExtractItem.Activated += OnExtractContextItemActivated; this.ExportItem.Activated += OnExportItemContextItemActivated; this.OpenItem.Activated += OnOpenContextItemActivated; this.CopyItem.Activated += OnCopyContextItemActivated; this.QueueItem.Activated += OnQueueContextItemActivated; this.RemoveQueueItem.Activated += OnQueueRemoveContextItemActivated; this.FiletreeBuilder = new ExplorerBuilder ( new ExplorerStore ( this.GameExplorerTreeStore, this.GameExplorerTreeFilter, this.GameExplorerTreeSorter ) ); this.FiletreeBuilder.PackageGroupAdded += OnPackageGroupAdded; this.FiletreeBuilder.PackageEnumerated += OnPackageEnumerated; this.FiletreeBuilder.Start(); /* * Set up item control sections to default states */ EnableControlPage(ControlPage.None); }
/// <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(); var graphicsMode = new GraphicsMode ( new ColorFormat(24), 24, 0, 4, 0, 2, false ); this.ViewportWidget = new ViewportArea(graphicsMode, 3, 3, GraphicsContextFlags.Default) { AutoRender = true, CanFocus = true }; this.ViewportWidget.Events |= EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.EnterNotifyMask | EventMask.LeaveNotifyMask | EventMask.KeyPressMask | EventMask.KeyReleaseMask; this.ViewportWidget.Initialized += (sender, args) => { this.RenderingEngine.Initialize(); }; this.ViewportWidget.Render += (sender, args) => { if (this.IsShuttingDown) { return; } if (!this.RenderingEngine.IsInitialized) { return; } this.RenderingEngine.RenderFrame(); this.ViewportWidget.QueueRender(); }; this.ViewportWidget.ButtonPressEvent += OnViewportButtonPressed; this.ViewportWidget.ButtonReleaseEvent += OnViewportButtonReleased; this.ViewportWidget.EnterNotifyEvent += OnViewportMouseEnter; this.ViewportWidget.LeaveNotifyEvent += OnViewportMouseLeave; 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], CellRenderers.RenderExportQueueReferenceIcon ); this.ExportQueueTreeView.GetColumn(0).Expand = true; this.ExportQueueTreeView.GetColumn(0).SetCellDataFunc ( this.ExportQueueTreeView.GetColumn(0).Cells[1], CellRenderers.RenderExportQueueReferenceName ); this.ModelVariationComboBox.SetCellDataFunc ( this.ModelVariationTextRenderer, CellRenderers.RenderModelVariationName ); this.RemoveQueueItem.Activated += OnQueueRemoveContextItemActivated; this.ClearExportQueueButton.Clicked += OnClearExportQueueButtonClicked; this.RunExportQueueButton.Clicked += OnRunExportQueueButtonClicked; this.FileFilterComboBox.Changed += OnFilterChanged; this.CancelCurrentActionButton.Clicked += OnCancelCurrentActionClicked; /* * Set up item control sections to default states */ EnableControlPage(ControlPage.None); /* * Bind item control events */ BindImageControlEvents(); BindModelControlEvents(); }
public static void Main(string[] args) { Console.WriteLine("Starting"); var terrainTypes = new TerrainTypes(); var map = TerrainMap.CreateMap(terrainTypes); var renderType = RenderType.Grid; var navigator = new LimitedRangeNavigator <GridDirection>(GridNavigation.CreateNavigator(renderType), map.Width, map.Height); var desert = new TextTile("Desert", '.', ConsoleColor.DarkYellow); var tileRegistry = new BasicTileRegistry <TextTile>() { { "terrain.grasland", new TextTile("Gras", 'g', ConsoleColor.DarkGreen) }, { "terrain.desert", desert }, { "terrain.hills", new TextTile("Hills", 'h', ConsoleColor.Gray) }, { "terrain.plains", new TextTile("Plains", '_', ConsoleColor.Green) } }; var list = new List <ITileMatcher <TextTile, Nothing> > { new BasicTileSelector <TextTile, Nothing>( (x, y) => map[x, y].Terrain == terrainTypes.Desert, navigator, tileRegistry, "terrain.desert"), new BasicTileSelector <TextTile, Nothing>( (x, y) => map[x, y].Terrain == terrainTypes.Grasland, navigator, tileRegistry, "terrain.grasland"), new BasicTileSelector <TextTile, Nothing>( (x, y) => map[x, y].Terrain == terrainTypes.Hills, navigator, tileRegistry, "terrain.hills"), new BasicTileSelector <TextTile, Nothing>( (x, y) => map[x, y].Terrain == terrainTypes.Plains, navigator, tileRegistry, "terrain.plains") }; var bMatcher = new AggregateTileMatcher <TextTile, Nothing>(list); var viewport = new MapViewport(renderType) { SizeInTiles = new IntDimension(20, 20), CenterPoint = new ContinuousViewportCoordinates(0, 0) }; var consoleRenderer = new ViewportRenderer <TextTile, Nothing>(viewport) { RenderTarget = new ConsoleRenderer() }; var plotOp = new PlotOperation <TextTile, Nothing>(bMatcher, renderType, consoleRenderer); var t = new GridPlotter(viewport, navigator); do { t.Draw(plotOp); var consoleKeyInfo = Console.ReadKey(true); if (consoleKeyInfo.Key == ConsoleKey.Escape || consoleKeyInfo.Key == ConsoleKey.Enter) { break; } var center = viewport.CenterPoint; if (consoleKeyInfo.Key == ConsoleKey.LeftArrow) { center += new ContinuousViewportCoordinates(-1, 0); } if (consoleKeyInfo.Key == ConsoleKey.RightArrow) { center += new ContinuousViewportCoordinates(+1, 0); } if (consoleKeyInfo.Key == ConsoleKey.UpArrow) { center += new ContinuousViewportCoordinates(0, -1); } if (consoleKeyInfo.Key == ConsoleKey.DownArrow) { center += new ContinuousViewportCoordinates(0, +1); } viewport.CenterPoint = center; } while (true); }