diff options
author | Campbell Barton <ideasman42@gmail.com> | 2016-07-30 09:34:01 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2016-07-30 09:46:13 +0300 |
commit | 4e845e06704bad3c11297ae8e86b400ef80b2a89 (patch) | |
tree | e26c66b90934e6230f5c4bc67f3fe7419b199ecf /source/blender/makesrna | |
parent | 362b3bbe58ae378d5e154dd1a27d55d913594a1a (diff) |
Py-Driver: add 'self' option
Drivers can use this to refer to the data which the driver is applied to,
useful for objects, bones, to avoid having to create a variable pointing to its self.
Diffstat (limited to 'source/blender/makesrna')
-rw-r--r-- | source/blender/makesrna/RNA_access.h | 5 | ||||
-rw-r--r-- | source/blender/makesrna/RNA_types.h | 10 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_access.c | 19 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_fcurve.c | 8 |
4 files changed, 41 insertions, 1 deletions
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h index c3d25ed2972..e884d769afe 100644 --- a/source/blender/makesrna/RNA_access.h +++ b/source/blender/makesrna/RNA_access.h @@ -715,6 +715,11 @@ void RNA_main_pointer_create(struct Main *main, PointerRNA *r_ptr); void RNA_id_pointer_create(struct ID *id, PointerRNA *r_ptr); void RNA_pointer_create(struct ID *id, StructRNA *type, void *data, PointerRNA *r_ptr); +bool RNA_path_resolved_create( + PointerRNA *ptr, struct PropertyRNA *prop, + const int prop_index, + PathResolvedRNA *r_anim_rna); + void RNA_blender_rna_pointer_create(PointerRNA *r_ptr); void RNA_pointer_recast(PointerRNA *ptr, PointerRNA *r_ptr); diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h index 1d5f46a1814..276531992f9 100644 --- a/source/blender/makesrna/RNA_types.h +++ b/source/blender/makesrna/RNA_types.h @@ -64,6 +64,16 @@ typedef struct PropertyPointerRNA { struct PropertyRNA *prop; } PropertyPointerRNA; +/** + * Stored result of a RNA path lookup (as used by anim-system) + */ +typedef struct PathResolvedRNA { + struct PointerRNA ptr; + struct PropertyRNA *prop; + /* -1 for non-array access */ + int prop_index; +} PathResolvedRNA; + /* Property */ typedef enum PropertyType { diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index 5a93e18a7dd..047e5ea17ab 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -6966,3 +6966,22 @@ bool RNA_struct_equals(PointerRNA *a, PointerRNA *b, eRNAEqualsMode mode) return equals; } + +bool RNA_path_resolved_create( + PointerRNA *ptr, struct PropertyRNA *prop, + const int prop_index, + PathResolvedRNA *r_anim_rna) +{ + int array_len = RNA_property_array_length(ptr, prop); + + if ((array_len == 0) || (prop_index < array_len)) { + r_anim_rna->ptr = *ptr; + r_anim_rna->prop = prop; + r_anim_rna->prop_index = array_len ? prop_index : -1; + + return true; + } + else { + return false; + } +} diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c index 5fb581eb74a..08c0f98e45b 100644 --- a/source/blender/makesrna/intern/rna_fcurve.c +++ b/source/blender/makesrna/intern/rna_fcurve.c @@ -1600,7 +1600,13 @@ static void rna_def_channeldriver(BlenderRNA *brna) RNA_def_property_boolean_sdna(prop, NULL, "flag", DRIVER_FLAG_SHOWDEBUG); RNA_def_property_ui_text(prop, "Show Debug Info", "Show intermediate values for the driver calculations to allow debugging of drivers"); - + + prop = RNA_def_property(srna, "use_self", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", DRIVER_FLAG_USE_SELF); + RNA_def_property_ui_text(prop, "Use Self", + "Pass 'self' argument to Py-Driver, " + "so it can access the data referenced by the driver (object, bone, etc...)"); + /* State Info (for Debugging) */ prop = RNA_def_property(srna, "is_valid", PROP_BOOLEAN, PROP_NONE); RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", DRIVER_FLAG_INVALID); |