Blender V4.5
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);
38 *r_ntree = snode->geometry_nodes_tool_tree;
39 return;
40 }
41
42 const Scene *scene = CTX_data_scene(C);
43 ViewLayer *view_layer = CTX_data_view_layer(C);
44 BKE_view_layer_synced_ensure(scene, view_layer);
46
47 if (ob == nullptr) {
48 return;
49 }
50
52
53 if (md == nullptr) {
54 return;
55 }
56
57 if (md->type == eModifierType_Nodes) {
58 const NodesModifierData *nmd = reinterpret_cast<const NodesModifierData *>(md);
59 if (nmd->node_group != nullptr) {
60 *r_from = &ob->id;
61 *r_id = &ob->id;
62 *r_ntree = nmd->node_group;
63 }
64 }
65}
66
68{
70
71 /* Needed to give correct types to reroutes. */
73}
74
75static void foreach_nodeclass(void *calldata, blender::bke::bNodeClassCallback func)
76{
77 func(calldata, NODE_CLASS_INPUT, N_("Input"));
78 func(calldata, NODE_CLASS_GEOMETRY, N_("Geometry"));
79 func(calldata, NODE_CLASS_ATTRIBUTE, N_("Attribute"));
80 func(calldata, NODE_CLASS_OP_COLOR, N_("Color"));
81 func(calldata, NODE_CLASS_OP_VECTOR, N_("Vector"));
82 func(calldata, NODE_CLASS_CONVERTER, N_("Converter"));
83 func(calldata, NODE_CLASS_LAYOUT, N_("Layout"));
84}
85
88{
89 /* Geometry, string, object, material, texture and collection sockets can only be connected to
90 * themselves. The other types can be converted between each other. */
93 {
94 return true;
95 }
96 if (ELEM(type_a, SOCK_FLOAT, SOCK_VECTOR) && type_b == SOCK_ROTATION) {
97 /* Floats and vectors implicitly convert to rotations. */
98 return true;
99 }
100
101 /* Support implicit conversions between matrices and rotations. */
102 if (type_a == SOCK_MATRIX && type_b == SOCK_ROTATION) {
103 return true;
104 }
105 if (type_a == SOCK_ROTATION && type_b == SOCK_MATRIX) {
106 return true;
107 }
108
109 if (type_a == SOCK_ROTATION && type_b == SOCK_VECTOR) {
110 /* Rotations implicitly convert to vectors. */
111 return true;
112 }
113 return type_a == type_b;
114}
115
138
140{
141 blender::bke::bNodeTreeType *tt = ntreeType_Geometry = MEM_new<blender::bke::bNodeTreeType>(
142 __func__);
143 tt->type = NTREE_GEOMETRY;
144 tt->idname = "GeometryNodeTree";
145 tt->group_idname = "GeometryNodeGroup";
146 tt->ui_name = N_("Geometry Node Editor");
147 tt->ui_icon = ICON_GEOMETRY_NODES;
148 tt->ui_description = N_("Geometry nodes");
149 tt->rna_ext.srna = &RNA_GeometryNodeTree;
155
157}
158
160{
161 const blender::bke::bNodeSocketType *typeinfo = socket.socket_typeinfo();
162 BLI_assert(typeinfo != nullptr);
163
164 if (typeinfo->type != SOCK_BOOLEAN) {
165 return false;
166 }
167 return (socket.flag & NODE_INTERFACE_SOCKET_LAYER_SELECTION) != 0;
168}
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:439
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:447
#define NODE_CLASS_OP_VECTOR
Definition BKE_node.hh:436
#define NODE_CLASS_LAYOUT
Definition BKE_node.hh:449
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:435
#define NODE_CLASS_INPUT
Definition BKE_node.hh:433
#define NODE_CLASS_ATTRIBUTE
Definition BKE_node.hh:448
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_TEXTURE
@ 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:4742
void node_tree_type_add(bNodeTreeType &nt)
Definition node.cc:2672
void(*)(void *calldata, int nclass, StringRefNull name) bNodeClassCallback
Definition BKE_node.hh:478
bool node_is_static_socket_type(const bNodeSocketType &stype)
Definition node.cc:3158
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 RNA_types.hh:909
Definition DNA_ID.h:404
struct bNodeTree * node_group
struct bNodeTree * geometry_nodes_tool_tree
char geometry_nodes_type
Defines a socket type.
Definition BKE_node.hh:152
eNodeSocketDatatype type
Definition BKE_node.hh:187
void(* update)(bNodeTree *ntree)
Definition BKE_node.hh:508
void(* foreach_nodeclass)(void *calldata, bNodeClassCallback func)
Definition BKE_node.hh:493
void(* get_from_context)(const bContext *C, bNodeTreeType *ntreetype, bNodeTree **r_ntree, ID **r_id, ID **r_from)
Definition BKE_node.hh:497
bool(* validate_link)(eNodeSocketDatatype from, eNodeSocketDatatype to)
Definition BKE_node.hh:510
bool(* valid_socket_type)(bNodeTreeType *ntreetype, bNodeSocketType *socket_type)
Definition BKE_node.hh:515
#define N_(msgid)