Grass interaction (#413)
* hairparticle simulation clamping * editor: hair particle interaction * update
This commit is contained in:
@@ -1124,6 +1124,11 @@ void EditorComponent::Update(float dt)
|
||||
Scene& scene = wi::scene::GetScene();
|
||||
CameraComponent& camera = wi::scene::GetCamera();
|
||||
|
||||
if (scene.forces.Contains(grass_interaction_entity))
|
||||
{
|
||||
scene.Entity_Remove(grass_interaction_entity);
|
||||
}
|
||||
|
||||
cameraWnd.Update();
|
||||
animWnd.Update();
|
||||
weatherWnd.Update();
|
||||
@@ -1501,6 +1506,22 @@ void EditorComponent::Update(float dt)
|
||||
}
|
||||
}
|
||||
|
||||
if (scene.hairs.Contains(hovered.entity))
|
||||
{
|
||||
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 = ENTITY_TYPE_FORCEFIELD_POINT;
|
||||
force.gravity = -80;
|
||||
force.range_local = 3;
|
||||
transform.Translate(P);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -151,6 +151,7 @@ public:
|
||||
|
||||
Translator translator;
|
||||
wi::scene::PickResult hovered;
|
||||
wi::ecs::Entity grass_interaction_entity = wi::ecs::INVALID_ENTITY;
|
||||
|
||||
void ClearSelected();
|
||||
void AddSelected(wi::ecs::Entity entity);
|
||||
|
||||
@@ -159,9 +159,14 @@ void main(uint3 DTid : SV_DispatchThreadID, uint3 Gid : SV_GroupID, uint groupIn
|
||||
velocity += surface_velocity;
|
||||
|
||||
// Apply forces:
|
||||
velocity += force;
|
||||
normal += velocity * delta_time;
|
||||
normal = normalize(normal);
|
||||
float3 newVelocity = velocity + force;
|
||||
float3 newNormal = normal + newVelocity * delta_time;
|
||||
newNormal = normalize(newNormal);
|
||||
if (dot(target, newNormal) > 0.5) // clamp the offset
|
||||
{
|
||||
normal = newNormal;
|
||||
velocity = newVelocity;
|
||||
}
|
||||
|
||||
// Drag:
|
||||
velocity *= 0.98f;
|
||||
|
||||
Reference in New Issue
Block a user