|
Blender
V2.59
|
00001 /* 00002 * $Id: rna_animation.c 36746 2011-05-18 11:21:10Z blendix $ 00003 * 00004 * ***** BEGIN GPL LICENSE BLOCK ***** 00005 * 00006 * This program is free software; you can redistribute it and/or 00007 * modify it under the terms of the GNU General Public License 00008 * as published by the Free Software Foundation; either version 2 00009 * of the License, or (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software Foundation, 00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00019 * 00020 * Contributor(s): Blender Foundation (2009), Joshua Leung 00021 * 00022 * ***** END GPL LICENSE BLOCK ***** 00023 */ 00024 00030 #include <stdlib.h> 00031 00032 #include "RNA_access.h" 00033 #include "RNA_define.h" 00034 #include "RNA_enum_types.h" 00035 00036 #include "rna_internal.h" 00037 00038 #include "DNA_anim_types.h" 00039 #include "DNA_action_types.h" 00040 #include "DNA_scene_types.h" 00041 00042 #include "MEM_guardedalloc.h" 00043 00044 #include "ED_keyframing.h" 00045 00046 #include "WM_types.h" 00047 00048 /* exported for use in API */ 00049 EnumPropertyItem keyingset_path_grouping_items[] = { 00050 {KSP_GROUP_NAMED, "NAMED", 0, "Named Group", ""}, 00051 {KSP_GROUP_NONE, "NONE", 0, "None", ""}, 00052 {KSP_GROUP_KSNAME, "KEYINGSET", 0, "Keying Set Name", ""}, 00053 {0, NULL, 0, NULL, NULL}}; 00054 00055 #ifdef RNA_RUNTIME 00056 00057 #include "BKE_animsys.h" 00058 #include "BKE_fcurve.h" 00059 #include "BKE_nla.h" 00060 00061 #include "WM_api.h" 00062 00063 static int rna_AnimData_action_editable(PointerRNA *ptr) 00064 { 00065 AnimData *adt= (AnimData *)ptr->data; 00066 00067 /* active action is only editable when it is not a tweaking strip */ 00068 if ((adt->flag & ADT_NLA_EDIT_ON) || (adt->actstrip) || (adt->tmpact)) 00069 return 0; 00070 else 00071 return 1; 00072 } 00073 00074 static void rna_AnimData_action_set(PointerRNA *ptr, PointerRNA value) 00075 { 00076 ID *ownerId = (ID *)ptr->id.data; 00077 AnimData *adt = (AnimData *)ptr->data; 00078 00079 /* assume that AnimData's action can in fact be edited... */ 00080 if ((value.data) && (ownerId)) { 00081 bAction *act = (bAction *)value.data; 00082 00083 /* action must have same type as owner */ 00084 if (ownerId) { 00085 if (ELEM(act->idroot, 0, GS(ownerId->name))) { 00086 /* can set */ 00087 adt->action = act; 00088 } 00089 else { 00090 /* cannot set */ 00091 printf("ERROR: Couldn't set Action '%s' onto ID '%s', as it doesn't have suitably rooted paths for this purpose\n", 00092 act->id.name+2, ownerId->name); 00093 } 00094 } 00095 else { 00096 /* cannot tell if we can set, so let's just be generous... */ 00097 printf("Warning: Set Action '%s' onto AnimData block with an unknown ID-owner. May have attached invalid data\n", 00098 act->id.name+2); 00099 00100 adt->action = act; 00101 } 00102 } 00103 else { 00104 /* just clearing the action... */ 00105 adt->action = NULL; 00106 } 00107 } 00108 00109 /* ****************************** */ 00110 00111 /* wrapper for poll callback */ 00112 static int RKS_POLL_rna_internal(KeyingSetInfo *ksi, bContext *C) 00113 { 00114 PointerRNA ptr; 00115 ParameterList list; 00116 FunctionRNA *func; 00117 void *ret; 00118 int ok; 00119 00120 RNA_pointer_create(NULL, ksi->ext.srna, ksi, &ptr); 00121 func= RNA_struct_find_function(&ptr, "poll"); 00122 00123 RNA_parameter_list_create(&list, &ptr, func); 00124 /* hook up arguments */ 00125 RNA_parameter_set_lookup(&list, "ksi", &ksi); 00126 RNA_parameter_set_lookup(&list, "context", &C); 00127 00128 /* execute the function */ 00129 ksi->ext.call(C, &ptr, func, &list); 00130 00131 /* read the result */ 00132 RNA_parameter_get_lookup(&list, "ok", &ret); 00133 ok= *(int*)ret; 00134 RNA_parameter_list_free(&list); 00135 00136 return ok; 00137 } 00138 00139 /* wrapper for iterator callback */ 00140 static void RKS_ITER_rna_internal(KeyingSetInfo *ksi, bContext *C, KeyingSet *ks) 00141 { 00142 PointerRNA ptr; 00143 ParameterList list; 00144 FunctionRNA *func; 00145 00146 RNA_pointer_create(NULL, ksi->ext.srna, ksi, &ptr); 00147 func= RNA_struct_find_function(&ptr, "iterator"); 00148 00149 RNA_parameter_list_create(&list, &ptr, func); 00150 /* hook up arguments */ 00151 RNA_parameter_set_lookup(&list, "ksi", &ksi); 00152 RNA_parameter_set_lookup(&list, "context", &C); 00153 RNA_parameter_set_lookup(&list, "ks", &ks); 00154 00155 /* execute the function */ 00156 ksi->ext.call(C, &ptr, func, &list); 00157 RNA_parameter_list_free(&list); 00158 } 00159 00160 /* wrapper for generator callback */ 00161 static void RKS_GEN_rna_internal(KeyingSetInfo *ksi, bContext *C, KeyingSet *ks, PointerRNA *data) 00162 { 00163 PointerRNA ptr; 00164 ParameterList list; 00165 FunctionRNA *func; 00166 00167 RNA_pointer_create(NULL, ksi->ext.srna, ksi, &ptr); 00168 func= RNA_struct_find_function(&ptr, "generate"); 00169 00170 RNA_parameter_list_create(&list, &ptr, func); 00171 /* hook up arguments */ 00172 RNA_parameter_set_lookup(&list, "ksi", &ksi); 00173 RNA_parameter_set_lookup(&list, "context", &C); 00174 RNA_parameter_set_lookup(&list, "ks", &ks); 00175 RNA_parameter_set_lookup(&list, "data", data); 00176 00177 /* execute the function */ 00178 ksi->ext.call(C, &ptr, func, &list); 00179 RNA_parameter_list_free(&list); 00180 } 00181 00182 /* ------ */ 00183 00184 // XXX: the exact purpose of this is not too clear... maybe we want to revise this at some point? 00185 static StructRNA *rna_KeyingSetInfo_refine(PointerRNA *ptr) 00186 { 00187 KeyingSetInfo *ksi= (KeyingSetInfo *)ptr->data; 00188 return (ksi->ext.srna)? ksi->ext.srna: &RNA_KeyingSetInfo; 00189 } 00190 00191 static void rna_KeyingSetInfo_unregister(Main *bmain, StructRNA *type) 00192 { 00193 KeyingSetInfo *ksi= RNA_struct_blender_type_get(type); 00194 00195 if (ksi == NULL) 00196 return; 00197 00198 /* free RNA data referencing this */ 00199 RNA_struct_free_extension(type, &ksi->ext); 00200 RNA_struct_free(&BLENDER_RNA, type); 00201 00202 /* unlink Blender-side data */ 00203 ANIM_keyingset_info_unregister(bmain, ksi); 00204 } 00205 00206 static StructRNA *rna_KeyingSetInfo_register(Main *bmain, ReportList *reports, void *data, const char *identifier, StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free) 00207 { 00208 KeyingSetInfo dummyksi = {NULL}; 00209 KeyingSetInfo *ksi; 00210 PointerRNA dummyptr = {{NULL}}; 00211 int have_function[3]; 00212 00213 /* setup dummy type info to store static properties in */ 00214 // TODO: perhaps we want to get users to register as if they're using 'KeyingSet' directly instead? 00215 RNA_pointer_create(NULL, &RNA_KeyingSetInfo, &dummyksi, &dummyptr); 00216 00217 /* validate the python class */ 00218 if (validate(&dummyptr, data, have_function) != 0) 00219 return NULL; 00220 00221 if (strlen(identifier) >= sizeof(dummyksi.idname)) { 00222 BKE_reportf(reports, RPT_ERROR, "registering keying set info class: '%s' is too long, maximum length is %d.", identifier, (int)sizeof(dummyksi.idname)); 00223 return NULL; 00224 } 00225 00226 /* check if we have registered this info before, and remove it */ 00227 ksi = ANIM_keyingset_info_find_named(dummyksi.idname); 00228 if (ksi && ksi->ext.srna) 00229 rna_KeyingSetInfo_unregister(bmain, ksi->ext.srna); 00230 00231 /* create a new KeyingSetInfo type */ 00232 ksi= MEM_callocN(sizeof(KeyingSetInfo), "python keying set info"); 00233 memcpy(ksi, &dummyksi, sizeof(KeyingSetInfo)); 00234 00235 /* set RNA-extensions info */ 00236 ksi->ext.srna= RNA_def_struct(&BLENDER_RNA, ksi->idname, "KeyingSetInfo"); 00237 ksi->ext.data= data; 00238 ksi->ext.call= call; 00239 ksi->ext.free= free; 00240 RNA_struct_blender_type_set(ksi->ext.srna, ksi); 00241 00242 /* set callbacks */ 00243 // NOTE: we really should have all of these... 00244 ksi->poll= (have_function[0])? RKS_POLL_rna_internal: NULL; 00245 ksi->iter= (have_function[1])? RKS_ITER_rna_internal: NULL; 00246 ksi->generate= (have_function[2])? RKS_GEN_rna_internal: NULL; 00247 00248 /* add and register with other info as needed */ 00249 ANIM_keyingset_info_register(ksi); 00250 00251 /* return the struct-rna added */ 00252 return ksi->ext.srna; 00253 } 00254 00255 /* ****************************** */ 00256 00257 static StructRNA *rna_ksPath_id_typef(PointerRNA *ptr) 00258 { 00259 KS_Path *ksp= (KS_Path*)ptr->data; 00260 return ID_code_to_RNA_type(ksp->idtype); 00261 } 00262 00263 static int rna_ksPath_id_editable(PointerRNA *ptr) 00264 { 00265 KS_Path *ksp= (KS_Path*)ptr->data; 00266 return (ksp->idtype)? PROP_EDITABLE : 0; 00267 } 00268 00269 static void rna_ksPath_id_type_set(PointerRNA *ptr, int value) 00270 { 00271 KS_Path *data= (KS_Path*)(ptr->data); 00272 00273 /* set the driver type, then clear the id-block if the type is invalid */ 00274 data->idtype= value; 00275 if ((data->id) && (GS(data->id->name) != data->idtype)) 00276 data->id= NULL; 00277 } 00278 00279 static void rna_ksPath_RnaPath_get(PointerRNA *ptr, char *value) 00280 { 00281 KS_Path *ksp= (KS_Path *)ptr->data; 00282 00283 if (ksp->rna_path) 00284 strcpy(value, ksp->rna_path); 00285 else 00286 strcpy(value, ""); 00287 } 00288 00289 static int rna_ksPath_RnaPath_length(PointerRNA *ptr) 00290 { 00291 KS_Path *ksp= (KS_Path *)ptr->data; 00292 00293 if (ksp->rna_path) 00294 return strlen(ksp->rna_path); 00295 else 00296 return 0; 00297 } 00298 00299 static void rna_ksPath_RnaPath_set(PointerRNA *ptr, const char *value) 00300 { 00301 KS_Path *ksp= (KS_Path *)ptr->data; 00302 00303 if (ksp->rna_path) 00304 MEM_freeN(ksp->rna_path); 00305 00306 if (strlen(value)) 00307 ksp->rna_path= BLI_strdup(value); 00308 else 00309 ksp->rna_path= NULL; 00310 } 00311 00312 /* ****************************** */ 00313 00314 static int rna_KeyingSet_active_ksPath_editable(PointerRNA *ptr) 00315 { 00316 KeyingSet *ks= (KeyingSet *)ptr->data; 00317 00318 /* only editable if there are some paths to change to */ 00319 return (ks->paths.first != NULL); 00320 } 00321 00322 static PointerRNA rna_KeyingSet_active_ksPath_get(PointerRNA *ptr) 00323 { 00324 KeyingSet *ks= (KeyingSet *)ptr->data; 00325 return rna_pointer_inherit_refine(ptr, &RNA_KeyingSetPath, BLI_findlink(&ks->paths, ks->active_path-1)); 00326 } 00327 00328 static void rna_KeyingSet_active_ksPath_set(PointerRNA *ptr, PointerRNA value) 00329 { 00330 KeyingSet *ks= (KeyingSet *)ptr->data; 00331 KS_Path *ksp= (KS_Path*)value.data; 00332 ks->active_path= BLI_findindex(&ks->paths, ksp) + 1; 00333 } 00334 00335 static int rna_KeyingSet_active_ksPath_index_get(PointerRNA *ptr) 00336 { 00337 KeyingSet *ks= (KeyingSet *)ptr->data; 00338 return MAX2(ks->active_path-1, 0); 00339 } 00340 00341 static void rna_KeyingSet_active_ksPath_index_set(PointerRNA *ptr, int value) 00342 { 00343 KeyingSet *ks= (KeyingSet *)ptr->data; 00344 ks->active_path= value+1; 00345 } 00346 00347 static void rna_KeyingSet_active_ksPath_index_range(PointerRNA *ptr, int *min, int *max) 00348 { 00349 KeyingSet *ks= (KeyingSet *)ptr->data; 00350 00351 *min= 0; 00352 *max= BLI_countlist(&ks->paths)-1; 00353 *max= MAX2(0, *max); 00354 } 00355 00356 static PointerRNA rna_KeyingSet_typeinfo_get(PointerRNA *ptr) 00357 { 00358 KeyingSet *ks= (KeyingSet *)ptr->data; 00359 KeyingSetInfo *ksi = NULL; 00360 00361 /* keying set info is only for builtin Keying Sets */ 00362 if ((ks->flag & KEYINGSET_ABSOLUTE)==0) 00363 ksi = ANIM_keyingset_info_find_named(ks->typeinfo); 00364 return rna_pointer_inherit_refine(ptr, &RNA_KeyingSetInfo, ksi); 00365 } 00366 00367 00368 00369 static KS_Path *rna_KeyingSet_paths_add(KeyingSet *keyingset, ReportList *reports, 00370 ID *id, const char rna_path[], int index, int group_method, const char group_name[]) 00371 { 00372 KS_Path *ksp = NULL; 00373 short flag = 0; 00374 00375 /* special case when index = -1, we key the whole array (as with other places where index is used) */ 00376 if (index == -1) { 00377 flag |= KSP_FLAG_WHOLE_ARRAY; 00378 index = 0; 00379 } 00380 00381 /* if data is valid, call the API function for this */ 00382 if (keyingset) { 00383 ksp= BKE_keyingset_add_path(keyingset, id, group_name, rna_path, index, flag, group_method); 00384 keyingset->active_path= BLI_countlist(&keyingset->paths); 00385 } 00386 else { 00387 BKE_report(reports, RPT_ERROR, "Keying Set Path could not be added."); 00388 } 00389 00390 /* return added path */ 00391 return ksp; 00392 } 00393 00394 static void rna_KeyingSet_paths_remove(KeyingSet *keyingset, ReportList *reports, KS_Path *ksp) 00395 { 00396 /* if data is valid, call the API function for this */ 00397 if (keyingset && ksp) { 00398 /* remove the active path from the KeyingSet */ 00399 BKE_keyingset_free_path(keyingset, ksp); 00400 00401 /* the active path number will most likely have changed */ 00402 // TODO: we should get more fancy and actually check if it was removed, but this will do for now 00403 keyingset->active_path = 0; 00404 } 00405 else { 00406 BKE_report(reports, RPT_ERROR, "Keying Set Path could not be removed."); 00407 } 00408 } 00409 00410 static void rna_KeyingSet_paths_clear(KeyingSet *keyingset, ReportList *reports) 00411 { 00412 /* if data is valid, call the API function for this */ 00413 if (keyingset) { 00414 KS_Path *ksp, *kspn; 00415 00416 /* free each path as we go to avoid looping twice */ 00417 for (ksp= keyingset->paths.first; ksp; ksp= kspn) { 00418 kspn= ksp->next; 00419 BKE_keyingset_free_path(keyingset, ksp); 00420 } 00421 00422 /* reset the active path, since there aren't any left */ 00423 keyingset->active_path = 0; 00424 } 00425 else { 00426 BKE_report(reports, RPT_ERROR, "Keying Set Paths could not be removed."); 00427 } 00428 } 00429 00430 /* needs wrapper function to push notifier */ 00431 static NlaTrack *rna_NlaTrack_new(AnimData *adt, bContext *C, NlaTrack *track) 00432 { 00433 NlaTrack *new_track = add_nlatrack(adt, track); 00434 00435 WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_ADDED, NULL); 00436 00437 return new_track; 00438 } 00439 00440 static void rna_NlaTrack_remove(AnimData *adt, bContext *C, NlaTrack *track) 00441 { 00442 free_nlatrack(&adt->nla_tracks, track); 00443 00444 WM_event_add_notifier(C, NC_ANIMATION|ND_NLA|NA_REMOVED, NULL); 00445 } 00446 00447 static PointerRNA rna_NlaTrack_active_get(PointerRNA *ptr) 00448 { 00449 AnimData *adt= (AnimData*)ptr->data; 00450 NlaTrack *track= BKE_nlatrack_find_active(&adt->nla_tracks); 00451 return rna_pointer_inherit_refine(ptr, &RNA_NlaTrack, track); 00452 } 00453 00454 static void rna_NlaTrack_active_set(PointerRNA *ptr, PointerRNA value) 00455 { 00456 AnimData *adt= (AnimData*)ptr->data; 00457 NlaTrack *track= (NlaTrack*)value.data; 00458 BKE_nlatrack_set_active(&adt->nla_tracks, track); 00459 } 00460 00461 00462 static FCurve *rna_Driver_from_existing(AnimData *adt, bContext *C, FCurve *src_driver) 00463 { 00464 /* verify that we've got a driver to duplicate */ 00465 if (ELEM(NULL, src_driver, src_driver->driver)) { 00466 BKE_reportf(CTX_wm_reports(C), RPT_ERROR, "No valid driver data to create copy of"); 00467 return NULL; 00468 } 00469 else { 00470 /* just make a copy of the existing one and add to self */ 00471 FCurve *new_fcu = copy_fcurve(src_driver); 00472 00473 // XXX: if we impose any ordering on these someday, this will be problematic 00474 BLI_addtail(&adt->drivers, new_fcu); 00475 return new_fcu; 00476 } 00477 } 00478 00479 #else 00480 00481 /* helper function for Keying Set -> keying settings */ 00482 static void rna_def_common_keying_flags(StructRNA *srna, short reg) 00483 { 00484 PropertyRNA *prop; 00485 00486 static EnumPropertyItem keying_flag_items[] = { 00487 {INSERTKEY_NEEDED, "INSERTKEY_NEEDED", 0, "Insert Keyframes - Only Needed", "Only insert keyframes where they're needed in the relevant F-Curves"}, 00488 {INSERTKEY_MATRIX, "INSERTKEY_VISUAL", 0, "Insert Keyframes - Visual", "Insert keyframes based on 'visual transforms'"}, 00489 {INSERTKEY_XYZ2RGB, "INSERTKEY_XYZ_TO_RGB", 0, "F-Curve Colors - XYZ to RGB", "Color for newly added transformation F-Curves (Location, Rotation, Scale) and also Color is based on the transform axis"}, 00490 {0, NULL, 0, NULL, NULL}}; 00491 00492 prop= RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE); 00493 RNA_def_property_enum_sdna(prop, NULL, "keyingflag"); 00494 RNA_def_property_enum_items(prop, keying_flag_items); 00495 RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL|PROP_ENUM_FLAG); 00496 RNA_def_property_ui_text(prop, "Options", "Keying set options"); 00497 } 00498 00499 /* --- */ 00500 00501 static void rna_def_keyingset_info(BlenderRNA *brna) 00502 { 00503 StructRNA *srna; 00504 PropertyRNA *prop; 00505 FunctionRNA *func; 00506 PropertyRNA *parm; 00507 00508 srna= RNA_def_struct(brna, "KeyingSetInfo", NULL); 00509 RNA_def_struct_sdna(srna, "KeyingSetInfo"); 00510 RNA_def_struct_ui_text(srna, "Keying Set Info", "Callback function defines for builtin Keying Sets"); 00511 RNA_def_struct_refine_func(srna, "rna_KeyingSetInfo_refine"); 00512 RNA_def_struct_register_funcs(srna, "rna_KeyingSetInfo_register", "rna_KeyingSetInfo_unregister", NULL); 00513 00514 /* Properties --------------------- */ 00515 00516 RNA_define_verify_sdna(0); // not in sdna 00517 00518 prop= RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE); 00519 RNA_def_property_string_sdna(prop, NULL, "idname"); 00520 RNA_def_property_flag(prop, PROP_REGISTER|PROP_NEVER_CLAMP); 00521 00522 /* Name */ 00523 prop= RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE); 00524 RNA_def_property_string_sdna(prop, NULL, "name"); 00525 RNA_def_property_ui_text(prop, "Name", ""); 00526 RNA_def_struct_name_property(srna, prop); 00527 RNA_def_property_flag(prop, PROP_REGISTER); 00528 00529 rna_def_common_keying_flags(srna, 1); /* '1' arg here is to indicate that we need these to be set on registering */ 00530 00531 RNA_define_verify_sdna(1); 00532 00533 /* Function Callbacks ------------- */ 00534 /* poll */ 00535 func= RNA_def_function(srna, "poll", NULL); 00536 RNA_def_function_ui_description(func, "Test if Keying Set can be used or not"); 00537 RNA_def_function_flag(func, FUNC_REGISTER); 00538 RNA_def_function_return(func, RNA_def_boolean(func, "ok", 1, "", "")); 00539 parm= RNA_def_pointer(func, "context", "Context", "", ""); 00540 RNA_def_property_flag(parm, PROP_REQUIRED); 00541 00542 /* iterator */ 00543 func= RNA_def_function(srna, "iterator", NULL); 00544 RNA_def_function_ui_description(func, "Call generate() on the structs which have properties to be keyframed"); 00545 RNA_def_function_flag(func, FUNC_REGISTER); 00546 parm= RNA_def_pointer(func, "context", "Context", "", ""); 00547 RNA_def_property_flag(parm, PROP_REQUIRED); 00548 parm= RNA_def_pointer(func, "ks", "KeyingSet", "", ""); 00549 RNA_def_property_flag(parm, PROP_REQUIRED); 00550 00551 /* generate */ 00552 func= RNA_def_function(srna, "generate", NULL); 00553 RNA_def_function_ui_description(func, "Add Paths to the Keying Set to keyframe the properties of the given data"); 00554 RNA_def_function_flag(func, FUNC_REGISTER); 00555 parm= RNA_def_pointer(func, "context", "Context", "", ""); 00556 RNA_def_property_flag(parm, PROP_REQUIRED); 00557 parm= RNA_def_pointer(func, "ks", "KeyingSet", "", ""); 00558 RNA_def_property_flag(parm, PROP_REQUIRED); 00559 parm= RNA_def_pointer(func, "data", "AnyType", "", ""); 00560 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_RNAPTR|PROP_NEVER_NULL); 00561 } 00562 00563 static void rna_def_keyingset_path(BlenderRNA *brna) 00564 { 00565 StructRNA *srna; 00566 PropertyRNA *prop; 00567 00568 srna= RNA_def_struct(brna, "KeyingSetPath", NULL); 00569 RNA_def_struct_sdna(srna, "KS_Path"); 00570 RNA_def_struct_ui_text(srna, "Keying Set Path", "Path to a setting for use in a Keying Set"); 00571 00572 /* ID */ 00573 prop= RNA_def_property(srna, "id", PROP_POINTER, PROP_NONE); 00574 RNA_def_property_struct_type(prop, "ID"); 00575 RNA_def_property_flag(prop, PROP_EDITABLE); 00576 RNA_def_property_editable_func(prop, "rna_ksPath_id_editable"); 00577 RNA_def_property_pointer_funcs(prop, NULL, NULL, "rna_ksPath_id_typef", NULL); 00578 RNA_def_property_ui_text(prop, "ID-Block", "ID-Block that keyframes for Keying Set should be added to (for Absolute Keying Sets only)"); 00579 RNA_def_property_update(prop, NC_SCENE|ND_KEYINGSET|NA_EDITED, NULL); // XXX: maybe a bit too noisy 00580 00581 prop= RNA_def_property(srna, "id_type", PROP_ENUM, PROP_NONE); 00582 RNA_def_property_enum_sdna(prop, NULL, "idtype"); 00583 RNA_def_property_enum_items(prop, id_type_items); 00584 RNA_def_property_enum_default(prop, ID_OB); 00585 RNA_def_property_enum_funcs(prop, NULL, "rna_ksPath_id_type_set", NULL); 00586 RNA_def_property_ui_text(prop, "ID Type", "Type of ID-block that can be used"); 00587 RNA_def_property_update(prop, NC_SCENE|ND_KEYINGSET|NA_EDITED, NULL); // XXX: maybe a bit too noisy 00588 00589 /* Group */ 00590 prop= RNA_def_property(srna, "group", PROP_STRING, PROP_NONE); 00591 RNA_def_property_ui_text(prop, "Group Name", "Name of Action Group to assign setting(s) for this path to"); 00592 RNA_def_property_update(prop, NC_SCENE|ND_KEYINGSET|NA_EDITED, NULL); // XXX: maybe a bit too noisy 00593 00594 /* Grouping */ 00595 prop= RNA_def_property(srna, "group_method", PROP_ENUM, PROP_NONE); 00596 RNA_def_property_enum_sdna(prop, NULL, "groupmode"); 00597 RNA_def_property_enum_items(prop, keyingset_path_grouping_items); 00598 RNA_def_property_ui_text(prop, "Grouping Method", "Method used to define which Group-name to use"); 00599 RNA_def_property_update(prop, NC_SCENE|ND_KEYINGSET|NA_EDITED, NULL); // XXX: maybe a bit too noisy 00600 00601 /* Path + Array Index */ 00602 prop= RNA_def_property(srna, "data_path", PROP_STRING, PROP_NONE); 00603 RNA_def_property_string_funcs(prop, "rna_ksPath_RnaPath_get", "rna_ksPath_RnaPath_length", "rna_ksPath_RnaPath_set"); 00604 RNA_def_property_ui_text(prop, "Data Path", "Path to property setting"); 00605 RNA_def_struct_name_property(srna, prop); // XXX this is the best indicator for now... 00606 RNA_def_property_update(prop, NC_SCENE|ND_KEYINGSET|NA_EDITED, NULL); 00607 00608 /* called 'index' when given as function arg */ 00609 prop= RNA_def_property(srna, "array_index", PROP_INT, PROP_NONE); 00610 RNA_def_property_ui_text(prop, "RNA Array Index", "Index to the specific setting if applicable"); 00611 RNA_def_property_update(prop, NC_SCENE|ND_KEYINGSET|NA_EDITED, NULL); // XXX: maybe a bit too noisy 00612 00613 /* Flags */ 00614 prop= RNA_def_property(srna, "use_entire_array", PROP_BOOLEAN, PROP_NONE); 00615 RNA_def_property_boolean_sdna(prop, NULL, "flag", KSP_FLAG_WHOLE_ARRAY); 00616 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"); 00617 RNA_def_property_update(prop, NC_SCENE|ND_KEYINGSET|NA_EDITED, NULL); // XXX: maybe a bit too noisy 00618 00619 /* Keyframing Settings */ 00620 rna_def_common_keying_flags(srna, 0); 00621 } 00622 00623 00624 /* keyingset.paths */ 00625 static void rna_def_keyingset_paths(BlenderRNA *brna, PropertyRNA *cprop) 00626 { 00627 StructRNA *srna; 00628 00629 FunctionRNA *func; 00630 PropertyRNA *parm; 00631 00632 PropertyRNA *prop; 00633 00634 RNA_def_property_srna(cprop, "KeyingSetPaths"); 00635 srna= RNA_def_struct(brna, "KeyingSetPaths", NULL); 00636 RNA_def_struct_sdna(srna, "KeyingSet"); 00637 RNA_def_struct_ui_text(srna, "Keying set paths", "Collection of keying set paths"); 00638 00639 00640 /* Add Path */ 00641 func= RNA_def_function(srna, "add", "rna_KeyingSet_paths_add"); 00642 RNA_def_function_ui_description(func, "Add a new path for the Keying Set."); 00643 RNA_def_function_flag(func, FUNC_USE_REPORTS); 00644 /* return arg */ 00645 parm= RNA_def_pointer(func, "ksp", "KeyingSetPath", "New Path", "Path created and added to the Keying Set"); 00646 RNA_def_function_return(func, parm); 00647 /* ID-block for target */ 00648 parm= RNA_def_pointer(func, "target_id", "ID", "Target ID", "ID-Datablock for the destination."); 00649 RNA_def_property_flag(parm, PROP_REQUIRED); 00650 /* rna-path */ 00651 parm= RNA_def_string(func, "data_path", "", 256, "Data-Path", "RNA-Path to destination property."); // xxx hopefully this is long enough 00652 RNA_def_property_flag(parm, PROP_REQUIRED); 00653 /* index (defaults to -1 for entire array) */ 00654 RNA_def_int(func, "index", -1, -1, INT_MAX, "Index", "The index of the destination property (i.e. axis of Location/Rotation/etc.), or -1 for the entire array.", 0, INT_MAX); 00655 /* grouping */ 00656 RNA_def_enum(func, "group_method", keyingset_path_grouping_items, KSP_GROUP_KSNAME, "Grouping Method", "Method used to define which Group-name to use."); 00657 RNA_def_string(func, "group_name", "", 64, "Group Name", "Name of Action Group to assign destination to (only if grouping mode is to use this name)."); 00658 00659 00660 /* Remove Path */ 00661 func= RNA_def_function(srna, "remove", "rna_KeyingSet_paths_remove"); 00662 RNA_def_function_ui_description(func, "Remove the given path from the Keying Set."); 00663 RNA_def_function_flag(func, FUNC_USE_REPORTS); 00664 /* path to remove */ 00665 parm= RNA_def_pointer(func, "path", "KeyingSetPath", "Path", ""); 00666 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); 00667 00668 00669 /* Remove All Paths */ 00670 func= RNA_def_function(srna, "clear", "rna_KeyingSet_paths_clear"); 00671 RNA_def_function_ui_description(func, "Remove all the paths from the Keying Set."); 00672 RNA_def_function_flag(func, FUNC_USE_REPORTS); 00673 00674 prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE); 00675 RNA_def_property_struct_type(prop, "KeyingSetPath"); 00676 RNA_def_property_flag(prop, PROP_EDITABLE); 00677 RNA_def_property_editable_func(prop, "rna_KeyingSet_active_ksPath_editable"); 00678 RNA_def_property_pointer_funcs(prop, "rna_KeyingSet_active_ksPath_get", "rna_KeyingSet_active_ksPath_set", NULL, NULL); 00679 RNA_def_property_ui_text(prop, "Active Keying Set", "Active Keying Set used to insert/delete keyframes"); 00680 00681 prop= RNA_def_property(srna, "active_index", PROP_INT, PROP_NONE); 00682 RNA_def_property_int_sdna(prop, NULL, "active_path"); 00683 RNA_def_property_int_funcs(prop, "rna_KeyingSet_active_ksPath_index_get", "rna_KeyingSet_active_ksPath_index_set", "rna_KeyingSet_active_ksPath_index_range"); 00684 RNA_def_property_ui_text(prop, "Active Path Index", "Current Keying Set index"); 00685 } 00686 00687 static void rna_def_keyingset(BlenderRNA *brna) 00688 { 00689 StructRNA *srna; 00690 PropertyRNA *prop; 00691 00692 srna= RNA_def_struct(brna, "KeyingSet", NULL); 00693 RNA_def_struct_ui_text(srna, "Keying Set", "Settings that should be keyframed together"); 00694 00695 /* Name */ 00696 prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); 00697 RNA_def_property_ui_text(prop, "Name", ""); 00698 RNA_def_struct_ui_icon(srna, ICON_KEY_HLT); // TODO: we need a dedicated icon 00699 RNA_def_struct_name_property(srna, prop); 00700 RNA_def_property_update(prop, NC_SCENE|ND_KEYINGSET|NA_RENAME, NULL); 00701 00702 /* KeyingSetInfo (Type Info) for Builtin Sets only */ 00703 prop= RNA_def_property(srna, "type_info", PROP_POINTER, PROP_NONE); 00704 RNA_def_property_struct_type(prop, "KeyingSetInfo"); 00705 RNA_def_property_pointer_funcs(prop, "rna_KeyingSet_typeinfo_get", NULL, NULL, NULL); 00706 RNA_def_property_ui_text(prop, "Type Info", "Callback function defines for built-in Keying Sets"); 00707 00708 /* Paths */ 00709 prop= RNA_def_property(srna, "paths", PROP_COLLECTION, PROP_NONE); 00710 RNA_def_property_collection_sdna(prop, NULL, "paths", NULL); 00711 RNA_def_property_struct_type(prop, "KeyingSetPath"); 00712 RNA_def_property_ui_text(prop, "Paths", "Keying Set Paths to define settings that get keyframed together"); 00713 rna_def_keyingset_paths(brna, prop); 00714 00715 /* Flags */ 00716 prop= RNA_def_property(srna, "is_path_absolute", PROP_BOOLEAN, PROP_NONE); 00717 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00718 RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYINGSET_ABSOLUTE); 00719 RNA_def_property_ui_text(prop, "Absolute", "Keying Set defines specific paths/settings to be keyframed (i.e. is not reliant on context info)"); 00720 00721 /* Keyframing Flags */ 00722 rna_def_common_keying_flags(srna, 0); 00723 00724 00725 /* Keying Set API */ 00726 RNA_api_keyingset(srna); 00727 } 00728 00729 /* --- */ 00730 00731 static void rna_api_animdata_nla_tracks(BlenderRNA *brna, PropertyRNA *cprop) 00732 { 00733 StructRNA *srna; 00734 PropertyRNA *parm; 00735 FunctionRNA *func; 00736 00737 PropertyRNA *prop; 00738 00739 RNA_def_property_srna(cprop, "NlaTracks"); 00740 srna= RNA_def_struct(brna, "NlaTracks", NULL); 00741 RNA_def_struct_sdna(srna, "AnimData"); 00742 RNA_def_struct_ui_text(srna, "NLA Tracks", "Collection of NLA Tracks"); 00743 00744 func = RNA_def_function(srna, "new", "rna_NlaTrack_new"); 00745 RNA_def_function_flag(func, FUNC_USE_CONTEXT); 00746 RNA_def_function_ui_description(func, "Add a new NLA Track"); 00747 RNA_def_pointer(func, "prev", "NlaTrack", "", "NLA Track to add the new one after."); 00748 /* return type */ 00749 parm = RNA_def_pointer(func, "track", "NlaTrack", "", "New NLA Track."); 00750 RNA_def_function_return(func, parm); 00751 00752 func = RNA_def_function(srna, "remove", "rna_NlaTrack_remove"); 00753 RNA_def_function_flag(func, FUNC_USE_CONTEXT); 00754 RNA_def_function_ui_description(func, "Remove a NLA Track."); 00755 parm = RNA_def_pointer(func, "track", "NlaTrack", "", "NLA Track to remove."); 00756 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL); 00757 00758 prop= RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE); 00759 RNA_def_property_struct_type(prop, "NlaTrack"); 00760 RNA_def_property_pointer_funcs(prop, "rna_NlaTrack_active_get", "rna_NlaTrack_active_set", NULL, NULL); 00761 RNA_def_property_flag(prop, PROP_EDITABLE); 00762 RNA_def_property_ui_text(prop, "Active Constraint", "Active Object constraint"); 00763 /* XXX: should (but doesn't) update the active track in the NLA window */ 00764 RNA_def_property_update(prop, NC_ANIMATION|ND_NLA|NA_SELECTED, NULL); 00765 } 00766 00767 static void rna_api_animdata_drivers(BlenderRNA *brna, PropertyRNA *cprop) 00768 { 00769 StructRNA *srna; 00770 PropertyRNA *parm; 00771 FunctionRNA *func; 00772 00773 // PropertyRNA *prop; 00774 00775 RNA_def_property_srna(cprop, "AnimDataDrivers"); 00776 srna= RNA_def_struct(brna, "AnimDataDrivers", NULL); 00777 RNA_def_struct_sdna(srna, "AnimData"); 00778 RNA_def_struct_ui_text(srna, "Drivers", "Collection of Driver F-Curves"); 00779 00780 func = RNA_def_function(srna, "from_existing", "rna_Driver_from_existing"); 00781 RNA_def_function_flag(func, FUNC_USE_CONTEXT); 00782 RNA_def_function_ui_description(func, "Add a new driver given an existing one"); 00783 RNA_def_pointer(func, "src_driver", "FCurve", "", "Existing Driver F-Curve to use as template for a new one"); 00784 /* return type */ 00785 parm = RNA_def_pointer(func, "driver", "FCurve", "", "New Driver F-Curve."); 00786 RNA_def_function_return(func, parm); 00787 } 00788 00789 void rna_def_animdata_common(StructRNA *srna) 00790 { 00791 PropertyRNA *prop; 00792 00793 prop= RNA_def_property(srna, "animation_data", PROP_POINTER, PROP_NONE); 00794 RNA_def_property_pointer_sdna(prop, NULL, "adt"); 00795 RNA_def_property_clear_flag(prop, PROP_EDITABLE); 00796 RNA_def_property_ui_text(prop, "Animation Data", "Animation data for this datablock"); 00797 } 00798 00799 void rna_def_animdata(BlenderRNA *brna) 00800 { 00801 StructRNA *srna; 00802 PropertyRNA *prop; 00803 00804 srna= RNA_def_struct(brna, "AnimData", NULL); 00805 RNA_def_struct_ui_text(srna, "Animation Data", "Animation data for datablock"); 00806 00807 /* NLA */ 00808 prop= RNA_def_property(srna, "nla_tracks", PROP_COLLECTION, PROP_NONE); 00809 RNA_def_property_collection_sdna(prop, NULL, "nla_tracks", NULL); 00810 RNA_def_property_struct_type(prop, "NlaTrack"); 00811 RNA_def_property_ui_text(prop, "NLA Tracks", "NLA Tracks (i.e. Animation Layers)"); 00812 00813 rna_api_animdata_nla_tracks(brna, prop); 00814 00815 /* Active Action */ 00816 prop= RNA_def_property(srna, "action", PROP_POINTER, PROP_NONE); 00817 RNA_def_property_flag(prop, PROP_EDITABLE); /* this flag as well as the dynamic test must be defined for this to be editable... */ 00818 RNA_def_property_pointer_funcs(prop, NULL, "rna_AnimData_action_set", NULL, "rna_Action_id_poll"); 00819 RNA_def_property_editable_func(prop, "rna_AnimData_action_editable"); 00820 RNA_def_property_ui_text(prop, "Action", "Active Action for this datablock"); 00821 RNA_def_property_update(prop, NC_ANIMATION, NULL); /* this will do? */ 00822 00823 /* Active Action Settings */ 00824 prop= RNA_def_property(srna, "action_extrapolation", PROP_ENUM, PROP_NONE); 00825 RNA_def_property_enum_sdna(prop, NULL, "act_extendmode"); 00826 RNA_def_property_enum_items(prop, nla_mode_extend_items); 00827 RNA_def_property_ui_text(prop, "Action Extrapolation", "Action to take for gaps past the Active Action's range (when evaluating with NLA)"); 00828 RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */ 00829 00830 prop= RNA_def_property(srna, "action_blend_type", PROP_ENUM, PROP_NONE); 00831 RNA_def_property_enum_sdna(prop, NULL, "act_blendmode"); 00832 RNA_def_property_enum_items(prop, nla_mode_blend_items); 00833 RNA_def_property_ui_text(prop, "Action Blending", "Method used for combining Active Action's result with result of NLA stack"); 00834 RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */ 00835 00836 prop= RNA_def_property(srna, "action_influence", PROP_FLOAT, PROP_NONE); 00837 RNA_def_property_float_sdna(prop, NULL, "act_influence"); 00838 RNA_def_property_float_default(prop, 1.0f); 00839 RNA_def_property_range(prop, 0.0f, 1.0f); 00840 RNA_def_property_ui_text(prop, "Action Influence", "Amount the Active Action contributes to the result of the NLA stack"); 00841 RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */ 00842 00843 /* Drivers */ 00844 prop= RNA_def_property(srna, "drivers", PROP_COLLECTION, PROP_NONE); 00845 RNA_def_property_collection_sdna(prop, NULL, "drivers", NULL); 00846 RNA_def_property_struct_type(prop, "FCurve"); 00847 RNA_def_property_ui_text(prop, "Drivers", "The Drivers/Expressions for this datablock"); 00848 00849 rna_api_animdata_drivers(brna, prop); 00850 00851 /* General Settings */ 00852 prop= RNA_def_property(srna, "use_nla", PROP_BOOLEAN, PROP_NONE); 00853 RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", ADT_NLA_EVAL_OFF); 00854 RNA_def_property_ui_text(prop, "NLA Evaluation Enabled", "NLA stack is evaluated when evaluating this block"); 00855 RNA_def_property_update(prop, NC_ANIMATION|ND_NLA, NULL); /* this will do? */ 00856 } 00857 00858 /* --- */ 00859 00860 void RNA_def_animation(BlenderRNA *brna) 00861 { 00862 rna_def_animdata(brna); 00863 00864 rna_def_keyingset(brna); 00865 rna_def_keyingset_path(brna); 00866 rna_def_keyingset_info(brna); 00867 } 00868 00869 #endif