[Bf-blender-cvs] [dca21ef42f8] functions: start improving custom events

Jacques Lucke noreply at git.blender.org
Sun Dec 22 14:25:28 CET 2019


Commit: dca21ef42f8a2f3f55531185630edfe54399c5d8
Author: Jacques Lucke
Date:   Fri Dec 20 16:19:38 2019 +0100
Branches: functions
https://developer.blender.org/rBdca21ef42f8a2f3f55531185630edfe54399c5d8

start improving custom events

===================================================================

M	release/scripts/startup/nodes/bparticle_nodes/events.py
M	source/blender/functions/FN_multi_function_common_contexts.h
M	source/blender/functions/FN_multi_function_context.h
M	source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc
M	source/blender/functions/intern/multi_function_common_contexts.cc
M	source/blender/functions/intern/multi_functions/particles.cc
M	source/blender/functions/intern/multi_functions/particles.h
M	source/blender/simulations/bparticles/events.cpp
M	source/blender/simulations/bparticles/events.hpp
M	source/blender/simulations/bparticles/node_frontend.cpp
M	source/blender/simulations/bparticles/particle_function.cpp
M	source/blender/simulations/bparticles/particle_function.hpp

===================================================================

diff --git a/release/scripts/startup/nodes/bparticle_nodes/events.py b/release/scripts/startup/nodes/bparticle_nodes/events.py
index 8c4a30565ed..3ea986bf4f6 100644
--- a/release/scripts/startup/nodes/bparticle_nodes/events.py
+++ b/release/scripts/startup/nodes/bparticle_nodes/events.py
@@ -1,6 +1,6 @@
 import bpy
 from bpy.props import *
-from .. base import SimulationNode
+from .. base import SimulationNode, FunctionNode
 from .. node_builder import NodeBuilder
 
 
@@ -38,6 +38,15 @@ class CustomEventNode(bpy.types.Node, SimulationNode):
 
     def declaration(self, builder: NodeBuilder):
         builder.fixed_input("condition", "Condition", "Boolean")
+        builder.fixed_input("time_factor", "Time Factor", "Float", default=1.0)
         builder.execute_input("execute_on_event", "Execute on Event", "execute_on_event__prop")
 
         builder.influences_output("event", "Event")
+
+
+class EventFilterEndTimeNode(bpy.types.Node, FunctionNode):
+    bl_idname = "fn_EventFilterEndTimeNode"
+    bl_label = "Event Filter End Time"
+
+    def declaration(self, builder: NodeBuilder):
+        builder.fixed_output("end_time", "End Time", "Float")
diff --git a/source/blender/functions/FN_multi_function_common_contexts.h b/source/blender/functions/FN_multi_function_common_contexts.h
index 15a329f7d63..5dbb94b6611 100644
--- a/source/blender/functions/FN_multi_function_common_contexts.h
+++ b/source/blender/functions/FN_multi_function_common_contexts.h
@@ -40,6 +40,11 @@ class EmitterTimeInfoContext {
   int step;
 };
 
+class EventFilterEndTimeContext {
+ public:
+  float end_time;
+};
+
 }  // namespace FN
 
 #endif /* __FN_MULTI_FUNCTION_COMMON_CONTEXTS_H__ */
diff --git a/source/blender/functions/FN_multi_function_context.h b/source/blender/functions/FN_multi_function_context.h
index 05a531435c5..b672749ec0f 100644
--- a/source/blender/functions/FN_multi_function_context.h
+++ b/source/blender/functions/FN_multi_function_context.h
@@ -103,8 +103,13 @@ class MFContextBuilder : BLI::NonCopyable, BLI::NonMovable {
 
   template<typename T> void add_global_context(const T &context)
   {
-    m_global_contexts.m_ids.append(BLI::get_class_id<T>());
-    m_global_contexts.m_contexts.append((const void *)&context);
+    this->add_global_context(BLI::get_class_id<T>(), (const void *)&context);
+  }
+
+  void add_global_context(BLI::class_id_t id, const void *context)
+  {
+    m_global_contexts.m_ids.append(id);
+    m_global_contexts.m_contexts.append(context);
   }
 };
 
