Blender V4.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 "BLI_string.h"
8
9#include "MEM_guardedalloc.h"
10
11#include "NOD_geometry.hh"
12
13#include "BKE_context.hh"
14#include "BKE_layer.hh"
15#include "BKE_node.hh"
16#include "BKE_object.hh"
17
18#include "DNA_modifier_types.h"
19#include "DNA_node_types.h"
20#include "DNA_space_types.h"
21
22#include "RNA_prototypes.hh"
23
24#include "UI_resources.hh"
25
26#include "BLT_translation.hh"
27
28#include "node_common.h"
29
31
33 blender::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);
40 *r_ntree = snode->geometry_nodes_tool_tree;
41 return;
42 }
43
44 const Scene *scene = CTX_data_scene(C);
45 ViewLayer *view_layer = CTX_data_view_layer(C);
46 BKE_view_layer_synced_ensure(scene, view_layer);
48
49 if (ob == nullptr) {
50 return;
51 }
52
54
55 if (md == nullptr) {
56 return;
57 }
58
59 if (md->type == eModifierType_Nodes) {
60 const NodesModifierData *nmd = reinterpret_cast<const NodesModifierData *>(md);
61 if (nmd->node_group != nullptr) {
62 *r_from = &ob->id;
63 *r_id = &ob->id;
64 *r_ntree = nmd->node_group;
65 }
66 }
67}
68
70{
72
73 /* Needed to give correct types to reroutes. */
75}
76
77static void foreach_nodeclass(void *calldata, blender::bke::bNodeClassCallback func)
78{
79 func(calldata, NODE_CLASS_INPUT, N_("Input"));
80 func(calldata, NODE_CLASS_GEOMETRY, N_("Geometry"));
81 func(calldata, NODE_CLASS_ATTRIBUTE, N_("Attribute"));
82 func(calldata, NODE_CLASS_OP_COLOR, N_("Color"));
83 func(calldata, NODE_CLASS_OP_VECTOR, N_("Vector"));
84 func(calldata, NODE_CLASS_CONVERTER, N_("Converter"));
85 func(calldata, NODE_CLASS_LAYOUT, N_("Layout"));
86}
87
90{
91 /* Geometry, string, object, material, texture and collection sockets can only be connected to
92 * themselves. The other types can be converted between each other. */
95 {
96 return true;
97 }
98 if (ELEM(type_a, SOCK_FLOAT, SOCK_VECTOR) && type_b == SOCK_ROTATION) {
99 /* Floats and vectors implicitly convert to rotations. */
100 return true;
101 }
102
103 /* Support implicit conversions between matrices and rotations. */
104 if (type_a == SOCK_MATRIX && type_b == SOCK_ROTATION) {
105 return true;
106 }
107 if (type_a == SOCK_ROTATION && type_b == SOCK_MATRIX) {
108 return true;
109 }
110
111 if (type_a == SOCK_ROTATION && type_b == SOCK_VECTOR) {
112 /* Rotations implicitly convert to vectors. */
113 return true;
114 }
115 return type_a == type_b;
116}
117
138
140{
142 static_cast<blender::bke::bNodeTreeType *>(
143 MEM_callocN(sizeof(blender::bke::bNodeTreeType), "geometry node tree type"));
144 tt->type = NTREE_GEOMETRY;
145 STRNCPY(tt->idname, "GeometryNodeTree");
146 STRNCPY(tt->group_idname, "GeometryNodeGroup");
147 STRNCPY(tt->ui_name, N_("Geometry Node Editor"));
148 tt->ui_icon = ICON_GEOMETRY_NODES;
149 STRNCPY(tt->ui_description, N_("Geometry nodes"));
150 tt->rna_ext.srna = &RNA_GeometryNodeTree;
156
158}
159
161{
162 const blender::bke::bNodeSocketType *typeinfo = socket.socket_typeinfo();
163 BLI_assert(typeinfo != nullptr);
164
165 if (typeinfo->type != SOCK_BOOLEAN) {
166 return false;
167 }
168 return (socket.flag & NODE_INTERFACE_SOCKET_LAYER_SELECTION) != 0;
169}
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:410
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:418
#define NODE_CLASS_OP_VECTOR
Definition BKE_node.hh:407
#define NODE_CLASS_LAYOUT
Definition BKE_node.hh:420
#define NODE_CLASS_OP_COLOR
Definition BKE_node.hh:406
#define NODE_CLASS_INPUT
Definition BKE_node.hh:404
#define NODE_CLASS_ATTRIBUTE
Definition BKE_node.hh:419
General operations, lookup, etc. for blender objects.
ModifierData * BKE_object_active_modifier(const Object *ob)
#define BLI_assert(a)
Definition BLI_assert.h:50
#define STRNCPY(dst, src)
Definition BLI_string.h:593
#define ELEM(...)
@ eModifierType_Nodes
@ NODE_INTERFACE_SOCKET_LAYER_SELECTION
@ NTREE_GEOMETRY
eNodeSocketDatatype
@ SOCK_INT
@ SOCK_TEXTURE
@ SOCK_VECTOR
@ SOCK_BOOLEAN
@ SOCK_MATERIAL
@ SOCK_MATRIX
@ SOCK_FLOAT
@ SOCK_IMAGE
@ SOCK_COLLECTION
@ SOCK_GEOMETRY
@ SOCK_ROTATION
@ SOCK_OBJECT
@ SOCK_STRING
@ SOCK_RGBA
@ SOCK_MENU
@ SNODE_GEOMETRY_TOOL
Read Guarded memory(de)allocation.
void *(* MEM_callocN)(size_t len, const char *str)
Definition mallocn.cc:42
void node_tree_set_output(bNodeTree *ntree)
Definition node.cc:3650
bool node_is_static_socket_type(const bNodeSocketType *stype)
Definition node.cc:2117
void(*)(void *calldata, int nclass, const char *name) bNodeClassCallback
Definition BKE_node.hh:446
void node_tree_type_add(bNodeTreeType *nt)
Definition node.cc:1633
void ntree_update_reroute_nodes(bNodeTree *ntree)
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:780
Definition DNA_ID.h:413
struct bNodeTree * node_group
struct bNodeTree * geometry_nodes_tool_tree
char geometry_nodes_type
Defines a socket type.
Definition BKE_node.hh:151
void(* update)(bNodeTree *ntree)
Definition BKE_node.hh:473
void(* foreach_nodeclass)(void *calldata, bNodeClassCallback func)
Definition BKE_node.hh:461
void(* get_from_context)(const bContext *C, bNodeTreeType *ntreetype, bNodeTree **r_ntree, ID **r_id, ID **r_from)
Definition BKE_node.hh:465
bool(* validate_link)(eNodeSocketDatatype from, eNodeSocketDatatype to)
Definition BKE_node.hh:475
bool(* valid_socket_type)(bNodeTreeType *ntreetype, bNodeSocketType *socket_type)
Definition BKE_node.hh:480
#define N_(msgid)