Skip to content

Commit

Permalink
#123 Add editor handles (not yet implement) to modify position, scale…
Browse files Browse the repository at this point in the history
…, rotate
  • Loading branch information
ducphamhong committed May 8, 2021
1 parent 87e5b77 commit eaed344
Show file tree
Hide file tree
Showing 9 changed files with 389 additions and 57 deletions.
86 changes: 29 additions & 57 deletions Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ This file is part of the "Skylicht Engine".
#include "CSpaceScene.h"
#include "GUI/Input/CInput.h"
#include "GridPlane/CGridPlane.h"
#include "Tween/CTweenManager.h"
#include "EditorComponents/Viewpoint/CViewpoint.h"

#include "Editor/SpaceController/CSceneController.h"

Expand All @@ -52,7 +50,8 @@ namespace Skylicht
m_viewpointZone(NULL),
m_viewpoint(NULL),
m_viewpointCamera(NULL),
m_3dPanel(NULL)
m_3dPanel(NULL),
m_handlesRenderer(NULL)
{
initDefaultScene();

Expand Down Expand Up @@ -147,6 +146,9 @@ namespace Skylicht
viewpoint->setName(L"Viewpoint");
m_viewpoint = viewpoint->addComponent<CViewpoint>();

// handles
m_handlesRenderer = m_scene->getEntityManager()->addRenderSystem<CHandlesRenderer>();

// set scene to controller
CSceneController::getInstance()->setScene(m_scene);
}
Expand Down Expand Up @@ -204,6 +206,21 @@ namespace Skylicht
m_viewpointCamera->lookAt(core::vector3df(0.0f, 0.0f, 0.0f), up);
}

void CSpaceScene::setupCameraTween(CTweenVector3df* look, CTweenVector3df* up)
{
look->OnUpdate = [camera = m_editorCamera, up, look](CTween* t)
{
camera->setUpVector(up->getValue());
camera->setLookVector(look->getValue());
};

up->setEase(EEasingFunctions::EaseLinear);
look->setEase(EEasingFunctions::EaseLinear);

CTweenManager::getInstance()->addTween(up);
CTweenManager::getInstance()->addTween(look);
}