diff --git a/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc b/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc
index a729c21a799..f28c3039a70 100644
--- a/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc
+++ b/source/blender/functions/intern/inlined_tree_multi_function_network/mappings_nodes.cc
@@ -532,6 +532,11 @@ static void INSERT_node_instance_identifier(VNodeMFNetworkBuilder &builder)
   builder.set_constructed_matching_fn<MF_ConstantValue<std::string>>(std::move(identifier));
 }
 
+static void INSERT_event_filter_end_time(VNodeMFNetworkBuilder &builder)
+{
+  builder.set_constructed_matching_fn<MF_EventFilterEndTime>();
+}
+
 void add_inlined_tree_node_mapping_info(VTreeMultiFunctionMappings &mappings)
 {
   mappings.xnode_inserters.add_new("fn_CombineColorNode", INSERT_combine_color);
@@ -606,6 +611,7 @@ void add_inlined_tree_node_mapping_info(VTreeMultiFunctionMappings &mappings)
   mappings.xnode_inserters.add_new("fn_JoinTextListNode", INSERT_join_text_list);
   mappings.xnode_inserters.add_new("fn_NodeInstanceIdentifierNode",
                                    INSERT_node_instance_identifier);
+  mappings.xnode_inserters.add_new("fn_EventFilterEndTimeNode", INSERT_event_filter_end_time);
 }
 
 };  // namespace FN
diff --git a/source/blender/functions/intern/multi_function_common_contexts.cc b/source/blender/functions/intern/multi_function_common_contexts.cc
index 4e1ae6c5b8f..553cc8c331e 100644
--- a/source/blender/functions/intern/multi_function_common_contexts.cc
+++ b/source/blender/functions/intern/multi_function_common_contexts.cc
@@ -9,3 +9,4 @@ BLI_CREATE_CLASS_ID(FN::ParticleAttributesContext)
 BLI_CREATE_CLASS_ID(BKE::IDHandleLookup)
 BLI_CREATE_CLASS_ID(BKE::IDDataCache)
 BLI_CREATE_CLASS_ID(FN::EmitterTimeInfoContext)
+BLI_CREATE_CLASS_ID(FN::EventFilterEndTimeContext)
diff --git a/source/blender/functions/intern/multi_functions/particles.cc b/source/blender/functions/intern/multi_functions/particles.cc
index 7439c8f0b24..9212c9b8fa4 100644
--- a/source/blender/functions/intern/multi_functions/particles.cc
+++ b/source/blender/functions/intern/multi_functions/particles.cc
@@ -79,4 +79,24 @@ void MF_EmitterTimeInfo::call(IndexMask mask, MFParams params, MFContext context
   }
 }
 
+MF_EventFilterEndTime::MF_EventFilterEndTime()
+{
+  MFSignatureBuilder signature = this->get_builder("Event Filter End Time");
+  signature.use_global_context<EventFilterEndTimeContext>();
+  signature.single_output<float>("End Time");
+}
+
+void MF_EventFilterEndTime::call(IndexMask mask, MFParams params, MFContext context) const
+{
+  MutableArrayRef<float> end_times = params.uninitialized_single_output<float>(0, "End Time");
+
+  auto *time_context = context.try_find_global<EventFilterEndTimeContext>();
+  if (time_context == nullptr) {
+    end_times.fill_indices(mask.indices(), 0.0f);
+  }
+  else {
+    end_times.fill_indices(mask.indices(), time_context->end_time);
+  }
+}
+
 }  // namespace FN
diff --git a/source/blender/functions/intern/multi_functions/particles.h b/source/blender/functions/intern/multi_functions/particles.h
index 3f92030f140..ca942bc2e9b 100644
--- a/source/blender/functions/intern/multi_functions/particles.h
+++ b/source/blender/functions/intern/multi_functions/particles.h
@@ -19,4 +19,10 @@ class MF_EmitterTimeInfo final : public MultiFunction {
   void call(IndexMask mask, MFParams params, MFContext context) const override;
 };
 
+class MF_EventFilterEndTime final : public MultiFunction {
+ public:
+  MF_EventFilterEndTime();
+  void call(IndexMask mask, MFParams params, MFContext context) const override;
+};
+
 }  // namespace FN
