diff options
author | Hans Goudey <h.goudey@me.com> | 2020-12-02 15:35:07 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2020-12-02 17:38:47 +0300 |
commit | 600fb28b629598af2537c542e7f3f76ba0e94389 (patch) | |
tree | db944815f74d9c81b48095f4d30402080c9192d6 /source/blender/nodes/geometry | |
parent | fc4a853846123ed320914df7f78340ec95efc97e (diff) |
Geometry Nodes: active modifier + geometry nodes editor
This commit adds functions to set and get the object's active
modifier, which is stored as a flag in the ModifierData struct,
similar to constraints. This will be used to set the context in
the node editor. There are no visible changes in this commit.
Similar to how the node editor context works for materials, this commit
makes the node group displayed in the node editor depend on the active
object and its active modifier. To keep the node group from changing,
just pin the node group in the header.
* Shortcuts performed while there is an active modifier will affect
only that modifier (the exception is the A to expand the modifiers).
* Clicking anywhere on the empty space in a modifier's panel will make it active.
These changes require some refactoring of object modifier code. First
is splitting up the modifier property invoke callback, which now needs
to be able to get the active modifier separately from the hovered
modifier for the different operators.
Second is a change to removing modifiers, where there is now a separate
function to remove a modifier from an object's list, in order to handle
changing the active.
Finally, the panel handler needs a small tweak so that this "click in panel"
event can be handled afterwards.
Diffstat (limited to 'source/blender/nodes/geometry')
-rw-r--r-- | source/blender/nodes/geometry/node_geometry_tree.cc | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/source/blender/nodes/geometry/node_geometry_tree.cc b/source/blender/nodes/geometry/node_geometry_tree.cc index d4a9805f311..69f9f7fb4ed 100644 --- a/source/blender/nodes/geometry/node_geometry_tree.cc +++ b/source/blender/nodes/geometry/node_geometry_tree.cc @@ -20,16 +20,49 @@ #include "NOD_geometry.h" +#include "BKE_context.h" #include "BKE_node.h" +#include "BKE_object.h" #include "BLT_translation.h" +#include "DNA_modifier_types.h" #include "DNA_node_types.h" +#include "DNA_space_types.h" #include "RNA_access.h" bNodeTreeType *ntreeType_Geometry; +static void geometry_node_tree_get_from_context(const bContext *C, + bNodeTreeType *UNUSED(treetype), + bNodeTree **r_ntree, + ID **r_id, + ID **r_from) +{ + ViewLayer *view_layer = CTX_data_view_layer(C); + Object *ob = OBACT(view_layer); + + if (ob == nullptr) { + return; + } + + const ModifierData *md = BKE_object_active_modifier(ob); + + if (md == nullptr) { + return; + } + + if (md->type == eModifierType_Nodes) { + NodesModifierData *nmd = (NodesModifierData *)md; + if (nmd->node_group != nullptr) { + *r_from = &ob->id; + *r_id = &ob->id; + *r_ntree = nmd->node_group; + } + } +} + void register_node_tree_type_geo(void) { bNodeTreeType *tt = ntreeType_Geometry = static_cast<bNodeTreeType *>( @@ -41,5 +74,7 @@ void register_node_tree_type_geo(void) strcpy(tt->ui_description, N_("Geometry nodes")); tt->rna_ext.srna = &RNA_GeometryNodeTree; + tt->get_from_context = geometry_node_tree_get_from_context; + ntreeTypeAdd(tt); } |