Blender V5.3
node_shader_uvmap.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2005 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "node_shader_util.hh"
10#include "node_util.hh"
11
12#include "BKE_context.hh"
13
15
17
18#include "ED_node.hh"
19
20#include "RNA_access.hh"
21
23#include "UI_resources.hh"
24
25namespace blender {
26
28
30{
31 b.add_output<decl::Vector>("UV"_ustr);
32}
33
35{
36 layout.prop(ptr, "from_instancer", ui::ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
37
38 if (!RNA_boolean_get(ptr, "from_instancer")) {
40
41 if (object && object->type == OB_MESH) {
42 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
43
44 if (depsgraph) {
45 Object *object_eval = DEG_get_evaluated(depsgraph, object);
46 PointerRNA dataptr = RNA_id_pointer_create(object_eval->data);
47 layout.prop_search(ptr, "uv_map", &dataptr, "uv_layers", "", ICON_GROUP_UVS);
48 return;
49 }
50 }
51
52 layout.prop(ptr, "uv_map", ui::ITEM_R_SPLIT_EMPTY_NAME, "", ICON_GROUP_UVS);
53 }
54}
55
56static void node_shader_init_uvmap(bNodeTree * /*ntree*/, bNode *node)
57{
58 NodeShaderUVMap *attr = MEM_new<NodeShaderUVMap>("NodeShaderUVMap");
59 node->storage = attr;
60}
61
63 bNode *node,
64 bNodeExecData * /*execdata*/,
67{
68 NodeShaderUVMap *attr = static_cast<NodeShaderUVMap *>(node->storage);
69
70 /* NOTE: using CD_AUTO_FROM_NAME instead of CD_MTFACE as geometry nodes may overwrite data which
71 * will also change the eCustomDataType. This will also make EEVEE and Cycles consistent. See
72 * #93179. */
74
75 GPU_stack_link(mat, node, "node_uvmap", in, out, mtface);
76
78
79 return 1;
80}
81
83#ifdef WITH_MATERIALX
84{
85 /* NODE: "From Instances" not implemented */
86 NodeShaderUVMap *attr = static_cast<NodeShaderUVMap *>(node_->storage);
87 NodeItem res = texcoord_node(NodeItem::Type::Vector2, attr->uv_map);
88 return res;
89}
90#endif
92
93} // namespace nodes::node_shader_uvmap_cc
94
95/* node type definition */
97{
98 namespace file_ns = nodes::node_shader_uvmap_cc;
99
100 static bke::bNodeType ntype;
101
102 sh_node_type_base(&ntype, "ShaderNodeUVMap"_ustr, SH_NODE_UVMAP);
103 ntype.ui_name = "UV Map";
104 ntype.ui_description =
105 "Retrieve a UV map from the geometry, or the default fallback if none is specified";
106 ntype.enum_name_legacy = "UVMAP";
107 ntype.nclass = NODE_CLASS_INPUT;
108 ntype.declare = file_ns::node_declare;
109 ntype.draw_buttons = file_ns::node_shader_buts_uvmap;
111 ntype.initfunc = file_ns::node_shader_init_uvmap;
113 ntype, "NodeShaderUVMap", node_free_standard_storage, node_copy_standard_storage);
114 ntype.gpu_fn = file_ns::node_shader_gpu_uvmap;
115 ntype.materialx_fn = file_ns::node_shader_materialx;
116
118}
119
120} // namespace blender
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define SH_NODE_UVMAP
#define C
Definition RandGen.cpp:29
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
void node_type_storage(bNodeType &ntype, std::optional< StringRefNull > storagename, void(*freefunc)(bNode *node), void(*copyfunc)(bNodeTree *dest_ntree, bNode *dest_node, const bNode *src_node))
Definition node.cc:6166
Object * get_space_editor_object(const bContext *C)
static void node_shader_init_uvmap(bNodeTree *, bNode *node)
static void node_shader_buts_uvmap(ui::Layout &layout, bContext *C, PointerRNA *ptr)
static int node_shader_gpu_uvmap(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_declare(NodeDeclarationBuilder &b)
BMesh Iterators.
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
PointerRNA RNA_id_pointer_create(ID *id)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
void sh_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
void register_node_type_sh_uvmap()
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void node_shader_gpu_bump_tex_coord(GPUMaterial *mat, bNode *, GPUNodeLink **link)
GPUNodeLink * GPU_attribute(GPUMaterial *mat, eCustomDataType type, const char *name)
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:57
void node_free_standard_storage(bNode *node)
Definition node_util.cc:45
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
static constexpr int _160
Definition BKE_node.hh:246
Defines a node type.
Definition BKE_node.hh:265
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:375
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:290
std::string ui_description
Definition BKE_node.hh:271
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:373
void(*) initfunc(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:320
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393
void prop_search(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *searchptr, PropertyRNA *searchprop, PropertyRNA *item_searchpropname, std::optional< StringRefNull > name, int icon, bool results_are_suggestions)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)