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

179 lines
5.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"
#include "Graphics/Graphics.h"
#include "Asset/MeshAsset.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"
2022-01-12 14:40:26 +01:00
#include "Scene/Components/MyComponent.h"
#include "Scene/Components/MyOtherComponent.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)
2021-11-13 19:28:18 +01:00
: View(graphics, owner, createInfo, "SceneView")
2021-11-01 20:25:16 +01: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
{
2021-11-01 20:25:16 +01:00
scene = new Scene(graphics);
scene->addActor(activeCamera);
2021-12-27 15:04:53 +01:00
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Body_Diffuse.png");
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Body_Lightmap.png");
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Face_Diffuse.png");
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Hair_Diffuse.png");
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Sword_Ayaka_Tex_Hair_Lightmap.png");
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Avatar_Girl_Tex_FaceLightmap.png");
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ayaka\\Ayaka.fbx");
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Ely\\Ely.fbx");
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Cube\\cube.obj");
AssetRegistry::importFile("C:\\Users\\Dynamitos\\TestSeeleProject\\Assets\\Plane\\plane.fbx");
2022-01-12 14:40:26 +01:00
PPrimitiveComponent ayaka = new PrimitiveComponent(AssetRegistry::findMesh("Ayaka"));
2022-03-19 22:45:30 +01:00
ayaka->setRelativeLocation(Vector(0, 0, 0));
ayaka->setRelativeScale(Vector(10, 10, 10));
2022-02-24 22:38:26 +01:00
//scene->addPrimitiveComponent(ayaka);
2021-11-01 20:25:16 +01:00
PPrimitiveComponent plane = new PrimitiveComponent(AssetRegistry::findMesh("plane"));
2022-03-19 22:45:30 +01:00
plane->setRelativeScale(Vector(100, 100, 100));
2021-11-01 20:25:16 +01:00
scene->addPrimitiveComponent(plane);
2022-01-12 14:40:26 +01:00
2022-03-19 22:45:30 +01:00
for(uint32 i = 0; i < 100000; ++i)
2022-02-14 16:29:26 +01:00
{
PMyComponent myComp = new MyComponent();
PMyOtherComponent myOtherComp = new MyOtherComponent();
PActor actor = new Actor();
actor->setRootComponent(myComp);
myComp->addChildComponent(myOtherComp);
scene->addActor(actor);
}
2022-01-12 14:40:26 +01:00
scene->start();
2021-12-27 15:04:53 +01:00
2021-11-01 20:25:16 +01:00
PRenderGraphResources resources = new RenderGraphResources();
depthPrepass.setResources(resources);
lightCullingPass.setResources(resources);
basePass.setResources(resources);
2021-10-15 23:12:29 +02:00
2021-11-01 20:25:16 +01:00
depthPrepass.publishOutputs();
lightCullingPass.publishOutputs();
basePass.publishOutputs();
2021-10-15 23:12:29 +02:00
2021-11-01 20:25:16 +01:00
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
2022-01-12 14:40:26 +01:00
Job SceneView::beginUpdate()
2021-01-19 15:30:00 +01:00
{
2022-01-12 14:40:26 +01:00
co_await scene->beginUpdate(Gfx::currentFrameDelta);
co_return;
2021-01-19 15:30:00 +01:00
}
2022-01-12 14:40:26 +01:00
Job SceneView::update()
2021-10-01 19:55:04 +02:00
{
2022-01-12 14:40:26 +01:00
co_await scene->commitUpdate();
co_return;
2021-10-01 19:55:04 +02:00
}
2021-10-15 23:12:29 +02:00
void SceneView::commitUpdate()
2021-10-01 19:55:04 +02:00
{
2021-11-01 20:25:16 +01:00
depthPrepassData.staticDrawList = scene->getStaticMeshes();
lightCullingPassData.lightEnv = scene->getLightBuffer();
basePassData.staticDrawList = scene->getStaticMeshes();
2021-10-01 19:55:04 +02:00
}
void SceneView::prepareRender()
{
2021-11-01 20:25:16 +01:00
depthPrepass.updateViewFrame(depthPrepassData);
lightCullingPass.updateViewFrame(lightCullingPassData);
basePass.updateViewFrame(basePassData);
2021-10-01 19:55:04 +02:00
}
2021-12-02 13:00:03 +01:00
MainJob SceneView::render()
2021-10-01 19:55:04 +02:00
{
2022-03-19 22:45:30 +01:00
return depthPrepass.beginFrame()
.then(lightCullingPass.beginFrame())
.then(basePass.beginFrame())
2022-02-24 22:38:26 +01:00
.then(depthPrepass.render())
.then(lightCullingPass.render())
.then(basePass.render())
2022-03-19 22:45:30 +01:00
.then(depthPrepass.endFrame())
.then(lightCullingPass.endFrame())
.then(basePass.endFrame());
2021-10-01 19:55:04 +02:00
}
2022-03-19 22:45:30 +01:00
static float cameraSpeed = 1;
void SceneView::keyCallback(KeyCode code, InputAction action, KeyModifier mod)
{
2022-03-19 22:45:30 +01:00
if((KeyModifierFlags)mod & (KeyModifierFlags)KeyModifier::MOD_SHIFT)
{
cameraSpeed = 5;
}
else
{
cameraSpeed = 1;
}
2021-11-01 20:25:16 +01:00
if(action != InputAction::RELEASE)
{
if(code == KeyCode::KEY_W)
{
2022-03-19 22:45:30 +01:00
activeCamera->getCameraComponent()->moveX(1);
2021-11-01 20:25:16 +01:00
}
if(code == KeyCode::KEY_S)
{
2022-03-19 22:45:30 +01:00
activeCamera->getCameraComponent()->moveX(-1);
}
if(code == KeyCode::KEY_A)
{
activeCamera->getCameraComponent()->moveY(1);
}
if(code == KeyCode::KEY_D)
{
activeCamera->getCameraComponent()->moveY(-1);
2021-11-01 20:25:16 +01:00
}
}
}
2021-01-19 15:30:00 +01:00
static bool mouseDown = false;
void SceneView::mouseMoveCallback(double xPos, double yPos)
{
2021-11-01 20:25:16 +01:00
static double prevXPos = 0.0f, prevYPos = 0.0f;
double deltaX = prevXPos - xPos;
double deltaY = prevYPos - yPos;
prevXPos = xPos;
prevYPos = yPos;
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
{
2022-03-19 22:45:30 +01:00
if(button == MouseButton::MOUSE_BUTTON_2 && action != InputAction::RELEASE)
2021-11-01 20:25:16 +01:00
{
mouseDown = true;
}
else
{
mouseDown = false;
}
2021-01-19 15:30:00 +01:00
}
2021-04-01 16:40:14 +02:00
void SceneView::scrollCallback(double, double yOffset)
2021-01-19 15:30:00 +01:00
{
2021-11-01 20:25:16 +01:00
activeCamera->getCameraComponent()->mouseScroll(yOffset);
2021-01-19 15:30:00 +01:00
}
2021-04-01 16:40:14 +02:00
void SceneView::fileCallback(int, const char**)
2021-01-19 15:30:00 +01:00
{
2021-11-01 20:25:16 +01:00
2020-10-29 02:22:01 +01:00
}