Blender V5.0
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
5#include "node_shader_util.hh"
6#include "node_util.hh"
7
8#include "BKE_context.hh"
9
11
13
14#include "RNA_access.hh"
15
17#include "UI_resources.hh"
18
20
22{
23 b.add_output<decl::Vector>("UV");
24}
25
27{
28 layout->prop(ptr, "from_instancer", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_NONE);
29
30 if (!RNA_boolean_get(ptr, "from_instancer")) {
31 PointerRNA obptr = CTX_data_pointer_get(C, "active_object");
32 Object *object = static_cast<Object *>(obptr.data);
33
34 if (object && object->type == OB_MESH) {
36
37 if (depsgraph) {
38 Object *object_eval = DEG_get_evaluated(depsgraph, object);
39 PointerRNA dataptr = RNA_id_pointer_create(static_cast<ID *>(object_eval->data));
40 layout->prop_search(ptr, "uv_map", &dataptr, "uv_layers", "", ICON_GROUP_UVS);
41 return;
42 }
43 }
44
45 layout->prop(ptr, "uv_map", UI_ITEM_R_SPLIT_EMPTY_NAME, std::nullopt, ICON_GROUP_UVS);
46 }
47}
48
49static void node_shader_init_uvmap(bNodeTree * /*ntree*/, bNode *node)
50{
51 NodeShaderUVMap *attr = MEM_callocN<NodeShaderUVMap>("NodeShaderUVMap");
52 node->storage = attr;
53}
54
56 bNode *node,
57 bNodeExecData * /*execdata*/,
60{
61 NodeShaderUVMap *attr = static_cast<NodeShaderUVMap *>(node->storage);
62
63 /* NOTE: using CD_AUTO_FROM_NAME instead of CD_MTFACE as geometry nodes may overwrite data which
64 * will also change the eCustomDataType. This will also make EEVEE and Cycles consistent. See
65 * #93179. */
67
68 GPU_stack_link(mat, node, "node_uvmap", in, out, mtface);
69
70 node_shader_gpu_bump_tex_coord(mat, node, &out[0].link);
71
72 return 1;
73}
74
76#ifdef WITH_MATERIALX
77{
78 /* NODE: "From Instances" not implemented */
79 NodeShaderUVMap *attr = static_cast<NodeShaderUVMap *>(node_->storage);
80 NodeItem res = texcoord_node(NodeItem::Type::Vector2, attr->uv_map);
81 return res;
82}
83#endif
85
86} // namespace blender::nodes::node_shader_uvmap_cc
87
88/* node type definition */
90{
91 namespace file_ns = blender::nodes::node_shader_uvmap_cc;
92
93 static blender::bke::bNodeType ntype;
94
95 sh_node_type_base(&ntype, "ShaderNodeUVMap", SH_NODE_UVMAP);
96 ntype.ui_name = "UV Map";
97 ntype.ui_description =
98 "Retrieve a UV map from the geometry, or the default fallback if none is specified";
99 ntype.enum_name_legacy = "UVMAP";
100 ntype.nclass = NODE_CLASS_INPUT;
101 ntype.declare = file_ns::node_declare;
102 ntype.draw_buttons = file_ns::node_shader_buts_uvmap;
104 ntype.initfunc = file_ns::node_shader_init_uvmap;
106 ntype, "NodeShaderUVMap", node_free_standard_storage, node_copy_standard_storage);
107 ntype.gpu_fn = file_ns::node_shader_gpu_uvmap;
108 ntype.materialx_fn = file_ns::node_shader_materialx;
109
111}
PointerRNA CTX_data_pointer_get(const bContext *C, const char *member)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
#define SH_NODE_UVMAP
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
@ CD_AUTO_FROM_NAME
@ OB_MESH
bool GPU_stack_link(GPUMaterial *mat, const bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out,...)
GPUNodeLink * GPU_attribute(GPUMaterial *mat, eCustomDataType type, const char *name)
#define C
Definition RandGen.cpp:29
@ UI_ITEM_R_SPLIT_EMPTY_NAME
BPy_StructRNA * depsgraph
#define in
#define out
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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:5414
void node_type_size_preset(bNodeType &ntype, eNodeSizePreset size)
Definition node.cc:5396
static void node_shader_init_uvmap(bNodeTree *, bNode *node)
static int node_shader_gpu_uvmap(GPUMaterial *mat, bNode *node, bNodeExecData *, GPUNodeStack *in, GPUNodeStack *out)
static void node_declare(NodeDeclarationBuilder &b)
static void node_shader_buts_uvmap(uiLayout *layout, bContext *C, PointerRNA *ptr)
#define NODE_SHADER_MATERIALX_BEGIN
#define NODE_SHADER_MATERIALX_END
void sh_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
void node_shader_gpu_bump_tex_coord(GPUMaterial *mat, bNode *, GPUNodeLink **link)
void register_node_type_sh_uvmap()
void node_free_standard_storage(bNode *node)
Definition node_util.cc:42
void node_copy_standard_storage(bNodeTree *, bNode *dest_node, const bNode *src_node)
Definition node_util.cc:54
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
PointerRNA RNA_id_pointer_create(ID *id)
Definition DNA_ID.h:414
void * data
Definition RNA_types.hh:53
void * storage
Defines a node type.
Definition BKE_node.hh:238
NodeMaterialXFunction materialx_fn
Definition BKE_node.hh:344
std::string ui_description
Definition BKE_node.hh:244
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
NodeGPUExecFunction gpu_fn
Definition BKE_node.hh:342
const char * enum_name_legacy
Definition BKE_node.hh:247
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
NodeDeclareFunction declare
Definition BKE_node.hh:362
void prop_search(PointerRNA *ptr, PropertyRNA *prop, PointerRNA *searchptr, PropertyRNA *searchprop, PropertyRNA *item_searchpropname, std::optional< blender::StringRefNull > name, int icon, bool results_are_suggestions)
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
PointerRNA * ptr
Definition wm_files.cc:4238