diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2022-06-29 22:50:35 +0300 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2022-06-29 22:50:35 +0300 |
commit | fa2084ae58a77b1201289b6bedac427f73c762d1 (patch) | |
tree | fd99401eb8e742415f59332d115f0f34699f92b6 /source/blender/nodes/geometry | |
parent | 0ea282f7462070041b2599389ba61c7ef50426b5 (diff) |
Geometry Nodes: Experimental rigid body integration.
This is an exploration of how geometry nodes might be coupled with
rigid bodies and iterative simulations in general. It's a very
rough-and-ready implementation, not meant as a final version, but rather
to prove the possiblity and to find challenging areas where redesign is
needed.
The core additions are:
- Geometry nodes to flag points and/or instances as rigid bodies.
- Depsgraph integration to ensure the necessary order of operations
between modifiers and rigid body pre/post simulation updates.
- Simple cache feature to store arbitrary geometry and loop back into
the next iteration.
Diffstat (limited to 'source/blender/nodes/geometry')
3 files changed, 21 insertions, 2 deletions
diff --git a/source/blender/nodes/geometry/node_geometry_util.cc b/source/blender/nodes/geometry/node_geometry_util.cc index 8f673d2264e..c67cfe77c04 100644 --- a/source/blender/nodes/geometry/node_geometry_util.cc +++ b/source/blender/nodes/geometry/node_geometry_util.cc @@ -45,7 +45,7 @@ bool geo_node_poll_default(bNodeType *UNUSED(ntype), bNodeTree *ntree, const char **r_disabled_hint) { - if (!STREQ(ntree->idname, "GeometryNodeTree")) { + if (!STR_ELEM(ntree->idname, "GeometryNodeTree", "SimulationNodeTree")) { *r_disabled_hint = TIP_("Not a geometry node tree"); return false; } diff --git a/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc b/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc index 0c56b0e9804..e7aa209a099 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc @@ -133,6 +133,18 @@ static void join_components(Span<const VolumeComponent *> src_components, Geomet UNUSED_VARS(src_components, dst_component); } +static void join_components(Span<const SimulationComponent *> src_components, GeometrySet &result) +{ + SimulationComponent &dst_component = result.get_component_for_write<SimulationComponent>(); + + for (const SimulationComponent *src_component : src_components) { + for (const auto &shape : src_component->shapes()) { + dst_component.add_shape(shape); + } + } + join_attributes(to_base_components(src_components), dst_component, {"position"}); +} + template<typename Component> static void join_component_type(Span<GeometrySet> src_geometry_sets, GeometrySet &result) { @@ -156,7 +168,7 @@ static void join_component_type(Span<GeometrySet> src_geometry_sets, GeometrySet InstancesComponent &instances = instances_geometry_set.get_component_for_write<InstancesComponent>(); - if constexpr (is_same_any_v<Component, InstancesComponent, VolumeComponent>) { + if constexpr (is_same_any_v<Component, InstancesComponent, SimulationComponent, VolumeComponent>) { join_components(components, result); } else { @@ -185,6 +197,7 @@ static void node_geo_exec(GeoNodeExecParams params) join_component_type<InstancesComponent>(geometry_sets, geometry_set_result); join_component_type<VolumeComponent>(geometry_sets, geometry_set_result); join_component_type<CurveComponent>(geometry_sets, geometry_set_result); + join_component_type<SimulationComponent>(geometry_sets, geometry_set_result); params.set_output("Geometry", std::move(geometry_set_result)); } diff --git a/source/blender/nodes/geometry/nodes/node_geo_separate_components.cc b/source/blender/nodes/geometry/nodes/node_geo_separate_components.cc index b29ebd0d4d4..124b977f63c 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_separate_components.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_separate_components.cc @@ -12,6 +12,7 @@ static void node_declare(NodeDeclarationBuilder &b) b.add_output<decl::Geometry>(N_("Curve")); b.add_output<decl::Geometry>(N_("Volume")); b.add_output<decl::Geometry>(N_("Instances")); + b.add_output<decl::Geometry>(N_("Simulation")); } static void node_geo_exec(GeoNodeExecParams params) @@ -23,6 +24,7 @@ static void node_geo_exec(GeoNodeExecParams params) GeometrySet volumes; GeometrySet curves; GeometrySet instances; + GeometrySet simulation; if (geometry_set.has<MeshComponent>()) { meshes.add(*geometry_set.get_component_for_read<MeshComponent>()); @@ -39,12 +41,16 @@ static void node_geo_exec(GeoNodeExecParams params) if (geometry_set.has<InstancesComponent>()) { instances.add(*geometry_set.get_component_for_read<InstancesComponent>()); } + if (geometry_set.has<SimulationComponent>()) { + simulation.add(*geometry_set.get_component_for_read<SimulationComponent>()); + } params.set_output("Mesh", meshes); params.set_output("Point Cloud", point_clouds); params.set_output("Curve", curves); params.set_output("Volume", volumes); params.set_output("Instances", instances); + params.set_output("Simulation", simulation); } } // namespace blender::nodes::node_geo_separate_components_cc |