Geometry Nodes: add simulation support #104924

Closed
Hans Goudey wants to merge 211 commits from geometry-nodes-simulation into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
2 changed files with 9 additions and 14 deletions
Showing only changes of commit 97df619be7 - Show all commits

View File

@ -13,7 +13,6 @@ NODE_STORAGE_FUNCS(NodeGeometrySimulationInput);
static void node_declare(NodeDeclarationBuilder &b) static void node_declare(NodeDeclarationBuilder &b)
{ {
b.add_input<decl::Bool>(N_("Run"));
b.add_input<decl::Geometry>(N_("Geometry")); b.add_input<decl::Geometry>(N_("Geometry"));
b.add_output<decl::Float>(N_("Delta Time")); b.add_output<decl::Float>(N_("Delta Time"));
@ -35,9 +34,6 @@ static void node_geo_exec(GeoNodeExecParams params)
const float scene_ctime = BKE_scene_ctime_get(scene); const float scene_ctime = BKE_scene_ctime_get(scene);
const int scene_frame = int(scene_ctime); const int scene_frame = int(scene_ctime);
/* TODO: Somehow use "Run" input. We also need to pass through the simulation state directly to
* the output node on the first frame the "Run" input is true. */
const GeoNodesLFUserData &lf_data = *params.user_data(); const GeoNodesLFUserData &lf_data = *params.user_data();
bke::ComputeCaches &all_caches = *lf_data.modifier_data->cache_per_frame; bke::ComputeCaches &all_caches = *lf_data.modifier_data->cache_per_frame;
const bke::SimulationCache *cache = all_caches.lookup_context(lf_data.compute_context->hash()); const bke::SimulationCache *cache = all_caches.lookup_context(lf_data.compute_context->hash());

View File

@ -16,7 +16,7 @@ NODE_STORAGE_FUNCS(NodeGeometrySimulationOutput);
static void node_declare(NodeDeclarationBuilder &b) static void node_declare(NodeDeclarationBuilder &b)
{ {
b.add_input<decl::Bool>(N_("Stop")); b.add_input<decl::Bool>(N_("Run"));
b.add_input<decl::Geometry>(N_("Geometry")); b.add_input<decl::Geometry>(N_("Geometry"));
b.add_output<decl::Bool>(N_("Started")); b.add_output<decl::Bool>(N_("Started"));
b.add_output<decl::Bool>(N_("Ended")); b.add_output<decl::Bool>(N_("Ended"));
@ -38,7 +38,7 @@ static void node_init(bNodeTree * /*tree*/, bNode *node)
static void node_geo_exec(GeoNodeExecParams params) static void node_geo_exec(GeoNodeExecParams params)
{ {
if (params.lazy_require_input("Stop")) { if (params.lazy_require_input("Run")) {
return; return;
} }
@ -51,7 +51,6 @@ static void node_geo_exec(GeoNodeExecParams params)
bke::ComputeCaches &all_caches = *lf_data.modifier_data->cache_per_frame; bke::ComputeCaches &all_caches = *lf_data.modifier_data->cache_per_frame;
bke::SimulationCache &cache = all_caches.ensure_for_context(lf_data.compute_context->hash()); bke::SimulationCache &cache = all_caches.ensure_for_context(lf_data.compute_context->hash());
/* TODO: Retrieve "started" from "run" socket on simulation input node? */
if (cache.geometry_per_frame.is_empty()) { if (cache.geometry_per_frame.is_empty()) {
if (params.lazy_output_is_required("Started")) { if (params.lazy_output_is_required("Started")) {
params.set_output("Started", false); params.set_output("Started", false);
@ -66,8 +65,13 @@ static void node_geo_exec(GeoNodeExecParams params)
} }
} }
const bool stop = params.get_input<bool>("Stop"); const bool run = params.get_input<bool>("Run");
if (stop) { if (run) {
if (params.lazy_output_is_required("Ended")) {
params.set_output("Ended", false);
}
}
else {
if (params.lazy_output_is_required("Ended")) { if (params.lazy_output_is_required("Ended")) {
params.set_output("Ended", true); params.set_output("Ended", true);
} }
@ -77,11 +81,6 @@ static void node_geo_exec(GeoNodeExecParams params)
return; return;
} }
} }
else {
if (params.lazy_output_is_required("Ended")) {
params.set_output("Ended", false);
}
}
if (const bke::GeometryCacheValue *data = cache.value_at_time(scene_frame)) { if (const bke::GeometryCacheValue *data = cache.value_at_time(scene_frame)) {
params.set_output("Geometry", data->geometry_set); params.set_output("Geometry", data->geometry_set);