Blender V5.0
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
29
31 blender::bke::bNodeTreeType * /*treetype*/,
32 bNodeTree **r_ntree,
33 ID **r_id,
34 ID **r_from)
35{
36 const SpaceNode *snode = CTX_wm_space_node(C);
39 *r_ntree = snode->selected_node_group;
40 return;
41 }
42 *r_ntree = nullptr;
43 return;
44 }
45
46 const Scene *scene = CTX_data_scene(C);
47 ViewLayer *view_layer = CTX_data_view_layer(C);
48 BKE_view_layer_synced_ensure(scene, view_layer);
50
51 if (ob == nullptr) {
52 return;
53 }
54
56
57 if (md == nullptr) {
58 return;
59 }
60
61 if (md->type == eModifierType_Nodes) {
62 const NodesModifierData *nmd = reinterpret_cast<const NodesModifierData *>(md);
63 if (nmd->node_group != nullptr) {
64 *r_from = &ob->id;
65 *r_id = &ob->id;
66 *r_ntree = nmd->node_group;
67 }
68 }
69}
70
72{
74
75 /* Needed to give correct types to reroutes. */
77}
78
79static void foreach_nodeclass(void *calldata, blender::bke::bNodeClassCallback func)
80{
81 func(calldata, NODE_CLASS_INPUT, N_("Input"));
82 func(calldata, NODE_CLASS_GEOMETRY, N_("Geometry"));
83 func(calldata, NODE_CLASS_ATTRIBUTE, N_("Attribute"));
84 func(calldata, NODE_CLASS_OP_COLOR, N_("Color"));
85 func(calldata, NODE_CLASS_OP_VECTOR, N_("Vector"));
86 func(calldata, NODE_CLASS_CONVERTER, N_("Converter"));
87 func(calldata, NODE_CLASS_LAYOUT, N_("Layout"));
88}
89
92{
93 /* Geometry, string, object, material, texture and collection sockets can only be connected to
94 * themselves. The other types can be converted between each other. */
97 {
98 return true;
99 }
100 if (ELEM(type_a, SOCK_FLOAT, SOCK_VECTOR) && type_b == SOCK_ROTATION) {
101 /* Floats and vectors implicitly convert to rotations. */
102 return true;
103 }
104
105 /* Support implicit conversions between matrices and rotations. */
106 if (type_a == SOCK_MATRIX && type_b == SOCK_ROTATION) {
107 return true;
108 }
109 if (type_a == SOCK_ROTATION && type_b == SOCK_MATRIX) {
110 return true;
111 }
112
113 if (type_a == SOCK_ROTATION && type_b == SOCK_VECTOR) {
114 /* Rotations implicitly convert to vectors. */
115 return true;
116 }
117 return type_a == type_b;
118}
119
122{
123 return blender::bke::node_is_static_socket_type(*socket_type) &&
124 (ELEM(socket_type->type,
127 SOCK_RGBA,
131 SOCK_INT,
138 SOCK_MENU) ||
139 ELEM(socket_type->type, SOCK_BUNDLE, SOCK_CLOSURE));
140}
141
143{
144 blender::bke::bNodeTreeType *tt = ntreeType_Geometry = MEM_new<blender::bke::bNodeTreeType>(
145 __func__);
146 tt->type = NTREE_GEOMETRY;
147 tt->idname = "GeometryNodeTree";
148 tt->group_idname = "GeometryNodeGroup";
149 tt->ui_name = N_("Geometry Node Editor");
150 tt->ui_icon = ICON_GEOMETRY_NODES;
151 tt->ui_description = N_("Advanced geometry editing and tools creation using nodes");
152 tt->rna_ext.srna = &RNA_GeometryNodeTree;
158
160}
161
163{
164 const blender::bke::bNodeSocketType *typeinfo = socket.socket_typeinfo();
165 BLI_assert(typeinfo != nullptr);
166
167 if (typeinfo->type != SOCK_BOOLEAN) {
168 return false;
169 }
170 return (socket.flag & NODE_INTERFACE_SOCKET_LAYER_SELECTION) != 0;
171}
SpaceNode * CTX_wm_space_node(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
ViewLayer * CTX_data_view_layer(const bContext *C)
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
Object * BKE_view_layer_active_object_get(const ViewLayer *view_layer)
#define NODE_CLASS_CONVERTER
Definition BKE_node.hh:453
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:461
#define NODE_CLASS_OP_VECTOR
Definition BKE_node.hh:450
#define NODE_CLASS_LAYOUT
Definition BKE_node.hh:463
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:449
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#define NODE_CLASS_ATTRIBUTE
Definition BKE_node.hh:462
General operations, lookup, etc. for blender objects.
ModifierData * BKE_object_active_modifier(const Object *ob)
#define BLI_assert(a)
Definition BLI_assert.h:46
#define ELEM(...)
@ eModifierType_Nodes
@ NODE_INTERFACE_SOCKET_LAYER_SELECTION
@ NTREE_GEOMETRY
eNodeSocketDatatype
@ SOCK_INT
@ SOCK_VECTOR
@ SOCK_CLOSURE
@ SOCK_BOOLEAN
@ SOCK_MATERIAL
@ SOCK_MATRIX
@ SOCK_FLOAT
@ SOCK_IMAGE
@ SOCK_COLLECTION
@ SOCK_BUNDLE
@ SOCK_GEOMETRY
@ SOCK_ROTATION
@ SOCK_OBJECT
@ SOCK_STRING
@ SOCK_RGBA
@ SOCK_MENU
@ SNODE_GEOMETRY_TOOL
Read Guarded memory(de)allocation.
#define C
Definition RandGen.cpp:29
void node_tree_set_output(bNodeTree &ntree)
Definition node.cc:4469
void node_tree_type_add(bNodeTreeType &nt)
Definition node.cc:2340
void(*)(void *calldata, int nclass, StringRefNull name) bNodeClassCallback
Definition BKE_node.hh:492
bool node_is_static_socket_type(const bNodeSocketType &stype)
Definition node.cc:2826
void ntree_update_reroute_nodes(bNodeTree *ntree)
static void foreach_nodeclass(void *calldata, blender::bke::bNodeClassCallback func)
static void geometry_node_tree_get_from_context(const bContext *C, blender::bke::bNodeTreeType *, bNodeTree **r_ntree, ID **r_id, ID **r_from)
bool is_layer_selection_field(const bNodeTreeInterfaceSocket &socket)
blender::bke::bNodeTreeType * ntreeType_Geometry
static void geometry_node_tree_update(bNodeTree *ntree)
static bool geometry_node_tree_socket_type_valid(blender::bke::bNodeTreeType *, blender::bke::bNodeSocketType *socket_type)
void register_node_tree_type_geo()
static bool geometry_node_tree_validate_link(eNodeSocketDatatype type_a, eNodeSocketDatatype type_b)
static void foreach_nodeclass(void *calldata, blender::bke::bNodeClassCallback func)
StructRNA * srna
Definition DNA_ID.h:414
struct bNodeTree * node_group
struct bNodeTree * selected_node_group
char node_tree_sub_type
Defines a socket type.
Definition BKE_node.hh:158
eNodeSocketDatatype type
Definition BKE_node.hh:193
void(* update)(bNodeTree *ntree)
Definition BKE_node.hh:522
void(* foreach_nodeclass)(void *calldata, bNodeClassCallback func)
Definition BKE_node.hh:507
void(* get_from_context)(const bContext *C, bNodeTreeType *ntreetype, bNodeTree **r_ntree, ID **r_id, ID **r_from)
Definition BKE_node.hh:511
bool(* validate_link)(eNodeSocketDatatype from, eNodeSocketDatatype to)
Definition BKE_node.hh:524
bool(* valid_socket_type)(bNodeTreeType *ntreetype, bNodeSocketType *socket_type)
Definition BKE_node.hh:529
#define N_(msgid)