Blender  V3.3
node_geometry_tree.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <cstring>
4 
5 #include "MEM_guardedalloc.h"
6 
7 #include "NOD_geometry.h"
8 
9 #include "BKE_context.h"
10 #include "BKE_node.h"
11 #include "BKE_object.h"
12 
13 #include "BLT_translation.h"
14 
15 #include "DNA_modifier_types.h"
16 #include "DNA_node_types.h"
17 #include "DNA_space_types.h"
18 
19 #include "RNA_access.h"
20 #include "RNA_prototypes.h"
21 
22 #include "UI_resources.h"
23 
24 #include "node_common.h"
25 
27 
29  bNodeTreeType *UNUSED(treetype),
30  bNodeTree **r_ntree,
31  ID **r_id,
32  ID **r_from)
33 {
34  ViewLayer *view_layer = CTX_data_view_layer(C);
35  Object *ob = OBACT(view_layer);
36 
37  if (ob == nullptr) {
38  return;
39  }
40 
42 
43  if (md == nullptr) {
44  return;
45  }
46 
47  if (md->type == eModifierType_Nodes) {
49  if (nmd->node_group != nullptr) {
50  *r_from = &ob->id;
51  *r_id = &ob->id;
52  *r_ntree = nmd->node_group;
53  }
54  }
55 }
56 
58 {
60 
61  /* Needed to give correct types to reroutes. */
63 }
64 
65 static void foreach_nodeclass(Scene *UNUSED(scene), void *calldata, bNodeClassCallback func)
66 {
67  func(calldata, NODE_CLASS_INPUT, N_("Input"));
68  func(calldata, NODE_CLASS_GEOMETRY, N_("Geometry"));
69  func(calldata, NODE_CLASS_ATTRIBUTE, N_("Attribute"));
70  func(calldata, NODE_CLASS_OP_COLOR, N_("Color"));
71  func(calldata, NODE_CLASS_OP_VECTOR, N_("Vector"));
72  func(calldata, NODE_CLASS_CONVERTER, N_("Converter"));
73  func(calldata, NODE_CLASS_LAYOUT, N_("Layout"));
74 }
75 
77  eNodeSocketDatatype type_b)
78 {
79  /* Geometry, string, object, material, texture and collection sockets can only be connected to
80  * themselves. The other types can be converted between each other. */
83  return true;
84  }
85  return type_a == type_b;
86 }
87 
89  bNodeSocketType *socket_type)
90 {
91  return nodeIsStaticSocketType(socket_type) && ELEM(socket_type->type,
92  SOCK_FLOAT,
94  SOCK_RGBA,
96  SOCK_INT,
101  SOCK_TEXTURE,
102  SOCK_IMAGE,
103  SOCK_MATERIAL);
104 }
105 
107 {
108  bNodeTreeType *tt = ntreeType_Geometry = static_cast<bNodeTreeType *>(
109  MEM_callocN(sizeof(bNodeTreeType), "geometry node tree type"));
110  tt->type = NTREE_GEOMETRY;
111  strcpy(tt->idname, "GeometryNodeTree");
112  strcpy(tt->ui_name, N_("Geometry Node Editor"));
113  tt->ui_icon = ICON_GEOMETRY_NODES;
114  strcpy(tt->ui_description, N_("Geometry nodes"));
115  tt->rna_ext.srna = &RNA_GeometryNodeTree;
121 
122  ntreeTypeAdd(tt);
123 }
struct ViewLayer * CTX_data_view_layer(const bContext *C)
Definition: context.c:1100
void ntreeTypeAdd(struct bNodeTreeType *nt)
Definition: node.cc:1292
#define NODE_CLASS_CONVERTER
Definition: BKE_node.h:351
void(* bNodeClassCallback)(void *calldata, int nclass, const char *name)
Definition: BKE_node.h:372
#define NODE_CLASS_GEOMETRY
Definition: BKE_node.h:359
bool nodeIsStaticSocketType(const struct bNodeSocketType *stype)
Definition: node.cc:1701
void ntreeSetOutput(struct bNodeTree *ntree)
Definition: node.cc:3141
#define NODE_CLASS_OP_VECTOR
Definition: BKE_node.h:348
#define NODE_CLASS_LAYOUT
Definition: BKE_node.h:361
#define NODE_CLASS_OP_COLOR
Definition: BKE_node.h:347
#define NODE_CLASS_INPUT
Definition: BKE_node.h:345
#define NODE_CLASS_ATTRIBUTE
Definition: BKE_node.h:360
General operations, lookup, etc. for blender objects.
struct ModifierData * BKE_object_active_modifier(const struct Object *ob)
#define UNUSED(x)
#define ELEM(...)
@ eModifierType_Nodes
#define NTREE_GEOMETRY
eNodeSocketDatatype
@ SOCK_INT
@ SOCK_TEXTURE
@ SOCK_VECTOR
@ SOCK_BOOLEAN
@ SOCK_MATERIAL
@ SOCK_FLOAT
@ SOCK_IMAGE
@ SOCK_COLLECTION
@ SOCK_GEOMETRY
@ SOCK_OBJECT
@ SOCK_STRING
@ SOCK_RGBA
#define OBACT(_view_layer)
Read Guarded memory(de)allocation.
#define C
Definition: RandGen.cpp:25
Scene scene
bNodeTree * ntree
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:31
void ntree_update_reroute_nodes(bNodeTree *ntree)
Definition: node_common.cc:321
static void foreach_nodeclass(Scene *UNUSED(scene), void *calldata, bNodeClassCallback func)
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)
static void geometry_node_tree_update(bNodeTree *ntree)
void register_node_tree_type_geo()
static bool geometry_node_tree_socket_type_valid(bNodeTreeType *UNUSED(ntreetype), bNodeSocketType *socket_type)
static bool geometry_node_tree_validate_link(eNodeSocketDatatype type_a, eNodeSocketDatatype type_b)
StructRNA * srna
Definition: RNA_types.h:766
Definition: DNA_ID.h:368
struct bNodeTree * node_group
Defines a socket type.
Definition: BKE_node.h:143
bool(* validate_link)(eNodeSocketDatatype from, eNodeSocketDatatype to)
Definition: BKE_node.h:402
char idname[64]
Definition: BKE_node.h:375
void(* update)(struct bNodeTree *ntree)
Definition: BKE_node.h:400
void(* get_from_context)(const struct bContext *C, struct bNodeTreeType *ntreetype, struct bNodeTree **r_ntree, struct ID **r_id, struct ID **r_from)
Definition: BKE_node.h:389
char ui_name[64]
Definition: BKE_node.h:377
char ui_description[256]
Definition: BKE_node.h:378
bool(* valid_socket_type)(struct bNodeTreeType *ntreetype, struct bNodeSocketType *socket_type)
Definition: BKE_node.h:407
void(* foreach_nodeclass)(struct Scene *scene, void *calldata, bNodeClassCallback func)
Definition: BKE_node.h:385
ExtensionRNA rna_ext
Definition: BKE_node.h:410
#define N_(msgid)