Пример #1
0
/* helper func - just draw the F-Curve by sampling the visible region (for drawing curves with modifiers) */
static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d, View2DGrid *grid)
{
	ChannelDriver *driver;
	float samplefreq, ctime;
	float stime, etime;
	float unitFac;
	float dx, dy;
	short mapping_flag = ANIM_get_normalization_flags(ac);

	/* when opening a blend file on a different sized screen or while dragging the toolbar this can happen
	 * best just bail out in this case */
	UI_view2d_grid_size(grid, &dx, &dy);
	if (dx <= 0.0f)
		return;


	/* disable any drivers temporarily */
	driver = fcu->driver;
	fcu->driver = NULL;
	
	/* compute unit correction factor */
	unitFac = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag);
	
	/* Note about sampling frequency:
	 *  Ideally, this is chosen such that we have 1-2 pixels = 1 segment
	 *	which means that our curves can be as smooth as possible. However,
	 *  this does mean that curves may not be fully accurate (i.e. if they have
	 *  sudden spikes which happen at the sampling point, we may have problems).
	 *  Also, this may introduce lower performance on less densely detailed curves,'
	 *	though it is impossible to predict this from the modifiers!
	 *
	 *	If the automatically determined sampling frequency is likely to cause an infinite
	 *	loop (i.e. too close to 0), then clamp it to a determined "safe" value. The value
	 *  chosen here is just the coarsest value which still looks reasonable...
	 */
	/* grid->dx represents the number of 'frames' between gridlines, but we divide by U.v2d_min_gridsize to get pixels-steps */
	/* TODO: perhaps we should have 1.0 frames as upper limit so that curves don't get too distorted? */
	samplefreq = dx / (U.v2d_min_gridsize * U.pixelsize);
	if (samplefreq < 0.00001f) samplefreq = 0.00001f;
	
	
	/* the start/end times are simply the horizontal extents of the 'cur' rect */
	stime = v2d->cur.xmin;
	etime = v2d->cur.xmax + samplefreq; /* + samplefreq here so that last item gets included... */
	
	
	/* at each sampling interval, add a new vertex 
	 *	- apply the unit correction factor to the calculated values so that 
	 *	  the displayed values appear correctly in the viewport
	 */
	glBegin(GL_LINE_STRIP);
	
	for (ctime = stime; ctime <= etime; ctime += samplefreq)
		glVertex2f(ctime, evaluate_fcurve(fcu, ctime) * unitFac);
	
	glEnd();
	
	/* restore driver */
	fcu->driver = driver;
}
Пример #2
0
/* This is called twice from space_graph.c -> graph_main_area_draw()
 * Unselected then selected F-Curves are drawn so that they do not occlude each other.
 */
void graph_draw_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid *grid, short sel)
{
	ListBase anim_data = {NULL, NULL};
	bAnimListElem *ale;
	int filter;
	
	/* build list of curves to draw */
	filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE);
	filter |= ((sel) ? (ANIMFILTER_SEL) : (ANIMFILTER_UNSEL));
	ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
		
	/* for each curve:
	 *	draw curve, then handle-lines, and finally vertices in this order so that 
	 *  the data will be layered correctly
	 */
	for (ale = anim_data.first; ale; ale = ale->next) {
		FCurve *fcu = (FCurve *)ale->key_data;
		FModifier *fcm = find_active_fmodifier(&fcu->modifiers);
		AnimData *adt = ANIM_nla_mapping_get(ac, ale);
		
		/* map keyframes for drawing if scaled F-Curve */
		if (adt)
			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 0); 
		
		/* draw curve:
		 *	- curve line may be result of one or more destructive modifiers or just the raw data,
		 *	  so we need to check which method should be used
		 *	- controls from active modifier take precedence over keyframes
		 *	  (XXX! editing tools need to take this into account!)
		 */
		 
		/* 1) draw curve line */
		{
			/* set color/drawing style for curve itself */
			if (BKE_fcurve_is_protected(fcu)) {
				/* protected curves (non editable) are drawn with dotted lines */
				setlinestyle(2);
			}
			if (((fcu->grp) && (fcu->grp->flag & AGRP_MUTED)) || (fcu->flag & FCURVE_MUTED)) {
				/* muted curves are drawn in a grayish hue */
				/* XXX should we have some variations? */
				UI_ThemeColorShade(TH_HEADER, 50);
			}
			else {
				/* set whatever color the curve has set 
				 *	- unselected curves draw less opaque to help distinguish the selected ones
				 */
				glColor4f(fcu->color[0], fcu->color[1], fcu->color[2], fcurve_display_alpha(fcu));
			}
			
			/* draw active F-Curve thicker than the rest to make it stand out */
			if (fcu->flag & FCURVE_ACTIVE) {
				glLineWidth(2.0);
			}
			
			/* anti-aliased lines for less jagged appearance */
			if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) glEnable(GL_LINE_SMOOTH);
			glEnable(GL_BLEND);
			
			/* draw F-Curve */
			if ((fcu->modifiers.first) || (fcu->flag & FCURVE_INT_VALUES)) {
				/* draw a curve affected by modifiers or only allowed to have integer values 
				 * by sampling it at various small-intervals over the visible region 
				 */
				draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, grid);
			}
			else if (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert)) {
				/* just draw curve based on defined data (i.e. no modifiers) */
				if (fcu->bezt)
					//draw_fcurve_curve_bezts(ac, ale->id, fcu, &ar->v2d);
					draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, grid);  // XXX: better to do an optimised integration here instead, but for now, this works
				else if (fcu->fpt)
					draw_fcurve_curve_samples(ac, ale->id, fcu, &ar->v2d);
			}
			
			/* restore settings */
			setlinestyle(0);
			glLineWidth(1.0);
			
			if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) glDisable(GL_LINE_SMOOTH);
			glDisable(GL_BLEND);
		}
		
		/* 2) draw handles and vertices as appropriate based on active 
		 *	- if the option to only show controls if the F-Curve is selected is enabled, we must obey this
		 */
		if (!(sipo->flag & SIPO_SELCUVERTSONLY) || (fcu->flag & FCURVE_SELECTED)) {
			if (fcurve_are_keyframes_usable(fcu) == 0) {
				/* only draw controls if this is the active modifier */
				if ((fcu->flag & FCURVE_ACTIVE) && (fcm)) {
					switch (fcm->type) {
						case FMODIFIER_TYPE_ENVELOPE: /* envelope */
							draw_fcurve_modifier_controls_envelope(fcm, &ar->v2d);
							break;
					}
				}
			}
			else if (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert)) {
				short mapping_flag = ANIM_get_normalization_flags(ac);
				float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, mapping_flag);

				glPushMatrix();
				glScalef(1.0f, unit_scale, 1.0f);

				if (fcu->bezt) {
					int do_handles = draw_fcurve_handles_check(sipo, fcu);
					
					if (do_handles) {
						/* only draw handles/vertices on keyframes */
						glEnable(GL_BLEND);
						draw_fcurve_handles(sipo, fcu);
						glDisable(GL_BLEND);
					}
					
					draw_fcurve_vertices(sipo, ar, fcu, do_handles, (sipo->flag & SIPO_SELVHANDLESONLY), unit_scale);
				}
				else {
					/* samples: only draw two indicators at either end as indicators */
					draw_fcurve_samples(sipo, ar, fcu);
				}

				glPopMatrix();
			}
		}
		
		/* 3) draw driver debugging stuff */
		if ((ac->datatype == ANIMCONT_DRIVERS) && (fcu->flag & FCURVE_ACTIVE)) {
			graph_draw_driver_debug(ac, ale->id, fcu);
		}
		
		/* undo mapping of keyframes for drawing if scaled F-Curve */
		if (adt)
			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 0); 
	}
	
	/* free list of curves */
	BLI_freelistN(&anim_data);
}
Пример #3
0
/* Draw indicators which show the value calculated from the driver, 
 * and how this is mapped to the value that comes out of it. This
 * is handy for helping users better understand how to interpret
 * the graphs, and also facilitates debugging. 
 */
