Blender V5.3
node_geometry_tree.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include <cstring>
6
7#include "MEM_guardedalloc.h"
8
9#include "NOD_geometry.hh"
10
11#include "BKE_context.hh"
12#include "BKE_layer.hh"
13#include "BKE_node.hh"
14#include "BKE_object.hh"
15
16#include "DNA_modifier_types.h"
17#include "DNA_node_types.h"
18#include "DNA_space_types.h"
19
20#include "RNA_prototypes.hh"
21
22#include "UI_resources.hh"
23
24#include "BLT_translation.hh"
25
26#include "node_common.h"
27
28namespace blender {
29
31
33 bke::bNodeTreeType * /*treetype*/,
34 bNodeTree **r_ntree,
35 ID **r_id,
36 ID **r_from)
37{
38 const SpaceNode *snode = CTX_wm_space_node(C);
41 *r_ntree = snode->selected_node_group;
42 return;
43 }
44 *r_ntree = nullptr;
45 return;
46 }
47
48 const Main *bmain = CTX_data_main(C);
49 const Scene *scene = CTX_data_scene(C);
50 ViewLayer *view_layer = CTX_data_view_layer(C);
51 BKE_view_layer_synced_ensure(*bmain, scene, view_layer);
53
54 if (ob == nullptr) {
55 return;
56 }
57
59
60 if (md == nullptr) {
61 return;
62 }
63
64 if (md->type == eModifierType_Nodes) {
65 const NodesModifierData *nmd = reinterpret_cast<const NodesModifierData *>(md);
66 if (nmd->node_group != nullptr && !ID_MISSING(nmd->node_group)) {
67 *r_from = &ob->id;
68 *r_id = &ob->id;
69 *r_ntree = nmd->node_group;
70 }
71 }
72}
73
75{
77
78 /* Needed to give correct types to reroutes. */
80}
81
82static void foreach_nodeclass(void *calldata, bke::bNodeClassCallback func)
83{
84 func(calldata, NODE_CLASS_INPUT, N_("Input"));
85 func(calldata, NODE_CLASS_GEOMETRY, N_("Geometry"));
86 func(calldata, NODE_CLASS_ATTRIBUTE, N_("Attribute"));
87 func(calldata, NODE_CLASS_OP_COLOR, N_("Color"));
88 func(calldata, NODE_CLASS_OP_VECTOR, N_("Vector"));
89 func(calldata, NODE_CLASS_CONVERTER, N_("Converter"));
90 func(calldata, NODE_CLASS_LAYOUT, N_("Layout"));
91}
92
95{
96 /* Geometry, string, object, material, texture and collection sockets can only be connected to
97 * themselves. The other types can be converted between each other. */
100 {
101 return true;
102 }
103 if (ELEM(type_a, SOCK_FLOAT, SOCK_VECTOR) && type_b == SOCK_ROTATION) {
104 /* Floats and vectors implicitly convert to rotations. */
105 return true;
106 }
107
108 /* Support implicit conversions between matrices and rotations. */
109 if (type_a == SOCK_MATRIX && type_b == SOCK_ROTATION) {
110 return true;
111 }
112 if (type_a == SOCK_ROTATION && type_b == SOCK_MATRIX) {
113 return true;
114 }
115
116 if (type_a == SOCK_ROTATION && type_b == SOCK_VECTOR) {
117 /* Rotations implicitly convert to vectors. */
118 return true;
119 }
120 return type_a == type_b;
121}
122
124 bke::bNodeSocketType *socket_type)
125{
126 return bke::node_is_static_socket_type(*socket_type) &&
127 (ELEM(socket_type->type,
130 SOCK_RGBA,
134 SOCK_INT,
141 SOCK_MENU) ||
143}
144
146{
147 bke::bNodeTreeType *tt = ntreeType_Geometry = MEM_new<bke::bNodeTreeType>(__func__);
148 tt->type = NTREE_GEOMETRY;
149 tt->idname = "GeometryNodeTree"_ustr;
150 tt->group_idname = "GeometryNodeGroup"_ustr;
151 tt->ui_name = N_("Geometry Node Editor");
152 tt->ui_icon = ICON_GEOMETRY_NODES;
153 tt->ui_description = N_("Advanced geometry editing and tools creation using nodes");
154 tt->asset_catalog_path_prefix = "Geometry Nodes";
155 tt->rna_ext.srna = RNA_GeometryNodeTree;
161
163}
164
166{
167 const bke::bNodeSocketType *typeinfo = socket.socket_typeinfo();
168 BLI_assert(typeinfo != nullptr);
169
170 if (typeinfo->type != SOCK_BOOLEAN) {
171 return false;
172 }
173 return (socket.flag & NODE_INTERFACE_SOCKET_LAYER_SELECTION) != 0;
174}
175
176} // namespace blender
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:484
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
#define NODE_CLASS_OP_VECTOR
Definition BKE_node.hh:481
#define NODE_CLASS_LAYOUT
Definition BKE_node.hh:494
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:480
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define NODE_CLASS_ATTRIBUTE
Definition BKE_node.hh:493
General operations, lookup, etc. for blender objects.
#define ID_MISSING(_id)
Definition DNA_ID.h:695
Read Blender memory allocation and freeing.
#define C
Definition RandGen.cpp:29
#define ELEM(...)
void node_tree_set_output(bNodeTree &ntree)
Definition node.cc:5238
void node_tree_type_add(bNodeTreeType &nt)
Definition node.cc:2844
void(*)(void *calldata, int nclass, StringRefNull name) bNodeClassCallback
Definition BKE_node.hh:523
bool node_is_static_socket_type(const bNodeSocketType &stype)
Definition node.cc:3483
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
bke::bNodeTreeType * ntreeType_Geometry
static bool geometry_node_tree_socket_type_valid(bke::bNodeTreeType *, bke::bNodeSocketType *socket_type)
ViewLayer * CTX_data_view_layer(const bContext *C)
bool is_layer_selection_field(const bNodeTreeInterfaceSocket &socket)
ModifierData * BKE_object_active_modifier(const Object *ob)
Definition object.cc:1427
void register_node_tree_type_geo()
static bool geometry_node_tree_validate_link(eNodeSocketDatatype type_a, eNodeSocketDatatype type_b)
bool BKE_view_layer_synced_ensure(const Main &bmain, const Scene *scene, ViewLayer *view_layer)
SpaceNode * CTX_wm_space_node(const bContext *C)
static void geometry_node_tree_get_from_context(const bContext *C, bke::bNodeTreeType *, bNodeTree **r_ntree, ID **r_id, ID **r_from)
Main * CTX_data_main(const bContext *C)
void ntree_update_reroute_nodes(bNodeTree *ntree)
Scene * CTX_data_scene(const bContext *C)
static void foreach_nodeclass(void *calldata, bke::bNodeClassCallback func)
static void geometry_node_tree_update(bNodeTree *ntree)
struct bNodeTree * selected_node_group
eNodeTree_Type type
Defines a socket type.
Definition BKE_node.hh:163
eNodeSocketDatatype type
Definition BKE_node.hh:198
bool(*) valid_socket_type(bNodeTreeType *ntreetype, bNodeSocketType *socket_type)
Definition BKE_node.hh:569
void(*) get_from_context(const bContext *C, bNodeTreeType *ntreetype, bNodeTree **r_ntree, ID **r_id, ID **r_from)
Definition BKE_node.hh:554
void(*) update(bNodeTree *ntree)
Definition BKE_node.hh:564
void(*) foreach_nodeclass(void *calldata, bNodeClassCallback func)
Definition BKE_node.hh:550
std::optional< std::string > asset_catalog_path_prefix
Definition BKE_node.hh:546
bool(*) validate_link(eNodeSocketDatatype from, eNodeSocketDatatype to)
Definition BKE_node.hh:566
#define N_(msgid)