Add some input sockets

This commit is contained in:
Hans Goudey 2022-11-22 21:57:06 -06:00
parent 5aaa435ac7
commit f55f2b5ff4
3 changed files with 49 additions and 3 deletions

View File

@ -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 {

View File

@ -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);
}

View File

@ -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);
}