Merging r59136 through r59152 from trunk into soc-2013-depsgraph_mt
[blender.git] / source / blender / blenkernel / intern / curve.c
index d677a6b07e47452984c68d317479faf2f4fb9cc5..4b98723b1b430355b2d402dbcf3a26c430a342dc 100644 (file)
@@ -2412,12 +2412,23 @@ static void make_bevel_list_2D(BevList *bl)
        /* note: bevp->dir and bevp->quat are not needed for beveling but are
         * used when making a path from a 2D curve, therefor they need to be set - Campbell */
 
-       BevPoint *bevp2 = (BevPoint *)(bl + 1);
-       BevPoint *bevp1 = bevp2 + (bl->nr - 1);
-       BevPoint *bevp0 = bevp1 - 1;
+       BevPoint *bevp0, *bevp1, *bevp2;
        int nr;
 
-       nr = bl->nr;
+       if (bl->poly != -1) {
+               bevp2 = (BevPoint *)(bl + 1);
+               bevp1 = bevp2 + (bl->nr - 1);
+               bevp0 = bevp1 - 1;
+               nr = bl->nr;
+       }
+       else {
+               bevp0 = (BevPoint *)(bl + 1);
+               bevp1 = bevp0 + 1;
+               bevp2 = bevp1 + 1;
+
+               nr = bl->nr - 2;
+       }
+
        while (nr--) {
                const float x1 = bevp1->vec[0] - bevp0->vec[0];
                const float x2 = bevp1->vec[0] - bevp2->vec[0];
@@ -2439,15 +2450,23 @@ static void make_bevel_list_2D(BevList *bl)
 
        /* correct non-cyclic cases */
        if (bl->poly == -1) {
-               BevPoint *bevp = (BevPoint *)(bl + 1);
-               bevp1 = bevp + 1;
-               bevp->sina = bevp1->sina;
-               bevp->cosa = bevp1->cosa;
+               BevPoint *bevp;
+               float angle;
+
+               /* first */
+               bevp = (BevPoint *)(bl + 1);
+               angle = atan2(bevp->dir[0], bevp->dir[1]) - M_PI / 2.0;
+               bevp->sina = sinf(angle);
+               bevp->cosa = cosf(angle);
+               vec_to_quat(bevp->quat, bevp->dir, 5, 1);
+
+               /* last */
                bevp = (BevPoint *)(bl + 1);
                bevp += (bl->nr - 1);
-               bevp1 = bevp - 1;
-               bevp->sina = bevp1->sina;
-               bevp->cosa = bevp1->cosa;
+               angle = atan2(bevp->dir[0], bevp->dir[1]) - M_PI / 2.0;
+               bevp->sina = sinf(angle);
+               bevp->cosa = cosf(angle);
+               vec_to_quat(bevp->quat, bevp->dir, 5, 1);
        }
 }
 
@@ -3858,7 +3877,7 @@ void BKE_curve_translate(Curve *cu, float offset[3], int do_keys)
        }
 }
 
-void BKE_curve_delete_material_index(Curve *cu, int index)
+void BKE_curve_material_index_remove(Curve *cu, int index)
 {
        const int curvetype = BKE_curve_type_get(cu);
 
@@ -3877,8 +3896,32 @@ void BKE_curve_delete_material_index(Curve *cu, int index)
                for (nu = cu->nurb.first; nu; nu = nu->next) {
                        if (nu->mat_nr && nu->mat_nr >= index) {
                                nu->mat_nr--;
-                               if (curvetype == OB_CURVE)
+                               if (curvetype == OB_CURVE) {
                                        nu->charidx--;
+                               }
+                       }
+               }
+       }
+}
+
+void BKE_curve_material_index_clear(Curve *cu)
+{
+       const int curvetype = BKE_curve_type_get(cu);
+
+       if (curvetype == OB_FONT) {
+               struct CharInfo *info = cu->strinfo;
+               int i;
+               for (i = cu->len - 1; i >= 0; i--, info++) {
+                       info->mat_nr = 0;
+               }
+       }
+       else {
+               Nurb *nu;
+
+               for (nu = cu->nurb.first; nu; nu = nu->next) {
+                       nu->mat_nr = 0;
+                       if (curvetype == OB_CURVE) {
+                               nu->charidx = 0;
                        }
                }
        }