feat: Add Camera component / Add cooked model and texture loading
This commit is contained in:
@@ -72,10 +72,6 @@ add_custom_target(_internal_clean_game_assets
|
||||
)
|
||||
|
||||
add_custom_target(_internal_cook_game_assets
|
||||
COMMAND TheChef
|
||||
--input "${ASSETS_SRC_DIR}"
|
||||
--output "${ASSETS_RUNTIME_DIR}"
|
||||
--clean
|
||||
COMMAND TheChef
|
||||
--input "${ASSETS_SRC_DIR}"
|
||||
--output "${ASSETS_RUNTIME_DIR}"
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "destrum/Graphics/Resources/Cubemap.h"
|
||||
#include "destrum/ObjectModel/GameObject.h"
|
||||
|
||||
class CameraComponent;
|
||||
class FirstPersonController;
|
||||
class LightKeeper final : public App {
|
||||
public:
|
||||
@@ -30,6 +31,7 @@ private:
|
||||
void loadScene();
|
||||
void createEmptyScene();
|
||||
void submitBoxColliderDebugLines();
|
||||
[[nodiscard]] CameraComponent* getSceneCamera() const;
|
||||
|
||||
Camera camera{glm::vec3(0.f, 0.f, -5.f), glm::vec3(0, 1, 0)};
|
||||
|
||||
@@ -51,6 +53,7 @@ private:
|
||||
bool renderQuads{true};
|
||||
bool renderDebugLines{true};
|
||||
bool showTestWindow{true};
|
||||
bool useFreeCamera{false};
|
||||
};
|
||||
|
||||
#endif //LIGHTKEEPER_H
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "destrum/Util/ModelDoc.h"
|
||||
#include "destrum/Components/Animator.h"
|
||||
#include "destrum/Components/LightComponent.h"
|
||||
#include "destrum/Components/CameraComponent.h"
|
||||
#include <components/FirstPersonController.h>
|
||||
#include <components/TriggerLoggerComponent.h>
|
||||
|
||||
@@ -109,10 +110,7 @@ void LightKeeper::customInit()
|
||||
const auto planeObj = scene.CreateGameObject("GroundPlane");
|
||||
const auto planeMeshComp = planeObj->AddComponent<MeshRendererComponent>();
|
||||
|
||||
auto planeModel = ModelDoc::LoadModel(
|
||||
AssetFS::GetInstance().GetFullPath("game://plane.glb").generic_string(),
|
||||
staticModelOptions
|
||||
);
|
||||
auto planeModel = AssetManager::GetInstance().LoadModel("game://plane.glb", staticModelOptions);
|
||||
ModelDocUtils::LogModelDocSummary(planeModel, "plane.glb");
|
||||
|
||||
const auto& planePrimitive = ModelDocUtils::GetFirstPrimitiveOrThrow(planeModel, "game://plane.glb");
|
||||
@@ -153,8 +151,8 @@ void LightKeeper::customInit()
|
||||
characterModelOptions.loadSkeleton = true;
|
||||
characterModelOptions.loadAnimations = true;
|
||||
|
||||
auto charModel = ModelDoc::LoadModel(
|
||||
AssetFS::GetInstance().GetFullPath("engine://cotw-capybara-male/source/capybara.fbx").generic_string(),
|
||||
auto charModel = AssetManager::GetInstance().LoadModel(
|
||||
"engine://cotw-capybara-male/source/capybara.fbx",
|
||||
characterModelOptions
|
||||
);
|
||||
ModelDocUtils::LogModelDocSummary(charModel, "capybara.fbx");
|
||||
@@ -521,7 +519,7 @@ void LightKeeper::customUpdate(float dt)
|
||||
camera.CalculateViewMatrix();
|
||||
camera.CalculateProjectionMatrix();
|
||||
}
|
||||
else
|
||||
else if (getSceneCamera() == nullptr)
|
||||
{
|
||||
camera.Update(dt);
|
||||
}
|
||||
@@ -563,6 +561,15 @@ void LightKeeper::customUpdate(float dt)
|
||||
|
||||
}
|
||||
|
||||
CameraComponent* LightKeeper::getSceneCamera() const
|
||||
{
|
||||
const auto& activeScenes = SceneManager::GetInstance().GetActiveScenes();
|
||||
if (useFreeCamera || activeScenes.empty()) {
|
||||
return nullptr;
|
||||
}
|
||||
return activeScenes.front()->GetCurrentCamera();
|
||||
}
|
||||
|
||||
void LightKeeper::customWindowsMenu()
|
||||
{
|
||||
ImGui::Separator();
|
||||
@@ -616,6 +623,27 @@ void LightKeeper::drawDebugMenuBar()
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
if (ImGui::BeginMenu("Camera")) {
|
||||
ImGui::MenuItem("Free Camera", nullptr, &useFreeCamera);
|
||||
ImGui::Separator();
|
||||
|
||||
auto& scene = SceneManager::GetInstance().GetCurrentScene();
|
||||
const auto cameras = scene.GetCameras();
|
||||
if (cameras.empty()) {
|
||||
ImGui::TextDisabled("No cameras in the scene");
|
||||
}
|
||||
for (CameraComponent* sceneCamera : cameras) {
|
||||
const GameObject* owner = sceneCamera->GetGameObject();
|
||||
ImGui::PushID(owner);
|
||||
if (ImGui::MenuItem(owner->GetName().c_str(), nullptr, !useFreeCamera && sceneCamera->IsCurrent())) {
|
||||
scene.SetCurrentCamera(sceneCamera);
|
||||
useFreeCamera = false;
|
||||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
ImGui::EndMenu();
|
||||
}
|
||||
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
|
||||
@@ -751,11 +779,14 @@ void LightKeeper::customDraw()
|
||||
glm::vec2{100.0f, 100.0f}, glm::vec2{200.0f, 200.0f}, 0.0f,
|
||||
glm::vec4{1.0f}, texID);
|
||||
|
||||
CameraComponent* sceneCamera = getSceneCamera();
|
||||
Camera& viewCamera = sceneCamera != nullptr ? sceneCamera->GetCamera(camera.GetAspectRatio()) : camera;
|
||||
|
||||
const RenderContext ctx{
|
||||
.renderer = renderer,
|
||||
.camera = camera,
|
||||
.camera = viewCamera,
|
||||
.sceneData = {
|
||||
.camera = camera,
|
||||
.camera = viewCamera,
|
||||
.ambientColor = glm::vec3(0.1f),
|
||||
.ambientIntensity = 0.5f,
|
||||
.fogColor = glm::vec3(0.5f),
|
||||
@@ -769,8 +800,8 @@ void LightKeeper::customDraw()
|
||||
const auto& drawImage = renderer.getDrawImage();
|
||||
|
||||
renderer.draw(
|
||||
cmd, gfxDevice, camera, GameRenderer::SceneData{
|
||||
camera, glm::vec3(0.1f), 0.5f, glm::vec3(0.5f), 0.01f
|
||||
cmd, gfxDevice, viewCamera, GameRenderer::SceneData{
|
||||
viewCamera, glm::vec3(0.1f), 0.5f, glm::vec3(0.5f), 0.01f
|
||||
});
|
||||
|
||||
gfxDevice.endFrame(
|
||||
|
||||
Reference in New Issue
Block a user