[Bf-blender-cvs] [38f2f4c] master: [T40372] FCurve Eval/Drawing Optimisation: Skip Bezier handle eval when all handles are flat

Joshua Leung noreply at git.blender.org
Sun Nov 16 11:34:08 CET 2014


Commit: 38f2f4c564e1431108b9b7f9ae6992041c89c280
Author: Joshua Leung
Date:   Sun Nov 16 22:30:42 2014 +1300
Branches: master
https://developer.blender.org/rB38f2f4c564e1431108b9b7f9ae6992041c89c280

[T40372] FCurve Eval/Drawing Optimisation: Skip Bezier handle eval when all handles are flat

Small optimisation (which shouldn't have much of an effect) where we skip
complex handle calculations if all the handles/verts for a Bezier curve
segment are all flat.

Patch by Campbell (T40372 -> F91346)

===================================================================

M	source/blender/blenkernel/intern/fcurve.c

===================================================================

diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c
index 325c605..88d7069 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -2157,18 +2157,29 @@ static float fcurve_eval_keyframes(FCurve *fcu, BezTriple *bezts, float evaltime
 						v4[0] = bezt->vec[1][0];
 						v4[1] = bezt->vec[1][1];
 						
-						/* adjust handles so that they don't overlap (forming a loop) */
-						correct_bezpart(v1, v2, v3, v4);
-						
-						/* try to get a value for this position - if failure, try another set of points */
-						b = findzero(evaltime, v1[0], v2[0], v3[0], v4[0], opl);
-						if (b) {
-							berekeny(v1[1], v2[1], v3[1], v4[1], opl, 1);
-							cvalue = opl[0];
-							/* break; */
-						}
-						else {
-							if (G.debug & G_DEBUG) printf("    ERROR: findzero() failed at %f with %f %f %f %f\n", evaltime, v1[0], v2[0], v3[0], v4[0]);
+						if (fabsf(v1[1] - v4[1]) < FLT_EPSILON &&
+						    fabsf(v2[1] - v3[1]) < FLT_EPSILON &&
+						    fabsf(v3[1] - v4[1]) < FLT_EPSILON)
+						{
+							/* Optimisation: If all the handles are flat/at the same values,
+							 * the value is simply the shared value (see T40372 -> F91346)
+							 */
+							cvalue = v1[1];
+ 						}
+ 						else {
+							/* adjust handles so that they don't overlap (forming a loop) */
+							correct_bezpart(v1, v2, v3, v4);
+							
+							/* try to get a value for this position - if failure, try another set of points */
+							b = findzero(evaltime, v1[0], v2[0], v3[0], v4[0], opl);
+							if (b) {
+								berekeny(v1[1], v2[1], v3[1], v4[1], opl, 1);
+								cvalue = opl[0];
+								/* break; */
+							}
+							else {
+								if (G.debug & G_DEBUG) printf("    ERROR: findzero() failed at %f with %f %f %f %f\n", evaltime, v1[0], v2[0], v3[0], v4[0]);
+							}
 						}
 						break;




More information about the Bf-blender-cvs mailing list