[Bf-blender-cvs] [63116f2c8ce] functions: improved handling of moving colliders
Jacques Lucke
noreply at git.blender.org
Sun Sep 22 12:44:13 CEST 2019
Commit: 63116f2c8ce950ff7883d0bf940cca63a662e249
Author: Jacques Lucke
Date: Sun Sep 22 12:44:07 2019 +0200
Branches: functions
https://developer.blender.org/rB63116f2c8ce950ff7883d0bf940cca63a662e249
improved handling of moving colliders
===================================================================
M source/blender/simulations/bparticles/events.cpp
M source/blender/simulations/bparticles/events.hpp
M source/blender/simulations/bparticles/node_frontend.cpp
===================================================================
diff --git a/source/blender/simulations/bparticles/events.cpp b/source/blender/simulations/bparticles/events.cpp
index 5c3d8fc055f..82e658c1627 100644
--- a/source/blender/simulations/bparticles/events.cpp
+++ b/source/blender/simulations/bparticles/events.cpp
@@ -136,23 +136,28 @@ void MeshCollisionEvent::filter(EventFilterInterface &interface)
auto position_offsets = interface.attribute_offsets().get<float3>("Position");
for (uint pindex : interface.pindices()) {
- float3 ray_start = m_world_to_local.transform_position(positions[pindex]);
- float3 ray_direction = m_world_to_local.transform_direction(position_offsets[pindex]);
- float length = ray_direction.normalize_and_get_length();
+ float3 world_ray_start = positions[pindex];
+ float3 world_ray_direction = position_offsets[pindex];
+ float3 world_ray_end = world_ray_start + world_ray_direction;
- auto result = this->ray_cast(ray_start, ray_direction, length);
+ float3 local_ray_start = m_world_to_local_begin.transform_position(world_ray_start);
+ float3 local_ray_end = m_world_to_local_end.transform_position(world_ray_end);
+ float3 local_ray_direction = local_ray_end - local_ray_start;
+ float local_ray_length = local_ray_direction.normalize_and_get_length();
+
+ auto result = this->ray_cast(local_ray_start, local_ray_direction, local_ray_length);
if (result.success) {
- float time_factor = result.distance / length;
+ float time_factor = result.distance / local_ray_length;
float time = interface.time_span(pindex).interpolate(time_factor);
if (std::abs(last_collision_times[pindex] - time) < 0.0001f) {
continue;
}
auto &storage = interface.trigger_particle<EventStorage>(pindex, time_factor);
- if (float3::dot(result.normal, ray_direction) > 0) {
+ if (float3::dot(result.normal, local_ray_direction) > 0) {
result.normal = -result.normal;
}
storage.local_normal = result.normal;
- storage.local_position = ray_start + ray_direction * result.distance;
+ storage.local_position = local_ray_start + local_ray_direction * result.distance;
storage.looptri_index = result.index;
}
}
@@ -194,7 +199,7 @@ void MeshCollisionEvent::execute(EventExecuteInterface &interface)
}
MeshSurfaceContext surface_context(m_object,
- m_local_to_world,
+ m_local_to_world_begin,
interface.pindices(),
local_positions,
local_normals,
diff --git a/source/blender/simulations/bparticles/events.hpp b/source/blender/simulations/bparticles/events.hpp
index f576b008a29..18c707a8b28 100644
--- a/source/blender/simulations/bparticles/events.hpp
+++ b/source/blender/simulations/bparticles/events.hpp
@@ -55,8 +55,10 @@ class MeshCollisionEvent : public Event {
std::string m_identifier;
Object *m_object;
BVHTreeFromMesh m_bvhtree_data;
- float4x4 m_local_to_world;
- float4x4 m_world_to_local;
+ float4x4 m_local_to_world_begin;
+ float4x4 m_world_to_local_begin;
+ float4x4 m_local_to_world_end;
+ float4x4 m_world_to_local_end;
Action &m_action;
struct RayCastResult {
@@ -73,12 +75,18 @@ class MeshCollisionEvent : public Event {
};
public:
- MeshCollisionEvent(StringRef identifier, Object *object, Action &action)
+ MeshCollisionEvent(StringRef identifier,
+ Object *object,
+ Action &action,
+ float4x4 local_to_world_begin,
+ float4x4 local_to_world_end)
: m_identifier(identifier), m_object(object), m_action(action)
{
BLI_assert(object->type == OB_MESH);
- m_local_to_world = m_object->obmat;
- m_world_to_local = m_local_to_world.inverted__LocRotScale();
+ m_local_to_world_begin = local_to_world_begin;
+ m_local_to_world_end = local_to_world_end;
+ m_world_to_local_begin = m_local_to_world_begin.inverted__LocRotScale();
+ m_world_to_local_end = m_local_to_world_end.inverted__LocRotScale();
BKE_bvhtree_from_mesh_get(&m_bvhtree_data, (Mesh *)object->data, BVHTREE_FROM_LOOPTRI, 2);
}
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index 63d43e68953..5ff91d73541 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -615,7 +615,7 @@ static void PARSE_drag_force(InfluencesCollector &collector,
static void PARSE_mesh_collision(InfluencesCollector &collector,
VTreeData &vtree_data,
- WorldTransition &UNUSED(world_transition),
+ WorldTransition &world_transition,
VirtualNode *vnode)
{
ParticleFunction *inputs_fn = vtree_data.particle_function_for_all_inputs(vnode);
@@ -637,8 +637,13 @@ static void PARSE_mesh_collision(InfluencesCollector &collector,
vnode->output(0, "Event"));
Action &action = vtree_data.build_action_list(vnode, "Execute on Event");
+ float4x4 local_to_world_end = object->obmat;
+ float4x4 local_to_world_begin =
+ world_transition.update_float4x4(object->id.name, "obmat", object->obmat).start;
+
for (const std::string &system_name : system_names) {
- Event *event = new MeshCollisionEvent(vnode->name(), object, action);
+ Event *event = new MeshCollisionEvent(
+ vnode->name(), object, action, local_to_world_begin, local_to_world_end);
collector.m_events.add(system_name, event);
}
}
More information about the Bf-blender-cvs
mailing list