| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351 |
- #include "BsEditorApplication.h"
- #include "BsEditorWindowManager.h"
- #include "BsEditorWidgetManager.h"
- #include "BsMainEditorWindow.h"
- #include "BsRenderWindow.h"
- #include "BsBuiltinEditorResources.h"
- #include "BsUndoRedo.h"
- #include "BsFileSerializer.h"
- #include "BsFileSystem.h"
- #include "BsResourceImporter.h"
- #include "BsEditorWidgetLayout.h"
- #include "BsScenePicking.h"
- #include "BsSelection.h"
- #include "BsGizmoManager.h"
- #include "BsCodeEditor.h"
- #include "BsBuildManager.h"
- #include "BsScriptCodeImporter.h"
- #include "BsShaderIncludeHandler.h"
- #include "BsDropDownWindowManager.h"
- // DEBUG ONLY
- #include "DbgEditorWidget1.h"
- #include "DbgEditorWidget2.h"
- #include "BsResources.h"
- #include "BsSceneObject.h"
- #include "BsImporter.h"
- #include "BsGpuProgram.h"
- #include "BsShader.h"
- #include "BsTexture.h"
- #include "BsMaterial.h"
- #include "BsTechnique.h"
- #include "BsPass.h"
- #include "BsRenderable.h"
- #include "BsDbgTestGameObjectRef.h"
- #include "BsVirtualInput.h"
- #include "BsFolderMonitor.h"
- #include "BsProjectLibrary.h"
- #include "BsCamera.h"
- #include "BsGUIWidget.h"
- #include "BsGUIButton.h"
- #include "BsGUILayout.h"
- #include "BsEvent.h"
- #include "BsCoreRenderer.h"
- #include "BsEditorSettings.h"
- #include "BsMesh.h"
- #include "BsMath.h"
- namespace BansheeEngine
- {
- const Path EditorApplication::WIDGET_LAYOUT_PATH = L"Internal\\Layout.asset";
- const Path EditorApplication::BUILD_DATA_PATH = L"Internal\\BuildData.asset";
- RENDER_WINDOW_DESC createRenderWindowDesc()
- {
- RENDER_WINDOW_DESC renderWindowDesc;
- renderWindowDesc.videoMode = VideoMode(1280, 720);
- renderWindowDesc.title = "BansheeEditor";
- renderWindowDesc.fullscreen = false;
- renderWindowDesc.border = WindowBorder::None;
- renderWindowDesc.hideUntilSwap = true;
- return renderWindowDesc;
- }
- EditorApplication::EditorApplication(RenderSystemPlugin renderSystemPlugin)
- :Application(createRenderWindowDesc(), renderSystemPlugin, RendererPlugin::Default),
- mActiveRSPlugin(renderSystemPlugin), mSBansheeEditorPlugin(nullptr)
- {
-
- }
- EditorApplication::~EditorApplication()
- {
- BuildManager::instance().save(BUILD_DATA_PATH);
- CodeEditorManager::shutDown();
- BuildManager::shutDown();
- GizmoManager::shutDown();
- Selection::shutDown();
- ScenePicking::shutDown();
- saveWidgetLayout(EditorWidgetManager::instance().getLayout());
- // TODO - Save project settings
- DropDownWindowManager::shutDown();
- EditorWidgetManager::shutDown();
- EditorWindowManager::shutDown();
- UndoRedo::shutDown();
- // We purposely don't unload this plugin, it needs to be unloaded after
- // all mono assemblies have been unloaded (since their finalizers will call
- // into the plugin). So we leave it to be unloaded automatically on app exit
- shutdownPlugin(mSBansheeEditorPlugin);
- /************************************************************************/
- /* DEBUG CODE */
- /************************************************************************/
- gResources().unload(mTestTexRef);
- gResources().unload(mDbgMeshRef);
- gResources().unload(mTestShader);
- gResources().unload(mTestMaterial);
- mTestMaterial = nullptr;
- mTestTexRef = nullptr;
- mDbgMeshRef = nullptr;
- mTestShader = nullptr;
- /************************************************************************/
- /* END DEBUG CODE */
- /************************************************************************/
- ProjectLibrary::shutDown();
- BuiltinEditorResources::shutDown();
- }
- void EditorApplication::onStartUp()
- {
- Application::onStartUp();
- // TODO - Load project settings
- mEditorSettings = bs_shared_ptr<EditorSettings>();
- BuiltinEditorResources::startUp();
- {
- auto inputConfig = VirtualInput::instance().getConfiguration();
- inputConfig->registerButton("Rename", BC_F2);
- inputConfig->registerButton("Undo", BC_Z, ButtonModifier::Ctrl);
- inputConfig->registerButton("Redo", BC_Y, ButtonModifier::Ctrl);
- inputConfig->registerButton("Copy", BC_C, ButtonModifier::Ctrl);
- inputConfig->registerButton("Cut", BC_X, ButtonModifier::Ctrl);
- inputConfig->registerButton("Paste", BC_V, ButtonModifier::Ctrl);
- inputConfig->registerButton("Delete", BC_DELETE);
- }
- ScriptCodeImporter* scriptCodeImporter = bs_new<ScriptCodeImporter>();
- Importer::instance()._registerAssetImporter(scriptCodeImporter);
- ResourceImporter* resourceImporter = bs_new<ResourceImporter>();
- Importer::instance()._registerAssetImporter(resourceImporter);
- ProjectLibrary::startUp(getProjectPath());
- UndoRedo::startUp();
- EditorWindowManager::startUp();
- EditorWidgetManager::startUp();
- DropDownWindowManager::startUp();
- ScenePicking::startUp();
- Selection::startUp();
- GizmoManager::startUp();
- BuildManager::startUp();
- CodeEditorManager::startUp();
- MainEditorWindow* mainWindow = MainEditorWindow::create(getPrimaryWindow());
- loadPlugin("SBansheeEditor", &mSBansheeEditorPlugin); // Managed part of the editor
- EditorWidgetLayoutPtr layout = loadWidgetLayout();
- if (layout != nullptr)
- EditorWidgetManager::instance().setLayout(layout);
- BuildManager::instance().load(BUILD_DATA_PATH);
- /************************************************************************/
- /* DEBUG CODE */
- /************************************************************************/
- HShader dummyParsedShader = Importer::instance().import<Shader>("..\\..\\..\\..\\Data\\Raw\\Engine\\Shaders\\TestFX.bsl");
- assert(dummyParsedShader != nullptr); // Ad hoc unit test
- RenderAPICore* renderSystem = RenderAPICore::instancePtr();
- HSceneObject testModelGO = SceneObject::create("TestMesh");
- HRenderable testRenderable = testModelGO->addComponent<Renderable>();
- WString testShaderLoc = L"..\\..\\..\\..\\Data\\Test.bsl";;
-
- mTestShader = Importer::instance().import<Shader>(testShaderLoc);
- gResources().save(mTestShader, L"C:\\testShader.asset", true);
- gResources().unload(mTestShader);
- mTestShader = gResources().load<Shader>(L"C:\\testShader.asset");
- mTestMaterial = Material::create(mTestShader);
- mTestTexRef = static_resource_cast<Texture>(Importer::instance().import(L"..\\..\\..\\..\\Data\\Examples\\Dragon.tga"));
- mDbgMeshRef = static_resource_cast<Mesh>(Importer::instance().import(L"..\\..\\..\\..\\Data\\Examples\\Dragon.fbx"));
- gResources().save(mTestTexRef, L"C:\\ExportTest.tex", true);
- gResources().save(mDbgMeshRef, L"C:\\ExportMesh.mesh", true);
- gResources().unload(mTestTexRef);
- gResources().unload(mDbgMeshRef);
- mTestTexRef = static_resource_cast<Texture>(gResources().loadAsync(L"C:\\ExportTest.tex"));
- mDbgMeshRef = static_resource_cast<Mesh>(gResources().loadAsync(L"C:\\ExportMesh.mesh"));
- mDbgMeshRef.blockUntilLoaded();
- mDbgMeshRef->blockUntilCoreInitialized();
- mTestTexRef.blockUntilLoaded();
- mTestTexRef->blockUntilCoreInitialized();
- mTestMaterial->setTexture("tex", mTestTexRef);
- gResources().save(mTestShader, L"C:\\ExportShader.asset", true);
- gResources().save(mTestMaterial, L"C:\\ExportMaterial.mat", true);
- gResources().unload(mTestMaterial);
- gResources().unload(mTestShader);
- mTestShader = gResources().load<Shader>(L"C:\\ExportShader.asset");
- mTestMaterial = gResources().load<Material>(L"C:\\ExportMaterial.mat");
- testRenderable->setMesh(mDbgMeshRef);
- testRenderable->setMaterial(0, mTestMaterial);
- GameObjectHandle<DbgTestGameObjectRef> dbgTestGameObjectRef = testModelGO->addComponent<DbgTestGameObjectRef>();
- dbgTestGameObjectRef->mRenderable = testRenderable;
- HSceneObject clone = testModelGO->clone();
- GameObjectHandle<DbgTestGameObjectRef> clonedDbgTestGameObjectRef = clone->getComponent<DbgTestGameObjectRef>();
- testModelGO->destroy();
- /************************************************************************/
- /* END DEBUG CODE */
- /************************************************************************/
- DbgEditorWidget1::open(); // DEBUG ONLY
- DbgEditorWidget2::open(); // DEBUG ONLY
- }
- void EditorApplication::onShutDown()
- {
- Application::onShutDown();
- }
- void EditorApplication::startUp(RenderSystemPlugin renderSystemPlugin)
- {
- CoreApplication::startUp<EditorApplication>(renderSystemPlugin);
- }
- void EditorApplication::closeModalWindow(RenderWindowPtr window, HSceneObject sceneObject)
- {
- //sceneObject->destroy();
- window->destroy();
- }
- void EditorApplication::preUpdate()
- {
- Application::preUpdate();
- EditorWidgetManager::instance().update();
- DropDownWindowManager::instance().update();
- }
- void EditorApplication::postUpdate()
- {
- Application::postUpdate();
- ProjectLibrary::instance().update();
- EditorWindowManager::instance().update();
- }
- bool EditorApplication::isProjectLoaded() const
- {
- return true; // TODO - DEBUG ONLY
- }
- bool EditorApplication::isGameViewFocused() const
- {
- return false; // TODO
- }
- bool EditorApplication::isSceneViewFocused() const
- {
- return true; // TODO
- }
- const Path& EditorApplication::getProjectPath() const
- {
- static Path dummyProjectPath = L"D:\\DummyBansheeProject\\";
- return dummyProjectPath;
- }
- const WString& EditorApplication::getProjectName() const
- {
- static WString dummyProjectName = L"DummyBansheeProject";
- return dummyProjectName;
- }
- Path EditorApplication::getEditorAssemblyPath() const
- {
- Path assemblyPath = getBuiltinAssemblyFolder();
- assemblyPath.append(toWString(EDITOR_ASSEMBLY) + L".dll");
- return assemblyPath;
- }
- Path EditorApplication::getEditorScriptAssemblyPath() const
- {
- Path assemblyPath = getScriptAssemblyFolder();
- assemblyPath.append(toWString(SCRIPT_EDITOR_ASSEMBLY) + L".dll");
- return assemblyPath;
- }
- Path EditorApplication::getScriptAssemblyFolder() const
- {
- Path assemblyFolder = getProjectPath();
- assemblyFolder.append(INTERNAL_ASSEMBLY_PATH);
- return assemblyFolder;
- }
- EditorWidgetLayoutPtr EditorApplication::loadWidgetLayout()
- {
- Path layoutPath = getProjectPath();
- layoutPath.append(WIDGET_LAYOUT_PATH);
- if(FileSystem::exists(layoutPath))
- {
- FileDecoder fs(layoutPath);
- return std::static_pointer_cast<EditorWidgetLayout>(fs.decode());
- }
- return nullptr;
- }
- void EditorApplication::saveWidgetLayout(const EditorWidgetLayoutPtr& layout)
- {
- Path layoutPath = getProjectPath();
- layoutPath.append(WIDGET_LAYOUT_PATH);
- FileEncoder fs(layoutPath);
- fs.encode(layout.get());
- }
- ShaderIncludeHandlerPtr EditorApplication::getShaderIncludeHandler() const
- {
- return bs_shared_ptr<EditorShaderIncludeHandler>();
- }
- EditorApplication& gEditorApplication()
- {
- return static_cast<EditorApplication&>(EditorApplication::instance());
- }
- }
|