[Bf-blender-cvs] [4bbee4acf27] functions: new Change Particle Color node
Jacques Lucke
noreply at git.blender.org
Tue Jul 30 13:27:56 CEST 2019
Commit: 4bbee4acf27a1bb6948d271ef26e6949d6268571
Author: Jacques Lucke
Date: Tue Jul 30 12:14:42 2019 +0200
Branches: functions
https://developer.blender.org/rB4bbee4acf27a1bb6948d271ef26e6949d6268571
new Change Particle Color node
===================================================================
A release/scripts/startup/nodes/bparticle_nodes/change_color.py
M source/blender/simulations/bparticles/actions.cpp
M source/blender/simulations/bparticles/actions.hpp
M source/blender/simulations/bparticles/inserters.cpp
===================================================================
diff --git a/release/scripts/startup/nodes/bparticle_nodes/change_color.py b/release/scripts/startup/nodes/bparticle_nodes/change_color.py
new file mode 100644
index 00000000000..2e29f85a333
--- /dev/null
+++ b/release/scripts/startup/nodes/bparticle_nodes/change_color.py
@@ -0,0 +1,13 @@
+import bpy
+from bpy.props import *
+from .. base import BParticlesNode
+from .. node_builder import NodeBuilder
+
+class ChangeParticleColorNode(bpy.types.Node, BParticlesNode):
+ bl_idname = "bp_ChangeParticleColorNode"
+ bl_label = "Change Particle Color"
+
+ def declaration(self, builder: NodeBuilder):
+ builder.control_flow_input("control_in", "(In)")
+ builder.fixed_input("color", "Color", "Color")
+ builder.control_flow_output("control_out", "(Out)")
diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
index fc2d6729ac9..6734e46b159 100644
--- a/source/blender/simulations/bparticles/actions.cpp
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -4,6 +4,8 @@
namespace BParticles {
+using BLI::rgba_f;
+
void NoneAction::execute(ActionInterface &UNUSED(interface))
{
}
@@ -33,6 +35,22 @@ void ChangeDirectionAction::execute(ActionInterface &interface)
m_post_action->execute(interface);
}
+void ChangeColorAction::execute(ActionInterface &interface)
+{
+ ParticleSet particles = interface.particles();
+ auto colors = particles.attributes().get<float3>("Color");
+
+ auto inputs = m_compute_inputs->compute(interface);
+ for (uint pindex : particles.pindices()) {
+ rgba_f color = inputs->get<rgba_f>("Color", 0, pindex);
+ colors[pindex].x = color.r;
+ colors[pindex].y = color.g;
+ colors[pindex].z = color.b;
+ }
+
+ m_post_action->execute(interface);
+}
+
void KillAction::execute(ActionInterface &interface)
{
interface.kill(interface.particles().pindices());
diff --git a/source/blender/simulations/bparticles/actions.hpp b/source/blender/simulations/bparticles/actions.hpp
index 40656929120..8ac5081915f 100644
--- a/source/blender/simulations/bparticles/actions.hpp
+++ b/source/blender/simulations/bparticles/actions.hpp
@@ -28,6 +28,21 @@ class ChangeDirectionAction : public Action {
void execute(ActionInterface &interface) override;
};
+class ChangeColorAction : public Action {
+ private:
+ std::unique_ptr<ParticleFunction> m_compute_inputs;
+ std::unique_ptr<Action> m_post_action;
+
+ public:
+ ChangeColorAction(std::unique_ptr<ParticleFunction> compute_inputs,
+ std::unique_ptr<Action> post_action)
+ : m_compute_inputs(std::move(compute_inputs)), m_post_action(std::move(post_action))
+ {
+ }
+
+ void execute(ActionInterface &interface) override;
+};
+
class ExplodeAction : public Action {
private:
std::string m_new_particle_name;
diff --git a/source/blender/simulations/bparticles/inserters.cpp b/source/blender/simulations/bparticles/inserters.cpp
index 39a1cfd509d..53420bf16fb 100644
--- a/source/blender/simulations/bparticles/inserters.cpp
+++ b/source/blender/simulations/bparticles/inserters.cpp
@@ -74,6 +74,19 @@ static std::unique_ptr<Action> BUILD_ACTION_change_direction(
new ChangeDirectionAction(std::move(compute_inputs_fn), std::move(post_action)));
}
+static std::unique_ptr<Action> BUILD_ACTION_change_color(
+ BuildContext &ctx,
+ VirtualSocket *start,
+ VirtualSocket *trigger,
+ std::unique_ptr<ParticleFunction> compute_inputs_fn)
+{
+ VirtualNode *vnode = start->vnode();
+ auto post_action = build_action(ctx, vnode->output(0), trigger);
+
+ return std::unique_ptr<ChangeColorAction>(
+ new ChangeColorAction(std::move(compute_inputs_fn), std::move(post_action)));
+}
+
static std::unique_ptr<Action> BUILD_ACTION_explode(
BuildContext &ctx,
VirtualSocket *start,
@@ -118,6 +131,7 @@ BLI_LAZY_INIT_STATIC(StringMap<ActionFromNodeCallback>, get_action_builders)
map.add_new("bp_ChangeParticleDirectionNode", BUILD_ACTION_change_direction);
map.add_new("bp_ExplodeParticleNode", BUILD_ACTION_explode);
map.add_new("bp_ParticleConditionNode", BUILD_ACTION_condition);
+ map.add_new("bp_ChangeParticleColorNode", BUILD_ACTION_change_color);
return map;
}
More information about the Bf-blender-cvs
mailing list