main.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. // Material Editor Written by Dave Calabrese and Travis Vroman of Gaslight Studios
  23. function initializeMaterialEditor()
  24. {
  25. echo(" % - Initializing Material Editor");
  26. // Load Preview Window
  27. exec("~/materialEditor/gui/guiMaterialPreviewWindow.ed.gui");
  28. // Load Properties Window
  29. exec("~/materialEditor/gui/guiMaterialPropertiesWindow.ed.gui");
  30. //Material Instance viewer
  31. exec("~/materialEditor/gui/materialInstancesView.ed.gui");
  32. // Load Client Scripts.
  33. exec("./scripts/materialEditor.ed.cs");
  34. exec("./scripts/materialEditorUndo.ed.cs");
  35. exec("./scripts/materialInstanceView.ed.cs");
  36. //exec("./gui/profiles.ed.cs");
  37. MaterialEditorPreviewWindow.setVisible( false );
  38. //matEd_cubemapEditor.setVisible( false );
  39. matEd_addCubemapWindow.setVisible( false );
  40. MaterialEditorPropertiesWindow.setVisible( false );
  41. EditorGui.add( MaterialEditorPreviewWindow );
  42. EditorGui.add( matEd_cubemapEditor );
  43. EditorGui.add( matEd_addCubemapWindow );
  44. EditorGui.add( MaterialEditorPropertiesWindow );
  45. }
  46. function destroyMaterialEditor()
  47. {
  48. }
  49. // Material Editor
  50. function MaterialEditorPlugin::onWorldEditorStartup( %this )
  51. {
  52. // Add ourselves to the window menu.
  53. %accel = EditorGui.addToEditorsMenu( "Material Editor", "", MaterialEditorPlugin );
  54. // Add ourselves to the ToolsToolbar
  55. %tooltip = "Material Editor (" @ %accel @ ")";
  56. EditorGui.addToToolsToolbar( "MaterialEditorPlugin", "MaterialEditorPalette", expandFilename("tools/worldEditor/images/toolbar/material-editor"), %tooltip );
  57. //connect editor windows
  58. GuiWindowCtrl::attach( MaterialEditorPropertiesWindow, MaterialEditorPreviewWindow);
  59. %map = new ActionMap();
  60. %map.bindCmd( keyboard, "1", "EWorldEditorNoneModeBtn.performClick();", "" ); // Select
  61. %map.bindCmd( keyboard, "2", "EWorldEditorMoveModeBtn.performClick();", "" ); // Move
  62. %map.bindCmd( keyboard, "3", "EWorldEditorRotateModeBtn.performClick();", "" ); // Rotate
  63. %map.bindCmd( keyboard, "4", "EWorldEditorScaleModeBtn.performClick();", "" ); // Scale
  64. %map.bindCmd( keyboard, "f", "FitToSelectionBtn.performClick();", "" );// Fit Camera to Selection
  65. %map.bindCmd( keyboard, "z", "EditorGuiStatusBar.setCamera(\"Standard Camera\");", "" );// Free Camera
  66. %map.bindCmd( keyboard, "n", "ToggleNodeBar->renderHandleBtn.performClick();", "" );// Render Node
  67. %map.bindCmd( keyboard, "shift n", "ToggleNodeBar->renderTextBtn.performClick();", "" );// Render Node Text
  68. %map.bindCmd( keyboard, "alt s", "MaterialEditorGui.save();", "" );// Save Material
  69. //%map.bindCmd( keyboard, "delete", "ToggleNodeBar->renderTextBtn.performClick();", "" );// delete Material
  70. %map.bindCmd( keyboard, "g", "ESnapOptions-->GridSnapButton.performClick();" ); // Grid Snappping
  71. %map.bindCmd( keyboard, "t", "SnapToBar->objectSnapDownBtn.performClick();", "" );// Terrain Snapping
  72. %map.bindCmd( keyboard, "b", "SnapToBar-->objectSnapBtn.performClick();" ); // Soft Snappping
  73. %map.bindCmd( keyboard, "v", "EWorldEditorToolbar->boundingBoxColBtn.performClick();", "" );// Bounds Selection
  74. %map.bindCmd( keyboard, "o", "objectCenterDropdown->objectBoxBtn.performClick(); objectCenterDropdown.toggle();", "" );// Object Center
  75. %map.bindCmd( keyboard, "p", "objectCenterDropdown->objectBoundsBtn.performClick(); objectCenterDropdown.toggle();", "" );// Bounds Center
  76. %map.bindCmd( keyboard, "k", "objectTransformDropdown->objectTransformBtn.performClick(); objectTransformDropdown.toggle();", "" );// Object Transform
  77. %map.bindCmd( keyboard, "l", "objectTransformDropdown->worldTransformBtn.performClick(); objectTransformDropdown.toggle();", "" );// World Transform
  78. MaterialEditorPlugin.map = %map;
  79. MaterialEditorGui.fileSpec = "Torque Material Files (materials.cs)|materials.cs|All Files (*.*)|*.*|";
  80. MaterialEditorGui.textureFormats = "Image Files (*.png, *.jpg, *.dds, *.bmp, *.gif, *.jng. *.tga)|*.png;*.jpg;*.dds;*.bmp;*.gif;*.jng;*.tga|All Files (*.*)|*.*|";
  81. MaterialEditorGui.modelFormats = "DTS Files (*.dts)|*.dts";
  82. MaterialEditorGui.lastTexturePath = "";
  83. MaterialEditorGui.lastTextureFile = "";
  84. MaterialEditorGui.lastModelPath = "";
  85. MaterialEditorGui.lastModelFile = "";
  86. MaterialEditorGui.currentMaterial = "";
  87. MaterialEditorGui.lastMaterial = "";
  88. MaterialEditorGui.currentCubemap = "";
  89. MaterialEditorGui.currentObject = "";
  90. MaterialEditorGui.livePreview = "1";
  91. MaterialEditorGui.currentLayer = "0";
  92. MaterialEditorGui.currentMode = "Material";
  93. MaterialEditorGui.currentMeshMode = "EditorShape";
  94. new ArrayObject(UnlistedCubemaps);
  95. UnlistedCubemaps.add( "unlistedCubemaps", matEdCubeMapPreviewMat );
  96. UnlistedCubemaps.add( "unlistedCubemaps", WarnMatCubeMap );
  97. //MaterialEditor persistence manager
  98. new PersistenceManager(matEd_PersistMan);
  99. }
  100. function MaterialEditorPlugin::onActivated( %this )
  101. {
  102. if($gfx::wireframe){
  103. $wasInWireFrameMode = true;
  104. $gfx::wireframe = false;
  105. }else{
  106. $wasInWireFrameMode = false;
  107. }
  108. advancedTextureMapsRollout.Expanded = false;
  109. accumulationPropertiesRollout.Expanded = false;
  110. lightingPropertiesRollout.Expanded = false;
  111. materialAnimationPropertiesRollout.Expanded = false;
  112. materialAdvancedPropertiesRollout.Expanded = false;
  113. WorldEditorPlugin.onActivated();
  114. EditorGui-->MatEdPropertiesWindow.setVisible( true );
  115. EditorGui-->MatEdPreviewWindow.setVisible( true );
  116. EditorGui-->WorldEditorToolbar.setVisible( true );
  117. MaterialEditorGui.currentObject = $Tools::materialEditorList;
  118. // Execute the back end scripts that actually do the work.
  119. MaterialEditorGui.open();
  120. %this.map.push();
  121. Parent::onActivated(%this);
  122. }
  123. function MaterialEditorPlugin::onEditMenuSelect( %this, %editMenu )
  124. {
  125. WorldEditorPlugin.onEditMenuSelect( %editMenu );
  126. }
  127. function MaterialEditorPlugin::onDeactivated( %this )
  128. {
  129. if($wasInWireFrameMode)
  130. $gfx::wireframe = true;
  131. WorldEditorPlugin.onDeactivated();
  132. MaterialEditorGui.quit();
  133. EditorGui-->MatEdPropertiesWindow.setVisible( false );
  134. EditorGui-->MatEdPreviewWindow.setVisible( false );
  135. EditorGui-->WorldEditorToolbar.setVisible( false );
  136. %this.map.pop();
  137. Parent::onDeactivated(%this);
  138. }