[Bf-blender-cvs] [f674976edd8] master: Curve: Remove 'CU_2D' flag used for nurbs

Germano Cavalcante noreply at git.blender.org
Thu Apr 1 15:55:13 CEST 2021


Commit: f674976edd884d7a9a409042708f2b1169fd4e98
Author: Germano Cavalcante
Date:   Thu Apr 1 10:41:12 2021 -0300
Branches: master
https://developer.blender.org/rBf674976edd884d7a9a409042708f2b1169fd4e98

Curve: Remove 'CU_2D' flag used for nurbs

This fixes T86440

As the CU_2D flag is set for nurbs, a Curve can have 2D nurbs mixed with 3D.

But the UI does not allow this mixing. It updates all nurbs to 2D or 3D when set.

So remove this specific flag for nurbs.

This may break old files, since 2D curves with mixed 3D are now set as 3D.

Differential Revision: https://developer.blender.org/D10738

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

M	source/blender/blenkernel/BKE_curve.h
M	source/blender/blenkernel/intern/curve.c
M	source/blender/blenkernel/intern/curve_convert.c
M	source/blender/blenkernel/intern/displist.c
M	source/blender/blenkernel/intern/font.c
M	source/blender/blenlib/intern/freetypefont.c
M	source/blender/blenloader/intern/versioning_250.c
M	source/blender/blenloader/intern/versioning_290.c
M	source/blender/editors/curve/curve_intern.h
M	source/blender/editors/curve/editcurve.c
M	source/blender/editors/curve/editcurve_add.c
M	source/blender/editors/curve/editcurve_paint.c
M	source/blender/editors/object/object_add.c
M	source/blender/editors/object/object_data_transform.c
M	source/blender/editors/space_view3d/view3d_buttons.c
M	source/blender/editors/transform/transform_convert_curve.c
M	source/blender/editors/util/ed_transverts.c
M	source/blender/makesdna/DNA_curve_types.h
M	source/blender/makesrna/intern/rna_curve.c

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

diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h
index 2380af6a08e..8381f015bee 100644
--- a/source/blender/blenkernel/BKE_curve.h
+++ b/source/blender/blenkernel/BKE_curve.h
@@ -69,16 +69,16 @@ typedef struct CVKeyIndex {
 #define SEGMENTSU(nu) (((nu)->flagu & CU_NURB_CYCLIC) ? (nu)->pntsu : (nu)->pntsu - 1)
 #define SEGMENTSV(nu) (((nu)->flagv & CU_NURB_CYCLIC) ? (nu)->pntsv : (nu)->pntsv - 1)
 
-#define CU_DO_TILT(cu, nu) ((((nu)->flag & CU_2D) && ((cu)->flag & CU_3D) == 0) ? 0 : 1)
 #define CU_DO_RADIUS(cu, nu) \
-  ((CU_DO_TILT(cu, nu) || ((cu)->flag & CU_PATH_RADIUS) || (cu)->bevobj || (cu)->ext1 != 0.0f || \
+  ((((cu)->flag & (CU_PATH_RADIUS | CU_3D)) || (cu)->bevobj || (cu)->ext1 != 0.0f || \
     (cu)->ext2 != 0.0f) ? \
        1 : \
        0)
 
+#define CU_IS_2D(cu) (((cu)->flag & CU_3D) == 0)
+
 /* not 3d and not unfilled */
-#define CU_DO_2DFILL(cu) \
-  ((((cu)->flag & CU_3D) == 0) && (((cu)->flag & (CU_FRONT | CU_BACK)) != 0))
+#define CU_DO_2DFILL(cu) (CU_IS_2D(cu) && (((cu)->flag & (CU_FRONT | CU_BACK)) != 0))
 
 /* ** Curve ** */
 void BKE_curve_editfont_free(struct Curve *cu);
@@ -86,7 +86,7 @@ void BKE_curve_init(struct Curve *cu, const short curve_type);
 struct Curve *BKE_curve_add(struct Main *bmain, const char *name, int type);
 short BKE_curve_type_get(const struct Curve *cu);
 void BKE_curve_type_test(struct Object *ob);
-void BKE_curve_curve_dimension_update(struct Curve *cu);
+void BKE_curve_dimension_update(struct Curve *cu);
 
 struct BoundBox *BKE_curve_boundbox_get(struct Object *ob);
 
@@ -186,7 +186,7 @@ void BKE_nurb_free(struct Nurb *nu);
 struct Nurb *BKE_nurb_duplicate(const struct Nurb *nu);
 struct Nurb *BKE_nurb_copy(struct Nurb *src, int pntsu, int pntsv);
 
-void BKE_nurb_test_2d(struct Nurb *nu);
+void BKE_nurb_project_2d(struct Nurb *nu);
 void BKE_nurb_minmax(const struct Nurb *nu, bool use_radius, float min[3], float max[3]);
 float BKE_nurb_calc_length(const struct Nurb *nu, int resolution);
 
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index 021aea20d22..95c242c31b2 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -462,24 +462,19 @@ short BKE_curve_type_get(const Curve *cu)
   return type;
 }
 
-void BKE_curve_curve_dimension_update(Curve *cu)
+void BKE_curve_dimension_update(Curve *cu)
 {
   ListBase *nurbs = BKE_curve_nurbs_get(cu);
+  bool is_2d = CU_IS_2D(cu);
 
-  if (cu->flag & CU_3D) {
-    LISTBASE_FOREACH (Nurb *, nu, nurbs) {
-      nu->flag &= ~CU_2D;
+  LISTBASE_FOREACH (Nurb *, nu, nurbs) {
+    if (is_2d) {
+      BKE_nurb_project_2d(nu);
     }
-  }
-  else {
-    LISTBASE_FOREACH (Nurb *, nu, nurbs) {
-      nu->flag |= CU_2D;
-      BKE_nurb_test_2d(nu);
 
-      /* since the handles are moved they need to be auto-located again */
-      if (nu->type == CU_BEZIER) {
-        BKE_nurb_handles_calc(nu);
-      }
+    /* since the handles are moved they need to be auto-located again */
+    if (nu->type == CU_BEZIER) {
+      BKE_nurb_handles_calc(nu);
     }
   }
 }
@@ -489,7 +484,10 @@ void BKE_curve_type_test(Object *ob)
   ob->type = BKE_curve_type_get(ob->data);
 
   if (ob->type == OB_CURVE) {
-    BKE_curve_curve_dimension_update((Curve *)ob->data);
+    Curve *cu = ob->data;
+    if (CU_IS_2D(cu)) {
+      BKE_curve_dimension_update(cu);
+    }
   }
 }
 
@@ -745,16 +743,12 @@ void BKE_nurbList_duplicate(ListBase *lb1, const ListBase *lb2)
   }
 }
 
-void BKE_nurb_test_2d(Nurb *nu)
+void BKE_nurb_project_2d(Nurb *nu)
 {
   BezTriple *bezt;
   BPoint *bp;
   int a;
 
-  if ((nu->flag & CU_2D) == 0) {
-    return;
-  }
-
   if (nu->type == CU_BEZIER) {
     a = nu->pntsu;
     bezt = nu->bezt;
@@ -2712,8 +2706,9 @@ void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render)
       continue;
     }
 
-    /* check if we will calculate tilt data */
-    do_tilt = CU_DO_TILT(cu, nu);
+    /* Tilt, as the rotation angle of curve control points, is only calculated for 3D curves,
+     * (since this transformation affects the 3D space). */
+    do_tilt = (cu->flag & CU_3D) != 0;
 
     /* Normal display uses the radius, better just to calculate them. */
     do_radius = CU_DO_RADIUS(cu, nu);
@@ -3125,7 +3120,7 @@ void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render)
     }
 
     /* turning direction */