diff --git a/source/blender/simulations/bparticles/events.cpp b/source/blender/simulations/bparticles/events.cpp
index cfe78d2ea62..b98b6ad1e85 100644
--- a/source/blender/simulations/bparticles/events.cpp
+++ b/source/blender/simulations/bparticles/events.cpp
@@ -61,35 +61,27 @@ void AgeReachedEvent::execute(EventExecuteInterface &interface)
 
 void CustomEvent::filter(EventFilterInterface &interface)
 {
-  auto was_activated_before = interface.attributes().get<bool>(m_is_triggered_attribute);
-
-  LargeScopedVector<uint> pindices_to_check;
-  pindices_to_check.reserve(interface.index_mask().indices_amount());
-
-  for (uint pindex : interface.index_mask().indices()) {
-    if (!was_activated_before[pindex]) {
-      pindices_to_check.append(pindex);
-    }
-  }
+  FN::EventFilterEndTimeContext end_time_context = {interface.step_end_time()};
 
   auto inputs = ParticleFunctionResult::Compute(
-      *m_inputs_fn, pindices_to_check.as_ref(), interface.attributes());
+      m_inputs_fn,
+      interface.index_mask(),
+      interface.attributes(),
+      {BLI::get_class_id<FN::EventFilterEndTimeContext>()},
+      {(const void *)&end_time_context});
 
-  for (uint pindex : pindices_to_check) {
+  for (uint pindex : interface.index_mask().indices()) {
     bool condition = inputs.get_single<bool>("Condition", 0, pindex);
     if (condition) {
-      interface.trigger_particle(pindex, 0.0f);
+      float time_factor = inputs.get_single<float>("Time Factor", 1, pindex);
+      time_factor = std::min(std::max(time_factor, 0.0f), 1.0f);
+      interface.trigger_particle(pindex, time_factor);
     }
   }
 }
 
 void CustomEvent::execute(EventExecuteInterface &interface)
 {
-  auto was_activated_before = interface.attributes().get<bool>(m_is_triggered_attribute);
-  for (uint pindex : interface.pindices()) {
-    was_activated_before[pindex] = true;
-  }
-
   m_action.execute_from_event(interface);
 }
 
diff --git a/source/blender/simulations/bparticles/events.hpp b/source/blender/simulations/bparticles/events.hpp
index ab8a44b2217..e80210db4fc 100644
--- a/source/blender/simulations/bparticles/events.hpp
+++ b/source/blender/simulations/bparticles/events.hpp
@@ -36,15 +36,12 @@ class AgeReachedEvent : public Event {
 
 class CustomEvent : public Event {
  private:
-  std::string m_is_triggered_attribute;
-  ParticleFunction *m_inputs_fn;
+  const ParticleFunction &m_inputs_fn;
   ParticleAction &m_action;
 
  public:
-  CustomEvent(StringRef is_triggered_attribute,
-              ParticleFunction *inputs_fn,
-              ParticleAction &action)
-      : m_is_triggered_attribute(is_triggered_attribute), m_inputs_fn(inputs_fn), m_action(action)
+  CustomEvent(const ParticleFunction &inputs_fn, ParticleAction &action)
+      : m_inputs_fn(inputs_fn), m_action(action)
   {
   }
 
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index 926b3e8f79e..c9586a9263a 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -1024,16 +1024,9 @@ static void PARSE_custom_event(XNodeInfluencesBuilder &builder)
   }
 
   ArrayRef<std::string> system_names = builder.find_target_system_names(0, "Event");
-
-  std::string is_triggered_attribute = builder.node_identifier();
-  bool attribute_added = builder.try_add_attribute<bool>(
-      system_names, is_triggered_attribute, false);
-  if (!attribute_added) {
-    return;
-  }
-
   ParticleAction &action = builder.build_action_list("Execute on Event", system_names);
-  Event &event = builder.construct<CustomEvent>(is_triggered_attribute, inputs_fn, action);
+
+  Event &event = builder.construct<CustomEvent>(*inputs_fn, action);
   builder.add_event(system_names, event);
 }
 
diff --git a/source/blender/simulations/bparticles/particle_function.cpp b/source/blender/simulations/bparticles/particle_function.cpp
index 08abe15578a..7654e1dd562 100644

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list