diff options
Diffstat (limited to 'source/blender/makesrna/intern')
58 files changed, 3541 insertions, 2007 deletions
diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt index af8767a1220..7e6e3bcf90e 100644 --- a/source/blender/makesrna/intern/CMakeLists.txt +++ b/source/blender/makesrna/intern/CMakeLists.txt @@ -6,6 +6,11 @@ if(CMAKE_COMPILER_IS_GNUCC) string(APPEND CMAKE_C_FLAGS " -Werror=implicit-function-declaration") endif() +# Needed for `mallocn.c`. +if(HAVE_MALLOC_STATS_H) + add_definitions(-DHAVE_MALLOC_STATS_H) +endif() + # files rna_access.c rna_define.c makesrna.c intentionally excluded. set(DEFSRC rna_ID.c @@ -26,6 +31,7 @@ set(DEFSRC rna_context.c rna_curve.c rna_curveprofile.c + rna_curves.c rna_depsgraph.c rna_dynamicpaint.c rna_fcurve.c @@ -84,9 +90,7 @@ set(DEFSRC if(WITH_EXPERIMENTAL_FEATURES) add_definitions(-DWITH_SIMULATION_DATABLOCK) - add_definitions(-DWITH_NEW_CURVES_TYPE) list(APPEND DEFSRC - rna_curves.c rna_simulation.c ) endif() @@ -160,6 +164,7 @@ set(SRC_RNA_INC ../RNA_documentation.h ../RNA_enum_items.h ../RNA_enum_types.h + ../RNA_path.h ../RNA_types.h ) @@ -387,7 +392,6 @@ blender_include_dirs( ../../render ../../../../intern/cycles/blender ../../../../intern/atomic - ../../../../intern/glew-mx ../../../../intern/guardedalloc ../../../../intern/memutil ../../../../intern/mantaflow/extern @@ -417,6 +421,7 @@ add_custom_command( set(SRC rna_access.c rna_access_compare_override.c + rna_path.cc ${GENSRC} ${SRC_RNA_INC} @@ -449,8 +454,6 @@ set(LIB bf_editor_undo ) -add_definitions(${GL_DEFINITIONS}) - blender_add_lib(bf_rna "${SRC}" "${INC}" "${INC_SYS}" "${LIB}") # Needed so we can use dna_type_offsets.h for defaults initialization. diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c index 400944d60d4..a7b8488c371 100644 --- a/source/blender/makesrna/intern/makesrna.c +++ b/source/blender/makesrna/intern/makesrna.c @@ -826,7 +826,23 @@ static char *rna_def_property_get_func( fprintf(f, "{\n"); if (manualfunc) { - fprintf(f, " %s(ptr, values);\n", manualfunc); + /* Assign `fn` to ensure function signatures match. */ + if (prop->type == PROP_BOOLEAN) { + fprintf(f, " PropBooleanArrayGetFunc fn = %s;\n", manualfunc); + fprintf(f, " fn(ptr, values);\n"); + } + else if (prop->type == PROP_INT) { + fprintf(f, " PropIntArrayGetFunc fn = %s;\n", manualfunc); + fprintf(f, " fn(ptr, values);\n"); + } + else if (prop->type == PROP_FLOAT) { + fprintf(f, " PropFloatArrayGetFunc fn = %s;\n", manualfunc); + fprintf(f, " fn(ptr, values);\n"); + } + else { + BLI_assert_unreachable(); /* Valid but should be handled by type checks. */ + fprintf(f, " %s(ptr, values);\n", manualfunc); + } } else { rna_print_data_get(f, dp); @@ -902,7 +918,27 @@ static char *rna_def_property_get_func( fprintf(f, "{\n"); if (manualfunc) { - fprintf(f, " return %s(ptr);\n", manualfunc); + /* Assign `fn` to ensure function signatures match. */ + if (prop->type == PROP_BOOLEAN) { + fprintf(f, " PropBooleanGetFunc fn = %s;\n", manualfunc); + fprintf(f, " return fn(ptr);\n"); + } + else if (prop->type == PROP_INT) { + fprintf(f, " PropIntGetFunc fn = %s;\n", manualfunc); + fprintf(f, " return fn(ptr);\n"); + } + else if (prop->type == PROP_FLOAT) { + fprintf(f, " PropFloatGetFunc fn = %s;\n", manualfunc); + fprintf(f, " return fn(ptr);\n"); + } + else if (prop->type == PROP_ENUM) { + fprintf(f, " PropEnumGetFunc fn = %s;\n", manualfunc); + fprintf(f, " return fn(ptr);\n"); + } + else { + BLI_assert_unreachable(); /* Valid but should be handled by type checks. */ + fprintf(f, " return %s(ptr);\n", manualfunc); + } } else { rna_print_data_get(f, dp); @@ -1117,8 +1153,10 @@ static char *rna_def_property_set_func( fprintf( f, " if (data->%s != NULL) { MEM_freeN(data->%s); }\n", dp->dnaname, dp->dnaname); fprintf(f, " const int length = strlen(value);\n"); - fprintf(f, " data->%s = MEM_mallocN(length + 1, __func__);\n", dp->dnaname); - fprintf(f, " %s(data->%s, value, length + 1);\n", string_copy_func, dp->dnaname); + fprintf(f, " if (length > 0) {\n"); + fprintf(f, " data->%s = MEM_mallocN(length + 1, __func__);\n", dp->dnaname); + fprintf(f, " %s(data->%s, value, length + 1);\n", string_copy_func, dp->dnaname); + fprintf(f, " } else { data->%s = NULL; }\n", dp->dnaname); } else { /* Handle char array properties. */ @@ -1195,7 +1233,23 @@ static char *rna_def_property_set_func( fprintf(f, "{\n"); if (manualfunc) { - fprintf(f, " %s(ptr, values);\n", manualfunc); + /* Assign `fn` to ensure function signatures match. */ + if (prop->type == PROP_BOOLEAN) { + fprintf(f, " PropBooleanArraySetFunc fn = %s;\n", manualfunc); + fprintf(f, " fn(ptr, values);\n"); + } + else if (prop->type == PROP_INT) { + fprintf(f, " PropIntArraySetFunc fn = %s;\n", manualfunc); + fprintf(f, " fn(ptr, values);\n"); + } + else if (prop->type == PROP_FLOAT) { + fprintf(f, " PropFloatArraySetFunc fn = %s;\n", manualfunc); + fprintf(f, " fn(ptr, values);\n"); + } + else { + BLI_assert_unreachable(); /* Valid but should be handled by type checks. */ + fprintf(f, " %s(ptr, values);\n", manualfunc); + } } else { rna_print_data_get(f, dp); @@ -1287,7 +1341,27 @@ static char *rna_def_property_set_func( fprintf(f, "{\n"); if (manualfunc) { - fprintf(f, " %s(ptr, value);\n", manualfunc); + /* Assign `fn` to ensure function signatures match. */ + if (prop->type == PROP_BOOLEAN) { + fprintf(f, " PropBooleanSetFunc fn = %s;\n", manualfunc); + fprintf(f, " fn(ptr, value);\n"); + } + else if (prop->type == PROP_INT) { + fprintf(f, " PropIntSetFunc fn = %s;\n", manualfunc); + fprintf(f, " fn(ptr, value);\n"); + } + else if (prop->type == PROP_FLOAT) { + fprintf(f, " PropFloatSetFunc fn = %s;\n", manualfunc); + fprintf(f, " fn(ptr, value);\n"); + } + else if (prop->type == PROP_ENUM) { + fprintf(f, " PropEnumSetFunc fn = %s;\n", manualfunc); + fprintf(f, " fn(ptr, value);\n"); + } + else { + BLI_assert_unreachable(); /* Valid but should be handled by type checks. */ + fprintf(f, " %s(ptr, value);\n", manualfunc); + } } else { rna_print_data_get(f, dp); @@ -3030,7 +3104,7 @@ static void rna_def_function_funcs(FILE *f, StructDefRNA *dsrna, FunctionDefRNA } if (dparm->next) { - fprintf(f, "\t_data += %d;\n", rna_parameter_size(dparm->prop)); + fprintf(f, "\t_data += %d;\n", rna_parameter_size_pad(rna_parameter_size(dparm->prop))); } } @@ -4433,9 +4507,7 @@ static RNAProcessItem PROCESS_ITEMS[] = { {"rna_dynamicpaint.c", NULL, RNA_def_dynamic_paint}, {"rna_fcurve.c", "rna_fcurve_api.c", RNA_def_fcurve}, {"rna_gpencil.c", NULL, RNA_def_gpencil}, -#ifdef WITH_NEW_CURVES_TYPE {"rna_curves.c", NULL, RNA_def_curves}, -#endif {"rna_image.c", "rna_image_api.c", RNA_def_image}, {"rna_key.c", NULL, RNA_def_key}, {"rna_light.c", NULL, RNA_def_light}, diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index 8d2ee0ab534..d31a312816a 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -16,6 +16,7 @@ #include "BKE_icons.h" #include "BKE_lib_id.h" +#include "BKE_main_namemap.h" #include "BKE_object.h" #include "RNA_access.h" @@ -233,6 +234,10 @@ const struct IDFilterEnumPropertyItem rna_enum_id_type_filter_items[] = { # include "WM_api.h" +# ifdef WITH_PYTHON +# include "BPY_extern.h" +# endif + void rna_ID_override_library_property_operation_refname_get(PointerRNA *ptr, char *value) { IDOverrideLibraryPropertyOperation *opop = ptr->data; @@ -273,6 +278,7 @@ int rna_ID_name_length(PointerRNA *ptr) void rna_ID_name_set(PointerRNA *ptr, const char *value) { ID *id = (ID *)ptr->data; + BKE_main_namemap_remove_name(G_MAIN, id, id->name + 2); BLI_strncpy_utf8(id->name + 2, value, sizeof(id->name) - 2); BLI_assert(BKE_id_is_in_global_main(id)); BLI_libblock_ensure_unique_name(G_MAIN, id->name); @@ -316,7 +322,7 @@ int rna_ID_name_full_length(PointerRNA *ptr) return strlen(name); } -static int rna_ID_is_evaluated_get(PointerRNA *ptr) +static bool rna_ID_is_evaluated_get(PointerRNA *ptr) { ID *id = (ID *)ptr->data; @@ -375,11 +381,9 @@ short RNA_type_to_ID_code(const StructRNA *type) if (base_type == &RNA_FreestyleLineStyle) { return ID_LS; } -# ifdef WITH_NEW_CURVES_TYPE if (base_type == &RNA_Curves) { return ID_CV; } -# endif if (base_type == &RNA_Lattice) { return ID_LT; } @@ -483,11 +487,7 @@ StructRNA *ID_code_to_RNA_type(short idcode) case ID_GR: return &RNA_Collection; case ID_CV: -# ifdef WITH_NEW_CURVES_TYPE return &RNA_Curves; -# else - return &RNA_ID; -# endif case ID_IM: return &RNA_Image; case ID_KE: @@ -654,7 +654,7 @@ static ID *rna_ID_evaluated_get(ID *id, struct Depsgraph *depsgraph) static ID *rna_ID_copy(ID *id, Main *bmain) { - ID *newid = BKE_id_copy(bmain, id); + ID *newid = BKE_id_copy_for_use_in_bmain(bmain, id); if (newid != NULL) { id_us_min(newid); @@ -699,7 +699,16 @@ static ID *rna_ID_override_create(ID *id, Main *bmain, bool remap_local_usages) BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, true); } - ID *local_id = BKE_lib_override_library_create_from_id(bmain, id, remap_local_usages); + ID *local_id = NULL; +# ifdef WITH_PYTHON + BPy_BEGIN_ALLOW_THREADS; +# endif + + local_id = BKE_lib_override_library_create_from_id(bmain, id, remap_local_usages); + +# ifdef WITH_PYTHON + BPy_END_ALLOW_THREADS; +# endif if (remap_local_usages) { BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false); @@ -721,9 +730,18 @@ static ID *rna_ID_override_hierarchy_create( BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false); ID *id_root_override = NULL; + +# ifdef WITH_PYTHON + BPy_BEGIN_ALLOW_THREADS; +# endif + BKE_lib_override_library_create( bmain, scene, view_layer, NULL, id, id, id_instance_hint, &id_root_override, false); +# ifdef WITH_PYTHON + BPy_END_ALLOW_THREADS; +# endif + WM_main_add_notifier(NC_ID | NA_ADDED, NULL); WM_main_add_notifier(NC_WM | ND_LIB_OVERRIDE_CHANGED, NULL); @@ -2049,7 +2067,10 @@ static void rna_def_ID(BlenderRNA *brna) func = RNA_def_function(srna, "copy", "rna_ID_copy"); RNA_def_function_ui_description( - func, "Create a copy of this data-block (not supported for all data-blocks)"); + func, + "Create a copy of this data-block (not supported for all data-blocks). " + "The result is added to the Blend-File Data (Main database), with all references to other " + "data-blocks ensured to be from within the same Blend-File Data"); RNA_def_function_flag(func, FUNC_USE_MAIN); parm = RNA_def_pointer(func, "id", "ID", "", "New copy of the ID"); RNA_def_function_return(func, parm); @@ -2159,7 +2180,7 @@ static void rna_def_ID(BlenderRNA *brna) func = RNA_def_function(srna, "animation_data_clear", "rna_ID_animation_data_free"); RNA_def_function_flag(func, FUNC_USE_MAIN); - RNA_def_function_ui_description(func, "Clear animation on this this ID"); + RNA_def_function_ui_description(func, "Clear animation on this ID"); func = RNA_def_function(srna, "update_tag", "rna_ID_update_tag"); RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_REPORTS); diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 0bc35d86490..835265b1986 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -46,6 +46,7 @@ #include "RNA_access.h" #include "RNA_define.h" #include "RNA_enum_types.h" +#include "RNA_path.h" #include "WM_api.h" #include "WM_message.h" @@ -738,7 +739,7 @@ PropertyRNA *RNA_struct_find_property(PointerRNA *ptr, const char *identifier) } /* Find the property which uses the given nested struct */ -static PropertyRNA *RNA_struct_find_nested(PointerRNA *ptr, StructRNA *srna) +PropertyRNA *rna_struct_find_nested(PointerRNA *ptr, StructRNA *srna) { PropertyRNA *prop = NULL; @@ -1422,7 +1423,7 @@ StructRNA *RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop) return cprop->item_type; } } - /* ignore other types, RNA_struct_find_nested calls with unchecked props */ + /* ignore other types, rna_struct_find_nested calls with unchecked props */ return &RNA_UnknownType; } @@ -2072,7 +2073,7 @@ static void rna_property_update( } #if 1 - /* TODO(campbell): Should eventually be replaced entirely by message bus (below) + /* TODO(@campbellbarton): Should eventually be replaced entirely by message bus (below) * for now keep since COW, bugs are hard to track when we have other missing updates. */ if (prop->noteflag) { WM_main_add_notifier(prop->noteflag, ptr->owner_id); @@ -2141,6 +2142,7 @@ void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop) void RNA_property_update_main(Main *bmain, Scene *scene, PointerRNA *ptr, PropertyRNA *prop) { + BLI_assert(bmain != NULL); rna_property_update(NULL, bmain, scene, ptr, prop); } @@ -4078,6 +4080,20 @@ int RNA_property_collection_lookup_index(PointerRNA *ptr, return -1; } +bool RNA_property_collection_lookup_int_has_fn(PropertyRNA *prop) +{ + BLI_assert(RNA_property_type(prop) == PROP_COLLECTION); + CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)rna_ensure_property(prop); + return cprop->lookupint != NULL; +} + +bool RNA_property_collection_lookup_string_has_fn(PropertyRNA *prop) +{ + BLI_assert(RNA_property_type(prop) == PROP_COLLECTION); + CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)rna_ensure_property(prop); + return cprop->lookupstring != NULL; +} + int RNA_property_collection_lookup_int(PointerRNA *ptr, PropertyRNA *prop, int key, @@ -4820,1337 +4836,6 @@ PointerRNA rna_array_lookup_int( return rna_pointer_inherit_refine(ptr, type, ((char *)data) + index * itemsize); } -/* RNA Path - Experiment */ - -/** - * Extract the first token from `path`. - * - * \param path: Extract the token from path, step the pointer to the beginning of the next token - * \return The nil terminated token. - */ -static char *rna_path_token(const char **path, char *fixedbuf, int fixedlen) -{ - int len = 0; - - /* Get data until `.` or `[`. */ - const char *p = *path; - while (*p && !ELEM(*p, '.', '[')) { - len++; - p++; - } - - /* Empty, return. */ - if (UNLIKELY(len == 0)) { - return NULL; - } - - /* Try to use fixed buffer if possible. */ - char *buf = (len + 1 < fixedlen) ? fixedbuf : MEM_mallocN(sizeof(char) * (len + 1), __func__); - memcpy(buf, *path, sizeof(char) * len); - buf[len] = '\0'; - - if (*p == '.') { - p++; - } - *path = p; - - return buf; -} - -/** - * Extract the first token in brackets from `path` (with quoted text support). - * - * - `[0]` -> `0` - * - `["Some\"Quote"]` -> `Some"Quote` - * - * \param path: Extract the token from path, step the pointer to the beginning of the next token - * (past quoted text and brackets). - * \return The nil terminated token. - */ -static char *rna_path_token_in_brackets(const char **path, - char *fixedbuf, - int fixedlen, - bool *r_quoted) -{ - int len = 0; - bool quoted = false; - - BLI_assert(r_quoted != NULL); - - /* Get data between `[]`, check escaping quotes and back-slashes with #BLI_str_unescape. */ - if (UNLIKELY(**path != '[')) { - return NULL; - } - - (*path)++; - const char *p = *path; - - /* 2 kinds of look-ups now, quoted or unquoted. */ - if (*p == '"') { - /* Find the matching quote. */ - (*path)++; - p = *path; - const char *p_end = BLI_str_escape_find_quote(p); - if (p_end == NULL) { - /* No Matching quote. */ - return NULL; - } - /* Exclude the last quote from the length. */ - len += (p_end - p); - - /* Skip the last quoted char to get the `]`. */ - p_end += 1; - p = p_end; - quoted = true; - } - else { - /* Find the matching bracket. */ - while (*p && (*p != ']')) { - len++; - p++; - } - } - - if (UNLIKELY(*p != ']')) { - return NULL; - } - - /* Empty, return. */ - if (UNLIKELY(len == 0)) { - return NULL; - } - - /* Try to use fixed buffer if possible. */ - char *buf = (len + 1 < fixedlen) ? fixedbuf : MEM_mallocN(sizeof(char) * (len + 1), __func__); - - /* Copy string, taking into account escaped ']' */ - if (quoted) { - BLI_str_unescape(buf, *path, len); - /* +1 to step over the last quote. */ - BLI_assert((*path)[len] == '"'); - p = (*path) + len + 1; - } - else { - memcpy(buf, *path, sizeof(char) * len); - buf[len] = '\0'; - } - /* Set path to start of next token. */ - if (*p == ']') { - p++; - } - if (*p == '.') { - p++; - } - *path = p; - - *r_quoted = quoted; - - return buf; -} - -/** - * \return true when the key in the path is correctly parsed and found in the collection - * or when the path is empty. - */ -static bool rna_path_parse_collection_key(const char **path, - PointerRNA *ptr, - PropertyRNA *prop, - PointerRNA *r_nextptr) -{ - char fixedbuf[256]; - int intkey; - - *r_nextptr = *ptr; - - /* end of path, ok */ - if (!(**path)) { - return true; - } - - bool found = false; - if (**path == '[') { - bool quoted; - char *token; - - /* resolve the lookup with [] brackets */ - token = rna_path_token_in_brackets(path, fixedbuf, sizeof(fixedbuf), "ed); - - if (!token) { - return false; - } - - /* check for "" to see if it is a string */ - if (quoted) { - if (RNA_property_collection_lookup_string(ptr, prop, token, r_nextptr)) { - found = true; - } - else { - r_nextptr->data = NULL; - } - } - else { - /* otherwise do int lookup */ - intkey = atoi(token); - if (intkey == 0 && (token[0] != '0' || token[1] != '\0')) { - return false; /* we can be sure the fixedbuf was used in this case */ - } - if (RNA_property_collection_lookup_int(ptr, prop, intkey, r_nextptr)) { - found = true; - } - else { - r_nextptr->data = NULL; - } - } - - if (token != fixedbuf) { - MEM_freeN(token); - } - } - else { - if (RNA_property_collection_type_get(ptr, prop, r_nextptr)) { - found = true; - } - else { - /* ensure we quit on invalid values */ - r_nextptr->data = NULL; - } - } - - return found; -} - -static bool rna_path_parse_array_index(const char **path, - PointerRNA *ptr, - PropertyRNA *prop, - int *r_index) -{ - char fixedbuf[256]; - int index_arr[RNA_MAX_ARRAY_DIMENSION] = {0}; - int len[RNA_MAX_ARRAY_DIMENSION]; - const int dim = RNA_property_array_dimension(ptr, prop, len); - int i; - - *r_index = -1; - - /* end of path, ok */ - if (!(**path)) { - return true; - } - - for (i = 0; i < dim; i++) { - int temp_index = -1; - char *token; - - /* multi index resolve */ - if (**path == '[') { - bool quoted; - token = rna_path_token_in_brackets(path, fixedbuf, sizeof(fixedbuf), "ed); - - if (token == NULL) { - /* invalid syntax blah[] */ - return false; - } - /* check for "" to see if it is a string */ - if (quoted) { - temp_index = RNA_property_array_item_index(prop, *token); - } - else { - /* otherwise do int lookup */ - temp_index = atoi(token); - - if (temp_index == 0 && (token[0] != '0' || token[1] != '\0')) { - if (token != fixedbuf) { - MEM_freeN(token); - } - - return false; - } - } - } - else if (dim == 1) { - /* location.x || scale.X, single dimension arrays only */ - token = rna_path_token(path, fixedbuf, sizeof(fixedbuf)); - if (token == NULL) { - /* invalid syntax blah. */ - return false; - } - temp_index = RNA_property_array_item_index(prop, *token); - } - else { - /* just to avoid uninitialized pointer use */ - token = fixedbuf; - } - - if (token != fixedbuf) { - MEM_freeN(token); - } - - /* out of range */ - if (temp_index < 0 || temp_index >= len[i]) { - return false; - } - - index_arr[i] = temp_index; - /* end multi index resolve */ - } - - /* arrays always contain numbers so further values are not valid */ - if (**path) { - return false; - } - - /* flatten index over all dimensions */ - { - int totdim = 1; - int flat_index = 0; - - for (i = dim - 1; i >= 0; i--) { - flat_index += index_arr[i] * totdim; - totdim *= len[i]; - } - - *r_index = flat_index; - } - return true; -} - -/** - * Generic rna path parser. - * - * \note All parameters besides \a ptr and \a path are optional. - * - * \param ptr: The root of given RNA path. - * \param path: The RNA path. - * \param r_ptr: The final RNA data holding the last property in \a path. - * \param r_prop: The final property of \a r_ptr, from \a path. - * \param r_index: The final index in the \a r_prop, if defined by \a path. - * \param r_item_ptr: Only valid for Pointer and Collection, return the actual value of the - * pointer, or of the collection item. - * Mutually exclusive with \a eval_pointer option. - * \param r_elements: A list of \a PropertyElemRNA items(pairs of \a PointerRNA, \a PropertyRNA - * that represent the whole given \a path). - * \param eval_pointer: If \a true, and \a path leads to a Pointer property, or an item in a - * Collection property, \a r_ptr will be set to the value of that property, - * and \a r_prop will be NULL. - * Mutually exclusive with \a r_item_ptr. - * - * \return \a true on success, \a false if the path is somehow invalid. - */ -static bool rna_path_parse(const PointerRNA *ptr, - const char *path, - PointerRNA *r_ptr, - PropertyRNA **r_prop, - int *r_index, - PointerRNA *r_item_ptr, - ListBase *r_elements, - const bool eval_pointer) -{ - BLI_assert(r_item_ptr == NULL || !eval_pointer); - PropertyRNA *prop; - PointerRNA curptr, nextptr; - PropertyElemRNA *prop_elem = NULL; - int index = -1; - char fixedbuf[256]; - int type; - const bool do_item_ptr = r_item_ptr != NULL && !eval_pointer; - - if (do_item_ptr) { - RNA_POINTER_INVALIDATE(&nextptr); - } - - prop = NULL; - curptr = *ptr; - - if (path == NULL || *path == '\0') { - return false; - } - - while (*path) { - if (do_item_ptr) { - RNA_POINTER_INVALIDATE(&nextptr); - } - - const bool use_id_prop = (*path == '['); - /* custom property lookup ? - * C.object["someprop"] - */ - - if (!curptr.data) { - return false; - } - - /* look up property name in current struct */ - bool quoted = false; - char *token = use_id_prop ? - rna_path_token_in_brackets(&path, fixedbuf, sizeof(fixedbuf), "ed) : - rna_path_token(&path, fixedbuf, sizeof(fixedbuf)); - if (!token) { - return false; - } - - prop = NULL; - if (use_id_prop) { /* look up property name in current struct */ - IDProperty *group = RNA_struct_idprops(&curptr, 0); - if (group && quoted) { - prop = (PropertyRNA *)IDP_GetPropertyFromGroup(group, token); - } - } - else { - prop = RNA_struct_find_property(&curptr, token); - } - - if (token != fixedbuf) { - MEM_freeN(token); - } - - if (!prop) { - return false; - } - - if (r_elements) { - prop_elem = MEM_mallocN(sizeof(PropertyElemRNA), __func__); - prop_elem->ptr = curptr; - prop_elem->prop = prop; - prop_elem->index = -1; /* index will be added later, if needed. */ - BLI_addtail(r_elements, prop_elem); - } - - type = RNA_property_type(prop); - - /* now look up the value of this property if it is a pointer or - * collection, otherwise return the property rna so that the - * caller can read the value of the property itself */ - switch (type) { - case PROP_POINTER: { - /* resolve pointer if further path elements follow - * or explicitly requested - */ - if (do_item_ptr || eval_pointer || *path != '\0') { - nextptr = RNA_property_pointer_get(&curptr, prop); - } - - if (eval_pointer || *path != '\0') { - curptr = nextptr; - prop = NULL; /* now we have a PointerRNA, the prop is our parent so forget it */ - index = -1; - } - break; - } - case PROP_COLLECTION: { - /* Resolve pointer if further path elements follow. - * Note that if path is empty, rna_path_parse_collection_key will do nothing anyway, - * so do_item_ptr is of no use in that case. - */ - if (*path) { - if (!rna_path_parse_collection_key(&path, &curptr, prop, &nextptr)) { - return false; - } - - if (eval_pointer || *path != '\0') { - curptr = nextptr; - prop = NULL; /* now we have a PointerRNA, the prop is our parent so forget it */ - index = -1; - } - } - break; - } - default: - if (r_index || prop_elem) { - if (!rna_path_parse_array_index(&path, &curptr, prop, &index)) { - return false; - } - - if (prop_elem) { - prop_elem->index = index; - } - } - break; - } - } - - if (r_ptr) { - *r_ptr = curptr; - } - if (r_prop) { - *r_prop = prop; - } - if (r_index) { - *r_index = index; - } - if (r_item_ptr && do_item_ptr) { - *r_item_ptr = nextptr; - } - - if (prop_elem && (prop_elem->ptr.data != curptr.data || prop_elem->prop != prop || - prop_elem->index != index)) { - prop_elem = MEM_mallocN(sizeof(PropertyElemRNA), __func__); - prop_elem->ptr = curptr; - prop_elem->prop = prop; - prop_elem->index = index; - BLI_addtail(r_elements, prop_elem); - } - - return true; -} - -bool RNA_path_resolve(const PointerRNA *ptr, - const char *path, - PointerRNA *r_ptr, - PropertyRNA **r_prop) -{ - if (!rna_path_parse(ptr, path, r_ptr, r_prop, NULL, NULL, NULL, true)) { - return false; - } - - return r_ptr->data != NULL; -} - -bool RNA_path_resolve_full( - const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index) -{ - if (!rna_path_parse(ptr, path, r_ptr, r_prop, r_index, NULL, NULL, true)) { - return false; - } - - return r_ptr->data != NULL; -} - -bool RNA_path_resolve_full_maybe_null( - const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index) -{ - return rna_path_parse(ptr, path, r_ptr, r_prop, r_index, NULL, NULL, true); -} - -bool RNA_path_resolve_property(const PointerRNA *ptr, - const char *path, - PointerRNA *r_ptr, - PropertyRNA **r_prop) -{ - if (!rna_path_parse(ptr, path, r_ptr, r_prop, NULL, NULL, NULL, false)) { - return false; - } - - return r_ptr->data != NULL && *r_prop != NULL; -} - -bool RNA_path_resolve_property_full( - const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index) -{ - if (!rna_path_parse(ptr, path, r_ptr, r_prop, r_index, NULL, NULL, false)) { - return false; - } - - return r_ptr->data != NULL && *r_prop != NULL; -} - -bool RNA_path_resolve_property_and_item_pointer(const PointerRNA *ptr, - const char *path, - PointerRNA *r_ptr, - PropertyRNA **r_prop, - PointerRNA *r_item_ptr) -{ - if (!rna_path_parse(ptr, path, r_ptr, r_prop, NULL, r_item_ptr, NULL, false)) { - return false; - } - - return r_ptr->data != NULL && *r_prop != NULL; -} - -bool RNA_path_resolve_property_and_item_pointer_full(const PointerRNA *ptr, - const char *path, - PointerRNA *r_ptr, - PropertyRNA **r_prop, - int *r_index, - PointerRNA *r_item_ptr) -{ - if (!rna_path_parse(ptr, path, r_ptr, r_prop, r_index, r_item_ptr, NULL, false)) { - return false; - } - - return r_ptr->data != NULL && *r_prop != NULL; -} -bool RNA_path_resolve_elements(PointerRNA *ptr, const char *path, ListBase *r_elements) -{ - return rna_path_parse(ptr, path, NULL, NULL, NULL, NULL, r_elements, false); -} - -char *RNA_path_append(const char *path, - const PointerRNA *UNUSED(ptr), - PropertyRNA *prop, - int intkey, - const char *strkey) -{ - DynStr *dynstr; - char *result; - - dynstr = BLI_dynstr_new(); - - /* add .identifier */ - if (path) { - BLI_dynstr_append(dynstr, path); - if (*path) { - BLI_dynstr_append(dynstr, "."); - } - } - - BLI_dynstr_append(dynstr, RNA_property_identifier(prop)); - - if (RNA_property_type(prop) == PROP_COLLECTION) { - /* add ["strkey"] or [intkey] */ - BLI_dynstr_append(dynstr, "["); - - if (strkey) { - const int strkey_esc_max_size = (strlen(strkey) * 2) + 1; - char *strkey_esc = BLI_array_alloca(strkey_esc, strkey_esc_max_size); - BLI_str_escape(strkey_esc, strkey, strkey_esc_max_size); - BLI_dynstr_append(dynstr, "\""); - BLI_dynstr_append(dynstr, strkey_esc); - BLI_dynstr_append(dynstr, "\""); - } - else { - char appendstr[128]; - BLI_snprintf(appendstr, sizeof(appendstr), "%d", intkey); - BLI_dynstr_append(dynstr, appendstr); - } - - BLI_dynstr_append(dynstr, "]"); - } - - result = BLI_dynstr_get_cstring(dynstr); - BLI_dynstr_free(dynstr); - - return result; -} - -/* Having both path append & back seems like it could be useful, - * this function isn't used at the moment. */ -static UNUSED_FUNCTION_WITH_RETURN_TYPE(char *, RNA_path_back)(const char *path) -{ - char fixedbuf[256]; - const char *previous, *current; - char *result; - int i; - - if (!path) { - return NULL; - } - - previous = NULL; - current = path; - - /* parse token by token until the end, then we back up to the previous - * position and strip of the next token to get the path one step back */ - while (*current) { - char *token; - - token = rna_path_token(¤t, fixedbuf, sizeof(fixedbuf)); - - if (!token) { - return NULL; - } - if (token != fixedbuf) { - MEM_freeN(token); - } - - /* in case of collection we also need to strip off [] */ - bool quoted; - token = rna_path_token_in_brackets(¤t, fixedbuf, sizeof(fixedbuf), "ed); - if (token && token != fixedbuf) { - MEM_freeN(token); - } - - if (!*current) { - break; - } - - previous = current; - } - - if (!previous) { - return NULL; - } - - /* copy and strip off last token */ - i = previous - path; - result = BLI_strdup(path); - - if (i > 0 && result[i - 1] == '.') { - i--; - } - result[i] = 0; - - return result; -} - -const char *RNA_path_array_index_token_find(const char *rna_path, const PropertyRNA *array_prop) -{ - if (array_prop != NULL) { - if (!ELEM(array_prop->type, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) { - BLI_assert(array_prop->arraydimension == 0); - return NULL; - } - if (array_prop->arraydimension == 0) { - return NULL; - } - } - - /* Valid 'array part' of a rna path can only have '[', ']' and digit characters. - * It may have more than one of those (e.g. `[12][1]`) in case of multi-dimensional arrays. */ - off_t rna_path_len = (off_t)strlen(rna_path); - if (rna_path[rna_path_len] != ']') { - return NULL; - } - const char *last_valid_index_token_start = NULL; - for (rna_path_len--; rna_path_len >= 0; rna_path_len--) { - switch (rna_path[rna_path_len]) { - case '[': - if (rna_path_len <= 0 || rna_path[rna_path_len - 1] != ']') { - return &rna_path[rna_path_len]; - } - last_valid_index_token_start = &rna_path[rna_path_len]; - rna_path_len--; - break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - break; - default: - return last_valid_index_token_start; - } - } - return last_valid_index_token_start; -} - -/* generic path search func - * if its needed this could also reference the IDProperty direct */ -typedef struct IDP_Chain { - struct IDP_Chain *up; /* parent member, reverse and set to child for path conversion. */ - - const char *name; - int index; - -} IDP_Chain; - -static char *rna_idp_path_create(IDP_Chain *child_link) -{ - DynStr *dynstr = BLI_dynstr_new(); - char *path; - bool is_first = true; - - int tot = 0; - IDP_Chain *link = child_link; - - /* reverse the list */ - IDP_Chain *link_prev; - link_prev = NULL; - while (link) { - IDP_Chain *link_next = link->up; - link->up = link_prev; - link_prev = link; - link = link_next; - tot++; - } - - for (link = link_prev; link; link = link->up) { - /* pass */ - if (link->index >= 0) { - BLI_dynstr_appendf(dynstr, is_first ? "%s[%d]" : ".%s[%d]", link->name, link->index); - } - else { - BLI_dynstr_appendf(dynstr, is_first ? "%s" : ".%s", link->name); - } - - is_first = false; - } - - path = BLI_dynstr_get_cstring(dynstr); - BLI_dynstr_free(dynstr); - - if (*path == '\0') { - MEM_freeN(path); - path = NULL; - } - - return path; -} - -static char *rna_idp_path(PointerRNA *ptr, - IDProperty *haystack, - IDProperty *needle, - IDP_Chain *parent_link) -{ - char *path = NULL; - IDP_Chain link; - - IDProperty *iter; - int i; - - BLI_assert(haystack->type == IDP_GROUP); - - link.up = parent_link; - /* Always set both name and index, else a stale value might get used. */ - link.name = NULL; - link.index = -1; - - for (i = 0, iter = haystack->data.group.first; iter; iter = iter->next, i++) { - if (needle == iter) { /* found! */ - link.name = iter->name; - link.index = -1; - path = rna_idp_path_create(&link); - break; - } - - /* Early out in case the IDProperty type cannot contain RNA properties. */ - if (!ELEM(iter->type, IDP_GROUP, IDP_IDPARRAY)) { - continue; - } - - /* Ensure this is RNA. */ - /* NOTE: `iter` might be a fully user-defined IDProperty (a.k.a. custom data), which name - * collides with an actual fully static RNA property of the same struct (which would then not - * be flagged with `PROP_IDPROPERTY`). - * - * That case must be ignored here, we only want to deal with runtime RNA properties stored in - * IDProps. - * - * See T84091. */ - PropertyRNA *prop = RNA_struct_find_property(ptr, iter->name); - if (prop == NULL || (prop->flag & PROP_IDPROPERTY) == 0) { - continue; - } - - if (iter->type == IDP_GROUP) { - if (prop->type == PROP_POINTER) { - PointerRNA child_ptr = RNA_property_pointer_get(ptr, prop); - if (RNA_pointer_is_null(&child_ptr)) { - /* Pointer ID prop might be a 'leaf' in the IDProp group hierarchy, in which case a NULL - * value is perfectly valid. Just means it won't match the searched needle. */ - continue; - } - - link.name = iter->name; - link.index = -1; - if ((path = rna_idp_path(&child_ptr, iter, needle, &link))) { - break; - } - } - } - else if (iter->type == IDP_IDPARRAY) { - if (prop->type == PROP_COLLECTION) { - IDProperty *array = IDP_IDPArray(iter); - if (needle >= array && needle < (iter->len + array)) { /* found! */ - link.name = iter->name; - link.index = (int)(needle - array); - path = rna_idp_path_create(&link); - break; - } - int j; - link.name = iter->name; - for (j = 0; j < iter->len; j++, array++) { - PointerRNA child_ptr; - if (RNA_property_collection_lookup_int(ptr, prop, j, &child_ptr)) { - if (RNA_pointer_is_null(&child_ptr)) { - /* Array item ID prop might be a 'leaf' in the IDProp group hierarchy, in which case - * a NULL value is perfectly valid. Just means it won't match the searched needle. */ - continue; - } - link.index = j; - if ((path = rna_idp_path(&child_ptr, array, needle, &link))) { - break; - } - } - } - if (path) { - break; - } - } - } - } - - return path; -} - -char *RNA_path_from_struct_to_idproperty(PointerRNA *ptr, IDProperty *needle) -{ - IDProperty *haystack = RNA_struct_idprops(ptr, false); - - if (haystack) { /* can fail when called on bones */ - return rna_idp_path(ptr, haystack, needle, NULL); - } - return NULL; -} - -static char *rna_path_from_ID_to_idpgroup(const PointerRNA *ptr) -{ - PointerRNA id_ptr; - - BLI_assert(ptr->owner_id != NULL); - - /* TODO: Support Bones/PoseBones. no pointers stored to the bones from here, only the ID. - * See example in T25746. - * Unless this is added only way to find this is to also search - * all bones and pose bones of an armature or object. - */ - RNA_id_pointer_create(ptr->owner_id, &id_ptr); - - return RNA_path_from_struct_to_idproperty(&id_ptr, ptr->data); -} - -ID *RNA_find_real_ID_and_path(Main *bmain, ID *id, const char **r_path) -{ - if (r_path) { - *r_path = ""; - } - - if ((id == NULL) || (id->flag & LIB_EMBEDDED_DATA) == 0) { - return id; - } - - const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id); - if (r_path) { - switch (GS(id->name)) { - case ID_NT: - *r_path = "node_tree"; - break; - case ID_GR: - *r_path = "collection"; - break; - default: - BLI_assert_msg(0, "Missing handling of embedded id type."); - } - } - - if (id_type->owner_get == NULL) { - BLI_assert_msg(0, "Missing handling of embedded id type."); - return id; - } - return id_type->owner_get(bmain, id); -} - -static char *rna_prepend_real_ID_path(Main *bmain, ID *id, char *path, ID **r_real_id) -{ - if (r_real_id != NULL) { - *r_real_id = NULL; - } - - const char *prefix; - ID *real_id = RNA_find_real_ID_and_path(bmain, id, &prefix); - - if (r_real_id != NULL) { - *r_real_id = real_id; - } - - if (path != NULL) { - char *new_path = NULL; - - if (real_id) { - if (prefix[0]) { - new_path = BLI_sprintfN("%s%s%s", prefix, path[0] == '[' ? "" : ".", path); - } - else { - return path; - } - } - - MEM_freeN(path); - return new_path; - } - return prefix[0] != '\0' ? BLI_strdup(prefix) : NULL; -} - -char *RNA_path_from_ID_to_struct(const PointerRNA *ptr) -{ - char *ptrpath = NULL; - - if (!ptr->owner_id || !ptr->data) { - return NULL; - } - - if (!RNA_struct_is_ID(ptr->type)) { - if (ptr->type->path) { - /* if type has a path to some ID, use it */ - ptrpath = ptr->type->path((PointerRNA *)ptr); - } - else if (ptr->type->nested && RNA_struct_is_ID(ptr->type->nested)) { - PointerRNA parentptr; - PropertyRNA *userprop; - - /* find the property in the struct we're nested in that references this struct, and - * use its identifier as the first part of the path used... - */ - RNA_id_pointer_create(ptr->owner_id, &parentptr); - userprop = RNA_struct_find_nested(&parentptr, ptr->type); - - if (userprop) { - ptrpath = BLI_strdup(RNA_property_identifier(userprop)); - } - else { - return NULL; /* can't do anything about this case yet... */ - } - } - else if (RNA_struct_is_a(ptr->type, &RNA_PropertyGroup)) { - /* special case, easier to deal with here than in ptr->type->path() */ - return rna_path_from_ID_to_idpgroup(ptr); - } - else { - return NULL; - } - } - - return ptrpath; -} - -char *RNA_path_from_real_ID_to_struct(Main *bmain, const PointerRNA *ptr, struct ID **r_real) -{ - char *path = RNA_path_from_ID_to_struct(ptr); - - /* NULL path is valid in that case, when given struct is an ID one... */ - return rna_prepend_real_ID_path(bmain, ptr->owner_id, path, r_real); -} - -static void rna_path_array_multi_from_flat_index(const int dimsize[RNA_MAX_ARRAY_LENGTH], - const int totdims, - const int index_dim, - int index, - int r_index_multi[RNA_MAX_ARRAY_LENGTH]) -{ - int dimsize_step[RNA_MAX_ARRAY_LENGTH + 1]; - int i = totdims - 1; - dimsize_step[i + 1] = 1; - dimsize_step[i] = dimsize[i]; - while (--i != -1) { - dimsize_step[i] = dimsize[i] * dimsize_step[i + 1]; - } - while (++i != index_dim) { - int index_round = index / dimsize_step[i + 1]; - r_index_multi[i] = index_round; - index -= (index_round * dimsize_step[i + 1]); - } - BLI_assert(index == 0); -} - -static void rna_path_array_multi_string_from_flat_index(const PointerRNA *ptr, - PropertyRNA *prop, - int index_dim, - int index, - char *index_str, - int index_str_len) -{ - int dimsize[RNA_MAX_ARRAY_LENGTH]; - int totdims = RNA_property_array_dimension(ptr, prop, dimsize); - int index_multi[RNA_MAX_ARRAY_LENGTH]; - - rna_path_array_multi_from_flat_index(dimsize, totdims, index_dim, index, index_multi); - - for (int i = 0, offset = 0; (i < index_dim) && (offset < index_str_len); i++) { - offset += BLI_snprintf_rlen( - &index_str[offset], index_str_len - offset, "[%d]", index_multi[i]); - } -} - -char *RNA_path_from_ID_to_property_index(const PointerRNA *ptr, - PropertyRNA *prop, - int index_dim, - int index) -{ - const bool is_rna = (prop->magic == RNA_MAGIC); - const char *propname; - char *ptrpath, *path; - - if (!ptr->owner_id || !ptr->data) { - return NULL; - } - - /* path from ID to the struct holding this property */ - ptrpath = RNA_path_from_ID_to_struct(ptr); - - propname = RNA_property_identifier(prop); - - /* support indexing w/ multi-dimensional arrays */ - char index_str[RNA_MAX_ARRAY_LENGTH * 12 + 1]; - if (index_dim == 0) { - index_str[0] = '\0'; - } - else { - rna_path_array_multi_string_from_flat_index( - ptr, prop, index_dim, index, index_str, sizeof(index_str)); - } - - if (ptrpath) { - if (is_rna) { - path = BLI_sprintfN("%s.%s%s", ptrpath, propname, index_str); - } - else { - char propname_esc[MAX_IDPROP_NAME * 2]; - BLI_str_escape(propname_esc, propname, sizeof(propname_esc)); - path = BLI_sprintfN("%s[\"%s\"]%s", ptrpath, propname_esc, index_str); - } - MEM_freeN(ptrpath); - } - else if (RNA_struct_is_ID(ptr->type)) { - if (is_rna) { - path = BLI_sprintfN("%s%s", propname, index_str); - } - else { - char propname_esc[MAX_IDPROP_NAME * 2]; - BLI_str_escape(propname_esc, propname, sizeof(propname_esc)); - path = BLI_sprintfN("[\"%s\"]%s", propname_esc, index_str); - } - } - else { - path = NULL; - } - - return path; -} - -char *RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop) -{ - return RNA_path_from_ID_to_property_index(ptr, prop, 0, -1); -} - -char *RNA_path_from_real_ID_to_property_index(Main *bmain, - const PointerRNA *ptr, - PropertyRNA *prop, - int index_dim, - int index, - ID **r_real_id) -{ - char *path = RNA_path_from_ID_to_property_index(ptr, prop, index_dim, index); - - /* NULL path is always an error here, in that case do not return the 'fake ID from real ID' part - * of the path either. */ - return path != NULL ? rna_prepend_real_ID_path(bmain, ptr->owner_id, path, r_real_id) : NULL; -} - -char *RNA_path_resolve_from_type_to_property(const PointerRNA *ptr, - PropertyRNA *prop, - const StructRNA *type) -{ - /* Try to recursively find an "type"'d ancestor, - * to handle situations where path from ID is not enough. */ - PointerRNA idptr; - ListBase path_elems = {NULL}; - char *path = NULL; - char *full_path = RNA_path_from_ID_to_property(ptr, prop); - - if (full_path == NULL) { - return NULL; - } - - RNA_id_pointer_create(ptr->owner_id, &idptr); - - if (RNA_path_resolve_elements(&idptr, full_path, &path_elems)) { - PropertyElemRNA *prop_elem; - - for (prop_elem = path_elems.last; prop_elem; prop_elem = prop_elem->prev) { - if (RNA_struct_is_a(prop_elem->ptr.type, type)) { - char *ref_path = RNA_path_from_ID_to_struct(&prop_elem->ptr); - if (ref_path) { - path = BLI_strdup(full_path + strlen(ref_path) + 1); /* +1 for the linking '.' */ - MEM_freeN(ref_path); - } - break; - } - } - - BLI_freelistN(&path_elems); - } - - MEM_freeN(full_path); - return path; -} - -char *RNA_path_full_ID_py(Main *bmain, ID *id) -{ - const char *path; - ID *id_real = RNA_find_real_ID_and_path(bmain, id, &path); - - if (id_real) { - id = id_real; - } - else { - path = ""; - } - - char lib_filepath_esc[(sizeof(id->lib->filepath) * 2) + 4]; - if (ID_IS_LINKED(id)) { - int ofs = 0; - memcpy(lib_filepath_esc, ", \"", 3); - ofs += 3; - ofs += BLI_str_escape(lib_filepath_esc + ofs, id->lib->filepath, sizeof(lib_filepath_esc)); - memcpy(lib_filepath_esc + ofs, "\"", 2); - } - else { - lib_filepath_esc[0] = '\0'; - } - - char id_esc[(sizeof(id->name) - 2) * 2]; - BLI_str_escape(id_esc, id->name + 2, sizeof(id_esc)); - - return BLI_sprintfN("bpy.data.%s[\"%s\"%s]%s%s", - BKE_idtype_idcode_to_name_plural(GS(id->name)), - id_esc, - lib_filepath_esc, - path[0] ? "." : "", - path); -} - -char *RNA_path_full_struct_py(Main *bmain, const PointerRNA *ptr) -{ - char *id_path; - char *data_path; - - char *ret; - - if (!ptr->owner_id) { - return NULL; - } - - /* never fails */ - id_path = RNA_path_full_ID_py(bmain, ptr->owner_id); - - data_path = RNA_path_from_ID_to_struct(ptr); - - /* XXX data_path may be NULL (see T36788), - * do we want to get the 'bpy.data.foo["bar"].(null)' stuff? */ - ret = BLI_sprintfN("%s.%s", id_path, data_path); - - if (data_path) { - MEM_freeN(data_path); - } - MEM_freeN(id_path); - - return ret; -} - -char *RNA_path_full_property_py_ex( - Main *bmain, const PointerRNA *ptr, PropertyRNA *prop, int index, bool use_fallback) -{ - char *id_path; - const char *data_delim; - const char *data_path; - bool data_path_free; - - char *ret; - - if (!ptr->owner_id) { - return NULL; - } - - /* never fails */ - id_path = RNA_path_full_ID_py(bmain, ptr->owner_id); - - data_path = RNA_path_from_ID_to_property(ptr, prop); - if (data_path) { - data_delim = (data_path[0] == '[') ? "" : "."; - data_path_free = true; - } - else { - if (use_fallback) { - /* Fuzzy fallback. Be explicit in our ignorance. */ - data_path = RNA_property_identifier(prop); - data_delim = " ... "; - } - else { - data_delim = "."; - } - data_path_free = false; - } - - if ((index == -1) || (RNA_property_array_check(prop) == false)) { - ret = BLI_sprintfN("%s%s%s", id_path, data_delim, data_path); - } - else { - ret = BLI_sprintfN("%s%s%s[%d]", id_path, data_delim, data_path, index); - } - MEM_freeN(id_path); - if (data_path_free) { - MEM_freeN((void *)data_path); - } - - return ret; -} - -char *RNA_path_full_property_py(Main *bmain, const PointerRNA *ptr, PropertyRNA *prop, int index) -{ - return RNA_path_full_property_py_ex(bmain, ptr, prop, index, false); -} - -char *RNA_path_struct_property_py(PointerRNA *ptr, PropertyRNA *prop, int index) -{ - char *data_path; - - char *ret; - - if (!ptr->owner_id) { - return NULL; - } - - data_path = RNA_path_from_ID_to_property(ptr, prop); - - if (data_path == NULL) { - /* This may not be an ID at all, check for simple when pointer owns property. - * TODO: more complex nested case. */ - if (!RNA_struct_is_ID(ptr->type)) { - const char *prop_identifier = RNA_property_identifier(prop); - if (RNA_struct_find_property(ptr, prop_identifier) == prop) { - data_path = BLI_strdup(prop_identifier); - } - } - } - - if ((index == -1) || (RNA_property_array_check(prop) == false)) { - ret = BLI_strdup(data_path); - } - else { - ret = BLI_sprintfN("%s[%d]", data_path, index); - } - - if (data_path) { - MEM_freeN(data_path); - } - - return ret; -} - -char *RNA_path_property_py(const PointerRNA *UNUSED(ptr), PropertyRNA *prop, int index) -{ - const bool is_rna = (prop->magic == RNA_MAGIC); - const char *propname = RNA_property_identifier(prop); - char *ret; - - if ((index == -1) || (RNA_property_array_check(prop) == false)) { - if (is_rna) { - ret = BLI_strdup(propname); - } - else { - char propname_esc[MAX_IDPROP_NAME * 2]; - BLI_str_escape(propname_esc, propname, sizeof(propname_esc)); - ret = BLI_sprintfN("[\"%s\"]", propname_esc); - } - } - else { - if (is_rna) { - ret = BLI_sprintfN("%s[%d]", propname, index); - } - else { - char propname_esc[MAX_IDPROP_NAME * 2]; - BLI_str_escape(propname_esc, propname, sizeof(propname_esc)); - ret = BLI_sprintfN("[\"%s\"][%d]", propname_esc, index); - } - } - - return ret; -} - /* Quick name based property access */ bool RNA_boolean_get(PointerRNA *ptr, const char *name) @@ -6661,15 +5346,15 @@ char *RNA_pointer_as_string_id(bContext *C, PointerRNA *ptr) return cstring; } -static char *rna_pointer_as_string__bldata(Main *bmain, PointerRNA *ptr) +static char *rna_pointer_as_string__bldata(PointerRNA *ptr) { if (ptr->type == NULL || ptr->owner_id == NULL) { return BLI_strdup("None"); } if (RNA_struct_is_ID(ptr->type)) { - return RNA_path_full_ID_py(bmain, ptr->owner_id); + return RNA_path_full_ID_py(ptr->owner_id); } - return RNA_path_full_struct_py(bmain, ptr); + return RNA_path_full_struct_py(ptr); } char *RNA_pointer_as_string(bContext *C, @@ -6684,7 +5369,7 @@ char *RNA_pointer_as_string(bContext *C, if ((prop = rna_idproperty_check(&prop_ptr, ptr)) && prop->type != IDP_ID) { return RNA_pointer_as_string_id(C, ptr_prop); } - return rna_pointer_as_string__bldata(CTX_data_main(C), ptr_prop); + return rna_pointer_as_string__bldata(ptr_prop); } char *RNA_pointer_as_string_keywords_ex(bContext *C, @@ -7130,7 +5815,7 @@ ParameterList *RNA_parameter_list_create(ParameterList *parms, /* allocate data */ for (parm = func->cont.properties.first; parm; parm = parm->next) { - alloc_size += rna_parameter_size(parm); + alloc_size += rna_parameter_size_pad(rna_parameter_size(parm)); if (parm->flag_parameter & PARM_OUTPUT) { parms->ret_count++; @@ -7206,7 +5891,7 @@ ParameterList *RNA_parameter_list_create(ParameterList *parms, } } - data = ((char *)data) + rna_parameter_size(parm); + data = ((char *)data) + rna_parameter_size_pad(size); } return parms; @@ -7230,7 +5915,7 @@ void RNA_parameter_list_free(ParameterList *parms) } } - tot += rna_parameter_size(parm); + tot += rna_parameter_size_pad(rna_parameter_size(parm)); } MEM_freeN(parms->data); @@ -7272,7 +5957,7 @@ void RNA_parameter_list_begin(ParameterList *parms, ParameterIterator *iter) void RNA_parameter_list_next(ParameterIterator *iter) { - iter->offset += iter->size; + iter->offset += rna_parameter_size_pad(iter->size); iter->parm = iter->parm->next; iter->valid = iter->parm != NULL; diff --git a/source/blender/makesrna/intern/rna_access_compare_override.c b/source/blender/makesrna/intern/rna_access_compare_override.c index 17c00923efa..808578b4746 100644 --- a/source/blender/makesrna/intern/rna_access_compare_override.c +++ b/source/blender/makesrna/intern/rna_access_compare_override.c @@ -38,6 +38,7 @@ #include "RNA_access.h" #include "RNA_define.h" #include "RNA_enum_types.h" +#include "RNA_path.h" #include "RNA_prototypes.h" #include "rna_access_internal.h" @@ -53,7 +54,7 @@ static CLG_LogRef LOG = {"rna.access_compare_override"}; * #RNA_find_real_ID_and_path, since in overrides we also consider shape keys as embedded data, not * only root node trees and master collections. */ -static ID *rna_property_override_property_real_id_owner(Main *bmain, +static ID *rna_property_override_property_real_id_owner(Main *UNUSED(bmain), PointerRNA *ptr, PropertyRNA *prop, char **r_rna_path) @@ -85,7 +86,7 @@ static ID *rna_property_override_property_real_id_owner(Main *bmain, case ID_GR: case ID_NT: /* Master collections, Root node trees. */ - owner_id = RNA_find_real_ID_and_path(bmain, id, &rna_path_prefix); + owner_id = RNA_find_real_ID_and_path(id, &rna_path_prefix); break; default: BLI_assert_unreachable(); diff --git a/source/blender/makesrna/intern/rna_access_internal.h b/source/blender/makesrna/intern/rna_access_internal.h index a7dd35af670..384ff417fc9 100644 --- a/source/blender/makesrna/intern/rna_access_internal.h +++ b/source/blender/makesrna/intern/rna_access_internal.h @@ -10,6 +10,10 @@ #include "rna_internal_types.h" +#ifdef __cplusplus +extern "C" { +#endif + struct IDProperty; struct PropertyRNAOrID; @@ -26,3 +30,9 @@ void rna_property_rna_or_id_get(PropertyRNA *prop, void rna_idproperty_touch(struct IDProperty *idprop); struct IDProperty *rna_idproperty_find(PointerRNA *ptr, const char *name); + +PropertyRNA *rna_struct_find_nested(PointerRNA *ptr, StructRNA *srna); + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/makesrna/intern/rna_action.c b/source/blender/makesrna/intern/rna_action.c index a1266443631..14f4a82c62b 100644 --- a/source/blender/makesrna/intern/rna_action.c +++ b/source/blender/makesrna/intern/rna_action.c @@ -168,10 +168,16 @@ static void rna_Action_fcurve_remove(bAction *act, ReportList *reports, PointerR WM_main_add_notifier(NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); } +static void rna_Action_fcurve_clear(bAction *act) +{ + BKE_action_fcurves_clear(act); + WM_main_add_notifier(NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); +} + static TimeMarker *rna_Action_pose_markers_new(bAction *act, const char name[]) { TimeMarker *marker = MEM_callocN(sizeof(TimeMarker), "TimeMarker"); - marker->flag = 1; + marker->flag = SELECT; marker->frame = 1; BLI_strncpy_utf8(marker->name, name, sizeof(marker->name)); BLI_addtail(&act->markers, marker); @@ -690,6 +696,11 @@ static void rna_def_action_group(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Lock", "Action group is locked"); RNA_def_property_update(prop, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL); + prop = RNA_def_property(srna, "mute", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", AGRP_MUTED); + RNA_def_property_ui_text(prop, "Mute", "Action group is muted"); + RNA_def_property_update(prop, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL); + prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE); RNA_def_property_flag(prop, PROP_NO_DEG_UPDATE); RNA_def_property_boolean_sdna(prop, NULL, "flag", AGRP_EXPANDED); @@ -788,6 +799,10 @@ static void rna_def_action_fcurves(BlenderRNA *brna, PropertyRNA *cprop) parm = RNA_def_pointer(func, "fcurve", "FCurve", "", "F-Curve to remove"); RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR); RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0); + + /* Action.fcurves.clear() */ + func = RNA_def_function(srna, "clear", "rna_Action_fcurve_clear"); + RNA_def_function_ui_description(func, "Remove all F-Curves"); } static void rna_def_action_pose_markers(BlenderRNA *brna, PropertyRNA *cprop) diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c index a4094630266..f83ec0dc09b 100644 --- a/source/blender/makesrna/intern/rna_armature.c +++ b/source/blender/makesrna/intern/rna_armature.c @@ -8,6 +8,8 @@ #include "BLI_math.h" +#include "BLT_translation.h" + #include "RNA_access.h" #include "RNA_define.h" @@ -725,6 +727,7 @@ void rna_def_bone_curved_common(StructRNA *srna, bool is_posebone, bool is_editb RNA_def_property_ui_range(prop, -5.0f, 5.0f, 1, 3); RNA_def_property_float_default(prop, 1.0f); RNA_def_property_ui_text(prop, "Ease In", "Length of first Bezier Handle (for B-Bones only)"); + RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_ARMATURE); RNA_DEF_CURVEBONE_UPDATE(prop, is_posebone, is_editbone); prop = RNA_def_property(srna, "bbone_easeout", PROP_FLOAT, PROP_NONE); @@ -732,6 +735,7 @@ void rna_def_bone_curved_common(StructRNA *srna, bool is_posebone, bool is_editb RNA_def_property_ui_range(prop, -5.0f, 5.0f, 1, 3); RNA_def_property_float_default(prop, 1.0f); RNA_def_property_ui_text(prop, "Ease Out", "Length of second Bezier Handle (for B-Bones only)"); + RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_ARMATURE); RNA_DEF_CURVEBONE_UPDATE(prop, is_posebone, is_editbone); if (is_posebone == false) { diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c index 423cb084f27..789a8b381b6 100644 --- a/source/blender/makesrna/intern/rna_brush.c +++ b/source/blender/makesrna/intern/rna_brush.c @@ -14,8 +14,12 @@ #include "DNA_texture_types.h" #include "DNA_workspace_types.h" +#include "BKE_layer.h" + #include "BLI_math.h" +#include "BLT_translation.h" + #include "RNA_define.h" #include "RNA_enum_types.h" @@ -251,9 +255,14 @@ const EnumPropertyItem rna_enum_brush_curves_sculpt_tool_items[] = { {CURVES_SCULPT_TOOL_ADD, "ADD", ICON_BRUSH_CURVES_ADD, "Add Curves", ""}, {CURVES_SCULPT_TOOL_GROW_SHRINK, "GROW_SHRINK", ICON_BRUSH_CURVES_GROW_SHRINK, "Grow / Shrink Curves", ""}, {CURVES_SCULPT_TOOL_SELECTION_PAINT, "SELECTION_PAINT", ICON_BRUSH_PAINT_SELECT, "Paint Selection", ""}, + {CURVES_SCULPT_TOOL_PINCH, "PINCH", ICON_BRUSH_CURVES_PINCH, "Pinch Curves", ""}, + {CURVES_SCULPT_TOOL_SMOOTH, "SMOOTH", ICON_BRUSH_CURVES_SMOOTH, "Smooth Curves", ""}, + {CURVES_SCULPT_TOOL_PUFF, "PUFF", ICON_BRUSH_CURVES_PUFF, "Puff Curves", ""}, + {CURVES_SCULPT_TOOL_DENSITY, "DENSITY", ICON_BRUSH_CURVES_DENSITY, "Density Curves", ""}, + {CURVES_SCULPT_TOOL_SLIDE, "SLIDE", ICON_BRUSH_CURVES_SLIDE, "Slide Curves", ""}, {0, NULL, 0, NULL, NULL}, }; -/* clang-format om */ +/* clang-format on */ #ifndef RNA_RUNTIME static EnumPropertyItem rna_enum_gpencil_brush_eraser_modes_items[] = { @@ -760,11 +769,11 @@ static void rna_Brush_set_size(PointerRNA *ptr, int value) brush->size = value; } -static void rna_Brush_use_gradient_set(PointerRNA *ptr, bool value) +static void rna_Brush_use_gradient_set(PointerRNA *ptr, int value) { Brush *br = (Brush *)ptr->data; - if (value) { + if (value & BRUSH_USE_GRADIENT) { br->flag |= BRUSH_USE_GRADIENT; } else { @@ -889,6 +898,7 @@ static const EnumPropertyItem *rna_Brush_direction_itemf(bContext *C, switch (me->curves_sculpt_tool) { case CURVES_SCULPT_TOOL_GROW_SHRINK: case CURVES_SCULPT_TOOL_SELECTION_PAINT: + case CURVES_SCULPT_TOOL_PINCH: return prop_direction_items; default: return DummyRNA_DEFAULT_items; @@ -963,7 +973,7 @@ static void rna_BrushGpencilSettings_default_eraser_update(Main *bmain, static void rna_BrushGpencilSettings_use_material_pin_update(bContext *C, PointerRNA *ptr) { ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = OBACT(view_layer); + Object *ob = BKE_view_layer_active_object_get(view_layer); Brush *brush = (Brush *)ptr->owner_id; if (brush->gpencil_settings->flag & GP_BRUSH_MATERIAL_PINNED) { @@ -1318,6 +1328,7 @@ static void rna_def_gpencil_options(BlenderRNA *brna) RNA_def_property_float_sdna(prop, NULL, "draw_jitter"); RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Jitter", "Jitter factor for new strokes"); + RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_BRUSH); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL); @@ -1645,6 +1656,15 @@ static void rna_def_gpencil_options(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, NULL); + /* Factor to determine outline external perimeter thickness. */ + prop = RNA_def_property(srna, "outline_thickness_factor", PROP_FLOAT, PROP_FACTOR); + RNA_def_property_float_sdna(prop, NULL, "outline_fac"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_float_default(prop, 0.0f); + RNA_def_property_ui_text( + prop, "Thickness", "Thickness of the outline stroke relative to current brush thickness"); + RNA_def_parameter_clear_flags(prop, PROP_ANIMATABLE, 0); + /* Flags */ prop = RNA_def_property(srna, "use_pressure", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSH_USE_PRESSURE); @@ -1814,6 +1834,12 @@ static void rna_def_gpencil_options(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Trim Stroke Ends", "Trim intersecting stroke ends"); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + prop = RNA_def_property(srna, "use_settings_outline", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSH_OUTLINE_STROKE); + RNA_def_property_boolean_default(prop, false); + RNA_def_property_ui_text(prop, "Outline", "Convert stroke to perimeter"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + prop = RNA_def_property(srna, "direction", PROP_ENUM, PROP_NONE); RNA_def_property_enum_bitflag_sdna(prop, NULL, "sculpt_flag"); RNA_def_property_enum_items(prop, prop_direction_items); @@ -1877,6 +1903,15 @@ static void rna_def_gpencil_options(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_Brush_material_update"); + /* Secondary Material */ + prop = RNA_def_property(srna, "material_alt", PROP_POINTER, PROP_NONE); + RNA_def_property_struct_type(prop, "Material"); + RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_BrushGpencilSettings_material_poll"); + RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK | PROP_CONTEXT_UPDATE); + RNA_def_property_ui_text(prop, "Material", "Material used for secondary uses for this brush"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_Brush_material_update"); + prop = RNA_def_property(srna, "show_fill_boundary", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", GP_BRUSH_FILL_SHOW_HELPLINES); RNA_def_property_boolean_default(prop, true); @@ -1949,6 +1984,26 @@ static void rna_def_curves_sculpt_options(BlenderRNA *brna) StructRNA *srna; PropertyRNA *prop; + static const EnumPropertyItem density_mode_items[] = { + {BRUSH_CURVES_SCULPT_DENSITY_MODE_AUTO, + "AUTO", + ICON_AUTO, + "Auto", + "Either add or remove curves depending on the minimum distance of the curves under the " + "cursor"}, + {BRUSH_CURVES_SCULPT_DENSITY_MODE_ADD, + "ADD", + ICON_ADD, + "Add", + "Add new curves between existing curves, taking the minimum distance into account"}, + {BRUSH_CURVES_SCULPT_DENSITY_MODE_REMOVE, + "REMOVE", + ICON_REMOVE, + "Remove", + "Remove curves whose root points are too close"}, + {0, NULL, 0, NULL, NULL}, + }; + srna = RNA_def_struct(brna, "BrushCurvesSculptSettings", NULL); RNA_def_struct_sdna(srna, "BrushCurvesSculptSettings"); RNA_def_struct_ui_text(srna, "Curves Sculpt Brush Settings", ""); @@ -1997,6 +2052,22 @@ static void rna_def_curves_sculpt_options(BlenderRNA *brna) prop, "Curve Length", "Length of newly added curves when it is not interpolated from other curves"); + + prop = RNA_def_property(srna, "minimum_distance", PROP_FLOAT, PROP_DISTANCE); + RNA_def_property_range(prop, 0.0f, FLT_MAX); + RNA_def_property_ui_range(prop, 0.0, 1000.0f, 0.001, 2); + RNA_def_property_ui_text( + prop, "Minimum Distance", "Goal distance between curve roots for the Density brush"); + + prop = RNA_def_property(srna, "density_add_attempts", PROP_INT, PROP_NONE); + RNA_def_property_range(prop, 0, INT32_MAX); + RNA_def_property_ui_text( + prop, "Density Add Attempts", "How many times the Density brush tries to add a new curve"); + + prop = RNA_def_property(srna, "density_mode", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, density_mode_items); + RNA_def_property_ui_text( + prop, "Density Mode", "Determines whether the brush adds or removes curves"); } static void rna_def_brush(BlenderRNA *brna) @@ -2549,6 +2620,7 @@ static void rna_def_brush(BlenderRNA *brna) RNA_def_property_range(prop, 0.0f, 1000.0f); RNA_def_property_ui_range(prop, 0.0f, 2.0f, 0.1, 4); RNA_def_property_ui_text(prop, "Jitter", "Jitter the position of the brush while painting"); + RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_BRUSH); RNA_def_property_update(prop, 0, "rna_Brush_update"); prop = RNA_def_property(srna, "jitter_absolute", PROP_INT, PROP_PIXEL); @@ -2556,6 +2628,7 @@ static void rna_def_brush(BlenderRNA *brna) RNA_def_property_range(prop, 0, 1000000); RNA_def_property_ui_text( prop, "Jitter", "Jitter the position of the brush in pixels while painting"); + RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_BRUSH); RNA_def_property_update(prop, 0, "rna_Brush_update"); prop = RNA_def_property(srna, "spacing", PROP_INT, PROP_PERCENTAGE); diff --git a/source/blender/makesrna/intern/rna_camera.c b/source/blender/makesrna/intern/rna_camera.c index 9628c6b2d65..0807dbe61eb 100644 --- a/source/blender/makesrna/intern/rna_camera.c +++ b/source/blender/makesrna/intern/rna_camera.c @@ -10,6 +10,8 @@ #include "BLI_math.h" +#include "BLT_translation.h" + #include "RNA_access.h" #include "RNA_define.h" @@ -369,6 +371,7 @@ static void rna_def_camera_background_image(BlenderRNA *brna) RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag"); RNA_def_property_enum_items(prop, bgpic_display_depth_items); RNA_def_property_ui_text(prop, "Depth", "Display under or over everything"); + RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_CAMERA); RNA_def_property_update(prop, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, NULL); /* expose 2 flags as a enum of 3 items */ @@ -519,6 +522,12 @@ static void rna_def_camera_dof_settings_data(BlenderRNA *brna) prop, "Focus Object", "Use this object to define the depth of field focal point"); RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_dependency_update"); + prop = RNA_def_property(srna, "focus_subtarget", PROP_STRING, PROP_NONE); + RNA_def_property_string_sdna(prop, NULL, "focus_subtarget"); + RNA_def_property_ui_text( + prop, "Focus Bone", "Use this armature bone to define the depth of field focal point"); + RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_dependency_update"); + prop = RNA_def_property(srna, "focus_distance", PROP_FLOAT, PROP_DISTANCE); // RNA_def_property_pointer_sdna(prop, NULL, "focus_distance"); RNA_def_property_range(prop, 0.0f, FLT_MAX); @@ -689,14 +698,12 @@ void RNA_def_camera(BlenderRNA *brna) prop = RNA_def_property(srna, "shift_x", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "shiftx"); - RNA_def_property_range(prop, -10.0f, 10.0f); RNA_def_property_ui_range(prop, -2.0, 2.0, 1, 3); RNA_def_property_ui_text(prop, "Shift X", "Camera horizontal shift"); RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_update"); prop = RNA_def_property(srna, "shift_y", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "shifty"); - RNA_def_property_range(prop, -10.0f, 10.0f); RNA_def_property_ui_range(prop, -2.0, 2.0, 1, 3); RNA_def_property_ui_text(prop, "Shift Y", "Camera vertical shift"); RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Camera_update"); diff --git a/source/blender/makesrna/intern/rna_collection.c b/source/blender/makesrna/intern/rna_collection.c index 599d36c0af7..84ddea368e7 100644 --- a/source/blender/makesrna/intern/rna_collection.c +++ b/source/blender/makesrna/intern/rna_collection.c @@ -39,6 +39,7 @@ const EnumPropertyItem rna_enum_collection_color_items[] = { # include "DEG_depsgraph.h" # include "DEG_depsgraph_build.h" +# include "DEG_depsgraph_query.h" # include "BKE_collection.h" # include "BKE_global.h" @@ -79,26 +80,45 @@ static PointerRNA rna_Collection_objects_get(CollectionPropertyIterator *iter) return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, cob->ob); } -static void rna_Collection_objects_link(Collection *collection, - Main *bmain, - ReportList *reports, - Object *object) +static bool rna_collection_objects_edit_check(Collection *collection, + ReportList *reports, + Object *object) { + if (!DEG_is_original_id(&collection->id)) { + BKE_reportf( + reports, RPT_ERROR, "Collection '%s' is not an original ID", collection->id.name + 2); + return false; + } + if (!DEG_is_original_id(&object->id)) { + BKE_reportf(reports, RPT_ERROR, "Collection '%s' is not an original ID", object->id.name + 2); + return false; + } /* Currently this should not be allowed (might be supported in the future though...). */ if (ID_IS_OVERRIDE_LIBRARY(&collection->id)) { BKE_reportf(reports, RPT_ERROR, - "Could not link the object '%s' because the collection '%s' is overridden", + "Could not (un)link the object '%s' because the collection '%s' is overridden", object->id.name + 2, collection->id.name + 2); - return; + return false; } if (ID_IS_LINKED(&collection->id)) { BKE_reportf(reports, RPT_ERROR, - "Could not link the object '%s' because the collection '%s' is linked", + "Could not (un)link the object '%s' because the collection '%s' is linked", object->id.name + 2, collection->id.name + 2); + return false; + } + return true; +} + +static void rna_Collection_objects_link(Collection *collection, + Main *bmain, + ReportList *reports, + Object *object) +{ + if (!rna_collection_objects_edit_check(collection, reports, object)) { return; } if (!BKE_collection_object_add(bmain, collection, object)) { @@ -120,6 +140,9 @@ static void rna_Collection_objects_unlink(Collection *collection, ReportList *reports, Object *object) { + if (!rna_collection_objects_edit_check(collection, reports, object)) { + return; + } if (!BKE_collection_object_remove(bmain, collection, object, false)) { BKE_reportf(reports, RPT_ERROR, @@ -204,11 +227,47 @@ static PointerRNA rna_Collection_children_get(CollectionPropertyIterator *iter) return rna_pointer_inherit_refine(&iter->parent, &RNA_Collection, child->collection); } +static bool rna_collection_children_edit_check(Collection *collection, + ReportList *reports, + Collection *child) +{ + if (!DEG_is_original_id(&collection->id)) { + BKE_reportf( + reports, RPT_ERROR, "Collection '%s' is not an original ID", collection->id.name + 2); + return false; + } + if (!DEG_is_original_id(&child->id)) { + BKE_reportf(reports, RPT_ERROR, "Collection '%s' is not an original ID", child->id.name + 2); + return false; + } + /* Currently this should not be allowed (might be supported in the future though...). */ + if (ID_IS_OVERRIDE_LIBRARY(&collection->id)) { + BKE_reportf(reports, + RPT_ERROR, + "Could not (un)link the collection '%s' because the collection '%s' is overridden", + child->id.name + 2, + collection->id.name + 2); + return false; + } + if (ID_IS_LINKED(&collection->id)) { + BKE_reportf(reports, + RPT_ERROR, + "Could not (un)link the collection '%s' because the collection '%s' is linked", + child->id.name + 2, + collection->id.name + 2); + return false; + } + return true; +} + static void rna_Collection_children_link(Collection *collection, Main *bmain, ReportList *reports, Collection *child) { + if (!rna_collection_children_edit_check(collection, reports, child)) { + return; + } if (!BKE_collection_child_add(bmain, collection, child)) { BKE_reportf(reports, RPT_ERROR, @@ -228,6 +287,9 @@ static void rna_Collection_children_unlink(Collection *collection, ReportList *reports, Collection *child) { + if (!rna_collection_children_edit_check(collection, reports, child)) { + return; + } if (!BKE_collection_child_remove(bmain, collection, child)) { BKE_reportf(reports, RPT_ERROR, @@ -359,6 +421,14 @@ static void rna_Collection_color_tag_update(Main *UNUSED(bmain), WM_main_add_notifier(NC_SCENE | ND_LAYER_CONTENT, scene); } +static void rna_Collection_instance_offset_update(Main *UNUSED(bmain), + Scene *UNUSED(scene), + PointerRNA *ptr) +{ + Collection *collection = (Collection *)ptr->data; + DEG_id_tag_update(&collection->id, ID_RECALC_GEOMETRY); +} + #else /* collection.objects */ @@ -433,7 +503,7 @@ void RNA_def_collections(BlenderRNA *brna) RNA_def_property_ui_text( prop, "Instance Offset", "Offset from the origin to use when instancing"); RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, RNA_TRANSLATION_PREC_DEFAULT); - RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL); + RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Collection_instance_offset_update"); prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE); RNA_def_property_struct_type(prop, "Object"); @@ -549,6 +619,22 @@ void RNA_def_collections(BlenderRNA *brna) prop, "Masks", "Intersection generated by this collection will have this mask value"); RNA_def_property_update(prop, NC_SCENE, NULL); + prop = RNA_def_property(srna, "lineart_intersection_priority", PROP_INT, PROP_NONE); + RNA_def_property_range(prop, 0, 255); + RNA_def_property_ui_text(prop, + "Intersection Priority", + "The intersection line will be included into the object with the " + "higher intersection priority value"); + RNA_def_property_update(prop, NC_SCENE, NULL); + + prop = RNA_def_property(srna, "use_lineart_intersection_priority", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_default(prop, 0); + RNA_def_property_boolean_sdna( + prop, NULL, "lineart_flags", COLLECTION_LRT_USE_INTERSECTION_PRIORITY); + RNA_def_property_ui_text( + prop, "Use Intersection Priority", "Assign intersection priority value for this collection"); + RNA_def_property_update(prop, NC_SCENE, NULL); + prop = RNA_def_property(srna, "color_tag", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "color_tag"); RNA_def_property_enum_funcs( diff --git a/source/blender/makesrna/intern/rna_color.c b/source/blender/makesrna/intern/rna_color.c index 92cdcc6d781..b68d87587e7 100644 --- a/source/blender/makesrna/intern/rna_color.c +++ b/source/blender/makesrna/intern/rna_color.c @@ -23,6 +23,7 @@ #ifdef RNA_RUNTIME # include "RNA_access.h" +# include "RNA_path.h" # include "DNA_image_types.h" # include "DNA_material_types.h" @@ -681,7 +682,6 @@ static void rna_ColorManagement_update(Main *UNUSED(bmain), Scene *UNUSED(scene) } if (GS(id->name) == ID_SCE) { - DEG_id_tag_update(id, 0); WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, NULL); } } @@ -1270,7 +1270,7 @@ static void rna_def_colormanage(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Use Curves", "Use RGB curved for pre-display transformation"); RNA_def_property_update(prop, NC_WINDOW, "rna_ColorManagement_update"); - /* ** Colorspace ** */ + /* ** Color-space ** */ srna = RNA_def_struct(brna, "ColorManagedInputColorspaceSettings", NULL); RNA_def_struct_path_func(srna, "rna_ColorManagedInputColorspaceSettings_path"); RNA_def_struct_ui_text( diff --git a/source/blender/makesrna/intern/rna_constraint.c b/source/blender/makesrna/intern/rna_constraint.c index 1420ef36493..719c7441174 100644 --- a/source/blender/makesrna/intern/rna_constraint.c +++ b/source/blender/makesrna/intern/rna_constraint.c @@ -603,7 +603,7 @@ static const EnumPropertyItem *rna_Constraint_target_space_itemf(bContext *UNUSE if (BKE_constraint_targets_get(con, &targets)) { for (ct = targets.first; ct; ct = ct->next) { - if (ct->tar && ct->tar->type == OB_ARMATURE) { + if (ct->tar && ct->tar->type == OB_ARMATURE && !(ct->flag & CONSTRAINT_TAR_CUSTOM_SPACE)) { break; } } @@ -3450,6 +3450,7 @@ void RNA_def_constraint(BlenderRNA *brna) RNA_def_struct_refine_func(srna, "rna_ConstraintType_refine"); RNA_def_struct_path_func(srna, "rna_Constraint_path"); RNA_def_struct_sdna(srna, "bConstraint"); + RNA_def_struct_ui_icon(srna, ICON_CONSTRAINT); /* strings */ prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_curve.c b/source/blender/makesrna/intern/rna_curve.c index fff3f479a3f..3a90d631c63 100644 --- a/source/blender/makesrna/intern/rna_curve.c +++ b/source/blender/makesrna/intern/rna_curve.c @@ -67,7 +67,8 @@ const EnumPropertyItem rna_enum_keyframe_handle_type_items[] = { */ const EnumPropertyItem rna_enum_beztriple_interpolation_mode_items[] = { /* Interpolation. */ - RNA_ENUM_ITEM_HEADING(N_("Interpolation"), "Standard transitions between keyframes"), + RNA_ENUM_ITEM_HEADING(CTX_N_(BLT_I18NCONTEXT_ID_ACTION, "Interpolation"), + N_("Standard transitions between keyframes")), {BEZT_IPO_CONST, "CONSTANT", ICON_IPO_CONSTANT, @@ -85,9 +86,9 @@ const EnumPropertyItem rna_enum_beztriple_interpolation_mode_items[] = { "Smooth interpolation between A and B, with some control over curve shape"}, /* Easing. */ - RNA_ENUM_ITEM_HEADING(N_("Easing (by strength)"), - "Predefined inertial transitions, useful for motion graphics " - "(from least to most \"dramatic\")"), + RNA_ENUM_ITEM_HEADING(CTX_N_(BLT_I18NCONTEXT_ID_ACTION, "Easing (by strength)"), + N_("Predefined inertial transitions, useful for motion graphics " + "(from least to most \"dramatic\")")), {BEZT_IPO_SINE, "SINE", ICON_IPO_SINE, @@ -104,7 +105,8 @@ const EnumPropertyItem rna_enum_beztriple_interpolation_mode_items[] = { "Circular", "Circular easing (strongest and most dynamic)"}, - RNA_ENUM_ITEM_HEADING(N_("Dynamic Effects"), "Simple physics-inspired easing effects"), + RNA_ENUM_ITEM_HEADING(CTX_N_(BLT_I18NCONTEXT_ID_ACTION, "Dynamic Effects"), + N_("Simple physics-inspired easing effects")), {BEZT_IPO_BACK, "BACK", ICON_IPO_BACK, "Back", "Cubic easing with overshoot and settle"}, {BEZT_IPO_BOUNCE, "BOUNCE", @@ -437,7 +439,7 @@ static void rna_Curve_bevelObject_set(PointerRNA *ptr, if (ob) { /* If bevel object has got the save curve, as object, for which it's set as bevobj, - * there could be infinity loop in #DispList calculation. */ + * there could be an infinite loop in curve evaluation. */ if (ob->type == OB_CURVES_LEGACY && ob->data != cu) { cu->bevobj = ob; id_lib_extern((ID *)ob); @@ -512,7 +514,7 @@ static void rna_Curve_taperObject_set(PointerRNA *ptr, if (ob) { /* If taper object has got the save curve, as object, for which it's set as bevobj, - * there could be infinity loop in #DispList calculation. */ + * there could be an infinite loop in curve evaluation. */ if (ob->type == OB_CURVES_LEGACY && ob->data != cu) { cu->taperobj = ob; id_lib_extern((ID *)ob); diff --git a/source/blender/makesrna/intern/rna_curveprofile.c b/source/blender/makesrna/intern/rna_curveprofile.c index 8aa358e074d..d425afdd537 100644 --- a/source/blender/makesrna/intern/rna_curveprofile.c +++ b/source/blender/makesrna/intern/rna_curveprofile.c @@ -13,6 +13,8 @@ #include "RNA_define.h" #include "rna_internal.h" +#include "BLT_translation.h" + #include "WM_api.h" #include "WM_types.h" @@ -220,6 +222,7 @@ static void rna_def_curveprofile(BlenderRNA *brna) prop = RNA_def_property(srna, "preset", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "preset"); RNA_def_property_enum_items(prop, rna_enum_curveprofile_preset_items); + RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_MESH); RNA_def_property_ui_text(prop, "Preset", ""); prop = RNA_def_property(srna, "use_clip", PROP_BOOLEAN, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_curves.c b/source/blender/makesrna/intern/rna_curves.c index bc3e5203ed0..17290d1c582 100644 --- a/source/blender/makesrna/intern/rna_curves.c +++ b/source/blender/makesrna/intern/rna_curves.c @@ -64,7 +64,24 @@ static int rna_CurvePoint_index_get_const(const PointerRNA *ptr) { const Curves *curves = rna_curves(ptr); const float(*co)[3] = ptr->data; - return (int)(co - curves->geometry.position); + const float(*positions)[3] = (const float(*)[3])CustomData_get_layer_named( + &curves->geometry.point_data, CD_PROP_FLOAT3, "position"); + return (int)(co - positions); +} + +static int rna_Curves_position_data_length(PointerRNA *ptr) +{ + const Curves *curves = rna_curves(ptr); + return curves->geometry.point_num; +} + +static void rna_Curves_position_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) +{ + const Curves *curves = rna_curves(ptr); + const float(*positions)[3] = (const float(*)[3])CustomData_get_layer_named( + &curves->geometry.point_data, CD_PROP_FLOAT3, "position"); + rna_iterator_array_begin( + iter, (void *)positions, sizeof(float[3]), curves->geometry.point_num, false, NULL); } static int rna_CurvePoint_index_get(PointerRNA *ptr) @@ -85,21 +102,23 @@ static void rna_CurvePoint_location_set(PointerRNA *ptr, const float value[3]) static float rna_CurvePoint_radius_get(PointerRNA *ptr) { const Curves *curves = rna_curves(ptr); - if (curves->geometry.radius == NULL) { + const float *radii = (const float *)CustomData_get_layer_named( + &curves->geometry.point_data, CD_PROP_FLOAT, "radius"); + if (radii == NULL) { return 0.0f; } - const float(*co)[3] = ptr->data; - return curves->geometry.radius[co - curves->geometry.position]; + return radii[rna_CurvePoint_index_get_const(ptr)]; } static void rna_CurvePoint_radius_set(PointerRNA *ptr, float value) { const Curves *curves = rna_curves(ptr); - if (curves->geometry.radius == NULL) { + float *radii = (float *)CustomData_get_layer_named( + &curves->geometry.point_data, CD_PROP_FLOAT, "radius"); + if (radii == NULL) { return; } - const float(*co)[3] = ptr->data; - curves->geometry.radius[co - curves->geometry.position] = value; + radii[rna_CurvePoint_index_get_const(ptr)] = value; } static char *rna_CurvePoint_path(const PointerRNA *ptr) @@ -123,16 +142,6 @@ static char *rna_CurveSlice_path(const PointerRNA *ptr) return BLI_sprintfN("curves[%d]", rna_CurveSlice_index_get_const(ptr)); } -static void rna_CurveSlice_points_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) -{ - Curves *curves = rna_curves(ptr); - const int *offset_ptr = (int *)ptr->data; - const int offset = *offset_ptr; - const int size = *(offset_ptr + 1) - offset; - float(*co)[3] = curves->geometry.position + *offset_ptr; - rna_iterator_array_begin(iter, co, sizeof(float[3]), size, 0, NULL); -} - static int rna_CurveSlice_first_point_index_get(PointerRNA *ptr) { const int *offset_ptr = (int *)ptr->data; @@ -146,6 +155,17 @@ static int rna_CurveSlice_points_length_get(PointerRNA *ptr) return *(offset_ptr + 1) - offset; } +static void rna_CurveSlice_points_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) +{ + Curves *curves = rna_curves(ptr); + const int offset = rna_CurveSlice_first_point_index_get(ptr); + const int size = rna_CurveSlice_points_length_get(ptr); + float(*positions)[3] = (float(*)[3])CustomData_get_layer_named( + &curves->geometry.point_data, CD_PROP_FLOAT3, "position"); + float(*co)[3] = positions + offset; + rna_iterator_array_begin(iter, co, sizeof(float[3]), size, 0, NULL); +} + static void rna_Curves_update_data(struct Main *UNUSED(bmain), struct Scene *UNUSED(scene), PointerRNA *ptr) @@ -175,7 +195,7 @@ static void rna_def_curves_point(BlenderRNA *brna) PropertyRNA *prop; srna = RNA_def_struct(brna, "CurvePoint", NULL); - RNA_def_struct_ui_text(srna, "Curve Point", "Curve curve control point"); + RNA_def_struct_ui_text(srna, "Curve Point", "Curve control point"); RNA_def_struct_path_func(srna, "rna_CurvePoint_path"); prop = RNA_def_property(srna, "position", PROP_FLOAT, PROP_TRANSLATION); @@ -252,20 +272,32 @@ static void rna_def_curves(BlenderRNA *brna) RNA_def_property_struct_type(prop, "CurveSlice"); RNA_def_property_ui_text(prop, "Curves", "All curves in the data-block"); - /* TODO: better solution for (*co)[3] parsing issue. */ - - RNA_define_verify_sdna(0); prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE); - RNA_def_property_collection_sdna(prop, NULL, "geometry.position", "geometry.point_num"); RNA_def_property_struct_type(prop, "CurvePoint"); + RNA_def_property_collection_funcs(prop, + "rna_Curves_position_data_begin", + "rna_iterator_array_next", + "rna_iterator_array_end", + "rna_iterator_array_get", + "rna_Curves_position_data_length", + NULL, + NULL, + NULL); RNA_def_property_ui_text(prop, "Points", "Control points of all curves"); - RNA_define_verify_sdna(1); /* Direct access to built-in attributes. */ RNA_define_verify_sdna(0); prop = RNA_def_property(srna, "position_data", PROP_COLLECTION, PROP_NONE); - RNA_def_property_collection_sdna(prop, NULL, "geometry.position", "geometry.point_num"); + RNA_def_property_collection_funcs(prop, + "rna_Curves_position_data_begin", + "rna_iterator_array_next", + "rna_iterator_array_end", + "rna_iterator_array_get", + "rna_Curves_position_data_length", + NULL, + NULL, + NULL); RNA_def_property_struct_type(prop, "FloatVectorAttributeValue"); RNA_def_property_update(prop, 0, "rna_Curves_update_data"); RNA_define_verify_sdna(1); diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c index 9d26797aa88..44b642d0fcc 100644 --- a/source/blender/makesrna/intern/rna_define.c +++ b/source/blender/makesrna/intern/rna_define.c @@ -4421,6 +4421,16 @@ int rna_parameter_size(PropertyRNA *parm) return sizeof(void *); } +int rna_parameter_size_pad(const int size) +{ + /* Pad parameters in memory so the next parameter is properly aligned. + * This silences warnings in UBSAN. More complicated logic to pack parameters + * more tightly in memory is unlikely to improve performance, and aligning + * to the requirements for pointers is enough for all data types we use. */ + const int alignment = sizeof(void *); + return (size + alignment - 1) & ~(alignment - 1); +} + /* Dynamic Enums */ void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item) @@ -4435,7 +4445,7 @@ void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropert #endif } else if (tot >= 8 && (tot & (tot - 1)) == 0) { - /* power of two > 8 */ + /* Power of two > 8. */ *items = MEM_recallocN_id(*items, sizeof(EnumPropertyItem) * tot * 2, __func__); #ifdef DEBUG memset((*items) + tot, 0xff, sizeof(EnumPropertyItem) * tot); @@ -4467,8 +4477,8 @@ void RNA_enum_items_add_value(EnumPropertyItem **items, for (; item->identifier; item++) { if (item->value == value) { RNA_enum_item_add(items, totitem, item); - /* break on first match - does this break anything? - * (is quick hack to get object->parent_type working ok for armature/lattice) */ + /* Break on first match - does this break anything? + * (is quick hack to get `object->parent_type` working ok for armature/lattice). */ break; } } diff --git a/source/blender/makesrna/intern/rna_depsgraph.c b/source/blender/makesrna/intern/rna_depsgraph.c index 6196f8d1ca0..ff107d0b833 100644 --- a/source/blender/makesrna/intern/rna_depsgraph.c +++ b/source/blender/makesrna/intern/rna_depsgraph.c @@ -43,23 +43,41 @@ /* **************** Object Instance **************** */ +typedef struct RNA_DepsgraphIterator { + BLI_Iterator iter; +# ifdef WITH_PYTHON + /** + * Store the Python instance so the #BPy_StructRNA can be set as invalid iteration is completed. + * Otherwise accessing from Python (console auto-complete for e.g.) crashes, see: T100286. */ + void *py_instance; +# endif +} RNA_DepsgraphIterator; + +# ifdef WITH_PYTHON +void **rna_DepsgraphIterator_instance(PointerRNA *ptr) +{ + RNA_DepsgraphIterator *di = ptr->data; + return &di->py_instance; +} +# endif + static PointerRNA rna_DepsgraphObjectInstance_object_get(PointerRNA *ptr) { - BLI_Iterator *iterator = ptr->data; - return rna_pointer_inherit_refine(ptr, &RNA_Object, iterator->current); + RNA_DepsgraphIterator *di = ptr->data; + return rna_pointer_inherit_refine(ptr, &RNA_Object, di->iter.current); } -static int rna_DepsgraphObjectInstance_is_instance_get(PointerRNA *ptr) +static bool rna_DepsgraphObjectInstance_is_instance_get(PointerRNA *ptr) { - BLI_Iterator *iterator = ptr->data; - DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data; + RNA_DepsgraphIterator *di = ptr->data; + DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data; return (deg_iter->dupli_object_current != NULL); } static PointerRNA rna_DepsgraphObjectInstance_instance_object_get(PointerRNA *ptr) { - BLI_Iterator *iterator = ptr->data; - DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data; + RNA_DepsgraphIterator *di = ptr->data; + DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data; Object *instance_object = NULL; if (deg_iter->dupli_object_current != NULL) { instance_object = deg_iter->dupli_object_current->ob; @@ -69,24 +87,24 @@ static PointerRNA rna_DepsgraphObjectInstance_instance_object_get(PointerRNA *pt static bool rna_DepsgraphObjectInstance_show_self_get(PointerRNA *ptr) { - BLI_Iterator *iterator = ptr->data; - DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data; - int ob_visibility = BKE_object_visibility(iterator->current, deg_iter->eval_mode); + RNA_DepsgraphIterator *di = ptr->data; + DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data; + int ob_visibility = BKE_object_visibility(di->iter.current, deg_iter->eval_mode); return (ob_visibility & OB_VISIBLE_SELF) != 0; } static bool rna_DepsgraphObjectInstance_show_particles_get(PointerRNA *ptr) { - BLI_Iterator *iterator = ptr->data; - DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data; - int ob_visibility = BKE_object_visibility(iterator->current, deg_iter->eval_mode); + RNA_DepsgraphIterator *di = ptr->data; + DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data; + int ob_visibility = BKE_object_visibility(di->iter.current, deg_iter->eval_mode); return (ob_visibility & OB_VISIBLE_PARTICLES) != 0; } static PointerRNA rna_DepsgraphObjectInstance_parent_get(PointerRNA *ptr) { - BLI_Iterator *iterator = ptr->data; - DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data; + RNA_DepsgraphIterator *di = ptr->data; + DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data; Object *dupli_parent = NULL; if (deg_iter->dupli_object_current != NULL) { dupli_parent = deg_iter->dupli_parent; @@ -96,8 +114,8 @@ static PointerRNA rna_DepsgraphObjectInstance_parent_get(PointerRNA *ptr) static PointerRNA rna_DepsgraphObjectInstance_particle_system_get(PointerRNA *ptr) { - BLI_Iterator *iterator = ptr->data; - DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data; + RNA_DepsgraphIterator *di = ptr->data; + DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data; struct ParticleSystem *particle_system = NULL; if (deg_iter->dupli_object_current != NULL) { particle_system = deg_iter->dupli_object_current->particle_system; @@ -107,8 +125,8 @@ static PointerRNA rna_DepsgraphObjectInstance_particle_system_get(PointerRNA *pt static void rna_DepsgraphObjectInstance_persistent_id_get(PointerRNA *ptr, int *persistent_id) { - BLI_Iterator *iterator = ptr->data; - DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data; + RNA_DepsgraphIterator *di = ptr->data; + DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data; if (deg_iter->dupli_object_current != NULL) { memcpy(persistent_id, deg_iter->dupli_object_current->persistent_id, @@ -119,12 +137,12 @@ static void rna_DepsgraphObjectInstance_persistent_id_get(PointerRNA *ptr, int * } } -static unsigned int rna_DepsgraphObjectInstance_random_id_get(PointerRNA *ptr) +static int rna_DepsgraphObjectInstance_random_id_get(PointerRNA *ptr) { - BLI_Iterator *iterator = ptr->data; - DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data; + RNA_DepsgraphIterator *di = ptr->data; + DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data; if (deg_iter->dupli_object_current != NULL) { - return deg_iter->dupli_object_current->random_id; + return (int)deg_iter->dupli_object_current->random_id; } else { return 0; @@ -133,23 +151,23 @@ static unsigned int rna_DepsgraphObjectInstance_random_id_get(PointerRNA *ptr) static void rna_DepsgraphObjectInstance_matrix_world_get(PointerRNA *ptr, float *mat) { - BLI_Iterator *iterator = ptr->data; - DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data; + RNA_DepsgraphIterator *di = ptr->data; + DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data; if (deg_iter->dupli_object_current != NULL) { copy_m4_m4((float(*)[4])mat, deg_iter->dupli_object_current->mat); } else { /* We can return actual object's matrix here, no reason to return identity matrix * when this is not actually an instance... */ - Object *ob = (Object *)iterator->current; + Object *ob = (Object *)di->iter.current; copy_m4_m4((float(*)[4])mat, ob->obmat); } } static void rna_DepsgraphObjectInstance_orco_get(PointerRNA *ptr, float *orco) { - BLI_Iterator *iterator = ptr->data; - DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data; + RNA_DepsgraphIterator *di = ptr->data; + DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data; if (deg_iter->dupli_object_current != NULL) { copy_v3_v3(orco, deg_iter->dupli_object_current->orco); } @@ -160,8 +178,8 @@ static void rna_DepsgraphObjectInstance_orco_get(PointerRNA *ptr, float *orco) static void rna_DepsgraphObjectInstance_uv_get(PointerRNA *ptr, float *uv) { - BLI_Iterator *iterator = ptr->data; - DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data; + RNA_DepsgraphIterator *di = ptr->data; + DEGObjectIterData *deg_iter = (DEGObjectIterData *)di->iter.data; if (deg_iter->dupli_object_current != NULL) { copy_v2_v2(uv, deg_iter->dupli_object_current->uv); } @@ -321,7 +339,7 @@ static PointerRNA rna_Depsgraph_objects_get(CollectionPropertyIterator *iter) * so that previous one remains valid memory for python to access to. Yuck. */ typedef struct RNA_Depsgraph_Instances_Iterator { - BLI_Iterator iterators[2]; + RNA_DepsgraphIterator iterators[2]; DEGObjectIterData deg_data[2]; DupliObject dupli_object_current[2]; int counter; @@ -337,9 +355,9 @@ static void rna_Depsgraph_object_instances_begin(CollectionPropertyIterator *ite data->flag = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET | DEG_ITER_OBJECT_FLAG_VISIBLE | DEG_ITER_OBJECT_FLAG_DUPLI; - di_it->iterators[0].valid = true; - DEG_iterator_objects_begin(&di_it->iterators[0], data); - iter->valid = di_it->iterators[0].valid; + di_it->iterators[0].iter.valid = true; + DEG_iterator_objects_begin(&di_it->iterators[0].iter, data); + iter->valid = di_it->iterators[0].iter.valid; } static void rna_Depsgraph_object_instances_next(CollectionPropertyIterator *iter) @@ -348,12 +366,12 @@ static void rna_Depsgraph_object_instances_next(CollectionPropertyIterator *iter iter->internal.custom; /* We need to copy current iterator status to next one being worked on. */ - di_it->iterators[(di_it->counter + 1) % 2] = di_it->iterators[di_it->counter % 2]; + di_it->iterators[(di_it->counter + 1) % 2].iter = di_it->iterators[di_it->counter % 2].iter; di_it->deg_data[(di_it->counter + 1) % 2] = di_it->deg_data[di_it->counter % 2]; di_it->counter++; - di_it->iterators[di_it->counter % 2].data = &di_it->deg_data[di_it->counter % 2]; - DEG_iterator_objects_next(&di_it->iterators[di_it->counter % 2]); + di_it->iterators[di_it->counter % 2].iter.data = &di_it->deg_data[di_it->counter % 2]; + DEG_iterator_objects_next(&di_it->iterators[di_it->counter % 2].iter); /* Dupli_object_current is also temp memory generated during the iterations, * it may be freed when last item has been iterated, * so we have same issue as with the iterator itself: @@ -365,15 +383,24 @@ static void rna_Depsgraph_object_instances_next(CollectionPropertyIterator *iter di_it->deg_data[di_it->counter % 2].dupli_object_current = &di_it->dupli_object_current[di_it->counter % 2]; } - iter->valid = di_it->iterators[di_it->counter % 2].valid; + iter->valid = di_it->iterators[di_it->counter % 2].iter.valid; } static void rna_Depsgraph_object_instances_end(CollectionPropertyIterator *iter) { RNA_Depsgraph_Instances_Iterator *di_it = (RNA_Depsgraph_Instances_Iterator *) iter->internal.custom; - DEG_iterator_objects_end(&di_it->iterators[0]); - DEG_iterator_objects_end(&di_it->iterators[1]); + for (int i = 0; i < ARRAY_SIZE(di_it->iterators); i++) { + RNA_DepsgraphIterator *di = &di_it->iterators[i]; + DEG_iterator_objects_end(&di->iter); + +# ifdef WITH_PYTHON + if (di->py_instance) { + BPY_DECREF_RNA_INVALIDATE(di->py_instance); + } +# endif + } + MEM_freeN(di_it); } @@ -381,8 +408,8 @@ static PointerRNA rna_Depsgraph_object_instances_get(CollectionPropertyIterator { RNA_Depsgraph_Instances_Iterator *di_it = (RNA_Depsgraph_Instances_Iterator *) iter->internal.custom; - BLI_Iterator *iterator = &di_it->iterators[di_it->counter % 2]; - return rna_pointer_inherit_refine(&iter->parent, &RNA_DepsgraphObjectInstance, iterator); + RNA_DepsgraphIterator *di = &di_it->iterators[di_it->counter % 2]; + return rna_pointer_inherit_refine(&iter->parent, &RNA_DepsgraphObjectInstance, di); } /* Iteration over evaluated IDs */ @@ -498,6 +525,10 @@ static void rna_def_depsgraph_instance(BlenderRNA *brna) "Extended information about dependency graph object iterator " "(Warning: All data here is 'evaluated' one, not original .blend IDs)"); +# ifdef WITH_PYTHON + RNA_def_struct_register_funcs(srna, NULL, NULL, "rna_DepsgraphIterator_instance"); +# endif + prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE); RNA_def_property_struct_type(prop, "Object"); RNA_def_property_ui_text(prop, "Object", "Evaluated object the iterator points to"); diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c index ac8aebd2fdd..727d329781d 100644 --- a/source/blender/makesrna/intern/rna_fcurve.c +++ b/source/blender/makesrna/intern/rna_fcurve.c @@ -612,7 +612,7 @@ static void rna_tag_animation_update(Main *bmain, ID *id) static void rna_FCurve_update_data_ex(ID *id, FCurve *fcu, Main *bmain) { sort_time_fcurve(fcu); - calchandles_fcurve(fcu); + BKE_fcurve_handles_recalc(fcu); rna_tag_animation_update(bmain, id); } @@ -752,7 +752,7 @@ static void rna_FModifier_update(Main *bmain, Scene *UNUSED(scene), PointerRNA * FModifier *fcm = (FModifier *)ptr->data; if (fcm->curve && fcm->type == FMODIFIER_TYPE_CYCLES) { - calchandles_fcurve(fcm->curve); + BKE_fcurve_handles_recalc(fcm->curve); } rna_tag_animation_update(bmain, id); @@ -1021,9 +1021,20 @@ static void rna_FKeyframe_points_remove( return; } - delete_fcurve_key(fcu, index, !do_fast); + BKE_fcurve_delete_key(fcu, index); RNA_POINTER_INVALIDATE(bezt_ptr); + if (!do_fast) { + BKE_fcurve_handles_recalc(fcu); + } + + rna_tag_animation_update(bmain, id); +} + +static void rna_FKeyframe_points_clear(ID *id, FCurve *fcu, Main *bmain) +{ + BKE_fcurve_delete_keys_all(fcu); + rna_tag_animation_update(bmain, id); } @@ -2306,6 +2317,10 @@ static void rna_def_fcurve_keyframe_points(BlenderRNA *brna, PropertyRNA *cprop) /* optional */ RNA_def_boolean( func, "fast", 0, "Fast", "Fast keyframe removal to avoid recalculating the curve each time"); + + func = RNA_def_function(srna, "clear", "rna_FKeyframe_points_clear"); + RNA_def_function_ui_description(func, "Remove all keyframes from an F-Curve"); + RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN); } static void rna_def_fcurve(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_fluid.c b/source/blender/makesrna/intern/rna_fluid.c index 3b22ae9d40f..384ce8f04fb 100644 --- a/source/blender/makesrna/intern/rna_fluid.c +++ b/source/blender/makesrna/intern/rna_fluid.c @@ -218,16 +218,22 @@ static void rna_Fluid_parts_create(Main *bmain, # else Object *ob = (Object *)ptr->owner_id; BKE_fluid_particle_system_create(bmain, ob, pset_name, parts_name, psys_name, psys_type); + + DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); + DEG_relations_tag_update(bmain); # endif } -static void rna_Fluid_parts_delete(PointerRNA *ptr, int ptype) +static void rna_Fluid_parts_delete(Main *bmain, PointerRNA *ptr, int ptype) { # ifndef WITH_FLUID - UNUSED_VARS(ptr, ptype); + UNUSED_VARS(bmain, ptr, ptype); # else Object *ob = (Object *)ptr->owner_id; BKE_fluid_particle_system_destroy(ob, ptype); + + DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); + DEG_relations_tag_update(bmain); # endif } @@ -254,7 +260,7 @@ static void rna_Fluid_flip_parts_update(Main *bmain, Scene *scene, PointerRNA *p /* Only create a particle system in liquid domain mode. * Remove any remaining data from a liquid sim when switching to gas. */ if (fmd->domain->type != FLUID_DOMAIN_TYPE_LIQUID) { - rna_Fluid_parts_delete(ptr, PART_FLUID_FLIP); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_FLIP); fmd->domain->particle_type &= ~FLUID_DOMAIN_PARTICLE_FLIP; rna_Fluid_domain_data_reset(bmain, scene, ptr); return; @@ -266,7 +272,7 @@ static void rna_Fluid_flip_parts_update(Main *bmain, Scene *scene, PointerRNA *p fmd->domain->particle_type |= FLUID_DOMAIN_PARTICLE_FLIP; } else { - rna_Fluid_parts_delete(ptr, PART_FLUID_FLIP); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_FLIP); fmd->domain->particle_type &= ~FLUID_DOMAIN_PARTICLE_FLIP; } rna_Fluid_update(bmain, scene, ptr); @@ -285,7 +291,7 @@ static void rna_Fluid_spray_parts_update(Main *bmain, Scene *UNUSED(scene), Poin fmd->domain->particle_type |= FLUID_DOMAIN_PARTICLE_SPRAY; } else { - rna_Fluid_parts_delete(ptr, PART_FLUID_SPRAY); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_SPRAY); fmd->domain->particle_type &= ~FLUID_DOMAIN_PARTICLE_SPRAY; } } @@ -307,7 +313,7 @@ static void rna_Fluid_bubble_parts_update(Main *bmain, Scene *UNUSED(scene), Poi fmd->domain->particle_type |= FLUID_DOMAIN_PARTICLE_BUBBLE; } else { - rna_Fluid_parts_delete(ptr, PART_FLUID_BUBBLE); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_BUBBLE); fmd->domain->particle_type &= ~FLUID_DOMAIN_PARTICLE_BUBBLE; } } @@ -325,7 +331,7 @@ static void rna_Fluid_foam_parts_update(Main *bmain, Scene *UNUSED(scene), Point fmd->domain->particle_type |= FLUID_DOMAIN_PARTICLE_FOAM; } else { - rna_Fluid_parts_delete(ptr, PART_FLUID_FOAM); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_FOAM); fmd->domain->particle_type &= ~FLUID_DOMAIN_PARTICLE_FOAM; } } @@ -347,7 +353,7 @@ static void rna_Fluid_tracer_parts_update(Main *bmain, Scene *UNUSED(scene), Poi fmd->domain->particle_type |= FLUID_DOMAIN_PARTICLE_TRACER; } else { - rna_Fluid_parts_delete(ptr, PART_FLUID_TRACER); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_TRACER); fmd->domain->particle_type &= ~FLUID_DOMAIN_PARTICLE_TRACER; } } @@ -359,10 +365,10 @@ static void rna_Fluid_combined_export_update(Main *bmain, Scene *scene, PointerR fmd = (FluidModifierData *)BKE_modifiers_findby_type(ob, eModifierType_Fluid); if (fmd->domain->sndparticle_combined_export == SNDPARTICLE_COMBINED_EXPORT_OFF) { - rna_Fluid_parts_delete(ptr, PART_FLUID_SPRAYFOAM); - rna_Fluid_parts_delete(ptr, PART_FLUID_SPRAYBUBBLE); - rna_Fluid_parts_delete(ptr, PART_FLUID_FOAMBUBBLE); - rna_Fluid_parts_delete(ptr, PART_FLUID_SPRAYFOAMBUBBLE); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_SPRAYFOAM); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_SPRAYBUBBLE); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_FOAMBUBBLE); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_SPRAYFOAMBUBBLE); bool exists_spray = rna_Fluid_parts_exists(ptr, PART_FLUID_SPRAY); bool exists_foam = rna_Fluid_parts_exists(ptr, PART_FLUID_FOAM); @@ -392,11 +398,11 @@ static void rna_Fluid_combined_export_update(Main *bmain, Scene *scene, PointerR fmd->domain->particle_type |= FLUID_DOMAIN_PARTICLE_SPRAY; fmd->domain->particle_type |= FLUID_DOMAIN_PARTICLE_FOAM; - rna_Fluid_parts_delete(ptr, PART_FLUID_SPRAY); - rna_Fluid_parts_delete(ptr, PART_FLUID_FOAM); - rna_Fluid_parts_delete(ptr, PART_FLUID_SPRAYBUBBLE); - rna_Fluid_parts_delete(ptr, PART_FLUID_FOAMBUBBLE); - rna_Fluid_parts_delete(ptr, PART_FLUID_SPRAYFOAMBUBBLE); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_SPRAY); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_FOAM); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_SPRAYBUBBLE); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_FOAMBUBBLE); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_SPRAYFOAMBUBBLE); /* Re-add spray if enabled and no particle system exists for it anymore. */ bool exists_bubble = rna_Fluid_parts_exists(ptr, PART_FLUID_BUBBLE); @@ -418,11 +424,11 @@ static void rna_Fluid_combined_export_update(Main *bmain, Scene *scene, PointerR fmd->domain->particle_type |= FLUID_DOMAIN_PARTICLE_SPRAY; fmd->domain->particle_type |= FLUID_DOMAIN_PARTICLE_BUBBLE; - rna_Fluid_parts_delete(ptr, PART_FLUID_SPRAY); - rna_Fluid_parts_delete(ptr, PART_FLUID_BUBBLE); - rna_Fluid_parts_delete(ptr, PART_FLUID_SPRAYFOAM); - rna_Fluid_parts_delete(ptr, PART_FLUID_FOAMBUBBLE); - rna_Fluid_parts_delete(ptr, PART_FLUID_SPRAYFOAMBUBBLE); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_SPRAY); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_BUBBLE); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_SPRAYFOAM); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_FOAMBUBBLE); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_SPRAYFOAMBUBBLE); /* Re-add foam if enabled and no particle system exists for it anymore. */ bool exists_foam = rna_Fluid_parts_exists(ptr, PART_FLUID_FOAM); @@ -444,11 +450,11 @@ static void rna_Fluid_combined_export_update(Main *bmain, Scene *scene, PointerR fmd->domain->particle_type |= FLUID_DOMAIN_PARTICLE_FOAM; fmd->domain->particle_type |= FLUID_DOMAIN_PARTICLE_BUBBLE; - rna_Fluid_parts_delete(ptr, PART_FLUID_FOAM); - rna_Fluid_parts_delete(ptr, PART_FLUID_BUBBLE); - rna_Fluid_parts_delete(ptr, PART_FLUID_SPRAYFOAM); - rna_Fluid_parts_delete(ptr, PART_FLUID_SPRAYBUBBLE); - rna_Fluid_parts_delete(ptr, PART_FLUID_SPRAYFOAMBUBBLE); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_FOAM); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_BUBBLE); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_SPRAYFOAM); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_SPRAYBUBBLE); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_SPRAYFOAMBUBBLE); /* Re-add foam if enabled and no particle system exists for it anymore. */ bool exists_spray = rna_Fluid_parts_exists(ptr, PART_FLUID_SPRAY); @@ -472,12 +478,12 @@ static void rna_Fluid_combined_export_update(Main *bmain, Scene *scene, PointerR fmd->domain->particle_type |= FLUID_DOMAIN_PARTICLE_FOAM; fmd->domain->particle_type |= FLUID_DOMAIN_PARTICLE_BUBBLE; - rna_Fluid_parts_delete(ptr, PART_FLUID_SPRAY); - rna_Fluid_parts_delete(ptr, PART_FLUID_FOAM); - rna_Fluid_parts_delete(ptr, PART_FLUID_BUBBLE); - rna_Fluid_parts_delete(ptr, PART_FLUID_SPRAYFOAM); - rna_Fluid_parts_delete(ptr, PART_FLUID_SPRAYBUBBLE); - rna_Fluid_parts_delete(ptr, PART_FLUID_FOAMBUBBLE); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_SPRAY); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_FOAM); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_BUBBLE); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_SPRAYFOAM); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_SPRAYBUBBLE); + rna_Fluid_parts_delete(bmain, ptr, PART_FLUID_FOAMBUBBLE); } } else { diff --git a/source/blender/makesrna/intern/rna_gpencil.c b/source/blender/makesrna/intern/rna_gpencil.c index 6854ce37c94..cf0ff546d41 100644 --- a/source/blender/makesrna/intern/rna_gpencil.c +++ b/source/blender/makesrna/intern/rna_gpencil.c @@ -1807,6 +1807,7 @@ static void rna_def_gpencil_frame(BlenderRNA *brna) /* XXX NOTE: this cannot occur on the same frame as another sketch. */ RNA_def_property_range(prop, -MAXFRAME, MAXFRAME); RNA_def_property_ui_text(prop, "Frame Number", "The frame on which this sketch appears"); + RNA_def_property_update(prop, NC_GPENCIL | ND_DATA, "rna_GPencil_update"); prop = RNA_def_property(srna, "keyframe_type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "key_type"); diff --git a/source/blender/makesrna/intern/rna_gpencil_modifier.c b/source/blender/makesrna/intern/rna_gpencil_modifier.c index 47bed955b54..2dfd9d46665 100644 --- a/source/blender/makesrna/intern/rna_gpencil_modifier.c +++ b/source/blender/makesrna/intern/rna_gpencil_modifier.c @@ -774,7 +774,7 @@ static bool dash_segment_name_exists_fn(void *arg, const char *name) { const DashGpencilModifierData *dmd = (const DashGpencilModifierData *)arg; for (int i = 0; i < dmd->segments_len; i++) { - if (STREQ(dmd->segments[i].name, name)) { + if (STREQ(dmd->segments[i].name, name) && dmd->segments[i].name != name) { return true; } } @@ -3196,6 +3196,38 @@ static void rna_def_modifier_gpencillineart(BlenderRNA *brna) {0, NULL, 0, NULL, NULL}, }; + static const EnumPropertyItem modifier_lineart_shadow_region_filtering[] = { + {LRT_SHADOW_FILTER_NONE, + "NONE", + 0, + "None", + "Not filtering any lines based on illumination region"}, + {LRT_SHADOW_FILTER_ILLUMINATED, + "ILLUMINATED", + 0, + "Illuminated", + "Only selecting lines from illuminated regions"}, + {LRT_SHADOW_FILTER_SHADED, + "SHADED", + 0, + "Shaded", + "Only selecting lines from shaded regions"}, + {LRT_SHADOW_FILTER_ILLUMINATED_ENCLOSED_SHAPES, + "ILLUMINATED_ENCLOSED", + 0, + "Illuminated (Enclosed Shapes)", + "Selecting lines from lit regions, and make the combination of contour, light contour and " + "shadow lines into enclosed shapes"}, + {0, NULL, 0, NULL, NULL}, + }; + + static const EnumPropertyItem modifier_lineart_silhouette_filtering[] = { + {LRT_SILHOUETTE_FILTER_NONE, "NONE", 0, "Contour", ""}, + {LRT_SILHOUETTE_FILTER_GROUP, "GROUP", 0, "Silhouette", ""}, + {LRT_SILHOUETTE_FILTER_INDIVIDUAL, "INDIVIDUAL", 0, "Individual Silhouette", ""}, + {0, NULL, 0, NULL, NULL}, + }; + srna = RNA_def_struct(brna, "LineartGpencilModifier", "GpencilModifier"); RNA_def_struct_ui_text( srna, "Line Art Modifier", "Generate line art strokes from selected source"); @@ -3208,7 +3240,7 @@ static void rna_def_modifier_gpencillineart(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "calculation_flags", LRT_USE_CUSTOM_CAMERA); RNA_def_property_ui_text( prop, "Use Custom Camera", "Use custom camera instead of the active camera"); - RNA_def_property_update(prop, NC_SCENE, "rna_GpencilModifier_update"); + RNA_def_property_update(prop, 0, "rna_GpencilModifier_dependency_update"); prop = RNA_def_property(srna, "use_fuzzy_intersections", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "calculation_flags", LRT_INTERSECTION_AS_CONTOUR); @@ -3250,8 +3282,11 @@ static void rna_def_modifier_gpencillineart(BlenderRNA *brna) prop = RNA_def_property(srna, "crease_threshold", PROP_FLOAT, PROP_ANGLE); RNA_def_property_range(prop, 0, DEG2RAD(180.0f)); RNA_def_property_ui_range(prop, 0.0f, DEG2RAD(180.0f), 0.01f, 1); - RNA_def_property_ui_text( - prop, "Crease Threshold", "Angles smaller than this will be treated as creases"); + RNA_def_property_ui_text(prop, + "Crease Threshold", + "Angles smaller than this will be treated as creases. Crease angle " + "priority: object line art crease override > mesh auto smooth angle > " + "line art default crease"); RNA_def_property_update(prop, NC_SCENE, "rna_GpencilModifier_update"); prop = RNA_def_property(srna, "split_angle", PROP_FLOAT, PROP_ANGLE); @@ -3367,6 +3402,14 @@ static void rna_def_modifier_gpencillineart(BlenderRNA *brna) prop, "Camera Object", "Use specified camera object for generating line art"); RNA_def_property_update(prop, 0, "rna_GpencilModifier_dependency_update"); + prop = RNA_def_property(srna, "light_contour_object", PROP_POINTER, PROP_NONE); + RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK); + RNA_def_property_struct_type(prop, "Object"); + RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY); + RNA_def_property_ui_text( + prop, "Light Object", "Use this light object to generate light contour"); + RNA_def_property_update(prop, 0, "rna_GpencilModifier_dependency_update"); + prop = RNA_def_property(srna, "source_type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_items(prop, modifier_lineart_source_type); RNA_def_property_ui_text(prop, "Source Type", "Line art stroke source type"); @@ -3417,6 +3460,34 @@ static void rna_def_modifier_gpencillineart(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Use Intersection", "Generate strokes from intersections"); RNA_def_property_update(prop, 0, "rna_GpencilModifier_update"); + prop = RNA_def_property(srna, "use_light_contour", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "edge_types", LRT_EDGE_FLAG_LIGHT_CONTOUR); + RNA_def_property_ui_text(prop, + "Use Light Contour", + "Generate light/shadow separation lines from a reference light object"); + RNA_def_property_update(prop, 0, "rna_GpencilModifier_update"); + + prop = RNA_def_property(srna, "use_shadow", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "edge_types", LRT_EDGE_FLAG_PROJECTED_SHADOW); + RNA_def_property_ui_text( + prop, "Use Shadow", "Project contour lines using a light source object"); + RNA_def_property_update(prop, 0, "rna_GpencilModifier_update"); + + prop = RNA_def_property(srna, "shadow_region_filtering", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "shadow_selection"); + RNA_def_property_enum_items(prop, modifier_lineart_shadow_region_filtering); + RNA_def_property_ui_text(prop, + "Shadow Region Filtering", + "Select feature lines that comes from lit or shaded regions. Will not " + "affect cast shadow and light contour since they are at the border"); + RNA_def_property_update(prop, 0, "rna_GpencilModifier_dependency_update"); + + prop = RNA_def_property(srna, "silhouette_filtering", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "silhouette_selection"); + RNA_def_property_enum_items(prop, modifier_lineart_silhouette_filtering); + RNA_def_property_ui_text(prop, "Silhouette Filtering", "Select contour or silhouette"); + RNA_def_property_update(prop, 0, "rna_GpencilModifier_dependency_update"); + prop = RNA_def_property(srna, "use_multiple_levels", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "use_multiple_levels", 0); RNA_def_property_ui_text( @@ -3558,6 +3629,27 @@ static void rna_def_modifier_gpencillineart(BlenderRNA *brna) "different occlusion levels than when disabled"); RNA_def_property_update(prop, 0, "rna_GpencilModifier_update"); + prop = RNA_def_property(srna, "shadow_camera_near", PROP_FLOAT, PROP_NONE); + RNA_def_property_ui_text(prop, "Shadow Camera Near", "Near clipping distance of shadow camera"); + RNA_def_property_ui_range(prop, 0.0f, 500.0f, 0.1f, 2); + RNA_def_property_range(prop, 0.0f, 10000.0f); + RNA_def_property_update(prop, 0, "rna_GpencilModifier_update"); + + prop = RNA_def_property(srna, "shadow_camera_far", PROP_FLOAT, PROP_NONE); + RNA_def_property_ui_text(prop, "Shadow Camera Far", "Far clipping distance of shadow camera"); + RNA_def_property_ui_range(prop, 0.0f, 500.0f, 0.1f, 2); + RNA_def_property_range(prop, 0.0f, 10000.0f); + RNA_def_property_update(prop, 0, "rna_GpencilModifier_update"); + + prop = RNA_def_property(srna, "shadow_camera_size", PROP_FLOAT, PROP_NONE); + RNA_def_property_ui_text(prop, + "Shadow Camera Size", + "This value represent the \"Orthographic Scale\" of an ortho camera." + "If the camera is put at the lamps position with this scale, it will " + "represent the coverage of the shadow \"camera\" "); + RNA_def_property_ui_range(prop, 0.0f, 500.0f, 0.1f, 2); + RNA_def_property_range(prop, 0.0f, 10000.0f); + prop = RNA_def_property(srna, "use_invert_collection", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flags", LRT_GPENCIL_INVERT_COLLECTION); RNA_def_property_ui_text(prop, @@ -3565,6 +3657,11 @@ static void rna_def_modifier_gpencillineart(BlenderRNA *brna) "Select everything except lines from specified collection"); RNA_def_property_update(prop, 0, "rna_GpencilModifier_update"); + prop = RNA_def_property(srna, "use_invert_silhouette", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flags", LRT_GPENCIL_INVERT_SILHOUETTE_FILTER); + RNA_def_property_ui_text(prop, "Invert Silhouette Filtering", "Select anti-silhouette lines"); + RNA_def_property_update(prop, 0, "rna_GpencilModifier_update"); + RNA_define_lib_overridable(false); } diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c index 39f5b6e0e9f..b7ab7689dd7 100644 --- a/source/blender/makesrna/intern/rna_image.c +++ b/source/blender/makesrna/intern/rna_image.c @@ -52,6 +52,7 @@ static const EnumPropertyItem image_source_items[] = { #ifdef RNA_RUNTIME # include "BLI_math_base.h" +# include "BLI_math_vector.h" # include "BKE_global.h" @@ -85,6 +86,10 @@ static void rna_Image_source_set(PointerRNA *ptr, int value) ima->source = value; BLI_assert(BKE_id_is_in_global_main(&ima->id)); BKE_image_signal(G_MAIN, ima, NULL, IMA_SIGNAL_SRC_CHANGE); + if (ima->source == IMA_SRC_TILED) { + BKE_image_signal(G_MAIN, ima, NULL, IMA_SIGNAL_RELOAD); + } + DEG_id_tag_update(&ima->id, 0); DEG_id_tag_update(&ima->id, ID_RECALC_EDITORS); DEG_relations_tag_update(G_MAIN); @@ -100,6 +105,83 @@ static void rna_Image_reload_update(Main *bmain, Scene *UNUSED(scene), PointerRN DEG_id_tag_update(&ima->id, ID_RECALC_EDITORS); } +static int rna_Image_generated_type_get(PointerRNA *ptr) +{ + Image *ima = (Image *)ptr->data; + ImageTile *base_tile = BKE_image_get_tile(ima, 0); + return base_tile->gen_type; +} + +static void rna_Image_generated_type_set(PointerRNA *ptr, int value) +{ + Image *ima = (Image *)ptr->data; + ImageTile *base_tile = BKE_image_get_tile(ima, 0); + base_tile->gen_type = value; +} + +static int rna_Image_generated_width_get(PointerRNA *ptr) +{ + Image *ima = (Image *)ptr->data; + ImageTile *base_tile = BKE_image_get_tile(ima, 0); + return base_tile->gen_x; +} + +static void rna_Image_generated_width_set(PointerRNA *ptr, int value) +{ + Image *ima = (Image *)ptr->data; + ImageTile *base_tile = BKE_image_get_tile(ima, 0); + base_tile->gen_x = CLAMPIS(value, 1, 65536); +} + +static int rna_Image_generated_height_get(PointerRNA *ptr) +{ + Image *ima = (Image *)ptr->data; + ImageTile *base_tile = BKE_image_get_tile(ima, 0); + return base_tile->gen_y; +} + +static void rna_Image_generated_height_set(PointerRNA *ptr, int value) +{ + Image *ima = (Image *)ptr->data; + ImageTile *base_tile = BKE_image_get_tile(ima, 0); + base_tile->gen_y = CLAMPIS(value, 1, 65536); +} + +static bool rna_Image_generated_float_get(PointerRNA *ptr) +{ + Image *ima = (Image *)ptr->data; + ImageTile *base_tile = BKE_image_get_tile(ima, 0); + return (base_tile->gen_flag & IMA_GEN_FLOAT) != 0; +} + +static void rna_Image_generated_float_set(PointerRNA *ptr, bool value) +{ + Image *ima = (Image *)ptr->data; + ImageTile *base_tile = BKE_image_get_tile(ima, 0); + if (value) { + base_tile->gen_flag |= IMA_GEN_FLOAT; + } + else { + base_tile->gen_flag &= ~IMA_GEN_FLOAT; + } +} + +void rna_Image_generated_color_get(PointerRNA *ptr, float values[4]) +{ + Image *ima = (Image *)(ptr->data); + ImageTile *base_tile = BKE_image_get_tile(ima, 0); + copy_v4_v4(values, base_tile->gen_color); +} + +void rna_Image_generated_color_set(PointerRNA *ptr, const float values[4]) +{ + Image *ima = (Image *)(ptr->data); + ImageTile *base_tile = BKE_image_get_tile(ima, 0); + for (unsigned int i = 0; i < 4; i++) { + base_tile->gen_color[i] = CLAMPIS(values[i], 0.0f, FLT_MAX); + } +} + static void rna_Image_generated_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr) { Image *ima = (Image *)ptr->owner_id; @@ -335,6 +417,20 @@ static void rna_UDIMTile_tile_number_set(PointerRNA *ptr, int value) } } +static void rna_UDIMTile_generated_update(Main *UNUSED(bmain), + Scene *UNUSED(scene), + PointerRNA *ptr) +{ + Image *ima = (Image *)ptr->owner_id; + ImageTile *tile = (ImageTile *)ptr->data; + + /* If the tile is still marked as generated, then update the tile as requested. */ + if ((tile->gen_flag & IMA_GEN_TILE) != 0) { + BKE_image_fill_tile(ima, tile); + BKE_image_partial_update_mark_full_update(ima); + } +} + static int rna_Image_active_tile_index_get(PointerRNA *ptr) { Image *image = (Image *)ptr->data; @@ -475,18 +571,19 @@ static int rna_Image_frame_duration_get(PointerRNA *ptr) Image *ima = (Image *)ptr->owner_id; int duration = 1; + if (!BKE_image_has_anim(ima)) { + /* Ensure image has been loaded into memory and frame duration is known. */ + void *lock; + ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); + BKE_image_release_ibuf(ima, ibuf, lock); + } + if (BKE_image_has_anim(ima)) { struct anim *anim = ((ImageAnim *)ima->anims.first)->anim; if (anim) { duration = IMB_anim_get_duration(anim, IMB_TC_RECORD_RUN); } } - else { - /* acquire ensures ima->anim is set, if possible! */ - void *lock; - ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock); - BKE_image_release_ibuf(ima, ibuf, lock); - } return duration; } @@ -895,6 +992,43 @@ static void rna_def_udim_tile(BlenderRNA *brna) RNA_def_property_int_funcs(prop, "rna_UDIMTile_channels_get", NULL, NULL); RNA_def_property_ui_text(prop, "Channels", "Number of channels in the tile pixels buffer"); RNA_def_property_clear_flag(prop, PROP_EDITABLE); + + /* Generated tile information. */ + prop = RNA_def_property(srna, "generated_type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "gen_type"); + RNA_def_property_enum_items(prop, rna_enum_image_generated_type_items); + RNA_def_property_ui_text(prop, "Generated Type", "Generated image type"); + RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_UDIMTile_generated_update"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + + prop = RNA_def_property(srna, "generated_width", PROP_INT, PROP_PIXEL); + RNA_def_property_int_sdna(prop, NULL, "gen_x"); + RNA_def_property_flag(prop, PROP_PROPORTIONAL); + RNA_def_property_range(prop, 1, 65536); + RNA_def_property_ui_text(prop, "Generated Width", "Generated image width"); + RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_UDIMTile_generated_update"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + + prop = RNA_def_property(srna, "generated_height", PROP_INT, PROP_PIXEL); + RNA_def_property_int_sdna(prop, NULL, "gen_y"); + RNA_def_property_flag(prop, PROP_PROPORTIONAL); + RNA_def_property_range(prop, 1, 65536); + RNA_def_property_ui_text(prop, "Generated Height", "Generated image height"); + RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_UDIMTile_generated_update"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + + prop = RNA_def_property(srna, "use_generated_float", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "gen_flag", IMA_GEN_FLOAT); + RNA_def_property_ui_text(prop, "Float Buffer", "Generate floating-point buffer"); + RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_UDIMTile_generated_update"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + + prop = RNA_def_property(srna, "generated_color", PROP_FLOAT, PROP_COLOR_GAMMA); + RNA_def_property_float_sdna(prop, NULL, "gen_color"); + RNA_def_property_array(prop, 4); + RNA_def_property_ui_text(prop, "Color", "Fill color for the generated image"); + RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_UDIMTile_generated_update"); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); } static void rna_def_udim_tiles(BlenderRNA *brna, PropertyRNA *cprop) @@ -1078,6 +1212,8 @@ static void rna_def_image(BlenderRNA *brna) RNA_def_property_enum_sdna(prop, NULL, "gen_type"); RNA_def_property_enum_items(prop, rna_enum_image_generated_type_items); RNA_def_property_ui_text(prop, "Generated Type", "Generated image type"); + RNA_def_property_enum_funcs( + prop, "rna_Image_generated_type_get", "rna_Image_generated_type_set", NULL); RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_generated_update"); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); @@ -1086,6 +1222,8 @@ static void rna_def_image(BlenderRNA *brna) RNA_def_property_flag(prop, PROP_PROPORTIONAL); RNA_def_property_range(prop, 1, 65536); RNA_def_property_ui_text(prop, "Generated Width", "Generated image width"); + RNA_def_property_int_funcs( + prop, "rna_Image_generated_width_get", "rna_Image_generated_width_set", NULL); RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_generated_update"); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); @@ -1094,12 +1232,16 @@ static void rna_def_image(BlenderRNA *brna) RNA_def_property_flag(prop, PROP_PROPORTIONAL); RNA_def_property_range(prop, 1, 65536); RNA_def_property_ui_text(prop, "Generated Height", "Generated image height"); + RNA_def_property_int_funcs( + prop, "rna_Image_generated_height_get", "rna_Image_generated_height_set", NULL); RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_generated_update"); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); prop = RNA_def_property(srna, "use_generated_float", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "gen_flag", IMA_GEN_FLOAT); RNA_def_property_ui_text(prop, "Float Buffer", "Generate floating-point buffer"); + RNA_def_property_boolean_funcs( + prop, "rna_Image_generated_float_get", "rna_Image_generated_float_set"); RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_generated_update"); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); @@ -1107,6 +1249,8 @@ static void rna_def_image(BlenderRNA *brna) RNA_def_property_float_sdna(prop, NULL, "gen_color"); RNA_def_property_array(prop, 4); RNA_def_property_ui_text(prop, "Color", "Fill color for the generated image"); + RNA_def_property_float_funcs( + prop, "rna_Image_generated_color_get", "rna_Image_generated_color_set", NULL); RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_generated_update"); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h index 9e743a4f205..3d5c1810558 100644 --- a/source/blender/makesrna/intern/rna_internal.h +++ b/source/blender/makesrna/intern/rna_internal.h @@ -14,6 +14,10 @@ #include "UI_resources.h" +#ifdef __cplusplus +extern "C" { +#endif + #define RNA_MAGIC ((int)~0) struct AssetLibraryReference; @@ -351,7 +355,7 @@ void rna_FreestyleSettings_module_remove(struct ID *id, void rna_Scene_use_view_map_cache_update(struct Main *bmain, struct Scene *scene, struct PointerRNA *ptr); -void rna_Scene_glsl_update(struct Main *bmain, struct Scene *scene, struct PointerRNA *ptr); +void rna_Scene_render_update(struct Main *bmain, struct Scene *scene, struct PointerRNA *ptr); void rna_Scene_freestyle_update(struct Main *bmain, struct Scene *scene, struct PointerRNA *ptr); void rna_ViewLayer_name_set(struct PointerRNA *ptr, const char *value); void rna_ViewLayer_material_override_update(struct Main *bmain, @@ -504,9 +508,7 @@ void RNA_def_main_cachefiles(BlenderRNA *brna, PropertyRNA *cprop); void RNA_def_main_paintcurves(BlenderRNA *brna, PropertyRNA *cprop); void RNA_def_main_workspaces(BlenderRNA *brna, PropertyRNA *cprop); void RNA_def_main_lightprobes(BlenderRNA *brna, PropertyRNA *cprop); -#ifdef WITH_NEW_CURVES_TYPE void RNA_def_main_hair_curves(BlenderRNA *brna, PropertyRNA *cprop); -#endif void RNA_def_main_pointclouds(BlenderRNA *brna, PropertyRNA *cprop); void RNA_def_main_volumes(BlenderRNA *brna, PropertyRNA *cprop); #ifdef WITH_SIMULATION_DATABLOCK @@ -635,6 +637,7 @@ PointerRNA rna_pointer_inherit_refine(struct PointerRNA *ptr, struct StructRNA * /* Functions */ int rna_parameter_size(struct PropertyRNA *parm); +int rna_parameter_size_pad(const int size); /* XXX, these should not need to be defined here~! */ struct MTex *rna_mtex_texture_slots_add(struct ID *self, @@ -692,3 +695,7 @@ void rna_RenderPass_rect_set(PointerRNA *ptr, const float *values); : -FLT_MAX, double \ : -DBL_MAX) #endif + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/makesrna/intern/rna_light.c b/source/blender/makesrna/intern/rna_light.c index a9e33b8cea6..9cc4b52e637 100644 --- a/source/blender/makesrna/intern/rna_light.c +++ b/source/blender/makesrna/intern/rna_light.c @@ -212,6 +212,7 @@ static void rna_def_light_energy(StructRNA *srna, const short light_type) "Power", "The energy this light would emit over its entire area " "if it wasn't limited by the spot angle"); + RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_LIGHT); RNA_def_property_update(prop, 0, "rna_Light_draw_update"); break; } @@ -224,6 +225,7 @@ static void rna_def_light_energy(StructRNA *srna, const short light_type) prop, "Power", "Light energy emitted over the entire area of the light in all directions"); + RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_LIGHT); RNA_def_property_update(prop, 0, "rna_Light_draw_update"); break; } diff --git a/source/blender/makesrna/intern/rna_main.c b/source/blender/makesrna/intern/rna_main.c index 7200bcaa2a6..e0128595b7f 100644 --- a/source/blender/makesrna/intern/rna_main.c +++ b/source/blender/makesrna/intern/rna_main.c @@ -96,9 +96,7 @@ RNA_MAIN_LISTBASE_FUNCS_DEF(collections) RNA_MAIN_LISTBASE_FUNCS_DEF(curves) RNA_MAIN_LISTBASE_FUNCS_DEF(fonts) RNA_MAIN_LISTBASE_FUNCS_DEF(gpencils) -# ifdef WITH_NEW_CURVES_TYPE RNA_MAIN_LISTBASE_FUNCS_DEF(hair_curves) -# endif RNA_MAIN_LISTBASE_FUNCS_DEF(images) RNA_MAIN_LISTBASE_FUNCS_DEF(lattices) RNA_MAIN_LISTBASE_FUNCS_DEF(libraries) @@ -171,7 +169,6 @@ void RNA_def_main(BlenderRNA *brna) { StructRNA *srna; PropertyRNA *prop; - CollectionDefFunc *func; /* plural must match idtypes in readblenentry.c */ MainCollectionDef lists[] = { @@ -375,7 +372,6 @@ void RNA_def_main(BlenderRNA *brna) "Light Probes", "Light Probe data-blocks", RNA_def_main_lightprobes}, -# ifdef WITH_NEW_CURVES_TYPE /** * \note The name `hair_curves` is chosen to be different than `curves`, * but they are generic curve data-blocks, not just for hair. @@ -386,7 +382,6 @@ void RNA_def_main(BlenderRNA *brna) "Hair Curves", "Hair curve data-blocks", RNA_def_main_hair_curves}, -# endif {"pointclouds", "PointCloud", "rna_Main_pointclouds_begin", @@ -471,7 +466,7 @@ void RNA_def_main(BlenderRNA *brna) RNA_def_property_ui_text(prop, lists[i].name, lists[i].description); /* collection functions */ - func = lists[i].func; + CollectionDefFunc *func = lists[i].func; if (func) { func(brna, prop); } diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c index 6c621604e40..1f21fa3fab9 100644 --- a/source/blender/makesrna/intern/rna_main_api.c +++ b/source/blender/makesrna/intern/rna_main_api.c @@ -749,7 +749,6 @@ static bGPdata *rna_Main_gpencils_new(Main *bmain, const char *name) return gpd; } -# ifdef WITH_NEW_CURVES_TYPE static Curves *rna_Main_hair_curves_new(Main *bmain, const char *name) { char safe_name[MAX_ID_NAME - 2]; @@ -762,7 +761,6 @@ static Curves *rna_Main_hair_curves_new(Main *bmain, const char *name) return curves; } -# endif static PointCloud *rna_Main_pointclouds_new(Main *bmain, const char *name) { @@ -847,9 +845,7 @@ RNA_MAIN_ID_TAG_FUNCS_DEF(cachefiles, cachefiles, ID_CF) RNA_MAIN_ID_TAG_FUNCS_DEF(paintcurves, paintcurves, ID_PC) RNA_MAIN_ID_TAG_FUNCS_DEF(workspaces, workspaces, ID_WS) RNA_MAIN_ID_TAG_FUNCS_DEF(lightprobes, lightprobes, ID_LP) -# ifdef WITH_NEW_CURVES_TYPE RNA_MAIN_ID_TAG_FUNCS_DEF(hair_curves, hair_curves, ID_CV) -# endif RNA_MAIN_ID_TAG_FUNCS_DEF(pointclouds, pointclouds, ID_PT) RNA_MAIN_ID_TAG_FUNCS_DEF(volumes, volumes, ID_VO) # ifdef WITH_SIMULATION_DATABLOCK @@ -2255,7 +2251,6 @@ void RNA_def_main_lightprobes(BlenderRNA *brna, PropertyRNA *cprop) RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); } -# ifdef WITH_NEW_CURVES_TYPE void RNA_def_main_hair_curves(BlenderRNA *brna, PropertyRNA *cprop) { StructRNA *srna; @@ -2299,7 +2294,6 @@ void RNA_def_main_hair_curves(BlenderRNA *brna, PropertyRNA *cprop) parm = RNA_def_boolean(func, "value", 0, "Value", ""); RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); } -# endif void RNA_def_main_pointclouds(BlenderRNA *brna, PropertyRNA *cprop) { diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c index 4fb7495bac8..252d2e657b5 100644 --- a/source/blender/makesrna/intern/rna_material.c +++ b/source/blender/makesrna/intern/rna_material.c @@ -367,13 +367,13 @@ static char *rna_GpencilColorData_path(const PointerRNA *UNUSED(ptr)) return BLI_strdup("grease_pencil"); } -static int rna_GpencilColorData_is_stroke_visible_get(PointerRNA *ptr) +static bool rna_GpencilColorData_is_stroke_visible_get(PointerRNA *ptr) { MaterialGPencilStyle *pcolor = ptr->data; return (pcolor->stroke_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH); } -static int rna_GpencilColorData_is_fill_visible_get(PointerRNA *ptr) +static bool rna_GpencilColorData_is_fill_visible_get(PointerRNA *ptr) { MaterialGPencilStyle *pcolor = (MaterialGPencilStyle *)ptr->data; return ((pcolor->fill_rgba[3] > GPENCIL_ALPHA_OPACITY_THRESH) || (pcolor->fill_style > 0)); @@ -754,6 +754,22 @@ static void rna_def_material_lineart(BlenderRNA *brna) "Effectiveness", "Faces with this material will behave as if it has set number of layers in occlusion"); RNA_def_property_update(prop, NC_GPENCIL | ND_SHADING, "rna_MaterialLineArt_update"); + + prop = RNA_def_property(srna, "intersection_priority", PROP_INT, PROP_NONE); + RNA_def_property_range(prop, 0, 255); + RNA_def_property_ui_text(prop, + "Intersection Priority", + "The intersection line will be included into the object with the " + "higher intersection priority value"); + RNA_def_property_update(prop, NC_GPENCIL | ND_SHADING, "rna_MaterialLineArt_update"); + + prop = RNA_def_property(srna, "use_intersection_priority_override", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_default(prop, 0); + RNA_def_property_boolean_sdna(prop, NULL, "flags", LRT_MATERIAL_CUSTOM_INTERSECTION_PRIORITY); + RNA_def_property_ui_text(prop, + "Use Intersection Priority", + "Override object and collection intersection priority value"); + RNA_def_property_update(prop, NC_GPENCIL | ND_SHADING, "rna_MaterialLineArt_update"); } void RNA_def_material(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index fd548ea6a56..c36e53a49cd 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -21,6 +21,7 @@ #include "BLI_math_rotation.h" #include "BLI_utildefines.h" +#include "BKE_attribute.h" #include "BKE_editmesh.h" #include "RNA_access.h" @@ -166,27 +167,62 @@ static CustomData *rna_cd_from_layer(PointerRNA *ptr, CustomDataLayer *cdl) static void rna_MeshVertexLayer_name_set(PointerRNA *ptr, const char *value) { - rna_cd_layer_name_set(rna_mesh_vdata(ptr), (CustomDataLayer *)ptr->data, value); + CustomDataLayer *layer = (CustomDataLayer *)ptr->data; + + if (CD_TYPE_AS_MASK(layer->type) & CD_MASK_PROP_ALL) { + BKE_id_attribute_rename(ptr->owner_id, layer->name, value, NULL); + } + else { + rna_cd_layer_name_set(rna_mesh_vdata(ptr), layer, value); + } } # if 0 static void rna_MeshEdgeLayer_name_set(PointerRNA *ptr, const char *value) { - rna_cd_layer_name_set(rna_mesh_edata(ptr), (CustomDataLayer *)ptr->data, value); + CustomDataLayer *layer = (CustomDataLayer *)ptr->data; + + if (CD_TYPE_AS_MASK(layer->type) & CD_MASK_PROP_ALL) { + BKE_id_attribute_rename(ptr->owner_id, layer->name, value, NULL); + } + else { + rna_cd_layer_name_set(rna_mesh_edata(ptr), layer, value); + } } # endif static void rna_MeshPolyLayer_name_set(PointerRNA *ptr, const char *value) { - rna_cd_layer_name_set(rna_mesh_pdata(ptr), (CustomDataLayer *)ptr->data, value); + CustomDataLayer *layer = (CustomDataLayer *)ptr->data; + + if (CD_TYPE_AS_MASK(layer->type) & CD_MASK_PROP_ALL) { + BKE_id_attribute_rename(ptr->owner_id, layer->name, value, NULL); + } + else { + rna_cd_layer_name_set(rna_mesh_pdata(ptr), layer, value); + } } static void rna_MeshLoopLayer_name_set(PointerRNA *ptr, const char *value) { - rna_cd_layer_name_set(rna_mesh_ldata(ptr), (CustomDataLayer *)ptr->data, value); + CustomDataLayer *layer = (CustomDataLayer *)ptr->data; + + if (CD_TYPE_AS_MASK(layer->type) & CD_MASK_PROP_ALL) { + BKE_id_attribute_rename(ptr->owner_id, layer->name, value, NULL); + } + else { + rna_cd_layer_name_set(rna_mesh_ldata(ptr), layer, value); + } } /* only for layers shared between types */ static void rna_MeshAnyLayer_name_set(PointerRNA *ptr, const char *value) { - CustomData *cd = rna_cd_from_layer(ptr, (CustomDataLayer *)ptr->data); - rna_cd_layer_name_set(cd, (CustomDataLayer *)ptr->data, value); + CustomDataLayer *layer = (CustomDataLayer *)ptr->data; + + if (CD_TYPE_AS_MASK(layer->type) & CD_MASK_PROP_ALL) { + BKE_id_attribute_rename(ptr->owner_id, layer->name, value, NULL); + } + else { + CustomData *cd = rna_cd_from_layer(ptr, layer); + rna_cd_layer_name_set(cd, layer, value); + } } static bool rna_Mesh_has_custom_normals_get(PointerRNA *ptr) @@ -295,22 +331,101 @@ static void rna_Mesh_update_facemask(Main *bmain, Scene *scene, PointerRNA *ptr) rna_Mesh_update_draw(bmain, scene, ptr); } +static void rna_Mesh_update_positions_tag(Main *bmain, Scene *scene, PointerRNA *ptr) +{ + Mesh *mesh = rna_mesh(ptr); + BKE_mesh_tag_coords_changed(mesh); + rna_Mesh_update_data_legacy_deg_tag_all(bmain, scene, ptr); +} + /** \} */ /* -------------------------------------------------------------------- */ /** \name Property get/set Callbacks * \{ */ +static int rna_MeshVertex_index_get(PointerRNA *ptr) +{ + const Mesh *mesh = rna_mesh(ptr); + const MVert *vert = (MVert *)ptr->data; + const int index = (int)(vert - BKE_mesh_verts(mesh)); + BLI_assert(index >= 0); + BLI_assert(index < mesh->totvert); + return index; +} + +static int rna_MeshEdge_index_get(PointerRNA *ptr) +{ + const Mesh *mesh = rna_mesh(ptr); + const MEdge *edge = (MEdge *)ptr->data; + const int index = (int)(edge - BKE_mesh_edges(mesh)); + BLI_assert(index >= 0); + BLI_assert(index < mesh->totedge); + return index; +} + +static int rna_MeshPolygon_index_get(PointerRNA *ptr) +{ + const Mesh *mesh = rna_mesh(ptr); + const MPoly *mpoly = (MPoly *)ptr->data; + const int index = (int)(mpoly - BKE_mesh_polys(mesh)); + BLI_assert(index >= 0); + BLI_assert(index < mesh->totpoly); + return index; +} + +static int rna_MeshLoop_index_get(PointerRNA *ptr) +{ + const Mesh *mesh = rna_mesh(ptr); + const MLoop *mloop = (MLoop *)ptr->data; + const int index = (int)(mloop - BKE_mesh_loops(mesh)); + BLI_assert(index >= 0); + BLI_assert(index < mesh->totloop); + return index; +} + +static int rna_MeshLoopTriangle_index_get(PointerRNA *ptr) +{ + const Mesh *mesh = rna_mesh(ptr); + const MLoopTri *ltri = (MLoopTri *)ptr->data; + const int index = (int)(ltri - mesh->runtime.looptris.array); + BLI_assert(index >= 0); + BLI_assert(index < mesh->runtime.looptris.len); + return index; +} + static void rna_MeshVertex_normal_get(PointerRNA *ptr, float *value) { Mesh *mesh = rna_mesh(ptr); const float(*vert_normals)[3] = BKE_mesh_vertex_normals_ensure(mesh); + const int index = rna_MeshVertex_index_get(ptr); + copy_v3_v3(value, vert_normals[index]); +} - const int index = (MVert *)ptr->data - mesh->mvert; - BLI_assert(index >= 0); - BLI_assert(index < mesh->totvert); +static bool rna_MeshVertex_hide_get(PointerRNA *ptr) +{ + const Mesh *mesh = rna_mesh(ptr); + const bool *hide_vert = (const bool *)CustomData_get_layer_named( + &mesh->vdata, CD_PROP_BOOL, ".hide_vert"); + const int index = rna_MeshVertex_index_get(ptr); + return hide_vert == NULL ? false : hide_vert[index]; +} - copy_v3_v3(value, vert_normals[index]); +static void rna_MeshVertex_hide_set(PointerRNA *ptr, bool value) +{ + Mesh *mesh = rna_mesh(ptr); + bool *hide_vert = (bool *)CustomData_duplicate_referenced_layer_named( + &mesh->vdata, CD_PROP_BOOL, ".hide_vert", mesh->totvert); + if (!hide_vert) { + if (!value) { + /* Skip adding layer if it doesn't exist already anyway and we're not hiding an element. */ + return; + } + hide_vert = (bool *)CustomData_add_layer_named( + &mesh->vdata, CD_PROP_BOOL, CD_SET_DEFAULT, NULL, mesh->totvert, ".hide_vert"); + } + const int index = rna_MeshVertex_index_get(ptr); + hide_vert[index] = value; } static float rna_MeshVertex_bevel_weight_get(PointerRNA *ptr) @@ -352,8 +467,8 @@ static void rna_MEdge_crease_set(PointerRNA *ptr, float value) static void rna_MeshLoop_normal_get(PointerRNA *ptr, float *values) { Mesh *me = rna_mesh(ptr); - MLoop *ml = (MLoop *)ptr->data; - const float(*vec)[3] = CustomData_get(&me->ldata, (int)(ml - me->mloop), CD_NORMAL); + const int index = rna_MeshLoop_index_get(ptr); + const float(*vec)[3] = CustomData_get(&me->ldata, index, CD_NORMAL); if (!vec) { zero_v3(values); @@ -366,8 +481,8 @@ static void rna_MeshLoop_normal_get(PointerRNA *ptr, float *values) static void rna_MeshLoop_normal_set(PointerRNA *ptr, const float *values) { Mesh *me = rna_mesh(ptr); - MLoop *ml = (MLoop *)ptr->data; - float(*vec)[3] = CustomData_get(&me->ldata, (int)(ml - me->mloop), CD_NORMAL); + const int index = rna_MeshLoop_index_get(ptr); + float(*vec)[3] = CustomData_get(&me->ldata, index, CD_NORMAL); if (vec) { normalize_v3_v3(*vec, values); @@ -377,8 +492,8 @@ static void rna_MeshLoop_normal_set(PointerRNA *ptr, const float *values) static void rna_MeshLoop_tangent_get(PointerRNA *ptr, float *values) { Mesh *me = rna_mesh(ptr); - MLoop *ml = (MLoop *)ptr->data; - const float(*vec)[4] = CustomData_get(&me->ldata, (int)(ml - me->mloop), CD_MLOOPTANGENT); + const int index = rna_MeshLoop_index_get(ptr); + const float(*vec)[4] = CustomData_get(&me->ldata, index, CD_MLOOPTANGENT); if (!vec) { zero_v3(values); @@ -391,8 +506,8 @@ static void rna_MeshLoop_tangent_get(PointerRNA *ptr, float *values) static float rna_MeshLoop_bitangent_sign_get(PointerRNA *ptr) { Mesh *me = rna_mesh(ptr); - MLoop *ml = (MLoop *)ptr->data; - const float(*vec)[4] = CustomData_get(&me->ldata, (int)(ml - me->mloop), CD_MLOOPTANGENT); + const int index = rna_MeshLoop_index_get(ptr); + const float(*vec)[4] = CustomData_get(&me->ldata, index, CD_MLOOPTANGENT); return (vec) ? (*vec)[3] : 0.0f; } @@ -400,9 +515,9 @@ static float rna_MeshLoop_bitangent_sign_get(PointerRNA *ptr) static void rna_MeshLoop_bitangent_get(PointerRNA *ptr, float *values) { Mesh *me = rna_mesh(ptr); - MLoop *ml = (MLoop *)ptr->data; - const float(*nor)[3] = CustomData_get(&me->ldata, (int)(ml - me->mloop), CD_NORMAL); - const float(*vec)[4] = CustomData_get(&me->ldata, (int)(ml - me->mloop), CD_MLOOPTANGENT); + const int index = rna_MeshLoop_index_get(ptr); + const float(*nor)[3] = CustomData_get(&me->ldata, index, CD_NORMAL); + const float(*vec)[4] = CustomData_get(&me->ldata, index, CD_MLOOPTANGENT); if (nor && vec) { cross_v3_v3v3(values, (const float *)nor, (const float *)vec); @@ -417,31 +532,76 @@ static void rna_MeshPolygon_normal_get(PointerRNA *ptr, float *values) { Mesh *me = rna_mesh(ptr); MPoly *mp = (MPoly *)ptr->data; + const MVert *verts = BKE_mesh_verts(me); + const MLoop *loops = BKE_mesh_loops(me); + BKE_mesh_calc_poly_normal(mp, loops + mp->loopstart, verts, values); +} + +static bool rna_MeshPolygon_hide_get(PointerRNA *ptr) +{ + const Mesh *mesh = rna_mesh(ptr); + const bool *hide_poly = (const bool *)CustomData_get_layer_named( + &mesh->pdata, CD_PROP_BOOL, ".hide_poly"); + const int index = rna_MeshPolygon_index_get(ptr); + return hide_poly == NULL ? false : hide_poly[index]; +} + +static void rna_MeshPolygon_hide_set(PointerRNA *ptr, bool value) +{ + Mesh *mesh = rna_mesh(ptr); + bool *hide_poly = (bool *)CustomData_duplicate_referenced_layer_named( + &mesh->pdata, CD_PROP_BOOL, ".hide_poly", mesh->totpoly); + if (!hide_poly) { + if (!value) { + /* Skip adding layer if it doesn't exist already anyway and we're not hiding an element. */ + return; + } + hide_poly = (bool *)CustomData_add_layer_named( + &mesh->pdata, CD_PROP_BOOL, CD_SET_DEFAULT, NULL, mesh->totpoly, ".hide_poly"); + } + const int index = rna_MeshPolygon_index_get(ptr); + hide_poly[index] = value; +} + +static int rna_MeshPolygon_material_index_get(PointerRNA *ptr) +{ + const Mesh *mesh = rna_mesh(ptr); + const int *material_indices = BKE_mesh_material_indices(mesh); + const int index = rna_MeshPolygon_index_get(ptr); + return material_indices == NULL ? 0 : material_indices[index]; +} - BKE_mesh_calc_poly_normal(mp, me->mloop + mp->loopstart, me->mvert, values); +static void rna_MeshPolygon_material_index_set(PointerRNA *ptr, int value) +{ + Mesh *mesh = rna_mesh(ptr); + int *material_indices = BKE_mesh_material_indices_for_write(mesh); + const int index = rna_MeshPolygon_index_get(ptr); + material_indices[index] = value; } static void rna_MeshPolygon_center_get(PointerRNA *ptr, float *values) { Mesh *me = rna_mesh(ptr); MPoly *mp = (MPoly *)ptr->data; - - BKE_mesh_calc_poly_center(mp, me->mloop + mp->loopstart, me->mvert, values); + const MVert *verts = BKE_mesh_verts(me); + const MLoop *loops = BKE_mesh_loops(me); + BKE_mesh_calc_poly_center(mp, loops + mp->loopstart, verts, values); } static float rna_MeshPolygon_area_get(PointerRNA *ptr) { Mesh *me = (Mesh *)ptr->owner_id; MPoly *mp = (MPoly *)ptr->data; - - return BKE_mesh_calc_poly_area(mp, me->mloop + mp->loopstart, me->mvert); + const MVert *verts = BKE_mesh_verts(me); + const MLoop *loops = BKE_mesh_loops(me); + return BKE_mesh_calc_poly_area(mp, loops + mp->loopstart, verts); } static void rna_MeshPolygon_flip(ID *id, MPoly *mp) { Mesh *me = (Mesh *)id; - - BKE_mesh_polygon_flip(mp, me->mloop, &me->ldata); + MLoop *loops = BKE_mesh_loops_for_write(me); + BKE_mesh_polygon_flip(mp, loops, &me->ldata); BKE_mesh_tessface_clear(me); BKE_mesh_runtime_clear_geometry(me); BKE_mesh_normals_tag_dirty(me); @@ -450,21 +610,24 @@ static void rna_MeshPolygon_flip(ID *id, MPoly *mp) static void rna_MeshLoopTriangle_verts_get(PointerRNA *ptr, int *values) { Mesh *me = rna_mesh(ptr); + const MLoop *loops = BKE_mesh_loops(me); MLoopTri *lt = (MLoopTri *)ptr->data; - values[0] = me->mloop[lt->tri[0]].v; - values[1] = me->mloop[lt->tri[1]].v; - values[2] = me->mloop[lt->tri[2]].v; + values[0] = loops[lt->tri[0]].v; + values[1] = loops[lt->tri[1]].v; + values[2] = loops[lt->tri[2]].v; } static void rna_MeshLoopTriangle_normal_get(PointerRNA *ptr, float *values) { Mesh *me = rna_mesh(ptr); MLoopTri *lt = (MLoopTri *)ptr->data; - unsigned int v1 = me->mloop[lt->tri[0]].v; - unsigned int v2 = me->mloop[lt->tri[1]].v; - unsigned int v3 = me->mloop[lt->tri[2]].v; + const MVert *verts = BKE_mesh_verts(me); + const MLoop *loops = BKE_mesh_loops(me); + unsigned int v1 = loops[lt->tri[0]].v; + unsigned int v2 = loops[lt->tri[1]].v; + unsigned int v3 = loops[lt->tri[2]].v; - normal_tri_v3(values, me->mvert[v1].co, me->mvert[v2].co, me->mvert[v3].co); + normal_tri_v3(values, verts[v1].co, verts[v2].co, verts[v3].co); } static void rna_MeshLoopTriangle_split_normals_get(PointerRNA *ptr, float *values) @@ -489,11 +652,12 @@ static float rna_MeshLoopTriangle_area_get(PointerRNA *ptr) { Mesh *me = rna_mesh(ptr); MLoopTri *lt = (MLoopTri *)ptr->data; - unsigned int v1 = me->mloop[lt->tri[0]].v; - unsigned int v2 = me->mloop[lt->tri[1]].v; - unsigned int v3 = me->mloop[lt->tri[2]].v; - - return area_tri_v3(me->mvert[v1].co, me->mvert[v2].co, me->mvert[v3].co); + const MVert *verts = BKE_mesh_verts(me); + const MLoop *loops = BKE_mesh_loops(me); + unsigned int v1 = loops[lt->tri[0]].v; + unsigned int v2 = loops[lt->tri[1]].v; + unsigned int v3 = loops[lt->tri[2]].v; + return area_tri_v3(verts[v1].co, verts[v2].co, verts[v3].co); } static void rna_MeshLoopColor_color_get(PointerRNA *ptr, float *values) @@ -543,10 +707,10 @@ static void rna_Mesh_texspace_loc_get(PointerRNA *ptr, float values[3]) static void rna_MeshVertex_groups_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { Mesh *me = rna_mesh(ptr); - - if (me->dvert) { - MVert *mvert = (MVert *)ptr->data; - MDeformVert *dvert = me->dvert + (mvert - me->mvert); + MDeformVert *dverts = (MDeformVert *)BKE_mesh_deform_verts(me); + if (dverts) { + const int index = rna_MeshVertex_index_get(ptr); + MDeformVert *dvert = &dverts[index]; rna_iterator_array_begin( iter, (void *)dvert->dw, sizeof(MDeformWeight), dvert->totweight, 0, NULL); @@ -563,11 +727,12 @@ static void rna_MeshVertex_undeformed_co_get(PointerRNA *ptr, float values[3]) const float(*orco)[3] = CustomData_get_layer(&me->vdata, CD_ORCO); if (orco) { + const int index = rna_MeshVertex_index_get(ptr); /* orco is normalized to 0..1, we do inverse to match mvert->co */ float loc[3], size[3]; BKE_mesh_texspace_get(me->texcomesh ? me->texcomesh : me, loc, size); - madd_v3_v3v3v3(values, loc, orco[(mvert - me->mvert)], size); + madd_v3_v3v3v3(values, loc, orco[index], size); } else { copy_v3_v3(values, mvert->co); @@ -610,7 +775,7 @@ static void rna_CustomDataLayer_active_set( CustomData_set_layer_active(data, type, n); } - BKE_mesh_update_customdata_pointers(me, true); + BKE_mesh_tessface_clear(me); } static void rna_CustomDataLayer_clone_set(PointerRNA *ptr, CustomData *data, int value, int type) @@ -627,9 +792,8 @@ static void rna_CustomDataLayer_clone_set(PointerRNA *ptr, CustomData *data, int static bool rna_MEdge_freestyle_edge_mark_get(PointerRNA *ptr) { const Mesh *me = rna_mesh(ptr); - const MEdge *medge = (MEdge *)ptr->data; - const FreestyleEdge *fed = CustomData_get( - &me->edata, (int)(medge - me->medge), CD_FREESTYLE_EDGE); + const int index = rna_MeshEdge_index_get(ptr); + const FreestyleEdge *fed = CustomData_get(&me->edata, index, CD_FREESTYLE_EDGE); return fed && (fed->flag & FREESTYLE_EDGE_MARK) != 0; } @@ -637,11 +801,11 @@ static bool rna_MEdge_freestyle_edge_mark_get(PointerRNA *ptr) static void rna_MEdge_freestyle_edge_mark_set(PointerRNA *ptr, bool value) { Mesh *me = rna_mesh(ptr); - MEdge *medge = (MEdge *)ptr->data; - FreestyleEdge *fed = CustomData_get(&me->edata, (int)(medge - me->medge), CD_FREESTYLE_EDGE); + const int index = rna_MeshEdge_index_get(ptr); + FreestyleEdge *fed = CustomData_get(&me->edata, index, CD_FREESTYLE_EDGE); if (!fed) { - fed = CustomData_add_layer(&me->edata, CD_FREESTYLE_EDGE, CD_CALLOC, NULL, me->totedge); + fed = CustomData_add_layer(&me->edata, CD_FREESTYLE_EDGE, CD_SET_DEFAULT, NULL, me->totedge); } if (value) { fed->flag |= FREESTYLE_EDGE_MARK; @@ -654,21 +818,20 @@ static void rna_MEdge_freestyle_edge_mark_set(PointerRNA *ptr, bool value) static bool rna_MPoly_freestyle_face_mark_get(PointerRNA *ptr) { const Mesh *me = rna_mesh(ptr); - const MPoly *mpoly = (MPoly *)ptr->data; - const FreestyleFace *ffa = CustomData_get( - &me->pdata, (int)(mpoly - me->mpoly), CD_FREESTYLE_FACE); + const int index = rna_MeshPolygon_index_get(ptr); + const FreestyleFace *ffa = CustomData_get(&me->pdata, index, CD_FREESTYLE_FACE); return ffa && (ffa->flag & FREESTYLE_FACE_MARK) != 0; } -static void rna_MPoly_freestyle_face_mark_set(PointerRNA *ptr, int value) +static void rna_MPoly_freestyle_face_mark_set(PointerRNA *ptr, bool value) { Mesh *me = rna_mesh(ptr); - MPoly *mpoly = (MPoly *)ptr->data; - FreestyleFace *ffa = CustomData_get(&me->pdata, (int)(mpoly - me->mpoly), CD_FREESTYLE_FACE); + const int index = rna_MeshPolygon_index_get(ptr); + FreestyleFace *ffa = CustomData_get(&me->pdata, index, CD_FREESTYLE_FACE); if (!ffa) { - ffa = CustomData_add_layer(&me->pdata, CD_FREESTYLE_FACE, CD_CALLOC, NULL, me->totpoly); + ffa = CustomData_add_layer(&me->pdata, CD_FREESTYLE_FACE, CD_SET_DEFAULT, NULL, me->totpoly); } if (value) { ffa->flag |= FREESTYLE_FACE_MARK; @@ -1102,7 +1265,8 @@ static void rna_MeshPoly_vertices_get(PointerRNA *ptr, int *values) { Mesh *me = rna_mesh(ptr); MPoly *mp = (MPoly *)ptr->data; - MLoop *ml = &me->mloop[mp->loopstart]; + const MLoop *loops = BKE_mesh_loops(me); + const MLoop *ml = &loops[mp->loopstart]; unsigned int i; for (i = mp->totloop; i > 0; i--, values++, ml++) { *values = ml->v; @@ -1112,8 +1276,10 @@ static void rna_MeshPoly_vertices_get(PointerRNA *ptr, int *values) static void rna_MeshPoly_vertices_set(PointerRNA *ptr, const int *values) { Mesh *me = rna_mesh(ptr); - MPoly *mp = (MPoly *)ptr->data; - MLoop *ml = &me->mloop[mp->loopstart]; + const MPoly *mp = (const MPoly *)ptr->data; + MLoop *loops = BKE_mesh_loops_for_write(me); + + MLoop *ml = &loops[mp->loopstart]; unsigned int i; for (i = mp->totloop; i > 0; i--, values++, ml++) { ml->v = *values; @@ -1131,53 +1297,46 @@ static void rna_MeshPoly_material_index_range( } # endif -static int rna_MeshVertex_index_get(PointerRNA *ptr) +static bool rna_MeshEdge_hide_get(PointerRNA *ptr) { - Mesh *me = rna_mesh(ptr); - MVert *vert = (MVert *)ptr->data; - return (int)(vert - me->mvert); -} - -static int rna_MeshEdge_index_get(PointerRNA *ptr) -{ - Mesh *me = rna_mesh(ptr); - MEdge *edge = (MEdge *)ptr->data; - return (int)(edge - me->medge); + const Mesh *mesh = rna_mesh(ptr); + const bool *hide_edge = (const bool *)CustomData_get_layer_named( + &mesh->edata, CD_PROP_BOOL, ".hide_edge"); + const int index = rna_MeshEdge_index_get(ptr); + return hide_edge == NULL ? false : hide_edge[index]; } -static int rna_MeshLoopTriangle_index_get(PointerRNA *ptr) +static void rna_MeshEdge_hide_set(PointerRNA *ptr, bool value) { - Mesh *me = rna_mesh(ptr); - MLoopTri *ltri = (MLoopTri *)ptr->data; - return (int)(ltri - me->runtime.looptris.array); + Mesh *mesh = rna_mesh(ptr); + bool *hide_edge = (bool *)CustomData_duplicate_referenced_layer_named( + &mesh->edata, CD_PROP_BOOL, ".hide_edge", mesh->totedge); + if (!hide_edge) { + if (!value) { + /* Skip adding layer if it doesn't exist already anyway and we're not hiding an element. */ + return; + } + hide_edge = (bool *)CustomData_add_layer_named( + &mesh->edata, CD_PROP_BOOL, CD_SET_DEFAULT, NULL, mesh->totedge, ".hide_edge"); + } + const int index = rna_MeshEdge_index_get(ptr); + hide_edge[index] = value; } static int rna_MeshLoopTriangle_material_index_get(PointerRNA *ptr) { - Mesh *me = rna_mesh(ptr); - MLoopTri *ltri = (MLoopTri *)ptr->data; - return me->mpoly[ltri->poly].mat_nr; + const Mesh *me = rna_mesh(ptr); + const int *material_indices = BKE_mesh_material_indices(me); + const MLoopTri *ltri = (MLoopTri *)ptr->data; + return material_indices == NULL ? 0 : material_indices[ltri->poly]; } static bool rna_MeshLoopTriangle_use_smooth_get(PointerRNA *ptr) { - Mesh *me = rna_mesh(ptr); - MLoopTri *ltri = (MLoopTri *)ptr->data; - return me->mpoly[ltri->poly].flag & ME_SMOOTH; -} - -static int rna_MeshPolygon_index_get(PointerRNA *ptr) -{ - Mesh *me = rna_mesh(ptr); - MPoly *mpoly = (MPoly *)ptr->data; - return (int)(mpoly - me->mpoly); -} - -static int rna_MeshLoop_index_get(PointerRNA *ptr) -{ - Mesh *me = rna_mesh(ptr); - MLoop *mloop = (MLoop *)ptr->data; - return (int)(mloop - me->mloop); + const Mesh *me = rna_mesh(ptr); + const MLoopTri *ltri = (MLoopTri *)ptr->data; + const MPoly *polys = BKE_mesh_polys(me); + return polys[ltri->poly].flag & ME_SMOOTH; } /* path construction */ @@ -1186,10 +1345,10 @@ static char *rna_VertexGroupElement_path(const PointerRNA *ptr) { const Mesh *me = rna_mesh(ptr); /* XXX not always! */ const MDeformWeight *dw = (MDeformWeight *)ptr->data; - const MDeformVert *dvert; + const MDeformVert *dvert = BKE_mesh_deform_verts(me); int a, b; - for (a = 0, dvert = me->dvert; a < me->totvert; a++, dvert++) { + for (a = 0; a < me->totvert; a++, dvert++) { for (b = 0; b < dvert->totweight; b++) { if (dw == &dvert->dw[b]) { return BLI_sprintfN("vertices[%d].groups[%d]", a, b); @@ -1202,7 +1361,7 @@ static char *rna_VertexGroupElement_path(const PointerRNA *ptr) static char *rna_MeshPolygon_path(const PointerRNA *ptr) { - return BLI_sprintfN("polygons[%d]", (int)((MPoly *)ptr->data - rna_mesh(ptr)->mpoly)); + return BLI_sprintfN("polygons[%d]", rna_MeshPolygon_index_get((PointerRNA *)ptr)); } static char *rna_MeshLoopTriangle_path(const PointerRNA *ptr) @@ -1213,17 +1372,17 @@ static char *rna_MeshLoopTriangle_path(const PointerRNA *ptr) static char *rna_MeshEdge_path(const PointerRNA *ptr) { - return BLI_sprintfN("edges[%d]", (int)((MEdge *)ptr->data - rna_mesh(ptr)->medge)); + return BLI_sprintfN("edges[%d]", rna_MeshEdge_index_get((PointerRNA *)ptr)); } static char *rna_MeshLoop_path(const PointerRNA *ptr) { - return BLI_sprintfN("loops[%d]", (int)((MLoop *)ptr->data - rna_mesh(ptr)->mloop)); + return BLI_sprintfN("loops[%d]", rna_MeshLoop_index_get((PointerRNA *)ptr)); } static char *rna_MeshVertex_path(const PointerRNA *ptr) { - return BLI_sprintfN("vertices[%d]", (int)((MVert *)ptr->data - rna_mesh(ptr)->mvert)); + return BLI_sprintfN("vertices[%d]", rna_MeshVertex_index_get((PointerRNA *)ptr)); } static char *rna_VertCustomData_data_path(const PointerRNA *ptr, const char *collection, int type) @@ -1289,6 +1448,98 @@ static char *rna_LoopCustomData_data_path(const PointerRNA *ptr, const char *col return NULL; } +static void rna_Mesh_vertices_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) +{ + Mesh *mesh = rna_mesh(ptr); + rna_iterator_array_begin( + iter, BKE_mesh_verts_for_write(mesh), sizeof(MVert), mesh->totvert, false, NULL); +} +static int rna_Mesh_vertices_length(PointerRNA *ptr) +{ + const Mesh *mesh = rna_mesh(ptr); + return mesh->totvert; +} +int rna_Mesh_vertices_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr) +{ + Mesh *mesh = rna_mesh(ptr); + if (index < 0 || index >= mesh->totvert) { + return false; + } + r_ptr->owner_id = &mesh->id; + r_ptr->type = &RNA_MeshVertex; + r_ptr->data = &BKE_mesh_verts_for_write(mesh)[index]; + return true; +} + +static void rna_Mesh_edges_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) +{ + Mesh *mesh = rna_mesh(ptr); + rna_iterator_array_begin( + iter, BKE_mesh_edges_for_write(mesh), sizeof(MEdge), mesh->totedge, false, NULL); +} +static int rna_Mesh_edges_length(PointerRNA *ptr) +{ + const Mesh *mesh = rna_mesh(ptr); + return mesh->totedge; +} +int rna_Mesh_edges_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr) +{ + Mesh *mesh = rna_mesh(ptr); + if (index < 0 || index >= mesh->totedge) { + return false; + } + r_ptr->owner_id = &mesh->id; + r_ptr->type = &RNA_MeshEdge; + r_ptr->data = &BKE_mesh_edges_for_write(mesh)[index]; + return true; +} + +static void rna_Mesh_polygons_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) +{ + Mesh *mesh = rna_mesh(ptr); + rna_iterator_array_begin( + iter, BKE_mesh_polys_for_write(mesh), sizeof(MPoly), mesh->totpoly, false, NULL); +} +static int rna_Mesh_polygons_length(PointerRNA *ptr) +{ + const Mesh *mesh = rna_mesh(ptr); + return mesh->totpoly; +} +int rna_Mesh_polygons_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr) +{ + Mesh *mesh = rna_mesh(ptr); + if (index < 0 || index >= mesh->totpoly) { + return false; + } + r_ptr->owner_id = &mesh->id; + r_ptr->type = &RNA_MeshPolygon; + r_ptr->data = &BKE_mesh_polys_for_write(mesh)[index]; + return true; +} + +static void rna_Mesh_loops_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) +{ + Mesh *mesh = rna_mesh(ptr); + rna_iterator_array_begin( + iter, BKE_mesh_loops_for_write(mesh), sizeof(MLoop), mesh->totloop, false, NULL); +} +static int rna_Mesh_loops_length(PointerRNA *ptr) +{ + const Mesh *mesh = rna_mesh(ptr); + return mesh->totloop; +} +int rna_Mesh_loops_lookup_int(PointerRNA *ptr, int index, PointerRNA *r_ptr) +{ + Mesh *mesh = rna_mesh(ptr); + if (index < 0 || index >= mesh->totloop) { + return false; + } + r_ptr->owner_id = &mesh->id; + r_ptr->type = &RNA_MeshLoop; + r_ptr->data = &BKE_mesh_loops_for_write(mesh)[index]; + return true; +} + static void rna_Mesh_vertex_normals_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { const Mesh *mesh = rna_mesh(ptr); @@ -1565,9 +1816,7 @@ static void rna_Mesh_vertex_color_remove(struct Mesh *me, ReportList *reports, CustomDataLayer *layer) { - if (ED_mesh_color_remove_named(me, layer->name) == false) { - BKE_reportf(reports, RPT_ERROR, "Vertex color '%s' not found", layer->name); - } + BKE_id_attribute_remove(&me->id, layer->name, reports); } static PointerRNA rna_Mesh_sculpt_vertex_color_new(struct Mesh *me, @@ -1578,7 +1827,7 @@ static PointerRNA rna_Mesh_sculpt_vertex_color_new(struct Mesh *me, PointerRNA ptr; CustomData *vdata; CustomDataLayer *cdl = NULL; - int index = ED_mesh_sculpt_color_add(me, name, false, do_init, reports); + int index = ED_mesh_sculpt_color_add(me, name, do_init, reports); if (index != -1) { vdata = rna_mesh_vdata_helper(me); @@ -1593,9 +1842,7 @@ static void rna_Mesh_sculpt_vertex_color_remove(struct Mesh *me, ReportList *reports, CustomDataLayer *layer) { - if (ED_mesh_sculpt_color_remove_named(me, layer->name) == false) { - BKE_reportf(reports, RPT_ERROR, "Sculpt vertex color '%s' not found", layer->name); - } + BKE_id_attribute_remove(&me->id, layer->name, reports); } # define DEFINE_CUSTOMDATA_PROPERTY_API( \ @@ -1607,7 +1854,8 @@ static void rna_Mesh_sculpt_vertex_color_remove(struct Mesh *me, CustomDataLayer *cdl = NULL; \ int index; \ \ - CustomData_add_layer_named(&me->cdata, cd_prop_type, CD_DEFAULT, NULL, me->countvar, name); \ + CustomData_add_layer_named( \ + &me->cdata, cd_prop_type, CD_SET_DEFAULT, NULL, me->countvar, name); \ index = CustomData_get_named_layer_index(&me->cdata, cd_prop_type, name); \ \ cdl = (index == -1) ? NULL : &(me->cdata.layers[index]); \ @@ -1680,6 +1928,56 @@ static void UNUSED_FUNCTION(rna_mesh_unused)(void) /* end unused function block */ } +static bool rna_Mesh_materials_override_apply(Main *bmain, + PointerRNA *ptr_dst, + PointerRNA *UNUSED(ptr_src), + PointerRNA *UNUSED(ptr_storage), + PropertyRNA *prop_dst, + PropertyRNA *UNUSED(prop_src), + PropertyRNA *UNUSED(prop_storage), + const int UNUSED(len_dst), + const int UNUSED(len_src), + const int UNUSED(len_storage), + PointerRNA *ptr_item_dst, + PointerRNA *ptr_item_src, + PointerRNA *UNUSED(ptr_item_storage), + IDOverrideLibraryPropertyOperation *opop) +{ + BLI_assert_msg(opop->operation == IDOVERRIDE_LIBRARY_OP_REPLACE, + "Unsupported RNA override operation on collections' objects"); + UNUSED_VARS_NDEBUG(opop); + + Mesh *mesh_dst = (Mesh *)ptr_dst->owner_id; + + if (ptr_item_dst->type == NULL || ptr_item_src->type == NULL) { + // BLI_assert_msg(0, "invalid source or destination material."); + return false; + } + + Material *mat_dst = ptr_item_dst->data; + Material *mat_src = ptr_item_src->data; + + if (mat_src == mat_dst) { + return true; + } + + bool is_modified = false; + for (int i = 0; i < mesh_dst->totcol; i++) { + if (mesh_dst->mat[i] == mat_dst) { + id_us_min(&mat_dst->id); + mesh_dst->mat[i] = mat_src; + id_us_plus(&mat_src->id); + is_modified = true; + } + } + + if (is_modified) { + RNA_property_update_main(bmain, NULL, ptr_dst, prop_dst); + } + + return true; +} + /** \} */ #else @@ -1727,7 +2025,7 @@ static void rna_def_mvert(BlenderRNA *brna) prop = RNA_def_property(srna, "co", PROP_FLOAT, PROP_TRANSLATION); RNA_def_property_ui_text(prop, "Location", ""); - RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all"); + RNA_def_property_update(prop, 0, "rna_Mesh_update_positions_tag"); prop = RNA_def_property(srna, "normal", PROP_FLOAT, PROP_DIRECTION); RNA_def_property_array(prop, 3); @@ -1741,8 +2039,8 @@ static void rna_def_mvert(BlenderRNA *brna) RNA_def_property_update(prop, 0, "rna_Mesh_update_select"); prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_HIDE); RNA_def_property_ui_text(prop, "Hide", ""); + RNA_def_property_boolean_funcs(prop, "rna_MeshVertex_hide_get", "rna_MeshVertex_hide_set"); RNA_def_property_update(prop, 0, "rna_Mesh_update_select"); prop = RNA_def_property(srna, "bevel_weight", PROP_FLOAT, PROP_NONE); @@ -1817,8 +2115,8 @@ static void rna_def_medge(BlenderRNA *brna) RNA_def_property_update(prop, 0, "rna_Mesh_update_select"); prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_HIDE); RNA_def_property_ui_text(prop, "Hide", ""); + RNA_def_property_boolean_funcs(prop, "rna_MeshEdge_hide_get", "rna_MeshEdge_hide_set"); RNA_def_property_update(prop, 0, "rna_Mesh_update_select"); prop = RNA_def_property(srna, "use_seam", PROP_BOOLEAN, PROP_NONE); @@ -2017,7 +2315,8 @@ static void rna_def_mpolygon(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Loop Total", "Number of loops used by this polygon"); prop = RNA_def_property(srna, "material_index", PROP_INT, PROP_UNSIGNED); - RNA_def_property_int_sdna(prop, NULL, "mat_nr"); + RNA_def_property_int_funcs( + prop, "rna_MeshPolygon_material_index_get", "rna_MeshPolygon_material_index_set", false); RNA_def_property_ui_text(prop, "Material Index", "Material slot index of this polygon"); # if 0 RNA_def_property_int_funcs(prop, NULL, NULL, "rna_MeshPoly_material_index_range"); @@ -2030,8 +2329,8 @@ static void rna_def_mpolygon(BlenderRNA *brna) RNA_def_property_update(prop, 0, "rna_Mesh_update_select"); prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_HIDE); RNA_def_property_ui_text(prop, "Hide", ""); + RNA_def_property_boolean_funcs(prop, "rna_MeshPolygon_hide_get", "rna_MeshPolygon_hide_set"); RNA_def_property_update(prop, 0, "rna_Mesh_update_select"); prop = RNA_def_property(srna, "use_smooth", PROP_BOOLEAN, PROP_NONE); @@ -2124,6 +2423,7 @@ static void rna_def_mloopuv(BlenderRNA *brna) srna = RNA_def_struct(brna, "MeshUVLoop", NULL); RNA_def_struct_sdna(srna, "MLoopUV"); + RNA_def_struct_ui_text(srna, "Mesh UV Layer", "Layer of UV coordinates in a Mesh data-block"); RNA_def_struct_path_func(srna, "rna_MeshUVLoop_path"); prop = RNA_def_property(srna, "uv", PROP_FLOAT, PROP_XYZ); @@ -2435,6 +2735,8 @@ void rna_def_texmat_common(StructRNA *srna, const char *texspace_editable) RNA_def_property_struct_type(prop, "Material"); RNA_def_property_ui_text(prop, "Materials", ""); RNA_def_property_srna(prop, "IDMaterials"); /* see rna_ID.c */ + RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY); + RNA_def_property_override_funcs(prop, NULL, NULL, "rna_Mesh_materials_override_apply"); RNA_def_property_collection_funcs( prop, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "rna_IDMaterials_assign_int"); } @@ -3068,28 +3370,60 @@ static void rna_def_mesh(BlenderRNA *brna) RNA_def_struct_ui_icon(srna, ICON_MESH_DATA); prop = RNA_def_property(srna, "vertices", PROP_COLLECTION, PROP_NONE); - RNA_def_property_collection_sdna(prop, NULL, "mvert", "totvert"); + RNA_def_property_collection_funcs(prop, + "rna_Mesh_vertices_begin", + "rna_iterator_array_next", + "rna_iterator_array_end", + "rna_iterator_array_get", + "rna_Mesh_vertices_length", + "rna_Mesh_vertices_lookup_int", + NULL, + NULL); RNA_def_property_struct_type(prop, "MeshVertex"); RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE); RNA_def_property_ui_text(prop, "Vertices", "Vertices of the mesh"); rna_def_mesh_vertices(brna, prop); prop = RNA_def_property(srna, "edges", PROP_COLLECTION, PROP_NONE); - RNA_def_property_collection_sdna(prop, NULL, "medge", "totedge"); + RNA_def_property_collection_funcs(prop, + "rna_Mesh_edges_begin", + "rna_iterator_array_next", + "rna_iterator_array_end", + "rna_iterator_array_get", + "rna_Mesh_edges_length", + "rna_Mesh_edges_lookup_int", + NULL, + NULL); RNA_def_property_struct_type(prop, "MeshEdge"); RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE); RNA_def_property_ui_text(prop, "Edges", "Edges of the mesh"); rna_def_mesh_edges(brna, prop); prop = RNA_def_property(srna, "loops", PROP_COLLECTION, PROP_NONE); - RNA_def_property_collection_sdna(prop, NULL, "mloop", "totloop"); + RNA_def_property_collection_funcs(prop, + "rna_Mesh_loops_begin", + "rna_iterator_array_next", + "rna_iterator_array_end", + "rna_iterator_array_get", + "rna_Mesh_loops_length", + "rna_Mesh_loops_lookup_int", + NULL, + NULL); RNA_def_property_struct_type(prop, "MeshLoop"); RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE); RNA_def_property_ui_text(prop, "Loops", "Loops of the mesh (polygon corners)"); rna_def_mesh_loops(brna, prop); prop = RNA_def_property(srna, "polygons", PROP_COLLECTION, PROP_NONE); - RNA_def_property_collection_sdna(prop, NULL, "mpoly", "totpoly"); + RNA_def_property_collection_funcs(prop, + "rna_Mesh_polygons_begin", + "rna_iterator_array_next", + "rna_iterator_array_end", + "rna_iterator_array_get", + "rna_Mesh_polygons_length", + "rna_Mesh_polygons_lookup_int", + NULL, + NULL); RNA_def_property_struct_type(prop, "MeshPolygon"); RNA_def_property_override_flag(prop, PROPOVERRIDE_IGNORE); RNA_def_property_ui_text(prop, "Polygons", "Polygons of the mesh"); diff --git a/source/blender/makesrna/intern/rna_mesh_api.c b/source/blender/makesrna/intern/rna_mesh_api.c index 8447074a3ef..7551f9d7096 100644 --- a/source/blender/makesrna/intern/rna_mesh_api.c +++ b/source/blender/makesrna/intern/rna_mesh_api.c @@ -44,7 +44,7 @@ static const char *rna_Mesh_unit_test_compare(struct Mesh *mesh, static void rna_Mesh_create_normals_split(Mesh *mesh) { if (!CustomData_has_layer(&mesh->ldata, CD_NORMAL)) { - CustomData_add_layer(&mesh->ldata, CD_NORMAL, CD_CALLOC, NULL, mesh->totloop); + CustomData_add_layer(&mesh->ldata, CD_NORMAL, CD_SET_DEFAULT, NULL, mesh->totloop); CustomData_set_layer_flag(&mesh->ldata, CD_NORMAL, CD_FLAG_TEMPORARY); } } @@ -64,7 +64,7 @@ static void rna_Mesh_calc_tangents(Mesh *mesh, ReportList *reports, const char * } else { r_looptangents = CustomData_add_layer( - &mesh->ldata, CD_MLOOPTANGENT, CD_CALLOC, NULL, mesh->totloop); + &mesh->ldata, CD_MLOOPTANGENT, CD_SET_DEFAULT, NULL, mesh->totloop); CustomData_set_layer_flag(&mesh->ldata, CD_MLOOPTANGENT, CD_FLAG_TEMPORARY); } @@ -90,11 +90,11 @@ static void rna_Mesh_calc_smooth_groups( Mesh *mesh, bool use_bitflags, int *r_poly_group_len, int **r_poly_group, int *r_group_total) { *r_poly_group_len = mesh->totpoly; - *r_poly_group = BKE_mesh_calc_smoothgroups(mesh->medge, + *r_poly_group = BKE_mesh_calc_smoothgroups(BKE_mesh_edges(mesh), mesh->totedge, - mesh->mpoly, + BKE_mesh_polys(mesh), mesh->totpoly, - mesh->mloop, + BKE_mesh_loops(mesh), mesh->totloop, r_group_total, use_bitflags); @@ -102,10 +102,10 @@ static void rna_Mesh_calc_smooth_groups( static void rna_Mesh_normals_split_custom_do(Mesh *mesh, float (*custom_loopnors)[3], - const bool use_vertices) + const bool use_verts) { - if (use_vertices) { - BKE_mesh_set_custom_normals_from_vertices(mesh, custom_loopnors); + if (use_verts) { + BKE_mesh_set_custom_normals_from_verts(mesh, custom_loopnors); } else { BKE_mesh_set_custom_normals(mesh, custom_loopnors); @@ -165,7 +165,8 @@ static void rna_Mesh_transform(Mesh *mesh, float mat[16], bool shape_keys) static void rna_Mesh_flip_normals(Mesh *mesh) { - BKE_mesh_polygons_flip(mesh->mpoly, mesh->mloop, &mesh->ldata, mesh->totpoly); + BKE_mesh_polys_flip( + BKE_mesh_polys(mesh), BKE_mesh_loops_for_write(mesh), &mesh->ldata, mesh->totpoly); BKE_mesh_tessface_clear(mesh); BKE_mesh_normals_tag_dirty(mesh); BKE_mesh_runtime_clear_geometry(mesh); diff --git a/source/blender/makesrna/intern/rna_mesh_utils.h b/source/blender/makesrna/intern/rna_mesh_utils.h index 0b1a8ddcb4d..495c58d7b30 100644 --- a/source/blender/makesrna/intern/rna_mesh_utils.h +++ b/source/blender/makesrna/intern/rna_mesh_utils.h @@ -81,7 +81,7 @@ layer++, a++) { \ if (value.data == layer) { \ CustomData_set_layer_##active_type(data, layer_type, a); \ - BKE_mesh_update_customdata_pointers(me, true); \ + BKE_mesh_tessface_clear(me); \ return; \ } \ } \ @@ -105,6 +105,6 @@ CustomData *data = rna_mesh_##customdata_type(ptr); \ if (data) { \ CustomData_set_layer_##active_type(data, layer_type, value); \ - BKE_mesh_update_customdata_pointers(me, true); \ + BKE_mesh_tessface_clear(me); \ } \ } diff --git a/source/blender/makesrna/intern/rna_meta.c b/source/blender/makesrna/intern/rna_meta.c index e6cf743e167..75188f29fac 100644 --- a/source/blender/makesrna/intern/rna_meta.c +++ b/source/blender/makesrna/intern/rna_meta.c @@ -81,18 +81,16 @@ static void rna_MetaBall_redraw_data(Main *UNUSED(bmain), Scene *UNUSED(scene), WM_main_add_notifier(NC_GEOM | ND_DATA, id); } -static void rna_MetaBall_update_data(Main *bmain, Scene *scene, PointerRNA *ptr) +static void rna_MetaBall_update_data(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr) { MetaBall *mb = (MetaBall *)ptr->owner_id; - Object *ob; - /* cheating way for importers to avoid slow updates */ + /* NOTE: The check on the number of users allows to avoid many repetitive (slow) updates in some + * cases, like e.g. importers. Calling `BKE_mball_properties_copy` on an obdata with no users + * would be meaningless anyway, as by definition it would not be used by any object, so not part + * of any meta-ball group. */ if (mb->id.us > 0) { - for (ob = bmain->objects.first; ob; ob = ob->id.next) { - if (ob->data == mb) { - BKE_mball_properties_copy(scene, ob); - } - } + BKE_mball_properties_copy(bmain, mb); DEG_id_tag_update(&mb->id, 0); WM_main_add_notifier(NC_GEOM | ND_DATA, mb); diff --git a/source/blender/makesrna/intern/rna_meta_api.c b/source/blender/makesrna/intern/rna_meta_api.c index 6595c811abc..1f8748143e3 100644 --- a/source/blender/makesrna/intern/rna_meta_api.c +++ b/source/blender/makesrna/intern/rna_meta_api.c @@ -28,7 +28,7 @@ static void rna_Meta_transform(struct MetaBall *mb, float mat[16]) static void rna_Mball_update_gpu_tag(MetaBall *mb) { - BKE_mball_batch_cache_dirty_tag(mb, BKE_MBALL_BATCH_DIRTY_ALL); + DEG_id_tag_update(&mb->id, ID_RECALC_SHADING); } #else diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index 8591d4abd63..c5da15003e1 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -725,6 +725,11 @@ static void rna_Modifier_name_set(PointerRNA *ptr, const char *value) BKE_animdata_fix_paths_rename_all(NULL, "modifiers", oldname, md->name); } +static void rna_Modifier_name_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *UNUSED(ptr)) +{ + DEG_relations_tag_update(bmain); +} + static char *rna_Modifier_path(const PointerRNA *ptr) { const ModifierData *md = ptr->data; @@ -4993,7 +4998,7 @@ static void rna_def_modifier_weightvg_mask(BlenderRNA *UNUSED(brna), 0, "Object", "Use local generated coordinates of another object"}, - {MOD_DISP_MAP_UV, "UV", 0, "UV", "Use coordinates from an UV layer"}, + {MOD_DISP_MAP_UV, "UV", 0, "UV", "Use coordinates from a UV layer"}, {0, NULL, 0, NULL, NULL}, }; @@ -7243,12 +7248,13 @@ void RNA_def_modifier(BlenderRNA *brna) RNA_def_struct_refine_func(srna, "rna_Modifier_refine"); RNA_def_struct_path_func(srna, "rna_Modifier_path"); RNA_def_struct_sdna(srna, "ModifierData"); + RNA_def_struct_ui_icon(srna, ICON_MODIFIER); /* strings */ prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Modifier_name_set"); RNA_def_property_ui_text(prop, "Name", "Modifier name"); - RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER | NA_RENAME, NULL); + RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER | NA_RENAME, "rna_Modifier_name_update"); RNA_def_struct_name_property(srna, prop); /* enums */ diff --git a/source/blender/makesrna/intern/rna_nla.c b/source/blender/makesrna/intern/rna_nla.c index 978a94ca7b0..524e3134f9c 100644 --- a/source/blender/makesrna/intern/rna_nla.c +++ b/source/blender/makesrna/intern/rna_nla.c @@ -83,9 +83,6 @@ const EnumPropertyItem rna_enum_nla_mode_extend_items[] = { # include "DEG_depsgraph.h" # include "DEG_depsgraph_build.h" -/* temp constant defined for these funcs only... */ -# define NLASTRIP_MIN_LEN_THRESH 0.1f - static void rna_NlaStrip_name_set(PointerRNA *ptr, const char *value) { NlaStrip *data = (NlaStrip *)ptr->data; @@ -165,75 +162,181 @@ static void rna_NlaStrip_transform_update(Main *bmain, Scene *scene, PointerRNA static void rna_NlaStrip_start_frame_set(PointerRNA *ptr, float value) { + /* Simply set the frame start in a valid range : if there are any NLA strips before/after, clamp + * the start value. If the new start value is past-the-end, clamp it. Otherwise, set it. + * + * NOTE: Unless neighboring strips are transitions, NLASTRIP_MIN_LEN_THRESH is not needed, as + * strips can be 'glued' to one another. If they are however, ensure transitions have a bit of + * time allotted in order to be performed. + */ NlaStrip *data = (NlaStrip *)ptr->data; - /* Clamp value to lie within valid limits: - * - Cannot start past the end of the strip + some flexibility threshold. - * - Cannot start before the previous strip (if present) ends. - * -> But if it was a transition, - * we could go up to the start of the strip + some flexibility threshold. - * as long as we re-adjust the transition afterwards. - * - Minimum frame is -MAXFRAME so that we don't get clipping on frame 0. - */ - if (data->prev) { - if (data->prev->type == NLASTRIP_TYPE_TRANSITION) { - CLAMP( - value, data->prev->start + NLASTRIP_MIN_LEN_THRESH, data->end - NLASTRIP_MIN_LEN_THRESH); + const float limit_prev = BKE_nlastrip_compute_frame_from_previous_strip(data); + const float limit_next = BKE_nlastrip_compute_frame_to_next_strip(data); + CLAMP(value, limit_prev, limit_next); - /* re-adjust the transition to stick to the endpoints of the action-clips */ - data->prev->end = value; - } - else { - CLAMP(value, data->prev->end, data->end - NLASTRIP_MIN_LEN_THRESH); + data->start = value; + + /* The ONLY case where we actively modify the value set by the user, is in case the start value + * value is past the old end frame (here delta = NLASTRIP_MIN_LEN_THRESH) : + * - if there's no "room" for the end frame to be placed at (new_start + delta), move old_end to + * the limit, and new_start to (limit - delta) + * - otherwise, do _not_ change the end frame. This property is not accessible from the UI, and + * can only be set via scripts. The script should be responsible of setting the end frame. + */ + if (data->start > (data->end - NLASTRIP_MIN_LEN_THRESH)) { + /* If past-the-allowed-end : */ + if ((data->start + NLASTRIP_MIN_LEN_THRESH) > limit_next) { + data->end = limit_next; + data->start = data->end - NLASTRIP_MIN_LEN_THRESH; } } - else { - CLAMP(value, MINAFRAME, data->end); + + /* Ensure transitions are kept 'glued' to the strip : */ + if (data->prev && data->prev->type == NLASTRIP_TYPE_TRANSITION) { + data->prev->end = data->start; } +} + +static void rna_NlaStrip_frame_start_ui_set(PointerRNA *ptr, float value) +{ + NlaStrip *data = (NlaStrip *)ptr->data; + + /* Changing the NLA strip's start frame is exactly the same as translating it in the NLA editor. + * When 'translating' the clip, the length of it should stay identical. Se we also need to set + * this strip's end frame after modifying its start (to `start + (old_end - old_start)`). + * Of course, we might have a few other strips on this NLA track, so we have to respect the + * previous strip's end frame. + * + * Also, different types of NLA strips (*_CLIP, *_TRANSITION, *_META, *_SOUND) have their own + * properties to respect. Needs testing on a real-world use case for the transition, meta, and + * sound types. + */ + + /* The strip's total length before modifying it & also how long we'd like it to be afterwards. */ + const float striplen = data->end - data->start; + + /* We're only modifying one strip at a time. The start and end times of its neighbors should not + * change. As such, here are the 'bookends' (frame limits) for the start position to respect : + * - if a next strip exists, don't allow the strip to start after (next->end - striplen - delta), + * (delta being the min length of a Nla Strip : the NLASTRIP_MIN_THRESH macro) + * - if a previous strip exists, don't allow this strip to start before it (data->prev) ends + * - otherwise, limit to the program limit macros defined in DNA_scene_types.h : {MINA|MAX}FRAMEF + */ + const float limit_prev = BKE_nlastrip_compute_frame_from_previous_strip(data); + const float limit_next = BKE_nlastrip_compute_frame_to_next_strip(data) - striplen; + /* For above : we want to be able to fit the entire strip before the next frame limit, so shift + * the next limit by 'striplen' no matter the context. */ + + CLAMP(value, limit_prev, limit_next); data->start = value; + + if (data->type != NLASTRIP_TYPE_TRANSITION) { + data->end = data->start + striplen; + } + + /* Update properties of the prev/next strips if they are transitions to ensure consistency : */ + if (data->prev && data->prev->type == NLASTRIP_TYPE_TRANSITION) { + data->prev->end = data->start; + } + if (data->next && data->next->type == NLASTRIP_TYPE_TRANSITION) { + data->next->start = data->end; + } } static void rna_NlaStrip_end_frame_set(PointerRNA *ptr, float value) { NlaStrip *data = (NlaStrip *)ptr->data; + const float limit_prev = BKE_nlastrip_compute_frame_from_previous_strip(data); + const float limit_next = BKE_nlastrip_compute_frame_to_next_strip(data); + CLAMP(value, limit_prev, limit_next); + + data->end = value; + + /* The ONLY case where we actively modify the value set by the user, is in case the start value + * value is past the old end frame (here delta = NLASTRIP_MIN_LEN_THRESH): + * - if there's no "room" for the end frame to be placed at (new_start + delta), move old_end to + * the limit, and new_start to (limit - delta) + * - otherwise, do _not_ change the end frame. This property is not accessible from the UI, and + * can only be set via scripts. The script should be responsible for setting the end frame. + */ + if (data->end < (data->start + NLASTRIP_MIN_LEN_THRESH)) { + /* If before-the-allowed-start : */ + if ((data->end - NLASTRIP_MIN_LEN_THRESH) < limit_prev) { + data->start = limit_prev; + data->end = data->start + NLASTRIP_MIN_LEN_THRESH; + } + } + + /* Ensure transitions are kept "glued" to the strip: */ + if (data->next && data->next->type == NLASTRIP_TYPE_TRANSITION) { + data->next->start = data->end; + } +} + +static void rna_NlaStrip_frame_end_ui_set(PointerRNA *ptr, float value) +{ + NlaStrip *data = (NlaStrip *)ptr->data; + + /* Changing the strip's end frame will update its action 'range' (defined by actstart->actend) to + * accommodate the extra length of the strip. No other parameters of the strip will change. But + * this means we have to get the current strip's end frame right now : + */ + const float old_strip_end = data->end; + /* clamp value to lie within valid limits * - must not have zero or negative length strip, so cannot start before the first frame * + some minimum-strip-length threshold * - cannot end later than the start of the next strip (if present) - * -> but if it was a transition, - * we could go up to the start of the end - some flexibility threshold - * as long as we re-adjust the transition afterwards + * -> relies on the BKE_nlastrip_compute_frame_to_next_strip() function */ - if (data->next) { - if (data->next->type == NLASTRIP_TYPE_TRANSITION) { - CLAMP( - value, data->start + NLASTRIP_MIN_LEN_THRESH, data->next->end - NLASTRIP_MIN_LEN_THRESH); + const float limit_prev = data->start + NLASTRIP_MIN_LEN_THRESH; + const float limit_next = BKE_nlastrip_compute_frame_to_next_strip(data); - /* readjust the transition to stick to the endpoints of the action-clips */ - data->next->start = value; - } - else { - CLAMP(value, data->start + NLASTRIP_MIN_LEN_THRESH, data->next->start); - } - } - else { - CLAMP(value, data->start + NLASTRIP_MIN_LEN_THRESH, MAXFRAME); - } + CLAMP(value, limit_prev, limit_next); data->end = value; - /* calculate the lengths the strip and its action (if applicable) */ - if (data->type == NLASTRIP_TYPE_CLIP) { - float len, actlen; + /* Only adjust transitions at this stage : */ + if (data->next && data->next->type == NLASTRIP_TYPE_TRANSITION) { + data->next->start = value; + } - len = data->end - data->start; - actlen = data->actend - data->actstart; + /* calculate the lengths the strip and its action : * + * (Meta and transitions shouldn't be updated, but clip and sound should) */ + if (data->type == NLASTRIP_TYPE_CLIP || data->type == NLASTRIP_TYPE_SOUND) { + float actlen = data->actend - data->actstart; if (IS_EQF(actlen, 0.0f)) { - actlen = 1.0f; + actlen = 1.0f; /* Only sanity check needed : we use this as divisor later on. */ } - /* now, adjust the 'scale' setting to reflect this (so that this change can be valid) */ - data->scale = len / ((actlen)*data->repeat); + /* Modify the strip's action end frame, or repeat based on : + * - if data->repeat == 1.0f, modify the action end frame : + * - if the number of frames to subtract is the number of frames, set the action end frame + * to the action start + 1 and modify the end of the strip to add that frame + * - if the number of frames + * - otherwise, modify the repeat property to accommodate for the new length + */ + float action_length_delta = (old_strip_end - data->end) / data->scale; + /* If no repeats are used, then modify the action end frame : */ + if (IS_EQF(data->repeat, 1.0f)) { + /* If they're equal, strip has been reduced by the same amount as the whole strip length, so + * clamp the action clip length to 1 frame, and add a frame to end so that len(strip)!=0 :*/ + if (IS_EQF(action_length_delta, actlen)) { + data->actend = data->actstart + 1.0f; + data->end += 1.0f; + } + else if (action_length_delta < actlen) { + /* Now, adjust the new strip's actend to the value it's supposed to have : */ + data->actend = data->actend - action_length_delta; + } + /* The case where the delta is bigger than the action length should not be possible, since + * data->end is guaranteed to be clamped to data->start + threshold above. + */ + } + else { + data->repeat -= (action_length_delta / actlen); + } } } @@ -640,6 +743,31 @@ static void rna_def_nlastrip(BlenderRNA *brna) RNA_def_property_update( prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_transform_update"); + /* Strip extents, when called from UI elements : */ + prop = RNA_def_property(srna, "frame_start_ui", PROP_FLOAT, PROP_TIME); + RNA_def_property_float_sdna(prop, NULL, "start"); + RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_frame_start_ui_set", NULL); + RNA_def_property_ui_text( + prop, + "Start Frame (manipulated from UI)", + "Start frame of the NLA strip. Note: changing this value also updates the value of " + "the strip's end frame. If only the start frame should be changed, see the \"frame_start\" " + "property instead"); + RNA_def_property_update( + prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_transform_update"); + + prop = RNA_def_property(srna, "frame_end_ui", PROP_FLOAT, PROP_TIME); + RNA_def_property_float_sdna(prop, NULL, "end"); + RNA_def_property_float_funcs(prop, NULL, "rna_NlaStrip_frame_end_ui_set", NULL); + RNA_def_property_ui_text( + prop, + "End Frame (manipulated from UI)", + "End frame of the NLA strip. Note: changing this value also updates the value of " + "the strip's repeats or its action's end frame. If only the end frame should be " + "changed, see the \"frame_end\" property instead"); + RNA_def_property_update( + prop, NC_ANIMATION | ND_NLA | NA_EDITED, "rna_NlaStrip_transform_update"); + /* Blending */ prop = RNA_def_property(srna, "blend_in", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "blendin"); diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c index 65a8d8bf24a..0be1dd3117c 100644 --- a/source/blender/makesrna/intern/rna_nodetree.c +++ b/source/blender/makesrna/intern/rna_nodetree.c @@ -1267,6 +1267,20 @@ static void rna_NodeTree_active_node_set(PointerRNA *ptr, if (node && BLI_findindex(&ntree->nodes, node) != -1) { nodeSetActive(ntree, node); + + /* Handle NODE_DO_OUTPUT as well. */ + if (node->typeinfo->nclass == NODE_CLASS_OUTPUT && node->type != CMP_NODE_OUTPUT_FILE) { + /* If this node becomes the active output, the others of the same type can't be the active + * output anymore. */ + LISTBASE_FOREACH (bNode *, other_node, &ntree->nodes) { + if (other_node->type == node->type) { + other_node->flag &= ~NODE_DO_OUTPUT; + } + } + node->flag |= NODE_DO_OUTPUT; + ntreeSetOutput(ntree); + BKE_ntree_update_tag_active_output_changed(ntree); + } } else { nodeClearActive(ntree); @@ -4840,6 +4854,7 @@ static void def_math(StructRNA *srna) RNA_def_property_enum_sdna(prop, NULL, "custom1"); RNA_def_property_enum_items(prop, rna_enum_node_math_items); RNA_def_property_ui_text(prop, "Operation", ""); + RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_NODETREE); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_ShaderNode_socket_update"); prop = RNA_def_property(srna, "use_clamp", PROP_BOOLEAN, PROP_NONE); @@ -4912,6 +4927,54 @@ static void def_compare(StructRNA *srna) RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); } +static void def_sh_mix(StructRNA *srna) +{ + static const EnumPropertyItem rna_enum_mix_data_type_items[] = { + {SOCK_FLOAT, "FLOAT", 0, "Float", ""}, + {SOCK_VECTOR, "VECTOR", 0, "Vector", ""}, + {SOCK_RGBA, "RGBA", 0, "Color", ""}, + {0, NULL, 0, NULL, NULL}, + }; + + static const EnumPropertyItem rna_enum_mix_mode_items[] = { + {NODE_MIX_MODE_UNIFORM, "UNIFORM", 0, "Uniform", "Use a single factor for all components"}, + {NODE_MIX_MODE_NON_UNIFORM, "NON_UNIFORM", 0, "Non-Uniform", "Per component factor"}, + {0, NULL, 0, NULL, NULL}, + }; + + PropertyRNA *prop; + + RNA_def_struct_sdna_from(srna, "NodeShaderMix", "storage"); + + prop = RNA_def_property(srna, "data_type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, rna_enum_mix_data_type_items); + RNA_def_property_enum_default(prop, SOCK_FLOAT); + RNA_def_property_ui_text(prop, "Data Type", ""); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); + + prop = RNA_def_property(srna, "factor_mode", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, rna_enum_mix_mode_items); + RNA_def_property_enum_default(prop, NODE_MIX_MODE_UNIFORM); + RNA_def_property_ui_text(prop, "Factor Mode", ""); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); + + prop = RNA_def_property(srna, "blend_type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "blend_type"); + RNA_def_property_enum_items(prop, rna_enum_ramp_blend_items); + RNA_def_property_ui_text(prop, "Blending Mode", ""); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); + + prop = RNA_def_property(srna, "clamp_factor", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "clamp_factor", 1); + RNA_def_property_ui_text(prop, "Clamp Factor", "Clamp the factor to [0,1] range"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); + + prop = RNA_def_property(srna, "clamp_result", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "clamp_result", 1); + RNA_def_property_ui_text(prop, "Clamp Result", "Clamp the result to [0,1] range"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); +} + static void def_float_to_int(StructRNA *srna) { PropertyRNA *prop; @@ -5282,7 +5345,6 @@ static void def_sh_tex_sky(StructRNA *srna) prop = RNA_def_property(srna, "sun_elevation", PROP_FLOAT, PROP_ANGLE); RNA_def_property_ui_text(prop, "Sun Elevation", "Sun angle from horizon"); - RNA_def_property_range(prop, -M_PI_2, M_PI_2); RNA_def_property_float_default(prop, M_PI_2); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); @@ -6478,7 +6540,7 @@ static void def_sh_script(StructRNA *srna) RNA_def_function_return(func, parm); func = RNA_def_function(srna, "add_socket", "rna_ShaderNodeScript_add_socket"); - RNA_def_function_ui_description(func, "Add a socket socket"); + RNA_def_function_ui_description(func, "Add a socket"); RNA_def_function_flag(func, FUNC_USE_SELF_ID); parm = RNA_def_string(func, "name", NULL, 0, "Name", ""); RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); @@ -6489,7 +6551,7 @@ static void def_sh_script(StructRNA *srna) RNA_def_function_return(func, parm); func = RNA_def_function(srna, "remove_socket", "rna_ShaderNodeScript_remove_socket"); - RNA_def_function_ui_description(func, "Remove a socket socket"); + RNA_def_function_ui_description(func, "Remove a socket"); RNA_def_function_flag(func, FUNC_USE_SELF_ID); parm = RNA_def_pointer(func, "sock", "NodeSocket", "Socket", ""); RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED); @@ -6738,7 +6800,7 @@ static void def_cmp_set_alpha(StructRNA *srna) "REPLACE_ALPHA", 0, "Replace Alpha", - "Replace the input image's alpha channels by the alpha input value"}, + "Replace the input image's alpha channel by the alpha input value"}, {0, NULL, 0, NULL, NULL}, }; @@ -7046,10 +7108,10 @@ static void def_cmp_dilate_erode(StructRNA *srna) PropertyRNA *prop; static const EnumPropertyItem mode_items[] = { - {CMP_NODE_DILATEERODE_STEP, "STEP", 0, "Step", ""}, - {CMP_NODE_DILATEERODE_DISTANCE_THRESH, "THRESHOLD", 0, "Threshold", ""}, - {CMP_NODE_DILATEERODE_DISTANCE, "DISTANCE", 0, "Distance", ""}, - {CMP_NODE_DILATEERODE_DISTANCE_FEATHER, "FEATHER", 0, "Feather", ""}, + {CMP_NODE_DILATE_ERODE_STEP, "STEP", 0, "Step", ""}, + {CMP_NODE_DILATE_ERODE_DISTANCE_THRESHOLD, "THRESHOLD", 0, "Threshold", ""}, + {CMP_NODE_DILATE_ERODE_DISTANCE, "DISTANCE", 0, "Distance", ""}, + {CMP_NODE_DILATE_ERODE_DISTANCE_FEATHER, "FEATHER", 0, "Feather", ""}, {0, NULL, 0, NULL, NULL}, }; @@ -7066,7 +7128,7 @@ static void def_cmp_dilate_erode(StructRNA *srna) RNA_def_property_ui_text(prop, "Distance", "Distance to grow/shrink (number of iterations)"); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); - /* CMP_NODE_DILATEERODE_DISTANCE_THRESH only */ + /* CMP_NODE_DILATE_ERODE_DISTANCE_THRESH only */ prop = RNA_def_property(srna, "edge", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "custom3"); RNA_def_property_range(prop, -100, 100); @@ -7075,7 +7137,7 @@ static void def_cmp_dilate_erode(StructRNA *srna) RNA_def_struct_sdna_from(srna, "NodeDilateErode", "storage"); - /* CMP_NODE_DILATEERODE_DISTANCE_FEATHER only */ + /* CMP_NODE_DILATE_ERODE_DISTANCE_FEATHER only */ prop = RNA_def_property(srna, "falloff", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "falloff"); RNA_def_property_enum_items(prop, rna_enum_proportional_falloff_curve_only_items); @@ -8051,6 +8113,7 @@ static void def_cmp_lensdist(StructRNA *srna) prop = RNA_def_property(srna, "use_jitter", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "jit", 1); RNA_def_property_ui_text(prop, "Jitter", "Enable/disable jittering (faster, but also noisier)"); + RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_NODETREE); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); prop = RNA_def_property(srna, "use_fit", PROP_BOOLEAN, PROP_NONE); @@ -9879,6 +9942,33 @@ static void def_geo_points_to_volume(StructRNA *srna) RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); } +static void def_geo_uv_unwrap(StructRNA *srna) +{ + PropertyRNA *prop; + + static EnumPropertyItem rna_node_geometry_uv_unwrap_method_items[] = { + {GEO_NODE_UV_UNWRAP_METHOD_ANGLE_BASED, + "ANGLE_BASED", + 0, + "Angle Based", + "This method gives a good 2D representation of a mesh"}, + {GEO_NODE_UV_UNWRAP_METHOD_CONFORMAL, + "CONFORMAL", + 0, + "Conformal", + "Uses LSCM (Least Squares Conformal Mapping). This usually gives a less accurate UV " + "mapping than Angle Based, but works better for simpler objects"}, + {0, NULL, 0, NULL, NULL}, + }; + + RNA_def_struct_sdna_from(srna, "NodeGeometryUVUnwrap", "storage"); + + prop = RNA_def_property(srna, "method", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, rna_node_geometry_uv_unwrap_method_items); + RNA_def_property_ui_text(prop, "Method", ""); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update"); +} + static void def_geo_collection_info(StructRNA *srna) { PropertyRNA *prop; @@ -9970,6 +10060,32 @@ static void def_geo_volume_to_mesh(StructRNA *srna) RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); } +static void def_geo_mesh_to_volume(StructRNA *srna) +{ + PropertyRNA *prop; + + static EnumPropertyItem resolution_mode_items[] = { + {MESH_TO_VOLUME_RESOLUTION_MODE_VOXEL_AMOUNT, + "VOXEL_AMOUNT", + 0, + "Amount", + "Desired number of voxels along one axis"}, + {MESH_TO_VOLUME_RESOLUTION_MODE_VOXEL_SIZE, + "VOXEL_SIZE", + 0, + "Size", + "Desired voxel side length"}, + {0, NULL, 0, NULL, NULL}, + }; + + RNA_def_struct_sdna_from(srna, "NodeGeometryMeshToVolume", "storage"); + + prop = RNA_def_property(srna, "resolution_mode", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_items(prop, resolution_mode_items); + RNA_def_property_ui_text(prop, "Resolution Mode", "How the voxel size is specified"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_socket_update"); +} + static void def_geo_mesh_circle(StructRNA *srna) { PropertyRNA *prop; @@ -10702,6 +10818,25 @@ static void def_geo_field_at_index(StructRNA *srna) RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_GeometryNode_socket_update"); } +static void def_geo_interpolate_domain(StructRNA *srna) +{ + PropertyRNA *prop; + + prop = RNA_def_property(srna, "domain", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "custom1"); + RNA_def_property_enum_items(prop, rna_enum_attribute_domain_items); + RNA_def_property_ui_text(prop, "Domain", "Domain the field is evaluated in"); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_GeometryNode_socket_update"); + + prop = RNA_def_property(srna, "data_type", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "custom2"); + RNA_def_property_enum_items(prop, rna_enum_attribute_type_items); + RNA_def_property_enum_funcs( + prop, NULL, NULL, "rna_GeometryNodeAttributeType_type_with_socket_itemf"); + RNA_def_property_ui_text(prop, "Data Type", ""); + RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_GeometryNode_socket_update"); +} + static void def_geo_scale_elements(StructRNA *srna) { PropertyRNA *prop; @@ -10877,6 +11012,11 @@ static void rna_def_node_socket(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Linked", "True if the socket is connected"); + prop = RNA_def_property(srna, "is_unavailable", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", SOCK_UNAVAIL); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Unavailable", "True if the socket is unavailable"); + prop = RNA_def_property(srna, "is_multi_input", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", SOCK_MULTI_INPUT); RNA_def_property_clear_flag(prop, PROP_EDITABLE); @@ -11461,6 +11601,8 @@ static void rna_def_node_socket_object(BlenderRNA *brna, RNA_def_property_struct_type(prop, "Object"); RNA_def_property_ui_text(prop, "Default Value", "Input value used for unconnected socket"); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketInterface_update"); + RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT); + RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY); } static void rna_def_node_socket_image(BlenderRNA *brna, @@ -11497,6 +11639,8 @@ static void rna_def_node_socket_image(BlenderRNA *brna, RNA_def_property_struct_type(prop, "Image"); RNA_def_property_ui_text(prop, "Default Value", "Input value used for unconnected socket"); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketInterface_update"); + RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT); + RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY); } static void rna_def_node_socket_geometry(BlenderRNA *brna, @@ -11548,6 +11692,8 @@ static void rna_def_node_socket_collection(BlenderRNA *brna, RNA_def_property_struct_type(prop, "Collection"); RNA_def_property_ui_text(prop, "Default Value", "Input value used for unconnected socket"); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketInterface_update"); + RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT); + RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY); } static void rna_def_node_socket_texture(BlenderRNA *brna, @@ -11584,6 +11730,8 @@ static void rna_def_node_socket_texture(BlenderRNA *brna, RNA_def_property_struct_type(prop, "Texture"); RNA_def_property_ui_text(prop, "Default Value", "Input value used for unconnected socket"); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketInterface_update"); + RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT); + RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY); } static void rna_def_node_socket_material(BlenderRNA *brna, @@ -11624,6 +11772,8 @@ static void rna_def_node_socket_material(BlenderRNA *brna, prop, NULL, NULL, NULL, "rna_NodeSocketMaterial_default_value_poll"); RNA_def_property_ui_text(prop, "Default Value", "Input value used for unconnected socket"); RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_NodeSocketInterface_update"); + RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT); + RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY); } static void rna_def_node_socket_standard_types(BlenderRNA *brna) @@ -12318,7 +12468,7 @@ static void rna_def_nodetree_nodes_api(BlenderRNA *brna, PropertyRNA *cprop) prop, "rna_NodeTree_active_node_get", "rna_NodeTree_active_node_set", NULL, NULL); RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK); RNA_def_property_ui_text(prop, "Active Node", "Active node in this tree"); - RNA_def_property_update(prop, NC_SCENE | ND_OB_ACTIVE, NULL); + RNA_def_property_update(prop, NC_SCENE | ND_OB_ACTIVE, "rna_NodeTree_update"); } static void rna_def_nodetree_link_api(BlenderRNA *brna, PropertyRNA *cprop) diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c index 56652a35ecb..6cbc24db2d8 100644 --- a/source/blender/makesrna/intern/rna_object.c +++ b/source/blender/makesrna/intern/rna_object.c @@ -511,7 +511,7 @@ static PointerRNA rna_Object_data_get(PointerRNA *ptr) Object *ob = (Object *)ptr->data; if (ob->type == OB_MESH) { Mesh *me = (Mesh *)ob->data; - me = BKE_mesh_wrapper_ensure_subdivision(ob, me); + me = BKE_mesh_wrapper_ensure_subdivision(me); return rna_pointer_inherit_refine(ptr, &RNA_Mesh, me); } return rna_pointer_inherit_refine(ptr, &RNA_ID, ob->data); @@ -607,11 +607,7 @@ static StructRNA *rna_Object_data_typef(PointerRNA *ptr) case OB_GPENCIL: return &RNA_GreasePencil; case OB_CURVES: -# ifdef WITH_NEW_CURVES_TYPE return &RNA_Curves; -# else - return &RNA_ID; -# endif case OB_POINTCLOUD: return &RNA_PointCloud; case OB_VOLUME: @@ -691,6 +687,11 @@ static void rna_Object_parent_type_set(PointerRNA *ptr, int value) { Object *ob = (Object *)ptr->data; + /* Skip if type did not change (otherwise we loose parent inverse in ED_object_parent). */ + if (ob->partype == value) { + return; + } + ED_object_parent(ob, ob->parent, value, ob->parsubstr); } @@ -2228,7 +2229,7 @@ bool rna_GPencil_object_poll(PointerRNA *UNUSED(ptr), PointerRNA value) return ((Object *)value.owner_id)->type == OB_GPENCIL; } -int rna_Object_use_dynamic_topology_sculpting_get(PointerRNA *ptr) +bool rna_Object_use_dynamic_topology_sculpting_get(PointerRNA *ptr) { SculptSession *ss = ((Object *)ptr->owner_id)->sculpt; return (ss && ss->bm); @@ -2950,6 +2951,22 @@ static void rna_def_object_lineart(BlenderRNA *brna) RNA_def_property_ui_range(prop, 0.0f, DEG2RAD(180.0f), 0.01f, 1); RNA_def_property_ui_text(prop, "Crease", "Angles smaller than this will be treated as creases"); RNA_def_property_update(prop, 0, "rna_object_lineart_update"); + + prop = RNA_def_property(srna, "use_intersection_priority_override", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flags", OBJECT_LRT_OWN_INTERSECTION_PRIORITY); + RNA_def_property_ui_text( + prop, + "Use Intersection Priority", + "Use this object's intersection priority to override collection setting"); + RNA_def_property_update(prop, 0, "rna_object_lineart_update"); + + prop = RNA_def_property(srna, "intersection_priority", PROP_INT, PROP_NONE); + RNA_def_property_range(prop, 0, 255); + RNA_def_property_ui_text(prop, + "Intersection Priority", + "The intersection line will be included into the object with the " + "higher intersection priority value"); + RNA_def_property_update(prop, NC_GPENCIL | ND_SHADING, "rna_object_lineart_update"); } static void rna_def_object_visibility(StructRNA *srna) @@ -3563,6 +3580,14 @@ static void rna_def_object(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Empty Image Side", "Show front/back side"); RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL); + prop = RNA_def_property(srna, "add_rest_position_attribute", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "modifier_flag", OB_MODIFIER_FLAG_ADD_REST_POSITION); + RNA_def_property_ui_text(prop, + "Add Rest Position", + "Add a \"rest_position\" attribute that is a copy of the position " + "attribute before shape keys and modifiers are evaluated"); + RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_internal_update_data"); + /* render */ prop = RNA_def_property(srna, "pass_index", PROP_INT, PROP_UNSIGNED); RNA_def_property_int_sdna(prop, NULL, "index"); diff --git a/source/blender/makesrna/intern/rna_object_force.c b/source/blender/makesrna/intern/rna_object_force.c index 2ed539aa511..40000a49f03 100644 --- a/source/blender/makesrna/intern/rna_object_force.c +++ b/source/blender/makesrna/intern/rna_object_force.c @@ -1276,7 +1276,7 @@ static void rna_def_effector_weight(BlenderRNA *brna) prop = RNA_def_property(srna, "collection", PROP_POINTER, PROP_NONE); RNA_def_property_struct_type(prop, "Collection"); RNA_def_property_pointer_sdna(prop, NULL, "group"); - RNA_def_property_flag(prop, PROP_EDITABLE); + RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT); RNA_def_property_ui_text(prop, "Effector Collection", "Limit effectors to this collection"); RNA_def_property_update(prop, 0, "rna_EffectorWeight_dependency_update"); diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c index a67b0f7c8e6..40e7f6e65c2 100644 --- a/source/blender/makesrna/intern/rna_particle.c +++ b/source/blender/makesrna/intern/rna_particle.c @@ -25,6 +25,7 @@ #include "RNA_enum_types.h" #include "BKE_mesh.h" +#include "BKE_mesh_legacy_convert.h" #include "BLI_listbase.h" @@ -211,10 +212,10 @@ static void rna_ParticleHairKey_location_object_get(PointerRNA *ptr, float *valu if (pa) { Mesh *hair_mesh = (psmd->psys->flag & PSYS_HAIR_DYNAMICS) ? psmd->psys->hair_out_mesh : NULL; - + const MVert *verts = BKE_mesh_verts(hair_mesh); if (hair_mesh) { - MVert *mvert = &hair_mesh->mvert[pa->hair_index + (hkey - pa->hair)]; - copy_v3_v3(values, mvert->co); + const MVert *mv = &verts[pa->hair_index + (hkey - pa->hair)]; + copy_v3_v3(values, mv->co); } else { float hairmat[4][4]; @@ -278,9 +279,9 @@ static void hair_key_location_object_set(HairKey *hair_key, if (hair_key_index == -1) { return; } - - MVert *mvert = &hair_mesh->mvert[particle->hair_index + (hair_key_index)]; - copy_v3_v3(mvert->co, src_co); + MVert *verts = BKE_mesh_verts_for_write(hair_mesh); + MVert *mv = &verts[particle->hair_index + (hair_key_index)]; + copy_v3_v3(mv->co, src_co); return; } @@ -323,8 +324,9 @@ static void rna_ParticleHairKey_co_object(HairKey *hairkey, NULL; if (particle) { if (hair_mesh) { - MVert *mvert = &hair_mesh->mvert[particle->hair_index + (hairkey - particle->hair)]; - copy_v3_v3(n_co, mvert->co); + const MVert *verts = BKE_mesh_verts(hair_mesh); + const MVert *mv = &verts[particle->hair_index + (hairkey - particle->hair)]; + copy_v3_v3(n_co, mv->co); } else { float hairmat[4][4]; @@ -401,8 +403,8 @@ static void rna_Particle_uv_on_emitter(ParticleData *particle, MFace *mface; MTFace *mtface; - mface = modifier->mesh_final->mface; - mtface = modifier->mesh_final->mtface; + mface = CustomData_get_layer(&modifier->mesh_final->fdata, CD_MFACE); + mtface = CustomData_get_layer(&modifier->mesh_final->fdata, CD_MTFACE); if (mface && mtface) { mtface += num; @@ -566,7 +568,7 @@ static int rna_ParticleSystem_tessfaceidx_on_emitter(ParticleSystem *particlesys } else if (part->from == PART_FROM_VERT) { if (num != DMCACHE_NOTFOUND && num < totvert) { - MFace *mface = modifier->mesh_final->mface; + MFace *mface = CustomData_get_layer(&modifier->mesh_final->fdata, CD_MFACE); *r_fuv = &particle->fuv; @@ -609,7 +611,7 @@ static int rna_ParticleSystem_tessfaceidx_on_emitter(ParticleSystem *particlesys } else if (part->from == PART_FROM_VERT) { if (num != DMCACHE_NOTFOUND && num < totvert) { - MFace *mface = modifier->mesh_final->mface; + MFace *mface = CustomData_get_layer(&modifier->mesh_final->fdata, CD_MFACE); *r_fuv = &parent->fuv; @@ -659,7 +661,8 @@ static void rna_ParticleSystem_uv_on_emitter(ParticleSystem *particlesystem, zero_v2(r_uv); } else { - MFace *mface = &modifier->mesh_final->mface[num]; + MFace *mfaces = CustomData_get_layer(&modifier->mesh_final->fdata, CD_MFACE); + MFace *mface = &mfaces[num]; const MTFace *mtface = (const MTFace *)CustomData_get_layer_n( &modifier->mesh_final->fdata, CD_MTFACE, uv_no); @@ -693,7 +696,8 @@ static void rna_ParticleSystem_mcol_on_emitter(ParticleSystem *particlesystem, zero_v3(r_mcol); } else { - MFace *mface = &modifier->mesh_final->mface[num]; + MFace *mfaces = CustomData_get_layer(&modifier->mesh_final->fdata, CD_MFACE); + MFace *mface = &mfaces[num]; const MCol *mc = (const MCol *)CustomData_get_layer_n( &modifier->mesh_final->fdata, CD_MCOL, vcol_no); MCol mcol; @@ -1043,7 +1047,7 @@ static float rna_PartSetting_linelenhead_get(struct PointerRNA *ptr) return settings->draw_line[1]; } -static int rna_PartSettings_is_fluid_get(PointerRNA *ptr) +static bool rna_PartSettings_is_fluid_get(PointerRNA *ptr) { ParticleSettings *part = ptr->data; return (ELEM(part->type, @@ -2685,6 +2689,7 @@ static void rna_def_particle_settings(BlenderRNA *brna) prop = RNA_def_property(srna, "use_parent_particles", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "draw", PART_DRAW_PARENT); RNA_def_property_ui_text(prop, "Parents", "Render parent particles"); + RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_PARTICLESETTINGS); RNA_def_property_update(prop, 0, "rna_Particle_redo"); prop = RNA_def_property(srna, "show_number", PROP_BOOLEAN, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_path.cc b/source/blender/makesrna/intern/rna_path.cc new file mode 100644 index 00000000000..bc77ca3f7d3 --- /dev/null +++ b/source/blender/makesrna/intern/rna_path.cc @@ -0,0 +1,1366 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup RNA + */ + +#include <cstdlib> +#include <stdlib.h> +#include <string.h> + +#include "BLI_alloca.h" +#include "BLI_dynstr.h" +#include "BLI_listbase.h" +#include "BLI_string.h" +#include "BLI_utildefines.h" + +#include "BKE_idprop.h" +#include "BKE_idtype.h" + +#include "DNA_ID.h" /* For ID properties. */ + +#include "MEM_guardedalloc.h" + +#include "RNA_access.h" +#include "RNA_define.h" +#include "RNA_path.h" +#include "RNA_prototypes.h" + +#include "rna_access_internal.h" +#include "rna_internal.h" + +/** + * Extract the first token from `path`. + * + * \param path: Extract the token from path, step the pointer to the beginning of the next token + * \return The nil terminated token. + */ +static char *rna_path_token(const char **path, char *fixedbuf, int fixedlen) +{ + int len = 0; + + /* Get data until `.` or `[`. */ + const char *p = *path; + while (*p && !ELEM(*p, '.', '[')) { + len++; + p++; + } + + /* Empty, return. */ + if (UNLIKELY(len == 0)) { + return nullptr; + } + + /* Try to use fixed buffer if possible. */ + char *buf = (len + 1 < fixedlen) ? fixedbuf : + (char *)MEM_mallocN(sizeof(char) * (len + 1), __func__); + memcpy(buf, *path, sizeof(char) * len); + buf[len] = '\0'; + + if (*p == '.') { + p++; + } + *path = p; + + return buf; +} + +/** + * Extract the first token in brackets from `path` (with quoted text support). + * + * - `[0]` -> `0` + * - `["Some\"Quote"]` -> `Some"Quote` + * + * \param path: Extract the token from path, step the pointer to the beginning of the next token + * (past quoted text and brackets). + * \return The nil terminated token. + */ +static char *rna_path_token_in_brackets(const char **path, + char *fixedbuf, + int fixedlen, + bool *r_quoted) +{ + int len = 0; + bool quoted = false; + + BLI_assert(r_quoted != nullptr); + + /* Get data between `[]`, check escaping quotes and back-slashes with #BLI_str_unescape. */ + if (UNLIKELY(**path != '[')) { + return nullptr; + } + + (*path)++; + const char *p = *path; + + /* 2 kinds of look-ups now, quoted or unquoted. */ + if (*p == '"') { + /* Find the matching quote. */ + (*path)++; + p = *path; + const char *p_end = BLI_str_escape_find_quote(p); + if (p_end == nullptr) { + /* No Matching quote. */ + return nullptr; + } + /* Exclude the last quote from the length. */ + len += (p_end - p); + + /* Skip the last quoted char to get the `]`. */ + p_end += 1; + p = p_end; + quoted = true; + } + else { + /* Find the matching bracket. */ + while (*p && (*p != ']')) { + len++; + p++; + } + } + + if (UNLIKELY(*p != ']')) { + return nullptr; + } + + /* Empty, return. */ + if (UNLIKELY(len == 0)) { + return nullptr; + } + + /* Try to use fixed buffer if possible. */ + char *buf = (len + 1 < fixedlen) ? fixedbuf : + (char *)MEM_mallocN(sizeof(char) * (len + 1), __func__); + + /* Copy string, taking into account escaped ']' */ + if (quoted) { + BLI_str_unescape(buf, *path, len); + /* +1 to step over the last quote. */ + BLI_assert((*path)[len] == '"'); + p = (*path) + len + 1; + } + else { + memcpy(buf, *path, sizeof(char) * len); + buf[len] = '\0'; + } + /* Set path to start of next token. */ + if (*p == ']') { + p++; + } + if (*p == '.') { + p++; + } + *path = p; + + *r_quoted = quoted; + + return buf; +} + +/** + * \return true when the key in the path is correctly parsed and found in the collection + * or when the path is empty. + */ +static bool rna_path_parse_collection_key(const char **path, + PointerRNA *ptr, + PropertyRNA *prop, + PointerRNA *r_nextptr) +{ + char fixedbuf[256]; + int intkey; + + *r_nextptr = *ptr; + + /* end of path, ok */ + if (!(**path)) { + return true; + } + + bool found = false; + if (**path == '[') { + bool quoted; + char *token; + + /* resolve the lookup with [] brackets */ + token = rna_path_token_in_brackets(path, fixedbuf, sizeof(fixedbuf), "ed); + + if (!token) { + return false; + } + + /* check for "" to see if it is a string */ + if (quoted) { + if (RNA_property_collection_lookup_string(ptr, prop, token, r_nextptr)) { + found = true; + } + else { + r_nextptr->data = nullptr; + } + } + else { + /* otherwise do int lookup */ + intkey = atoi(token); + if (intkey == 0 && (token[0] != '0' || token[1] != '\0')) { + return false; /* we can be sure the fixedbuf was used in this case */ + } + if (RNA_property_collection_lookup_int(ptr, prop, intkey, r_nextptr)) { + found = true; + } + else { + r_nextptr->data = nullptr; + } + } + + if (token != fixedbuf) { + MEM_freeN(token); + } + } + else { + if (RNA_property_collection_type_get(ptr, prop, r_nextptr)) { + found = true; + } + else { + /* ensure we quit on invalid values */ + r_nextptr->data = nullptr; + } + } + + return found; +} + +static bool rna_path_parse_array_index(const char **path, + PointerRNA *ptr, + PropertyRNA *prop, + int *r_index) +{ + char fixedbuf[256]; + int index_arr[RNA_MAX_ARRAY_DIMENSION] = {0}; + int len[RNA_MAX_ARRAY_DIMENSION]; + const int dim = RNA_property_array_dimension(ptr, prop, len); + int i; + + *r_index = -1; + + /* end of path, ok */ + if (!(**path)) { + return true; + } + + for (i = 0; i < dim; i++) { + int temp_index = -1; + char *token; + + /* multi index resolve */ + if (**path == '[') { + bool quoted; + token = rna_path_token_in_brackets(path, fixedbuf, sizeof(fixedbuf), "ed); + + if (token == nullptr) { + /* invalid syntax blah[] */ + return false; + } + /* check for "" to see if it is a string */ + if (quoted) { + temp_index = RNA_property_array_item_index(prop, *token); + } + else { + /* otherwise do int lookup */ + temp_index = atoi(token); + + if (temp_index == 0 && (token[0] != '0' || token[1] != '\0')) { + if (token != fixedbuf) { + MEM_freeN(token); + } + + return false; + } + } + } + else if (dim == 1) { + /* location.x || scale.X, single dimension arrays only */ + token = rna_path_token(path, fixedbuf, sizeof(fixedbuf)); + if (token == nullptr) { + /* invalid syntax blah. */ + return false; + } + temp_index = RNA_property_array_item_index(prop, *token); + } + else { + /* just to avoid uninitialized pointer use */ + token = fixedbuf; + } + + if (token != fixedbuf) { + MEM_freeN(token); + } + + /* out of range */ + if (temp_index < 0 || temp_index >= len[i]) { + return false; + } + + index_arr[i] = temp_index; + /* end multi index resolve */ + } + + /* arrays always contain numbers so further values are not valid */ + if (**path) { + return false; + } + + /* flatten index over all dimensions */ + { + int totdim = 1; + int flat_index = 0; + + for (i = dim - 1; i >= 0; i--) { + flat_index += index_arr[i] * totdim; + totdim *= len[i]; + } + + *r_index = flat_index; + } + return true; +} + +/** + * Generic rna path parser. + * + * \note All parameters besides \a ptr and \a path are optional. + * + * \param ptr: The root of given RNA path. + * \param path: The RNA path. + * \param r_ptr: The final RNA data holding the last property in \a path. + * \param r_prop: The final property of \a r_ptr, from \a path. + * \param r_index: The final index in the \a r_prop, if defined by \a path. + * \param r_item_ptr: Only valid for Pointer and Collection, return the actual value of the + * pointer, or of the collection item. + * Mutually exclusive with \a eval_pointer option. + * \param r_elements: A list of \a PropertyElemRNA items(pairs of \a PointerRNA, \a PropertyRNA + * that represent the whole given \a path). + * \param eval_pointer: If \a true, and \a path leads to a Pointer property, or an item in a + * Collection property, \a r_ptr will be set to the value of that property, + * and \a r_prop will be NULL. + * Mutually exclusive with \a r_item_ptr. + * + * \return \a true on success, \a false if the path is somehow invalid. + */ +static bool rna_path_parse(const PointerRNA *ptr, + const char *path, + PointerRNA *r_ptr, + PropertyRNA **r_prop, + int *r_index, + PointerRNA *r_item_ptr, + ListBase *r_elements, + const bool eval_pointer) +{ + BLI_assert(r_item_ptr == nullptr || !eval_pointer); + PropertyRNA *prop; + PointerRNA curptr, nextptr; + PropertyElemRNA *prop_elem = nullptr; + int index = -1; + char fixedbuf[256]; + int type; + const bool do_item_ptr = r_item_ptr != nullptr && !eval_pointer; + + if (do_item_ptr) { + RNA_POINTER_INVALIDATE(&nextptr); + } + + prop = nullptr; + curptr = *ptr; + + if (path == nullptr || *path == '\0') { + return false; + } + + while (*path) { + if (do_item_ptr) { + RNA_POINTER_INVALIDATE(&nextptr); + } + + const bool use_id_prop = (*path == '['); + /* Custom property lookup: e.g. `C.object["someprop"]`. */ + + if (!curptr.data) { + return false; + } + + /* look up property name in current struct */ + bool quoted = false; + char *token = use_id_prop ? + rna_path_token_in_brackets(&path, fixedbuf, sizeof(fixedbuf), "ed) : + rna_path_token(&path, fixedbuf, sizeof(fixedbuf)); + if (!token) { + return false; + } + + prop = nullptr; + if (use_id_prop) { /* look up property name in current struct */ + IDProperty *group = RNA_struct_idprops(&curptr, 0); + if (group && quoted) { + prop = (PropertyRNA *)IDP_GetPropertyFromGroup(group, token); + } + } + else { + prop = RNA_struct_find_property(&curptr, token); + } + + if (token != fixedbuf) { + MEM_freeN(token); + } + + if (!prop) { + return false; + } + + if (r_elements) { + prop_elem = MEM_cnew<PropertyElemRNA>(__func__); + prop_elem->ptr = curptr; + prop_elem->prop = prop; + prop_elem->index = -1; /* index will be added later, if needed. */ + BLI_addtail(r_elements, prop_elem); + } + + type = RNA_property_type(prop); + + /* now look up the value of this property if it is a pointer or + * collection, otherwise return the property rna so that the + * caller can read the value of the property itself */ + switch (type) { + case PROP_POINTER: { + /* resolve pointer if further path elements follow + * or explicitly requested + */ + if (do_item_ptr || eval_pointer || *path != '\0') { + nextptr = RNA_property_pointer_get(&curptr, prop); + } + + if (eval_pointer || *path != '\0') { + curptr = nextptr; + prop = nullptr; /* now we have a PointerRNA, the prop is our parent so forget it */ + index = -1; + } + break; + } + case PROP_COLLECTION: { + /* Resolve pointer if further path elements follow. + * Note that if path is empty, rna_path_parse_collection_key will do nothing anyway, + * so do_item_ptr is of no use in that case. + */ + if (*path) { + if (!rna_path_parse_collection_key(&path, &curptr, prop, &nextptr)) { + return false; + } + + if (eval_pointer || *path != '\0') { + curptr = nextptr; + prop = nullptr; /* now we have a PointerRNA, the prop is our parent so forget it */ + index = -1; + } + } + break; + } + default: + if (r_index || prop_elem) { + if (!rna_path_parse_array_index(&path, &curptr, prop, &index)) { + return false; + } + + if (prop_elem) { + prop_elem->index = index; + } + } + break; + } + } + + if (r_ptr) { + *r_ptr = curptr; + } + if (r_prop) { + *r_prop = prop; + } + if (r_index) { + *r_index = index; + } + if (r_item_ptr && do_item_ptr) { + *r_item_ptr = nextptr; + } + + if (prop_elem && (prop_elem->ptr.data != curptr.data || prop_elem->prop != prop || + prop_elem->index != index)) { + prop_elem = MEM_cnew<PropertyElemRNA>(__func__); + prop_elem->ptr = curptr; + prop_elem->prop = prop; + prop_elem->index = index; + BLI_addtail(r_elements, prop_elem); + } + + return true; +} + +bool RNA_path_resolve(const PointerRNA *ptr, + const char *path, + PointerRNA *r_ptr, + PropertyRNA **r_prop) +{ + if (!rna_path_parse(ptr, path, r_ptr, r_prop, nullptr, nullptr, nullptr, true)) { + return false; + } + + return r_ptr->data != nullptr; +} + +bool RNA_path_resolve_full( + const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index) +{ + if (!rna_path_parse(ptr, path, r_ptr, r_prop, r_index, nullptr, nullptr, true)) { + return false; + } + + return r_ptr->data != nullptr; +} + +bool RNA_path_resolve_full_maybe_null( + const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index) +{ + return rna_path_parse(ptr, path, r_ptr, r_prop, r_index, nullptr, nullptr, true); +} + +bool RNA_path_resolve_property(const PointerRNA *ptr, + const char *path, + PointerRNA *r_ptr, + PropertyRNA **r_prop) +{ + if (!rna_path_parse(ptr, path, r_ptr, r_prop, nullptr, nullptr, nullptr, false)) { + return false; + } + + return r_ptr->data != nullptr && *r_prop != nullptr; +} + +bool RNA_path_resolve_property_full( + const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop, int *r_index) +{ + if (!rna_path_parse(ptr, path, r_ptr, r_prop, r_index, nullptr, nullptr, false)) { + return false; + } + + return r_ptr->data != nullptr && *r_prop != nullptr; +} + +bool RNA_path_resolve_property_and_item_pointer(const PointerRNA *ptr, + const char *path, + PointerRNA *r_ptr, + PropertyRNA **r_prop, + PointerRNA *r_item_ptr) +{ + if (!rna_path_parse(ptr, path, r_ptr, r_prop, nullptr, r_item_ptr, nullptr, false)) { + return false; + } + + return r_ptr->data != nullptr && *r_prop != nullptr; +} + +bool RNA_path_resolve_property_and_item_pointer_full(const PointerRNA *ptr, + const char *path, + PointerRNA *r_ptr, + PropertyRNA **r_prop, + int *r_index, + PointerRNA *r_item_ptr) +{ + if (!rna_path_parse(ptr, path, r_ptr, r_prop, r_index, r_item_ptr, nullptr, false)) { + return false; + } + + return r_ptr->data != nullptr && *r_prop != nullptr; +} +bool RNA_path_resolve_elements(PointerRNA *ptr, const char *path, ListBase *r_elements) +{ + return rna_path_parse(ptr, path, nullptr, nullptr, nullptr, nullptr, r_elements, false); +} + +char *RNA_path_append(const char *path, + const PointerRNA *UNUSED(ptr), + PropertyRNA *prop, + int intkey, + const char *strkey) +{ + DynStr *dynstr; + char *result; + + dynstr = BLI_dynstr_new(); + + /* add .identifier */ + if (path) { + BLI_dynstr_append(dynstr, path); + if (*path) { + BLI_dynstr_append(dynstr, "."); + } + } + + BLI_dynstr_append(dynstr, RNA_property_identifier(prop)); + + const bool has_key = (intkey > -1) || (strkey != nullptr); + if (has_key && (RNA_property_type(prop) == PROP_COLLECTION)) { + /* add ["strkey"] or [intkey] */ + BLI_dynstr_append(dynstr, "["); + + if (strkey) { + const int strkey_esc_max_size = (strlen(strkey) * 2) + 1; + char *strkey_esc = static_cast<char *>(BLI_array_alloca(strkey_esc, strkey_esc_max_size)); + BLI_str_escape(strkey_esc, strkey, strkey_esc_max_size); + BLI_dynstr_append(dynstr, "\""); + BLI_dynstr_append(dynstr, strkey_esc); + BLI_dynstr_append(dynstr, "\""); + } + else { + char appendstr[128]; + BLI_snprintf(appendstr, sizeof(appendstr), "%d", intkey); + BLI_dynstr_append(dynstr, appendstr); + } + + BLI_dynstr_append(dynstr, "]"); + } + + result = BLI_dynstr_get_cstring(dynstr); + BLI_dynstr_free(dynstr); + + return result; +} + +/* Having both path append & back seems like it could be useful, + * this function isn't used at the moment. */ +static UNUSED_FUNCTION_WITH_RETURN_TYPE(char *, RNA_path_back)(const char *path) +{ + char fixedbuf[256]; + const char *previous, *current; + char *result; + int i; + + if (!path) { + return nullptr; + } + + previous = nullptr; + current = path; + + /* parse token by token until the end, then we back up to the previous + * position and strip of the next token to get the path one step back */ + while (*current) { + char *token; + + token = rna_path_token(¤t, fixedbuf, sizeof(fixedbuf)); + + if (!token) { + return nullptr; + } + if (token != fixedbuf) { + MEM_freeN(token); + } + + /* in case of collection we also need to strip off [] */ + bool quoted; + token = rna_path_token_in_brackets(¤t, fixedbuf, sizeof(fixedbuf), "ed); + if (token && token != fixedbuf) { + MEM_freeN(token); + } + + if (!*current) { + break; + } + + previous = current; + } + + if (!previous) { + return nullptr; + } + + /* copy and strip off last token */ + i = previous - path; + result = BLI_strdup(path); + + if (i > 0 && result[i - 1] == '.') { + i--; + } + result[i] = 0; + + return result; +} + +const char *RNA_path_array_index_token_find(const char *rna_path, const PropertyRNA *array_prop) +{ + if (array_prop != nullptr) { + if (!ELEM(array_prop->type, PROP_BOOLEAN, PROP_INT, PROP_FLOAT)) { + BLI_assert(array_prop->arraydimension == 0); + return nullptr; + } + if (array_prop->arraydimension == 0) { + return nullptr; + } + } + + /* Valid 'array part' of a rna path can only have '[', ']' and digit characters. + * It may have more than one of those (e.g. `[12][1]`) in case of multi-dimensional arrays. */ + if (UNLIKELY(rna_path[0] == '\0')) { + return nullptr; + } + size_t rna_path_len = (size_t)strlen(rna_path) - 1; + if (rna_path[rna_path_len] != ']') { + return nullptr; + } + + const char *last_valid_index_token_start = nullptr; + while (rna_path_len--) { + switch (rna_path[rna_path_len]) { + case '[': + if (rna_path_len <= 0 || rna_path[rna_path_len - 1] != ']') { + return &rna_path[rna_path_len]; + } + last_valid_index_token_start = &rna_path[rna_path_len]; + rna_path_len--; + break; + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + break; + default: + return last_valid_index_token_start; + } + } + return last_valid_index_token_start; +} + +/* generic path search func + * if its needed this could also reference the IDProperty direct */ +typedef struct IDP_Chain { + struct IDP_Chain *up; /* parent member, reverse and set to child for path conversion. */ + + const char *name; + int index; + +} IDP_Chain; + +static char *rna_idp_path_create(IDP_Chain *child_link) +{ + DynStr *dynstr = BLI_dynstr_new(); + char *path; + bool is_first = true; + + int tot = 0; + IDP_Chain *link = child_link; + + /* reverse the list */ + IDP_Chain *link_prev; + link_prev = nullptr; + while (link) { + IDP_Chain *link_next = link->up; + link->up = link_prev; + link_prev = link; + link = link_next; + tot++; + } + + for (link = link_prev; link; link = link->up) { + /* pass */ + if (link->index >= 0) { + BLI_dynstr_appendf(dynstr, is_first ? "%s[%d]" : ".%s[%d]", link->name, link->index); + } + else { + BLI_dynstr_appendf(dynstr, is_first ? "%s" : ".%s", link->name); + } + + is_first = false; + } + + path = BLI_dynstr_get_cstring(dynstr); + BLI_dynstr_free(dynstr); + + if (*path == '\0') { + MEM_freeN(path); + path = nullptr; + } + + return path; +} + +static char *rna_idp_path(PointerRNA *ptr, + IDProperty *haystack, + IDProperty *needle, + IDP_Chain *parent_link) +{ + char *path = nullptr; + IDP_Chain link; + + IDProperty *iter; + int i; + + BLI_assert(haystack->type == IDP_GROUP); + + link.up = parent_link; + /* Always set both name and index, else a stale value might get used. */ + link.name = nullptr; + link.index = -1; + + for (i = 0, iter = static_cast<IDProperty *>(haystack->data.group.first); iter; + iter = iter->next, i++) { + if (needle == iter) { /* found! */ + link.name = iter->name; + link.index = -1; + path = rna_idp_path_create(&link); + break; + } + + /* Early out in case the IDProperty type cannot contain RNA properties. */ + if (!ELEM(iter->type, IDP_GROUP, IDP_IDPARRAY)) { + continue; + } + + /* Ensure this is RNA. */ + /* NOTE: `iter` might be a fully user-defined IDProperty (a.k.a. custom data), which name + * collides with an actual fully static RNA property of the same struct (which would then not + * be flagged with `PROP_IDPROPERTY`). + * + * That case must be ignored here, we only want to deal with runtime RNA properties stored in + * IDProps. + * + * See T84091. */ + PropertyRNA *prop = RNA_struct_find_property(ptr, iter->name); + if (prop == nullptr || (prop->flag & PROP_IDPROPERTY) == 0) { + continue; + } + + if (iter->type == IDP_GROUP) { + if (prop->type == PROP_POINTER) { + PointerRNA child_ptr = RNA_property_pointer_get(ptr, prop); + if (RNA_pointer_is_null(&child_ptr)) { + /* Pointer ID prop might be a 'leaf' in the IDProp group hierarchy, in which case a NULL + * value is perfectly valid. Just means it won't match the searched needle. */ + continue; + } + + link.name = iter->name; + link.index = -1; + if ((path = rna_idp_path(&child_ptr, iter, needle, &link))) { + break; + } + } + } + else if (iter->type == IDP_IDPARRAY) { + if (prop->type == PROP_COLLECTION) { + IDProperty *array = IDP_IDPArray(iter); + if (needle >= array && needle < (iter->len + array)) { /* found! */ + link.name = iter->name; + link.index = (int)(needle - array); + path = rna_idp_path_create(&link); + break; + } + int j; + link.name = iter->name; + for (j = 0; j < iter->len; j++, array++) { + PointerRNA child_ptr; + if (RNA_property_collection_lookup_int(ptr, prop, j, &child_ptr)) { + if (RNA_pointer_is_null(&child_ptr)) { + /* Array item ID prop might be a 'leaf' in the IDProp group hierarchy, in which case + * a NULL value is perfectly valid. Just means it won't match the searched needle. */ + continue; + } + link.index = j; + if ((path = rna_idp_path(&child_ptr, array, needle, &link))) { + break; + } + } + } + if (path) { + break; + } + } + } + } + + return path; +} + +char *RNA_path_from_struct_to_idproperty(PointerRNA *ptr, IDProperty *needle) +{ + IDProperty *haystack = RNA_struct_idprops(ptr, false); + + if (haystack) { /* can fail when called on bones */ + return rna_idp_path(ptr, haystack, needle, nullptr); + } + return nullptr; +} + +static char *rna_path_from_ID_to_idpgroup(const PointerRNA *ptr) +{ + PointerRNA id_ptr; + + BLI_assert(ptr->owner_id != nullptr); + + /* TODO: Support Bones/PoseBones. no pointers stored to the bones from here, only the ID. + * See example in T25746. + * Unless this is added only way to find this is to also search + * all bones and pose bones of an armature or object. + */ + RNA_id_pointer_create(ptr->owner_id, &id_ptr); + + return RNA_path_from_struct_to_idproperty(&id_ptr, static_cast<IDProperty *>(ptr->data)); +} + +ID *RNA_find_real_ID_and_path(ID *id, const char **r_path) +{ + if (r_path) { + *r_path = ""; + } + + if ((id == nullptr) || (id->flag & LIB_EMBEDDED_DATA) == 0) { + return id; + } + + const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id); + if (r_path) { + switch (GS(id->name)) { + case ID_NT: + *r_path = "node_tree"; + break; + case ID_GR: + *r_path = "collection"; + break; + default: + BLI_assert_msg(0, "Missing handling of embedded id type."); + } + } + + if (id_type->owner_get == nullptr) { + BLI_assert_msg(0, "Missing handling of embedded id type."); + return id; + } + return id_type->owner_get(id); +} + +static char *rna_prepend_real_ID_path(Main * /*bmain*/, ID *id, char *path, ID **r_real_id) +{ + if (r_real_id != nullptr) { + *r_real_id = nullptr; + } + + const char *prefix; + ID *real_id = RNA_find_real_ID_and_path(id, &prefix); + + if (r_real_id != nullptr) { + *r_real_id = real_id; + } + + if (path != nullptr) { + char *new_path = nullptr; + + if (real_id) { + if (prefix[0]) { + new_path = BLI_sprintfN("%s%s%s", prefix, path[0] == '[' ? "" : ".", path); + } + else { + return path; + } + } + + MEM_freeN(path); + return new_path; + } + return prefix[0] != '\0' ? BLI_strdup(prefix) : nullptr; +} + +char *RNA_path_from_ID_to_struct(const PointerRNA *ptr) +{ + char *ptrpath = nullptr; + + if (!ptr->owner_id || !ptr->data) { + return nullptr; + } + + if (!RNA_struct_is_ID(ptr->type)) { + if (ptr->type->path) { + /* if type has a path to some ID, use it */ + ptrpath = ptr->type->path((PointerRNA *)ptr); + } + else if (ptr->type->nested && RNA_struct_is_ID(ptr->type->nested)) { + PointerRNA parentptr; + PropertyRNA *userprop; + + /* find the property in the struct we're nested in that references this struct, and + * use its identifier as the first part of the path used... + */ + RNA_id_pointer_create(ptr->owner_id, &parentptr); + userprop = rna_struct_find_nested(&parentptr, ptr->type); + + if (userprop) { + ptrpath = BLI_strdup(RNA_property_identifier(userprop)); + } + else { + return nullptr; /* can't do anything about this case yet... */ + } + } + else if (RNA_struct_is_a(ptr->type, &RNA_PropertyGroup)) { + /* special case, easier to deal with here than in ptr->type->path() */ + return rna_path_from_ID_to_idpgroup(ptr); + } + else { + return nullptr; + } + } + + return ptrpath; +} + +char *RNA_path_from_real_ID_to_struct(Main *bmain, const PointerRNA *ptr, struct ID **r_real) +{ + char *path = RNA_path_from_ID_to_struct(ptr); + + /* NULL path is valid in that case, when given struct is an ID one... */ + return rna_prepend_real_ID_path(bmain, ptr->owner_id, path, r_real); +} + +static void rna_path_array_multi_from_flat_index(const int dimsize[RNA_MAX_ARRAY_LENGTH], + const int totdims, + const int index_dim, + int index, + int r_index_multi[RNA_MAX_ARRAY_LENGTH]) +{ + int dimsize_step[RNA_MAX_ARRAY_LENGTH + 1]; + int i = totdims - 1; + dimsize_step[i + 1] = 1; + dimsize_step[i] = dimsize[i]; + while (--i != -1) { + dimsize_step[i] = dimsize[i] * dimsize_step[i + 1]; + } + while (++i != index_dim) { + int index_round = index / dimsize_step[i + 1]; + r_index_multi[i] = index_round; + index -= (index_round * dimsize_step[i + 1]); + } + BLI_assert(index == 0); +} + +static void rna_path_array_multi_string_from_flat_index(const PointerRNA *ptr, + PropertyRNA *prop, + int index_dim, + int index, + char *index_str, + int index_str_len) +{ + int dimsize[RNA_MAX_ARRAY_LENGTH]; + int totdims = RNA_property_array_dimension(ptr, prop, dimsize); + int index_multi[RNA_MAX_ARRAY_LENGTH]; + + rna_path_array_multi_from_flat_index(dimsize, totdims, index_dim, index, index_multi); + + for (int i = 0, offset = 0; (i < index_dim) && (offset < index_str_len); i++) { + offset += BLI_snprintf_rlen( + &index_str[offset], index_str_len - offset, "[%d]", index_multi[i]); + } +} + +char *RNA_path_from_ID_to_property_index(const PointerRNA *ptr, + PropertyRNA *prop, + int index_dim, + int index) +{ + const bool is_rna = (prop->magic == RNA_MAGIC); + const char *propname; + char *ptrpath, *path; + + if (!ptr->owner_id || !ptr->data) { + return nullptr; + } + + /* path from ID to the struct holding this property */ + ptrpath = RNA_path_from_ID_to_struct(ptr); + + propname = RNA_property_identifier(prop); + + /* support indexing w/ multi-dimensional arrays */ + char index_str[RNA_MAX_ARRAY_LENGTH * 12 + 1]; + if (index_dim == 0) { + index_str[0] = '\0'; + } + else { + rna_path_array_multi_string_from_flat_index( + ptr, prop, index_dim, index, index_str, sizeof(index_str)); + } + + if (ptrpath) { + if (is_rna) { + path = BLI_sprintfN("%s.%s%s", ptrpath, propname, index_str); + } + else { + char propname_esc[MAX_IDPROP_NAME * 2]; + BLI_str_escape(propname_esc, propname, sizeof(propname_esc)); + path = BLI_sprintfN("%s[\"%s\"]%s", ptrpath, propname_esc, index_str); + } + MEM_freeN(ptrpath); + } + else if (RNA_struct_is_ID(ptr->type)) { + if (is_rna) { + path = BLI_sprintfN("%s%s", propname, index_str); + } + else { + char propname_esc[MAX_IDPROP_NAME * 2]; + BLI_str_escape(propname_esc, propname, sizeof(propname_esc)); + path = BLI_sprintfN("[\"%s\"]%s", propname_esc, index_str); + } + } + else { + path = nullptr; + } + + return path; +} + +char *RNA_path_from_ID_to_property(const PointerRNA *ptr, PropertyRNA *prop) +{ + return RNA_path_from_ID_to_property_index(ptr, prop, 0, -1); +} + +char *RNA_path_from_real_ID_to_property_index(Main *bmain, + const PointerRNA *ptr, + PropertyRNA *prop, + int index_dim, + int index, + ID **r_real_id) +{ + char *path = RNA_path_from_ID_to_property_index(ptr, prop, index_dim, index); + + /* NULL path is always an error here, in that case do not return the 'fake ID from real ID' part + * of the path either. */ + return path != nullptr ? rna_prepend_real_ID_path(bmain, ptr->owner_id, path, r_real_id) : + nullptr; +} + +char *RNA_path_resolve_from_type_to_property(const PointerRNA *ptr, + PropertyRNA *prop, + const StructRNA *type) +{ + /* Try to recursively find an "type"'d ancestor, + * to handle situations where path from ID is not enough. */ + PointerRNA idptr; + ListBase path_elems = {nullptr}; + char *path = nullptr; + char *full_path = RNA_path_from_ID_to_property(ptr, prop); + + if (full_path == nullptr) { + return nullptr; + } + + RNA_id_pointer_create(ptr->owner_id, &idptr); + + if (RNA_path_resolve_elements(&idptr, full_path, &path_elems)) { + LISTBASE_FOREACH_BACKWARD (PropertyElemRNA *, prop_elem, &path_elems) { + if (RNA_struct_is_a(prop_elem->ptr.type, type)) { + char *ref_path = RNA_path_from_ID_to_struct(&prop_elem->ptr); + if (ref_path) { + path = BLI_strdup(full_path + strlen(ref_path) + 1); /* +1 for the linking '.' */ + MEM_freeN(ref_path); + } + break; + } + } + + BLI_freelistN(&path_elems); + } + + MEM_freeN(full_path); + return path; +} + +char *RNA_path_full_ID_py(ID *id) +{ + const char *path; + ID *id_real = RNA_find_real_ID_and_path(id, &path); + + if (id_real) { + id = id_real; + } + else { + path = ""; + } + + char lib_filepath_esc[(sizeof(id->lib->filepath) * 2) + 4]; + if (ID_IS_LINKED(id)) { + int ofs = 0; + memcpy(lib_filepath_esc, ", \"", 3); + ofs += 3; + ofs += BLI_str_escape(lib_filepath_esc + ofs, id->lib->filepath, sizeof(lib_filepath_esc)); + memcpy(lib_filepath_esc + ofs, "\"", 2); + } + else { + lib_filepath_esc[0] = '\0'; + } + + char id_esc[(sizeof(id->name) - 2) * 2]; + BLI_str_escape(id_esc, id->name + 2, sizeof(id_esc)); + + return BLI_sprintfN("bpy.data.%s[\"%s\"%s]%s%s", + BKE_idtype_idcode_to_name_plural(GS(id->name)), + id_esc, + lib_filepath_esc, + path[0] ? "." : "", + path); +} + +char *RNA_path_full_struct_py(const PointerRNA *ptr) +{ + char *id_path; + char *data_path; + + char *ret; + + if (!ptr->owner_id) { + return nullptr; + } + + /* never fails */ + id_path = RNA_path_full_ID_py(ptr->owner_id); + + data_path = RNA_path_from_ID_to_struct(ptr); + + /* XXX data_path may be NULL (see T36788), + * do we want to get the 'bpy.data.foo["bar"].(null)' stuff? */ + ret = BLI_sprintfN("%s.%s", id_path, data_path); + + if (data_path) { + MEM_freeN(data_path); + } + MEM_freeN(id_path); + + return ret; +} + +char *RNA_path_full_property_py_ex(const PointerRNA *ptr, + PropertyRNA *prop, + int index, + bool use_fallback) +{ + char *id_path; + const char *data_delim; + const char *data_path; + bool data_path_free; + + char *ret; + + if (!ptr->owner_id) { + return nullptr; + } + + /* never fails */ + id_path = RNA_path_full_ID_py(ptr->owner_id); + + data_path = RNA_path_from_ID_to_property(ptr, prop); + if (data_path) { + data_delim = (data_path[0] == '[') ? "" : "."; + data_path_free = true; + } + else { + if (use_fallback) { + /* Fuzzy fallback. Be explicit in our ignorance. */ + data_path = RNA_property_identifier(prop); + data_delim = " ... "; + } + else { + data_delim = "."; + } + data_path_free = false; + } + + if ((index == -1) || (RNA_property_array_check(prop) == false)) { + ret = BLI_sprintfN("%s%s%s", id_path, data_delim, data_path); + } + else { + ret = BLI_sprintfN("%s%s%s[%d]", id_path, data_delim, data_path, index); + } + MEM_freeN(id_path); + if (data_path_free) { + MEM_freeN((void *)data_path); + } + + return ret; +} + +char *RNA_path_full_property_py(const PointerRNA *ptr, PropertyRNA *prop, int index) +{ + return RNA_path_full_property_py_ex(ptr, prop, index, false); +} + +char *RNA_path_struct_property_py(PointerRNA *ptr, PropertyRNA *prop, int index) +{ + char *data_path; + + char *ret; + + if (!ptr->owner_id) { + return nullptr; + } + + data_path = RNA_path_from_ID_to_property(ptr, prop); + + if (data_path == nullptr) { + /* This may not be an ID at all, check for simple when pointer owns property. + * TODO: more complex nested case. */ + if (!RNA_struct_is_ID(ptr->type)) { + const char *prop_identifier = RNA_property_identifier(prop); + if (RNA_struct_find_property(ptr, prop_identifier) == prop) { + data_path = BLI_strdup(prop_identifier); + } + } + } + + if ((index == -1) || (RNA_property_array_check(prop) == false)) { + ret = BLI_strdup(data_path); + } + else { + ret = BLI_sprintfN("%s[%d]", data_path, index); + } + + if (data_path) { + MEM_freeN(data_path); + } + + return ret; +} + +char *RNA_path_property_py(const PointerRNA *UNUSED(ptr), PropertyRNA *prop, int index) +{ + const bool is_rna = (prop->magic == RNA_MAGIC); + const char *propname = RNA_property_identifier(prop); + char *ret; + + if ((index == -1) || (RNA_property_array_check(prop) == false)) { + if (is_rna) { + ret = BLI_strdup(propname); + } + else { + char propname_esc[MAX_IDPROP_NAME * 2]; + BLI_str_escape(propname_esc, propname, sizeof(propname_esc)); + ret = BLI_sprintfN("[\"%s\"]", propname_esc); + } + } + else { + if (is_rna) { + ret = BLI_sprintfN("%s[%d]", propname, index); + } + else { + char propname_esc[MAX_IDPROP_NAME * 2]; + BLI_str_escape(propname_esc, propname, sizeof(propname_esc)); + ret = BLI_sprintfN("[\"%s\"][%d]", propname_esc, index); + } + } + + return ret; +} diff --git a/source/blender/makesrna/intern/rna_pointcloud.c b/source/blender/makesrna/intern/rna_pointcloud.c index 4c5dcd5a587..df09bff1aea 100644 --- a/source/blender/makesrna/intern/rna_pointcloud.c +++ b/source/blender/makesrna/intern/rna_pointcloud.c @@ -20,6 +20,7 @@ # include "BLI_math_vector.h" +# include "BKE_customdata.h" # include "BKE_pointcloud.h" # include "DEG_depsgraph.h" @@ -36,7 +37,9 @@ static int rna_Point_index_get_const(const PointerRNA *ptr) { const PointCloud *pointcloud = rna_pointcloud(ptr); const float(*co)[3] = ptr->data; - return (int)(co - pointcloud->co); + const float(*positions)[3] = (const float(*)[3])CustomData_get_layer_named( + &pointcloud->pdata, CD_PROP_FLOAT3, "position"); + return (int)(co - positions); } static int rna_Point_index_get(PointerRNA *ptr) @@ -44,6 +47,21 @@ static int rna_Point_index_get(PointerRNA *ptr) return rna_Point_index_get_const(ptr); } +static int rna_PointCloud_points_length(PointerRNA *ptr) +{ + const PointCloud *pointcloud = rna_pointcloud(ptr); + return pointcloud->totpoint; +} + +static void rna_PointCloud_points_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) +{ + const PointCloud *pointcloud = rna_pointcloud(ptr); + const float(*positions)[3] = (const float(*)[3])CustomData_get_layer_named( + &pointcloud->pdata, CD_PROP_FLOAT3, "position"); + rna_iterator_array_begin( + iter, (void *)positions, sizeof(float[3]), pointcloud->totpoint, false, NULL); +} + static void rna_Point_location_get(PointerRNA *ptr, float value[3]) { copy_v3_v3(value, (const float *)ptr->data); @@ -57,21 +75,22 @@ static void rna_Point_location_set(PointerRNA *ptr, const float value[3]) static float rna_Point_radius_get(PointerRNA *ptr) { const PointCloud *pointcloud = rna_pointcloud(ptr); - if (pointcloud->radius == NULL) { + const float *radii = (const float *)CustomData_get_layer_named( + &pointcloud->pdata, CD_PROP_FLOAT, "radius"); + if (radii == NULL) { return 0.0f; } - const float(*co)[3] = ptr->data; - return pointcloud->radius[co - pointcloud->co]; + return radii[rna_Point_index_get_const(ptr)]; } static void rna_Point_radius_set(PointerRNA *ptr, float value) { - const PointCloud *pointcloud = rna_pointcloud(ptr); - if (pointcloud->radius == NULL) { + PointCloud *pointcloud = rna_pointcloud(ptr); + float *radii = (float *)CustomData_get_layer_named(&pointcloud->pdata, CD_PROP_FLOAT, "radius"); + if (radii == NULL) { return; } - const float(*co)[3] = ptr->data; - pointcloud->radius[co - pointcloud->co] = value; + radii[rna_Point_index_get_const(ptr)] = value; } static char *rna_Point_path(const PointerRNA *ptr) @@ -130,13 +149,18 @@ static void rna_def_pointcloud(BlenderRNA *brna) RNA_def_struct_ui_icon(srna, ICON_POINTCLOUD_DATA); /* geometry */ - /* TODO: better solution for (*co)[3] parsing issue. */ - RNA_define_verify_sdna(0); prop = RNA_def_property(srna, "points", PROP_COLLECTION, PROP_NONE); - RNA_def_property_collection_sdna(prop, NULL, "co", "totpoint"); RNA_def_property_struct_type(prop, "Point"); + RNA_def_property_collection_funcs(prop, + "rna_PointCloud_points_begin", + "rna_iterator_array_next", + "rna_iterator_array_end", + "rna_iterator_array_get", + "rna_PointCloud_points_length", + NULL, + NULL, + NULL); RNA_def_property_ui_text(prop, "Points", ""); - RNA_define_verify_sdna(1); /* materials */ prop = RNA_def_property(srna, "materials", PROP_COLLECTION, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c index 4108baca2fa..182f3ff6afa 100644 --- a/source/blender/makesrna/intern/rna_pose.c +++ b/source/blender/makesrna/intern/rna_pose.c @@ -127,7 +127,7 @@ static char *rna_PoseBone_path(const PointerRNA *ptr) static bool rna_bone_group_poll(Object *ob, ReportList *reports) { if (ID_IS_OVERRIDE_LIBRARY(ob)) { - BKE_report(reports, RPT_ERROR, "Cannot edit bone groups for proxies or library overrides"); + BKE_report(reports, RPT_ERROR, "Cannot edit bone groups for library overrides"); return false; } @@ -600,7 +600,7 @@ static void rna_PoseChannel_constraints_remove( ED_object_constraint_update(bmain, ob); - /* XXX(Campbell): is this really needed? */ + /* XXX(@campbellbarton): is this really needed? */ BKE_constraints_active_set(&pchan->constraints, NULL); WM_main_add_notifier(NC_OBJECT | ND_CONSTRAINT | NA_REMOVED, id); @@ -698,16 +698,18 @@ bool rna_PoseChannel_constraints_override_apply(Main *bmain, return true; } -static int rna_PoseChannel_proxy_editable(PointerRNA *ptr, const char **r_info) +static int rna_PoseChannel_proxy_editable(PointerRNA *UNUSED(ptr), const char **UNUSED(r_info)) { +# if 0 Object *ob = (Object *)ptr->owner_id; bArmature *arm = ob->data; bPoseChannel *pchan = (bPoseChannel *)ptr->data; - if (false && pchan->bone && (pchan->bone->layer & arm->layer_protected)) { + if (pchan->bone && (pchan->bone->layer & arm->layer_protected)) { *r_info = "Can't edit property of a proxy on a protected layer"; return 0; } +# endif return PROP_EDITABLE; } diff --git a/source/blender/makesrna/intern/rna_render.c b/source/blender/makesrna/intern/rna_render.c index 11a7be69f68..6a66445ee4c 100644 --- a/source/blender/makesrna/intern/rna_render.c +++ b/source/blender/makesrna/intern/rna_render.c @@ -118,7 +118,7 @@ static int engine_get_preview_pixel_size(RenderEngine *UNUSED(engine), Scene *sc static void engine_bind_display_space_shader(RenderEngine *UNUSED(engine), Scene *UNUSED(scene)) { - GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE); + GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_IMAGE); GPU_shader_bind(shader); int img_loc = GPU_shader_get_uniform(shader, "image"); diff --git a/source/blender/makesrna/intern/rna_rigidbody.c b/source/blender/makesrna/intern/rna_rigidbody.c index 0c1fd8cab3c..7a499d10d3a 100644 --- a/source/blender/makesrna/intern/rna_rigidbody.c +++ b/source/blender/makesrna/intern/rna_rigidbody.c @@ -865,7 +865,7 @@ static void rna_def_rigidbody_world(BlenderRNA *brna) prop = RNA_def_property(srna, "collection", PROP_POINTER, PROP_NONE); RNA_def_property_struct_type(prop, "Collection"); RNA_def_property_pointer_sdna(prop, NULL, "group"); - RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK); + RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK | PROP_ID_REFCOUNT); RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY); RNA_def_property_ui_text( prop, "Collection", "Collection containing objects participating in this simulation"); @@ -873,7 +873,7 @@ static void rna_def_rigidbody_world(BlenderRNA *brna) prop = RNA_def_property(srna, "constraints", PROP_POINTER, PROP_NONE); RNA_def_property_struct_type(prop, "Collection"); - RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK); + RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK | PROP_ID_REFCOUNT); RNA_def_property_override_flag(prop, PROPOVERRIDE_OVERRIDABLE_LIBRARY); RNA_def_property_ui_text( prop, "Constraints", "Collection containing rigid body constraint objects"); diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c index 16a4dfe71cf..57f75fe892c 100644 --- a/source/blender/makesrna/intern/rna_rna.c +++ b/source/blender/makesrna/intern/rna_rna.c @@ -1145,7 +1145,7 @@ static bool rna_Function_no_self_get(PointerRNA *ptr) return !(func->flag & FUNC_NO_SELF); } -static int rna_Function_use_self_type_get(PointerRNA *ptr) +static bool rna_Function_use_self_type_get(PointerRNA *ptr) { FunctionRNA *func = (FunctionRNA *)ptr->data; return 0 != (func->flag & FUNC_USE_SELF_TYPE); @@ -1577,7 +1577,7 @@ static int rna_property_override_diff_propptr(Main *bmain, RNA_property_##_typename##_set((_ptr), (_prop), (_value))) /** - * /return `0` is matching, `-1` if `prop_a < prop_b`, `1` if `prop_a > prop_b`. Note that for + * \return `0` is matching, `-1` if `prop_a < prop_b`, `1` if `prop_a > prop_b`. Note that for * unquantifiable properties (e.g. pointers or collections), return value should be interpreted as * a boolean (false == matching, true == not matching). */ diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c index 9e2a1d81bd3..61eb2a11c02 100644 --- a/source/blender/makesrna/intern/rna_scene.c +++ b/source/blender/makesrna/intern/rna_scene.c @@ -88,6 +88,11 @@ static const EnumPropertyItem uv_sculpt_relaxation_items[] = { "Laplacian", "Use Laplacian method for relaxation"}, {UV_SCULPT_TOOL_RELAX_HC, "HC", 0, "HC", "Use HC method for relaxation"}, + {UV_SCULPT_TOOL_RELAX_COTAN, + "COTAN", + 0, + "Geometry", + "Use Geometry (cotangent) relaxation, making UV's follow the underlying 3D geometry"}, {0, NULL, 0, NULL, NULL}, }; #endif @@ -151,7 +156,16 @@ const EnumPropertyItem rna_enum_snap_element_items[] = { "Snap to increments of grid"}, {SCE_SNAP_MODE_VERTEX, "VERTEX", ICON_SNAP_VERTEX, "Vertex", "Snap to vertices"}, {SCE_SNAP_MODE_EDGE, "EDGE", ICON_SNAP_EDGE, "Edge", "Snap to edges"}, - {SCE_SNAP_MODE_FACE, "FACE", ICON_SNAP_FACE, "Face", "Snap to faces"}, + {SCE_SNAP_MODE_FACE_RAYCAST, + "FACE", /* TODO(@gfxcoder): replace with "FACE_RAYCAST" as "FACE" is not descriptive. */ + ICON_SNAP_FACE, + "Face Project", + "Snap by projecting onto faces"}, + {SCE_SNAP_MODE_FACE_NEAREST, + "FACE_NEAREST", + ICON_SNAP_FACE_NEAREST, + "Face Nearest", + "Snap to nearest point on faces"}, {SCE_SNAP_MODE_VOLUME, "VOLUME", ICON_SNAP_VOLUME, "Volume", "Snap to volume"}, {SCE_SNAP_MODE_EDGE_MIDPOINT, "EDGE_MIDPOINT", @@ -447,8 +461,8 @@ const EnumPropertyItem rna_enum_bake_target_items[] = { {R_BAKE_TARGET_VERTEX_COLORS, "VERTEX_COLORS", 0, - "Color Attributes", - "Bake to active color attribute layer on meshes"}, + "Active Color Attribute", + "Bake to the active color attribute on meshes"}, {0, NULL, 0, NULL, NULL}, }; @@ -693,7 +707,7 @@ static void rna_Gpencil_extend_selection(bContext *C, PointerRNA *UNUSED(ptr)) { /* Extend selection to all points in all selected strokes. */ ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = OBACT(view_layer); + Object *ob = BKE_view_layer_active_object_get(view_layer); if ((ob) && (ob->type == OB_GPENCIL)) { bGPdata *gpd = (bGPdata *)ob->data; CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) { @@ -839,12 +853,12 @@ void rna_Scene_set_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr) Scene *scene = (Scene *)ptr->owner_id; DEG_relations_tag_update(bmain); - DEG_id_tag_update_ex(bmain, &scene->id, 0); + DEG_id_tag_update_ex(bmain, &scene->id, ID_RECALC_BASE_FLAGS); if (scene->set != NULL) { /* Objects which are pulled into main scene's depsgraph needs to have * their base flags updated. */ - DEG_id_tag_update_ex(bmain, &scene->set->id, 0); + DEG_id_tag_update_ex(bmain, &scene->set->id, ID_RECALC_BASE_FLAGS); } } @@ -1286,7 +1300,7 @@ static const EnumPropertyItem *rna_ImageFormatSettings_color_mode_itemf(bContext ID *id = ptr->owner_id; const bool is_render = (id && GS(id->name) == ID_SCE); - /* NOTE(campbell): we need to act differently for render + /* NOTE(@campbellbarton): we need to act differently for render * where 'BW' will force grayscale even if the output format writes * as RGBA, this is age old blender convention and not sure how useful * it really is but keep it for now. */ @@ -1469,7 +1483,7 @@ static void rna_ImageFormatSettings_color_management_set(PointerRNA *ptr, int va if (owner_id && GS(owner_id->name) == ID_NT) { /* For compositing nodes, find the corresponding scene. */ const IDTypeInfo *type_info = BKE_idtype_get_info_from_id(owner_id); - owner_id = type_info->owner_get(G_MAIN, owner_id); + owner_id = type_info->owner_get(owner_id); } if (owner_id && GS(owner_id->name) == ID_SCE) { BKE_image_format_color_management_copy_from_scene(imf, (Scene *)owner_id); @@ -1666,18 +1680,18 @@ static bool rna_RenderSettings_use_spherical_stereo_get(PointerRNA *ptr) return BKE_scene_use_spherical_stereo(scene); } -void rna_Scene_glsl_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) +void rna_Scene_render_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) { Scene *scene = (Scene *)ptr->owner_id; - DEG_id_tag_update(&scene->id, 0); + DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE); } static void rna_Scene_world_update(Main *bmain, Scene *scene, PointerRNA *ptr) { Scene *screen = (Scene *)ptr->owner_id; - rna_Scene_glsl_update(bmain, scene, ptr); + rna_Scene_render_update(bmain, scene, ptr); WM_main_add_notifier(NC_WORLD | ND_WORLD, &screen->id); DEG_relations_tag_update(bmain); } @@ -1693,21 +1707,21 @@ static void rna_Scene_mesh_quality_update(Main *bmain, Scene *UNUSED(scene), Poi } FOREACH_SCENE_OBJECT_END; - rna_Scene_glsl_update(bmain, scene, ptr); + rna_Scene_render_update(bmain, scene, ptr); } void rna_Scene_freestyle_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) { Scene *scene = (Scene *)ptr->owner_id; - DEG_id_tag_update(&scene->id, 0); + DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE); } void rna_Scene_use_freestyle_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) { Scene *scene = (Scene *)ptr->owner_id; - DEG_id_tag_update(&scene->id, 0); + DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE); if (scene->nodetree) { ntreeCompositUpdateRLayers(scene->nodetree); @@ -1747,7 +1761,7 @@ static void rna_SceneRenderView_name_set(PointerRNA *ptr, const char *value) void rna_ViewLayer_material_override_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr) { Scene *scene = (Scene *)ptr->owner_id; - rna_Scene_glsl_update(bmain, scene, ptr); + rna_Scene_render_update(bmain, scene, ptr); DEG_relations_tag_update(bmain); } @@ -1784,7 +1798,7 @@ void rna_ViewLayer_pass_update(Main *bmain, Scene *activescene, PointerRNA *ptr) } } - rna_Scene_glsl_update(bmain, activescene, ptr); + rna_Scene_render_update(bmain, activescene, ptr); } static char *rna_ViewLayerEEVEE_path(const PointerRNA *ptr) @@ -1941,7 +1955,7 @@ static void rna_Scene_use_simplify_update(Main *bmain, Scene *UNUSED(scene), Poi WM_main_add_notifier(NC_GEOM | ND_DATA, NULL); WM_main_add_notifier(NC_OBJECT | ND_DRAW, NULL); - DEG_id_tag_update(&sce->id, 0); + DEG_id_tag_update(&sce->id, ID_RECALC_COPY_ON_WRITE); } static void rna_Scene_simplify_update(Main *bmain, Scene *scene, PointerRNA *ptr) @@ -2236,7 +2250,7 @@ static char *rna_MeshStatVis_path(const PointerRNA *UNUSED(ptr)) static void rna_Scene_update_active_object_data(bContext *C, PointerRNA *UNUSED(ptr)) { ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = OBACT(view_layer); + Object *ob = BKE_view_layer_active_object_get(view_layer); if (ob) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); @@ -2294,7 +2308,7 @@ FreestyleLineSet *rna_FreestyleSettings_lineset_add(ID *id, Scene *scene = (Scene *)id; FreestyleLineSet *lineset = BKE_freestyle_lineset_add(bmain, (FreestyleConfig *)config, name); - DEG_id_tag_update(&scene->id, 0); + DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE); WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL); return lineset; @@ -2315,7 +2329,7 @@ void rna_FreestyleSettings_lineset_remove(ID *id, RNA_POINTER_INVALIDATE(lineset_ptr); - DEG_id_tag_update(&scene->id, 0); + DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE); WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL); } @@ -2352,7 +2366,7 @@ FreestyleModuleConfig *rna_FreestyleSettings_module_add(ID *id, FreestyleSetting Scene *scene = (Scene *)id; FreestyleModuleConfig *module = BKE_freestyle_module_add((FreestyleConfig *)config); - DEG_id_tag_update(&scene->id, 0); + DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE); WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL); return module; @@ -2381,7 +2395,7 @@ void rna_FreestyleSettings_module_remove(ID *id, RNA_POINTER_INVALIDATE(module_ptr); - DEG_id_tag_update(&scene->id, 0); + DEG_id_tag_update(&scene->id, ID_RECALC_COPY_ON_WRITE); WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL); } @@ -2412,7 +2426,7 @@ static ViewLayer *rna_ViewLayer_new(ID *id, Scene *UNUSED(sce), Main *bmain, con Scene *scene = (Scene *)id; ViewLayer *view_layer = BKE_view_layer_add(scene, name, NULL, VIEWLAYER_ADD_NEW); - DEG_id_tag_update(&scene->id, 0); + DEG_id_tag_update(&scene->id, ID_RECALC_BASE_FLAGS); DEG_relations_tag_update(bmain); WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL); @@ -2492,7 +2506,7 @@ static void rna_ViewLayerLightgroup_name_set(PointerRNA *ptr, const char *value) Scene *scene = (Scene *)ptr->owner_id; ViewLayer *view_layer = BKE_view_layer_find_with_lightgroup(scene, lightgroup); - BKE_view_layer_rename_lightgroup(view_layer, lightgroup, value); + BKE_view_layer_rename_lightgroup(scene, view_layer, lightgroup, value); } /* Fake value, used internally (not saved to DNA). */ @@ -2719,7 +2733,11 @@ static void rna_FFmpegSettings_codec_update(Main *UNUSED(bmain), PointerRNA *ptr) { FFMpegCodecData *codec_data = (FFMpegCodecData *)ptr->data; - if (!ELEM(codec_data->codec, AV_CODEC_ID_H264, AV_CODEC_ID_MPEG4, AV_CODEC_ID_VP9)) { + if (!ELEM(codec_data->codec, + AV_CODEC_ID_H264, + AV_CODEC_ID_MPEG4, + AV_CODEC_ID_VP9, + AV_CODEC_ID_DNXHD)) { /* Constant Rate Factor (CRF) setting is only available for H264, * MPEG4 and WEBM/VP9 codecs. So changing encoder quality mode to * CBR as CRF is not supported. @@ -3125,6 +3143,7 @@ static void rna_def_tool_settings(BlenderRNA *brna) prop = RNA_def_property(srna, "workspace_tool_type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "workspace_tool_type"); RNA_def_property_enum_items(prop, workspace_tool_items); + RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_EDITOR_VIEW3D); RNA_def_property_ui_text(prop, "Drag", "Action when dragging in the viewport"); /* Transform */ @@ -3301,6 +3320,21 @@ static void rna_def_tool_settings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Snap Element", "Type of element to snap to"); RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); /* header redraw */ + prop = RNA_def_property(srna, "snap_face_nearest_steps", PROP_INT, PROP_FACTOR); + RNA_def_property_int_sdna(prop, NULL, "snap_face_nearest_steps"); + RNA_def_property_range(prop, 1, 100); + RNA_def_property_ui_text( + prop, + "Face Nearest Steps", + "Number of steps to break transformation into for face nearest snapping"); + + prop = RNA_def_property(srna, "use_snap_to_same_target", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "snap_flag", SCE_SNAP_KEEP_ON_SAME_OBJECT); + RNA_def_property_ui_text( + prop, + "Snap to Same Target", + "Snap only to target that source was initially near (Face Nearest Only)"); + /* node editor uses own set of snap modes */ prop = RNA_def_property(srna, "snap_node_element", PROP_ENUM, PROP_NONE); RNA_def_property_enum_bitflag_sdna(prop, NULL, "snap_node_mode"); @@ -3323,9 +3357,9 @@ static void rna_def_tool_settings(BlenderRNA *brna) "Absolute grid alignment while translating (based on the pivot center)"); RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); /* header redraw */ - /* TODO(@gfxcoder): Rename `snap_target` to `snap_source` to avoid - * previous ambiguity of "target" (now, "source" is geometry to be moved and "target" is - * geometry to which moved geometry is snapped). */ + /* TODO(@gfxcoder): Rename `snap_target` to `snap_source` to avoid previous ambiguity of "target" + * (now, "source" is geometry to be moved and "target" is geometry to which moved geometry is + * snapped). */ prop = RNA_def_property(srna, "snap_target", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "snap_target"); RNA_def_property_enum_items(prop, rna_enum_snap_source_items); @@ -3350,9 +3384,30 @@ static void rna_def_tool_settings(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Backface Culling", "Exclude back facing geometry from snapping"); RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); /* header redraw */ + /* TODO(@gfxcoder): Rename `use_snap_self` to `use_snap_active`, because active is correct but + * self is not (breaks API). This only makes a difference when more than one mesh is edited. */ prop = RNA_def_property(srna, "use_snap_self", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_negative_sdna(prop, NULL, "snap_flag", SCE_SNAP_NO_SELF); - RNA_def_property_ui_text(prop, "Project onto Self", "Snap onto itself (Edit Mode Only)"); + RNA_def_property_boolean_negative_sdna(prop, NULL, "snap_flag", SCE_SNAP_NOT_TO_ACTIVE); + RNA_def_property_ui_text( + prop, "Snap onto Active", "Snap onto itself only if enabled (Edit Mode Only)"); + RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); /* header redraw */ + + prop = RNA_def_property(srna, "use_snap_edit", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "snap_flag", SCE_SNAP_TO_INCLUDE_EDITED); + RNA_def_property_ui_text( + prop, "Snap onto Edited", "Snap onto non-active objects in Edit Mode (Edit Mode Only)"); + RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); /* header redraw */ + + prop = RNA_def_property(srna, "use_snap_nonedit", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "snap_flag", SCE_SNAP_TO_INCLUDE_NONEDITED); + RNA_def_property_ui_text( + prop, "Snap onto Non-edited", "Snap onto objects not in Edit Mode (Edit Mode Only)"); + RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); /* header redraw */ + + prop = RNA_def_property(srna, "use_snap_selectable", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "snap_flag", SCE_SNAP_TO_ONLY_SELECTABLE); + RNA_def_property_ui_text( + prop, "Snap onto Selectable Only", "Snap only onto objects that are selectable"); RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); /* header redraw */ prop = RNA_def_property(srna, "use_snap_translate", PROP_BOOLEAN, PROP_NONE); @@ -4412,7 +4467,7 @@ void rna_def_view_layer_common(BlenderRNA *brna, StructRNA *srna, const bool sce RNA_def_property_boolean_sdna(prop, NULL, "layflag", SCE_LAY_SKY); RNA_def_property_ui_text(prop, "Sky", "Render Sky in this Layer"); if (scene) { - RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update"); + RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_render_update"); } else { RNA_def_property_clear_flag(prop, PROP_EDITABLE); @@ -4422,7 +4477,7 @@ void rna_def_view_layer_common(BlenderRNA *brna, StructRNA *srna, const bool sce RNA_def_property_boolean_sdna(prop, NULL, "layflag", SCE_LAY_AO); RNA_def_property_ui_text(prop, "Ambient Occlusion", "Render Ambient Occlusion in this Layer"); if (scene) { - RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update"); + RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_render_update"); } else { RNA_def_property_clear_flag(prop, PROP_EDITABLE); @@ -5762,19 +5817,19 @@ static void rna_def_scene_image_format_data(BlenderRNA *brna) prop = RNA_def_property(srna, "cineon_black", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "cineon_black"); RNA_def_property_range(prop, 0, 1024); - RNA_def_property_ui_text(prop, "B", "Log conversion reference blackpoint"); + RNA_def_property_ui_text(prop, "Black", "Log conversion reference blackpoint"); RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL); prop = RNA_def_property(srna, "cineon_white", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "cineon_white"); RNA_def_property_range(prop, 0, 1024); - RNA_def_property_ui_text(prop, "W", "Log conversion reference whitepoint"); + RNA_def_property_ui_text(prop, "White", "Log conversion reference whitepoint"); RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL); prop = RNA_def_property(srna, "cineon_gamma", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "cineon_gamma"); RNA_def_property_range(prop, 0.0f, 10.0f); - RNA_def_property_ui_text(prop, "G", "Log conversion gamma"); + RNA_def_property_ui_text(prop, "Gamma", "Log conversion gamma"); RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL); /* multiview */ @@ -6299,7 +6354,7 @@ static void rna_def_scene_render_data(BlenderRNA *brna) prop, "Transparent", "World background is transparent, for compositing the render over another background"); - RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update"); + RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_render_update"); prop = RNA_def_property(srna, "use_freestyle", PROP_BOOLEAN, PROP_NONE); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); @@ -6330,14 +6385,14 @@ static void rna_def_scene_render_data(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "mode", R_MBLUR); RNA_def_property_ui_text(prop, "Motion Blur", "Use multi-sampled 3D scene motion blur"); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); - RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update"); + RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_render_update"); prop = RNA_def_property(srna, "motion_blur_shutter", PROP_FLOAT, PROP_FACTOR); RNA_def_property_float_sdna(prop, NULL, "blurfac"); RNA_def_property_range(prop, 0.0f, FLT_MAX); RNA_def_property_ui_range(prop, 0.01f, 1.0f, 1, 2); RNA_def_property_ui_text(prop, "Shutter", "Time taken in frames between shutter open and close"); - RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update"); + RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_render_update"); prop = RNA_def_property(srna, "motion_blur_shutter_curve", PROP_POINTER, PROP_NONE); RNA_def_property_pointer_sdna(prop, NULL, "mblur_shutter_curve"); @@ -6349,13 +6404,13 @@ static void rna_def_scene_render_data(BlenderRNA *brna) prop = RNA_def_property(srna, "hair_type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_items(prop, hair_shape_type_items); RNA_def_property_ui_text(prop, "Curves Shape Type", "Curves shape type"); - RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update"); + RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_render_update"); prop = RNA_def_property(srna, "hair_subdiv", PROP_INT, PROP_NONE); RNA_def_property_range(prop, 0, 3); RNA_def_property_ui_text( prop, "Additional Subdivision", "Additional subdivision along the curves"); - RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update"); + RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_render_update"); /* Performance */ prop = RNA_def_property(srna, "use_high_quality_normals", PROP_BOOLEAN, PROP_NONE); diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c index 3de9e632ff6..42523508c14 100644 --- a/source/blender/makesrna/intern/rna_sculpt_paint.c +++ b/source/blender/makesrna/intern/rna_sculpt_paint.c @@ -22,6 +22,7 @@ #include "DNA_space_types.h" #include "BKE_brush.h" +#include "BKE_layer.h" #include "BKE_material.h" #include "BKE_paint.h" @@ -164,7 +165,7 @@ static void rna_ParticleEdit_redo(bContext *C, PointerRNA *UNUSED(ptr)) Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = OBACT(view_layer); + Object *ob = BKE_view_layer_active_object_get(view_layer); PTCacheEdit *edit = PE_get_current(depsgraph, scene, ob); if (!edit) { @@ -184,7 +185,7 @@ static void rna_ParticleEdit_update(bContext *C, PointerRNA *UNUSED(ptr)) { Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = OBACT(view_layer); + Object *ob = BKE_view_layer_active_object_get(view_layer); if (ob) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); @@ -215,7 +216,7 @@ static const EnumPropertyItem *rna_ParticleEdit_tool_itemf(bContext *C, bool *UNUSED(r_free)) { ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = OBACT(view_layer); + Object *ob = BKE_view_layer_active_object_get(view_layer); # if 0 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C); Scene *scene = CTX_data_scene(C); @@ -373,7 +374,7 @@ static void rna_Sculpt_update(bContext *C, PointerRNA *UNUSED(ptr)) { Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = OBACT(view_layer); + Object *ob = BKE_view_layer_active_object_get(view_layer); if (ob) { DEG_id_tag_update(&ob->id, ID_RECALC_GEOMETRY); @@ -389,7 +390,7 @@ static void rna_Sculpt_update(bContext *C, PointerRNA *UNUSED(ptr)) static void rna_Sculpt_ShowMask_update(bContext *C, PointerRNA *UNUSED(ptr)) { ViewLayer *view_layer = CTX_data_view_layer(C); - Object *object = OBACT(view_layer); + Object *object = BKE_view_layer_active_object_get(view_layer); if (object == NULL || object->sculpt == NULL) { return; } @@ -487,7 +488,7 @@ static void rna_ImaPaint_mode_update(bContext *C, PointerRNA *UNUSED(ptr)) { Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = OBACT(view_layer); + Object *ob = BKE_view_layer_active_object_get(view_layer); if (ob && ob->type == OB_MESH) { /* of course we need to invalidate here */ @@ -504,7 +505,7 @@ static void rna_ImaPaint_stencil_update(bContext *C, PointerRNA *UNUSED(ptr)) { Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = OBACT(view_layer); + Object *ob = BKE_view_layer_active_object_get(view_layer); if (ob && ob->type == OB_MESH) { ED_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL); @@ -523,7 +524,7 @@ static void rna_ImaPaint_canvas_update(bContext *C, PointerRNA *UNUSED(ptr)) Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Object *ob = OBACT(view_layer); + Object *ob = BKE_view_layer_active_object_get(view_layer); bScreen *screen; Image *ima = scene->toolsettings->imapaint.canvas; @@ -1040,7 +1041,7 @@ static void rna_def_paint_mode(BlenderRNA *brna) RNA_def_property_pointer_funcs( prop, NULL, NULL, NULL, "rna_PaintModeSettings_canvas_image_poll"); RNA_def_property_flag(prop, PROP_EDITABLE | PROP_CONTEXT_UPDATE); - RNA_def_property_ui_text(prop, "Texture", "Image used as as painting target"); + RNA_def_property_ui_text(prop, "Texture", "Image used as painting target"); } static void rna_def_image_paint(BlenderRNA *brna) @@ -1303,6 +1304,7 @@ static void rna_def_particle_edit(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "flag", PE_INTERPOLATE_ADDED); RNA_def_property_ui_text( prop, "Interpolate", "Interpolate new particles from the existing ones"); + RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, NULL); prop = RNA_def_property(srna, "default_key_count", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "totaddkey"); diff --git a/source/blender/makesrna/intern/rna_sequencer.c b/source/blender/makesrna/intern/rna_sequencer.c index 100d90df5d6..aa40ee846bf 100644 --- a/source/blender/makesrna/intern/rna_sequencer.c +++ b/source/blender/makesrna/intern/rna_sequencer.c @@ -43,6 +43,7 @@ #include "SEQ_prefetch.h" #include "SEQ_proxy.h" #include "SEQ_relations.h" +#include "SEQ_select.h" #include "SEQ_sequencer.h" #include "SEQ_sound.h" #include "SEQ_time.h" @@ -291,7 +292,7 @@ static void do_sequence_frame_change_update(Scene *scene, Sequence *seq) { ListBase *seqbase = SEQ_get_seqbase_by_seq(scene, seq); - if (SEQ_transform_test_overlap(seqbase, seq)) { + if (SEQ_transform_test_overlap(scene, seqbase, seq)) { SEQ_transform_seqbase_shuffle(seqbase, seq, scene); } @@ -311,14 +312,16 @@ static void rna_Sequence_frame_change_update(Main *UNUSED(bmain), do_sequence_frame_change_update(scene, (Sequence *)ptr->data); } -static void rna_Sequence_start_frame_set(PointerRNA *ptr, int value) +static int rna_Sequence_frame_final_start_get(PointerRNA *ptr) { - Sequence *seq = (Sequence *)ptr->data; Scene *scene = (Scene *)ptr->owner_id; + return SEQ_time_left_handle_frame_get(scene, (Sequence *)ptr->data); +} - SEQ_transform_translate_sequence(scene, seq, value - seq->start); - do_sequence_frame_change_update(scene, seq); - SEQ_relations_invalidate_cache_composite(scene, seq); +static int rna_Sequence_frame_final_end_get(PointerRNA *ptr) +{ + Scene *scene = (Scene *)ptr->owner_id; + return SEQ_time_right_handle_frame_get(scene, (Sequence *)ptr->data); } static void rna_Sequence_start_frame_final_set(PointerRNA *ptr, int value) @@ -343,7 +346,17 @@ static void rna_Sequence_end_frame_final_set(PointerRNA *ptr, int value) SEQ_relations_invalidate_cache_composite(scene, seq); } -static void rna_Sequence_frame_offset_start_set(PointerRNA *ptr, int value) +static void rna_Sequence_start_frame_set(PointerRNA *ptr, float value) +{ + Sequence *seq = (Sequence *)ptr->data; + Scene *scene = (Scene *)ptr->owner_id; + + SEQ_transform_translate_sequence(scene, seq, value - seq->start); + do_sequence_frame_change_update(scene, seq); + SEQ_relations_invalidate_cache_composite(scene, seq); +} + +static void rna_Sequence_frame_offset_start_set(PointerRNA *ptr, float value) { Sequence *seq = (Sequence *)ptr->data; Scene *scene = (Scene *)ptr->owner_id; @@ -352,7 +365,7 @@ static void rna_Sequence_frame_offset_start_set(PointerRNA *ptr, int value) seq->startofs = value; } -static void rna_Sequence_frame_offset_end_set(PointerRNA *ptr, int value) +static void rna_Sequence_frame_offset_end_set(PointerRNA *ptr, float value) { Sequence *seq = (Sequence *)ptr->data; Scene *scene = (Scene *)ptr->owner_id; @@ -402,7 +415,7 @@ static void rna_Sequence_anim_startofs_final_range( } static void rna_Sequence_frame_offset_start_range( - PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax)) + PointerRNA *ptr, float *min, float *max, float *UNUSED(softmin), float *UNUSED(softmax)) { Sequence *seq = (Sequence *)ptr->data; *min = ELEM(seq->type, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SOUND_HD) ? 0 : INT_MIN; @@ -410,7 +423,7 @@ static void rna_Sequence_frame_offset_start_range( } static void rna_Sequence_frame_offset_end_range( - PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax)) + PointerRNA *ptr, float *min, float *max, float *UNUSED(softmin), float *UNUSED(softmax)) { Sequence *seq = (Sequence *)ptr->data; *min = ELEM(seq->type, SEQ_TYPE_SOUND_RAM, SEQ_TYPE_SOUND_HD) ? 0 : INT_MIN; @@ -422,7 +435,7 @@ static void rna_Sequence_frame_length_set(PointerRNA *ptr, int value) Sequence *seq = (Sequence *)ptr->data; Scene *scene = (Scene *)ptr->owner_id; - SEQ_time_right_handle_frame_set(scene, seq, SEQ_time_left_handle_frame_get(seq) + value); + SEQ_time_right_handle_frame_set(scene, seq, SEQ_time_left_handle_frame_get(scene, seq) + value); do_sequence_frame_change_update(scene, seq); SEQ_relations_invalidate_cache_composite(scene, seq); } @@ -430,7 +443,8 @@ static void rna_Sequence_frame_length_set(PointerRNA *ptr, int value) static int rna_Sequence_frame_length_get(PointerRNA *ptr) { Sequence *seq = (Sequence *)ptr->data; - return SEQ_time_right_handle_frame_get(seq) - SEQ_time_left_handle_frame_get(seq); + Scene *scene = (Scene *)ptr->owner_id; + return SEQ_time_right_handle_frame_get(scene, seq) - SEQ_time_left_handle_frame_get(scene, seq); } static int rna_Sequence_frame_editable(PointerRNA *ptr, const char **UNUSED(r_info)) @@ -450,7 +464,7 @@ static void rna_Sequence_channel_set(PointerRNA *ptr, int value) const int channel_delta = (value >= seq->machine) ? 1 : -1; seq->machine = value; - if (SEQ_transform_test_overlap(seqbase, seq)) { + if (SEQ_transform_test_overlap(scene, seqbase, seq)) { SEQ_transform_seqbase_shuffle_ex(seqbase, seq, scene, channel_delta); } SEQ_relations_invalidate_cache_composite(scene, seq); @@ -804,7 +818,20 @@ static int rna_Sequence_proxy_filepath_length(PointerRNA *ptr) static void rna_Sequence_audio_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr) { - DEG_id_tag_update(ptr->owner_id, ID_RECALC_SEQUENCER_STRIPS); + DEG_id_tag_update(ptr->owner_id, ID_RECALC_SEQUENCER_STRIPS | ID_RECALC_AUDIO); +} + +static void rna_Sequence_speed_factor_update(Main *bmain, Scene *scene, PointerRNA *ptr) +{ + SEQ_cache_cleanup(scene); + rna_Sequence_audio_update(bmain, scene, ptr); +} + +static void rna_Sequence_speed_factor_set(PointerRNA *ptr, float value) +{ + Sequence *seq = (Sequence *)ptr->data; + Scene *scene = (Scene *)ptr->owner_id; + SEQ_time_speed_factor_set(scene, seq, value); } static void rna_Sequence_pan_range( @@ -1107,6 +1134,26 @@ static void rna_SequenceEditor_overlay_frame_set(PointerRNA *ptr, int value) } } +static void rna_SequenceEditor_display_stack(ID *id, + Editing *ed, + ReportList *reports, + Sequence *seqm) +{ + /* Check for non-meta sequence */ + if (seqm != NULL && seqm->type != SEQ_TYPE_META && SEQ_exists_in_seqbase(seqm, &ed->seqbase)) { + BKE_report(reports, RPT_ERROR, "Sequence type must be 'META'"); + return; + } + + /* Get editing base of meta sequence */ + Scene *scene = (Scene *)id; + SEQ_meta_stack_set(scene, seqm); + /* De-activate strip. This is to prevent strip from different timeline being drawn. */ + SEQ_select_active_set(scene, NULL); + + WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, scene); +} + static bool modifier_seq_cmp_fn(Sequence *seq, void *arg_pt) { SequenceSearchData *data = arg_pt; @@ -1707,12 +1754,12 @@ static void rna_def_color_balance(BlenderRNA *brna) prop = RNA_def_property(srna, "invert_gain", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", SEQ_COLOR_BALANCE_INVERSE_GAIN); - RNA_def_property_ui_text(prop, "Inverse Gain", "Invert the gain color`"); + RNA_def_property_ui_text(prop, "Inverse Gain", "Invert the gain color"); RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SequenceColorBalance_update"); prop = RNA_def_property(srna, "invert_slope", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "flag", SEQ_COLOR_BALANCE_INVERSE_SLOPE); - RNA_def_property_ui_text(prop, "Inverse Slope", "Invert the slope color`"); + RNA_def_property_ui_text(prop, "Inverse Slope", "Invert the slope color"); RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SequenceColorBalance_update"); prop = RNA_def_property(srna, "invert_offset", PROP_BOOLEAN, PROP_NONE); @@ -1938,11 +1985,12 @@ static void rna_def_sequence(BlenderRNA *brna) RNA_def_property_ui_text( prop, "Length", "The length of the contents of this strip before the handles are applied"); - prop = RNA_def_property(srna, "frame_start", PROP_INT, PROP_TIME); - RNA_def_property_int_sdna(prop, NULL, "start"); + prop = RNA_def_property(srna, "frame_start", PROP_FLOAT, PROP_TIME); + RNA_def_property_float_sdna(prop, NULL, "start"); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_ui_text(prop, "Start Frame", "X position where the strip begins"); - RNA_def_property_int_funcs( + RNA_def_property_ui_range(prop, MINFRAME, MAXFRAME, 3, 0); + RNA_def_property_float_funcs( prop, NULL, "rna_Sequence_start_frame_set", NULL); /* overlap tests and calc_seq_disp */ RNA_def_property_editable_func(prop, "rna_Sequence_frame_editable"); RNA_def_property_update( @@ -1950,6 +1998,9 @@ static void rna_def_sequence(BlenderRNA *brna) prop = RNA_def_property(srna, "frame_final_start", PROP_INT, PROP_TIME); RNA_def_property_int_sdna(prop, NULL, "startdisp"); + RNA_def_property_int_funcs( + prop, "rna_Sequence_frame_final_start_get", "rna_Sequence_start_frame_final_set", NULL); + RNA_def_property_editable_func(prop, "rna_Sequence_frame_editable"); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_ui_text( prop, @@ -1957,35 +2008,36 @@ static void rna_def_sequence(BlenderRNA *brna) "Start frame displayed in the sequence editor after offsets are applied, setting this is " "equivalent to moving the handle, not the actual start frame"); /* overlap tests and calc_seq_disp */ - RNA_def_property_int_funcs(prop, NULL, "rna_Sequence_start_frame_final_set", NULL); - RNA_def_property_editable_func(prop, "rna_Sequence_frame_editable"); RNA_def_property_update( prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_invalidate_preprocessed_update"); prop = RNA_def_property(srna, "frame_final_end", PROP_INT, PROP_TIME); RNA_def_property_int_sdna(prop, NULL, "enddisp"); + RNA_def_property_int_funcs( + prop, "rna_Sequence_frame_final_end_get", "rna_Sequence_end_frame_final_set", NULL); + RNA_def_property_editable_func(prop, "rna_Sequence_frame_editable"); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); RNA_def_property_ui_text( prop, "End Frame", "End frame displayed in the sequence editor after offsets are applied"); /* overlap tests and calc_seq_disp */ - RNA_def_property_int_funcs(prop, NULL, "rna_Sequence_end_frame_final_set", NULL); - RNA_def_property_editable_func(prop, "rna_Sequence_frame_editable"); RNA_def_property_update( prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_invalidate_preprocessed_update"); - prop = RNA_def_property(srna, "frame_offset_start", PROP_INT, PROP_TIME); - RNA_def_property_int_sdna(prop, NULL, "startofs"); + prop = RNA_def_property(srna, "frame_offset_start", PROP_FLOAT, PROP_TIME); + RNA_def_property_float_sdna(prop, NULL, "startofs"); // RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* overlap tests */ RNA_def_property_ui_text(prop, "Start Offset", ""); - RNA_def_property_int_funcs( + RNA_def_property_ui_range(prop, MINFRAME, MAXFRAME, 3, 0); + RNA_def_property_float_funcs( prop, NULL, "rna_Sequence_frame_offset_start_set", "rna_Sequence_frame_offset_start_range"); RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_frame_change_update"); - prop = RNA_def_property(srna, "frame_offset_end", PROP_INT, PROP_TIME); - RNA_def_property_int_sdna(prop, NULL, "endofs"); + prop = RNA_def_property(srna, "frame_offset_end", PROP_FLOAT, PROP_TIME); + RNA_def_property_float_sdna(prop, NULL, "endofs"); // RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* overlap tests */ RNA_def_property_ui_text(prop, "End Offset", ""); - RNA_def_property_int_funcs( + RNA_def_property_ui_range(prop, MINFRAME, MAXFRAME, 3, 0); + RNA_def_property_float_funcs( prop, NULL, "rna_Sequence_frame_offset_end_set", "rna_Sequence_frame_offset_end_range"); RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_frame_change_update"); @@ -2116,6 +2168,8 @@ static void rna_def_channel(BlenderRNA *brna) static void rna_def_editor(BlenderRNA *brna) { StructRNA *srna; + FunctionRNA *func; + PropertyRNA *parm; PropertyRNA *prop; static const EnumPropertyItem editing_storage_items[] = { @@ -2259,6 +2313,28 @@ static void rna_def_editor(BlenderRNA *brna) "Prefetch Frames", "Render frames ahead of current frame in the background for faster playback"); RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, NULL); + + /* functions */ + + func = RNA_def_function(srna, "display_stack", "rna_SequenceEditor_display_stack"); + RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_REPORTS); + RNA_def_function_ui_description(func, "Display sequences stack"); + parm = RNA_def_pointer( + func, "meta_sequence", "Sequence", "Meta Sequence", "Meta to display its stack"); + RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); +} + +static void rna_def_speed_factor(StructRNA *srna) +{ + PropertyRNA *prop = RNA_def_property(srna, "speed_factor", PROP_FLOAT, PROP_NONE); + RNA_def_property_float_sdna(prop, NULL, "speed_factor"); + RNA_def_property_float_default(prop, 1.0f); + RNA_def_property_range(prop, 0.1f, FLT_MAX); + RNA_def_property_ui_range(prop, 1.0f, 100.0f, 10.0, 3); + RNA_def_property_ui_text(prop, "Speed Factor", "Multiply playback speed"); + RNA_def_property_float_funcs( + prop, NULL, "rna_Sequence_speed_factor_set", NULL); /* overlap test */ + RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_speed_factor_update"); } static void rna_def_filter_video(StructRNA *srna) @@ -2493,6 +2569,7 @@ static void rna_def_image(BlenderRNA *brna) rna_def_proxy(srna); rna_def_input(srna); rna_def_color_management(srna); + rna_def_speed_factor(srna); } static void rna_def_meta(BlenderRNA *brna) @@ -2524,6 +2601,7 @@ static void rna_def_meta(BlenderRNA *brna) rna_def_filter_video(srna); rna_def_proxy(srna); rna_def_input(srna); + rna_def_speed_factor(srna); } static void rna_def_scene(BlenderRNA *brna) @@ -2572,6 +2650,7 @@ static void rna_def_scene(BlenderRNA *brna) rna_def_proxy(srna); rna_def_input(srna); rna_def_movie_types(srna); + rna_def_speed_factor(srna); } static void rna_def_movie(BlenderRNA *brna) @@ -2655,6 +2734,7 @@ static void rna_def_movie(BlenderRNA *brna) rna_def_input(srna); rna_def_color_management(srna); rna_def_movie_types(srna); + rna_def_speed_factor(srna); } static void rna_def_movieclip(BlenderRNA *brna) @@ -2682,6 +2762,7 @@ static void rna_def_movieclip(BlenderRNA *brna) rna_def_filter_video(srna); rna_def_input(srna); rna_def_movie_types(srna); + rna_def_speed_factor(srna); } static void rna_def_mask(BlenderRNA *brna) @@ -2700,6 +2781,7 @@ static void rna_def_mask(BlenderRNA *brna) rna_def_filter_video(srna); rna_def_input(srna); + rna_def_speed_factor(srna); } static void rna_def_sound(BlenderRNA *brna) @@ -2726,13 +2808,6 @@ static void rna_def_sound(BlenderRNA *brna) RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_SOUND); RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_audio_update"); - prop = RNA_def_property(srna, "pitch", PROP_FLOAT, PROP_NONE); - RNA_def_property_float_sdna(prop, NULL, "pitch"); - RNA_def_property_range(prop, 0.1f, 10.0f); - RNA_def_property_ui_text(prop, "Pitch", "Playback pitch of the sound"); - RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_SOUND); - RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_Sequence_audio_update"); - prop = RNA_def_property(srna, "pan", PROP_FLOAT, PROP_NONE); RNA_def_property_float_sdna(prop, NULL, "pan"); RNA_def_property_range(prop, -FLT_MAX, FLT_MAX); @@ -2748,6 +2823,7 @@ static void rna_def_sound(BlenderRNA *brna) RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, NULL); rna_def_input(srna); + rna_def_speed_factor(srna); } static void rna_def_effect(BlenderRNA *brna) diff --git a/source/blender/makesrna/intern/rna_sequencer_api.c b/source/blender/makesrna/intern/rna_sequencer_api.c index 52de98be502..ae241c11522 100644 --- a/source/blender/makesrna/intern/rna_sequencer_api.c +++ b/source/blender/makesrna/intern/rna_sequencer_api.c @@ -49,13 +49,21 @@ # include "WM_api.h" -static void rna_Sequence_swap_internal(Sequence *seq_self, +static StripElem *rna_Sequence_strip_elem_from_frame(ID *id, Sequence *self, int timeline_frame) +{ + Scene *scene = (Scene *)id; + return SEQ_render_give_stripelem(scene, self, timeline_frame); +} + +static void rna_Sequence_swap_internal(ID *id, + Sequence *seq_self, ReportList *reports, Sequence *seq_other) { const char *error_msg; + Scene *scene = (Scene *)id; - if (SEQ_edit_sequence_swap(seq_self, seq_other, &error_msg) == 0) { + if (SEQ_edit_sequence_swap(scene, seq_self, seq_other, &error_msg) == false) { BKE_report(reports, RPT_ERROR, error_msg); } } @@ -247,7 +255,7 @@ static Sequence *rna_Sequences_new_image(ID *id, char dir[FILE_MAX], filename[FILE_MAX]; BLI_split_dirfile(file, dir, filename, sizeof(dir), sizeof(filename)); SEQ_add_image_set_directory(seq, dir); - SEQ_add_image_load_file(seq, 0, filename); + SEQ_add_image_load_file(scene, seq, 0, filename); SEQ_add_image_init_alpha_mode(seq); DEG_relations_tag_update(bmain); @@ -647,7 +655,8 @@ void RNA_api_sequence_strip(StructRNA *srna) {0, NULL, 0, NULL, NULL}, }; - func = RNA_def_function(srna, "strip_elem_from_frame", "SEQ_render_give_stripelem"); + func = RNA_def_function(srna, "strip_elem_from_frame", "rna_Sequence_strip_elem_from_frame"); + RNA_def_function_flag(func, FUNC_USE_SELF_ID); RNA_def_function_ui_description(func, "Return the strip element from a given frame or None"); parm = RNA_def_int(func, "frame", @@ -664,6 +673,7 @@ void RNA_api_sequence_strip(StructRNA *srna) RNA_def_pointer(func, "elem", "SequenceElement", "", "strip element of the current frame")); func = RNA_def_function(srna, "swap", "rna_Sequence_swap_internal"); + RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID); RNA_def_function_flag(func, FUNC_USE_REPORTS); parm = RNA_def_pointer(func, "other", "Sequence", "Other", ""); RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED); diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c index cae86801402..51acb4da5c3 100644 --- a/source/blender/makesrna/intern/rna_space.c +++ b/source/blender/makesrna/intern/rna_space.c @@ -88,7 +88,7 @@ const EnumPropertyItem rna_enum_space_type_items[] = { {SPACE_EMPTY, "EMPTY", ICON_NONE, "Empty", ""}, /* General. */ - RNA_ENUM_ITEM_HEADING("General", NULL), + RNA_ENUM_ITEM_HEADING(N_("General"), NULL), {SPACE_VIEW3D, "VIEW_3D", ICON_VIEW3D, @@ -108,7 +108,7 @@ const EnumPropertyItem rna_enum_space_type_items[] = { {SPACE_CLIP, "CLIP_EDITOR", ICON_TRACKER, "Movie Clip Editor", "Motion tracking tools"}, /* Animation. */ - RNA_ENUM_ITEM_HEADING("Animation", NULL), + RNA_ENUM_ITEM_HEADING(N_("Animation"), NULL), #if 0 {SPACE_ACTION, "TIMELINE", @@ -125,7 +125,7 @@ const EnumPropertyItem rna_enum_space_type_items[] = { {SPACE_NLA, "NLA_EDITOR", ICON_NLA, "Nonlinear Animation", "Combine and layer Actions"}, /* Scripting. */ - RNA_ENUM_ITEM_HEADING("Scripting", NULL), + RNA_ENUM_ITEM_HEADING(N_("Scripting"), NULL), {SPACE_TEXT, "TEXT_EDITOR", ICON_TEXT, @@ -153,7 +153,7 @@ const EnumPropertyItem rna_enum_space_type_items[] = { "screen for general status information"}, /* Data. */ - RNA_ENUM_ITEM_HEADING("Data", NULL), + RNA_ENUM_ITEM_HEADING(N_("Data"), NULL), {SPACE_OUTLINER, "OUTLINER", ICON_OUTLINER, @@ -435,28 +435,28 @@ static const EnumPropertyItem rna_enum_studio_light_items[] = { }; static const EnumPropertyItem rna_enum_view3dshading_render_pass_type_items[] = { - RNA_ENUM_ITEM_HEADING("General", NULL), + RNA_ENUM_ITEM_HEADING(N_("General"), NULL), {EEVEE_RENDER_PASS_COMBINED, "COMBINED", 0, "Combined", ""}, {EEVEE_RENDER_PASS_EMIT, "EMISSION", 0, "Emission", ""}, {EEVEE_RENDER_PASS_ENVIRONMENT, "ENVIRONMENT", 0, "Environment", ""}, {EEVEE_RENDER_PASS_AO, "AO", 0, "Ambient Occlusion", ""}, {EEVEE_RENDER_PASS_SHADOW, "SHADOW", 0, "Shadow", ""}, - RNA_ENUM_ITEM_HEADING("Light", NULL), + RNA_ENUM_ITEM_HEADING(N_("Light"), NULL), {EEVEE_RENDER_PASS_DIFFUSE_LIGHT, "DIFFUSE_LIGHT", 0, "Diffuse Light", ""}, {EEVEE_RENDER_PASS_DIFFUSE_COLOR, "DIFFUSE_COLOR", 0, "Diffuse Color", ""}, {EEVEE_RENDER_PASS_SPECULAR_LIGHT, "SPECULAR_LIGHT", 0, "Specular Light", ""}, {EEVEE_RENDER_PASS_SPECULAR_COLOR, "SPECULAR_COLOR", 0, "Specular Color", ""}, {EEVEE_RENDER_PASS_VOLUME_LIGHT, "VOLUME_LIGHT", 0, "Volume Light", ""}, - RNA_ENUM_ITEM_HEADING("Effects", NULL), + RNA_ENUM_ITEM_HEADING(N_("Effects"), NULL), {EEVEE_RENDER_PASS_BLOOM, "BLOOM", 0, "Bloom", ""}, - RNA_ENUM_ITEM_HEADING("Data", NULL), + RNA_ENUM_ITEM_HEADING(N_("Data"), NULL), {EEVEE_RENDER_PASS_NORMAL, "NORMAL", 0, "Normal", ""}, {EEVEE_RENDER_PASS_MIST, "MIST", 0, "Mist", ""}, - RNA_ENUM_ITEM_HEADING("Shader AOV", NULL), + RNA_ENUM_ITEM_HEADING(N_("Shader AOV"), NULL), {EEVEE_RENDER_PASS_AOV, "AOV", 0, "AOV", ""}, {0, NULL, 0, NULL, NULL}, @@ -1100,7 +1100,7 @@ static bool rna_RegionView3D_is_orthographic_side_view_get(PointerRNA *ptr) return RV3D_VIEW_IS_AXIS(rv3d->view); } -static void rna_RegionView3D_is_orthographic_side_view_set(PointerRNA *ptr, int value) +static void rna_RegionView3D_is_orthographic_side_view_set(PointerRNA *ptr, bool value) { RegionView3D *rv3d = (RegionView3D *)(ptr->data); const bool was_axis_view = RV3D_VIEW_IS_AXIS(rv3d->view); @@ -1609,7 +1609,7 @@ static void rna_SpaceImageEditor_mode_update(Main *bmain, Scene *scene, PointerR } } -static void rna_SpaceImageEditor_show_stereo_set(PointerRNA *ptr, int value) +static void rna_SpaceImageEditor_show_stereo_set(PointerRNA *ptr, bool value) { SpaceImage *sima = (SpaceImage *)(ptr->data); @@ -1664,7 +1664,7 @@ static bool rna_SpaceImageEditor_show_uvedit_get(PointerRNA *ptr) wmWindow *win = ED_screen_window_find(screen, G_MAIN->wm.first); if (win != NULL) { ViewLayer *view_layer = WM_window_get_active_view_layer(win); - obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); + obedit = BKE_view_layer_edit_object_get(view_layer); } return ED_space_image_show_uvedit(sima, obedit); } @@ -1677,7 +1677,7 @@ static bool rna_SpaceImageEditor_show_maskedit_get(PointerRNA *ptr) wmWindow *win = ED_screen_window_find(screen, G_MAIN->wm.first); if (win != NULL) { ViewLayer *view_layer = WM_window_get_active_view_layer(win); - obedit = OBEDIT_FROM_VIEW_LAYER(view_layer); + obedit = BKE_view_layer_edit_object_get(view_layer); } return ED_space_image_check_show_maskedit(sima, obedit); } @@ -2177,7 +2177,7 @@ static void rna_SpaceDopeSheetEditor_action_update(bContext *C, PointerRNA *ptr) ViewLayer *view_layer = CTX_data_view_layer(C); Main *bmain = CTX_data_main(C); - Object *obact = OBACT(view_layer); + Object *obact = BKE_view_layer_active_object_get(view_layer); if (obact == NULL) { return; } @@ -2250,7 +2250,7 @@ static void rna_SpaceDopeSheetEditor_mode_update(bContext *C, PointerRNA *ptr) SpaceAction *saction = (SpaceAction *)(ptr->data); ScrArea *area = CTX_wm_area(C); ViewLayer *view_layer = CTX_data_view_layer(C); - Object *obact = OBACT(view_layer); + Object *obact = BKE_view_layer_active_object_get(view_layer); /* special exceptions for ShapeKey Editor mode */ if (saction->mode == SACTCONT_SHAPEKEY) { @@ -3478,9 +3478,9 @@ static void rna_def_space_mask_info(StructRNA *srna, int noteflag, const char *m RNA_def_property_ui_text(prop, "Edge Display Type", "Display type for mask splines"); RNA_def_property_update(prop, noteflag, NULL); - prop = RNA_def_property(srna, "show_mask_smooth", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "mask_info.draw_flag", MASK_DRAWFLAG_SMOOTH); - RNA_def_property_ui_text(prop, "Display Smooth Splines", ""); + prop = RNA_def_property(srna, "show_mask_spline", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "mask_info.draw_flag", MASK_DRAWFLAG_SPLINE); + RNA_def_property_ui_text(prop, "Show Mask Spline", ""); RNA_def_property_update(prop, noteflag, NULL); prop = RNA_def_property(srna, "show_mask_overlay", PROP_BOOLEAN, PROP_NONE); @@ -3493,6 +3493,13 @@ static void rna_def_space_mask_info(StructRNA *srna, int noteflag, const char *m RNA_def_property_enum_items(prop, overlay_mode_items); RNA_def_property_ui_text(prop, "Overlay Mode", "Overlay mode of rasterized mask"); RNA_def_property_update(prop, noteflag, NULL); + + prop = RNA_def_property(srna, "blend_factor", PROP_FLOAT, PROP_FACTOR); + RNA_def_property_float_sdna(prop, NULL, "mask_info.blend_factor"); + RNA_def_property_range(prop, 0.0f, 1.0f); + RNA_def_property_ui_range(prop, 0, 1., 0.1, 1); + RNA_def_property_ui_text(prop, "Blending Factor", "Overlay blending factor of rasterized mask"); + RNA_def_property_update(prop, noteflag, NULL); } static void rna_def_space_image_uv(BlenderRNA *brna) @@ -3539,6 +3546,7 @@ static void rna_def_space_image_uv(BlenderRNA *brna) RNA_def_property_enum_sdna(prop, NULL, "dt_uvstretch"); RNA_def_property_enum_items(prop, dt_uvstretch_items); RNA_def_property_ui_text(prop, "Display Stretch Type", "Type of stretch to display"); + RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_MESH); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, NULL); prop = RNA_def_property(srna, "show_modified_edges", PROP_BOOLEAN, PROP_NONE); @@ -4192,6 +4200,14 @@ static void rna_def_space_view3d_shading(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Shader AOV Name", "Name of the active Shader AOV"); RNA_def_property_flag(prop, PROP_HIDDEN); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + + prop = RNA_def_property(srna, "use_compositor", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_SHADING_COMPOSITOR); + RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); + RNA_def_property_boolean_default(prop, false); + RNA_def_property_ui_text( + prop, "Compositor", "Preview the compositor output inside the viewport"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D | NS_VIEW3D_SHADING, NULL); } static void rna_def_space_view3d_overlay(BlenderRNA *brna) @@ -4547,7 +4563,7 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna) RNA_def_property_enum_items(prop, rna_enum_curve_display_handle_items); RNA_def_property_ui_text( prop, "Display Handles", "Limit the display of curve handles in edit mode"); - RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_GPencil_update"); prop = RNA_def_property(srna, "show_curve_normals", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "overlay.edit_flag", V3D_OVERLAY_EDIT_CU_NORMALS); @@ -4720,6 +4736,13 @@ static void rna_def_space_view3d_overlay(BlenderRNA *brna) RNA_def_property_range(prop, 0.0f, 1.0f); RNA_def_property_ui_text(prop, "Opacity", "Vertex Paint mix factor"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_GPencil_update"); + + /* Developer Debug overlay */ + + prop = RNA_def_property(srna, "use_debug_freeze_view_culling", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "debug_flag", V3D_DEBUG_FREEZE_CULLING); + RNA_def_property_ui_text(prop, "Freeze Culling", "Freeze view culling bounds"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL); } static void rna_def_space_view3d(BlenderRNA *brna) @@ -5291,6 +5314,7 @@ static void rna_def_space_image_overlay(BlenderRNA *brna) prop = RNA_def_property(srna, "show_overlays", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "overlay.flag", SI_OVERLAY_SHOW_OVERLAYS); RNA_def_property_ui_text(prop, "Show Overlays", "Display overlays like UV Maps and Metadata"); + RNA_def_property_update(prop, NC_SPACE | ND_SPACE_IMAGE, NULL); prop = RNA_def_property(srna, "show_grid_background", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "overlay.flag", SI_OVERLAY_SHOW_GRID_BACKGROUND); @@ -5893,7 +5917,7 @@ static void rna_def_space_text(BlenderRNA *brna) prop = RNA_def_property(srna, "font_size", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "lheight"); - RNA_def_property_range(prop, 8, 32); + RNA_def_property_range(prop, 1, 256); /* Large range since Hi-DPI scales down size. */ RNA_def_property_ui_text(prop, "Font Size", "Font size to use for displaying the text"); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TEXT, NULL); @@ -6387,7 +6411,7 @@ static void rna_def_space_console(BlenderRNA *brna) /* display */ prop = RNA_def_property(srna, "font_size", PROP_INT, PROP_NONE); /* copied from text editor */ RNA_def_property_int_sdna(prop, NULL, "lheight"); - RNA_def_property_range(prop, 8, 32); + RNA_def_property_range(prop, 1, 256); /* Large range since Hi-DPI scales down size. */ RNA_def_property_ui_text(prop, "Font Size", "Font size to use for displaying the text"); RNA_def_property_update(prop, 0, "rna_SpaceConsole_rect_update"); @@ -6577,7 +6601,7 @@ static void rna_def_fileselect_params(BlenderRNA *brna) static const EnumPropertyItem display_size_items[] = { {64, "TINY", 0, "Tiny", ""}, {96, "SMALL", 0, "Small", ""}, - {128, "NORMAL", 0, "Regular", ""}, + {128, "NORMAL", 0, "Medium", ""}, {192, "LARGE", 0, "Large", ""}, {0, NULL, 0, NULL, NULL}, }; @@ -7798,12 +7822,6 @@ static void rna_def_spreadsheet_row_filter(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Color Value", ""); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_SPREADSHEET, NULL); - prop = RNA_def_property(srna, "value_byte_color", PROP_INT, PROP_NONE); - RNA_def_property_array(prop, 4); - RNA_def_property_range(prop, 0, 255); - RNA_def_property_ui_text(prop, "Byte Color Value", ""); - RNA_def_property_update(prop, NC_SPACE | ND_SPACE_SPREADSHEET, NULL); - prop = RNA_def_property(srna, "value_string", PROP_STRING, PROP_NONE); RNA_def_property_ui_text(prop, "Text Value", ""); RNA_def_property_update(prop, NC_SPACE | ND_SPACE_SPREADSHEET, NULL); diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c index dabb89bcd5e..9de32c24702 100644 --- a/source/blender/makesrna/intern/rna_ui.c +++ b/source/blender/makesrna/intern/rna_ui.c @@ -440,7 +440,7 @@ static PointerRNA rna_Panel_custom_data_get(PointerRNA *ptr) } /* UIList */ -static unsigned int rna_UIList_filter_const_FILTER_ITEM_get(PointerRNA *UNUSED(ptr)) +static int rna_UIList_filter_const_FILTER_ITEM_get(PointerRNA *UNUSED(ptr)) { return UILST_FLT_ITEM; } @@ -473,7 +473,7 @@ static int rna_UIList_list_id_length(PointerRNA *ptr) } static void uilist_draw_item(uiList *ui_list, - bContext *C, + const bContext *C, uiLayout *layout, PointerRNA *dataptr, PointerRNA *itemptr, @@ -507,7 +507,7 @@ static void uilist_draw_item(uiList *ui_list, RNA_parameter_list_free(&list); } -static void uilist_draw_filter(uiList *ui_list, bContext *C, uiLayout *layout) +static void uilist_draw_filter(uiList *ui_list, const bContext *C, uiLayout *layout) { extern FunctionRNA rna_UIList_draw_filter_func; @@ -527,7 +527,7 @@ static void uilist_draw_filter(uiList *ui_list, bContext *C, uiLayout *layout) } static void uilist_filter_items(uiList *ui_list, - bContext *C, + const bContext *C, PointerRNA *dataptr, const char *propname) { diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c index e05e4a03f40..e15b16e7740 100644 --- a/source/blender/makesrna/intern/rna_ui_api.c +++ b/source/blender/makesrna/intern/rna_ui_api.c @@ -1813,8 +1813,7 @@ void RNA_api_ui_layout(StructRNA *srna) func = RNA_def_function( srna, "template_colormanaged_view_settings", "uiTemplateColormanagedViewSettings"); - RNA_def_function_ui_description( - func, "Item. A widget to control color managed view settings settings."); + RNA_def_function_ui_description(func, "Item. A widget to control color managed view settings."); RNA_def_function_flag(func, FUNC_USE_CONTEXT); api_ui_item_rna_common(func); # if 0 diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c index 40dc1254a7d..61d4edccb06 100644 --- a/source/blender/makesrna/intern/rna_userdef.c +++ b/source/blender/makesrna/intern/rna_userdef.c @@ -38,23 +38,6 @@ #include "BLT_lang.h" -#ifdef WITH_OPENSUBDIV -static const EnumPropertyItem opensubdiv_compute_type_items[] = { - {USER_OPENSUBDIV_COMPUTE_NONE, "NONE", 0, "None", ""}, - {USER_OPENSUBDIV_COMPUTE_CPU, "CPU", 0, "CPU", ""}, - {USER_OPENSUBDIV_COMPUTE_OPENMP, "OPENMP", 0, "OpenMP", ""}, - {USER_OPENSUBDIV_COMPUTE_OPENCL, "OPENCL", 0, "OpenCL", ""}, - {USER_OPENSUBDIV_COMPUTE_CUDA, "CUDA", 0, "CUDA", ""}, - {USER_OPENSUBDIV_COMPUTE_GLSL_TRANSFORM_FEEDBACK, - "GLSL_TRANSFORM_FEEDBACK", - 0, - "GLSL Transform Feedback", - ""}, - {USER_OPENSUBDIV_COMPUTE_GLSL_COMPUTE, "GLSL_COMPUTE", 0, "GLSL Compute", ""}, - {0, NULL, 0, NULL, NULL}, -}; -#endif - const EnumPropertyItem rna_enum_preference_section_items[] = { {USER_SECTION_INTERFACE, "INTERFACE", 0, "Interface", ""}, {USER_SECTION_THEME, "THEMES", 0, "Themes", ""}, @@ -189,10 +172,6 @@ static const EnumPropertyItem rna_enum_userdef_viewport_aa_items[] = { # include "UI_interface.h" -# ifdef WITH_OPENSUBDIV -# include "opensubdiv_capi.h" -# endif - # ifdef WITH_SDL_DYNLOAD # include "sdlew.h" # endif @@ -728,55 +707,6 @@ static PointerRNA rna_Theme_space_list_generic_get(PointerRNA *ptr) return rna_pointer_inherit_refine(ptr, &RNA_ThemeSpaceListGeneric, ptr->data); } -# ifdef WITH_OPENSUBDIV -static const EnumPropertyItem *rna_userdef_opensubdiv_compute_type_itemf(bContext *UNUSED(C), - PointerRNA *UNUSED(ptr), - PropertyRNA *UNUSED(prop), - bool *r_free) -{ - EnumPropertyItem *item = NULL; - int totitem = 0; - int evaluators = openSubdiv_getAvailableEvaluators(); - - RNA_enum_items_add_value( - &item, &totitem, opensubdiv_compute_type_items, USER_OPENSUBDIV_COMPUTE_NONE); - -# define APPEND_COMPUTE(compute) \ - if (evaluators & OPENSUBDIV_EVALUATOR_##compute) { \ - RNA_enum_items_add_value( \ - &item, &totitem, opensubdiv_compute_type_items, USER_OPENSUBDIV_COMPUTE_##compute); \ - } \ - ((void)0) - - APPEND_COMPUTE(CPU); - APPEND_COMPUTE(OPENMP); - APPEND_COMPUTE(OPENCL); - APPEND_COMPUTE(CUDA); - APPEND_COMPUTE(GLSL_TRANSFORM_FEEDBACK); - APPEND_COMPUTE(GLSL_COMPUTE); - -# undef APPEND_COMPUTE - - RNA_enum_item_end(&item, &totitem); - *r_free = true; - - return item; -} - -static void rna_userdef_opensubdiv_update(Main *bmain, - Scene *UNUSED(scene), - PointerRNA *UNUSED(ptr)) -{ - Object *object; - - for (object = bmain->objects.first; object; object = object->id.next) { - DEG_id_tag_update(&object->id, ID_RECALC_TRANSFORM); - } - USERDEF_TAG_DIRTY; -} - -# endif - static const EnumPropertyItem *rna_userdef_audio_device_itemf(bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), @@ -1101,16 +1031,6 @@ int rna_show_statusbar_vram_editable(struct PointerRNA *UNUSED(ptr), const char return GPU_mem_stats_supported() ? PROP_EDITABLE : 0; } -static int rna_userdef_experimental_use_new_curve_tools_editable(struct PointerRNA *UNUSED(ptr), - const char **r_info) -{ - if (U.experimental.use_new_curves_type) { - return PROP_EDITABLE; - } - *r_info = "Only available when new curves type is enabled"; - return 0; -} - #else # define USERDEF_TAG_DIRTY_PROPERTY_UPDATE_ENABLE \ @@ -1978,6 +1898,7 @@ static void rna_def_userdef_theme_spaces_edge(StructRNA *srna) prop = RNA_def_property(srna, "edge_crease", PROP_FLOAT, PROP_COLOR_GAMMA); RNA_def_property_array(prop, 3); RNA_def_property_ui_text(prop, "Edge Crease", ""); + RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_WINDOWMANAGER); RNA_def_property_update(prop, 0, "rna_userdef_theme_update"); prop = RNA_def_property(srna, "edge_bevel", PROP_FLOAT, PROP_COLOR_GAMMA); @@ -2859,7 +2780,7 @@ static void rna_def_userdef_theme_space_node(BlenderRNA *brna) prop = RNA_def_property(srna, "wire", PROP_FLOAT, PROP_COLOR_GAMMA); RNA_def_property_float_sdna(prop, NULL, "wire"); - RNA_def_property_array(prop, 3); + RNA_def_property_array(prop, 4); RNA_def_property_ui_text(prop, "Wires", ""); RNA_def_property_update(prop, 0, "rna_userdef_theme_update"); @@ -5645,8 +5566,8 @@ static void rna_def_userdef_system(BlenderRNA *brna) RNA_def_property_ui_text( prop, "VBO Time Out", - "Time since last access of a GL Vertex buffer object in seconds after which it is freed " - "(set to 0 to keep vbo allocated)"); + "Time since last access of a GL vertex buffer object in seconds after which it is freed " + "(set to 0 to keep VBO allocated)"); prop = RNA_def_property(srna, "vbo_collection_rate", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "vbocollectrate"); @@ -5654,7 +5575,7 @@ static void rna_def_userdef_system(BlenderRNA *brna) RNA_def_property_ui_text( prop, "VBO Collection Rate", - "Number of seconds between each run of the GL Vertex buffer object garbage collector"); + "Number of seconds between each run of the GL vertex buffer object garbage collector"); /* Select */ @@ -5709,17 +5630,6 @@ static void rna_def_userdef_system(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Audio Channels", "Audio channel count"); RNA_def_property_update(prop, 0, "rna_UserDef_audio_update"); -# ifdef WITH_OPENSUBDIV - prop = RNA_def_property(srna, "opensubdiv_compute_type", PROP_ENUM, PROP_NONE); - RNA_def_property_flag(prop, PROP_ENUM_NO_CONTEXT); - RNA_def_property_enum_sdna(prop, NULL, "opensubdiv_compute_type"); - RNA_def_property_enum_items(prop, opensubdiv_compute_type_items); - RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_userdef_opensubdiv_compute_type_itemf"); - RNA_def_property_ui_text( - prop, "OpenSubdiv Compute Type", "Type of computer back-end used with OpenSubdiv"); - RNA_def_property_update(prop, NC_SPACE | ND_SPACE_PROPERTIES, "rna_userdef_opensubdiv_update"); -# endif - # ifdef WITH_CYCLES prop = RNA_def_property(srna, "legacy_compute_device_type", PROP_INT, PROP_NONE); RNA_def_property_int_sdna(prop, NULL, "compute_device_type"); @@ -6405,13 +6315,8 @@ static void rna_def_userdef_experimental(BlenderRNA *brna) "reduces execution time and memory usage)"); RNA_def_property_update(prop, 0, "rna_userdef_update"); - prop = RNA_def_property(srna, "use_new_curves_type", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_sdna(prop, NULL, "use_new_curves_type", 1); - RNA_def_property_ui_text(prop, "New Curves Type", "Enable the new curves data type in the UI"); - prop = RNA_def_property(srna, "use_new_curves_tools", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "use_new_curves_tools", 1); - RNA_def_property_editable_func(prop, "rna_userdef_experimental_use_new_curve_tools_editable"); RNA_def_property_ui_text( prop, "New Curves Tools", "Enable additional features for the new curves data block"); @@ -6425,6 +6330,10 @@ static void rna_def_userdef_experimental(BlenderRNA *brna) RNA_def_property_ui_text( prop, "Sculpt Mode Tilt Support", "Support for pen tablet tilt events in Sculpt Mode"); + prop = RNA_def_property(srna, "use_realtime_compositor", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "use_realtime_compositor", 1); + RNA_def_property_ui_text(prop, "Realtime Compositor", "Enable the new realtime compositor"); + prop = RNA_def_property(srna, "use_sculpt_texture_paint", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "use_sculpt_texture_paint", 1); RNA_def_property_ui_text(prop, "Sculpt Texture Paint", "Use texture painting in Sculpt Mode"); @@ -6463,6 +6372,14 @@ static void rna_def_userdef_experimental(BlenderRNA *brna) prop = RNA_def_property(srna, "enable_eevee_next", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_sdna(prop, NULL, "enable_eevee_next", 1); RNA_def_property_ui_text(prop, "EEVEE Next", "Enable the new EEVEE codebase, requires restart"); + + prop = RNA_def_property(srna, "use_viewport_debug", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "use_viewport_debug", 1); + RNA_def_property_ui_text(prop, + "Viewport Debug", + "Enable viewport debugging options for developpers in the overlays " + "pop-over"); + RNA_def_property_update(prop, 0, "rna_userdef_ui_update"); } static void rna_def_userdef_addon_collection(BlenderRNA *brna, PropertyRNA *cprop) diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c index 3ff9e6be3ce..ac1803b0a11 100644 --- a/source/blender/makesrna/intern/rna_wm.c +++ b/source/blender/makesrna/intern/rna_wm.c @@ -138,6 +138,7 @@ const EnumPropertyItem rna_enum_wm_job_type_items[] = { {WM_JOB_TYPE_RENDER_PREVIEW, "RENDER_PREVIEW", 0, "Rendering previews", ""}, {WM_JOB_TYPE_OBJECT_BAKE, "OBJECT_BAKE", 0, "Object Baking", ""}, {WM_JOB_TYPE_COMPOSITE, "COMPOSITE", 0, "Compositing", ""}, + {WM_JOB_TYPE_SHADER_COMPILATION, "SHADER_COMPILATION", 0, "Shader compilation", ""}, {0, NULL, 0, NULL, NULL}, }; @@ -606,14 +607,14 @@ static PointerRNA rna_OperatorMacro_properties_get(PointerRNA *ptr) static void rna_Event_ascii_get(PointerRNA *ptr, char *value) { const wmEvent *event = ptr->data; - value[0] = event->ascii; + value[0] = WM_event_utf8_to_ascii(event); value[1] = '\0'; } static int rna_Event_ascii_length(PointerRNA *ptr) { const wmEvent *event = ptr->data; - return (event->ascii) ? 1 : 0; + return WM_event_utf8_to_ascii(event) ? 1 : 0; } static void rna_Event_unicode_get(PointerRNA *ptr, char *value) @@ -863,6 +864,21 @@ static void rna_Window_view_layer_set(PointerRNA *ptr, WM_window_set_active_view_layer(win, view_layer); } +static void rna_KeyMap_modal_event_values_items_begin(CollectionPropertyIterator *iter, + PointerRNA *ptr) +{ + wmKeyMap *km = ptr->data; + + const EnumPropertyItem *items = rna_enum_keymap_propvalue_items; + if ((km->flag & KEYMAP_MODAL) != 0 && km->modal_items != NULL) { + items = km->modal_items; + } + + const int totitem = RNA_enum_items_count(items); + + rna_iterator_array_begin(iter, (void *)items, sizeof(EnumPropertyItem), totitem, false, NULL); +} + static PointerRNA rna_KeyMapItem_properties_get(PointerRNA *ptr) { wmKeyMapItem *kmi = ptr->data; @@ -2065,6 +2081,12 @@ static void rna_def_event(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Value", "The type of event, only applies to some"); + prop = RNA_def_property(srna, "value_prev", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "prev_val"); + RNA_def_property_enum_items(prop, rna_enum_event_value_items); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Previous Value", "The type of event, only applies to some"); + prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "type"); RNA_def_property_enum_items(prop, rna_enum_event_type_items); @@ -2072,6 +2094,13 @@ static void rna_def_event(BlenderRNA *brna) RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_ui_text(prop, "Type", ""); + prop = RNA_def_property(srna, "type_prev", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "prev_type"); + RNA_def_property_enum_items(prop, rna_enum_event_type_items); + RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UI_EVENTS); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_ui_text(prop, "Previous Type", ""); + prop = RNA_def_property(srna, "direction", PROP_ENUM, PROP_NONE); RNA_def_property_enum_sdna(prop, NULL, "direction"); RNA_def_property_enum_items(prop, rna_enum_event_direction_items); @@ -2603,6 +2632,23 @@ static void rna_def_keyconfig(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Children Expanded", "Children expanded in the user interface"); RNA_def_property_ui_icon(prop, ICON_DISCLOSURE_TRI_RIGHT, 1); + prop = RNA_def_property(srna, "modal_event_values", PROP_COLLECTION, PROP_NONE); + RNA_def_property_clear_flag(prop, PROP_EDITABLE); + RNA_def_property_struct_type(prop, "EnumPropertyItem"); + RNA_def_property_collection_funcs(prop, + "rna_KeyMap_modal_event_values_items_begin", + "rna_iterator_array_next", + "rna_iterator_array_end", + "rna_iterator_array_get", + NULL, + NULL, + NULL, + NULL); + RNA_def_property_ui_text(prop, + "Modal Events", + "Give access to the possible event values of this modal keymap's items " + "(#KeyMapItem.propvalue), for API introspection"); + RNA_api_keymap(srna); /* KeyMapItem */ diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c index b9f36d35ee8..b82458c4442 100644 --- a/source/blender/makesrna/intern/rna_wm_api.c +++ b/source/blender/makesrna/intern/rna_wm_api.c @@ -625,7 +625,7 @@ static wmEvent *rna_Window_event_add_simulate(wmWindow *win, return NULL; } } - if (ELEM(type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { + if (ISMOUSE_MOTION(type)) { if (value != KM_NOTHING) { BKE_report(reports, RPT_ERROR, "Value: must be 'NOTHING' for motion"); return NULL; @@ -639,16 +639,12 @@ static wmEvent *rna_Window_event_add_simulate(wmWindow *win, } /* TODO: validate NDOF. */ - char ascii = 0; if (unicode != NULL) { int len = BLI_str_utf8_size(unicode); if (len == -1 || unicode[len] != '\0') { BKE_report(reports, RPT_ERROR, "Only a single character supported"); return NULL; } - if (len == 1 && isascii(unicode[0])) { - ascii = unicode[0]; - } } wmEvent e = *win->eventstate; @@ -672,10 +668,8 @@ static wmEvent *rna_Window_event_add_simulate(wmWindow *win, e.modifier |= KM_OSKEY; } - e.ascii = '\0'; e.utf8_buf[0] = '\0'; if (unicode != NULL) { - e.ascii = ascii; STRNCPY(e.utf8_buf, unicode); } diff --git a/source/blender/makesrna/intern/rna_wm_gizmo.c b/source/blender/makesrna/intern/rna_wm_gizmo.c index 6c3d96726bb..a4630415ccd 100644 --- a/source/blender/makesrna/intern/rna_wm_gizmo.c +++ b/source/blender/makesrna/intern/rna_wm_gizmo.c @@ -353,7 +353,7 @@ static PointerRNA rna_Gizmo_properties_get(PointerRNA *ptr) } # define RNA_GIZMO_FLAG_RO_DEF(func_id, member_id, flag_value) \ - static int rna_Gizmo_##func_id##_get(PointerRNA *ptr) \ + static bool rna_Gizmo_##func_id##_get(PointerRNA *ptr) \ { \ wmGizmo *gz = ptr->data; \ return (gz->member_id & flag_value) != 0; \ @@ -1398,6 +1398,11 @@ static void rna_def_gizmogroup(BlenderRNA *brna) 0, "Tool Init", "Postpone running until tool operator run (when used with a tool)"}, + {WM_GIZMOGROUPTYPE_TOOL_FALLBACK_KEYMAP, + "TOOL_FALLBACK_KEYMAP", + 0, + "Use fallback tools keymap", + "Add fallback tools keymap to this gizmo type"}, {WM_GIZMOGROUPTYPE_VR_REDRAWS, "VR_REDRAWS", 0, diff --git a/source/blender/makesrna/intern/rna_wm_gizmo_api.c b/source/blender/makesrna/intern/rna_wm_gizmo_api.c index 419dfa68305..760121d2279 100644 --- a/source/blender/makesrna/intern/rna_wm_gizmo_api.c +++ b/source/blender/makesrna/intern/rna_wm_gizmo_api.c @@ -211,7 +211,15 @@ void RNA_api_gizmo(StructRNA *srna) RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); RNA_def_property_multi_array(parm, 2, rna_matrix_dimsize_4x4); RNA_def_property_ui_text(parm, "", "The matrix to transform"); - RNA_def_int(func, "select_id", -1, -1, INT_MAX, "Zero when not selecting", "", -1, INT_MAX); + RNA_def_int(func, + "select_id", + -1, + -1, + INT_MAX, + "ID to use when gizmo is selectable. Use -1 when not selecting", + "", + -1, + INT_MAX); /* draw_preset_box */ func = RNA_def_function(srna, "draw_preset_arrow", "rna_gizmo_draw_preset_arrow"); @@ -221,7 +229,15 @@ void RNA_api_gizmo(StructRNA *srna) RNA_def_property_multi_array(parm, 2, rna_matrix_dimsize_4x4); RNA_def_property_ui_text(parm, "", "The matrix to transform"); RNA_def_enum(func, "axis", rna_enum_object_axis_items, 2, "", "Arrow Orientation"); - RNA_def_int(func, "select_id", -1, -1, INT_MAX, "Zero when not selecting", "", -1, INT_MAX); + RNA_def_int(func, + "select_id", + -1, + -1, + INT_MAX, + "ID to use when gizmo is selectable. Use -1 when not selecting", + "", + -1, + INT_MAX); func = RNA_def_function(srna, "draw_preset_circle", "rna_gizmo_draw_preset_circle"); RNA_def_function_ui_description(func, "Draw a box"); @@ -230,7 +246,15 @@ void RNA_api_gizmo(StructRNA *srna) RNA_def_property_multi_array(parm, 2, rna_matrix_dimsize_4x4); RNA_def_property_ui_text(parm, "", "The matrix to transform"); RNA_def_enum(func, "axis", rna_enum_object_axis_items, 2, "", "Arrow Orientation"); - RNA_def_int(func, "select_id", -1, -1, INT_MAX, "Zero when not selecting", "", -1, INT_MAX); + RNA_def_int(func, + "select_id", + -1, + -1, + INT_MAX, + "ID to use when gizmo is selectable. Use -1 when not selecting", + "", + -1, + INT_MAX); /* -------------------------------------------------------------------- */ /* Other Shapes */ @@ -243,7 +267,15 @@ void RNA_api_gizmo(StructRNA *srna) RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED); parm = RNA_def_int(func, "face_map", 0, 0, INT_MAX, "Face map index", "", 0, INT_MAX); RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); - RNA_def_int(func, "select_id", -1, -1, INT_MAX, "Zero when not selecting", "", -1, INT_MAX); + RNA_def_int(func, + "select_id", + -1, + -1, + INT_MAX, + "ID to use when gizmo is selectable. Use -1 when not selecting", + "", + -1, + INT_MAX); /* -------------------------------------------------------------------- */ /* Property API */ diff --git a/source/blender/makesrna/intern/rna_workspace.c b/source/blender/makesrna/intern/rna_workspace.c index 0b6c3934985..2294c2c2b2d 100644 --- a/source/blender/makesrna/intern/rna_workspace.c +++ b/source/blender/makesrna/intern/rna_workspace.c @@ -193,7 +193,7 @@ static int rna_WorkSpaceTool_index_get(PointerRNA *ptr) return (tref->runtime) ? tref->runtime->index : 0; } -static int rna_WorkSpaceTool_has_datablock_get(PointerRNA *ptr) +static bool rna_WorkSpaceTool_has_datablock_get(PointerRNA *ptr) { bToolRef *tref = ptr->data; return (tref->runtime) ? (tref->runtime->data_block[0] != '\0') : false; @@ -413,6 +413,14 @@ static void rna_def_workspace(BlenderRNA *brna) RNA_def_property_ui_text( prop, "Object Mode", "Switch to this object mode when activating the workspace"); + prop = RNA_def_property(srna, "use_pin_scene", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flags", WORKSPACE_USE_PIN_SCENE); + RNA_def_property_ui_text(prop, + "Pin Scene", + "Remember the last used scene for the workspace and switch to it " + "whenever this workspace is activated again"); + RNA_def_property_update(prop, NC_WORKSPACE, NULL); + /* Flags */ prop = RNA_def_property(srna, "use_filter_by_owner", PROP_BOOLEAN, PROP_NONE); RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); |