-    if ((cu->flag & CU_3D) == 0) {
+    if (CU_IS_2D(cu)) {
       sd = sortdata;
       for (a = 0; a < poly; a++, sd++) {
         if (sd->bl->hole == sd->dir) {
@@ -3145,7 +3140,7 @@ void BKE_curve_bevelList_make(Object *ob, ListBase *nurbs, bool for_render)
   }
 
   /* STEP 4: 2D-COSINES or 3D ORIENTATION */
-  if ((cu->flag & CU_3D) == 0) {
+  if (CU_IS_2D(cu)) {
     /* 2D Curves */
     LISTBASE_FOREACH (BevList *, bl, bev) {
       if (bl->nr < 2) {
@@ -4730,9 +4725,7 @@ void BKE_curve_nurbs_vert_coords_apply_with_mat4(ListBase *lb,
     }
 
     if (constrain_2d) {
-      if (nu->flag & CU_2D) {
-        BKE_nurb_test_2d(nu);
-      }
+      BKE_nurb_project_2d(nu);
     }
 
     calchandlesNurb_intern(nu, SELECT, true);
@@ -4768,9 +4761,7 @@ void BKE_curve_nurbs_vert_coords_apply(ListBase *lb,
     }
 
     if (constrain_2d) {
-      if (nu->flag & CU_2D) {
-        BKE_nurb_test_2d(nu);
-      }
+      BKE_nurb_project_2d(nu);
     }
 
     calchandlesNurb_intern(nu, SELECT, true);
diff --git a/source/blender/blenkernel/intern/curve_convert.c b/source/blender/blenkernel/intern/curve_convert.c
index 988ddb3bbc0..5bcce9c339e 100644
--- a/source/blender/blenkernel/intern/curve_convert.c
+++ b/source/blender/blenkernel/intern/curve_convert.c
@@ -44,7 +44,7 @@ static Curve *curve_from_font_object(Object *object, Depsgraph *depsgraph)
   new_curve->type = OB_CURVE;
 
   new_curve->flag &= ~CU_3D;
-  BKE_curve_curve_dimension_update(new_curve);
+  BKE_curve_dimension_update(new_curve);
 
   return new_curve;
 }
diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c
index a04bad45bf6..9022760fe34 100644
--- a/source/blender/blenkernel/intern/displist.c
+++ b/source/blender/blenkernel/intern/displist.c
@@ -1185,7 +1185,7 @@ void BKE_displist_make_surf(Depsgraph *depsgraph,
 
       /* dl->rt will be used as flag for render face and */
       /* CU_2D conflicts with R_NOPUNOFLIP */
-      dl->rt = nu->flag & ~CU_2D;
+      dl->rt = nu->flag;
 
       data = dl->verts;
       if (nu->flagu & CU_NURB_CYCLIC) {
@@ -1209,7 +1209,7 @@ void BKE_displist_make_surf(Depsgraph *depsgraph,
 
       /* dl->rt will be used as flag for render face and */
       /* CU_2D conflicts with R_NOPUNOFLIP */
-      dl->rt = nu->flag & ~CU_2D;
+      dl->rt = nu->flag;
 
       data = dl->verts;
       dl->type = DL_SURF;
@@ -1320,7 +1320,7 @@ static void fillBevelCap(const Nurb *nu,
 
   /* dl->rt will be used as flag for render face and */
   /* CU_2D conflicts with R_NOPUNOFLIP */
-  dl->rt = nu->flag & ~CU_2D;
+  dl->rt = nu->flag;
 
   BLI_addtail(dispbase, dl);
 }
@@ -1551,7 +1551,7 @@ static void do_makeDispListCurveTypes(Depsgraph *depsgraph,
 
           /* dl->rt will be used as flag for render face and */
           /* CU_2D conflicts with R_NOPUNOFLIP */
-          dl->rt = nu->flag & ~CU_2D;
+          dl->rt = nu->flag;
 
           int a = dl->nr;
           BevPoint *bevp = bl->bevpoints;
@@ -1606,7 +1606,7 @@ static void do_makeDispListCurveTypes(Depsgraph *depsgraph,
 
             /* dl->rt will be used as flag for render face and */
             /* CU_2D conflicts with R_NOPUNOFLIP */
-            dl->rt = nu->flag & ~CU_2D;
+            dl->rt = nu->flag;
 
             /* for each point of poly make a bevel piece */
             BevPoint *bevp_first = bl->bevpoints;
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index febc9e24c9f..64f44240eed 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -447,7 +447,6 @@ static void build_underline(Curve *cu,
   nu2->resolu = cu->resolu;
   nu2->bezt = NULL;
   nu2->knotsu = nu2->knotsv = NULL;
-  nu2->flag = CU_2D;
   nu2->charidx = charidx + 1000;
   if (mat_nr > 0) {
     nu2->mat_nr = mat_nr - 1;
diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c
index e755a8e75b5..98da85e3a8c 100644
--- a/source/blender/blenlib/intern/freetypefont.c
+++ b/source/blender/blenlib/intern/freetypefont.c
@@ -135,7 +135,6 @@ static VChar *freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *
       nu->type = CU_BEZIER;
       nu->pntsu = onpoints[j];
       nu->resolu = 8;
-      nu->flag = CU_2D;
       nu->flagu = CU_NURB_CYCLIC;
       nu->bezt = bezt;
 
diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c
index 467fd8b0399..6338dc95aba 100644
--- a/source/blender/blenloader/intern/versioning_250.c
+++ b/source/blender/blenloader/intern/versioning_250.c
@@ -779,7 +779,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *bmain)
       Nurb *nu;
 
       for (nu = cu->nurb.first; nu; nu = nu->next) {
-        nu->flag |= (nu->type & CU_2D);
         nu->type &= CU_TYPE;
       }
     }
diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c
index 4997639de5e..0d59845e934 100644
--- a/source/blender/blenloader/intern/versioning_290.c
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -57,6 +57,7 @@
 #include "BKE_collection.h"
 #include "BKE_colortools.h"
 #include "BKE_cryptomatte.h"
+#include "BKE_curve.h"
 #include "BKE_fcurve.h"
 #include "BKE_gpencil.h"
 #include "BKE_lib_id.h"
@@ -1983,5 +1984,25 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
         }
       }
     }
+
+    /* The CU_2D flag has been removed. */
+    LISTBASE_FOREACH (Curve *, cu, &bmain->curves) {
+#define CU_2D (1 << 3)
+      ListBase *nurbs = BKE_curve_nurbs_get(cu);
+      bool is_2d = true;
+
+      LISTBASE_FOREACH (Nurb *, nu, nurbs) {
+        if (nu->flag & CU_2D) {
+          nu->flag &= ~CU_2D;
+        }
+      

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list