merge with/from trunk at r35190
[blender.git] / source / blender / modifiers / intern / MOD_screw.c
index 7cec359fd33ef6483add84c90c9498f1a71374b3..68ad5437585a690ce82ba80fa219ca538dd64884 100644 (file)
 *
 */
 
+/** \file blender/modifiers/intern/MOD_screw.c
+ *  \ingroup modifiers
+ */
+
+
 /* Screw modifier: revolves the edges about an axis */
 
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
 
 #include "BLI_math.h"
+#include "BLI_utildefines.h"
+
 
 #include "BKE_cdderivedmesh.h"
 
@@ -128,8 +135,9 @@ static void copyData(ModifierData *md, ModifierData *target)
 }
 
 static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
-                                                                               DerivedMesh *derivedData,
-                                                                               int useRenderParams, int isFinalCalc)
+                                               DerivedMesh *derivedData,
+                                               int useRenderParams,
+                                               int UNUSED(isFinalCalc))
 {
        DerivedMesh *dm= derivedData;
        DerivedMesh *result;
@@ -140,7 +148,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
        int step;
        int i, j;
        int i1,i2;
-       int step_tot= ltmd->steps;
+       int step_tot= useRenderParams ? ltmd->render_steps : ltmd->steps;
        const int do_flip = ltmd->flag & MOD_SCREW_NORMAL_FLIP ? 1 : 0;
        int maxVerts=0, maxEdges=0, maxFaces=0;
        int totvert= dm->getNumVerts(dm);
@@ -166,17 +174,10 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
 
        ScrewVertConnect *vc, *vc_tmp, *vert_connect= NULL;
 
-       float mat[4][4] =       {{0.0f, 0.0f, 0.0f, 0.0f},
-                                                {0.0f, 0.0f, 0.0f, 0.0f},
-                                                {0.0f, 0.0f, 0.0f, 0.0f},
-                                                {0.0f, 0.0f, 0.0f, 1.0f}};
-
        /* dont do anything? */
        if (!totvert)
                return CDDM_from_template(dm, 0, 0, 0, 0, 0);
 
-       step_tot= useRenderParams ? ltmd->render_steps : ltmd->steps;
-
        switch(ltmd->axis) {
        case 0:
                other_axis_1=1;
@@ -221,7 +222,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
 
                /* angle */
 
-#if 0  // cant incluide this, not pradictable enough, though quite fun,.
+#if 0  // cant incluide this, not predictable enough, though quite fun,.
                if(ltmd->flag & MOD_SCREW_OBJECT_ANGLE) {
                        float mtx3_tx[3][3];
                        copy_m3_m4(mtx3_tx, mtx_tx);
@@ -270,7 +271,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
        step_tot = ((step_tot + 1) * ltmd->iter) - (ltmd->iter - 1);
 
        /* will the screw be closed?
-        * Note! smaller then FLT_EPSILON*100 gives problems with float precission so its never closed. */
+        * Note! smaller then FLT_EPSILON*100 gives problems with float precision so its never closed. */
        if (fabs(screw_ofs) <= (FLT_EPSILON*100) && fabs(fabs(angle) - (M_PI * 2)) <= (FLT_EPSILON*100)) {
                close= 1;
                step_tot--;
@@ -304,6 +305,8 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
        medge_new =             result->getEdgeArray(result);
        
        origindex= result->getTessFaceDataArray(result, CD_ORIGINDEX);
+
+       DM_copy_vert_data(dm, result, 0, 0, totvert); /* copy first otherwise this overwrites our own vertex normals */
        
        /* Set the locations of the first set of verts */
        
@@ -435,15 +438,15 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
                        /* find the first vert */
                        vc= vert_connect;
                        for (i=0; i < totvert; i++, vc++) {
-                               int v_best=-1, ed_loop_closed=0; /* vert and vert new */
-                               int ed_loop_flip= 0; /* compiler complains if not initialized, but it should be initialized below */
-                               float fl= -1.0f;
-                               ScrewVertIter lt_iter;
-
                                /* Now do search for connected verts, order all edges and flip them
                                 * so resulting faces are flipped the right way */
                                vc_tot_linked= 0; /* count the number of linked verts for this loop */
                                if (vc->flag == 0) {
+                                       int v_best=-1, ed_loop_closed=0; /* vert and vert new */
+                                       ScrewVertIter lt_iter;
+                                       int ed_loop_flip= 0; /* compiler complains if not initialized, but it should be initialized below */
+                                       float fl= -1.0f;
+
                                        /*printf("Loop on connected vert: %i\n", i);*/
 
                                        for(j=0; j<2; j++) {
@@ -665,13 +668,12 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
        }
        /* done with edge connectivity based normal flipping */
        
-       DM_copy_vert_data(dm, result, 0, 0, totvert);
-       
        /* Add Faces */
        for (step=1; step < step_tot; step++) {
                const int varray_stride= totvert * step;
                float step_angle;
                float nor_tx[3];
+               float mat[4][4];
                /* Rotation Matrix */
                step_angle= (angle / (step_tot - (!close))) * step;
 
@@ -831,12 +833,15 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
        dm = CDDM_copy(result, 1); /*builds ngon faces from tess (mface) faces*/
        result->needsFree = 1;
        result->release(result);
+       
+       return dm;
 }
 
 
-static void updateDepgraph(
-                                                                       ModifierData *md, DagForest *forest,
-                                                                       struct Scene *scene, Object *ob, DagNode *obNode)
+static void updateDepgraph(ModifierData *md, DagForest *forest,
+                                               struct Scene *UNUSED(scene),
+                                               Object *UNUSED(ob),
+                                               DagNode *obNode)
 {
        ScrewModifierData *ltmd= (ScrewModifierData*) md;
 
@@ -861,13 +866,15 @@ static void foreachObjectLink(
 
 /* This dosnt work with material*/
 static DerivedMesh *applyModifierEM(
-                                               ModifierData *md, Object *ob, struct EditMesh *editData,
+                                               ModifierData *md,
+                                               Object *ob,
+                                               struct EditMesh *UNUSED(editData),
                                                DerivedMesh *derivedData)
 {
        return applyModifier(md, ob, derivedData, 0, 1);
 }
 
-static int dependsOnTime(ModifierData *md)
+static int dependsOnTime(ModifierData *UNUSED(md))
 {
        return 0;
 }
@@ -886,6 +893,7 @@ ModifierTypeInfo modifierType_Screw = {
 
        /* copyData */          copyData,
        /* deformVerts */       0,
+       /* deformMatrices */    0,
        /* deformVertsEM */     0,
        /* deformMatricesEM */  0,
        /* applyModifier */     applyModifier,
@@ -896,6 +904,7 @@ ModifierTypeInfo modifierType_Screw = {
        /* isDisabled */        0,
        /* updateDepgraph */    updateDepgraph,
        /* dependsOnTime */     dependsOnTime,
+       /* dependsOnNormals */  0,
        /* foreachObjectLink */ foreachObjectLink,
        /* foreachIDLink */     0,
 };