[Bf-blender-cvs] [10c73f79fa1] particle-solver-dev: simple collision object node

Jacques Lucke noreply at git.blender.org
Tue Mar 10 10:48:27 CET 2020


Commit: 10c73f79fa18aa25b92f2eb9d19ac097541f22e7
Author: Jacques Lucke
Date:   Mon Mar 9 16:05:24 2020 +0100
Branches: particle-solver-dev
https://developer.blender.org/rB10c73f79fa18aa25b92f2eb9d19ac097541f22e7

simple collision object node

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

A	release/scripts/startup/nodes/bparticle_nodes/collision_object.py
M	source/blender/simulations/bparticles/node_frontend.cpp
M	source/blender/simulations/bparticles/simulate.cpp
M	source/blender/simulations/bparticles/simulate.hpp

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

diff --git a/release/scripts/startup/nodes/bparticle_nodes/collision_object.py b/release/scripts/startup/nodes/bparticle_nodes/collision_object.py
new file mode 100644
index 00000000000..31cdd1f3b34
--- /dev/null
+++ b/release/scripts/startup/nodes/bparticle_nodes/collision_object.py
@@ -0,0 +1,11 @@
+import bpy
+from .. base import SimulationNode
+from .. node_builder import NodeBuilder
+
+class CollisionObjectNode(bpy.types.Node, SimulationNode):
+    bl_idname = "fn_CollisionObjectNode"
+    bl_label = "Collision Object"
+
+    def declaration(self, builder: NodeBuilder):
+        builder.fixed_input("object", "Object", "Object", display_name=False)
+        builder.influences_output("collider", "Collider")
diff --git a/source/blender/simulations/bparticles/node_frontend.cpp b/source/blender/simulations/bparticles/node_frontend.cpp
index f3dc4b7cd9b..63aed77bdec 100644
--- a/source/blender/simulations/bparticles/node_frontend.cpp
+++ b/source/blender/simulations/bparticles/node_frontend.cpp
@@ -66,6 +66,7 @@ class InfluencesCollector {
   StringMultiMap<Event *> m_events;
   StringMultiMap<OffsetHandler *> m_offset_handlers;
   StringMap<AttributesInfoBuilder *> m_attributes;
+  StringMultiMap<Object *> m_collision_objects;
 };
 
 class FunctionTreeData {
@@ -694,6 +695,16 @@ class FNodeInfluencesBuilder {
     }
   }
 
+  void add_collision_object(ArrayRef<std::string> system_names, Object *object)
+  {
+    for (StringRef system_name : system_names) {
+      if (!m_influences_collector.m_collision_objects.lookup_default(system_name)
+               .contains(object)) {
+        m_influences_collector.m_collision_objects.add(system_name, object);
+      }
+    }
+  }
+
   std::string node_identifier()
   {
     std::stringstream ss;
@@ -1033,6 +1044,24 @@ static void PARSE_always_execute(FNodeInfluencesBuilder &builder)
   builder.add_offset_handler(system_names, offset_handler);
 }
 
+static void PARSE_collision_object(FNodeInfluencesBuilder &builder)
+{
+  ArrayRef<std::string> system_names = builder.find_target_system_names(0, "Collider");
+
+  Optional<NamedGenericTupleRef> inputs = builder.compute_inputs({0});
+  if (!inputs.has_value()) {
+    return;
+  }
+
+  ObjectIDHandle object_handle = inputs->relocate_out<ObjectIDHandle>(0, "Object");
+  Object *object = builder.id_handle_lookup().lookup(object_handle);
+  if (object == nullptr || object->type != OB_MESH) {
+    return;
+  }
+
+  builder.add_collision_object(system_names, object);
+}
+
 static StringMap<ParseNodeCallback, BLI::RawAllocator> create_node_parsers_map()
 {
   StringMap<ParseNodeCallback, BLI::RawAllocator> map;
@@ -1047,6 +1076,7 @@ static StringMap<ParseNodeCallback, BLI::RawAllocator> create_node_parsers_map()
   map.add_new("fn_CustomEventNode", PARSE_custom_event);
   map.add_new("fn_AlwaysExecuteNode", PARSE_always_execute);
   map.add_new("fn_ForceNode", PARSE_custom_force);
+  map.add_new("fn_CollisionObjectNode", PARSE_collision_object);
   return map;
 }
 
@@ -1161,6 +1191,7 @@ class NodeTreeStepSimulator : public StepSimulator {
           integrators.lookup(name),
           influences_collector.m_events.lookup_default(name),
           influences_collector.m_offset_handlers.lookup_default(name),
+          influences_collector.m_collision_objects.lookup_default(name),
       };
       systems_to_simulate.add_new(name, type_info);
     }
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp
index 22d3752343f..6538242901d 100644
--- a/source/blender/simulations/bparticles/simulate.cpp
+++ b/source/blender/simulations/bparticles/simulate.cpp
@@ -430,6 +430,11 @@ void simulate_particles(SimulationState &simulation_state,
 {
   SCOPED_TIMER(__func__);
 
+  systems_to_simulate.foreach_item([](StringRef name, ParticleSystemInfo &system_info) {
+    system_info.collision_objects.print_as_lines(
+        name, [](Object *object) { std::cout << object->id.name; });
+  });
+
   ParticlesState &particles_state = simulation_state.particles();
   FloatInterval simulation_time_span = simulation_state.time().current_update_time();
 
diff --git a/source/blender/simulations/bparticles/simulate.hpp b/source/blender/simulations/bparticles/simulate.hpp
index a3c7f120925..3c7eae9a9e9 100644
--- a/source/blender/simulations/bparticles/simulate.hpp
+++ b/source/blender/simulations/bparticles/simulate.hpp
@@ -6,12 +6,15 @@
 #include "offset_handler_interface.hpp"
 #include "emitter_interface.hpp"
 
+#include "DNA_object_types.h"
+
 namespace BParticles {
 
 struct ParticleSystemInfo {
   Integrator *integrator;
   ArrayRef<Event *> events;
   ArrayRef<OffsetHandler *> offset_handlers;
+  ArrayRef<Object *> collision_objects;
 };
 
 void simulate_particles(SimulationState &state,



More information about the Bf-blender-cvs mailing list