diff --git a/Editor/CMakeLists.txt b/Editor/CMakeLists.txt index b0cb8b14e..2fea4ddf1 100644 --- a/Editor/CMakeLists.txt +++ b/Editor/CMakeLists.txt @@ -31,6 +31,7 @@ set (SOURCE_FILES WeatherWindow.cpp RigidBodyWindow.cpp SoftBodyWindow.cpp + ColliderWindow.cpp OptionsWindow.cpp ComponentsWindow.cpp TerrainGenerator.cpp diff --git a/Editor/ColliderWindow.cpp b/Editor/ColliderWindow.cpp new file mode 100644 index 000000000..beb108044 --- /dev/null +++ b/Editor/ColliderWindow.cpp @@ -0,0 +1,179 @@ +#include "stdafx.h" +#include "ColliderWindow.h" +#include "Editor.h" + +using namespace wi::ecs; +using namespace wi::scene; + +void ColliderWindow::Create(EditorComponent* _editor) +{ + editor = _editor; + + wi::gui::Window::Create(ICON_COLLIDER " Collider", wi::gui::Window::WindowControls::COLLAPSE | wi::gui::Window::WindowControls::CLOSE); + SetSize(XMFLOAT2(670, 260)); + + closeButton.SetTooltip("Delete ColliderComponent"); + OnClose([=](wi::gui::EventArgs args) { + + wi::Archive& archive = editor->AdvanceHistory(); + archive << EditorComponent::HISTORYOP_COMPONENT_DATA; + editor->RecordEntity(archive, entity); + + editor->GetCurrentScene().colliders.Remove(entity); + + editor->RecordEntity(archive, entity); + + editor->optionsWnd.RefreshEntityTree(); + }); + + float x = 60; + float y = 4; + float hei = 20; + float step = hei + 2; + float wid = 220; + + shapeCombo.Create("Shape: "); + shapeCombo.SetSize(XMFLOAT2(wid, hei)); + shapeCombo.SetPos(XMFLOAT2(x, y)); + shapeCombo.AddItem("Sphere", (uint64_t)ColliderComponent::Shape::Sphere); + shapeCombo.AddItem("Capsule", (uint64_t)ColliderComponent::Shape::Capsule); + shapeCombo.OnSelect([=](wi::gui::EventArgs args) { + wi::scene::Scene& scene = editor->GetCurrentScene(); + ColliderComponent* collider = scene.colliders.GetComponent(entity); + if (collider == nullptr) + return; + + collider->shape = (ColliderComponent::Shape)args.userdata; + }); + AddWidget(&shapeCombo); + + radiusSlider.Create(0, 10, 0, 100000, "Radius: "); + radiusSlider.SetSize(XMFLOAT2(wid, hei)); + radiusSlider.SetPos(XMFLOAT2(x, y += step)); + radiusSlider.OnSlide([&](wi::gui::EventArgs args) { + wi::scene::Scene& scene = editor->GetCurrentScene(); + ColliderComponent* collider = scene.colliders.GetComponent(entity); + if (collider == nullptr) + return; + + collider->radius = args.fValue; + }); + AddWidget(&radiusSlider); + + + y += step; + + + offsetX.Create(-10, 10, 0, 10000, "Offset X: "); + offsetX.SetSize(XMFLOAT2(wid, hei)); + offsetX.SetPos(XMFLOAT2(x, y += step)); + offsetX.OnSlide([=](wi::gui::EventArgs args) { + wi::scene::Scene& scene = editor->GetCurrentScene(); + ColliderComponent* collider = scene.colliders.GetComponent(entity); + if (collider == nullptr) + return; + + collider->offset.x = args.fValue; + }); + AddWidget(&offsetX); + + offsetY.Create(-10, 10, 0, 10000, "Offset Y: "); + offsetY.SetSize(XMFLOAT2(wid, hei)); + offsetY.SetPos(XMFLOAT2(x, y += step)); + offsetY.OnSlide([=](wi::gui::EventArgs args) { + wi::scene::Scene& scene = editor->GetCurrentScene(); + ColliderComponent* collider = scene.colliders.GetComponent(entity); + if (collider == nullptr) + return; + + collider->offset.y = args.fValue; + }); + AddWidget(&offsetY); + + offsetZ.Create(-10, 10, 0, 10000, "Offset Z: "); + offsetZ.SetSize(XMFLOAT2(wid, hei)); + offsetZ.SetPos(XMFLOAT2(x, y += step)); + offsetZ.OnSlide([=](wi::gui::EventArgs args) { + wi::scene::Scene& scene = editor->GetCurrentScene(); + ColliderComponent* collider = scene.colliders.GetComponent(entity); + if (collider == nullptr) + return; + + collider->offset.z = args.fValue; + }); + AddWidget(&offsetZ); + + + y += step; + + + tailX.Create(-10, 10, 0, 10000, "Tail X: "); + tailX.SetSize(XMFLOAT2(wid, hei)); + tailX.SetPos(XMFLOAT2(x, y += step)); + tailX.OnSlide([=](wi::gui::EventArgs args) { + wi::scene::Scene& scene = editor->GetCurrentScene(); + ColliderComponent* collider = scene.colliders.GetComponent(entity); + if (collider == nullptr) + return; + + collider->tail.x = args.fValue; + }); + AddWidget(&tailX); + + tailY.Create(-10, 10, 0, 10000, "Tail Y: "); + tailY.SetSize(XMFLOAT2(wid, hei)); + tailY.SetPos(XMFLOAT2(x, y += step)); + tailY.OnSlide([=](wi::gui::EventArgs args) { + wi::scene::Scene& scene = editor->GetCurrentScene(); + ColliderComponent* collider = scene.colliders.GetComponent(entity); + if (collider == nullptr) + return; + + collider->tail.y = args.fValue; + }); + AddWidget(&tailY); + + tailZ.Create(-10, 10, 0, 10000, "Tail Z: "); + tailZ.SetSize(XMFLOAT2(wid, hei)); + tailZ.SetPos(XMFLOAT2(x, y += step)); + tailZ.OnSlide([=](wi::gui::EventArgs args) { + wi::scene::Scene& scene = editor->GetCurrentScene(); + ColliderComponent* collider = scene.colliders.GetComponent(entity); + if (collider == nullptr) + return; + + collider->tail.z = args.fValue; + }); + AddWidget(&tailZ); + + + SetMinimized(true); + SetVisible(false); + + SetEntity(INVALID_ENTITY); +} + + +void ColliderWindow::SetEntity(Entity entity) +{ + if (this->entity == entity) + return; + + this->entity = entity; + + Scene& scene = editor->GetCurrentScene(); + + const ColliderComponent* collider = scene.colliders.GetComponent(entity); + + if (collider != nullptr) + { + shapeCombo.SetSelectedByUserdataWithoutCallback((uint64_t)collider->shape); + radiusSlider.SetValue(collider->radius); + offsetX.SetValue(collider->offset.x); + offsetY.SetValue(collider->offset.y); + offsetZ.SetValue(collider->offset.z); + tailX.SetValue(collider->tail.x); + tailY.SetValue(collider->tail.y); + tailZ.SetValue(collider->tail.z); + } +} diff --git a/Editor/ColliderWindow.h b/Editor/ColliderWindow.h new file mode 100644 index 000000000..c04f79da2 --- /dev/null +++ b/Editor/ColliderWindow.h @@ -0,0 +1,24 @@ +#pragma once +#include "WickedEngine.h" + +class EditorComponent; + +class ColliderWindow : public wi::gui::Window +{ +public: + void Create(EditorComponent* editor); + + EditorComponent* editor = nullptr; + wi::ecs::Entity entity = wi::ecs::INVALID_ENTITY; + void SetEntity(wi::ecs::Entity entity); + + wi::gui::ComboBox shapeCombo; + wi::gui::Slider radiusSlider; + wi::gui::Slider offsetX; + wi::gui::Slider offsetY; + wi::gui::Slider offsetZ; + wi::gui::Slider tailX; + wi::gui::Slider tailY; + wi::gui::Slider tailZ; +}; + diff --git a/Editor/ComponentsWindow.cpp b/Editor/ComponentsWindow.cpp index d332c968b..2f9b6985f 100644 --- a/Editor/ComponentsWindow.cpp +++ b/Editor/ComponentsWindow.cpp @@ -35,6 +35,7 @@ void ComponentsWindow::Create(EditorComponent* _editor) scriptWnd.Create(editor); rigidWnd.Create(editor); softWnd.Create(editor); + colliderWnd.Create(editor); newComponentCombo.Create("Add: "); @@ -61,6 +62,7 @@ void ComponentsWindow::Create(EditorComponent* _editor) newComponentCombo.AddItem("Script " ICON_SCRIPT, 15); newComponentCombo.AddItem("Rigid Body " ICON_RIGIDBODY, 16); newComponentCombo.AddItem("Soft Body " ICON_SOFTBODY, 17); + newComponentCombo.AddItem("Collider " ICON_COLLIDER, 18); newComponentCombo.OnSelect([=](wi::gui::EventArgs args) { newComponentCombo.SetSelectedWithoutCallback(-1); if (editor->translator.selected.empty()) @@ -148,6 +150,10 @@ void ComponentsWindow::Create(EditorComponent* _editor) if (scene.softbodies.Contains(entity)) return; break; + case 18: + if (scene.colliders.Contains(entity)) + return; + break; default: return; } @@ -235,6 +241,9 @@ void ComponentsWindow::Create(EditorComponent* _editor) case 17: scene.softbodies.Create(entity); break; + case 18: + scene.colliders.Create(entity); + break; default: break; } @@ -267,6 +276,7 @@ void ComponentsWindow::Create(EditorComponent* _editor) AddWidget(&scriptWnd); AddWidget(&rigidWnd); AddWidget(&softWnd); + AddWidget(&colliderWnd); materialWnd.SetVisible(false); weatherWnd.SetVisible(false); @@ -288,6 +298,7 @@ void ComponentsWindow::Create(EditorComponent* _editor) scriptWnd.SetVisible(false); rigidWnd.SetVisible(false); softWnd.SetVisible(false); + colliderWnd.SetVisible(false); SetSize(editor->optionsWnd.GetSize()); @@ -580,6 +591,19 @@ void ComponentsWindow::ResizeLayout() weatherWnd.SetVisible(false); } + if (scene.colliders.Contains(colliderWnd.entity)) + { + colliderWnd.SetVisible(true); + colliderWnd.SetPos(pos); + colliderWnd.SetSize(XMFLOAT2(width, colliderWnd.GetScale().y)); + pos.y += colliderWnd.GetSize().y; + pos.y += padding; + } + else + { + colliderWnd.SetVisible(false); + } + if (scene.scripts.Contains(scriptWnd.entity)) { scriptWnd.SetVisible(true); diff --git a/Editor/ComponentsWindow.h b/Editor/ComponentsWindow.h index 8d3278704..e95fe53be 100644 --- a/Editor/ComponentsWindow.h +++ b/Editor/ComponentsWindow.h @@ -20,6 +20,7 @@ #include "ScriptWindow.h" #include "RigidBodyWindow.h" #include "SoftBodyWindow.h" +#include "ColliderWindow.h" class EditorComponent; @@ -53,4 +54,5 @@ public: ScriptWindow scriptWnd; RigidBodyWindow rigidWnd; SoftBodyWindow softWnd; + ColliderWindow colliderWnd; }; diff --git a/Editor/Editor.cpp b/Editor/Editor.cpp index 66c8c570c..dbed48855 100644 --- a/Editor/Editor.cpp +++ b/Editor/Editor.cpp @@ -365,6 +365,7 @@ void EditorComponent::Load() componentsWnd.scriptWnd.SetEntity(INVALID_ENTITY); componentsWnd.rigidWnd.SetEntity(INVALID_ENTITY); componentsWnd.softWnd.SetEntity(INVALID_ENTITY); + componentsWnd.colliderWnd.SetEntity(INVALID_ENTITY); optionsWnd.RefreshEntityTree(); ResetHistory(); @@ -1315,6 +1316,7 @@ void EditorComponent::Update(float dt) componentsWnd.scriptWnd.SetEntity(INVALID_ENTITY); componentsWnd.rigidWnd.SetEntity(INVALID_ENTITY); componentsWnd.softWnd.SetEntity(INVALID_ENTITY); + componentsWnd.colliderWnd.SetEntity(INVALID_ENTITY); } else { @@ -1349,6 +1351,7 @@ void EditorComponent::Update(float dt) componentsWnd.animWnd.SetEntity(picked.entity); componentsWnd.scriptWnd.SetEntity(picked.entity); componentsWnd.rigidWnd.SetEntity(picked.entity); + componentsWnd.colliderWnd.SetEntity(picked.entity); if (picked.subsetIndex >= 0) { @@ -1534,20 +1537,6 @@ void EditorComponent::Render() const // Spring visualizer: if (componentsWnd.springWnd.debugCheckBox.GetCheck()) { - for (size_t i = 0; i < scene.colliders.GetCount(); ++i) - { - ColliderComponent& collider = scene.colliders[i]; - switch (collider.shape) - { - default: - case ColliderComponent::Shape::Sphere: - wi::renderer::DrawSphere(collider.sphere, XMFLOAT4(1, 0, 1, 1)); - break; - case ColliderComponent::Shape::Capsule: - wi::renderer::DrawCapsule(collider.capsule, XMFLOAT4(1, 1, 0, 1)); - break; - } - } for (size_t i = 0; i < scene.springs.GetCount(); ++i) { const SpringComponent& spring = scene.springs[i]; diff --git a/Editor/Editor_SOURCE.vcxitems b/Editor/Editor_SOURCE.vcxitems index fd4db280b..3cba77e98 100644 --- a/Editor/Editor_SOURCE.vcxitems +++ b/Editor/Editor_SOURCE.vcxitems @@ -16,6 +16,7 @@ + @@ -129,6 +130,7 @@ + diff --git a/Editor/Editor_SOURCE.vcxitems.filters b/Editor/Editor_SOURCE.vcxitems.filters index 2f0b7dc9b..fbd565c65 100644 --- a/Editor/Editor_SOURCE.vcxitems.filters +++ b/Editor/Editor_SOURCE.vcxitems.filters @@ -79,6 +79,7 @@ + @@ -122,6 +123,7 @@ + diff --git a/Editor/GraphicsWindow.cpp b/Editor/GraphicsWindow.cpp index f999ea21b..c6d62e152 100644 --- a/Editor/GraphicsWindow.cpp +++ b/Editor/GraphicsWindow.cpp @@ -14,7 +14,7 @@ void GraphicsWindow::Create(EditorComponent* _editor) wi::renderer::SetToDrawGridHelper(true); wi::renderer::SetToDrawDebugCameras(true); - SetSize(XMFLOAT2(580, 1750)); + SetSize(XMFLOAT2(580, 1760)); float step = 21; float itemheight = 18; @@ -1310,6 +1310,16 @@ void GraphicsWindow::Create(EditorComponent* _editor) cameraVisCheckBox.SetCheck(wi::renderer::GetToDrawDebugCameras()); AddWidget(&cameraVisCheckBox); + colliderVisCheckBox.Create("Collider visualizer: "); + colliderVisCheckBox.SetTooltip("Toggle visualization of colliders in the scene"); + colliderVisCheckBox.SetPos(XMFLOAT2(x, y += step)); + colliderVisCheckBox.SetSize(XMFLOAT2(itemheight, itemheight)); + colliderVisCheckBox.OnClick([](wi::gui::EventArgs args) { + wi::renderer::SetToDrawDebugColliders(args.bValue); + }); + colliderVisCheckBox.SetCheck(wi::renderer::GetToDrawDebugColliders()); + AddWidget(&colliderVisCheckBox); + gridHelperCheckBox.Create("Grid helper: "); gridHelperCheckBox.SetTooltip("Toggle showing of unit visualizer grid in the world origin"); gridHelperCheckBox.SetPos(XMFLOAT2(x, y += step)); @@ -1730,6 +1740,7 @@ void GraphicsWindow::ResizeLayout() add_right(disableAlbedoMapsCheckBox); add_right(forceDiffuseLightingCheckBox); add_right(wireFrameCheckBox); + add_right(gridHelperCheckBox); add_right(nameDebugCheckBox); add_right(physicsDebugCheckBox); add_right(aabbDebugCheckBox); @@ -1738,8 +1749,8 @@ void GraphicsWindow::ResizeLayout() add_right(debugForceFieldsCheckBox); add_right(debugRaytraceBVHCheckBox); add_right(envProbesCheckBox); - add_right(gridHelperCheckBox); add_right(cameraVisCheckBox); + add_right(colliderVisCheckBox); } diff --git a/Editor/GraphicsWindow.h b/Editor/GraphicsWindow.h index 26d1b4274..1f2d1cf0d 100644 --- a/Editor/GraphicsWindow.h +++ b/Editor/GraphicsWindow.h @@ -101,6 +101,7 @@ public: wi::gui::CheckBox envProbesCheckBox; wi::gui::CheckBox gridHelperCheckBox; wi::gui::CheckBox cameraVisCheckBox; + wi::gui::CheckBox colliderVisCheckBox; enum RENDERPATH { diff --git a/Editor/ModelImporter_GLTF.cpp b/Editor/ModelImporter_GLTF.cpp index fcf3e131c..f10dc7ba6 100644 --- a/Editor/ModelImporter_GLTF.cpp +++ b/Editor/ModelImporter_GLTF.cpp @@ -1662,8 +1662,8 @@ void Import_Extension_VRM(LoaderState& state) Entity colliderID = CreateEntity(); //component.colliders.push_back(colliderID); // for now, we will just use all colliders in the scene for every spring ColliderComponent& collider_component = state.scene->colliders.Create(colliderID); - state.scene->Component_Attach(colliderID, state.rootEntity); - collider_component.transformID = transformID; + state.scene->transforms.Create(colliderID); + state.scene->Component_Attach(colliderID, transformID, true); const auto& collider = colliders.Get(int(collider_index)); if (collider.Has("offset")) @@ -1785,10 +1785,10 @@ void Import_Extension_VRMC(LoaderState& state) const auto& node = collider.Get("node"); int node_index = node.GetNumberAsInt(); Entity entity = state.entityMap[node_index]; - component.transformID = entity; Entity colliderID = CreateEntity(); state.scene->colliders.Create(colliderID) = component; - state.scene->Component_Attach(colliderID, state.rootEntity); + state.scene->transforms.Create(colliderID); + state.scene->Component_Attach(colliderID, entity, true); } } } diff --git a/Editor/OptionsWindow.cpp b/Editor/OptionsWindow.cpp index 324391e69..8bc692e10 100644 --- a/Editor/OptionsWindow.cpp +++ b/Editor/OptionsWindow.cpp @@ -152,6 +152,7 @@ void OptionsWindow::Create(EditorComponent* _editor) newCombo.AddItem("Plane " ICON_SQUARE, 14); newCombo.AddItem("Animation " ICON_ANIMATION, 15); newCombo.AddItem("Script " ICON_SCRIPT, 16); + newCombo.AddItem("Collider " ICON_COLLIDER, 17); newCombo.OnSelect([&](wi::gui::EventArgs args) { newCombo.SetSelectedWithoutCallback(-1); const EditorComponent::EditorScene& editorscene = editor->GetCurrentEditorScene(); @@ -256,6 +257,12 @@ void OptionsWindow::Create(EditorComponent* _editor) scene.scripts.Create(pick.entity); scene.names.Create(pick.entity) = "script"; break; + case 17: + pick.entity = CreateEntity(); + scene.colliders.Create(pick.entity); + scene.transforms.Create(pick.entity); + scene.names.Create(pick.entity) = "collider"; + break; default: break; } diff --git a/Editor/RigidBodyWindow.cpp b/Editor/RigidBodyWindow.cpp index bbcb43d5b..61938ccc9 100644 --- a/Editor/RigidBodyWindow.cpp +++ b/Editor/RigidBodyWindow.cpp @@ -36,12 +36,11 @@ void RigidBodyWindow::Create(EditorComponent* _editor) collisionShapeComboBox.Create("Collision Shape: "); collisionShapeComboBox.SetSize(XMFLOAT2(wid, hei)); collisionShapeComboBox.SetPos(XMFLOAT2(x, y)); - collisionShapeComboBox.AddItem("DISABLED"); - collisionShapeComboBox.AddItem("Box"); - collisionShapeComboBox.AddItem("Sphere"); - collisionShapeComboBox.AddItem("Capsule"); - collisionShapeComboBox.AddItem("Convex Hull"); - collisionShapeComboBox.AddItem("Triangle Mesh"); + collisionShapeComboBox.AddItem("Box", RigidBodyPhysicsComponent::CollisionShape::BOX); + collisionShapeComboBox.AddItem("Sphere", RigidBodyPhysicsComponent::CollisionShape::SPHERE); + collisionShapeComboBox.AddItem("Capsule", RigidBodyPhysicsComponent::CollisionShape::CAPSULE); + collisionShapeComboBox.AddItem("Convex Hull", RigidBodyPhysicsComponent::CollisionShape::CONVEX_HULL); + collisionShapeComboBox.AddItem("Triangle Mesh", RigidBodyPhysicsComponent::CollisionShape::TRIANGLE_MESH); collisionShapeComboBox.OnSelect([&](wi::gui::EventArgs args) { if (entity == INVALID_ENTITY) @@ -49,94 +48,61 @@ void RigidBodyWindow::Create(EditorComponent* _editor) Scene& scene = editor->GetCurrentScene(); RigidBodyPhysicsComponent* physicscomponent = scene.rigidbodies.GetComponent(entity); - - if (args.iValue == 0) - { - if (physicscomponent != nullptr) - { - scene.rigidbodies.Remove(entity); - } - return; - } - if (physicscomponent == nullptr) + return; + + XSlider.SetEnabled(false); + YSlider.SetEnabled(false); + ZSlider.SetEnabled(false); + XSlider.SetText("-"); + YSlider.SetText("-"); + ZSlider.SetText("-"); + + RigidBodyPhysicsComponent::CollisionShape shape = (RigidBodyPhysicsComponent::CollisionShape)args.userdata; + if (physicscomponent->shape != shape) { - physicscomponent = &scene.rigidbodies.Create(entity); - physicscomponent->SetKinematic(kinematicCheckBox.GetCheck()); - physicscomponent->SetDisableDeactivation(disabledeactivationCheckBox.GetCheck()); - physicscomponent->shape = (RigidBodyPhysicsComponent::CollisionShape)collisionShapeComboBox.GetSelected(); + physicscomponent->physicsobject = nullptr; + physicscomponent->shape = shape; } - if (physicscomponent != nullptr) + switch (shape) { - XSlider.SetEnabled(false); - YSlider.SetEnabled(false); - ZSlider.SetEnabled(false); - XSlider.SetText("-"); + case RigidBodyPhysicsComponent::CollisionShape::BOX: + XSlider.SetEnabled(true); + YSlider.SetEnabled(true); + ZSlider.SetEnabled(true); + XSlider.SetText("Width"); + YSlider.SetText("Height"); + ZSlider.SetText("Depth"); + XSlider.SetValue(physicscomponent->box.halfextents.x); + YSlider.SetValue(physicscomponent->box.halfextents.y); + ZSlider.SetValue(physicscomponent->box.halfextents.z); + break; + case RigidBodyPhysicsComponent::CollisionShape::SPHERE: + XSlider.SetEnabled(true); + XSlider.SetText("Radius"); YSlider.SetText("-"); ZSlider.SetText("-"); - - switch (args.iValue) + XSlider.SetValue(physicscomponent->sphere.radius); + break; + case RigidBodyPhysicsComponent::CollisionShape::CAPSULE: + if (physicscomponent->shape != RigidBodyPhysicsComponent::CollisionShape::CAPSULE) { - case 1: - if (physicscomponent->shape != RigidBodyPhysicsComponent::CollisionShape::BOX) - { - physicscomponent->physicsobject = nullptr; - physicscomponent->shape = RigidBodyPhysicsComponent::CollisionShape::BOX; - } - XSlider.SetEnabled(true); - YSlider.SetEnabled(true); - ZSlider.SetEnabled(true); - XSlider.SetText("Width"); - YSlider.SetText("Height"); - ZSlider.SetText("Depth"); - XSlider.SetValue(physicscomponent->box.halfextents.x); - YSlider.SetValue(physicscomponent->box.halfextents.y); - ZSlider.SetValue(physicscomponent->box.halfextents.z); - break; - case 2: - if (physicscomponent->shape != RigidBodyPhysicsComponent::CollisionShape::SPHERE) - { - physicscomponent->physicsobject = nullptr; - physicscomponent->shape = RigidBodyPhysicsComponent::CollisionShape::SPHERE; - } - XSlider.SetEnabled(true); - XSlider.SetText("Radius"); - YSlider.SetText("-"); - ZSlider.SetText("-"); - XSlider.SetValue(physicscomponent->sphere.radius); - break; - case 3: - if (physicscomponent->shape != RigidBodyPhysicsComponent::CollisionShape::CAPSULE) - { - physicscomponent->physicsobject = nullptr; - physicscomponent->shape = RigidBodyPhysicsComponent::CollisionShape::CAPSULE; - } - XSlider.SetEnabled(true); - YSlider.SetEnabled(true); - XSlider.SetText("Height"); - YSlider.SetText("Radius"); - ZSlider.SetText("-"); - XSlider.SetValue(physicscomponent->capsule.height); - YSlider.SetValue(physicscomponent->capsule.radius); - break; - case 4: - if (physicscomponent->shape != RigidBodyPhysicsComponent::CollisionShape::CONVEX_HULL) - { - physicscomponent->physicsobject = nullptr; - physicscomponent->shape = RigidBodyPhysicsComponent::CollisionShape::CONVEX_HULL; - } - break; - case 5: - if (physicscomponent->shape != RigidBodyPhysicsComponent::CollisionShape::TRIANGLE_MESH) - { - physicscomponent->physicsobject = nullptr; - physicscomponent->shape = RigidBodyPhysicsComponent::CollisionShape::TRIANGLE_MESH; - } - break; - default: - break; + physicscomponent->physicsobject = nullptr; + physicscomponent->shape = RigidBodyPhysicsComponent::CollisionShape::CAPSULE; } + XSlider.SetEnabled(true); + YSlider.SetEnabled(true); + XSlider.SetText("Height"); + YSlider.SetText("Radius"); + ZSlider.SetText("-"); + XSlider.SetValue(physicscomponent->capsule.height); + YSlider.SetValue(physicscomponent->capsule.radius); + break; + case RigidBodyPhysicsComponent::CollisionShape::CONVEX_HULL: + case RigidBodyPhysicsComponent::CollisionShape::TRIANGLE_MESH: + default: + break; } }); collisionShapeComboBox.SetSelected(0); @@ -210,6 +176,10 @@ void RigidBodyWindow::Create(EditorComponent* _editor) }); AddWidget(&ZSlider); + XSlider.SetText("Width"); + YSlider.SetText("Height"); + ZSlider.SetText("Depth"); + massSlider.Create(0, 10, 1, 100000, "Mass: "); massSlider.SetTooltip("Set the mass amount for the physics engine."); massSlider.SetSize(XMFLOAT2(wid, hei)); diff --git a/Editor/RigidBodyWindow.h b/Editor/RigidBodyWindow.h index a2d01be5c..e95952ff5 100644 --- a/Editor/RigidBodyWindow.h +++ b/Editor/RigidBodyWindow.h @@ -12,7 +12,6 @@ public: wi::ecs::Entity entity = wi::ecs::INVALID_ENTITY; void SetEntity(wi::ecs::Entity entity); - wi::gui::Label physicsLabel; wi::gui::ComboBox collisionShapeComboBox; wi::gui::Slider XSlider; wi::gui::Slider YSlider; diff --git a/WickedEngine/wiRenderer.cpp b/WickedEngine/wiRenderer.cpp index a5d0d9380..eecb20c31 100644 --- a/WickedEngine/wiRenderer.cpp +++ b/WickedEngine/wiRenderer.cpp @@ -76,6 +76,7 @@ bool freezeCullingCamera = false; bool debugEnvProbes = false; bool debugForceFields = false; bool debugCameras = false; +bool debugColliders = false; bool gridHelper = false; bool voxelHelper = false; bool advancedLightCulling = true; @@ -5090,6 +5091,24 @@ void DrawDebugWorld( BindCommonResources(cmd); + if (GetToDrawDebugColliders()) + { + for (size_t i = 0; i < scene.colliders.GetCount(); ++i) + { + ColliderComponent& collider = scene.colliders[i]; + switch (collider.shape) + { + default: + case ColliderComponent::Shape::Sphere: + DrawSphere(collider.sphere, XMFLOAT4(1, 0, 1, 1)); + break; + case ColliderComponent::Shape::Capsule: + DrawCapsule(collider.capsule, XMFLOAT4(1, 1, 0, 1)); + break; + } + } + } + if (debugPartitionTree) { // Actually, there is no SPTree any more, so this will just render all aabbs... @@ -12980,6 +12999,8 @@ void SetToDrawDebugForceFields(bool param) { debugForceFields = param; } bool GetToDrawDebugForceFields() { return debugForceFields; } void SetToDrawDebugCameras(bool param) { debugCameras = param; } bool GetToDrawDebugCameras() { return debugCameras; } +void SetToDrawDebugColliders(bool param) { debugColliders = param; } +bool GetToDrawDebugColliders() { return debugColliders; } bool GetToDrawGridHelper() { return gridHelper; } void SetToDrawGridHelper(bool value) { gridHelper = value; } bool GetToDrawVoxelHelper() { return voxelHelper; } diff --git a/WickedEngine/wiRenderer.h b/WickedEngine/wiRenderer.h index 6fe75e43b..c574834ba 100644 --- a/WickedEngine/wiRenderer.h +++ b/WickedEngine/wiRenderer.h @@ -779,6 +779,8 @@ namespace wi::renderer bool GetToDrawDebugForceFields(); void SetToDrawDebugCameras(bool param); bool GetToDrawDebugCameras(); + void SetToDrawDebugColliders(bool param); + bool GetToDrawDebugColliders(); bool GetToDrawGridHelper(); void SetToDrawGridHelper(bool value); bool GetToDrawVoxelHelper(); diff --git a/WickedEngine/wiScene.cpp b/WickedEngine/wiScene.cpp index 9f37fc779..dcd3db593 100644 --- a/WickedEngine/wiScene.cpp +++ b/WickedEngine/wiScene.cpp @@ -1672,6 +1672,8 @@ namespace wi::scene RunInverseKinematicsUpdateSystem(ctx); + RunColliderUpdateSystem(ctx); + RunSpringUpdateSystem(ctx); RunArmatureUpdateSystem(ctx); @@ -3168,21 +3170,21 @@ namespace wi::scene }); } - void Scene::RunSpringUpdateSystem(wi::jobsystem::context& ctx) + void Scene::RunColliderUpdateSystem(wi::jobsystem::context& ctx) { for (size_t i = 0; i < colliders.GetCount(); ++i) { ColliderComponent& collider = colliders[i]; - if (!transforms.Contains(collider.transformID)) + Entity entity = colliders.GetEntity(i); + const TransformComponent* transform = transforms.GetComponent(entity); + if (transform == nullptr) continue; - const TransformComponent& transform = *transforms.GetComponent(collider.transformID); - - XMFLOAT3 scale = transform.GetScale(); + XMFLOAT3 scale = transform->GetScale(); collider.sphere.radius = collider.radius * std::max(scale.x, std::max(scale.y, scale.z)); collider.capsule.radius = collider.sphere.radius; - XMMATRIX W = XMLoadFloat4x4(&transform.world); + XMMATRIX W = XMLoadFloat4x4(&transform->world); XMVECTOR offset = XMLoadFloat3(&collider.offset); XMVECTOR tail = XMLoadFloat3(&collider.tail); offset = XMVector3Transform(offset, W); @@ -3194,22 +3196,10 @@ namespace wi::scene tail -= N * collider.capsule.radius; XMStoreFloat3(&collider.capsule.base, offset); XMStoreFloat3(&collider.capsule.tip, tail); - -#if 0 - // Debug collider shape: - switch (collider.shape) - { - default: - case ColliderComponent::Shape::Sphere: - wi::renderer::DrawSphere(collider.sphere, XMFLOAT4(1, 0, 1, 1)); - break; - case ColliderComponent::Shape::Capsule: - wi::renderer::DrawCapsule(collider.capsule, XMFLOAT4(1, 1, 0, 1)); - break; - } -#endif } - + } + void Scene::RunSpringUpdateSystem(wi::jobsystem::context& ctx) + { static float time = 0; time += dt; const XMVECTOR windDir = XMLoadFloat3(&weather.windDirection); diff --git a/WickedEngine/wiScene.h b/WickedEngine/wiScene.h index dcc3e2452..fc7a5f4dd 100644 --- a/WickedEngine/wiScene.h +++ b/WickedEngine/wiScene.h @@ -1330,7 +1330,6 @@ namespace wi::scene }; Shape shape; - wi::ecs::Entity transformID = wi::ecs::INVALID_ENTITY; float radius = 0; XMFLOAT3 offset = {}; XMFLOAT3 tail = {}; @@ -1402,7 +1401,7 @@ namespace wi::scene wi::ecs::ComponentManager& sounds = componentLibrary.Register("wi::scene::Scene::sounds"); wi::ecs::ComponentManager& inverse_kinematics = componentLibrary.Register("wi::scene::Scene::inverse_kinematics"); wi::ecs::ComponentManager& springs = componentLibrary.Register("wi::scene::Scene::springs", 1); // version = 1 - wi::ecs::ComponentManager& colliders = componentLibrary.Register("wi::scene::Scene::colliders"); + wi::ecs::ComponentManager& colliders = componentLibrary.Register("wi::scene::Scene::colliders", 1); // version = 1 wi::ecs::ComponentManager& scripts = componentLibrary.Register("wi::scene::Scene::scripts"); // Non-serialized attributes: @@ -1645,6 +1644,7 @@ namespace wi::scene void RunAnimationUpdateSystem(wi::jobsystem::context& ctx); void RunTransformUpdateSystem(wi::jobsystem::context& ctx); void RunHierarchyUpdateSystem(wi::jobsystem::context& ctx); + void RunColliderUpdateSystem(wi::jobsystem::context& ctx); void RunSpringUpdateSystem(wi::jobsystem::context& ctx); void RunInverseKinematicsUpdateSystem(wi::jobsystem::context& ctx); void RunArmatureUpdateSystem(wi::jobsystem::context& ctx); diff --git a/WickedEngine/wiScene_Serializers.cpp b/WickedEngine/wiScene_Serializers.cpp index b02eedef7..2e0bb96c9 100644 --- a/WickedEngine/wiScene_Serializers.cpp +++ b/WickedEngine/wiScene_Serializers.cpp @@ -1413,7 +1413,11 @@ namespace wi::scene int ishape = 0; archive >> ishape; shape = (Shape)ishape; - SerializeEntity(archive, transformID, seri); + if (seri.GetVersion() < 1) + { + Entity transformID; + SerializeEntity(archive, transformID, seri); + } archive >> radius; archive >> offset; archive >> tail; @@ -1422,7 +1426,6 @@ namespace wi::scene { archive << _flags; archive << (int)shape; - SerializeEntity(archive, transformID, seri); archive << radius; archive << offset; archive << tail; diff --git a/WickedEngine/wiVersion.cpp b/WickedEngine/wiVersion.cpp index f281b41d4..dff8682de 100644 --- a/WickedEngine/wiVersion.cpp +++ b/WickedEngine/wiVersion.cpp @@ -9,7 +9,7 @@ namespace wi::version // minor features, major updates, breaking compatibility changes const int minor = 71; // minor bug fixes, alterations, refactors, updates - const int revision = 23; + const int revision = 24; const std::string version_string = std::to_string(major) + "." + std::to_string(minor) + "." + std::to_string(revision);