private void button_EditvLuxSettings_Click(object sender, System.EventArgs e) { try { //add/edit lighting cfg (either custom or default name "lighting.cfg") to RCS: string lightingCfgFile = VLuxLightingTool.GetLightingCfgFile(_settings); ManagedBase.RCS.GetProvider().EditFile(lightingCfgFile); Process vLux = FileHelper.RunExternalTool("vLux", VLuxLightingDlg.vLuxEXEPath, VLuxArgumentString, true); if (vLux == null) { return; } Console.WriteLine(vLux.StandardOutput.ReadToEnd()); vLux.WaitForExit(); int iExitCode = vLux.ExitCode; //add lighting cfg file to RCS ManagedBase.RCS.GetProvider().AddFile(lightingCfgFile, false /* Text file */); } catch (Exception ex) { EditorManager.DumpException(ex); EditorManager.ShowMessageBox("Could not start vLux (\"" + VLuxLightingDlg.vLuxEXEPath + "\").\n\nDetailed message:\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button_EditvLuxSettings_Click(object sender, System.EventArgs e) { try { //add/edit lighting cfg (either custom or default name "lighting.cfg") to RCS: string lightingCfgFile = VLuxLightingTool.GetLightingCfgFile(_settings); ManagedBase.RCS.GetProvider().EditFile(lightingCfgFile); Process vLux = FileHelper.RunExternalTool("vLux", VLuxLightingDlg.vLuxEXEPath, VLuxArgumentString, true); if (vLux == null) { return; } // ReadToEnd will block so we do so in another thread. Thread StandardOutputThread = new Thread(() => { Console.WriteLine(vLux.StandardOutput.ReadToEnd()); }); using (WaitForProcessDlg waitDlg = new WaitForProcessDlg("vLux", vLux)) { waitDlg.ShowDialog(this); } // In case the user somehow succeeds in closing WaitForProcessDlg it will block here until the process in done. vLux.WaitForExit(); int iExitCode = vLux.ExitCode; //add lighting cfg file to RCS ManagedBase.RCS.GetProvider().AddFile(lightingCfgFile, false /* Text file */); } catch (Exception ex) { EditorManager.DumpException(ex); EditorManager.ShowMessageBox("Could not start vLux (\"" + VLuxLightingDlg.vLuxEXEPath + "\").\n\nDetailed message:\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
//CollectionPanel collectionPanel = null; // deactivated for now, will come in a later release //InteractiveHelpPanel interactiveHelpPanel = null; // I put this into a separate function because VS messed it up too often! void InitializeMyComponent() { this.SuspendLayout(); // Creating Docking Containers dockContainer.BringToFront(); dockContainer.Parent = this; EditorManager.ApplicationLayout.DockingArea = dockContainer; // Create Engine Panel enginePanel1 = new Editor.EnginePanel(EditorManager.ApplicationLayout.DockingArea); enginePanel1.ShowDockable(); // TEMP //interactiveHelpPanel = new InteractiveHelpPanel(); //interactiveHelpPanel.ShowDockable(); // create dockable undo redo history panel undoHistoryPanel = new UndoHistoryPanel(EditorManager.ApplicationLayout.DockingArea); undoHistoryPanel.ShowDockable(); // TEMP shapeCreatorPanel = new ShapeCreatorPanel(EditorManager.ApplicationLayout.DockingArea); shapeCreatorPanel.ShowDockable(); shapeCreatorPanel.SelectedCreatorObjectChanged += new EventHandler(shapeCreatorPanel_SelectedCreatorObjectChanged); // AssetBrowserPanel assetBrowserPanel = new AssetBrowserPanel(EditorManager.ApplicationLayout.DockingArea); assetBrowserPanel.ShowDockable(); // deactivated for now, will come in a later release //collectionPanel = new CollectionPanel(EditorManager.ApplicationLayout.DockingArea); //collectionPanel.ShowDockable(); // Create Dockable Property Panel propertyPanel1 = new Editor.PropertyPanel(EditorManager.ApplicationLayout.DockingArea); propertyPanel1.ShowDockable(); // Create Dockable ShapeTree Panel shapeTreePanel = new ShapeTreePanel(EditorManager.ApplicationLayout.DockingArea); shapeTreePanel.ShowDockable(); // Create Shape Search Panel shapeSearchPanel = new ShapeSearchPanel(EditorManager.ApplicationLayout.DockingArea); shapeSearchPanel.ShowDockable(); shapeDuplicatesPanel = new FindDuplicatesPanel(EditorManager.ApplicationLayout.DockingArea); shapeDuplicatesPanel.ShowDockable(); visibilityResultPanel = new VisibilityResultPanel(EditorManager.ApplicationLayout.DockingArea); visibilityResultPanel.ShowDockable(); actionRecorderPanel = new ActionRecorderPanel(EditorManager.ApplicationLayout.DockingArea); actionRecorderPanel.ShowDockable(); // Script Panel ScriptPanel scriptPanel = new VisionScriptPanel(EditorManager.ApplicationLayout.DockingArea); scriptPanel.ShowDockable(); ScriptPanel.Instance = scriptPanel; // Component Panel ConfigureShapeComponentsPanel.PanelInstance.ShowDockable(); try { resourceViewerPanel = new ResourceViewerPanel(EditorManager.ApplicationLayout.DockingArea); resourceViewerPanel.ShowDockable(); EditorManager.EngineManager.LogWindow = resourceViewerPanel; vResourceViewer.Classes.ResourceInfo.OnSelectedResourceChanged += new EventHandler(ResourceInfo_OnSelectedResourceChanged); vResourceViewerBase80.Controls.MasterPanel.OnAutomatedResourcePreview += new EventHandler(ResourceInfo_OnAutomatedResourcePreview); resourceViewerPanel.VisibleChanged += new EventHandler(resourceViewerPanel_VisibleChanged); EditorManager.EditorConsole = resourceViewerPanel; // it implements IEditorConsole } catch (Exception ex) { EditorManager.DumpException(ex); } this.ResumeLayout(true); // set the references in the EditorManager EditorManager.GUI.MainMenu = this.mainMenu; EditorManager.GUI.MainToolBar = this.mainToolBar; EditorManager.GUI.EnginePanelToolBar = this.enginePanel1.Toolbar; // Create the MRU lists mruList_RecentProjects = new MRUList(RecentProjects); mruList_RecentProjects.MRUEvent += new MRUListEventHandler(this.Menu_File_Recent_Project_Click); mruList_RecentProjects.LoadFromRegistry(@"Software\Havok\VisionSDK\vEngineEditor\RecentProjects"); mruList_RecentScenes = new MRUList(RecentScenes); mruList_RecentScenes.MRUEvent += new MRUListEventHandler(this.Menu_File_Recent_Scene_Click); mruList_RecentScenes.LoadFromRegistry(@"Software\Havok\VisionSDK\vEngineEditor\RecentScenes"); // Check for a tablet CSharpFramework.Contexts.WintabTabletContext tablet = new CSharpFramework.Contexts.WintabTabletContext(); if (tablet.IsAvailable && tablet.IsActive) EditorManager.Tablet = tablet; else EditorManager.Tablet = new NullTabletContext(); // default lighting tool VLux.VLuxLightingTool vLuxTool = new VLux.VLuxLightingTool(); EditorManager.SupportedLightingTools.Add(vLuxTool); }
public bool RunLighting(bool bShowDlg, ZoneCollection zones, bool bIncludeMainZone) { bool bExportInfoOnly = false; if (bShowDlg) { VLuxLightingDlg dlg = new VLuxLightingDlg(); dlg.Settings = (EditorManager.Scene as EditorScene).Settings; // clone settings dlg.LightMainPart = bIncludeMainZone; if (dlg.ShowDialog() != DialogResult.OK) { return(false); } // copy back settings: (EditorManager.Scene as EditorScene).Settings = dlg.Settings; if (!dlg.DoRelighting) { return(true); } bExportInfoOnly = dlg.ExportInfoOnly; } // for progress bar int iRelevantCount = bIncludeMainZone ? 1 : 0; foreach (Zone zone in zones) { if (zone.RunLighting) { iRelevantCount++; } } // nothing to light if (iRelevantCount == 0) { return(true); } Cursor oldCursor = EditorManager.MainForm.Cursor; EditorManager.MainForm.Cursor = Cursors.WaitCursor; VisionLightInfo info = new VisionLightInfo(); EditorManager.Progress.ShowProgressDialog("Calculate static lighting"); EditorManager.Progress.Percentage = 0.0f; float fPercentageStep = 100.0f / (float)iRelevantCount; // collect all infos foreach (Layer layer in EditorManager.Scene.Layers) { layer.GetStaticLightInfo(info); } // save all info files, for every zone and optionally main zone for (int i = 0; i <= zones.Count; i++) { Zone zone = null; if (i == zones.Count) { if (!bIncludeMainZone) { continue; } } else { zone = zones[i]; if (!zone.RunLighting) { continue; } } info.FilterByZone(zone); // save file that contains static lights string basename = "StaticLightingInfo"; if (zone != null) { zone.StaticLightInfo = (StaticLightInfo)info.Clone(); basename += "_" + zone.ZoneName; } string absfilename = Path.Combine(EditorManager.Scene.LayerDirectoryName, basename + ".XML"); if (!info.Save(absfilename)) { EditorManager.MainForm.Cursor = oldCursor; EditorManager.Progress.HideProgressDialog(); return(false); } // also, collect static mesh information string meshRelFilename = Path.Combine(EditorManager.Scene.RelativeLayerDirectoryName, basename + ".temp"); string meshAbsFilename = Path.Combine(EditorManager.Scene.LayerDirectoryName, basename + ".temp"); EditorManager.EngineManager.CreateStaticLightingMeshes(meshAbsFilename, info); EditorManager.Progress.Percentage += fPercentageStep; } if (bExportInfoOnly) { EditorManager.MainForm.Cursor = oldCursor; EditorManager.Progress.HideProgressDialog(); return(true); } // trigger the event (maybe another before info.Save?) EditorManager.TriggerSceneEvent(SceneEventArgs.Action.BeforeStaticLighting, true); // put together vLux parameter string string projectDir = EditorManager.Project.ProjectDir; if (projectDir.EndsWith(@"\")) { projectDir = projectDir.Remove(projectDir.Length - 1, 1); } // restart progress bar EditorManager.Progress.Percentage = 0.0f; // launch vLux n times bool bSuccess = true; for (int i = 0; i <= zones.Count; i++) { bool bVLuxSuccess = true; Zone zone = null; if (i == zones.Count) { if (!bIncludeMainZone) { continue; } } else { zone = zones[i]; if (!zone.Loaded || !zone.RunLighting) { continue; } } // save file that contains static lights string basename = "StaticLightingInfo"; if (zone != null) { basename += "_" + zone.ZoneName; } string meshLitFilename = Path.Combine(EditorManager.Scene.LayerDirectoryName, basename + ".lit"); // determine out filename (including relative path) and remove file extension string outFilename = EditorManager.Scene.FileName; string outFilenameExt = Path.GetExtension(outFilename); if (outFilenameExt != null) { outFilename = outFilename.Remove(outFilename.Length - outFilenameExt.Length, outFilenameExt.Length); } if (zone != null) { outFilename += "_" + zone.ZoneName; } //set edit mode for relevant lighting files EditorManager.EngineManager.EditOrAddRCSLightingFiles(Path.Combine(projectDir, outFilename), zone, meshLitFilename, false); string paramStr = "\"\""; // no v3d (first parameter just empty quotes) paramStr += " -project \"" + projectDir + "\""; // the project folder paramStr += " -tempfolder \"" + EditorManager.Scene.LayerDirectoryName + "\""; // the relative folder name where the temp files are located paramStr += " -out \"" + outFilename + "\""; // output filename if (zone != null) { paramStr += " -zone \"" + zone.ZoneName + "\""; } //paramStr += " -title \"" + EditorApp.Scene.FileName + "\""; // no window title required in this mode paramStr += " -quiet -minimized"; string lightingCfgFile = VLuxLightingTool.GetLightingCfgFile((EditorManager.Scene as EditorScene).Settings); ManagedBase.RCS.GetProvider().EditFile(lightingCfgFile); paramStr += " -config \"" + lightingCfgFile + "\""; try { // create a batch file for stand-alone lighting string batchName = Path.Combine(EditorManager.Scene.LayerDirectoryName, "Relight_" + basename + ".bat"); TextWriter txt = new StreamWriter(batchName); txt.WriteLine("vLux.exe " + paramStr); txt.Close(); } catch (Exception ex) { EditorManager.DumpException(ex); } try { Process vLux = FileHelper.RunExternalTool("vLux", VLuxLightingDlg.vLuxEXEPath, paramStr, true); if (vLux == null) { EditorManager.MainForm.Cursor = oldCursor; EditorManager.Progress.HideProgressDialog(); return(false); } Console.WriteLine(vLux.StandardOutput.ReadToEnd()); vLux.WaitForExit(); int iExitCode = vLux.ExitCode; // can we do something with this? } catch (Exception ex) { EditorManager.ShowMessageBox("vLux did not complete lighting. Please try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); EditorManager.DumpException(ex); bVLuxSuccess = false; } // wait until vLux is finished... EditorManager.Progress.Percentage += fPercentageStep; // reload the engine files if (bSuccess) { bVLuxSuccess &= EditorManager.EngineManager.ReloadLightingFiles(outFilename, zone); bVLuxSuccess &= EditorManager.EngineManager.ReloadStaticLightingMeshes(zone, meshLitFilename); EditorManager.Scene.UpdateView(true); EditorManager.Scene.UpdateView(true); //add relevant lighting files to RCS ManagedBase.RCS.GetProvider().AddFile(lightingCfgFile, false); EditorManager.EngineManager.EditOrAddRCSLightingFiles(Path.Combine(projectDir, outFilename), zone, meshLitFilename, true); } System.Diagnostics.Debug.Assert(bVLuxSuccess, "lighting was not successful"); bSuccess &= bVLuxSuccess; // trigger the event (maybe another before info.Save?) EditorManager.OnSceneEvent(new SceneEventArgs(SceneEventArgs.Action.AfterStaticLighting, bSuccess)); } // Update all shader assignments IScene.SendShaderResourceChangedEvent(new EventArgs()); // repaint EditorManager.Scene.UpdateView(false); EditorManager.MainForm.Cursor = oldCursor; EditorManager.Progress.HideProgressDialog(); return(bSuccess); }