diff options
Diffstat (limited to 'source/blender/makesrna/intern/rna_nodetree.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_nodetree.c | 197 |
1 files changed, 151 insertions, 46 deletions
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 8423c1e58cc..26e11ed047b 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -426,75 +426,81 @@ static const EnumPropertyItem rna_node_geometry_triangulate_ngon_method_items[] {0, NULL, 0, NULL, NULL}, }; -# define ITEM_ATTRIBUTE \ - { \ - GEO_NODE_ATTRIBUTE_INPUT_ATTRIBUTE, "ATTRIBUTE", 0, "Attribute", "" \ - } -# define ITEM_FLOAT \ - { \ - GEO_NODE_ATTRIBUTE_INPUT_FLOAT, "FLOAT", 0, "Float", "" \ - } -# define ITEM_VECTOR \ - { \ - GEO_NODE_ATTRIBUTE_INPUT_VECTOR, "VECTOR", 0, "Vector", "" \ - } -# define ITEM_COLOR \ - { \ - GEO_NODE_ATTRIBUTE_INPUT_COLOR, "COLOR", 0, "Color", "" \ - } -# define ITEM_BOOLEAN \ - { \ - GEO_NODE_ATTRIBUTE_INPUT_BOOLEAN, "BOOLEAN", 0, "Boolean", "" \ - } +static const EnumPropertyItem rna_node_geometry_point_distribute_method_items[] = { + {GEO_NODE_POINT_DISTRIBUTE_RANDOM, + "RANDOM", + 0, + "Random", + "Distribute points randomly on the surface"}, + {GEO_NODE_POINT_DISTRIBUTE_POISSON, + "POISSON", + 0, + "Poisson Disk", + "Project points on the surface evenly with a Poisson disk distribution"}, + {0, NULL, 0, NULL, NULL}, +}; -static const EnumPropertyItem rna_node_geometry_attribute_input_type_items_float[] = { +#endif + +#define ITEM_ATTRIBUTE \ + { \ + GEO_NODE_ATTRIBUTE_INPUT_ATTRIBUTE, "ATTRIBUTE", 0, "Attribute", "" \ + } +#define ITEM_FLOAT \ + { \ + GEO_NODE_ATTRIBUTE_INPUT_FLOAT, "FLOAT", 0, "Float", "" \ + } +#define ITEM_VECTOR \ + { \ + GEO_NODE_ATTRIBUTE_INPUT_VECTOR, "VECTOR", 0, "Vector", "" \ + } +#define ITEM_COLOR \ + { \ + GEO_NODE_ATTRIBUTE_INPUT_COLOR, "COLOR", 0, "Color", "" \ + } +#define ITEM_BOOLEAN \ + { \ + GEO_NODE_ATTRIBUTE_INPUT_BOOLEAN, "BOOLEAN", 0, "Boolean", "" \ + } + +/* Used in both runtime and static code. */ +static const EnumPropertyItem rna_node_geometry_attribute_input_type_items_any[] = { ITEM_ATTRIBUTE, ITEM_FLOAT, + ITEM_VECTOR, + ITEM_COLOR, + ITEM_BOOLEAN, {0, NULL, 0, NULL, NULL}, }; + +#ifndef RNA_RUNTIME + static const EnumPropertyItem rna_node_geometry_attribute_input_type_items_vector[] = { ITEM_ATTRIBUTE, ITEM_VECTOR, {0, NULL, 0, NULL, NULL}, }; -static const EnumPropertyItem rna_node_geometry_attribute_input_type_items_no_boolean[] = { +static const EnumPropertyItem rna_node_geometry_attribute_input_type_items_float[] = { ITEM_ATTRIBUTE, ITEM_FLOAT, - ITEM_VECTOR, - ITEM_COLOR, {0, NULL, 0, NULL, NULL}, }; -static const EnumPropertyItem rna_node_geometry_attribute_input_type_items_any[] = { +static const EnumPropertyItem rna_node_geometry_attribute_input_type_items_no_boolean[] = { ITEM_ATTRIBUTE, ITEM_FLOAT, ITEM_VECTOR, ITEM_COLOR, - ITEM_BOOLEAN, - {0, NULL, 0, NULL, NULL}, -}; - -# undef ITEM_ATTRIBUTE -# undef ITEM_FLOAT -# undef ITEM_VECTOR -# undef ITEM_COLOR -# undef ITEM_BOOLEAN - -static const EnumPropertyItem rna_node_geometry_point_distribute_method_items[] = { - {GEO_NODE_POINT_DISTRIBUTE_RANDOM, - "RANDOM", - 0, - "Random", - "Distribute points randomly on the surface"}, - {GEO_NODE_POINT_DISTRIBUTE_POISSON, - "POISSON", - 0, - "Poisson Disk", - "Project points on the surface evenly with a Poisson disk distribution"}, {0, NULL, 0, NULL, NULL}, }; #endif +#undef ITEM_ATTRIBUTE +#undef ITEM_FLOAT +#undef ITEM_VECTOR +#undef ITEM_COLOR +#undef ITEM_BOOLEAN + #ifdef RNA_RUNTIME # include "BLI_linklist.h" @@ -521,6 +527,8 @@ static const EnumPropertyItem rna_node_geometry_point_distribute_method_items[] # include "DNA_scene_types.h" # include "WM_api.h" +static void rna_Node_socket_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr); + int rna_node_tree_type_to_enum(bNodeTreeType *typeinfo) { int i = 0, result = -1; @@ -1971,6 +1979,69 @@ static const EnumPropertyItem *rna_GeometryNodeAttributeMath_operation_itemf( return itemf_function_check(rna_enum_node_math_items, attribute_math_operation_supported); } +/** + * This bit of ugly code makes sure the float / attribute option shows up instead of + * vector / attribute if the node uses an operation that uses a float for input B. + */ +static const EnumPropertyItem *rna_GeometryNodeAttributeVectorMath_input_type_b_itemf( + bContext *UNUSED(C), PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *r_free) +{ + bNode *node = ptr->data; + NodeAttributeVectorMath *node_storage = (NodeAttributeVectorMath *)node->storage; + + EnumPropertyItem *item_array = NULL; + int items_len = 0; + for (const EnumPropertyItem *item = rna_node_geometry_attribute_input_type_items_any; + item->identifier != NULL; + item++) { + if (item->value == GEO_NODE_ATTRIBUTE_INPUT_ATTRIBUTE) { + RNA_enum_item_add(&item_array, &items_len, item); + } + else if (item->value == GEO_NODE_ATTRIBUTE_INPUT_FLOAT) { + if (node_storage->operation == NODE_VECTOR_MATH_SCALE) { + RNA_enum_item_add(&item_array, &items_len, item); + } + } + else if (item->value == GEO_NODE_ATTRIBUTE_INPUT_VECTOR) { + if (node_storage->operation != NODE_VECTOR_MATH_SCALE) { + RNA_enum_item_add(&item_array, &items_len, item); + } + } + } + RNA_enum_item_end(&item_array, &items_len); + + *r_free = true; + return item_array; +} + +static void rna_GeometryNodeAttributeVectorMath_operation_update(Main *bmain, + Scene *scene, + PointerRNA *ptr) +{ + bNode *node = ptr->data; + NodeAttributeVectorMath *node_storage = (NodeAttributeVectorMath *)node->storage; + + const NodeVectorMathOperation operation = (NodeVectorMathOperation)node_storage->operation; + + /* The scale operation can't use a vector input, so reset + * the input type enum in case it's set to vector. */ + if (operation == NODE_VECTOR_MATH_SCALE) { + if (node_storage->input_type_b == GEO_NODE_ATTRIBUTE_INPUT_VECTOR) { + node_storage->input_type_b = GEO_NODE_ATTRIBUTE_INPUT_FLOAT; + } + } + + /* Scale is also the only operation that uses the float input type, so a + * a check is also necessary for the other direction. */ + if (operation != NODE_VECTOR_MATH_SCALE) { + if (node_storage->input_type_b == GEO_NODE_ATTRIBUTE_INPUT_FLOAT) { + node_storage->input_type_b = GEO_NODE_ATTRIBUTE_INPUT_VECTOR; + } + } + + rna_Node_socket_update(bmain, scene, ptr); +} + static StructRNA *rna_ShaderNode_register(Main *bmain, ReportList *reports, void *data, @@ -8503,6 +8574,40 @@ static void def_geo_attribute_math(StructRNA *srna) RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); } +static void def_geo_attribute_vector_math(StructRNA *srna) +{ + PropertyRNA *prop; + + RNA_def_struct_sdna_from(srna, "NodeAttributeVectorMath", "storage"); + + prop = RNA_def_property(srna, "operation", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "operation"); + RNA_def_property_enum_items(prop, rna_enum_node_vec_math_items); + RNA_def_property_ui_text(prop, "Operation", ""); + RNA_def_property_update( + prop, NC_NODE | NA_EDITED, "rna_GeometryNodeAttributeVectorMath_operation_update"); + + prop = RNA_def_property(srna, "input_type_a", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_bitflag_sdna(prop, NULL, "input_type_a"); + RNA_def_property_enum_items(prop, rna_node_geometry_attribute_input_type_items_vector); + RNA_def_property_ui_text(prop, "Input Type A", ""); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); + + prop = RNA_def_property(srna, "input_type_b", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_bitflag_sdna(prop, NULL, "input_type_b"); + RNA_def_property_enum_items(prop, rna_node_geometry_attribute_input_type_items_any); + RNA_def_property_enum_funcs( + prop, NULL, NULL, "rna_GeometryNodeAttributeVectorMath_input_type_b_itemf"); + RNA_def_property_ui_text(prop, "Input Type B", ""); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); + + prop = RNA_def_property(srna, "input_type_c", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_bitflag_sdna(prop, NULL, "input_type_b"); + RNA_def_property_enum_items(prop, rna_node_geometry_attribute_input_type_items_vector); + RNA_def_property_ui_text(prop, "Input Type B", ""); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); +} + static void def_geo_point_instance(StructRNA *srna) { static const EnumPropertyItem instance_type_items[] = { |