[Bf-blender-cvs] [d5b0df396a5] functions: various small improvements
Jacques Lucke
noreply at git.blender.org
Tue Jul 2 16:11:39 CEST 2019
Commit: d5b0df396a5f0ee91a1bdd667d63df03594f9e8a
Author: Jacques Lucke
Date: Tue Jul 2 12:02:54 2019 +0200
Branches: functions
https://developer.blender.org/rBd5b0df396a5f0ee91a1bdd667d63df03594f9e8a
various small improvements
===================================================================
M source/blender/blenlib/BLI_math.hpp
M source/blender/simulations/bparticles/events.cpp
M source/blender/simulations/bparticles/simulate.cpp
===================================================================
diff --git a/source/blender/blenlib/BLI_math.hpp b/source/blender/blenlib/BLI_math.hpp
index 5eab8c94cbe..f51904b4fb7 100644
--- a/source/blender/blenlib/BLI_math.hpp
+++ b/source/blender/blenlib/BLI_math.hpp
@@ -50,7 +50,7 @@ struct float3 {
*this = this->reflected(normal);
}
- float3 reflected(float3 normal)
+ float3 reflected(float3 normal) const
{
float3 result;
reflect_v3_v3v3(result, *this, normal);
@@ -64,6 +64,18 @@ struct float3 {
z = -z;
}
+ bool is_zero() const
+ {
+ return is_zero_v3(*this);
+ }
+
+ void zero_small_values(float eps = 0.000001f)
+ {
+ x = (std::abs(x) < eps) ? 0.0f : x;
+ y = (std::abs(y) < eps) ? 0.0f : y;
+ z = (std::abs(z) < eps) ? 0.0f : z;
+ }
+
friend float3 operator+(float3 a, float3 b)
{
return {a.x + b.x, a.y + b.y, a.z + b.z};
diff --git a/source/blender/simulations/bparticles/events.cpp b/source/blender/simulations/bparticles/events.cpp
index 9f9182a2556..4e0ca1df4e6 100644
--- a/source/blender/simulations/bparticles/events.cpp
+++ b/source/blender/simulations/bparticles/events.cpp
@@ -41,11 +41,11 @@ class AgeReachedEvent : public EventFilter {
class MeshBounceEvent : public Event {
private:
BVHTreeFromMesh *m_treedata;
- float4x4 m_normal_transform;
- float4x4 m_ray_transform;
+ float4x4 m_local_to_world;
+ float4x4 m_world_to_local;
- struct CollisionData {
- float3 normal;
+ struct EventData {
+ float3 hit_normal;
};
struct RayCastResult {
@@ -58,14 +58,14 @@ class MeshBounceEvent : public Event {
public:
MeshBounceEvent(BVHTreeFromMesh *treedata, float4x4 transform)
: m_treedata(treedata),
- m_normal_transform(transform),
- m_ray_transform(transform.inverted__LocRotScale())
+ m_local_to_world(transform),
+ m_world_to_local(transform.inverted__LocRotScale())
{
}
uint storage_size() override
{
- return sizeof(CollisionData);
+ return sizeof(EventData);
}
void filter(EventFilterInterface &interface) override
@@ -77,20 +77,20 @@ class MeshBounceEvent : public Event {
for (uint i : particles.range()) {
uint pindex = particles.get_particle_index(i);
- float3 ray_start = m_ray_transform.transform_position(positions[pindex]);
- float3 ray_direction = m_ray_transform.transform_direction(position_offsets[i]);
+ float3 ray_start = m_world_to_local.transform_position(positions[pindex]);
+ float3 ray_direction = m_world_to_local.transform_direction(position_offsets[i]);
float length = ray_direction.normalize_and_get_length();
auto result = this->ray_cast(ray_start, ray_direction, length);
if (result.success) {
float time_factor = result.distance / length;
- auto &data = interface.trigger_particle<CollisionData>(i, time_factor);
+ auto &data = interface.trigger_particle<EventData>(i, time_factor);
float3 normal = result.normal;
if (float3::dot(normal, ray_direction) > 0) {
normal.invert();
}
- data.normal = m_normal_transform.transform_direction(normal).normalized();
+ data.hit_normal = m_local_to_world.transform_direction(normal).normalized();
}
}
}
@@ -120,13 +120,13 @@ class MeshBounceEvent : public Event {
auto position_offsets = interface.attribute_offsets().get_float3("Position");
for (uint pindex : particles.indices()) {
- auto &data = interface.get_storage<CollisionData>(pindex);
+ auto &data = interface.get_storage<EventData>(pindex);
/* Move particle back a little bit to avoid double collision. */
- positions[pindex] += data.normal * 0.001f;
+ positions[pindex] += data.hit_normal * 0.001f;
- velocities[pindex] = this->bounce_direction(velocities[pindex], data.normal);
- position_offsets[pindex] = this->bounce_direction(position_offsets[pindex], data.normal);
+ velocities[pindex] = this->bounce_direction(velocities[pindex], data.hit_normal);
+ position_offsets[pindex] = this->bounce_direction(position_offsets[pindex], data.hit_normal);
}
}
@@ -138,7 +138,7 @@ class MeshBounceEvent : public Event {
float3 direction_normal = normal * normal_part;
float3 direction_tangent = direction - direction_normal;
- return direction_normal * 0.5 + direction_tangent * 0.99;
+ return direction_normal * 0.5 + direction_tangent * 0.9;
}
};
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 011814b8b88..a58294ec8c8 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -443,7 +443,7 @@ BLI_NOINLINE static void simulate_block(FixedArrayAllocator &array_allocator,
uint *indices_array = array_allocator.allocate_array<uint>();
VectorAdaptor<uint> unfinished_particle_indices(indices_array, amount);
- simulate_with_max_n_events(1,
+ simulate_with_max_n_events(10,
array_allocator,
block_allocator,
block,
@@ -453,6 +453,7 @@ BLI_NOINLINE static void simulate_block(FixedArrayAllocator &array_allocator,
events,
unfinished_particle_indices);
+ /* Not sure yet, if this really should be done. */
if (unfinished_particle_indices.size() > 0) {
ParticleSet remaining_particles(block, unfinished_particle_indices);
apply_remaining_offsets(remaining_particles, attribute_offsets);
More information about the Bf-blender-cvs
mailing list