Keying Sets: Wrapped KeyingSets in RNA

* The settings of KeyingSets can now be viewed/modified through RNA. 
* Shuffled RNA wrapping for AnimData over to its own file 
* Moved insert-key flags to DNA_anim_types.h, as they're now used for KeyingSets.
This commit is contained in:
Joshua Leung
2009-02-13 01:51:33 +00:00
parent ed7e211c2d
commit cec4a29977
12 changed files with 273 additions and 82 deletions

View File

@@ -33,7 +33,7 @@ struct AnimData *BKE_copy_animdata(struct AnimData *adt);
struct KeyingSet *BKE_keyingset_add(struct ListBase *list, const char name[], short flag, short keyingflag);
/* Add a destination to a KeyingSet */
void BKE_keyingset_add_destination(struct KeyingSet *ks, struct ID *id, const char group_name[], const char rna_path[], int array_index, int flag);
void BKE_keyingset_add_destination(struct KeyingSet *ks, struct ID *id, const char group_name[], const char rna_path[], int array_index, short flag, short groupmode);
/* Free data for KeyingSet but not set itself */
void BKE_keyingset_free(struct KeyingSet *ks);

View File

@@ -195,7 +195,7 @@ KeyingSet *BKE_keyingset_add (ListBase *list, const char name[], short flag, sho
/* Add a destination to a KeyingSet. Nothing is returned for now...
* Checks are performed to ensure that destination is appropriate for the KeyingSet in question
*/
void BKE_keyingset_add_destination (KeyingSet *ks, ID *id, const char group_name[], const char rna_path[], int array_index, int flag)
void BKE_keyingset_add_destination (KeyingSet *ks, ID *id, const char group_name[], const char rna_path[], int array_index, short flag, short groupmode)
{
KS_Path *ksp;
@@ -229,6 +229,7 @@ void BKE_keyingset_add_destination (KeyingSet *ks, ID *id, const char group_name
/* store flags */
ksp->flag= flag;
ksp->groupmode= groupmode;
/* add KeyingSet path to KeyingSet */
BLI_addtail(&ks->paths, ksp);

View File

@@ -2031,9 +2031,9 @@ static int commonkey_modifykey (ListBase *dsources, KeyingSet *ks, short mode, f
int arraylen, i;
/* get pointer to name of group to add channels to */
if (ksp->flag & KSP_FLAG_GROUP_NONE)
if (ksp->groupmode == KSP_GROUP_NONE)
groupname= NULL;
else if (ksp->flag & KSP_FLAG_GROUP_KSNAME)
else if (ksp->groupmode == KSP_GROUP_KSNAME)
groupname= ks->name;
else
groupname= ksp->group;

View File

@@ -52,23 +52,6 @@ int insert_bezt_fcurve(struct FCurve *fcu, struct BezTriple *bezt);
*/
void insert_vert_fcurve(struct FCurve *fcu, float x, float y, short flag);
/* flags for use by keyframe creation/deletion calls */
enum {
/* used by isnertkey() and insert_vert_icu() */
INSERTKEY_NEEDED = (1<<0), /* only insert keyframes where they're needed */
INSERTKEY_MATRIX = (1<<1), /* insert 'visual' keyframes where possible/needed */
INSERTKEY_FAST = (1<<2), /* don't recalculate handles,etc. after adding key */
INSERTKEY_FASTR = (1<<3), /* don't realloc mem (or increase count, as array has already been set out) */
INSERTKEY_REPLACE = (1<<4), /* only replace an existing keyframe (this overrides INSERTKEY_NEEDED) */
/* used by common_*key() functions - Note: these are generally mutually exclusive (only one will work at a time) */
COMMONKEY_ADDMAP = (1<<10), /* common key: add texture-slot offset bitflag to adrcode before use */
COMMONKEY_PCHANROT = (1<<11), /* common key: extend channel list using relevant pchan-rotations */
/* all possible items for common_*key() functions */
COMMONKEY_MODES = (COMMONKEY_ADDMAP|COMMONKEY_PCHANROT)
} eInsertKeyFlags;
/* -------- */
/* Main Keyframing API calls:

View File

@@ -3151,7 +3151,8 @@ static void ks_editop_add_cb(SpaceOops *soops, KeyingSet *ks, TreeElement *te, T
ID *id = NULL;
char *path=NULL, *newpath=NULL;
int array_index= 0;
int flag= KSP_FLAG_GROUP_KSNAME;
short flag = 0;
short groupmode= KSP_GROUP_KSNAME;
/* optimise tricks:
* - Don't do anything if the selected item is a 'struct', but arrays are allowed
@@ -3159,7 +3160,7 @@ static void ks_editop_add_cb(SpaceOops *soops, KeyingSet *ks, TreeElement *te, T
if (tselem->type == TSE_RNA_STRUCT)
return;
//printf("ks_editop_add_cb() \n");
printf("ks_editop_add_cb() \n");
/* Overview of Algorithm:
* 1. Go up the chain of parents until we find the 'root', taking note of the
@@ -3188,11 +3189,20 @@ static void ks_editop_add_cb(SpaceOops *soops, KeyingSet *ks, TreeElement *te, T
/* check if we're looking for first ID, or appending to path */
if (id) {
if (tse->type == TSE_RNA_STRUCT)
printf("\t tem = RNA Struct '%s' \n", tem->name);
else if (tse->type == TSE_RNA_ARRAY_ELEM)
printf("\t tem = RNA Array Elem '%s' \n", tem->name);
else if (tse->type == TSE_RNA_PROPERTY)
printf("\t tem = RNA Property '%s' \n", tem->name);
else
printf("\t tem = WTF? \n");
/* just 'append' property to path
* - to prevent memory leaks, we must write to newpath not path, then free old path + swap them
*/
// TODO: how to do this? we must use 'string' identifiers for collections so that these don't break if data is added/removed
//newpath= RNA_path_append(path, NULL, prop, index, NULL);
// TODO: how should this be done?
//newpath= RNA_path_append(path, ptr, prop, tem->index, /*RNA_property_identifier(ptr, prop)*/0);
if (path) MEM_freeN(path);
path= newpath;
@@ -3234,7 +3244,7 @@ static void ks_editop_add_cb(SpaceOops *soops, KeyingSet *ks, TreeElement *te, T
/* add a new path with the information obtained (only if valid) */
// TODO: what do we do with group name? for now, we don't supply one, and just let this use the KeyingSet name
if (path)
BKE_keyingset_add_destination(ks, id, NULL, path, array_index, flag);
BKE_keyingset_add_destination(ks, id, NULL, path, array_index, flag, groupmode);
}
/* free temp data */

View File

@@ -445,20 +445,26 @@ typedef struct KS_Path {
char *rna_path; /* dynamically (or statically in the case of predefined sets) path */
int array_index; /* index that path affects */
int flag; /* various settings, etc. */
short flag; /* various settings, etc. */
short groupmode; /* group naming (eKSP_Grouping) */
} KS_Path;
/* KS_Path->flag */
enum {
/* entire array (not just the specified index) gets keyframed */
KSP_FLAG_WHOLE_ARRAY = (1<<0),
/* path should not be grouped at all */
KSP_FLAG_GROUP_NONE = (1<<10),
/* path should be grouped under an ActionGroup KeyingSet's name */
KSP_FLAG_GROUP_KSNAME = (1<<11),
} eKSP_Settings;
/* KS_Path->groupmode */
enum {
/* path should be grouped using its own group-name */
KSP_GROUP_NAMED = 0,
/* path should not be grouped at all */
KSP_GROUP_NONE,
/* path should be grouped under an ActionGroup KeyingSet's name */
KSP_GROUP_KSNAME,
} eKSP_Grouping;
/* ---------------- */
/* KeyingSet definition (ks)
@@ -486,12 +492,19 @@ typedef struct KeyingSet {
enum {
/* keyingset cannot be removed (and doesn't need to be freed) */
KEYINGSET_BUILTIN = (1<<0),
/* keyingset is the one currently in use */
KEYINGSET_ACTIVE = (1<<1),
/* keyingset does not depend on context info (i.e. paths are absolute) */
KEYINGSET_ABSOLUTE = (1<<2),
KEYINGSET_ABSOLUTE = (1<<1),
} eKS_Settings;
/* Flags for use by keyframe creation/deletion calls */
enum {
INSERTKEY_NEEDED = (1<<0), /* only insert keyframes where they're needed */
INSERTKEY_MATRIX = (1<<1), /* insert 'visual' keyframes where possible/needed */
INSERTKEY_FAST = (1<<2), /* don't recalculate handles,etc. after adding key */
INSERTKEY_FASTR = (1<<3), /* don't realloc mem (or increase count, as array has already been set out) */
INSERTKEY_REPLACE = (1<<4), /* only replace an existing keyframe (this overrides INSERTKEY_NEEDED) */
} eInsertKeyFlags;
/* ************************************************ */
/* Animation Data */

View File

@@ -117,6 +117,8 @@ extern StructRNA RNA_IntProperty;
extern StructRNA RNA_JoystickSensor;
extern StructRNA RNA_Key;
extern StructRNA RNA_KeyboardSensor;
extern StructRNA RNA_KeyingSet;
extern StructRNA RNA_KeyingSetPath;
extern StructRNA RNA_Lamp;
extern StructRNA RNA_LampSkySettings;
extern StructRNA RNA_LampTextureSlot;

View File

@@ -1246,7 +1246,8 @@ typedef struct RNAProcessItem {
RNAProcessItem PROCESS_ITEMS[]= {
{"rna_ID.c", RNA_def_ID},
{"rna_texture.c", RNA_def_texture},
{"rna_action.c", RNA_def_animation},
{"rna_action.c", RNA_def_action},
{"rna_animation.c", RNA_def_animation},
{"rna_actuator.c", RNA_def_actuator},
{"rna_armature.c", RNA_def_armature},
{"rna_brush.c", RNA_def_brush},

View File

@@ -261,59 +261,17 @@ void rna_def_action(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Pose Markers", "Markers specific to this Action, for labeling poses.");
}
/* --- */
/* --------- */
void rna_def_animdata_common(StructRNA *srna)
void RNA_def_action(BlenderRNA *brna)
{
PropertyRNA *prop;
prop= RNA_def_property(srna, "animation_data", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "adt");
RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
RNA_def_property_ui_text(prop, "Animation Data", "Animation data for this datablock.");
}
void rna_def_animdata(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
srna= RNA_def_struct(brna, "AnimData", NULL);
//RNA_def_struct_sdna(srna, "AnimData");
RNA_def_struct_ui_text(srna, "Animation Data", "Animation data for datablock.");
/* NLA */
prop= RNA_def_property(srna, "nla_tracks", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "nla_tracks", NULL);
RNA_def_property_struct_type(prop, "UnknownType"); // XXX!
RNA_def_property_ui_text(prop, "NLA Tracks", "NLA Tracks (i.e. Animation Layers).");
/* Action */
prop= RNA_def_property(srna, "action", PROP_POINTER, PROP_NONE);
RNA_def_property_ui_text(prop, "Action", "Active Action for this datablock.");
/* Drivers */
prop= RNA_def_property(srna, "drivers", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "drivers", NULL);
RNA_def_property_struct_type(prop, "FCurve");
RNA_def_property_ui_text(prop, "Drivers", "The Drivers/Expressions for this datablock.");
/* Settings */
}
/* --- */
void RNA_def_animation(BlenderRNA *brna)
{
// XXX move this into its own file?
rna_def_animdata(brna);
rna_def_action(brna);
rna_def_action_group(brna);
// XXX move these to their own file?
// should these be in their own file, or is that overkill?
rna_def_fcurve(brna);
rna_def_channeldriver(brna);
}
#endif

View File

@@ -0,0 +1,213 @@
/**
* $Id$
*
* ***** BEGIN GPL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Contributor(s): Blender Foundation (2008), Roland Hess
*
* ***** END GPL LICENSE BLOCK *****
*/
#include <stdlib.h>
#include "RNA_define.h"
#include "RNA_types.h"
#include "rna_internal.h"
#include "DNA_anim_types.h"
#include "DNA_action_types.h"
#include "DNA_scene_types.h"
#include "MEM_guardedalloc.h"
#ifdef RNA_RUNTIME
static void rna_ksPath_RnaPath_get(PointerRNA *ptr, char *value)
{
KS_Path *ksp= (KS_Path *)ptr->data;
if (ksp->rna_path)
strcpy(value, ksp->rna_path);
else
strcpy(value, "");
}
static int rna_ksPath_RnaPath_length(PointerRNA *ptr)
{
KS_Path *ksp= (KS_Path *)ptr->data;
if (ksp->rna_path)
return strlen(ksp->rna_path);
else
return 0;
}
#if 0
static void rna_ksPath_RnaPath_set(PointerRNA *ptr, const char *value)
{
KS_Path *ksp= (KS_Path *)ptr->data;
if (ksp->rna_path)
MEM_freeN(ksp->ksp_path);
if (strlen(value))
ksp->rna_path= BLI_strdup(value);
else
ksp->rna_path= NULL;
}
#endif
#else
void rna_def_keyingset_path(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
static EnumPropertyItem prop_mode_grouping_items[] = {
{KSP_GROUP_NAMED, "NAMED", "Named Group", ""},
{KSP_GROUP_NONE, "NONE", "None", ""},
{KSP_GROUP_KSNAME, "KEYINGSET", "Keying Set Name", ""},
{0, NULL, NULL, NULL}};
srna= RNA_def_struct(brna, "KeyingSetPath", NULL);
RNA_def_struct_sdna(srna, "KS_Path");
RNA_def_struct_ui_text(srna, "Keying Set Path", "Path to a setting for use in a Keying Set.");
/* ID */
prop= RNA_def_property(srna, "id", PROP_POINTER, PROP_NONE);
RNA_def_property_ui_text(prop, "ID-Block", "ID-Block that keyframes for Keying Set should be added to (for Absolute Keying Sets only).");
/* Group */
prop= RNA_def_property(srna, "group", PROP_STRING, PROP_NONE);
RNA_def_property_ui_text(prop, "Group Name", "Name of Action Group to assign setting(s) for this path to.");
/* Grouping */
prop= RNA_def_property(srna, "grouping", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "groupmode");
RNA_def_property_enum_items(prop, prop_mode_grouping_items);
RNA_def_property_ui_text(prop, "Grouping Method", "Method used to define which Group-name to use.");
/* Path + Array Index */
prop= RNA_def_property(srna, "rna_path", PROP_STRING, PROP_NONE);
RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
RNA_def_property_string_funcs(prop, "rna_ksPath_RnaPath_get", "rna_ksPath_RnaPath_length", "rna_ksPath_RnaPath_set");
RNA_def_property_ui_text(prop, "RNA Path", "RNA Path to property setting.");
prop= RNA_def_property(srna, "array_index", PROP_INT, PROP_NONE);
RNA_def_property_ui_text(prop, "RNA Array Index", "Index to the specific setting if applicable.");
/* Flags */
prop= RNA_def_property(srna, "entire_array", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", KSP_FLAG_WHOLE_ARRAY);
RNA_def_property_ui_text(prop, "Entire Array", "When an 'array/vector' type is chosen (Location, Rotation, Color, etc.), entire array is to be used.");
}
void rna_def_keyingset(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
srna= RNA_def_struct(brna, "KeyingSet", NULL);
RNA_def_struct_ui_text(srna, "Keying Set", "Settings that should be keyframed together.");
/* Name */
prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
RNA_def_property_ui_text(prop, "Name", "");
RNA_def_struct_name_property(srna, prop);
/* Paths */
prop= RNA_def_property(srna, "paths", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "paths", NULL);
RNA_def_property_struct_type(prop, "KeyingSetPath");
RNA_def_property_ui_text(prop, "Paths", "Keying Set Paths to define settings that get keyframed together.");
/* Flags */
prop= RNA_def_property(srna, "builtin", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYINGSET_BUILTIN);
RNA_def_property_ui_text(prop, "Built-In", "Keying Set is a built-in to Blender.");
/* TODO: for now, this is editable, but do we really want this to happen? */
prop= RNA_def_property(srna, "absolute", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYINGSET_ABSOLUTE);
RNA_def_property_ui_text(prop, "Absolute", "Keying Set defines specifc paths/settings to be keyframed (i.e. is not reliant on context info)");
/* Keyframing Flags */
prop= RNA_def_property(srna, "insertkey_needed", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "keyingflag", INSERTKEY_NEEDED);
RNA_def_property_ui_text(prop, "Insert Keyframes - Only Needed", "Only insert keyframes where they're needed in the relevant F-Curves.");
prop= RNA_def_property(srna, "insertkey_visual", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "keyingflag", INSERTKEY_MATRIX);
RNA_def_property_ui_text(prop, "Insert Keyframes - Visual", "Insert keyframes based on 'visual transforms'.");
}
/* --- */
void rna_def_animdata_common(StructRNA *srna)
{
PropertyRNA *prop;
prop= RNA_def_property(srna, "animation_data", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "adt");
RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
RNA_def_property_ui_text(prop, "Animation Data", "Animation data for this datablock.");
}
void rna_def_animdata(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
srna= RNA_def_struct(brna, "AnimData", NULL);
RNA_def_struct_ui_text(srna, "Animation Data", "Animation data for datablock.");
/* NLA */
prop= RNA_def_property(srna, "nla_tracks", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "nla_tracks", NULL);
RNA_def_property_struct_type(prop, "UnknownType"); // XXX!
RNA_def_property_ui_text(prop, "NLA Tracks", "NLA Tracks (i.e. Animation Layers).");
/* Action */
prop= RNA_def_property(srna, "action", PROP_POINTER, PROP_NONE);
RNA_def_property_ui_text(prop, "Action", "Active Action for this datablock.");
/* Drivers */
prop= RNA_def_property(srna, "drivers", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "drivers", NULL);
RNA_def_property_struct_type(prop, "FCurve");
RNA_def_property_ui_text(prop, "Drivers", "The Drivers/Expressions for this datablock.");
/* Settings */
}
/* --- */
void RNA_def_animation(BlenderRNA *brna)
{
rna_def_animdata(brna);
rna_def_keyingset(brna);
rna_def_keyingset_path(brna);
}
#endif

View File

@@ -95,6 +95,7 @@ extern BlenderDefRNA DefRNA;
extern BlenderRNA BLENDER_RNA;
void RNA_def_ID(struct BlenderRNA *brna);
void RNA_def_action(struct BlenderRNA *brna);
void RNA_def_animation(struct BlenderRNA *brna);
void RNA_def_armature(struct BlenderRNA *brna);
void RNA_def_actuator(struct BlenderRNA *brna);

View File

@@ -237,6 +237,15 @@ void RNA_def_scene(BlenderRNA *brna)
prop= RNA_def_property(srna, "radiosity", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "radio");
RNA_def_property_ui_text(prop, "Radiosity", "");
prop= RNA_def_property(srna, "keyingsets", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "keyingsets", NULL);
RNA_def_property_struct_type(prop, "KeyingSet");
RNA_def_property_ui_text(prop, "Keying Sets", "Keying Sets for this Scene.");
prop= RNA_def_property(srna, "active_keyingset", PROP_INT, PROP_NONE);
RNA_def_property_flag(prop, PROP_NOT_EDITABLE);
RNA_def_property_ui_text(prop, "Active Keying Set", "Current Keying Set index.");
prop= RNA_def_property(srna, "tool_settings", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "toolsettings");