Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Gavrilov <angavrilov@gmail.com>2018-12-15 22:37:12 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2018-12-19 14:20:35 +0300
commit61c941f040d367d18fcaa57c9e8e0c2078193d97 (patch)
tree9cf843e4f19fffda991afb77595ec4d287a0b142 /source/blender/makesrna/intern/rna_access.c
parent908a2742403b279cd6dfa5c27acb76d68d3f1523 (diff)
RNA: support setting default values for custom properties.
NLA requires a usable default value for all properties that are to be animated via it, without any exceptions. This is the real cause of T36496: using the default of 0 for a scale related custom property obviously doesn't work. Thus, to really fix this it is necessary to support configurable default values for custom properties, which are very frequently used in rigs for auxiliary settings. For common use it is enough to support this for scalar float and integer properties. The default can be set via the custom property configuration popup, or a right click menu option. In addition, to help in updating old rigs, an operator that saves current values as defaults for all object and bone properties is added. Reviewers: campbellbarton, brecht Differential Revision: https://developer.blender.org/D4084
Diffstat (limited to 'source/blender/makesrna/intern/rna_access.c')
-rw-r--r--source/blender/makesrna/intern/rna_access.c171
1 files changed, 169 insertions, 2 deletions
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 2f23bc5eea9..1a212097c31 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -257,8 +257,7 @@ static void rna_idproperty_touch(IDProperty *idprop)
idprop->flag &= ~IDP_FLAG_GHOST;
}
-/* return a UI local ID prop definition for this prop */
-static IDProperty *rna_idproperty_ui(PropertyRNA *prop)
+static IDProperty *rna_idproperty_ui_container(PropertyRNA *prop)
{
IDProperty *idprop;
@@ -274,6 +273,14 @@ static IDProperty *rna_idproperty_ui(PropertyRNA *prop)
}
}
+ return idprop;
+}
+
+/* return a UI local ID prop definition for this prop */
+static IDProperty *rna_idproperty_ui(PropertyRNA *prop)
+{
+ IDProperty *idprop = rna_idproperty_ui_container(prop);
+
if (idprop) {
return IDP_GetPropertyTypeFromGroup(idprop, ((IDProperty *)prop)->name, IDP_GROUP);
}
@@ -281,6 +288,94 @@ static IDProperty *rna_idproperty_ui(PropertyRNA *prop)
return NULL;
}
+/* return or create a UI local ID prop definition for this prop */
+static IDProperty *rna_idproperty_ui_ensure(PointerRNA *ptr, PropertyRNA *prop, bool create)
+{
+ IDProperty *idprop = rna_idproperty_ui_container(prop);
+ IDPropertyTemplate dummy = { 0 };
+
+ if (idprop == NULL && create) {
+ IDProperty *props = RNA_struct_idprops(ptr, false);
+
+ /* Sanity check: props is the actual container of this property. */
+ if (props != NULL && BLI_findindex(&props->data.group, prop) >= 0) {
+ idprop = IDP_New(IDP_GROUP, &dummy, RNA_IDP_UI);
+
+ if (!IDP_AddToGroup(props, idprop)) {
+ IDP_FreeProperty(idprop);
+ return NULL;
+ }
+ }
+ }
+
+ if (idprop) {
+ const char *name = ((IDProperty *)prop)->name;
+ IDProperty *rv = IDP_GetPropertyTypeFromGroup(idprop, name, IDP_GROUP);
+
+ if (rv == NULL && create) {
+ rv = IDP_New(IDP_GROUP, &dummy, name);
+
+ if (!IDP_AddToGroup(idprop, rv)) {
+ IDP_FreeProperty(rv);
+ return NULL;
+ }
+ }
+
+ return rv;
+ }
+
+ return NULL;
+}
+
+static bool rna_idproperty_ui_set_default(PointerRNA *ptr, PropertyRNA *prop, const char type, IDPropertyTemplate *value)
+{
+ BLI_assert(ELEM(type, IDP_INT, IDP_DOUBLE));
+
+ if (prop->magic == RNA_MAGIC) {
+ return false;
+ }
+
+ /* attempt to get the local ID values */
+ IDProperty *idp_ui = rna_idproperty_ui_ensure(ptr, prop, value != NULL);
+
+ if (idp_ui == NULL) {
+ return (value == NULL);
+ }
+
+ IDProperty *item = IDP_GetPropertyTypeFromGroup(idp_ui, "default", type);
+
+ if (value == NULL) {
+ if (item != NULL) {
+ IDP_RemoveFromGroup(idp_ui, item);
+ }
+ }
+ else {
+ if (item != NULL) {
+ switch (type) {
+ case IDP_INT:
+ IDP_Int(item) = value->i;
+ break;
+ case IDP_DOUBLE:
+ IDP_Double(item) = value->d;
+ break;
+ default:
+ BLI_assert(false);
+ return false;
+ }
+ }
+ else {
+ item = IDP_New(type, value, "default");
+
+ if (!IDP_AddToGroup(idp_ui, item)) {
+ IDP_FreeProperty(item);
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
IDProperty *RNA_struct_idprops(PointerRNA *ptr, bool create)
{
StructRNA *type = ptr->type;
@@ -2726,9 +2821,33 @@ void RNA_property_int_set_index(PointerRNA *ptr, PropertyRNA *prop, int index, i
int RNA_property_int_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
{
IntPropertyRNA *iprop = (IntPropertyRNA *)rna_ensure_property(prop);
+
+ if (prop->magic != RNA_MAGIC) {
+ /* attempt to get the local ID values */
+ IDProperty *idp_ui = rna_idproperty_ui(prop);
+
+ if (idp_ui) {
+ IDProperty *item;
+
+ item = IDP_GetPropertyTypeFromGroup(idp_ui, "default", IDP_INT);
+ return item ? IDP_Int(item) : iprop->defaultvalue;
+ }
+ }
+
return iprop->defaultvalue;
}
+bool RNA_property_int_set_default(PointerRNA *ptr, PropertyRNA *prop, int value)
+{
+ if (value != 0) {
+ IDPropertyTemplate val = { .i = value };
+ return rna_idproperty_ui_set_default(ptr, prop, IDP_INT, &val);
+ }
+ else {
+ return rna_idproperty_ui_set_default(ptr, prop, IDP_INT, NULL);
+ }
+}
+
void RNA_property_int_get_default_array(PointerRNA *UNUSED(ptr), PropertyRNA *prop, int *values)
{
IntPropertyRNA *iprop = (IntPropertyRNA *)rna_ensure_property(prop);
@@ -3023,9 +3142,32 @@ float RNA_property_float_get_default(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
BLI_assert(RNA_property_type(prop) == PROP_FLOAT);
BLI_assert(RNA_property_array_check(prop) == false);
+ if (prop->magic != RNA_MAGIC) {
+ /* attempt to get the local ID values */
+ IDProperty *idp_ui = rna_idproperty_ui(prop);
+
+ if (idp_ui) {
+ IDProperty *item;
+
+ item = IDP_GetPropertyTypeFromGroup(idp_ui, "default", IDP_DOUBLE);
+ return item ? IDP_Double(item) : fprop->defaultvalue;
+ }
+ }
+
return fprop->defaultvalue;
}
+bool RNA_property_float_set_default(PointerRNA *ptr, PropertyRNA *prop, float value)
+{
+ if (value != 0) {
+ IDPropertyTemplate val = { .d = value };
+ return rna_idproperty_ui_set_default(ptr, prop, IDP_DOUBLE, &val);
+ }
+ else {
+ return rna_idproperty_ui_set_default(ptr, prop, IDP_DOUBLE, NULL);
+ }
+}
+
void RNA_property_float_get_default_array(PointerRNA *UNUSED(ptr), PropertyRNA *prop, float *values)
{
FloatPropertyRNA *fprop = (FloatPropertyRNA *)rna_ensure_property(prop);
@@ -7257,6 +7399,31 @@ bool RNA_property_reset(PointerRNA *ptr, PropertyRNA *prop, int index)
}
}
+bool RNA_property_assign_default(PointerRNA *ptr, PropertyRNA *prop)
+{
+ if (!RNA_property_is_idprop(prop) || RNA_property_array_check(prop)) {
+ return false;
+ }
+
+ /* get and set the default values as appropriate for the various types */
+ switch (RNA_property_type(prop)) {
+ case PROP_INT:
+ {
+ int value = RNA_property_int_get(ptr, prop);
+ return RNA_property_int_set_default(ptr, prop, value);
+ }
+
+ case PROP_FLOAT:
+ {
+ float value = RNA_property_float_get(ptr, prop);
+ return RNA_property_float_set_default(ptr, prop, value);
+ }
+
+ default:
+ return false;
+ }
+}
+
static bool rna_property_override_operation_apply(
Main *bmain,
PointerRNA *ptr_local, PointerRNA *ptr_override, PointerRNA *ptr_storage,