[Bf-blender-cvs] [3a370ec] master: Move curve's boundbox and texspace calculation out of modifier stack

Sergey Sharybin noreply at git.blender.org
Wed Dec 11 11:33:09 CET 2013


Commit: 3a370ec6ecb7c481ff7a9f0d5108367c903a29c1
Author: Sergey Sharybin
Date:   Sun Oct 20 14:41:33 2013 +0200
http://developer.blender.org/rB3a370ec6ecb7c481ff7a9f0d5108367c903a29c1

Move curve's boundbox and texspace calculation out of modifier stack

There were several issues with how bounding box and texture space
are calculated:

- This was done at the same time as applying modifiers, meaning if
  several objects are sharing the same curve datablock, bounding
  box and texture space will be calculated multiple times.

  Further, allocating bounding box wasn't safe for threading.

- Bounding box and texture space were evaluated after pre-tessellation
  modifiers are applied. This means Curve-level data is actually
  depends on object data, and it's really bad because different
  objects could have different modifiers and this leads to
  conflicts (curve's data depends on object evaluation order)
  and doesn't behave in a predictable way.

  This commit moves bounding box and texture space evaluation from
  modifier stack to own utility functions, just like it's was done
  for meshes.

  This makes curve objects update thread-safe, but gives some
  limitations as well. Namely, with such approach it's not so
  clear how to preserve the same behavior of texture space:
  before this change texture space and bounding box would match
  beveled curve as accurate as possible.

  Old behavior was nice for quick texturing -- in most cases you
  didn't need to modify texture space at all. But texture space
  was depending on render/preview settings which could easily lead
  to situations, when final result would be far different from
  preview one.

  Now we're using CV points coordinates and their radius to approximate
  the bounding box. This doesn't give the same exact texture space,
  but it helps a lot keeping texture space in a nice predictable way.

  We could make approximation smarter in the future, but fir now
  added operator to match texture space to fully tessellated curve
  called "Match Texture Space".

Review link:

  https://codereview.appspot.com/15410043/

Brief description:

  http://wiki.blender.org/index.php/User:Nazg-gul/GSoC-2013/Results#Curve_Texture_Space

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

M	release/scripts/startup/bl_ui/properties_data_curve.py
M	source/blender/blenkernel/BKE_curve.h
M	source/blender/blenkernel/intern/curve.c
M	source/blender/blenkernel/intern/displist.c
M	source/blender/blenkernel/intern/object.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/editors/curve/curve_intern.h
M	source/blender/editors/curve/curve_ops.c
M	source/blender/editors/curve/editcurve.c
M	source/blender/makesdna/DNA_curve_types.h

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

diff --git a/release/scripts/startup/bl_ui/properties_data_curve.py b/release/scripts/startup/bl_ui/properties_data_curve.py
index 117a662..1d90535 100644
--- a/release/scripts/startup/bl_ui/properties_data_curve.py
+++ b/release/scripts/startup/bl_ui/properties_data_curve.py
@@ -140,6 +140,8 @@ class DATA_PT_curve_texture_space(CurveButtonsPanel, Panel):
         row.column().prop(curve, "texspace_location", text="Location")
         row.column().prop(curve, "texspace_size", text="Size")
 
+        layout.operator("curve.match_texture_space")
+
 
 class DATA_PT_geometry_curve(CurveButtonsPanel, Panel):
     bl_label = "Geometry"
diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h
index dee27ce..8b21070 100644
--- a/source/blender/blenkernel/BKE_curve.h
+++ b/source/blender/blenkernel/BKE_curve.h
@@ -76,7 +76,7 @@ struct BoundBox *BKE_curve_boundbox_get(struct Object *ob);
 void BKE_curve_texspace_calc(struct Curve *cu);
 void BKE_curve_texspace_get(struct Curve *cu, float r_loc[3], float r_rot[3], float r_size[3]);
 
-bool BKE_curve_minmax(struct Curve *cu, float min[3], float max[3]);
+bool BKE_curve_minmax(struct Curve *cu, bool use_radius, float min[3], float max[3]);
 bool BKE_curve_center_median(struct Curve *cu, float cent[3]);
 bool BKE_curve_center_bounds(struct Curve *cu, float cent[3]);
 void BKE_curve_translate(struct Curve *cu, float offset[3], int do_keys);
@@ -122,7 +122,7 @@ struct Nurb *BKE_nurb_duplicate(struct Nurb *nu);
 struct Nurb *BKE_nurb_copy(struct Nurb *src, int pntsu, int pntsv);
 
 void BKE_nurb_test2D(struct Nurb *nu);
-void BKE_nurb_minmax(struct Nurb *nu, float min[3], float max[3]);
+void BKE_nurb_minmax(struct Nurb *nu, bool use_radius, float min[3], float max[3]);
 
 void BKE_nurb_makeFaces(struct Nurb *nu, float *coord_array, int rowstride, int resolu, int resolv);
 void BKE_nurb_makeCurve(struct Nurb *nu, float *coord_array, float *tilt_array, float *radius_array, float *weight_array, int resolu, int stride);
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index d57b514..969db19 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -143,7 +143,6 @@ void BKE_curve_editNurb_free(Curve *cu)
 void BKE_curve_free(Curve *cu)
 {
 	BKE_nurbList_free(&cu->nurb);
-	BKE_displist_free(&cu->disp);
 	BKE_curve_editfont_free(cu);
 
 	BKE_curve_editNurb_free(cu);
@@ -223,8 +222,6 @@ Curve *BKE_curve_copy(Curve *cu)
 	cun->key = BKE_key_copy(cu->key);
 	if (cun->key) cun->key->from = (ID *)cun;
 
-	cun->disp.first = cun->disp.last = NULL;
-
 	cun->editnurb = NULL;
 	cun->editfont = NULL;
 	cun->selboxes = NULL;
@@ -379,7 +376,11 @@ void BKE_curve_boundbox_calc(Curve *cu, float r_loc[3], float r_size[3])
 	if (!r_size) r_size = msize;
 
 	INIT_MINMAX(min, max);
-	BKE_displist_minmax(&cu->disp, min, max);
+	if (!BKE_curve_minmax(cu, true, min, max)) {
+		min[0] = min[1] = min[2] = -1.0f;
+		max[0] = max[1] = max[2] = 1.0f;
+	}
+
 	mid_v3_v3v3(r_loc, min, max);
 
 	r_size[0] = (max[0] - min[0]) / 2.0f;
@@ -642,18 +643,34 @@ void BKE_nurb_test2D(Nurb *nu)
 	}
 }
 