static void graph_draw_driver_debug(bAnimContext *ac, ID *id, FCurve *fcu)
{
	ChannelDriver *driver = fcu->driver;
	View2D *v2d = &ac->ar->v2d;
	short mapping_flag = ANIM_get_normalization_flags(ac);
	float unitfac = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag);
	
	/* for now, only show when debugging driver... */
	//if ((driver->flag & DRIVER_FLAG_SHOWDEBUG) == 0)
	//	return;
	
	/* No curve to modify/visualise the result? 
	 * => We still want to show the 1-1 default... 
	 */
	if ((fcu->totvert == 0) && BLI_listbase_is_empty(&fcu->modifiers)) {
		float t;
		
		/* draw with thin dotted lines in style of what curve would have been */
		glColor3fv(fcu->color);
		
		setlinestyle(20);
		glLineWidth(2.0f);
		
		/* draw 1-1 line, stretching just past the screen limits 
		 * NOTE: we need to scale the y-values to be valid for the units
		 */
		glBegin(GL_LINES);
			t = v2d->cur.xmin;
			glVertex2f(t, t * unitfac);
			
			t = v2d->cur.xmax;
			glVertex2f(t, t * unitfac); 
		glEnd();
		
		/* cleanup line drawing */
		setlinestyle(0);
		glLineWidth(1.0f);
	}
	
	/* draw driver only if actually functional */
	if ((driver->flag & DRIVER_FLAG_INVALID) == 0) {
		/* grab "coordinates" for driver outputs */
		float x = driver->curval;
		float y = fcu->curval * unitfac;
		
		/* only draw indicators if the point is in range*/
		if (x >= v2d->cur.xmin) {
			float co[2];
			
			/* draw dotted lines leading towards this point from both axes ....... */
			glColor3f(0.9f, 0.9f, 0.9f);
			setlinestyle(5);
			
			glBegin(GL_LINES);
				/* x-axis lookup */
				co[0] = x;
				
				if (y >= v2d->cur.ymin) {
					co[1] = v2d->cur.ymin - 1.0f;
					glVertex2fv(co);
					
					co[1] = y;
					glVertex2fv(co);
				}
				
				/* y-axis lookup */
				co[1] = y;
				
				co[0] = v2d->cur.xmin - 1.0f;
				glVertex2fv(co);
				
				co[0] = x;
				glVertex2fv(co);
			glEnd();
			
			setlinestyle(0);
			
			/* x marks the spot .................................................... */
			/* -> outer frame */
			glColor3f(0.9f, 0.9f, 0.9f);
			glPointSize(7.0);
			
			glBegin(GL_POINTS);
				glVertex2f(x, y);
			glEnd();
			
			/* inner frame */
			glColor3f(0.9f, 0.0f, 0.0f);
			glPointSize(3.0);
			
			glBegin(GL_POINTS);
				glVertex2f(x, y);
			glEnd();
			
			glPointSize(1.0f);
		}
	}
}
Пример #4
0
/* helper func - draw one repeat of an F-Curve */
static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d)
{
	BezTriple *prevbezt = fcu->bezt;
	BezTriple *bezt = prevbezt + 1;
	float v1[2], v2[2], v3[2], v4[2];
	float *fp, data[120];
	float fac = 0.0f;
	int b = fcu->totvert - 1;
	int resol;
	float unit_scale;
	short mapping_flag = ANIM_get_normalization_flags(ac);

	/* apply unit mapping */
	glPushMatrix();
	unit_scale = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag);
	glScalef(1.0f, unit_scale, 1.0f);

	glBegin(GL_LINE_STRIP);
	
	/* extrapolate to left? */
	if (prevbezt->vec[1][0] > v2d->cur.xmin) {
		/* left-side of view comes before first keyframe, so need to extend as not cyclic */
		v1[0] = v2d->cur.xmin;
		
		/* y-value depends on the interpolation */
		if ((fcu->extend == FCURVE_EXTRAPOLATE_CONSTANT) || (prevbezt->ipo == BEZT_IPO_CONST) || (fcu->totvert == 1)) {
			/* just extend across the first keyframe's value */
			v1[1] = prevbezt->vec[1][1];
		}
		else if (prevbezt->ipo == BEZT_IPO_LIN) {
			/* extrapolate linear dosnt use the handle, use the next points center instead */
			fac = (prevbezt->vec[1][0] - bezt->vec[1][0]) / (prevbezt->vec[1][0] - v1[0]);
			if (fac) fac = 1.0f / fac;
			v1[1] = prevbezt->vec[1][1] - fac * (prevbezt->vec[1][1] - bezt->vec[1][1]);
		}
		else {
			/* based on angle of handle 1 (relative to keyframe) */
			fac = (prevbezt->vec[0][0] - prevbezt->vec[1][0]) / (prevbezt->vec[1][0] - v1[0]);
			if (fac) fac = 1.0f / fac;
			v1[1] = prevbezt->vec[1][1] - fac * (prevbezt->vec[0][1] - prevbezt->vec[1][1]);
		}
		
		glVertex2fv(v1);
	}
	
	/* if only one keyframe, add it now */
	if (fcu->totvert == 1) {
		v1[0] = prevbezt->vec[1][0];
		v1[1] = prevbezt->vec[1][1];
		glVertex2fv(v1);
	}
	
	/* draw curve between first and last keyframe (if there are enough to do so) */
	/* TODO: optimize this to not have to calc stuff out of view too? */
	while (b--) {
		if (prevbezt->ipo == BEZT_IPO_CONST) {
			/* Constant-Interpolation: draw segment between previous keyframe and next, but holding same value */
			v1[0] = prevbezt->vec[1][0];
			v1[1] = prevbezt->vec[1][1];
			glVertex2fv(v1);
			
			v1[0] = bezt->vec[1][0];
			v1[1] = prevbezt->vec[1][1];
			glVertex2fv(v1);
		}
		else if (prevbezt->ipo == BEZT_IPO_LIN) {
			/* Linear interpolation: just add one point (which should add a new line segment) */
			v1[0] = prevbezt->vec[1][0];
			v1[1] = prevbezt->vec[1][1];
			glVertex2fv(v1);
		}
		else {
			/* Bezier-Interpolation: draw curve as series of segments between keyframes 
			 *	- resol determines number of points to sample in between keyframes
			 */
			
			/* resol depends on distance between points (not just horizontal) OR is a fixed high res */
			/* TODO: view scale should factor into this someday too... */
			if (fcu->driver) 
				resol = 32;
			else 
				resol = (int)(5.0f * len_v2v2(bezt->vec[1], prevbezt->vec[1]));
			
			if (resol < 2) {
				/* only draw one */
				v1[0] = prevbezt->vec[1][0];
				v1[1] = prevbezt->vec[1][1];
				glVertex2fv(v1);
			}
			else {
				/* clamp resolution to max of 32 */
				/* NOTE: higher values will crash */
				if (resol > 32) resol = 32;
				
				v1[0] = prevbezt->vec[1][0];
				v1[1] = prevbezt->vec[1][1];
				v2[0] = prevbezt->vec[2][0];
				v2[1] = prevbezt->vec[2][1];
				
				v3[0] = bezt->vec[0][0];
				v3[1] = bezt->vec[0][1];
				v4[0] = bezt->vec[1][0];
				v4[1] = bezt->vec[1][1];
				
				correct_bezpart(v1, v2, v3, v4);
				
				BKE_curve_forward_diff_bezier(v1[0], v2[0], v3[0], v4[0], data, resol, sizeof(float) * 3);
				BKE_curve_forward_diff_bezier(v1[1], v2[1], v3[1], v4[1], data + 1, resol, sizeof(float) * 3);
				
				for (fp = data; resol; resol--, fp += 3)
					glVertex2fv(fp);
			}
		}
		
		/* get next pointers */
		prevbezt = bezt;
		bezt++;
		
		/* last point? */
		if (b == 0) {
			v1[0] = prevbezt->vec[1][0];
			v1[1] = prevbezt->vec[1][1];
			glVertex2fv(v1);
		}
	}
	
	/* extrapolate to right? (see code for left-extrapolation above too) */
	if (prevbezt->vec[1][0] < v2d->cur.xmax) {
		v1[0] = v2d->cur.xmax;
		
		/* y-value depends on the interpolation */
		if ((fcu->extend == FCURVE_EXTRAPOLATE_CONSTANT) || (fcu->flag & FCURVE_INT_VALUES) || (prevbezt->ipo == BEZT_IPO_CONST) || (fcu->totvert == 1)) {
			/* based on last keyframe's value */
			v1[1] = prevbezt->vec[1][1];
		}
		else if (prevbezt->ipo == BEZT_IPO_LIN) {
			/* extrapolate linear dosnt use the handle, use the previous points center instead */
			bezt = prevbezt - 1;
			fac = (prevbezt->vec[1][0] - bezt->vec[1][0]) / (prevbezt->vec[1][0] - v1[0]);
			if (fac) fac = 1.0f / fac;
			v1[1] = prevbezt->vec[1][1] - fac * (prevbezt->vec[1][1] - bezt->vec[1][1]);
		}
		else {
			/* based on angle of handle 1 (relative to keyframe) */
			fac = (prevbezt->vec[2][0] - prevbezt->vec[1][0]) / (prevbezt->vec[1][0] - v1[0]);
			if (fac) fac = 1.0f / fac;
			v1[1] = prevbezt->vec[1][1] - fac * (prevbezt->vec[2][1] - prevbezt->vec[1][1]);
		}
		
		glVertex2fv(v1);
	}
	
	glEnd();
	glPopMatrix();
}
Пример #5
0
/* helper func - draw a samples-based F-Curve */
static void draw_fcurve_curve_samples(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d)
{
	FPoint *prevfpt = fcu->fpt;
	FPoint *fpt = prevfpt + 1;
	float fac, v[2];
	int b = fcu->totvert - 1;
	float unit_scale;
	short mapping_flag = ANIM_get_normalization_flags(ac);

	/* apply unit mapping */
	glPushMatrix();
	unit_scale = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag);
	glScalef(1.0f, unit_scale, 1.0f);

	glBegin(GL_LINE_STRIP);
	
	/* extrapolate to left? - left-side of view comes before first keyframe? */
	if (prevfpt->vec[0] > v2d->cur.xmin) {
		v[0] = v2d->cur.xmin;
		
		/* y-value depends on the interpolation */
		if ((fcu->extend == FCURVE_EXTRAPOLATE_CONSTANT) || (fcu->flag & FCURVE_INT_VALUES) || (fcu->totvert == 1)) {
			/* just extend across the first keyframe's value */
			v[1] = prevfpt->vec[1];
		}
		else {
			/* extrapolate linear doesn't use the handle, use the next points center instead */
			fac = (prevfpt->vec[0] - fpt->vec[0]) / (prevfpt->vec[0] - v[0]);
			if (fac) fac = 1.0f / fac;
			v[1] = prevfpt->vec[1] - fac * (prevfpt->vec[1] - fpt->vec[1]);
		}
		
		glVertex2fv(v);
	}
	
	/* if only one sample, add it now */
	if (fcu->totvert == 1)
		glVertex2fv(prevfpt->vec);
	
	/* loop over samples, drawing segments */
	/* draw curve between first and last keyframe (if there are enough to do so) */
	while (b--) {
		/* Linear interpolation: just add one point (which should add a new line segment) */
		glVertex2fv(prevfpt->vec);
		
		/* get next pointers */
		prevfpt = fpt;
		fpt++;
		
		/* last point? */
		if (b == 0)
			glVertex2fv(prevfpt->vec);
	}
	
	/* extrapolate to right? (see code for left-extrapolation above too) */
	if (prevfpt->vec[0] < v2d->cur.xmax) {
		v[0] = v2d->cur.xmax;
		
		/* y-value depends on the interpolation */
		if ((fcu->extend == FCURVE_EXTRAPOLATE_CONSTANT) || (fcu->flag & FCURVE_INT_VALUES) || (fcu->totvert == 1)) {
			/* based on last keyframe's value */
			v[1] = prevfpt->vec[1];
		}
		else {
			/* extrapolate linear doesn't use the handle, use the previous points center instead */
			fpt = prevfpt - 1;
			fac = (prevfpt->vec[0] - fpt->vec[0]) / (prevfpt->vec[0] - v[0]);
			if (fac) fac = 1.0f / fac;
			v[1] = prevfpt->vec[1] - fac * (prevfpt->vec[1] - fpt->vec[1]);
		}
		
		glVertex2fv(v);
	}
	
	glEnd();
	glPopMatrix();
}
Пример #6
0
/* Borderselect only selects keyframes now, as overshooting handles often get caught too,
 * which means that they may be inadvertently moved as well. However, incl_handles overrides
 * this, and allow handles to be considered independently too.
 * Also, for convenience, handles should get same status as keyframe (if it was within bounds).
 */
static void borderselect_graphkeys(
        bAnimContext *ac, const rctf *rectf_view, short mode, short selectmode, bool incl_handles,
        struct KeyframeEdit_LassoData *data_lasso)
{
	ListBase anim_data = {NULL, NULL};
	bAnimListElem *ale;
	int filter, mapping_flag;
	
	SpaceIpo *sipo = (SpaceIpo *)ac->sl;
	KeyframeEditData ked;
	KeyframeEditFunc ok_cb, select_cb;
	View2D *v2d = &ac->ar->v2d;
	rctf rectf, scaled_rectf;
	
	/* convert mouse coordinates to frame ranges and channel coordinates corrected for view pan/zoom */
	UI_view2d_region_to_view_rctf(v2d, rectf_view, &rectf);
	
	/* filter data */
	filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS);
	ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
	
	/* get beztriple editing/validation funcs  */
	select_cb = ANIM_editkeyframes_select(selectmode);
	ok_cb = ANIM_editkeyframes_ok(mode);
	
	/* init editing data */
	memset(&ked, 0, sizeof(KeyframeEditData));
	if (data_lasso) {
		data_lasso->rectf_scaled = &scaled_rectf;
		ked.data = data_lasso;
	}
	else {
		ked.data = &scaled_rectf;
	}
	
	/* treat handles separately? */
	if (incl_handles) {
		ked.iterflags |= KEYFRAME_ITER_INCL_HANDLES;
		mapping_flag = 0;
	}
	else
		mapping_flag = ANIM_UNITCONV_ONLYKEYS;

	mapping_flag |= ANIM_get_normalization_flags(ac);

	/* loop over data, doing border select */
	for (ale = anim_data.first; ale; ale = ale->next) {
		AnimData *adt = ANIM_nla_mapping_get(ac, ale);
		FCurve *fcu = (FCurve *)ale->key_data;
		float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, mapping_flag);

		/* apply NLA mapping to all the keyframes, since it's easier than trying to
		 * guess when a callback might use something different
		 */
		if (adt)
			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, incl_handles == 0);

		scaled_rectf.xmin = rectf.xmin;
		scaled_rectf.xmax = rectf.xmax;
		scaled_rectf.ymin = rectf.ymin / unit_scale;
		scaled_rectf.ymax = rectf.ymax / unit_scale;

		/* set horizontal range (if applicable) 
		 * NOTE: these values are only used for x-range and y-range but not region 
		 *      (which uses ked.data, i.e. rectf)
		 */
		if (mode != BEZT_OK_VALUERANGE) {
			ked.f1 = rectf.xmin;
			ked.f2 = rectf.xmax;
		}
		else {
			ked.f1 = rectf.ymin;
			ked.f2 = rectf.ymax;
		}
		
		/* firstly, check if any keyframes will be hit by this */
		if (ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, ok_cb, NULL)) {
			/* select keyframes that are in the appropriate places */
			ANIM_fcurve_keyframes_loop(&ked, fcu, ok_cb, select_cb, NULL);
			
			/* only change selection of channel when the visibility of keyframes doesn't depend on this */
			if ((sipo->flag & SIPO_SELCUVERTSONLY) == 0) {
				/* select the curve too now that curve will be touched */
				if (selectmode == SELECT_ADD)
					fcu->flag |= FCURVE_SELECTED;
			}
		}
		
		/* un-apply NLA mapping from all the keyframes */
		if (adt)
			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, incl_handles == 0);
	}
	
	/* cleanup */
	BLI_freelistN(&anim_data);
}
Пример #7
0
/* helper for find_nearest_fcurve_vert() - build the list of nearest matches */
static void get_nearest_fcurve_verts_list(bAnimContext *ac, const int mval[2], ListBase *matches)
{
	ListBase anim_data = {NULL, NULL};
	bAnimListElem *ale;
	int filter;
	
	SpaceIpo *sipo = (SpaceIpo *)ac->sl;
	View2D *v2d = &ac->ar->v2d;
	short mapping_flag = 0;
	
	/* get curves to search through 
	 *	- if the option to only show keyframes that belong to selected F-Curves is enabled,
	 *	  include the 'only selected' flag...
	 */
	filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS);
	if (sipo->flag & SIPO_SELCUVERTSONLY)   // FIXME: this should really be check for by the filtering code...
		filter |= ANIMFILTER_SEL;
	mapping_flag |= ANIM_get_normalization_flags(ac);
	ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
	
	for (ale = anim_data.first; ale; ale = ale->next) {
		FCurve *fcu = (FCurve *)ale->key_data;
		AnimData *adt = ANIM_nla_mapping_get(ac, ale);
		float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, mapping_flag);

		/* apply NLA mapping to all the keyframes */
		if (adt)
			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 0);

		if (fcu->bezt) {
			BezTriple *bezt1 = fcu->bezt, *prevbezt = NULL;
			int i;
			
			for (i = 0; i < fcu->totvert; i++, prevbezt = bezt1, bezt1++) {
				/* keyframe */
				nearest_fcurve_vert_store(matches, v2d, fcu, bezt1, NULL, NEAREST_HANDLE_KEY, mval, unit_scale);
				
				/* handles - only do them if they're visible */
				if (fcurve_handle_sel_check(sipo, bezt1) && (fcu->totvert > 1)) {
					/* first handle only visible if previous segment had handles */
					if ((!prevbezt && (bezt1->ipo == BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ))) {
						nearest_fcurve_vert_store(matches, v2d, fcu, bezt1, NULL, NEAREST_HANDLE_LEFT, mval, unit_scale);
					}
					
					/* second handle only visible if this segment is bezier */
					if (bezt1->ipo == BEZT_IPO_BEZ) {
						nearest_fcurve_vert_store(matches, v2d, fcu, bezt1, NULL, NEAREST_HANDLE_RIGHT, mval, unit_scale);
					}
				}
			}
		}
		else if (fcu->fpt) {
			// TODO; do this for samples too
			
		}
		
		/* un-apply NLA mapping from all the keyframes */
		if (adt)
			ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, 0);
	}
	
	/* free channels */
	BLI_freelistN(&anim_data);
}
Пример #8
0
/* helper func - just draw the F-Curve by sampling the visible region (for drawing curves with modifiers) */
static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d, View2DGrid *grid)
{
	SpaceIpo *sipo = (SpaceIpo *)ac->sl;
	ChannelDriver *driver;
	float samplefreq;
	float stime, etime;
	float unitFac, offset;
	float dx, dy;
	short mapping_flag = ANIM_get_normalization_flags(ac);
	int i, n;

	/* when opening a blend file on a different sized screen or while dragging the toolbar this can happen
	 * best just bail out in this case */
	UI_view2d_grid_size(grid, &dx, &dy);
	if (dx <= 0.0f)
		return;


	/* disable any drivers temporarily */
	driver = fcu->driver;
	fcu->driver = NULL;
	
	/* compute unit correction factor */
	unitFac = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag, &offset);
	
	/* Note about sampling frequency:
	 *  Ideally, this is chosen such that we have 1-2 pixels = 1 segment
	 *	which means that our curves can be as smooth as possible. However,
	 *  this does mean that curves may not be fully accurate (i.e. if they have
	 *  sudden spikes which happen at the sampling point, we may have problems).
	 *  Also, this may introduce lower performance on less densely detailed curves,
	 *	though it is impossible to predict this from the modifiers!
	 *
	 *	If the automatically determined sampling frequency is likely to cause an infinite
	 *	loop (i.e. too close to 0), then clamp it to a determined "safe" value. The value
	 *  chosen here is just the coarsest value which still looks reasonable...
	 */
	/* grid->dx represents the number of 'frames' between gridlines, but we divide by U.v2d_min_gridsize to get pixels-steps */
	/* TODO: perhaps we should have 1.0 frames as upper limit so that curves don't get too distorted? */
	samplefreq = dx / (U.v2d_min_gridsize * U.pixelsize);
	
	if (sipo->flag & SIPO_BEAUTYDRAW_OFF) {
		/* Low Precision = coarse lower-bound clamping
		 * 
		 * Although the "Beauty Draw" flag was originally for AA'd
		 * line drawing, the sampling rate here has a much greater
		 * impact on performance (e.g. for T40372)!
		 *
		 * This one still amounts to 10 sample-frames for each 1-frame interval
		 * which should be quite a decent approximation in many situations.
		 */
		if (samplefreq < 0.1f)
			samplefreq = 0.1f;
	}
	else {
		/* "Higher Precision" but slower - especially on larger windows (e.g. T40372) */
		if (samplefreq < 0.00001f)
			samplefreq = 0.00001f;
	}
	
	
	/* the start/end times are simply the horizontal extents of the 'cur' rect */
	stime = v2d->cur.xmin;
	etime = v2d->cur.xmax + samplefreq; /* + samplefreq here so that last item gets included... */
	
	
	/* at each sampling interval, add a new vertex 
	 *	- apply the unit correction factor to the calculated values so that 
	 *	  the displayed values appear correctly in the viewport
	 */
	glBegin(GL_LINE_STRIP);
	
	n = (etime - stime) / samplefreq + 0.5f;
	for (i = 0; i <= n; i++) {
		float ctime = stime + i * samplefreq;
		glVertex2f(ctime, (evaluate_fcurve(fcu, ctime) + offset) * unitFac);
	}
	
	glEnd();
	
	/* restore driver */
	fcu->driver = driver;
}