Blender V4.3
node_geo_viewer.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 "BKE_context.hh"
6
8#include "NOD_rna_define.hh"
10
11#include "UI_interface.hh"
12#include "UI_resources.hh"
13
14#include "ED_node.hh"
15#include "ED_viewer_path.hh"
16
17#include "RNA_enum_types.hh"
18
19#include "node_geometry_util.hh"
20
22
24
26{
27 const bNode *node = b.node_or_null();
28
29 b.add_input<decl::Geometry>("Geometry");
30 if (node != nullptr) {
31 const eCustomDataType data_type = eCustomDataType(node_storage(*node).data_type);
32 b.add_input(data_type, "Value").field_on_all().hide_value();
33 }
34}
35
36static void node_init(bNodeTree * /*tree*/, bNode *node)
37{
38 NodeGeometryViewer *data = MEM_cnew<NodeGeometryViewer>(__func__);
39 data->data_type = CD_PROP_FLOAT;
40 data->domain = int8_t(AttrDomain::Auto);
41 node->storage = data;
42}
43
44static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
45{
46 uiItemR(layout, ptr, "domain", UI_ITEM_NONE, "", ICON_NONE);
47}
48
49static void node_layout_ex(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
50{
51 uiItemR(layout, ptr, "data_type", UI_ITEM_NONE, "", ICON_NONE);
52}
53
55{
56 auto set_active_fn = [](LinkSearchOpParams &params, bNode &viewer_node) {
57 /* Set this new viewer node active in spreadsheet editors. */
59 Main *bmain = CTX_data_main(&params.C);
60 ED_node_set_active(bmain, snode, &params.node_tree, &viewer_node, nullptr);
61 ed::viewer_path::activate_geometry_node(*bmain, *snode, viewer_node);
62 };
63
64 const eNodeSocketDatatype socket_type = eNodeSocketDatatype(params.other_socket().type);
65 const std::optional<eCustomDataType> type = bke::socket_type_to_custom_data_type(socket_type);
66 if (params.in_out() == SOCK_OUT) {
67 /* The viewer node only has inputs. */
68 return;
69 }
70 if (params.other_socket().type == SOCK_GEOMETRY) {
71 params.add_item(IFACE_("Geometry"), [set_active_fn](LinkSearchOpParams &params) {
72 bNode &node = params.add_node("GeometryNodeViewer");
73 params.connect_available_socket(node, "Geometry");
74 set_active_fn(params, node);
75 });
76 }
77 if (type && ELEM(*type,
85 {
86 params.add_item(IFACE_("Value"), [type, set_active_fn](LinkSearchOpParams &params) {
87 bNode &node = params.add_node("GeometryNodeViewer");
88 node_storage(node).data_type = *type;
89 params.update_and_connect_available_socket(node, "Value");
90
91 /* If the source node has a geometry socket, connect it to the new viewer node as well. */
92 LISTBASE_FOREACH (bNodeSocket *, socket, &params.node.outputs) {
93 if (socket->type == SOCK_GEOMETRY && socket->is_visible()) {
94 bke::node_add_link(&params.node_tree,
95 &params.node,
96 socket,
97 &node,
98 static_cast<bNodeSocket *>(node.inputs.first));
99 break;
100 }
101 }
102
103 set_active_fn(params, node);
104 });
105 }
106}
107
109{
110 const auto data_type = eCustomDataType(node_storage(params.node).data_type);
111 if (ELEM(data_type, CD_PROP_QUATERNION, CD_PROP_FLOAT4X4)) {
113 row.icon = ICON_INFO;
114 row.text = TIP_("No color overlay");
115 row.tooltip = TIP_(
116 "Rotation values can only be displayed with the text overlay in the 3D view");
117 params.rows.append(std::move(row));
118 }
119}
120
121static void node_rna(StructRNA *srna)
122{
124 "data_type",
125 "Data Type",
126 "",
131
133 "domain",
134 "Domain",
135 "Domain to evaluate the field on",
138 int(AttrDomain::Point));
139}
140
141static void node_register()
142{
143 static blender::bke::bNodeType ntype;
144
145 geo_node_type_base(&ntype, GEO_NODE_VIEWER, "Viewer", NODE_CLASS_OUTPUT);
147 &ntype, "NodeGeometryViewer", node_free_standard_storage, node_copy_standard_storage);
148 ntype.declare = node_declare;
149 ntype.initfunc = node_init;
153 ntype.no_muting = true;
156
157 node_rna(ntype.rna_ext.srna);
158}
160
161} // namespace blender::nodes::node_geo_viewer_cc
SpaceNode * CTX_wm_space_node(const bContext *C)
Main * CTX_data_main(const bContext *C)
#define NODE_CLASS_OUTPUT
Definition BKE_node.hh:405
#define NODE_STORAGE_FUNCS(StorageT)
Definition BKE_node.hh:1799
#define LISTBASE_FOREACH(type, var, list)
#define ELEM(...)
#define TIP_(msgid)
#define IFACE_(msgid)
@ CD_PROP_FLOAT
@ CD_PROP_FLOAT3
@ CD_PROP_COLOR
@ CD_PROP_QUATERNION
@ CD_PROP_INT32
@ CD_PROP_FLOAT4X4
@ SOCK_OUT
eNodeSocketDatatype
@ SOCK_GEOMETRY
void ED_node_set_active(Main *bmain, SpaceNode *snode, bNodeTree *ntree, bNode *node, bool *r_active_texture_changed)
Definition node_edit.cc:722
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_storage_enum_accessors(member)
#define UI_ITEM_NONE
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
bNodeLink * node_add_link(bNodeTree *ntree, bNode *fromnode, bNodeSocket *fromsock, bNode *tonode, bNodeSocket *tosock)
Definition node.cc:2912
void node_type_storage(bNodeType *ntype, const char *storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:4632
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
std::optional< eCustomDataType > socket_type_to_custom_data_type(eNodeSocketDatatype type)
Definition node.cc:4379
void activate_geometry_node(Main &bmain, SpaceNode &snode, bNode &node)
const EnumPropertyItem * attribute_type_type_with_socket_fn(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
static void node_rna(StructRNA *srna)
static void node_init(bNodeTree *, bNode *node)
static void node_layout_ex(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_declare(NodeDeclarationBuilder &b)
static void node_extra_info(NodeExtraInfoParams &params)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_gather_link_searches(GatherLinkSearchOpParams &params)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
void node_free_standard_storage(bNode *node)
Definition node_util.cc:46
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:58
const EnumPropertyItem rna_enum_attribute_domain_with_auto_items[]
const EnumPropertyItem rna_enum_attribute_type_items[]
signed char int8_t
Definition stdint.h:75
StructRNA * srna
Definition RNA_types.hh:780
Defines a node type.
Definition BKE_node.hh:218
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
void(* draw_buttons_ex)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:240
NodeExtraInfoFunction get_extra_info
Definition BKE_node.hh:366
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:363
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126