From cb7cfd3ab6be1cfba96cb2070ac60d224126f1ea Mon Sep 17 00:00:00 2001 From: Kevin Dietrich Date: Wed, 2 Apr 2014 11:40:29 +0200 Subject: Cycles: add dedicated UV Map node, easier to find and has convenient auto complete. Fixes T37954. Reviewed By: brecht, dingto Differential Revision: https://developer.blender.org/D230 --- source/blender/blenkernel/BKE_node.h | 1 + source/blender/blenkernel/intern/node.c | 1 + source/blender/editors/space_node/drawnode.c | 17 +++++++ source/blender/makesdna/DNA_node_types.h | 4 ++ source/blender/makesrna/intern/rna_nodetree.c | 18 +++++++ source/blender/nodes/CMakeLists.txt | 1 + source/blender/nodes/NOD_shader.h | 1 + source/blender/nodes/NOD_static_types.h | 1 + .../blender/nodes/shader/nodes/node_shader_uvmap.c | 58 ++++++++++++++++++++++ 9 files changed, 102 insertions(+) create mode 100644 source/blender/nodes/shader/nodes/node_shader_uvmap.c (limited to 'source') diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 09c5776ccf0..1d76cabf78b 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -744,6 +744,7 @@ struct ShadeResult; #define SH_NODE_COMBHSV 184 #define SH_NODE_BSDF_HAIR 185 #define SH_NODE_LAMP 186 +#define SH_NODE_UVMAP 187 /* custom defines options for Material node */ #define SH_NODE_MAT_DIFF 1 diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 2122526988a..47ef03093b1 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -3520,6 +3520,7 @@ static void registerShaderNodes(void) register_node_type_sh_subsurface_scattering(); register_node_type_sh_mix_shader(); register_node_type_sh_add_shader(); + register_node_type_sh_uvmap(); register_node_type_sh_output_lamp(); register_node_type_sh_output_material(); diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c index 5e3ac42d865..d64607c5481 100644 --- a/source/blender/editors/space_node/drawnode.c +++ b/source/blender/editors/space_node/drawnode.c @@ -873,6 +873,20 @@ static void node_shader_buts_bump(uiLayout *layout, bContext *UNUSED(C), Pointer uiItemR(layout, ptr, "invert", 0, NULL, 0); } +static void node_shader_buts_uvmap(uiLayout *layout, bContext *C, PointerRNA *ptr) +{ + uiItemR(layout, ptr, "from_dupli", 0, NULL, 0); + + if(!RNA_boolean_get(ptr, "from_dupli")) { + PointerRNA obptr = CTX_data_pointer_get(C, "active_object"); + + if (obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) { + PointerRNA dataptr = RNA_pointer_get(&obptr, "data"); + uiItemPointerR(layout, ptr, "uv_map", &dataptr, "uv_textures", "", ICON_NONE); + } + } +} + static void node_shader_buts_normal_map(uiLayout *layout, bContext *C, PointerRNA *ptr) { uiItemR(layout, ptr, "space", 0, "", 0); @@ -1103,6 +1117,9 @@ static void node_shader_set_butfunc(bNodeType *ntype) ntype->draw_buttons = node_shader_buts_script; ntype->draw_buttons_ex = node_shader_buts_script_ex; break; + case SH_NODE_UVMAP: + ntype->draw_buttons = node_shader_buts_uvmap; + break; } } diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index 2d3a0fa2057..967ec8d8d06 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -847,6 +847,10 @@ typedef struct NodeShaderNormalMap { char uv_map[64]; } NodeShaderNormalMap; +typedef struct NodeShaderUVMap { + char uv_map[64]; +} NodeShaderUVMap; + /* script node mode */ #define NODE_SCRIPT_INTERNAL 0 #define NODE_SCRIPT_EXTERNAL 1 diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 0664ecf0d34..0f2380cbad4 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -3730,6 +3730,24 @@ static void def_hair(StructRNA *srna) RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); } +static void def_sh_uvmap(StructRNA *srna) +{ + PropertyRNA *prop; + + prop = RNA_def_property(srna, "from_dupli", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "custom1", 1); + RNA_def_property_ui_text(prop, "From Dupli", "Use the parent of the dupli object if possible"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); + + RNA_def_struct_sdna_from(srna, "NodeShaderUVMap", "storage"); + + prop = RNA_def_property(srna, "uv_map", PROP_STRING, PROP_NONE); + RNA_def_property_ui_text(prop, "UV Map", "UV coordinates to be used for mapping"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); + + RNA_def_struct_sdna_from(srna, "bNode", NULL); +} + static void def_sh_normal_map(StructRNA *srna) { static EnumPropertyItem prop_space_items[] = { diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt index fef6762d695..754a3c11d78 100644 --- a/source/blender/nodes/CMakeLists.txt +++ b/source/blender/nodes/CMakeLists.txt @@ -200,6 +200,7 @@ set(SRC shader/nodes/node_shader_tex_wave.c shader/nodes/node_shader_volume_scatter.c shader/nodes/node_shader_volume_absorption.c + shader/nodes/node_shader_uvmap.c shader/node_shader_tree.c shader/node_shader_util.c diff --git a/source/blender/nodes/NOD_shader.h b/source/blender/nodes/NOD_shader.h index 0f388a890a4..91b103da0e2 100644 --- a/source/blender/nodes/NOD_shader.h +++ b/source/blender/nodes/NOD_shader.h @@ -111,6 +111,7 @@ void register_node_type_sh_bsdf_hair(void); void register_node_type_sh_subsurface_scattering(void); void register_node_type_sh_mix_shader(void); void register_node_type_sh_add_shader(void); +void register_node_type_sh_uvmap(void); void register_node_type_sh_output_lamp(void); void register_node_type_sh_output_material(void); diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h index b406ac49008..434e737772d 100644 --- a/source/blender/nodes/NOD_static_types.h +++ b/source/blender/nodes/NOD_static_types.h @@ -119,6 +119,7 @@ DefNode( ShaderNode, SH_NODE_TEX_COORD, def_sh_tex_coord, "TE DefNode( ShaderNode, SH_NODE_VECT_TRANSFORM, def_sh_vect_transform, "VECT_TRANSFORM", VectorTransform, "Vector Transform", "" ) DefNode( ShaderNode, SH_NODE_SEPHSV, 0, "SEPHSV", SeparateHSV, "Separate HSV", "" ) DefNode( ShaderNode, SH_NODE_COMBHSV, 0, "COMBHSV", CombineHSV, "Combine HSV", "" ) +DefNode( ShaderNode, SH_NODE_UVMAP, def_sh_uvmap, "UVMAP", UVMap, "UV Map", "" ) DefNode( CompositorNode, CMP_NODE_VIEWER, def_cmp_viewer, "VIEWER", Viewer, "Viewer", "" ) DefNode( CompositorNode, CMP_NODE_RGB, 0, "RGB", RGB, "RGB", "" ) diff --git a/source/blender/nodes/shader/nodes/node_shader_uvmap.c b/source/blender/nodes/shader/nodes/node_shader_uvmap.c new file mode 100644 index 00000000000..fff1bc1df95 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_uvmap.c @@ -0,0 +1,58 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "../node_shader_util.h" + +#include "DNA_customdata_types.h" + +/* **************** OUTPUT ******************** */ + +static bNodeSocketTemplate sh_node_uvmap_out[] = { + { SOCK_VECTOR, 0, N_("UV"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + { -1, 0, "" } +}; + +static void node_shader_init_uvmap(bNodeTree *UNUSED(ntree), bNode *node) +{ + NodeShaderUVMap *attr = MEM_callocN(sizeof(NodeShaderUVMap), "NodeShaderUVMap"); + node->storage = attr; +} + +/* node type definition */ +void register_node_type_sh_uvmap(void) +{ + static bNodeType ntype; + + sh_node_type_base(&ntype, SH_NODE_UVMAP, "UV Map", NODE_CLASS_INPUT, 0); + node_type_compatibility(&ntype, NODE_NEW_SHADING); + node_type_socket_templates(&ntype, NULL, sh_node_uvmap_out); + node_type_size_preset(&ntype, NODE_SIZE_MIDDLE); + node_type_init(&ntype, node_shader_init_uvmap); + node_type_storage(&ntype, "NodeShaderUVMap", node_free_standard_storage, node_copy_standard_storage); + + nodeRegisterType(&ntype); +} -- cgit v1.2.3