Commit: 26d0bbffa89e364ca430407a0f59b16a15cf2785
Author: Martin Felke
Date: Tue Jul 30 14:39:25 2019 +0200
Branches: functions
https://developer.blender.org/rB26d0bbffa89e364ca430407a0f59b16a15cf2785
added point force node for particle nodes
===================================================================
A release/scripts/startup/nodes/bparticle_nodes/point_force.py
M source/blender/simulations/bparticles/forces.cpp
M source/blender/simulations/bparticles/forces.hpp
M source/blender/simulations/bparticles/inserters.cpp
===================================================================
diff --git a/release/scripts/startup/nodes/bparticle_nodes/point_force.py
b/release/scripts/startup/nodes/bparticle_nodes/point_force.py
new file mode 100644
index 00000000000..8ed7d4f7a17
--- /dev/null
+++ b/release/scripts/startup/nodes/bparticle_nodes/point_force.py
@@ -0,0 +1,16 @@
+import bpy
+from bpy.props import *
+from .. base import BParticlesNode
+from .. node_builder import NodeBuilder
+
+class PointForceNode(bpy.types.Node, BParticlesNode):
+ bl_idname = "bp_PointForceNode"
+ bl_label = "Point Force"
+
+ def declaration(self, builder : NodeBuilder):
+ builder.fixed_input("direction", "Direction", "Vector", default=(0, 0,
-1))
+ builder.fixed_input("strength", "Strength", "Float", default = 1.0)
+ builder.fixed_input("falloff", "Falloff", "Float", default = 1.0)
+ builder.fixed_input("distance", "Distance", "Float", default = 1.0)
+ builder.fixed_input("gravitation", "Gravitation", "Boolean",
default=False)
+ builder.particle_modifier_output("force", "Force")
diff --git a/source/blender/simulations/bparticles/forces.cpp
b/source/blender/simulations/bparticles/forces.cpp
index 8c2a7db7feb..e6d251fd82e 100644
--- a/source/blender/simulations/bparticles/forces.cpp
+++ b/source/blender/simulations/bparticles/forces.cpp
@@ -40,4 +40,33 @@ void TurbulenceForce::add_force(ForceInterface &interface)
}
}
+void PointForce::add_force(ForceInterface &interface)
+{
+ ParticlesBlock &block = interface.block();
+ ArrayRef<float3> destination = interface.combined_destination();
+
+ auto inputs = m_compute_inputs->compute(interface);
+
+ for (uint pindex = 0; pindex < block.active_amount(); pindex++) {
+ float3 direction = inputs->get<float3>("Direction", 0, pindex);
+ float strength = inputs->get<float>("Strength", 1, pindex);
+ float falloff = inputs->get<float>("Falloff", 2, pindex);
+ float distance = inputs->get<float>("Distance", 3, pindex);
+ bool gravitation = inputs->get<bool>("Gravitation", 4, pindex);
+
+ if (gravitation) {
+ if (distance < FLT_EPSILON) {
+ strength = 0.0f;
+ }
+ else {
+ strength *= powf(distance, -2.0f);
+ }
+ }
+
+ direction *= (strength * falloff);
+
+ destination[pindex] += direction;
+ }
+}
+
} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/forces.hpp
b/source/blender/simulations/bparticles/forces.hpp
index 1806713752d..0e36a981176 100644
--- a/source/blender/simulations/bparticles/forces.hpp
+++ b/source/blender/simulations/bparticles/forces.hpp
@@ -38,4 +38,17 @@ class TurbulenceForce : public Force {
void add_force(ForceInterface &interface) override;
};
+class PointForce : public Force {
+ private:
+ std::unique_ptr<ParticleFunction> m_compute_inputs;
+
+ public:
+ PointForce(std::unique_ptr<ParticleFunction> compute_inputs)
+ : m_compute_inputs(std::move(compute_inputs))
+ {
+ }
+
+ void add_force(ForceInterface &interface) override;
+};
+
} // namespace BParticles
diff --git a/source/blender/simulations/bparticles/inserters.cpp
b/source/blender/simulations/bparticles/inserters.cpp
index 53420bf16fb..fecd1f11adc 100644
--- a/source/blender/simulations/bparticles/inserters.cpp
+++ b/source/blender/simulations/bparticles/inserters.cpp
@@ -186,6 +186,14 @@ static std::unique_ptr<Force> BUILD_FORCE_turbulence(
return std::unique_ptr<Force>(new
TurbulenceForce(std::move(compute_inputs_fn)));
}
+static std::unique_ptr<Force> BUILD_FORCE_point(
+ BuildContext &UNUSED(ctx),
+ VirtualNode *UNUSED(vnode),
+ std::unique_ptr<ParticleFunction> compute_inputs_fn)
+{
+ return std::unique_ptr<Force>(new PointForce(std::move(compute_inputs_fn)));
+}
+
static std::unique_ptr<Event> BUILD_EVENT_mesh_collision(
BuildContext &ctx, VirtualNode *vnode, std::unique_ptr<ParticleFunction>
compute_inputs_fn)
{
@@ -426,6 +434,7 @@ BLI_LAZY_INIT(StringMap<ForceFromNodeCallback>,
get_force_builders)
StringMap<ForceFromNodeCallback> map;
map.add_new("bp_GravityForceNode", BUILD_FORCE_gravity);
map.add_new("bp_TurbulenceForceNode", BUILD_FORCE_turbulence);
+ map.add_new("bp_PointForceNode", BUILD_FORCE_point);
return map;
}
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs