65static FModifierTypeInfo FMI_MODNAME = {
66 FMODIFIER_TYPE_MODNAME,
69 FMI_REQUIRES_SOME_REQUIREMENT,
97 if (
data->coefficients) {
98 MEM_delete(
data->coefficients);
119 data->poly_order = 1;
131 switch (
data->mode) {
134 const int arraysize_new =
data->poly_order + 1;
136 if (
data->arraysize != arraysize_new) {
137 data->coefficients =
static_cast<float *
>(
139 data->arraysize = arraysize_new;
145 const int arraysize_new =
data->poly_order * 2;
147 if (
data->arraysize != arraysize_new) {
148 data->coefficients =
static_cast<float *
>(
150 data->arraysize = arraysize_new;
168 switch (
data->mode) {
178 for (
uint i = 0; i <
data->arraysize; i++) {
181 powers[i] = powers[i - 1] * evaltime;
189 for (
uint i = 0; i <
data->arraysize; i++) {
190 value +=
data->coefficients[i] * powers[i];
194 if (
data->poly_order) {
211 float value = 1.0f, *cp =
nullptr;
216 for (cp =
data->coefficients, i = 0; (cp) && (i <
uint(
data->poly_order)); cp += 2, i++) {
217 value *= (cp[0] * evaltime + cp[1]);
221 if (
data->poly_order) {
267 data->amplitude = 1.0f;
268 data->phase_multiplier = 1.0f;
277 if (
fabs(
x) < 0.0001) {
291 double arg =
data->phase_multiplier * evaltime +
data->phase_offset;
292 double (*
fn)(
double v) =
nullptr;
297 switch (
data->type) {
373 "FMod_FunctionGenerator",
391 MEM_delete(env->
data);
402 env->
data = MEM_dupalloc(oenv->
data);
433 float min = 0.0f,
max = 0.0f, fac = 0.0f;
437 if (env->
data ==
nullptr) {
442 lastfed = prevfed + (env->
totvert - 1);
445 if (prevfed->
time >= evaltime) {
450 else if (lastfed->
time <= evaltime) {
458 for (a = 0; prevfed && fed && (a < env->
totvert - 1); a++, prevfed = fed, fed++) {
460 if ((prevfed->time <= evaltime) && (fed->time >= evaltime)) {
461 float afac, bfac,
diff;
463 diff = fed->time - prevfed->time;
464 afac = (evaltime - prevfed->time) /
diff;
465 bfac = (fed->time - evaltime) /
diff;
467 min = bfac * prevfed->min + afac * fed->min;
468 max = bfac * prevfed->max + afac * fed->max;
504#define BINARYSEARCH_FRAMEEQ_THRESH 0.0001f
511 int start = 0, end = arraylen;
512 int loopbreaker = 0, maxloop = arraylen * 2;
521 if ((arraylen <= 0) || (
array ==
nullptr)) {
530 framenum =
array[0].time;
535 if (frame < framenum) {
540 framenum =
array[(arraylen - 1)].time;
543 return (arraylen - 1);
545 if (frame > framenum) {
552 for (loopbreaker = 0; (start <= end) && (loopbreaker < maxloop); loopbreaker++) {
556 int mid = start + ((end - start) / 2);
558 float midfra =
array[mid].time;
567 if (frame > midfra) {
570 else if (frame < midfra) {
576 if (loopbreaker == (maxloop - 1)) {
581 "\tround = %d: start = %d, end = %d, arraylen = %d",
591#undef BINARYSEARCH_FRAMEEQ_THRESH
621 const FCurve *fcu,
const FModifier *fcm,
float ,
float evaltime,
void *storage_)
625 float firstkey[2], lastkey[2], cycyofs = 0.0f;
626 short side = 0, mode = 0;
637 if (fcu ==
nullptr || (fcu->
bezt ==
nullptr && fcu->
fpt ==
nullptr)) {
646 firstkey[0] = firstbezt->
vec[1][0];
647 firstkey[1] = firstbezt->
vec[1][1];
649 lastkey[0] = lastbezt->
vec[1][0];
650 lastkey[1] = lastbezt->
vec[1][1];
657 firstkey[0] = prevfpt->
vec[0];
658 firstkey[1] = prevfpt->
vec[1];
660 lastkey[0] = lastfpt->
vec[0];
661 lastkey[1] = lastfpt->
vec[1];
668 if (evaltime < firstkey[0]) {
669 if (
data->before_mode) {
671 mode =
data->before_mode;
672 cycles =
data->before_cycles;
676 else if (evaltime > lastkey[0]) {
677 if (
data->after_mode) {
679 mode =
data->after_mode;
680 cycles =
data->after_cycles;
684 if (
ELEM(0, side, mode)) {
691 const float cycdx = lastkey[0] - firstkey[0];
692 const float cycdy = lastkey[1] - firstkey[1];
702 const double cycle = side * (double(evaltime) - double(ofs)) /
double(cycdx);
704 const float cyct =
fmod(evaltime - ofs, cycdx);
712 else if (cycle > cycles) {
722 cycyofs =
floor((evaltime - ofs) / cycdx);
725 cycyofs =
ceil((evaltime - ofs) / cycdx);
732 evaltime = (side == 1 ? lastkey[0] : firstkey[0]);
735 evaltime = (side == 1 ? firstkey[0] : lastkey[0]);
746 evaltime = firstkey[0] - cyct;
749 evaltime = lastkey[0] - cyct;
754 evaltime = firstkey[0] + cyct;
756 if (evaltime < firstkey[0]) {
804 data->strength = 1.0f;
809 data->lacunarity = 2.0f;
810 data->roughness = 0.5f;
811 data->legacy_noise = 0;
822 if (
data->legacy_noise) {
832 if (
data->size == 0.0f) {
840 const float offset = 0.61803398874;
852 switch (
data->modification) {
854 *cvalue = *cvalue +
noise *
data->strength;
857 *cvalue = *cvalue -
noise *
data->strength;
860 *cvalue = *cvalue *
noise *
data->strength;
864 *cvalue = *cvalue + (
noise - 0.5f) *
data->strength;
897 return data->rect.xmin;
900 return data->rect.xmax;
917 *cvalue =
data->rect.ymin;
920 *cvalue =
data->rect.ymax;
948 data->step_size = 2.0f;
962 if (evaltime < data->start_frame) {
967 if (evaltime >
data->end_frame) {
976 snapblock = int((evaltime -
data->offset) /
data->step_size);
981 return (
float(snapblock) *
data->step_size) +
data->offset;
1006 data->sigma = 0.33f;
1007 data->filter_width = 6;
1014 const float default_value)
1018 const float sigma =
data->sigma;
1019 const int filter_width =
data->filter_width;
1025 float total_weighted_value = 0.0f;
1026 float total_weight = 0.0f;
1029 const int start_frame =
floorf(evaltime - filter_width);
1030 const int end_frame =
ceilf(evaltime + filter_width);
1032 const float two_sigma_sq = 2.0f * sigma * sigma;
1035 for (
float sample_time = start_frame; sample_time <= end_frame; ++sample_time) {
1036 const float sample_distance = sample_time - evaltime;
1040 const float sample_dis_norm = sample_distance / filter_width;
1041 const float weight =
expf(-(sample_dis_norm * sample_dis_norm) / two_sigma_sq);
1045 total_weighted_value += sample_value * weight;
1046 total_weight += weight;
1049 if (total_weight <= 0.0f) {
1051 return default_value;
1054 return total_weighted_value / total_weight;
1058 const FCurve *fcu,
const FModifier *fcm,
float *cvalue,
float evaltime,
void * )
1064 if (is_integer_frame) {
1078 const float prev_frame =
floorf(evaltime);
1079 const float next_frame =
ceilf(evaltime);
1087 *cvalue =
interpf(next_value, prev_value, evaltime - prev_frame);
1141 "fmodifiersTypeInfo should be indexed by the modifier type number");
1160 CLOG_ERROR(&
LOG,
"No valid F-Curve Modifier type-info data available. Type = %i", type);
1187 if (
ELEM(
nullptr, modifiers, fmi)) {
1192 fcm = MEM_new<FModifier>(
"F-Curve Modifier");
1195 fcm->
curve = owner_fcu;
1205 if (modifiers->is_single()) {
1232 if (src ==
nullptr) {
1237 dst = MEM_dupalloc(src);
1239 dst->
curve =
nullptr;
1257 if (
ELEM(
nullptr, dst, src)) {
1261 dst->clear_no_delete();
1264 for (fcm = dst->first(), srcfcm = src->first(); fcm && srcfcm;
1265 srcfcm = srcfcm->
next, fcm = fcm->
next)
1271 fcm->
curve =
nullptr;
1285 if (fcm ==
nullptr) {
1326 if (modifiers ==
nullptr) {
1331 for (fcm = modifiers->first(); fcm; fcm = fmn) {
1340 if (
ELEM(
nullptr, modifiers, modifiers->first())) {
1358 if (
ELEM(
nullptr, modifiers, modifiers->first())) {
1376 if ((mtype == 0) && (acttype == 0)) {
1377 return (modifiers && modifiers->first());
1381 if (
ELEM(
nullptr, modifiers, modifiers->first())) {
1388 short mOk = 1, aOk = 1;
1392 mOk = (fcm.type == mtype);
1395 aOk = (fmi->
acttype == acttype);
1413 if (
ELEM(
nullptr, modifiers, modifiers->first())) {
1422 if (fmi ==
nullptr) {
1440 if (fcm ==
nullptr) {
1456 if ((evaltime < fcm->sfra) || (evaltime > fcm->
efra)) {
1460 if ((fcm->
blendin != 0.0f) && (evaltime >= fcm->
sfra) &&
1461 (evaltime <= fcm->sfra + fcm->
blendin))
1464 float a = fcm->
sfra;
1466 return influence * (evaltime - a) / (
b - a);
1468 if ((fcm->
blendout != 0.0f) && (evaltime <= fcm->efra) &&
1472 float a = fcm->
efra;
1474 return influence * (evaltime - a) / (
b - a);
1483 const ListBaseT<FModifier> *modifiers,
1489 if (
ELEM(
nullptr, modifiers, modifiers->last())) {
1508 for (
FModifier *fcm = modifiers->last(); fcm; fcm = fcm->
prev, fcm_index--) {
1511 if (fmi ==
nullptr) {
1519 ((fcm->sfra <= evaltime) && (fcm->efra >= evaltime)))
1525 fcm_index *
storage->size_per_modifier);
1530 evaltime =
interpf(nval, evaltime, influence);
1541 const ListBaseT<FModifier> *modifiers,
1549 if (
ELEM(
nullptr, modifiers, modifiers->first())) {
1559 for (fcm = modifiers->first(); fcm; fcm = fcm->
next, fcm_index++) {
1562 if (fmi ==
nullptr) {
1569 ((fcm->
sfra <= evaltime) && (fcm->
efra >= evaltime)))
1574 fcm_index *
storage->size_per_modifier);
1576 float nval = *cvalue;
1580 *cvalue =
interpf(nval, *cvalue, influence);
1596 CLOG_ERROR(&
LOG,
"No F-Curve with F-Curve Modifiers to Bake");
#define BLT_I18NCONTEXT_ID_ACTION
#define CTX_N_(context, msgid)
#define CLOG_ERROR(clg_ref,...)
#define CLOG_WARN(clg_ref,...)
#define CLOG_STR_ERROR(clg_ref, str)
Read Blender memory allocation and freeing.
#define BLI_assert_unreachable()
#define POINTER_OFFSET(v, ofs)
#define BLI_assert_msg(a, msg)
#define MEM_realloc_zeroed(vmemh, len)
#define BINARYSEARCH_FRAMEEQ_THRESH
IMETHOD Vector diff(const Vector &a, const Vector &b, double dt)
#define storage(slot, qualifiers)
float3x3 scale(float3x3 mat, float2 scale)
ccl_device_inline dual3 fabs(const ccl_private dual3 &a)
ccl_device_inline float2 fmod(const float2 a, const float b)
template float perlin_fbm< float2 >(float2 p, const float detail, const float roughness, const float lacunarity, const bool normalize)
static void fcm_fn_generator_evaluate(const FCurve *, const FModifier *fcm, float *cvalue, float evaltime, void *)
static void fmods_init_typeinfo()
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ UI_PANEL_DATA_EXPAND_ROOT
@ FMI_TYPE_GENERATE_CURVE
@ FMI_TYPE_REPLACE_VALUES
float BLI_noise_turbulence(float noisesize, float x, float y, float z, int nr)
static void fcm_generator_verify(FModifier *fcm)
static FModifierTypeInfo FMI_SMOOTH
void void void void void void BLI_duplicatelist(ListBase *dst, const ListBase *src) ATTR_NONNULL(1
@ FCM_GENERATOR_POLYNOMIAL
@ FCM_GENERATOR_POLYNOMIAL_FACTORISED
uint evaluate_fmodifiers_storage_size_per_modifier(const ListBaseT< FModifier > *modifiers)
void BKE_fmodifier_ensure_flag(ListBaseT< FModifier > *modifiers)
void BKE_fmodifier_name_set(FModifier *fcm, const char *name)
static FModifierTypeInfo * fmodifiersTypeInfo[FMODIFIER_NUM_TYPES]
void copy_fmodifiers(ListBaseT< FModifier > *dst, const ListBaseT< FModifier > *src)
static FModifierTypeInfo FMI_ENVELOPE
static void fcm_smooth_evaluate(const FCurve *fcu, const FModifier *fcm, float *cvalue, float evaltime, void *)
const FModifierTypeInfo * fmodifier_get_typeinfo(const FModifier *fcm)
static void fcm_stepped_new_data(void *mdata)
static void fcm_envelope_copy(FModifier *fcm, const FModifier *src)
static float fcm_stepped_time(const FCurve *, const FModifier *fcm, float, float evaltime, void *)
FModifier * add_fmodifier(ListBaseT< FModifier > *modifiers, int type, FCurve *owner_fcu)
float evaluate_fcurve_unmodified(const FCurve *fcu, float evaltime)
ATTR_WARN_UNUSED_RESULT const BMVert * v
bool list_has_suitable_fmodifier(const ListBaseT< FModifier > *modifiers, int mtype, short acttype)
void MEM_delete_void(void *vmemh)
bool remove_fmodifier(ListBaseT< FModifier > *modifiers, FModifier *fcm)
@ FCM_NOISE_MODIF_REPLACE
@ FCM_NOISE_MODIF_SUBTRACT
@ FCM_NOISE_MODIF_MULTIPLY
@ FMODIFIER_TYPE_ENVELOPE
@ FMODIFIER_TYPE_FN_GENERATOR
@ FMODIFIER_TYPE_GENERATOR
@ FCM_EXTRAPOLATE_CYCLIC_OFFSET
static void fcm_generator_new_data(void *mdata)
void * MEM_dupalloc_void(const void *vmemh) ATTR_WARN_UNUSED_RESULT
VecBase< float, 2 > float2
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void evaluate_value_fmodifiers(FModifiersStackStorage *storage, const ListBaseT< FModifier > *modifiers, const FCurve *fcu, float *cvalue, float evaltime)
static void fcm_cycles_evaluate(const FCurve *, const FModifier *, float *cvalue, float, void *storage_)
void BKE_fcurve_handles_recalc(FCurve &fcu)
BMesh const char void * data
static void fcm_generator_free(FModifier *fcm)
static void fcm_generator_copy(FModifier *fcm, const FModifier *src)
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
static FModifierTypeInfo FMI_STEPPED
FModifier * find_active_fmodifier(ListBaseT< FModifier > *modifiers)
static float eval_fmodifier_influence(FModifier *fcm, float evaltime)
static void fcm_noise_new_data(void *mdata)
static double sinc(double x)
void free_fmodifiers(ListBaseT< FModifier > *modifiers)
static void fcm_noise_evaluate(const FCurve *, const FModifier *fcm, float *cvalue, float evaltime, void *)
static FModifierTypeInfo FMI_CYCLES
static float fcm_limits_time(const FCurve *, const FModifier *fcm, float, float evaltime, void *)
static void fcm_cycles_new_data(void *mdata)
static void fcm_envelope_free(FModifier *fcm)
static void fcm_limits_evaluate(const FCurve *, const FModifier *fcm, float *cvalue, float, void *)
static void fcm_envelope_new_data(void *mdata)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void fcurve_bake_modifiers(FCurve *fcu, int start, int end)
static void fcm_envelope_evaluate(const FCurve *, const FModifier *fcm, float *cvalue, float evaltime, void *)
static void fcm_generator_evaluate(const FCurve *, const FModifier *fcm, float *cvalue, float evaltime, void *)
FModifier * copy_fmodifier(const FModifier *src)
int BKE_fcm_envelope_find_index(FCM_EnvelopeData *array, float frame, int arraylen, bool *r_exists)
static void fcm_envelope_verify(FModifier *fcm)
static float fcm_smooth_frame(const FCurve *fcu, const FModifier *fcm, const int evaltime, const float default_value)
MINLINE float interpf(float target, float origin, float t)
static void fcm_fn_generator_new_data(void *mdata)
void fcurve_store_samples(FCurve *fcu, void *data, int start, int end, FcuSampleFunc sample_cb)
float fcurve_samplingcb_evalcurve(FCurve *fcu, void *data, float evaltime)
static void fcm_smooth_new_data(void *mdata)
static FModifierTypeInfo FMI_NOISE
static FModifierTypeInfo FMI_FN_GENERATOR
static FModifierTypeInfo FMI_LIMITS
void set_active_fmodifier(ListBaseT< FModifier > *modifiers, FModifier *fcm)
@ FMI_REQUIRES_ORIGINAL_DATA
@ FMI_REQUIRES_RUNTIME_CHECK
const FModifierTypeInfo * get_fmodifier_typeinfo(int type)
static FModifierTypeInfo FMI_GENERATOR
float evaluate_time_fmodifiers(FModifiersStackStorage *storage, const ListBaseT< FModifier > *modifiers, const FCurve *fcu, float cvalue, float evaltime)
static float fcm_cycles_time(const FCurve *fcu, const FModifier *fcm, float, float evaltime, void *storage_)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
@ FMODIFIER_FLAG_DISABLED
@ FMODIFIER_FLAG_RANGERESTRICT
@ FMODIFIER_FLAG_USEINFLUENCE
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
ListBaseT< FModifier > modifiers
void(*) free_data(FModifier *fcm)
float(*) evaluate_modifier_time(const FCurve *fcu, const FModifier *fcm, float cvalue, float evaltime, void *storage)
void(*) evaluate_modifier(const FCurve *fcu, const FModifier *fcm, float *cvalue, float evaltime, void *storage)
void(*) new_data(void *mdata)
void(*) copy_data(FModifier *fcm, const FModifier *src)