void CSpaceScene::setCameraLook(CViewpointData::EAxis axis)
{
float time = 350.0f;
Expand All @@ -215,85 +232,37 @@ namespace Skylicht
{
CTweenVector3df* tweenLook = new CTweenVector3df(look, core::vector3df(-1.0f, 0.0f, 0.0f), time);
CTweenVector3df* tweenUp = new CTweenVector3df(up, core::vector3df(0.0f, 1.0f, 0.0f), time);

tweenUp->OnUpdate = [camera = m_editorCamera](CTween* t) {camera->setUpVector(((CTweenVector3df*)t)->getValue()); };
tweenUp->setEase(EEasingFunctions::EaseLinear);

tweenLook->OnUpdate = [camera = m_editorCamera](CTween* t) {camera->setLookVector(((CTweenVector3df*)t)->getValue()); };
tweenLook->setEase(EEasingFunctions::EaseLinear);

CTweenManager::getInstance()->addTween(tweenUp);
CTweenManager::getInstance()->addTween(tweenLook);
setupCameraTween(tweenLook, tweenUp);
}
else if (axis == CViewpointData::XNeg)
{
CTweenVector3df* tweenLook = new CTweenVector3df(look, core::vector3df(1.0f, 0.0f, 0.0f), time);
CTweenVector3df* tweenUp = new CTweenVector3df(up, core::vector3df(0.0f, 1.0f, 0.0f), time);

tweenUp->OnUpdate = [camera = m_editorCamera](CTween* t) {camera->setUpVector(((CTweenVector3df*)t)->getValue()); };
tweenUp->setEase(EEasingFunctions::EaseLinear);

tweenLook->OnUpdate = [camera = m_editorCamera](CTween* t) {camera->setLookVector(((CTweenVector3df*)t)->getValue()); };
tweenLook->setEase(EEasingFunctions::EaseLinear);

CTweenManager::getInstance()->addTween(tweenUp);
CTweenManager::getInstance()->addTween(tweenLook);
setupCameraTween(tweenLook, tweenUp);
}
else if (axis == CViewpointData::Z)
{
CTweenVector3df* tweenLook = new CTweenVector3df(look, core::vector3df(0.0f, 0.0f, -1.0f), time);
CTweenVector3df* tweenUp = new CTweenVector3df(up, core::vector3df(0.0f, 1.0f, 0.0f), time);

tweenUp->OnUpdate = [camera = m_editorCamera](CTween* t) {camera->setUpVector(((CTweenVector3df*)t)->getValue()); };
tweenUp->setEase(EEasingFunctions::EaseLinear);

tweenLook->OnUpdate = [camera = m_editorCamera](CTween* t) {camera->setLookVector(((CTweenVector3df*)t)->getValue()); };
tweenLook->setEase(EEasingFunctions::EaseLinear);

CTweenManager::getInstance()->addTween(tweenUp);
CTweenManager::getInstance()->addTween(tweenLook);
setupCameraTween(tweenLook, tweenUp);
}
else if (axis == CViewpointData::ZNeg)
{
CTweenVector3df* tweenLook = new CTweenVector3df(look, core::vector3df(0.0f, 0.0f, 1.0f), time);
CTweenVector3df* tweenUp = new CTweenVector3df(up, core::vector3df(0.0f, 1.0f, 0.0f), time);

tweenUp->OnUpdate = [camera = m_editorCamera](CTween* t) {camera->setUpVector(((CTweenVector3df*)t)->getValue()); };
tweenUp->setEase(EEasingFunctions::EaseLinear);

tweenLook->OnUpdate = [camera = m_editorCamera](CTween* t) {camera->setLookVector(((CTweenVector3df*)t)->getValue()); };
tweenLook->setEase(EEasingFunctions::EaseLinear);

CTweenManager::getInstance()->addTween(tweenUp);
CTweenManager::getInstance()->addTween(tweenLook);
setupCameraTween(tweenLook, tweenUp);
}
else if (axis == CViewpointData::Y)
{
CTweenVector3df* tweenLook = new CTweenVector3df(look, core::vector3df(0.0f, -1.0f, 0.0f), time);
CTweenVector3df* tweenUp = new CTweenVector3df(up, core::vector3df(0.0f, 0.0f, 1.0f), time);

tweenUp->OnUpdate = [camera = m_editorCamera](CTween* t) {camera->setUpVector(((CTweenVector3df*)t)->getValue()); };
tweenUp->setEase(EEasingFunctions::EaseLinear);

tweenLook->OnUpdate = [camera = m_editorCamera](CTween* t) {camera->setLookVector(((CTweenVector3df*)t)->getValue()); };
tweenLook->setEase(EEasingFunctions::EaseLinear);

CTweenManager::getInstance()->addTween(tweenUp);
CTweenManager::getInstance()->addTween(tweenLook);
setupCameraTween(tweenLook, tweenUp);
}
else if (axis == CViewpointData::YNeg)
{
CTweenVector3df* tweenLook = new CTweenVector3df(look, core::vector3df(0.0f, 1.0f, 0.0f), time);
CTweenVector3df* tweenUp = new CTweenVector3df(up, core::vector3df(0.0f, 0.0f, 1.0f), time);

tweenUp->OnUpdate = [camera = m_editorCamera](CTween* t) {camera->setUpVector(((CTweenVector3df*)t)->getValue()); };
tweenUp->setEase(EEasingFunctions::EaseLinear);

tweenLook->OnUpdate = [camera = m_editorCamera](CTween* t) {camera->setLookVector(((CTweenVector3df*)t)->getValue()); };
tweenLook->setEase(EEasingFunctions::EaseLinear);

CTweenManager::getInstance()->addTween(tweenUp);
CTweenManager::getInstance()->addTween(tweenLook);
setupCameraTween(tweenLook, tweenUp);
}
}

Expand All @@ -316,6 +285,7 @@ namespace Skylicht
// draw scene
m_scene->setVisibleAllZone(true);
m_viewpointZone->setVisible(false);
m_handlesRenderer->setEnable(true);

