Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/fmodifier.c
| Show All 29 Lines | |||||
| #include <math.h> | #include <math.h> | ||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <stddef.h> | #include <stddef.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include <float.h> | #include <float.h> | ||||
| #include "MEM_guardedalloc.h" | #include "MEM_guardedalloc.h" | ||||
| #include "CLG_log.h" | |||||
| #include "DNA_anim_types.h" | #include "DNA_anim_types.h" | ||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| #include "BLI_blenlib.h" | #include "BLI_blenlib.h" | ||||
| #include "BLI_ghash.h" | #include "BLI_ghash.h" | ||||
| #include "BLI_noise.h" | #include "BLI_noise.h" | ||||
| #include "BLI_math.h" /* windows needs for M_PI */ | #include "BLI_math.h" /* windows needs for M_PI */ | ||||
| #include "BLI_utildefines.h" | #include "BLI_utildefines.h" | ||||
| #include "BKE_fcurve.h" | #include "BKE_fcurve.h" | ||||
| #include "BKE_idprop.h" | #include "BKE_idprop.h" | ||||
| static CLG_LogRef LOG = {"bke.fmodifier"}; | |||||
| /* ******************************** F-Modifiers ********************************* */ | /* ******************************** F-Modifiers ********************************* */ | ||||
| /* Forward declarations. */ | /* Forward declarations. */ | ||||
| void fmodifiers_storage_put(FModifierStackStorage *storage, FModifier *fcm, void *data); | void fmodifiers_storage_put(FModifierStackStorage *storage, FModifier *fcm, void *data); | ||||
| void fmodifiers_storage_remove(FModifierStackStorage *storage, FModifier *fcm); | void fmodifiers_storage_remove(FModifierStackStorage *storage, FModifier *fcm); | ||||
| void *fmodifiers_storage_get(FModifierStackStorage *storage, FModifier *fcm); | void *fmodifiers_storage_get(FModifierStackStorage *storage, FModifier *fcm); | ||||
| /* Info ------------------------------- */ | /* Info ------------------------------- */ | ||||
| ▲ Show 20 Lines • Show All 278 Lines • ▼ Show 20 Lines | case FCM_GENERATOR_FN_SQRT: /* square root */ | ||||
| } | } | ||||
| else { | else { | ||||
| if ((data->flag & FCM_GENERATOR_ADDITIVE) == 0) | if ((data->flag & FCM_GENERATOR_ADDITIVE) == 0) | ||||
| *cvalue = 0.0f; /* no value possible here */ | *cvalue = 0.0f; /* no value possible here */ | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| default: | default: | ||||
| printf("Invalid Function-Generator for F-Modifier - %d\n", data->type); | CLOG_ERROR(&LOG, "Invalid Function-Generator for F-Modifier - %d", data->type); | ||||
| break; | break; | ||||
| } | } | ||||
| /* execute function callback to set value if appropriate */ | /* execute function callback to set value if appropriate */ | ||||
| if (fn) { | if (fn) { | ||||
| float value = (float)(data->amplitude * (float)fn(arg) + data->value_offset); | float value = (float)(data->amplitude * (float)fn(arg) + data->value_offset); | ||||
| ▲ Show 20 Lines • Show All 145 Lines • ▼ Show 20 Lines | int BKE_fcm_envelope_find_index(FCM_EnvelopeData array[], float frame, int arraylen, bool *r_exists) | ||||
| /* initialize exists-flag first */ | /* initialize exists-flag first */ | ||||
| *r_exists = false; | *r_exists = false; | ||||
| /* sneaky optimizations (don't go through searching process if...): | /* sneaky optimizations (don't go through searching process if...): | ||||
| * - keyframe to be added is to be added out of current bounds | * - keyframe to be added is to be added out of current bounds | ||||
| * - keyframe to be added would replace one of the existing ones on bounds | * - keyframe to be added would replace one of the existing ones on bounds | ||||
| */ | */ | ||||
| if ((arraylen <= 0) || (array == NULL)) { | if ((arraylen <= 0) || (array == NULL)) { | ||||
| printf("Warning: binarysearch_fcm_envelopedata_index() encountered invalid array\n"); | CLOG_WARN(&LOG, "encountered invalid array"); | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| else { | else { | ||||
| /* check whether to add before/after/on */ | /* check whether to add before/after/on */ | ||||
| float framenum; | float framenum; | ||||
| /* 'First' Point (when only one point, this case is used) */ | /* 'First' Point (when only one point, this case is used) */ | ||||
| framenum = array[0].time; | framenum = array[0].time; | ||||
| Show All 37 Lines | for (loopbreaker = 0; (start <= end) && (loopbreaker < maxloop); loopbreaker++) { | ||||
| } | } | ||||
| else if (frame < midfra) { | else if (frame < midfra) { | ||||
| end = mid - 1; | end = mid - 1; | ||||
| } | } | ||||
| } | } | ||||
| /* print error if loop-limit exceeded */ | /* print error if loop-limit exceeded */ | ||||
| if (loopbreaker == (maxloop - 1)) { | if (loopbreaker == (maxloop - 1)) { | ||||
| printf("Error: binarysearch_fcm_envelopedata_index() was taking too long\n"); | CLOG_ERROR(&LOG, "binary search was taking too long"); | ||||
| // include debug info | // include debug info | ||||
| printf("\tround = %d: start = %d, end = %d, arraylen = %d\n", loopbreaker, start, end, arraylen); | CLOG_ERROR(&LOG, "\tround = %d: start = %d, end = %d, arraylen = %d", loopbreaker, start, end, arraylen); | ||||
| } | } | ||||
| /* not found, so return where to place it */ | /* not found, so return where to place it */ | ||||
| return start; | return start; | ||||
| } | } | ||||
| #undef BINARYSEARCH_FRAMEEQ_THRESH | #undef BINARYSEARCH_FRAMEEQ_THRESH | ||||
| ▲ Show 20 Lines • Show All 457 Lines • ▼ Show 20 Lines | const FModifierTypeInfo *get_fmodifier_typeinfo(const int type) | ||||
| /* only return for valid types */ | /* only return for valid types */ | ||||
| if ((type >= FMODIFIER_TYPE_NULL) && | if ((type >= FMODIFIER_TYPE_NULL) && | ||||
| (type < FMODIFIER_NUM_TYPES)) | (type < FMODIFIER_NUM_TYPES)) | ||||
| { | { | ||||
| /* there shouldn't be any segfaults here... */ | /* there shouldn't be any segfaults here... */ | ||||
| return fmodifiersTypeInfo[type]; | return fmodifiersTypeInfo[type]; | ||||
| } | } | ||||
| else { | else { | ||||
| printf("No valid F-Curve Modifier type-info data available. Type = %i\n", type); | CLOG_ERROR(&LOG, "No valid F-Curve Modifier type-info data available. Type = %i", type); | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* This function should always be used to get the appropriate type-info, as it | /* This function should always be used to get the appropriate type-info, as it | ||||
| * has checks which prevent segfaults in some weird cases. | * has checks which prevent segfaults in some weird cases. | ||||
| */ | */ | ||||
| Show All 17 Lines | FModifier *add_fmodifier(ListBase *modifiers, int type, FCurve *owner_fcu) | ||||
| /* sanity checks */ | /* sanity checks */ | ||||
| if (ELEM(NULL, modifiers, fmi)) | if (ELEM(NULL, modifiers, fmi)) | ||||
| return NULL; | return NULL; | ||||
| /* special checks for whether modifier can be added */ | /* special checks for whether modifier can be added */ | ||||
| if ((modifiers->first) && (type == FMODIFIER_TYPE_CYCLES)) { | if ((modifiers->first) && (type == FMODIFIER_TYPE_CYCLES)) { | ||||
| /* cycles modifier must be first in stack, so for now, don't add if it can't be */ | /* cycles modifier must be first in stack, so for now, don't add if it can't be */ | ||||
| /* TODO: perhaps there is some better way, but for now, */ | /* TODO: perhaps there is some better way, but for now, */ | ||||
| printf("Error: Cannot add 'Cycles' modifier to F-Curve, as 'Cycles' modifier can only be first in stack.\n"); | CLOG_STR_ERROR(&LOG, "Cannot add 'Cycles' modifier to F-Curve, as 'Cycles' modifier can only be first in stack."); | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| /* add modifier itself */ | /* add modifier itself */ | ||||
| fcm = MEM_callocN(sizeof(FModifier), "F-Curve Modifier"); | fcm = MEM_callocN(sizeof(FModifier), "F-Curve Modifier"); | ||||
| fcm->type = type; | fcm->type = type; | ||||
| fcm->flag = FMODIFIER_FLAG_EXPANDED; | fcm->flag = FMODIFIER_FLAG_EXPANDED; | ||||
| fcm->curve = owner_fcu; | fcm->curve = owner_fcu; | ||||
| ▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | if (modifiers) { | ||||
| /* update the fcurve if the Cycles modifier is removed */ | /* update the fcurve if the Cycles modifier is removed */ | ||||
| if (update_fcu) | if (update_fcu) | ||||
| calchandles_fcurve(update_fcu); | calchandles_fcurve(update_fcu); | ||||
| return true; | return true; | ||||
| } | } | ||||
| else { | else { | ||||
| /* XXX this case can probably be removed some day, as it shouldn't happen... */ | /* XXX this case can probably be removed some day, as it shouldn't happen... */ | ||||
| printf("remove_fmodifier() - no modifier stack given\n"); | CLOG_STR_ERROR(&LOG, "no modifier stack given"); | ||||
| MEM_freeN(fcm); | MEM_freeN(fcm); | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| /* Remove all of a given F-Curve's modifiers */ | /* Remove all of a given F-Curve's modifiers */ | ||||
| void free_fmodifiers(ListBase *modifiers) | void free_fmodifiers(ListBase *modifiers) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 298 Lines • ▼ Show 20 Lines | |||||
| /* Bake modifiers for given F-Curve to curve sample data, in the frame range defined | /* Bake modifiers for given F-Curve to curve sample data, in the frame range defined | ||||
| * by start and end (inclusive). | * by start and end (inclusive). | ||||
| */ | */ | ||||
| void fcurve_bake_modifiers(FCurve *fcu, int start, int end) | void fcurve_bake_modifiers(FCurve *fcu, int start, int end) | ||||
| { | { | ||||
| ChannelDriver *driver; | ChannelDriver *driver; | ||||
| /* sanity checks */ | /* sanity checks */ | ||||
| /* TODO: make these tests report errors using reports not printf's */ | /* TODO: make these tests report errors using reports not CLOG's */ | ||||
| if (ELEM(NULL, fcu, fcu->modifiers.first)) { | if (ELEM(NULL, fcu, fcu->modifiers.first)) { | ||||
| printf("Error: No F-Curve with F-Curve Modifiers to Bake\n"); | CLOG_ERROR(&LOG, "No F-Curve with F-Curve Modifiers to Bake"); | ||||
| return; | return; | ||||
| } | } | ||||
| /* temporarily, disable driver while we sample, so that they don't influence the outcome */ | /* temporarily, disable driver while we sample, so that they don't influence the outcome */ | ||||
| driver = fcu->driver; | driver = fcu->driver; | ||||
| fcu->driver = NULL; | fcu->driver = NULL; | ||||
| /* bake the modifiers, by sampling the curve at each frame */ | /* bake the modifiers, by sampling the curve at each frame */ | ||||
| fcurve_store_samples(fcu, NULL, start, end, fcurve_samplingcb_evalcurve); | fcurve_store_samples(fcu, NULL, start, end, fcurve_samplingcb_evalcurve); | ||||
| /* free the modifiers now */ | /* free the modifiers now */ | ||||
| free_fmodifiers(&fcu->modifiers); | free_fmodifiers(&fcu->modifiers); | ||||
| /* restore driver */ | /* restore driver */ | ||||
| fcu->driver = driver; | fcu->driver = driver; | ||||
| } | } | ||||