/* This function should always be used to get the appropriate type-info, as it * has checks which prevent segfaults in some weird cases. */ FModifierTypeInfo *fmodifier_get_typeinfo(FModifier *fcm) { /* only return typeinfo for valid modifiers */ if (fcm) return get_fmodifier_typeinfo(fcm->type); else return NULL; }
/* This function should always be used to get the appropriate type-info, as it * has checks which prevent segfaults in some weird cases. */ const FModifierTypeInfo *fmodifier_get_typeinfo(const FModifier *fcm) { /* only return typeinfo for valid modifiers */ if (fcm) { return get_fmodifier_typeinfo(fcm->type); } else { return NULL; } }
/* Add a new F-Curve Modifier to the given F-Curve of a certain type */ FModifier *add_fmodifier(ListBase *modifiers, int type, FCurve *owner_fcu) { const FModifierTypeInfo *fmi = get_fmodifier_typeinfo(type); FModifier *fcm; /* sanity checks */ if (ELEM(NULL, modifiers, fmi)) { return NULL; } /* special checks for whether modifier can be added */ 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 */ /* TODO: perhaps there is some better way, but for now, */ CLOG_STR_ERROR(&LOG, "Cannot add 'Cycles' modifier to F-Curve, as 'Cycles' modifier can only be " "first in stack."); return NULL; } /* add modifier itself */ fcm = MEM_callocN(sizeof(FModifier), "F-Curve Modifier"); fcm->type = type; fcm->flag = FMODIFIER_FLAG_EXPANDED; fcm->curve = owner_fcu; fcm->influence = 1.0f; BLI_addtail(modifiers, fcm); /* tag modifier as "active" if no other modifiers exist in the stack yet */ if (BLI_listbase_is_single(modifiers)) { fcm->flag |= FMODIFIER_FLAG_ACTIVE; } /* add modifier's data */ fcm->data = MEM_callocN(fmi->size, fmi->structName); /* init custom settings if necessary */ if (fmi->new_data) { fmi->new_data(fcm->data); } /* update the fcurve if the Cycles modifier is added */ if ((owner_fcu) && (type == FMODIFIER_TYPE_CYCLES)) { calchandles_fcurve(owner_fcu); } /* return modifier for further editing */ return fcm; }
/* Add a new F-Curve Modifier to the given F-Curve of a certain type */ FModifier *add_fmodifier(ListBase *modifiers, int type) { FModifierTypeInfo *fmi = get_fmodifier_typeinfo(type); FModifier *fcm; /* sanity checks */ if (ELEM(NULL, modifiers, fmi)) return NULL; /* special checks for whether modifier can be added */ 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 */ // 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"); return NULL; } /* add modifier itself */ fcm = MEM_callocN(sizeof(FModifier), "F-Curve Modifier"); fcm->type = type; fcm->flag = FMODIFIER_FLAG_EXPANDED; fcm->influence = 1.0f; BLI_addtail(modifiers, fcm); /* tag modifier as "active" if no other modifiers exist in the stack yet */ if (modifiers->first == modifiers->last) fcm->flag |= FMODIFIER_FLAG_ACTIVE; /* add modifier's data */ fcm->data = MEM_callocN(fmi->size, fmi->structName); /* init custom settings if necessary */ if (fmi->new_data) fmi->new_data(fcm->data); /* return modifier for further editing */ return fcm; }