| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- /*
- Copyright (C) 2012 by Ivan Safrin
-
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
-
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- */
-
- #include "PolycodeEntityEditor.h"
- #include "PolycodeFrame.h"
- extern UIGlobalMenu *globalMenu;
- extern PolycodeFrame *globalFrame;
- EntityEditorMainView::EntityEditorMainView() {
- processInputEvents = true;
- mainScene = new Scene(Scene::SCENE_3D, true);
- renderTexture = new SceneRenderTexture(mainScene, mainScene->getDefaultCamera(), 512, 512);
- mainScene->clearColor.setColor(0.2, 0.2, 0.2, 1.0);
- mainScene->useClearColor = true;
- mainScene->rootEntity.processInputEvents = true;
-
- renderTextureShape = new UIRect(256, 256);
- renderTextureShape->setAnchorPoint(-1.0, -1.0, 0.0);
- renderTextureShape->setTexture(renderTexture->getTargetTexture());
- addChild(renderTextureShape);
- renderTextureShape->setPosition(0, 30);
-
-
- headerBg = new UIRect(10,10);
- addChild(headerBg);
- headerBg->setAnchorPoint(-1.0, -1.0, 0.0);
- headerBg->color.setColorHexFromString(CoreServices::getInstance()->getConfig()->getStringValue("Polycode", "uiHeaderBgColor"));
-
- sideBar = new Entity();
- addChild(sideBar);
- sideBar->setPosition(0, 0);
- sideBar->processInputEvents = true;
-
-
- mainScene->getDefaultCamera()->setPosition(10, 10, 10);
- mainScene->getDefaultCamera()->lookAt(Vector3());
- grid = new EditorGrid();
- mainScene->addChild(grid);
-
- sceneObjectRoot = new Entity();
- sceneObjectRoot->processInputEvents = true;
- mainScene->addChild(sceneObjectRoot);
-
- transformGizmo = new TransformGizmo(mainScene, mainScene->getDefaultCamera());
- mainScene->addChild(transformGizmo);
- trackballCamera = new TrackballCamera(mainScene->getDefaultCamera(), renderTextureShape);
-
- addEntityButton = new UIImageButton("entityEditor/add_entity.png", 1.0, 24, 24);
- sideBar->addChild(addEntityButton);
- addEntityButton->setPosition(4, 2);
- addEntityButton->addEventListener(this, UIEvent::CLICK_EVENT);
-
- transformGizmoMenu = new TransformGizmoMenu(transformGizmo);
- sideBar->addChild(transformGizmoMenu);
- transformGizmoMenu->setPositionX(40);
-
- }
- void EntityEditorMainView::Update() {
- }
- void EntityEditorMainView::setEditorProps(Entity *entity) {
- entity->processInputEvents = true;
- entity->addEventListener(this, InputEvent::EVENT_MOUSEDOWN);
-
- SceneMesh *sceneMesh = dynamic_cast<SceneMesh*>(entity);
- if(sceneMesh) {
- sceneMesh->wireFrameColor = Color(1.0, 0.8, 0.3, 1.0);
- sceneMesh->setLineWidth(CoreServices::getInstance()->getRenderer()->getBackingResolutionScaleX());
- }
- }
- void EntityEditorMainView::addEntityFromMenu(String command) {
- if(command == "add_primitive") {
- ScenePrimitive *newPrimitive = new ScenePrimitive(ScenePrimitive::TYPE_BOX, 1.0, 1.0, 1.0);
- sceneObjectRoot->addChild(newPrimitive);
- setEditorProps(newPrimitive);
- newPrimitive->setPosition(cursorPosition);
- return;
- }
- if(command == "add_mesh") {
- assetSelectType = "mesh";
- globalFrame->assetBrowser->addEventListener(this, UIEvent::OK_EVENT);
- std::vector<String> extensions;
- extensions.push_back("mesh");
- globalFrame->showAssetBrowser(extensions);
- return;
- }
- }
- void EntityEditorMainView::handleEvent(Event *event) {
- if(event->getDispatcher() == globalFrame->assetBrowser) {
- if(event->getEventCode() == UIEvent::OK_EVENT) {
- if(assetSelectType == "mesh") {
- SceneMesh *newMesh = new SceneMesh(globalFrame->assetBrowser->getFullSelectedAssetPath());
- sceneObjectRoot->addChild(newMesh);
- setEditorProps(newMesh);
- newMesh->setPosition(cursorPosition);
- }
-
- globalFrame->assetBrowser->removeAllHandlersForListener(this);
- globalFrame->hideModal();
- }
-
- } else if(event->getDispatcher() == addEntityMenu) {
- addEntityMenu->removeAllHandlersForListener(this);
- String command = addEntityMenu->getSelectedItem()->getMenuItemID();
- addEntityFromMenu(command);
- } else if(event->getDispatcher() == addEntityButton) {
- addEntityMenu = globalMenu->showMenuAtMouse(150);
- addEntityMenu->addOption("Add Primitive", "add_primitive");
- addEntityMenu->addOption("Add Mesh", "add_mesh");
- addEntityMenu->addOption("Add Entity", "add_entity");
- addEntityMenu->addOption("Add Sprite", "add_sprite");
- addEntityMenu->addOption("Add Label", "add_label");
- addEntityMenu->addDivider();
- addEntityMenu->addOption("Add Light", "add_light");
- addEntityMenu->addOption("Add Particle System", "add_particles");
- addEntityMenu->addOption("Add Sound", "add_sound");
- addEntityMenu->addOption("Add Camera", "add_camera");
- addEntityMenu->addDivider();
- addEntityMenu->addOption("Add Empty", "add_empty");
- addEntityMenu->fitToScreenVertical();
- addEntityMenu->addEventListener(this, UIEvent::OK_EVENT);
- } else {
- if(event->getEventCode() == InputEvent::EVENT_MOUSEDOWN ) {
- InputEvent *inputEvent = (InputEvent*) event;
- if(inputEvent->mouseButton == CoreInput::MOUSE_BUTTON2) {
- Entity* targetEntity = (Entity*) event->getDispatcher();
-
- for(int i=0; i < selectedEntities.size(); i++) {
- SceneMesh *sceneMesh = dynamic_cast<SceneMesh*>(selectedEntities[i]);
- if(sceneMesh) {
- sceneMesh->overlayWireframe = false;
- }
- }
-
- selectedEntities.clear();
- selectedEntities.push_back(targetEntity);
- transformGizmo->setTransformSelection(selectedEntities);
-
- SceneMesh *sceneMesh = dynamic_cast<SceneMesh*>(targetEntity);
- if(sceneMesh) {
- sceneMesh->overlayWireframe = true;
- }
- }
- }
- }
- }
- EntityEditorMainView::~EntityEditorMainView() {
-
- }
-
- void EntityEditorMainView::Resize(Number width, Number height) {
- headerBg->Resize(width, 30);
-
- mainScene->sceneMouseAdjust.x = renderTextureShape->getScreenPositionForMainCamera().x;
- mainScene->sceneMouseAdjust.y = CoreServices::getInstance()->getCore()->getYRes() - (renderTextureShape->getScreenPositionForMainCamera().y + renderTextureShape->getHeight());
-
- renderTexture->resizeRenderTexture(width, height-30);
- renderTextureShape->setTexture(renderTexture->getTargetTexture());
- renderTextureShape->Resize(width, height-30);
- }
- PolycodeEntityEditor::PolycodeEntityEditor() : PolycodeEditor(true){
- mainSizer = new UIHSizer(300, 300, 200, false);
- addChild(mainSizer);
-
- mainView = new EntityEditorMainView();
- mainSizer->addLeftChild(mainView);
- }
- PolycodeEntityEditor::~PolycodeEntityEditor() {
- }
- bool PolycodeEntityEditor::openFile(OSFileEntry filePath) {
- PolycodeEditor::openFile(filePath);
- return true;
- }
- void PolycodeEntityEditor::Resize(int x, int y) {
- mainSizer->Resize(x, y);
- PolycodeEditor::Resize(x,y);
- }
|