Softbody simplification with bones (#876)

This commit is contained in:
Turánszki János
2024-07-04 09:24:47 +02:00
committed by GitHub
parent faff256d18
commit fb41bf83bd
55 changed files with 1167 additions and 778 deletions
+47 -35
View File
@@ -1615,7 +1615,6 @@ void EditorComponent::Update(float dt)
{
if (
wi::input::Down(wi::input::MOUSE_BUTTON_LEFT) ||
wi::input::Down(wi::input::MOUSE_BUTTON_MIDDLE) ||
inspector_mode
)
{
@@ -1638,6 +1637,7 @@ void EditorComponent::Update(float dt)
// Interactions:
{
// Interact:
bool interaction_happened = false;
if (wi::input::Down((wi::input::BUTTON)'P'))
{
if (wi::input::Press(wi::input::MOUSE_BUTTON_MIDDLE))
@@ -1646,6 +1646,7 @@ void EditorComponent::Update(float dt)
wi::physics::RayIntersectionResult result = wi::physics::Intersects(scene, pickRay);
if (result.IsValid())
{
interaction_happened = true;
XMFLOAT3 impulse;
XMStoreFloat3(&impulse, XMVector3Normalize(XMLoadFloat3(&pickRay.direction)) * 20);
if (result.humanoid_ragdoll_entity != INVALID_ENTITY)
@@ -1676,6 +1677,10 @@ void EditorComponent::Update(float dt)
if (wi::input::Down(wi::input::MOUSE_BUTTON_MIDDLE))
{
wi::physics::PickDrag(scene, pickRay, physicsDragOp);
if (physicsDragOp.IsValid())
{
interaction_happened = true;
}
}
else
{
@@ -1714,50 +1719,53 @@ void EditorComponent::Update(float dt)
}
// Other:
if (hovered.entity != INVALID_ENTITY && wi::input::Down(wi::input::MOUSE_BUTTON_MIDDLE))
if (!interaction_happened && wi::input::Down(wi::input::MOUSE_BUTTON_MIDDLE))
{
if (dummy_enabled)
hovered = wi::scene::Pick(pickRay, wi::enums::FILTER_OBJECT_ALL, ~0u, scene);
if (hovered.entity != INVALID_ENTITY)
{
dummy_pos = hovered.position;
}
else
{
const ObjectComponent* object = scene.objects.GetComponent(hovered.entity);
if (object != nullptr)
if (dummy_enabled)
{
if (object->GetFilterMask() & wi::enums::FILTER_WATER)
dummy_pos = hovered.position;
}
else
{
const ObjectComponent* object = scene.objects.GetComponent(hovered.entity);
if (object != nullptr)
{
// if water, then put a water ripple onto it:
scene.PutWaterRipple(hovered.position);
}
else
{
// Check for interactive grass (hair particle that is child of hovered object:
for (size_t i = 0; i < scene.hairs.GetCount(); ++i)
if (object->GetFilterMask() & wi::enums::FILTER_WATER)
{
Entity entity = scene.hairs.GetEntity(i);
HierarchyComponent* hier = scene.hierarchy.GetComponent(entity);
if (hier != nullptr && hier->parentID == hovered.entity)
// if water, then put a water ripple onto it:
scene.PutWaterRipple(hovered.position);
}
else
{
// Check for interactive grass (hair particle that is child of hovered object:
for (size_t i = 0; i < scene.hairs.GetCount(); ++i)
{
XMVECTOR P = XMLoadFloat3(&hovered.position);
P += XMLoadFloat3(&hovered.normal) * 2;
if (grass_interaction_entity == INVALID_ENTITY)
Entity entity = scene.hairs.GetEntity(i);
HierarchyComponent* hier = scene.hierarchy.GetComponent(entity);
if (hier != nullptr && hier->parentID == hovered.entity)
{
grass_interaction_entity = CreateEntity();
XMVECTOR P = XMLoadFloat3(&hovered.position);
P += XMLoadFloat3(&hovered.normal) * 2;
if (grass_interaction_entity == INVALID_ENTITY)
{
grass_interaction_entity = CreateEntity();
}
ForceFieldComponent& force = scene.forces.Create(grass_interaction_entity);
TransformComponent& transform = scene.transforms.Create(grass_interaction_entity);
force.type = ForceFieldComponent::Type::Point;
force.gravity = -80;
force.range = 3;
transform.Translate(P);
break;
}
ForceFieldComponent& force = scene.forces.Create(grass_interaction_entity);
TransformComponent& transform = scene.transforms.Create(grass_interaction_entity);
force.type = ForceFieldComponent::Type::Point;
force.gravity = -80;
force.range = 3;
transform.Translate(P);
break;
}
}
}
}
}
}
}
@@ -2285,6 +2293,10 @@ void EditorComponent::Update(float dt)
if (navtest_enabled)
{
if (wi::input::Down(wi::input::MOUSE_BUTTON_MIDDLE))
{
hovered = wi::scene::Pick(pickRay, wi::enums::FILTER_OBJECT_ALL, ~0u, scene);
}
if (hovered.entity != INVALID_ENTITY && wi::input::Down(wi::input::KEYBOARD_BUTTON_F5))
{
navtest_start_pick = hovered;
@@ -2558,7 +2570,7 @@ void EditorComponent::Render() const
if (renderPath->getMSAASampleCount() > 1)
{
RenderPassImage rp[] = {
RenderPassImage::RenderTarget(&rt_selectionOutline_MSAA, RenderPassImage::LoadOp::CLEAR, RenderPassImage::StoreOp::DONTCARE),
RenderPassImage::RenderTarget(&rt_selectionOutline_MSAA, RenderPassImage::LoadOp::CLEAR),
RenderPassImage::Resolve(&rt_selectionOutline[0]),
RenderPassImage::DepthStencil(
renderPath->GetDepthStencil(),
@@ -2593,7 +2605,7 @@ void EditorComponent::Render() const
if (renderPath->getMSAASampleCount() > 1)
{
RenderPassImage rp[] = {
RenderPassImage::RenderTarget(&rt_selectionOutline_MSAA, RenderPassImage::LoadOp::CLEAR, RenderPassImage::StoreOp::DONTCARE),
RenderPassImage::RenderTarget(&rt_selectionOutline_MSAA, RenderPassImage::LoadOp::CLEAR),
RenderPassImage::Resolve(&rt_selectionOutline[1]),
RenderPassImage::DepthStencil(
renderPath->GetDepthStencil(),
@@ -2742,7 +2754,7 @@ void EditorComponent::Render() const
RenderPassImage::RenderTarget(
&editor_rendertarget,
RenderPassImage::LoadOp::CLEAR,
RenderPassImage::StoreOp::DONTCARE,
RenderPassImage::StoreOp::STORE,
ResourceState::RENDERTARGET,
ResourceState::RENDERTARGET
),