feat: Add Camera component / Add cooked model and texture loading

This commit is contained in:
2026-10-13 00:29:17 +02:00
parent fa98bf08e8
commit ce55f75ac3
26 changed files with 930 additions and 194 deletions
+42 -11
View File
@@ -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(