diff options
author | Antonio Vazquez <blendergit@gmail.com> | 2020-02-07 21:10:15 +0300 |
---|---|---|
committer | Antonio Vazquez <blendergit@gmail.com> | 2020-02-07 21:10:15 +0300 |
commit | 4e2cb23bbd1081a025d4325852b4d5aac6fe930a (patch) | |
tree | a4e79120fa58f0bf356515717a803e721e3e6e95 | |
parent | 6fda1c807303a67545f723dc64b54f2f54a9b2e9 (diff) | |
parent | 323808ca5a8da06030dedce9760eefeb7426646b (diff) |
Merge branch 'greasepencil-object' into greasepencil-refactor
-rw-r--r-- | source/blender/blenkernel/BKE_deform.h | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_modifier.h | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/fcurve.c | 286 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_allocator.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_array_cxx.h | 6 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_array_ref.h | 10 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_vector.h | 6 | ||||
-rw-r--r-- | source/blender/editors/object/object_relations.c | 6 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_modifier_types.h | 8 | ||||
-rw-r--r-- | source/blender/modifiers/MOD_modifiertypes.h | 8 |
10 files changed, 202 insertions, 145 deletions
diff --git a/source/blender/blenkernel/BKE_deform.h b/source/blender/blenkernel/BKE_deform.h index fd7fa632999..ca06716599c 100644 --- a/source/blender/blenkernel/BKE_deform.h +++ b/source/blender/blenkernel/BKE_deform.h @@ -20,6 +20,10 @@ #ifndef __BKE_DEFORM_H__ #define __BKE_DEFORM_H__ +#ifdef __cplusplus +extern "C" { +#endif + /** \file * \ingroup bke * \brief support for deformation groups and hooks. @@ -142,4 +146,8 @@ void BKE_defvert_extract_vgroup_to_polyweights(struct MDeformVert *dvert, void BKE_defvert_weight_to_rgb(float r_rgb[3], const float weight); +#ifdef __cplusplus +} +#endif + #endif /* __BKE_DEFORM_H__ */ diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h index 1e549849989..0872550d7ae 100644 --- a/source/blender/blenkernel/BKE_modifier.h +++ b/source/blender/blenkernel/BKE_modifier.h @@ -20,14 +20,14 @@ * \ingroup bke */ -#ifdef __cplusplus -extern "C" { -#endif - #include "DNA_modifier_types.h" /* needed for all enum typdefs */ #include "BLI_compiler_attrs.h" #include "BKE_customdata.h" +#ifdef __cplusplus +extern "C" { +#endif + struct BMEditMesh; struct CustomData_MeshMasks; struct DepsNodeHandle; diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index 5708cb0379b..251c6421d66 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -1320,60 +1320,7 @@ static float dtar_get_prop_val(ChannelDriver *driver, DriverTarget *dtar) RNA_id_pointer_create(id, &id_ptr); /* get property to read from, and get value as appropriate */ - if (RNA_path_resolve_property_full(&id_ptr, dtar->rna_path, &ptr, &prop, &index)) { - if (RNA_property_array_check(prop)) { - /* array */ - if ((index >= 0) && (index < RNA_property_array_length(&ptr, prop))) { - switch (RNA_property_type(prop)) { - case PROP_BOOLEAN: - value = (float)RNA_property_boolean_get_index(&ptr, prop, index); - break; - case PROP_INT: - value = (float)RNA_property_int_get_index(&ptr, prop, index); - break; - case PROP_FLOAT: - value = RNA_property_float_get_index(&ptr, prop, index); - break; - default: - break; - } - } - else { - /* out of bounds */ - if (G.debug & G_DEBUG) { - CLOG_ERROR(&LOG, - "Driver Evaluation Error: array index is out of bounds for %s -> %s (%d)", - id->name, - dtar->rna_path, - index); - } - - driver->flag |= DRIVER_FLAG_INVALID; - dtar->flag |= DTAR_FLAG_INVALID; - return 0.0f; - } - } - else { - /* not an array */ - switch (RNA_property_type(prop)) { - case PROP_BOOLEAN: - value = (float)RNA_property_boolean_get(&ptr, prop); - break; - case PROP_INT: - value = (float)RNA_property_int_get(&ptr, prop); - break; - case PROP_FLOAT: - value = RNA_property_float_get(&ptr, prop); - break; - case PROP_ENUM: - value = (float)RNA_property_enum_get(&ptr, prop); - break; - default: - break; - } - } - } - else { + if (!RNA_path_resolve_property_full(&id_ptr, dtar->rna_path, &ptr, &prop, &index)) { /* path couldn't be resolved */ if (G.debug & G_DEBUG) { CLOG_ERROR(&LOG, @@ -1387,6 +1334,57 @@ static float dtar_get_prop_val(ChannelDriver *driver, DriverTarget *dtar) return 0.0f; } + if (RNA_property_array_check(prop)) { + /* array */ + if (index < 0 || index >= RNA_property_array_length(&ptr, prop)) { + /* out of bounds */ + if (G.debug & G_DEBUG) { + CLOG_ERROR(&LOG, + "Driver Evaluation Error: array index is out of bounds for %s -> %s (%d)", + id->name, + dtar->rna_path, + index); + } + + driver->flag |= DRIVER_FLAG_INVALID; + dtar->flag |= DTAR_FLAG_INVALID; + return 0.0f; + } + + switch (RNA_property_type(prop)) { + case PROP_BOOLEAN: + value = (float)RNA_property_boolean_get_index(&ptr, prop, index); + break; + case PROP_INT: + value = (float)RNA_property_int_get_index(&ptr, prop, index); + break; + case PROP_FLOAT: + value = RNA_property_float_get_index(&ptr, prop, index); + break; + default: + break; + } + } + else { + /* not an array */ + switch (RNA_property_type(prop)) { + case PROP_BOOLEAN: + value = (float)RNA_property_boolean_get(&ptr, prop); + break; + case PROP_INT: + value = (float)RNA_property_int_get(&ptr, prop); + break; + case PROP_FLOAT: + value = RNA_property_float_get(&ptr, prop); + break; + case PROP_ENUM: + value = (float)RNA_property_enum_get(&ptr, prop); + break; + default: + break; + } + } + /* if we're still here, we should be ok... */ dtar->flag &= ~DTAR_FLAG_INVALID; return value; @@ -2356,6 +2354,98 @@ float driver_get_variable_value(ChannelDriver *driver, DriverVar *dvar) return dvar->curval; } +static void evaluate_driver_sum(ChannelDriver *driver) +{ + DriverVar *dvar; + + /* check how many variables there are first (i.e. just one?) */ + if (BLI_listbase_is_single(&driver->variables)) { + /* just one target, so just use that */ + dvar = driver->variables.first; + driver->curval = driver_get_variable_value(driver, dvar); + return; + } + + /* more than one target, so average the values of the targets */ + float value = 0.0f; + int tot = 0; + + /* loop through targets, adding (hopefully we don't get any overflow!) */ + for (dvar = driver->variables.first; dvar; dvar = dvar->next) { + value += driver_get_variable_value(driver, dvar); + tot++; + } + + /* perform operations on the total if appropriate */ + if (driver->type == DRIVER_TYPE_AVERAGE) { + driver->curval = tot ? (value / (float)tot) : 0.0f; + } + else { + driver->curval = value; + } +} + +static void evaluate_driver_min_max(ChannelDriver *driver) +{ + DriverVar *dvar; + float value = 0.0f; + + /* loop through the variables, getting the values and comparing them to existing ones */ + for (dvar = driver->variables.first; dvar; dvar = dvar->next) { + /* get value */ + float tmp_val = driver_get_variable_value(driver, dvar); + + /* store this value if appropriate */ + if (dvar->prev) { + /* check if greater/smaller than the baseline */ + if (driver->type == DRIVER_TYPE_MAX) { + /* max? */ + if (tmp_val > value) { + value = tmp_val; + } + } + else { + /* min? */ + if (tmp_val < value) { + value = tmp_val; + } + } + } + else { + /* first item - make this the baseline for comparisons */ + value = tmp_val; + } + } + + /* store value in driver */ + driver->curval = value; +} + +static void evaluate_driver_python(PathResolvedRNA *anim_rna, + ChannelDriver *driver, + ChannelDriver *driver_orig, + const float evaltime) +{ + /* check for empty or invalid expression */ + if ((driver_orig->expression[0] == '\0') || (driver_orig->flag & DRIVER_FLAG_INVALID)) { + driver->curval = 0.0f; + } + else if (!driver_try_evaluate_simple_expr(driver, driver_orig, &driver->curval, evaltime)) { +#ifdef WITH_PYTHON + /* this evaluates the expression using Python, and returns its result: + * - on errors it reports, then returns 0.0f + */ + BLI_mutex_lock(&python_driver_lock); + + driver->curval = BPY_driver_exec(anim_rna, driver, driver_orig, evaltime); + + BLI_mutex_unlock(&python_driver_lock); +#else /* WITH_PYTHON*/ + UNUSED_VARS(anim_rna, evaltime); +#endif /* WITH_PYTHON*/ + } +} + /* Evaluate an Channel-Driver to get a 'time' value to use instead of "evaltime" * - "evaltime" is the frame at which F-Curve is being evaluated * - has to return a float value @@ -2366,8 +2456,6 @@ float evaluate_driver(PathResolvedRNA *anim_rna, ChannelDriver *driver_orig, const float evaltime) { - DriverVar *dvar; - /* check if driver can be evaluated */ if (driver_orig->flag & DRIVER_FLAG_INVALID) { return 0.0f; @@ -2376,99 +2464,21 @@ float evaluate_driver(PathResolvedRNA *anim_rna, switch (driver->type) { case DRIVER_TYPE_AVERAGE: /* average values of driver targets */ case DRIVER_TYPE_SUM: /* sum values of driver targets */ - { - /* check how many variables there are first (i.e. just one?) */ - if (BLI_listbase_is_single(&driver->variables)) { - /* just one target, so just use that */ - dvar = driver->variables.first; - driver->curval = driver_get_variable_value(driver, dvar); - } - else { - /* more than one target, so average the values of the targets */ - float value = 0.0f; - int tot = 0; - - /* loop through targets, adding (hopefully we don't get any overflow!) */ - for (dvar = driver->variables.first; dvar; dvar = dvar->next) { - value += driver_get_variable_value(driver, dvar); - tot++; - } - - /* perform operations on the total if appropriate */ - if (driver->type == DRIVER_TYPE_AVERAGE) { - driver->curval = tot ? (value / (float)tot) : 0.0f; - } - else { - driver->curval = value; - } - } + evaluate_driver_sum(driver); break; - } case DRIVER_TYPE_MIN: /* smallest value */ case DRIVER_TYPE_MAX: /* largest value */ - { - float value = 0.0f; - - /* loop through the variables, getting the values and comparing them to existing ones */ - for (dvar = driver->variables.first; dvar; dvar = dvar->next) { - /* get value */ - float tmp_val = driver_get_variable_value(driver, dvar); - - /* store this value if appropriate */ - if (dvar->prev) { - /* check if greater/smaller than the baseline */ - if (driver->type == DRIVER_TYPE_MAX) { - /* max? */ - if (tmp_val > value) { - value = tmp_val; - } - } - else { - /* min? */ - if (tmp_val < value) { - value = tmp_val; - } - } - } - else { - /* first item - make this the baseline for comparisons */ - value = tmp_val; - } - } - - /* store value in driver */ - driver->curval = value; + evaluate_driver_min_max(driver); break; - } case DRIVER_TYPE_PYTHON: /* expression */ - { - /* check for empty or invalid expression */ - if ((driver_orig->expression[0] == '\0') || (driver_orig->flag & DRIVER_FLAG_INVALID)) { - driver->curval = 0.0f; - } - else if (!driver_try_evaluate_simple_expr(driver, driver_orig, &driver->curval, evaltime)) { -#ifdef WITH_PYTHON - /* this evaluates the expression using Python, and returns its result: - * - on errors it reports, then returns 0.0f - */ - BLI_mutex_lock(&python_driver_lock); - - driver->curval = BPY_driver_exec(anim_rna, driver, driver_orig, evaltime); - - BLI_mutex_unlock(&python_driver_lock); -#else /* WITH_PYTHON*/ - UNUSED_VARS(anim_rna, evaltime); -#endif /* WITH_PYTHON*/ - } + evaluate_driver_python(anim_rna, driver, driver_orig, evaltime); break; - } - default: { + default: /* special 'hack' - just use stored value * This is currently used as the mechanism which allows animated settings to be able * to be changed via the UI. */ break; - } } /* return value for driver */ diff --git a/source/blender/blenlib/BLI_allocator.h b/source/blender/blenlib/BLI_allocator.h index 52fa8d2b705..82cf76e425c 100644 --- a/source/blender/blenlib/BLI_allocator.h +++ b/source/blender/blenlib/BLI_allocator.h @@ -30,6 +30,7 @@ */ #include <stdlib.h> +#include <algorithm> #include "MEM_guardedalloc.h" diff --git a/source/blender/blenlib/BLI_array_cxx.h b/source/blender/blenlib/BLI_array_cxx.h index c7704e20fb1..e987121d68c 100644 --- a/source/blender/blenlib/BLI_array_cxx.h +++ b/source/blender/blenlib/BLI_array_cxx.h @@ -27,6 +27,7 @@ #include "BLI_allocator.h" #include "BLI_array_ref.h" #include "BLI_memory_utils_cxx.h" +#include "BLI_index_range.h" namespace BLI { @@ -182,6 +183,11 @@ template<typename T, typename Allocator = GuardedAllocator> class Array { return m_data + m_size; } + IndexRange index_range() const + { + return IndexRange(m_size); + } + private: T *allocate(uint size) { diff --git a/source/blender/blenlib/BLI_array_ref.h b/source/blender/blenlib/BLI_array_ref.h index e34647676d8..bef7b862bf9 100644 --- a/source/blender/blenlib/BLI_array_ref.h +++ b/source/blender/blenlib/BLI_array_ref.h @@ -246,6 +246,11 @@ template<typename T> class ArrayRef { return fallback; } + IndexRange index_range() const + { + return IndexRange(m_size); + } + /** * Get a new array ref to the same underlying memory buffer. No conversions are done. * Asserts when the sizes of the types don't match. @@ -411,6 +416,11 @@ template<typename T> class MutableArrayRef { { return ArrayRef<T>(m_start, m_size); } + + IndexRange index_range() const + { + return IndexRange(m_size); + } }; /** diff --git a/source/blender/blenlib/BLI_vector.h b/source/blender/blenlib/BLI_vector.h index 46c46a1440f..5c03a896692 100644 --- a/source/blender/blenlib/BLI_vector.h +++ b/source/blender/blenlib/BLI_vector.h @@ -37,6 +37,7 @@ #include "BLI_listbase_wrapper.h" #include "BLI_math_base.h" #include "BLI_allocator.h" +#include "BLI_index_range.h" #include "MEM_guardedalloc.h" @@ -520,6 +521,11 @@ template<typename T, uint N = 4, typename Allocator = GuardedAllocator> class Ve return (uint)(m_capacity_end - m_begin); } + IndexRange index_range() const + { + return IndexRange(this->size()); + } + void print_stats() const { std::cout << "Small Vector at " << (void *)this << ":" << std::endl; diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index e00b7fd2dc5..9057922906c 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -616,8 +616,6 @@ void OBJECT_OT_parent_clear(wmOperatorType *ot) ot->invoke = WM_menu_invoke; ot->exec = parent_clear_exec; - ot->poll = ED_operator_object_active_editable; - /* flags */ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; @@ -1056,7 +1054,9 @@ static int parent_set_invoke_menu(bContext *C, wmOperatorType *ot) if (parent->type == OB_ARMATURE) { uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_ARMATURE); uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_ARMATURE_NAME); - uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_ARMATURE_ENVELOPE); + if (!has_children_of_type.gpencil) { + uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_ARMATURE_ENVELOPE); + } if (has_children_of_type.mesh || has_children_of_type.gpencil) { uiItemEnumO_ptr(layout, ot, NULL, 0, "type", PAR_ARMATURE_AUTO); } diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index fcf41481ade..2c0d34fdccf 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -24,6 +24,10 @@ #include "DNA_defs.h" #include "DNA_listBase.h" +#ifdef __cplusplus +extern "C" { +#endif + /* WARNING ALERT! TYPEDEF VALUES ARE WRITTEN IN FILES! SO DO NOT CHANGE! * (ONLY ADD NEW ITEMS AT THE END) */ @@ -2042,4 +2046,8 @@ enum { #define MOD_MESHSEQ_READ_ALL \ (MOD_MESHSEQ_READ_VERT | MOD_MESHSEQ_READ_POLY | MOD_MESHSEQ_READ_UV | MOD_MESHSEQ_READ_COLOR) +#ifdef __cplusplus +} +#endif + #endif /* __DNA_MODIFIER_TYPES_H__ */ diff --git a/source/blender/modifiers/MOD_modifiertypes.h b/source/blender/modifiers/MOD_modifiertypes.h index 7dd1ce830aa..5dc4adf4393 100644 --- a/source/blender/modifiers/MOD_modifiertypes.h +++ b/source/blender/modifiers/MOD_modifiertypes.h @@ -23,6 +23,10 @@ #include "BKE_modifier.h" +#ifdef __cplusplus +extern "C" { +#endif + /* ****************** Type structures for all modifiers ****************** */ extern ModifierTypeInfo modifierType_None; @@ -86,4 +90,8 @@ extern ModifierTypeInfo modifierType_WeightedNormal; /* MOD_util.c */ void modifier_type_init(ModifierTypeInfo *types[]); +#ifdef __cplusplus +} +#endif + #endif /* __MOD_MODIFIERTYPES_H__ */ |