feat: add spherecollidor

This commit is contained in:
2026-06-24 15:55:57 +02:00
parent 9d3d14a54d
commit 81ab2a8a4a
6 changed files with 85 additions and 25 deletions
+78 -21
View File
@@ -20,6 +20,7 @@
#include <string>
#include "imgui.h"
#include "destrum/Components/Physics/SphereCollider.h"
#include "destrum/Util/ModelDocUtils.h"
@@ -52,10 +53,10 @@ void LightKeeper::customInit()
ModelDocUtils::LogModelDocSummary(kittyModel, "kitty.glb");
const auto& kittyPrimitive = ModelDocUtils::GetFirstPrimitiveOrThrow(kittyModel, "game://kitty.glb");
testMesh = kittyPrimitive.mesh;
auto testMesh = kittyPrimitive.mesh;
testMesh.name = "Test Mesh";
testMeshID = meshCache.addMesh(gfxDevice, testMesh);
auto testMeshID = meshCache.addMesh(gfxDevice, testMesh);
spdlog::info("TestMesh uploaded with id: {}", testMeshID);
const auto testTexturePath = ModelDocUtils::PickTexturePath(
@@ -67,13 +68,13 @@ void LightKeeper::customInit()
const auto testimgID = gfxDevice.loadImageFromFile(testTexturePath);
spdlog::info("Test image loaded from '{}' with id: {}", testTexturePath.generic_string(), testimgID);
testMaterialID = materialCache.addMaterial(gfxDevice, {
.baseColor = ModelDocUtils::GetImportedBaseColor(
kittyModel, kittyPrimitive),
.diffuseTexture = testimgID,
.name = ModelDocUtils::GetImportedMaterialName(
kittyModel, kittyPrimitive, "TestMaterial"),
});
auto testMaterialID = materialCache.addMaterial(gfxDevice, {
.baseColor = ModelDocUtils::GetImportedBaseColor(
kittyModel, kittyPrimitive),
.diffuseTexture = testimgID,
.name = ModelDocUtils::GetImportedMaterialName(
kittyModel, kittyPrimitive, "TestMaterial"),
});
spdlog::info("Test material created with id: {}", testMaterialID);
camera.SetRotation(glm::radians(glm::vec2(90.f, 0.f)));
@@ -152,7 +153,7 @@ void LightKeeper::customInit()
);
ModelDocUtils::LogModelDocSummary(charModel, "capybara.fbx");
const auto &charPrimitive = ModelDocUtils::GetFirstSkinnedPrimitiveOrFirstOrThrow(
const auto& charPrimitive = ModelDocUtils::GetFirstSkinnedPrimitiveOrFirstOrThrow(
charModel,
"engine://cotw-capybara-male/source/capybara.fbx"
);
@@ -185,7 +186,8 @@ void LightKeeper::customInit()
std::string firstAnimationName;
for (auto &clip: charModel.animations) {
for (auto& clip : charModel.animations)
{
spdlog::info("Loaded animation: '{}' ({:.2f}s)", clip.name, clip.duration);
if (firstAnimationName.empty())
@@ -194,7 +196,8 @@ void LightKeeper::customInit()
animator->addClip(std::make_shared<SkeletalAnimation>(std::move(clip)));
}
if (!firstAnimationName.empty()) {
if (!firstAnimationName.empty())
{
spdlog::info("Playing animation: '{}'", firstAnimationName);
animator->play(firstAnimationName);
}
@@ -275,11 +278,11 @@ void LightKeeper::customInit()
characterOptions
);
const auto &charPrimitive =
ModelDocUtils::GetFirstSkinnedPrimitiveOrFirstOrThrow(
charModel,
"engine://characterMedium.fbx"
);
const auto& charPrimitive =
ModelDocUtils::GetFirstSkinnedPrimitiveOrFirstOrThrow(
charModel,
"engine://characterMedium.fbx"
);
const auto charMeshID = meshCache.addMesh(gfxDevice, charPrimitive.mesh);
@@ -312,12 +315,14 @@ void LightKeeper::customInit()
charModel.skeleton
);
for (auto &clip: runClips) {
for (auto& clip : runClips)
{
spdlog::info("Loaded animation: '{}' ({:.2f}s)", clip.name, clip.duration);
animator->addClip(std::make_shared<SkeletalAnimation>(std::move(clip)));
}
if (!runClips.empty()) {
if (!runClips.empty())
{
animator->play("Root|Run");
}
@@ -379,7 +384,7 @@ void LightKeeper::customInit()
//
// for (int x = 0; x < cubeCount; x++)
// {
// for (int y = 0; y < cubeCount; y++)
// for (int y = 0; y < 3; y++)
// {
// for (int z = 0; z < cubeCount; z++)
// {
@@ -394,7 +399,7 @@ void LightKeeper::customInit()
//
// cube->GetTransform().SetWorldPosition(glm::vec3(
// (x - cubeCount / 2.0f) * spacing,
// y * spacing + 5,
// y * spacing + 0,
// (z - cubeCount / 2.0f) * spacing
// ));
//
@@ -405,6 +410,37 @@ void LightKeeper::customInit()
// }
// }
// }
{
auto sphereModel = ModelDoc::LoadModel(
AssetFS::GetInstance().GetFullPath("engine://sphere.fbx").generic_string(),
staticModelOptions
);
ModelDocUtils::LogModelDocSummary(sphereModel, "sphere.fbx");
const auto& spherePrimitive = ModelDocUtils::GetFirstPrimitiveOrThrow(sphereModel, "game://sphere.fbx");
const auto sphereTexturePath = ModelDocUtils::PickTexturePath(
sphereModel,
spherePrimitive,
AssetFS::GetInstance().GetFullPath("game://238882.png")
);
const auto sphereTextureID = gfxDevice.loadImageFromFile(sphereTexturePath);
sphereMaterial = materialCache.addMaterial(gfxDevice, {
.baseColor = ModelDocUtils::GetImportedBaseColor(planeModel, planePrimitive),
.textureFilteringMode =TextureFilteringMode::Anisotropic,
.diffuseTexture = sphereTextureID,
.name = ModelDocUtils::GetImportedMaterialName(
planeModel, planePrimitive,
"GroundPlaneMaterial"),
});
sphereMesh = meshCache.addMesh(gfxDevice, spherePrimitive.mesh);
}
}
void LightKeeper::customUpdate(float dt)
@@ -416,6 +452,27 @@ void LightKeeper::customUpdate(float dt)
{
renderer.setRenderWireframe(!renderer.getRenderWireframe());
}
ImGui::Begin("Test");
if (ImGui::Button("SPawn ball"))
{
auto sphere = std::make_shared<GameObject>("Sphere");
sphere->AddComponent<SphereCollider>(1.5f);
auto rb = sphere->AddComponent<Rigidbody>();
rb->SetMass(1000);
auto meshRenderComp = sphere->AddComponent<MeshRendererComponent>();
meshRenderComp->SetMaterialID(sphereMaterial);
meshRenderComp->SetMeshID(sphereMesh);
sphere->GetTransform().SetWorldPosition(0, 100, 0);
sphere->GetTransform().SetWorldScale(glm::vec3{0.015f});
SceneManager::GetInstance().GetCurrentScene().Add(sphere);
SceneManager::GetInstance().GetCurrentScene().GetPhysics().RegisterGameObject(*sphere);
}
ImGui::End();
}
void LightKeeper::customDraw()