[Bf-blender-cvs] [f55f2b5ff46] geometry-nodes-simulation: Add some input sockets

Hans Goudey noreply at git.blender.org
Thu Nov 24 00:20:06 CET 2022


Commit: f55f2b5ff465e27b35cba5b5aa7c07e772314c4c
Author: Hans Goudey
Date:   Tue Nov 22 21:57:06 2022 -0600
Branches: geometry-nodes-simulation
https://developer.blender.org/rBf55f2b5ff465e27b35cba5b5aa7c07e772314c4c

Add some input sockets

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

M	source/blender/blenkernel/BKE_compute_cache.hh
M	source/blender/nodes/geometry/nodes/node_geo_simulation_input.cc
M	source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc

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

diff --git a/source/blender/blenkernel/BKE_compute_cache.hh b/source/blender/blenkernel/BKE_compute_cache.hh
index 2dc07594a5c..d48ca1254bb 100644
--- a/source/blender/blenkernel/BKE_compute_cache.hh
+++ b/source/blender/blenkernel/BKE_compute_cache.hh
@@ -2,6 +2,8 @@
 
 #pragma once
 
+#include <map>
+
 #include "BLI_compute_context.hh"
 #include "BLI_map.hh"
 
@@ -9,8 +11,33 @@
 
 namespace blender::bke {
 
+struct GeometryCacheValue {
+  int frame;
+  GeometrySet geometry_set;
+};
+
 struct CacheData {
-  Map<int, GeometrySet> geometry_per_frame;
+  Vector<GeometryCacheValue> geometry_per_frame;
+
+  GeometrySet *first_item_before(const int frame)
+  {
+    if (geometry_per_frame.is_empty()) {
+      return nullptr;
+    }
+    if (frame < geometry_per_frame.first().frame) {
+      return nullptr;
+    }
+
+    GeometryCacheValue *last_value = nullptr;
+    for (int i = geometry_per_frame.size() - 1; i > 0; i--) {
+      if (geometry_per_frame[i].frame > frame) {
+        break;
+      }
+      last_value = &geometry_per_frame[i];
+    }
+
+    return last_value ? &last_value->geometry_set : nullptr;
+  }
 };
 
 struct ComputeCaches {
diff --git a/source/blender/nodes/geometry/nodes/node_geo_simulation_input.cc b/source/blender/nodes/geometry/nodes/node_geo_simulation_input.cc
index 5f5bc2c9908..354f6190405 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_simulation_input.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_simulation_input.cc
@@ -10,7 +10,11 @@ namespace blender::nodes::node_geo_simulation_input_cc {
 
 static void node_declare(NodeDeclarationBuilder &b)
 {
+  b.add_input<decl::Bool>(N_("Run"));
   b.add_input<decl::Geometry>(N_("Geometry"));
+
+  b.add_output<decl::Float>(N_("Delta Time"));
+  b.add_output<decl::Float>(N_("Elapsed Time"));
   b.add_output<decl::Geometry>(N_("Geometry"));
 }
 
@@ -32,7 +36,11 @@ static void node_geo_exec(GeoNodeExecParams params)
   if (cache->geometry_per_frame.contains(previous_frame)) {
     GeometrySet geometry_set = cache->geometry_per_frame.lookup(previous_frame);
     params.set_output("Geometry", std::move(geometry_set));
-    // params.set_input_unused("Geometry");
+    params.set_input_unused("Geometry");
+    return;
+  }
+
+  if (params.lazy_require_input("Geometry")) {
     return;
   }
 
@@ -51,5 +59,6 @@ void register_node_type_geo_simulation_input()
   geo_node_type_base(&ntype, GEO_NODE_SIMULATION_INPUT, "Simulation Input", NODE_CLASS_INTERFACE);
   ntype.geometry_node_execute = file_ns::node_geo_exec;
   ntype.declare = file_ns::node_declare;
+  ntype.geometry_node_execute_supports_laziness = true;
   nodeRegisterType(&ntype);
 }
diff --git a/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc b/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc
index 0726ae6d59f..6b280510163 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_simulation_output.cc
@@ -10,7 +10,11 @@ namespace blender::nodes::node_geo_simulation_output_cc {
 
 static void node_declare(NodeDeclarationBuilder &b)
 {
+  b.add_input<decl::Bool>(N_("Stop"));
   b.add_input<decl::Geometry>(N_("Geometry"));
+  b.add_output<decl::Bool>(N_("Started"));
+  b.add_output<decl::Bool>(N_("Ended"));
+  b.add_output<decl::Float>(N_("Elapsed Time"));
   b.add_output<decl::Geometry>(N_("Geometry"));
 }
 
@@ -27,7 +31,11 @@ static void node_geo_exec(GeoNodeExecParams params)
 
   if (cache.geometry_per_frame.contains(scene_frame)) {
     params.set_output("Geometry", cache.geometry_per_frame.lookup(scene_frame));
-    // params.set_input_unused("Geometry");
+    params.set_input_unused("Geometry");
+    return;
+  }
+
+  if (params.lazy_require_input("Geometry")) {
     return;
   }
 
@@ -36,6 +44,7 @@ static void node_geo_exec(GeoNodeExecParams params)
   cache.geometry_per_frame.add_new(scene_frame, geometry_set);
 
   params.set_output("Geometry", std::move(geometry_set));
+  params.set_default_remaining_outputs();
 }
 
 }  // namespace blender::nodes::node_geo_simulation_output_cc
@@ -50,5 +59,6 @@ void register_node_type_geo_simulation_output()
       &ntype, GEO_NODE_SIMULATION_OUTPUT, "Simulation Output", NODE_CLASS_INTERFACE);
   ntype.geometry_node_execute = file_ns::node_geo_exec;
   ntype.declare = file_ns::node_declare;
+  ntype.geometry_node_execute_supports_laziness = true;
   nodeRegisterType(&ntype);
 }



More information about the Bf-blender-cvs mailing list