Files
Seele/src/Engine/Window/SceneView.cpp
T

139 lines
3.7 KiB
C++
Raw Normal View History

2020-03-05 11:43:38 +01:00
#include "SceneView.h"
2020-06-08 01:44:47 +02:00
#include "Scene/Scene.h"
2020-05-05 01:51:13 +02:00
#include "Window.h"
2021-10-15 23:12:29 +02:00
#include "Asset/AssetRegistry.h"
2020-10-03 11:00:10 +02:00
#include "Scene/Actor/CameraActor.h"
2020-10-29 02:22:01 +01:00
#include "Scene/Components/CameraComponent.h"
2020-03-05 11:43:38 +01:00
using namespace Seele;
2020-05-05 01:51:13 +02:00
Seele::SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo &createInfo)
2020-04-15 02:03:56 +02:00
: View(graphics, owner, createInfo)
2021-10-01 19:55:04 +02:00
, activeCamera(new CameraActor())
, depthPrepass(DepthPrepass(graphics, viewport, activeCamera))
, lightCullingPass(LightCullingPass(graphics, viewport, activeCamera))
, basePass(BasePass(graphics, viewport, activeCamera))
2020-03-05 11:43:38 +01:00
{
2020-09-19 14:36:50 +02:00
scene = new Scene(graphics);
2020-10-29 02:22:01 +01:00
scene->addActor(activeCamera);
2021-10-15 23:12:29 +02:00
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Body_Diffuse.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Body_Lightmap.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Face_Diffuse.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Hair_Diffuse.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Hair_Lightmap.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Tex_FaceLightmap.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Ayaka.fbx");
PPrimitiveComponent ayaka = new PrimitiveComponent(AssetRegistry::findMesh("Ayaka"));
ayaka->addWorldTranslation(Vector(0, 0, 100));
ayaka->setWorldScale(Vector(0.1f, 0.1f, 0.1f));
scene->addPrimitiveComponent(ayaka);
PRenderGraphResources resources = new RenderGraphResources();
depthPrepass.setResources(resources);
lightCullingPass.setResources(resources);
basePass.setResources(resources);
depthPrepass.publishOutputs();
lightCullingPass.publishOutputs();
basePass.publishOutputs();
depthPrepass.createRenderPass();
lightCullingPass.createRenderPass();
basePass.createRenderPass();
2020-03-05 11:43:38 +01:00
}
Seele::SceneView::~SceneView()
{
}
2020-10-29 02:22:01 +01:00
2021-10-15 23:12:29 +02:00
void SceneView::beginUpdate()
2021-01-19 15:30:00 +01:00
{
2021-10-15 23:12:29 +02:00
View::beginUpdate();
2021-09-29 22:12:56 +02:00
scene->tick(Gfx::currentFrameDelta);
2021-01-19 15:30:00 +01:00
}
2021-10-01 19:55:04 +02:00
void SceneView::update()
{
}
2021-10-15 23:12:29 +02:00
void SceneView::commitUpdate()
2021-10-01 19:55:04 +02:00
{
depthPrepassData.staticDrawList = scene->getStaticMeshes();
lightCullingPassData.lightEnv = scene->getLightBuffer();
basePassData.staticDrawList = scene->getStaticMeshes();
}
void SceneView::prepareRender()
{
depthPrepass.updateViewFrame(depthPrepassData);
lightCullingPass.updateViewFrame(lightCullingPassData);
basePass.updateViewFrame(basePassData);
}
void SceneView::render()
{
2021-10-15 23:12:29 +02:00
depthPrepass.beginFrame();
lightCullingPass.beginFrame();
basePass.beginFrame();
2021-10-01 19:55:04 +02:00
depthPrepass.render();
lightCullingPass.render();
basePass.render();
2021-10-15 23:12:29 +02:00
depthPrepass.endFrame();
lightCullingPass.endFrame();
basePass.endFrame();
2021-10-01 19:55:04 +02:00
}
2021-04-01 16:40:14 +02:00
void SceneView::keyCallback(KeyCode code, InputAction action, KeyModifier)
{
2021-01-19 15:30:00 +01:00
if(action != InputAction::RELEASE)
{
if(code == KeyCode::KEY_W)
{
activeCamera->getCameraComponent()->moveOrigin(1);
}
if(code == KeyCode::KEY_S)
{
activeCamera->getCameraComponent()->moveOrigin(-1);
}
}
}
2021-01-19 15:30:00 +01:00
static bool mouseDown = false;
void SceneView::mouseMoveCallback(double xPos, double yPos)
{
static double prevXPos = 0.0f, prevYPos = 0.0f;
2021-01-19 15:30:00 +01:00
double deltaX = prevXPos - xPos;
double deltaY = prevYPos - yPos;
prevXPos = xPos;
prevYPos = yPos;
2021-01-19 15:30:00 +01:00
if(mouseDown)
{
activeCamera->getCameraComponent()->mouseMove((float)deltaX, (float)deltaY);
}
}
2021-04-01 16:40:14 +02:00
void SceneView::mouseButtonCallback(MouseButton button, InputAction action, KeyModifier)
2020-10-29 02:22:01 +01:00
{
2021-01-19 15:30:00 +01:00
if(button == MouseButton::MOUSE_BUTTON_1 && action != InputAction::RELEASE)
{
mouseDown = true;
}
else
{
mouseDown = false;
}
}
2021-04-01 16:40:14 +02:00
void SceneView::scrollCallback(double, double yOffset)
2021-01-19 15:30:00 +01:00
{
activeCamera->getCameraComponent()->mouseScroll(yOffset);
}
2021-04-01 16:40:14 +02:00
void SceneView::fileCallback(int, const char**)
2021-01-19 15:30:00 +01:00
{
2020-10-29 02:22:01 +01:00
}