diff --git a/destrum/CMakeLists.txt b/destrum/CMakeLists.txt index c6136b6..85b2de0 100644 --- a/destrum/CMakeLists.txt +++ b/destrum/CMakeLists.txt @@ -12,6 +12,7 @@ set(SRC_FILES "src/Components/Physics/Rigidbody.cpp" "src/Components/Physics/BoxCollider.cpp" + "src/Components/Physics/SphereCollider.cpp" "src/Graphics/BindlessSetManager.cpp" "src/Graphics/Camera.cpp" diff --git a/destrum/assets_src/sphere.fbx b/destrum/assets_src/sphere.fbx new file mode 100644 index 0000000..3a398b7 Binary files /dev/null and b/destrum/assets_src/sphere.fbx differ diff --git a/destrum/include/destrum/Components/Physics/SphereCollider.h b/destrum/include/destrum/Components/Physics/SphereCollider.h index 7831fb4..cf511e5 100644 --- a/destrum/include/destrum/Components/Physics/SphereCollider.h +++ b/destrum/include/destrum/Components/Physics/SphereCollider.h @@ -2,7 +2,7 @@ #include -#include +#include class SphereCollider final : public Collider { public: @@ -10,6 +10,8 @@ public: : Collider(owner) , m_Radius(radius) {} + void Update() override {} + [[nodiscard]] PhysicsShapeDesc BuildPhysicsShape() const override { return PhysicsShapeDesc::Sphere(m_Radius, m_CenterOffset, m_IsTrigger); } diff --git a/destrum/src/Components/Physics/SphereCollider.cpp b/destrum/src/Components/Physics/SphereCollider.cpp new file mode 100644 index 0000000..c55ff27 --- /dev/null +++ b/destrum/src/Components/Physics/SphereCollider.cpp @@ -0,0 +1 @@ +#include \ No newline at end of file diff --git a/lightkeeper/include/Lightkeeper.h b/lightkeeper/include/Lightkeeper.h index dbb88db..871634a 100644 --- a/lightkeeper/include/Lightkeeper.h +++ b/lightkeeper/include/Lightkeeper.h @@ -25,9 +25,8 @@ private: Camera camera{glm::vec3(0.f, 0.f, -5.f), glm::vec3(0, 1, 0)}; - CPUMesh testMesh{}; - MeshID testMeshID; - MaterialID testMaterialID; + MeshID sphereMesh; + MaterialID sphereMaterial; std::unique_ptr skyboxCubemap; diff --git a/lightkeeper/src/Lightkeeper.cpp b/lightkeeper/src/Lightkeeper.cpp index 0d9271f..aec3901 100644 --- a/lightkeeper/src/Lightkeeper.cpp +++ b/lightkeeper/src/Lightkeeper.cpp @@ -20,6 +20,7 @@ #include #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(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(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("Sphere"); + sphere->AddComponent(1.5f); + auto rb = sphere->AddComponent(); + rb->SetMass(1000); + + auto meshRenderComp = sphere->AddComponent(); + 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()