m_renderRP->render(NULL, m_editorCamera, m_scene->getEntityManager(), viewport);

Expand All @@ -338,12 +308,14 @@ namespace Skylicht
// draw viewpoint
m_scene->setVisibleAllZone(false);
m_viewpointZone->setVisible(true);
m_handlesRenderer->setEnable(false);

m_viewpointRP->render(NULL, m_viewpointCamera, m_scene->getEntityManager(), viewport);

// disable viewpoint
m_scene->setVisibleAllZone(true);
m_viewpointZone->setVisible(false);
m_handlesRenderer->setEnable(true);

// resume gui render
getVideoDriver()->enableScissor(true);
Expand Down
6 changes: 6 additions & 0 deletions Projects/Editor/Source/Editor/Space/Scene/CSpaceScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ This file is part of the "Skylicht Engine".
#include "SkylichtEngine.h"
#include "Editor/Space/CSpace.h"
#include "EditorComponents/Viewpoint/CViewpoint.h"
#include "EditorComponents/Handles/CHandlesRenderer.h"
#include "Tween/CTweenManager.h"

namespace Skylicht
{
Expand Down Expand Up @@ -55,6 +57,8 @@ namespace Skylicht
CZone* m_viewpointZone;
CCamera* m_viewpointCamera;

CHandlesRenderer* m_handlesRenderer;

core::rectf m_viewpointRect;

public:
Expand Down Expand Up @@ -86,6 +90,8 @@ namespace Skylicht

void updateViewpoint();

void setupCameraTween(CTweenVector3df* look, CTweenVector3df* up);

void setCameraLook(CViewpointData::EAxis axis);

void initRenderPipeline(float w, float h);
Expand Down
42 changes: 42 additions & 0 deletions Projects/Editor/Source/EditorComponents/Handles/CHandlesData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
!@
MIT License
CopyRight (c) 2021 Skylicht Technology CO., LTD
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.
This file is part of the "Skylicht Engine".
https://github.com/skylicht-lab/skylicht-engine
!#
*/

#include "pch.h"
#include "CHandlesData.h"

namespace Skylicht
{
namespace Editor
{
CHandlesData::CHandlesData()
{

}

CHandlesData::~CHandlesData()
{

}
}
}
42 changes: 42 additions & 0 deletions Projects/Editor/Source/EditorComponents/Handles/CHandlesData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
!@
MIT License
CopyRight (c) 2021 Skylicht Technology CO., LTD
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.
This file is part of the "Skylicht Engine".
https://github.com/skylicht-lab/skylicht-engine
!#
*/

#pragma once

#include "Entity/IEntityData.h"
#include "LineDraw/CLineDrawData.h"

namespace Skylicht
{
namespace Editor
{
class CHandlesData : public CLineDrawData
{
public:
CHandlesData();

virtual ~CHandlesData();
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
!@
MIT License
CopyRight (c) 2021 Skylicht Technology CO., LTD
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.
This file is part of the "Skylicht Engine".
https://github.com/skylicht-lab/skylicht-engine
!#
*/

#include "pch.h"
#include "CHandlesRenderer.h"
#include "Handles/CHandles.h"

namespace Skylicht
{
namespace Editor
{
CHandlesRenderer::CHandlesRenderer()
{
m_data = new CHandlesData();
}

CHandlesRenderer::~CHandlesRenderer()
{
delete m_data;
}

void CHandlesRenderer::beginQuery()
{

}

void CHandlesRenderer::onQuery(CEntityManager* entityManager, CEntity* entity)
{

}

void CHandlesRenderer::init(CEntityManager* entityManager)
{

}

void CHandlesRenderer::update(CEntityManager* entityManager)
{
if (m_enable == false)
return;

m_data->clearBuffer();
}

void CHandlesRenderer::render(CEntityManager* entityManager)
{
if (m_enable == false)
return;

IVideoDriver* driver = getVideoDriver();
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);

// IMeshBuffer* buffer = m_data->Buffer;
// driver->setMaterial(buffer->getMaterial());
// driver->drawMeshBuffer(buffer);
}
}
}
Loading

0 comments on commit eaed344

Please sign in to comment.