-void BKE_nurb_minmax(Nurb *nu, float min[3], float max[3])
+/* if use_radius is truth, minmax will take points' radius into account,
+ * which will make boundbox closer to bevelled curve.
+ */
+void BKE_nurb_minmax(Nurb *nu, bool use_radius, float min[3], float max[3])
 {
 	BezTriple *bezt;
 	BPoint *bp;
 	int a;
+	float point[3];
 
 	if (nu->type == CU_BEZIER) {
 		a = nu->pntsu;
 		bezt = nu->bezt;
 		while (a--) {
+			if (use_radius) {
+				float radius_vector[3];
+				radius_vector[0] = radius_vector[1] = radius_vector[2] = bezt->radius;
+
+				add_v3_v3v3(point, bezt->vec[1], radius_vector);
+				minmax_v3v3_v3(min, max, point);
+
+				sub_v3_v3v3(point, bezt->vec[1], radius_vector);
+				minmax_v3v3_v3(min, max, point);
+			}
+			else {
+				minmax_v3v3_v3(min, max, bezt->vec[1]);
+			}
 			minmax_v3v3_v3(min, max, bezt->vec[0]);
-			minmax_v3v3_v3(min, max, bezt->vec[1]);
 			minmax_v3v3_v3(min, max, bezt->vec[2]);
 			bezt++;
 		}
@@ -662,7 +679,20 @@ void BKE_nurb_minmax(Nurb *nu, float min[3], float max[3])
 		a = nu->pntsu * nu->pntsv;
 		bp = nu->bp;
 		while (a--) {
-			minmax_v3v3_v3(min, max, bp->vec);
+			if (nu->pntsv == 1 && use_radius) {
+				float radius_vector[3];
+				radius_vector[0] = radius_vector[1] = radius_vector[2] = bp->radius;
+
+				add_v3_v3v3(point, bp->vec, radius_vector);
+				minmax_v3v3_v3(min, max, point);
+
+				sub_v3_v3v3(point, bp->vec, radius_vector);
+				minmax_v3v3_v3(min, max, point);
+			}
+			else {
+				/* Surfaces doesn't use bevel, so no need to take radius into account. */
+				minmax_v3v3_v3(min, max, bp->vec);
+			}
 			bp++;
 		}
 	}
@@ -3840,13 +3870,13 @@ ListBase *BKE_curve_nurbs_get(Curve *cu)
 
 
 /* basic vertex data functions */
-bool BKE_curve_minmax(Curve *cu, float min[3], float max[3])
+bool BKE_curve_minmax(Curve *cu, bool use_radius, float min[3], float max[3])
 {
 	ListBase *nurb_lb = BKE_curve_nurbs_get(cu);
 	Nurb *nu;
 
 	for (nu = nurb_lb->first; nu; nu = nu->next)
-		BKE_nurb_minmax(nu, min, max);
+		BKE_nurb_minmax(nu, use_radius, min, max);
 
 	return (nurb_lb->first != NULL);
 }
@@ -3893,7 +3923,7 @@ bool BKE_curve_center_bounds(Curve *cu, float cent[3])
 {
 	float min[3], max[3];
 	INIT_MINMAX(min, max);
-	if (BKE_curve_minmax(cu, min, max)) {
+	if (BKE_curve_minmax(cu, false, min, max)) {
 		mid_v3_v3v3(cent, min, max);
 		return true;
 	}
diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c
index 9670a18..dd1df6e 100644
--- a/source/blender/blenkernel/intern/displist.c
+++ b/source/blender/blenkernel/intern/displist.c
@@ -1265,11 +1265,6 @@ void BKE_displist_make_surf(Scene *scene, Object *ob, ListBase *dispbase,
 		}
 	}
 
-	/* make copy of 'undeformed" displist for texture space calculation
-	 * actually, it's not totally undeformed -- pre-tessellation modifiers are
-	 * already applied, thats how it worked for years, so keep for compatibility (sergey) */
-	BKE_displist_copy(&cu->disp, dispbase);
-
 	if (!forOrco) {
 		curve_calc_modifiers_post(scene, ob, &nubase, dispbase, derivedFinal,
 		                          forRender, renderResolution);
@@ -1569,11 +1564,6 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
 		if ((cu->flag & CU_PATH) && !forOrco)
 			calc_curvepath(ob, &nubase);
 
-		/* make copy of 'undeformed" displist for texture space calculation
-		 * actually, it's not totally undeformed -- pre-tessellation modifiers are
-		 * already applied, thats how it worked for years, so keep for compatibility (sergey) */
-		BKE_displist_copy(&cu->disp, dispbase);
-
 		if (!forOrco)
 			curve_calc_modifiers_post(scene, ob, &nubase, dispbase, derivedFinal, forRender, renderResolution);
 
@@ -1587,7 +1577,6 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
 
 void BKE_displist_make_curveTypes(Scene *scene, Object *ob, int forOrco)
 {
-	Curve *cu = ob->data;
 	ListBase *dispbase;
 
 	/* The same check for duplis as in do_makeDispListCurveTypes.
@@ -1596,7 +1585,6 @@ void BKE_displist_make_curveTypes(Scene *scene, Object *ob, int forOrco)
 	if (!ELEM3(ob->type, OB_SURF, OB_CURVE, OB_FONT))
 		return;
 
-	BKE_displist_free(&cu->disp);
 	BKE_object_free_derived_caches(ob);
 
 	if (!ob->curve_cache) {
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index b730378..0694bde 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -312,6 +312,11 @@ void BKE_object_free_derived_caches(Object *ob)
 	
 	if (ob->curve_cache) {
 		BKE_displist_free(&ob->curve_cache->disp);
+		BLI_freelistN(&ob->curve_cache->bev);
+		if (ob->curve_cache->path) {
+			free_path(ob->curve_cache->path);
+			ob->curve_cache->path = NULL;
+		}
 	}
 }
 
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 047dc36..be76a8b 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3414,7 +3414,6 @@ static void direct_link_curve(FileData *fd, Curve *cu)
 		if (cu->wordspace == 0.0f) cu->wordspace = 1.0f;
 	}
 
-	cu->disp.first = cu->disp.last = NULL;
 	cu->editnurb = NULL;
 	cu->lastsel = NULL;
 	cu->editfont = NULL;
diff --git a/source/blender/editors/curve/curve_intern.h b/source/blender/editors/curve/curve_intern.h
index da8f865..3ee83c2 100644
--- a/source/blender/editors/curve/curve_intern.h
+++ b/source/blender/editors/curve/curve_intern.h
@@ -118,6 +118,8 @@ void CURVE_OT_vertex_add(struct wmOperatorType *ot);
 void CURVE_OT_extrude(struct wmOperatorType *ot);
 void CURVE_OT_cyclic_toggle(struct wmOperatorType *ot);
 
+void CURVE_OT_match_texture_space(struct wmOperatorType *ot);
+
 /* helper functions */
 void ed_editnurb_translate_flag(struct ListBase *editnurb, short flag, const float vec[3]);
 bool ed_editnurb_extrude_flag(struct EditNurb *editnurb, short flag);
diff --git a/source/blender/editors/curve/curve_ops.c b/source/blender/editors/curve/curve_ops.c
index 1cf194e..e978b81 100644
--- a/source/blender/editors/curve/curve_ops.c
+++ b/source/blender/editors/curve/curve_ops.c
@@ -137,6 +137,8 @@ void ED_operatortypes_curve(void)
 	WM_operatortype_append(CURVE_OT_vertex_add);
 	WM_operatortype_append(CURVE_OT_extrude);
 	WM_operatortype_append(CURVE_OT_cyclic_toggle);
+
+	WM_operatortype_append(CURVE_OT_match_texture_space);
 }
 
 void ED_operatormacros_curve(void)
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c
index def0d3cb..caa06eb 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -47,6 +47,7 @@
 #include "BKE_context.h"
 #include "BKE_curve.h"
 #include "BKE_depsgraph.h"
+#include "BKE_displist.h"
 #include "BKE_fcurve.h"
 #include "BKE_global.h"
 #include "BKE_key.h"
@@ -6807,3 +6808,65 @@ int ED_curve_actSelection(Curve *cu, float center[3])
 
 	return 1;
 }
+
+/******************** Match texture space operator ***********************/
+
+static int

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list