Merge branch 'master' into blender2.8
[blender.git] / source / blender / modifiers / intern / MOD_screw.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software  Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2005 by the Blender Foundation.
19  * All rights reserved.
20  *
21  * Contributor(s): Daniel Dunbar
22  *                 Ton Roosendaal,
23  *                 Ben Batt,
24  *                 Brecht Van Lommel,
25  *                 Campbell Barton
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  *
29  */
30
31 /** \file blender/modifiers/intern/MOD_screw.c
32  *  \ingroup modifiers
33  */
34
35
36 /* Screw modifier: revolves the edges about an axis */
37 #include <limits.h>
38
39 #include "DNA_mesh_types.h"
40 #include "DNA_meshdata_types.h"
41 #include "DNA_object_types.h"
42
43 #include "BLI_math.h"
44 #include "BLI_alloca.h"
45 #include "BLI_utildefines.h"
46
47 #include "BKE_library.h"
48 #include "BKE_library_query.h"
49 #include "BKE_mesh.h"
50
51 #include "DEG_depsgraph_build.h"
52
53 #include "MOD_modifiertypes.h"
54 #include "MEM_guardedalloc.h"
55
56 #include "BLI_strict_flags.h"
57
58 /* used for gathering edge connectivity */
59 typedef struct ScrewVertConnect {
60         float dist;  /* distance from the center axis */
61         float co[3]; /* loaction relative to the transformed axis */
62         float no[3]; /* calc normal of the vertex */
63         unsigned int v[2]; /* 2  verts on either side of this one */
64         MEdge *e[2]; /* edges on either side, a bit of a waste since each edge ref's 2 edges */
65         char flag;
66 } ScrewVertConnect;
67
68 typedef struct ScrewVertIter {
69         ScrewVertConnect *v_array;
70         ScrewVertConnect *v_poin;
71         unsigned int v, v_other;
72         MEdge *e;
73 } ScrewVertIter;
74
75 #define SV_UNUSED (UINT_MAX)
76 #define SV_INVALID ((UINT_MAX) - 1)
77 #define SV_IS_VALID(v) ((v) < SV_INVALID)
78
79 static void screwvert_iter_init(ScrewVertIter *iter, ScrewVertConnect *array, unsigned int v_init, unsigned int dir)
80 {
81         iter->v_array = array;
82         iter->v = v_init;
83
84         if (SV_IS_VALID(v_init)) {
85                 iter->v_poin = &array[v_init];
86                 iter->v_other = iter->v_poin->v[dir];
87                 iter->e = iter->v_poin->e[!dir];
88         }
89         else {
90                 iter->v_poin = NULL;
91                 iter->e = NULL;
92         }
93 }       
94
95
96 static void screwvert_iter_step(ScrewVertIter *iter)
97 {
98         if (iter->v_poin->v[0] == iter->v_other) {
99                 iter->v_other = iter->v;
100                 iter->v = iter->v_poin->v[1];
101         }
102         else if (iter->v_poin->v[1] == iter->v_other) {
103                 iter->v_other = iter->v;
104                 iter->v = iter->v_poin->v[0];
105         }
106         if (SV_IS_VALID(iter->v)) {
107                 iter->v_poin = &iter->v_array[iter->v];
108                 iter->e = iter->v_poin->e[(iter->v_poin->e[0] == iter->e)];
109         }
110         else {
111                 iter->e = NULL;
112                 iter->v_poin = NULL;
113         }
114 }
115
116 static Mesh *mesh_remove_doubles_on_axis(
117         Mesh *result, MVert *mvert_new, const uint totvert, const uint step_tot,
118         const float axis_vec[3], const float axis_offset[3], const float merge_threshold)
119 {
120         const float merge_threshold_sq = SQUARE(merge_threshold);
121         const bool use_offset = axis_offset != NULL;
122         uint tot_doubles = 0;
123         for (uint i = 0; i < totvert; i += 1) {
124                 float axis_co[3];
125                 if (use_offset) {
126                         float offset_co[3];
127                         sub_v3_v3v3(offset_co, mvert_new[i].co, axis_offset);
128                         project_v3_v3v3_normalized(axis_co, offset_co, axis_vec);
129                         add_v3_v3(axis_co, axis_offset);
130                 }
131                 else {
132                         project_v3_v3v3_normalized(axis_co, mvert_new[i].co, axis_vec);
133                 }
134                 const float dist_sq = len_squared_v3v3(axis_co, mvert_new[i].co);
135                 if (dist_sq <= merge_threshold_sq) {
136                         mvert_new[i].flag |= ME_VERT_TMP_TAG;
137                         tot_doubles += 1;
138                         copy_v3_v3(mvert_new[i].co, axis_co);
139                 }
140         }
141
142         if (tot_doubles != 0) {
143                 uint tot = totvert * step_tot;
144                 int *full_doubles_map = MEM_malloc_arrayN(tot, sizeof(int), __func__);
145                 copy_vn_i(full_doubles_map, (int)tot, -1);
146
147                 uint tot_doubles_left = tot_doubles;
148                 for (uint i = 0; i < totvert; i += 1) {
149                         if (mvert_new[i].flag & ME_VERT_TMP_TAG) {
150                                 int *doubles_map = &full_doubles_map[totvert + i] ;
151                                 for (uint step = 1; step < step_tot; step += 1) {
152                                         *doubles_map = (int)i;
153                                         doubles_map += totvert;
154                                 }
155                                 tot_doubles_left -= 1;
156                                 if (tot_doubles_left == 0) {
157                                         break;
158                                 }
159                         }
160                 }
161                 result = BKE_mesh_merge_verts(result, full_doubles_map, (int)(tot_doubles * (step_tot - 1)), MESH_MERGE_VERTS_DUMP_IF_MAPPED);
162                 MEM_freeN(full_doubles_map);
163         }
164         return result;
165 }
166
167 static void initData(ModifierData *md)
168 {
169         ScrewModifierData *ltmd = (ScrewModifierData *) md;
170         ltmd->ob_axis = NULL;
171         ltmd->angle = (float)(M_PI * 2.0);
172         ltmd->axis = 2;
173         ltmd->flag = MOD_SCREW_SMOOTH_SHADING;
174         ltmd->steps = 16;
175         ltmd->render_steps = 16;
176         ltmd->iter = 1;
177         ltmd->merge_dist = 0.01f;
178 }
179
180 static Mesh *applyModifier(
181         ModifierData *md, const ModifierEvalContext *ctx,
182         Mesh *meshData)
183 {
184         Mesh *mesh = meshData;
185         Mesh *result;
186         ScrewModifierData *ltmd = (ScrewModifierData *) md;
187         const bool use_render_params = (ctx->flag & MOD_APPLY_RENDER) != 0;
188         
189         int *origindex;
190         int mpoly_index = 0;
191         unsigned int step;
192         unsigned int i, j;
193         unsigned int i1, i2;
194         unsigned int step_tot = use_render_params ? ltmd->render_steps : ltmd->steps;
195         const bool do_flip = (ltmd->flag & MOD_SCREW_NORMAL_FLIP) != 0;
196
197         const int quad_ord[4] = {
198             do_flip ? 3 : 0,
199             do_flip ? 2 : 1,
200             do_flip ? 1 : 2,
201             do_flip ? 0 : 3,
202         };
203         const int quad_ord_ofs[4] = {
204             do_flip ? 2 : 0,
205             1,
206             do_flip ? 0 : 2,
207             3,
208         };
209
210         unsigned int maxVerts = 0, maxEdges = 0, maxPolys = 0;
211         const unsigned int totvert = (unsigned int)mesh->totvert;
212         const unsigned int totedge = (unsigned int)mesh->totedge;
213         const unsigned int totpoly = (unsigned int)mesh->totpoly;
214
215         unsigned int *edge_poly_map = NULL;  /* orig edge to orig poly */
216         unsigned int *vert_loop_map = NULL;  /* orig vert to orig loop */
217
218         /* UV Coords */
219         const unsigned int mloopuv_layers_tot = (unsigned int)CustomData_number_of_layers(&mesh->ldata, CD_MLOOPUV);
220         MLoopUV **mloopuv_layers = BLI_array_alloca(mloopuv_layers, mloopuv_layers_tot);
221         float uv_u_scale;
222         float uv_v_minmax[2] = {FLT_MAX, -FLT_MAX};
223         float uv_v_range_inv;
224         float uv_axis_plane[4];
225
226         char axis_char = 'X';
227         bool close;
228         float angle = ltmd->angle;
229         float screw_ofs = ltmd->screw_ofs;
230         float axis_vec[3] = {0.0f, 0.0f, 0.0f};
231         float tmp_vec1[3], tmp_vec2[3]; 
232         float mat3[3][3];
233         float mtx_tx[4][4]; /* transform the coords by an object relative to this objects transformation */
234         float mtx_tx_inv[4][4]; /* inverted */
235         float mtx_tmp_a[4][4];
236         
237         unsigned int vc_tot_linked = 0;
238         short other_axis_1, other_axis_2;
239         const float *tmpf1, *tmpf2;
240
241         unsigned int edge_offset;
242         
243         MPoly *mpoly_orig, *mpoly_new, *mp_new;
244         MLoop *mloop_orig, *mloop_new, *ml_new;
245         MEdge *medge_orig, *med_orig, *med_new, *med_new_firstloop, *medge_new;
246         MVert *mvert_new, *mvert_orig, *mv_orig, *mv_new, *mv_new_base;
247
248         ScrewVertConnect *vc, *vc_tmp, *vert_connect = NULL;
249
250         const char mpoly_flag = (ltmd->flag & MOD_SCREW_SMOOTH_SHADING) ? ME_SMOOTH : 0;
251
252         /* don't do anything? */
253         if (!totvert)
254                 return BKE_mesh_new_nomain_from_template(mesh, 0, 0, 0, 0, 0);
255
256         switch (ltmd->axis) {
257                 case 0:
258                         other_axis_1 = 1;
259                         other_axis_2 = 2;
260                         break;
261                 case 1:
262                         other_axis_1 = 0;
263                         other_axis_2 = 2;
264                         break;
265                 default: /* 2, use default to quiet warnings */
266                         other_axis_1 = 0;
267                         other_axis_2 = 1;
268                         break;
269         }
270
271         axis_vec[ltmd->axis] = 1.0f;
272
273         if (ltmd->ob_axis) {
274                 /* calc the matrix relative to the axis object */
275                 invert_m4_m4(mtx_tmp_a, ctx->object->obmat);
276                 copy_m4_m4(mtx_tx_inv, ltmd->ob_axis->obmat);
277                 mul_m4_m4m4(mtx_tx, mtx_tmp_a, mtx_tx_inv);
278
279                 /* calc the axis vec */
280                 mul_mat3_m4_v3(mtx_tx, axis_vec); /* only rotation component */
281                 normalize_v3(axis_vec);
282
283                 /* screw */
284                 if (ltmd->flag & MOD_SCREW_OBJECT_OFFSET) {
285                         /* find the offset along this axis relative to this objects matrix */
286                         float totlen = len_v3(mtx_tx[3]);
287
288                         if (totlen != 0.0f) {
289                                 float zero[3] = {0.0f, 0.0f, 0.0f};
290                                 float cp[3];
291                                 screw_ofs = closest_to_line_v3(cp, mtx_tx[3], zero, axis_vec);
292                         }
293                         else {
294                                 screw_ofs = 0.0f;
295                         }
296                 }
297
298                 /* angle */
299
300 #if 0   /* cant incluide this, not predictable enough, though quite fun. */
301                 if (ltmd->flag & MOD_SCREW_OBJECT_ANGLE) {
302                         float mtx3_tx[3][3];
303                         copy_m3_m4(mtx3_tx, mtx_tx);
304
305                         float vec[3] = {0, 1, 0};
306                         float cross1[3];
307                         float cross2[3];
308                         cross_v3_v3v3(cross1, vec, axis_vec);
309
310                         mul_v3_m3v3(cross2, mtx3_tx, cross1);
311                         {
312                                 float c1[3];
313                                 float c2[3];
314                                 float axis_tmp[3];
315
316                                 cross_v3_v3v3(c1, cross2, axis_vec);
317                                 cross_v3_v3v3(c2, axis_vec, c1);
318
319
320                                 angle = angle_v3v3(cross1, c2);
321
322                                 cross_v3_v3v3(axis_tmp, cross1, c2);
323                                 normalize_v3(axis_tmp);
324
325                                 if (len_v3v3(axis_tmp, axis_vec) > 1.0f)
326                                         angle = -angle;
327
328                         }
329                 }
330 #endif
331         }
332         else {
333                 /* exis char is used by i_rotate*/
334                 axis_char = (char)(axis_char + ltmd->axis); /* 'X' + axis */
335
336                 /* useful to be able to use the axis vec in some cases still */
337                 zero_v3(axis_vec);
338                 axis_vec[ltmd->axis] = 1.0f;
339         }
340
341         /* apply the multiplier */
342         angle *= (float)ltmd->iter;
343         screw_ofs *= (float)ltmd->iter;
344         uv_u_scale = 1.0f / (float)(step_tot);
345
346         /* multiplying the steps is a bit tricky, this works best */
347         step_tot = ((step_tot + 1) * ltmd->iter) - (ltmd->iter - 1);
348
349         /* will the screw be closed?
350          * Note! smaller then FLT_EPSILON * 100 gives problems with float precision so its never closed. */
351         if (fabsf(screw_ofs) <= (FLT_EPSILON * 100.0f) &&
352             fabsf(fabsf(angle) - ((float)M_PI * 2.0f)) <= (FLT_EPSILON * 100.0f))
353         {
354                 close = 1;
355                 step_tot--;
356                 if (step_tot < 3) step_tot = 3;
357         
358                 maxVerts = totvert  * step_tot;   /* -1 because we're joining back up */
359                 maxEdges = (totvert * step_tot) + /* these are the edges between new verts */
360                            (totedge * step_tot);  /* -1 because vert edges join */
361                 maxPolys = totedge * step_tot;
362
363                 screw_ofs = 0.0f;
364         }
365         else {
366                 close = 0;
367                 if (step_tot < 3) step_tot = 3;
368
369                 maxVerts =  totvert  * step_tot; /* -1 because we're joining back up */
370                 maxEdges =  (totvert * (step_tot - 1)) + /* these are the edges between new verts */
371                            (totedge * step_tot);  /* -1 because vert edges join */
372                 maxPolys =  totedge * (step_tot - 1);
373         }
374
375         if ((ltmd->flag & MOD_SCREW_UV_STRETCH_U) == 0) {
376                 uv_u_scale = (uv_u_scale / (float)ltmd->iter) * (angle / ((float)M_PI * 2.0f));
377         }
378         
379         result = BKE_mesh_new_nomain_from_template(mesh, (int)maxVerts, (int)maxEdges, 0, (int)maxPolys * 4, (int)maxPolys);
380         
381         /* copy verts from mesh */
382         mvert_orig =    mesh->mvert;
383         medge_orig =    mesh->medge;
384
385         mvert_new =     result->mvert;
386         mpoly_new =     result->mpoly;
387         mloop_new =     result->mloop;
388         medge_new =     result->medge;
389
390         if (!CustomData_has_layer(&result->pdata, CD_ORIGINDEX)) {
391                 CustomData_add_layer(&result->pdata, CD_ORIGINDEX, CD_CALLOC, NULL, (int)maxPolys);
392         }
393
394         origindex = CustomData_get_layer(&result->pdata, CD_ORIGINDEX);
395
396         CustomData_copy_data(&mesh->vdata, &result->vdata, 0, 0, (int)totvert);
397
398         if (mloopuv_layers_tot) {
399                 float zero_co[3] = {0};
400                 plane_from_point_normal_v3(uv_axis_plane, zero_co, axis_vec);
401         }
402
403         if (mloopuv_layers_tot) {
404                 unsigned int uv_lay;
405                 for (uv_lay = 0; uv_lay < mloopuv_layers_tot; uv_lay++) {
406                         mloopuv_layers[uv_lay] = CustomData_get_layer_n(&result->ldata, CD_MLOOPUV, (int)uv_lay);
407                 }
408
409                 if (ltmd->flag & MOD_SCREW_UV_STRETCH_V) {
410                         for (i = 0, mv_orig = mvert_orig; i < totvert; i++, mv_orig++) {
411                                 const float v = dist_signed_squared_to_plane_v3(mv_orig->co, uv_axis_plane);
412                                 uv_v_minmax[0] = min_ff(v, uv_v_minmax[0]);
413                                 uv_v_minmax[1] = max_ff(v, uv_v_minmax[1]);
414                         }
415                         uv_v_minmax[0] = sqrtf_signed(uv_v_minmax[0]);
416                         uv_v_minmax[1] = sqrtf_signed(uv_v_minmax[1]);
417                 }
418
419                 uv_v_range_inv = uv_v_minmax[1] - uv_v_minmax[0];
420                 uv_v_range_inv = uv_v_range_inv ? 1.0f / uv_v_range_inv : 0.0f;
421         }
422
423         /* Set the locations of the first set of verts */
424         
425         mv_new = mvert_new;
426         mv_orig = mvert_orig;
427         
428         /* Copy the first set of edges */
429         med_orig = medge_orig;
430         med_new = medge_new;
431         for (i = 0; i < totedge; i++, med_orig++, med_new++) {
432                 med_new->v1 = med_orig->v1;
433                 med_new->v2 = med_orig->v2;
434                 med_new->crease = med_orig->crease;
435                 med_new->flag = med_orig->flag &  ~ME_LOOSEEDGE;
436         }
437         
438         /* build polygon -> edge map */
439         if (totpoly) {
440                 MPoly *mp_orig;
441
442                 mpoly_orig = mesh->mpoly;
443                 mloop_orig = mesh->mloop;
444                 edge_poly_map = MEM_malloc_arrayN(totedge, sizeof(*edge_poly_map), __func__);
445                 memset(edge_poly_map, 0xff, sizeof(*edge_poly_map) * totedge);
446
447                 vert_loop_map = MEM_malloc_arrayN(totvert, sizeof(*vert_loop_map), __func__);
448                 memset(vert_loop_map, 0xff, sizeof(*vert_loop_map) * totvert);
449
450                 for (i = 0, mp_orig = mpoly_orig; i < totpoly; i++, mp_orig++) {
451                         unsigned int loopstart = (unsigned int)mp_orig->loopstart;
452                         unsigned int loopend = loopstart + (unsigned int)mp_orig->totloop;
453
454                         MLoop *ml_orig = &mloop_orig[loopstart];
455                         unsigned int k;
456                         for (k = loopstart; k < loopend; k++, ml_orig++) {
457                                 edge_poly_map[ml_orig->e] = i;
458                                 vert_loop_map[ml_orig->v] = k;
459
460                                 /* also order edges based on faces */
461                                 if (medge_new[ml_orig->e].v1 != ml_orig->v) {
462                                         SWAP(unsigned int, medge_new[ml_orig->e].v1, medge_new[ml_orig->e].v2);
463                                 }
464                         }
465                 }
466         }
467
468         if (ltmd->flag & MOD_SCREW_NORMAL_CALC) {
469                 /*
470                  * Normal Calculation (for face flipping)
471                  * Sort edge verts for correct face flipping
472                  * NOT REALLY NEEDED but face flipping is nice.
473                  *
474                  * */
475
476
477                 /* Notice!
478                  *
479                  * Since we are only ordering the edges here it can avoid mallocing the
480                  * extra space by abusing the vert array before its filled with new verts.
481                  * The new array for vert_connect must be at least sizeof(ScrewVertConnect) * totvert
482                  * and the size of our resulting meshes array is sizeof(MVert) * totvert * 3
483                  * so its safe to use the second 2 thrids of MVert the array for vert_connect,
484                  * just make sure ScrewVertConnect struct is no more than twice as big as MVert,
485                  * at the moment there is no chance of that being a problem,
486                  * unless MVert becomes half its current size.
487                  *
488                  * once the edges are ordered, vert_connect is not needed and it can be used for verts
489                  *
490                  * This makes the modifier faster with one less alloc.
491                  */
492
493                 vert_connect = MEM_malloc_arrayN(totvert, sizeof(ScrewVertConnect), "ScrewVertConnect");
494                 //vert_connect = (ScrewVertConnect *) &medge_new[totvert];  /* skip the first slice of verts */
495                 vc = vert_connect;
496
497                 /* Copy Vert Locations */
498                 /* - We can do this in a later loop - only do here if no normal calc */
499                 if (!totedge) {
500                         for (i = 0; i < totvert; i++, mv_orig++, mv_new++) {
501                                 copy_v3_v3(mv_new->co, mv_orig->co);
502                                 normalize_v3_v3(vc->no, mv_new->co); /* no edges- this is really a dummy normal */
503                         }
504                 }
505                 else {
506                         /*printf("\n\n\n\n\nStarting Modifier\n");*/
507                         /* set edge users */
508                         med_new = medge_new;
509                         mv_new = mvert_new;
510
511                         if (ltmd->ob_axis) {
512                                 /*mtx_tx is initialized early on */
513                                 for (i = 0; i < totvert; i++, mv_new++, mv_orig++, vc++) {
514                                         vc->co[0] = mv_new->co[0] = mv_orig->co[0];
515                                         vc->co[1] = mv_new->co[1] = mv_orig->co[1];
516                                         vc->co[2] = mv_new->co[2] = mv_orig->co[2];
517
518                                         vc->flag = 0;
519                                         vc->e[0] = vc->e[1] = NULL;
520                                         vc->v[0] = vc->v[1] = SV_UNUSED;
521
522                                         mul_m4_v3(mtx_tx, vc->co);
523                                         /* length in 2d, don't sqrt because this is only for comparison */
524                                         vc->dist = vc->co[other_axis_1] * vc->co[other_axis_1] +
525                                                    vc->co[other_axis_2] * vc->co[other_axis_2];
526
527                                         /* printf("location %f %f %f -- %f\n", vc->co[0], vc->co[1], vc->co[2], vc->dist);*/
528                                 }
529                         }
530                         else {
531                                 for (i = 0; i < totvert; i++, mv_new++, mv_orig++, vc++) {
532                                         vc->co[0] = mv_new->co[0] = mv_orig->co[0];
533                                         vc->co[1] = mv_new->co[1] = mv_orig->co[1];
534                                         vc->co[2] = mv_new->co[2] = mv_orig->co[2];
535
536                                         vc->flag = 0;
537                                         vc->e[0] = vc->e[1] = NULL;
538                                         vc->v[0] = vc->v[1] = SV_UNUSED;
539
540                                         /* length in 2d, don't sqrt because this is only for comparison */
541                                         vc->dist = vc->co[other_axis_1] * vc->co[other_axis_1] +
542                                                    vc->co[other_axis_2] * vc->co[other_axis_2];
543
544                                         /* printf("location %f %f %f -- %f\n", vc->co[0], vc->co[1], vc->co[2], vc->dist);*/
545                                 }
546                         }
547
548                         /* this loop builds connectivity info for verts */
549                         for (i = 0; i < totedge; i++, med_new++) {
550                                 vc = &vert_connect[med_new->v1];
551
552                                 if (vc->v[0] == SV_UNUSED) { /* unused */
553                                         vc->v[0] = med_new->v2;
554                                         vc->e[0] = med_new;
555                                 }
556                                 else if (vc->v[1] == SV_UNUSED) {
557                                         vc->v[1] = med_new->v2;
558                                         vc->e[1] = med_new;
559                                 }
560                                 else {
561                                         vc->v[0] = vc->v[1] = SV_INVALID; /* error value  - don't use, 3 edges on vert */
562                                 }
563
564                                 vc = &vert_connect[med_new->v2];
565
566                                 /* same as above but swap v1/2 */
567                                 if (vc->v[0] == SV_UNUSED) { /* unused */
568                                         vc->v[0] = med_new->v1;
569                                         vc->e[0] = med_new;
570                                 }
571                                 else if (vc->v[1] == SV_UNUSED) {
572                                         vc->v[1] = med_new->v1;
573                                         vc->e[1] = med_new;
574                                 }
575                                 else {
576                                         vc->v[0] = vc->v[1] = SV_INVALID; /* error value  - don't use, 3 edges on vert */
577                                 }
578                         }
579
580                         /* find the first vert */
581                         vc = vert_connect;
582                         for (i = 0; i < totvert; i++, vc++) {
583                                 /* Now do search for connected verts, order all edges and flip them
584                                  * so resulting faces are flipped the right way */
585                                 vc_tot_linked = 0; /* count the number of linked verts for this loop */
586                                 if (vc->flag == 0) {
587                                         unsigned int v_best = SV_UNUSED, ed_loop_closed = 0; /* vert and vert new */
588                                         ScrewVertIter lt_iter;
589                                         float fl = -1.0f;
590
591                                         /* compiler complains if not initialized, but it should be initialized below */
592                                         bool ed_loop_flip = false;
593
594                                         /*printf("Loop on connected vert: %i\n", i);*/
595
596                                         for (j = 0; j < 2; j++) {
597                                                 /*printf("\tSide: %i\n", j);*/
598                                                 screwvert_iter_init(&lt_iter, vert_connect, i, j);
599                                                 if (j == 1) {
600                                                         screwvert_iter_step(&lt_iter);
601                                                 }
602                                                 while (lt_iter.v_poin) {
603                                                         /*printf("\t\tVERT: %i\n", lt_iter.v);*/
604                                                         if (lt_iter.v_poin->flag) {
605                                                                 /*printf("\t\t\tBreaking Found end\n");*/
606                                                                 //endpoints[0] = endpoints[1] = SV_UNUSED;
607                                                                 ed_loop_closed = 1; /* circle */
608                                                                 break;
609                                                         }
610                                                         lt_iter.v_poin->flag = 1;
611                                                         vc_tot_linked++;
612                                                         /*printf("Testing 2 floats %f : %f\n", fl, lt_iter.v_poin->dist);*/
613                                                         if (fl <= lt_iter.v_poin->dist) {
614                                                                 fl = lt_iter.v_poin->dist;
615                                                                 v_best = lt_iter.v;
616                                                                 /*printf("\t\t\tVERT BEST: %i\n", v_best);*/
617                                                         }
618                                                         screwvert_iter_step(&lt_iter);
619                                                         if (!lt_iter.v_poin) {
620                                                                 /*printf("\t\t\tFound End Also Num %i\n", j);*/
621                                                                 /*endpoints[j] = lt_iter.v_other;*/ /* other is still valid */
622                                                                 break;
623                                                         }
624                                                 }
625                                         }
626
627                                         /* now we have a collection of used edges. flip their edges the right way*/
628                                         /*if (v_best != SV_UNUSED) - */
629
630                                         /*printf("Done Looking - vc_tot_linked: %i\n", vc_tot_linked);*/
631
632                                         if (vc_tot_linked > 1) {
633                                                 float vf_1, vf_2, vf_best;
634
635                                                 vc_tmp = &vert_connect[v_best];
636
637                                                 tmpf1 = vert_connect[vc_tmp->v[0]].co;
638                                                 tmpf2 = vert_connect[vc_tmp->v[1]].co;
639
640
641                                                 /* edge connects on each side! */
642                                                 if (SV_IS_VALID(vc_tmp->v[0]) && SV_IS_VALID(vc_tmp->v[1])) {
643                                                         /*printf("Verts on each side (%i %i)\n", vc_tmp->v[0], vc_tmp->v[1]);*/
644                                                         /* find out which is higher */
645
646                                                         vf_1 = tmpf1[ltmd->axis];
647                                                         vf_2 = tmpf2[ltmd->axis];
648                                                         vf_best = vc_tmp->co[ltmd->axis];
649
650                                                         if (vf_1 < vf_best && vf_best < vf_2) {
651                                                                 ed_loop_flip = 0;
652                                                         }
653                                                         else if (vf_1 > vf_best && vf_best > vf_2) {
654                                                                 ed_loop_flip = 1;
655                                                         }
656                                                         else {
657                                                                 /* not so simple to work out which edge is higher */
658                                                                 sub_v3_v3v3(tmp_vec1, tmpf1, vc_tmp->co);
659                                                                 sub_v3_v3v3(tmp_vec2, tmpf2, vc_tmp->co);
660                                                                 normalize_v3(tmp_vec1);
661                                                                 normalize_v3(tmp_vec2);
662
663                                                                 if (tmp_vec1[ltmd->axis] < tmp_vec2[ltmd->axis]) {
664                                                                         ed_loop_flip = 1;
665                                                                 }
666                                                                 else {
667                                                                         ed_loop_flip = 0;
668                                                                 }
669                                                         }
670                                                 }
671                                                 else if (SV_IS_VALID(vc_tmp->v[0])) { /*vertex only connected on 1 side */
672                                                         /*printf("Verts on ONE side (%i %i)\n", vc_tmp->v[0], vc_tmp->v[1]);*/
673                                                         if (tmpf1[ltmd->axis] < vc_tmp->co[ltmd->axis]) { /* best is above */
674                                                                 ed_loop_flip = 1;
675                                                         }
676                                                         else { /* best is below or even... in even case we cant know whet  to do. */
677                                                                 ed_loop_flip = 0;
678                                                         }
679
680                                                 }
681 #if 0
682                                                 else {
683                                                         printf("No Connected ___\n");
684                                                 }
685 #endif
686
687                                                 /*printf("flip direction %i\n", ed_loop_flip);*/
688
689
690                                                 /* switch the flip option if set
691                                                  * note: flip is now done at face level so copying vgroup slizes is easier */
692 #if 0
693                                                 if (do_flip)
694                                                         ed_loop_flip = !ed_loop_flip;
695 #endif
696
697                                                 if (angle < 0.0f)
698                                                         ed_loop_flip = !ed_loop_flip;
699
700                                                 /* if its closed, we only need 1 loop */
701                                                 for (j = ed_loop_closed; j < 2; j++) {
702                                                         /*printf("Ordering Side J %i\n", j);*/
703
704                                                         screwvert_iter_init(&lt_iter, vert_connect, v_best, j);
705                                                         /*printf("\n\nStarting - Loop\n");*/
706                                                         lt_iter.v_poin->flag = 1; /* so a non loop will traverse the other side */
707
708
709                                                         /* If this is the vert off the best vert and
710                                                          * the best vert has 2 edges connected too it
711                                                          * then swap the flip direction */
712                                                         if (j == 1 && SV_IS_VALID(vc_tmp->v[0]) && SV_IS_VALID(vc_tmp->v[1]))
713                                                                 ed_loop_flip = !ed_loop_flip;
714
715                                                         while (lt_iter.v_poin && lt_iter.v_poin->flag != 2) {
716                                                                 /*printf("\tOrdering Vert V %i\n", lt_iter.v);*/
717
718                                                                 lt_iter.v_poin->flag = 2;
719                                                                 if (lt_iter.e) {
720                                                                         if (lt_iter.v == lt_iter.e->v1) {
721                                                                                 if (ed_loop_flip == 0) {
722                                                                                         /*printf("\t\t\tFlipping 0\n");*/
723                                                                                         SWAP(unsigned int, lt_iter.e->v1, lt_iter.e->v2);
724                                                                                 }
725                                                                                 /* else {
726                                                                                     printf("\t\t\tFlipping Not 0\n");
727                                                                                    }*/
728                                                                         }
729                                                                         else if (lt_iter.v == lt_iter.e->v2) {
730                                                                                 if (ed_loop_flip == 1) {
731                                                                                         /*printf("\t\t\tFlipping 1\n");*/
732                                                                                         SWAP(unsigned int, lt_iter.e->v1, lt_iter.e->v2);
733                                                                                 }
734                                                                                 /* else {
735                                                                                     printf("\t\t\tFlipping Not 1\n");
736                                                                                    }*/
737                                                                         }
738                                                                         /* else {
739                                                                             printf("\t\tIncorrect edge topology");
740                                                                            }*/
741                                                                 }
742                                                                 /* else {
743                                                                     printf("\t\tNo Edge at this point\n");
744                                                                    }*/
745                                                                 screwvert_iter_step(&lt_iter);
746                                                         }
747                                                 }
748                                         }
749                                 }
750
751                                 /* *VERTEX NORMALS*
752                                  * we know the surrounding edges are ordered correctly now
753                                  * so its safe to create vertex normals.
754                                  *
755                                  * calculate vertex normals that can be propagated on lathing
756                                  * use edge connectivity work this out */
757                                 if (SV_IS_VALID(vc->v[0])) {
758                                         if (SV_IS_VALID(vc->v[1])) {
759                                                 /* 2 edges connedted */
760                                                 /* make 2 connecting vert locations relative to the middle vert */
761                                                 sub_v3_v3v3(tmp_vec1, mvert_new[vc->v[0]].co, mvert_new[i].co);
762                                                 sub_v3_v3v3(tmp_vec2, mvert_new[vc->v[1]].co, mvert_new[i].co);
763                                                 /* normalize so both edges have the same influence, no matter their length */
764                                                 normalize_v3(tmp_vec1);
765                                                 normalize_v3(tmp_vec2);
766
767                                                 /* vc_no_tmp1 - this line is the average direction of both connecting edges
768                                                  *
769                                                  * Use the edge order to make the subtraction, flip the normal the right way
770                                                  * edge should be there but check just in case... */
771                                                 if (vc->e[0]->v1 == i) {
772                                                         sub_v3_v3(tmp_vec1, tmp_vec2);
773                                                 }
774                                                 else {
775                                                         sub_v3_v3v3(tmp_vec1, tmp_vec2, tmp_vec1);
776                                                 }
777                                         }
778                                         else {
779                                                 /* only 1 edge connected - same as above except
780                                                  * don't need to average edge direction */
781                                                 if (vc->e[0]->v2 == i) {
782                                                         sub_v3_v3v3(tmp_vec1, mvert_new[i].co, mvert_new[vc->v[0]].co);
783                                                 }
784                                                 else {
785                                                         sub_v3_v3v3(tmp_vec1, mvert_new[vc->v[0]].co, mvert_new[i].co);
786                                                 }
787                                         }
788
789                                         /* tmp_vec2 - is a line 90d from the pivot to the vec
790                                          * This is used so the resulting normal points directly away from the middle */
791                                         cross_v3_v3v3(tmp_vec2, axis_vec, vc->co);
792
793                                         if (UNLIKELY(is_zero_v3(tmp_vec2))) {
794                                                 /* we're _on_ the axis, so copy it based on our winding */
795                                                 if (vc->e[0]->v2 == i) {
796                                                         negate_v3_v3(vc->no, axis_vec);
797                                                 }
798                                                 else {
799                                                         copy_v3_v3(vc->no, axis_vec);
800                                                 }
801                                         }
802                                         else {
803                                                 /* edge average vector and right angle to the pivot make the normal */
804                                                 cross_v3_v3v3(vc->no, tmp_vec1, tmp_vec2);
805                                         }
806
807                                 }
808                                 else {
809                                         copy_v3_v3(vc->no, vc->co);
810                                 }
811
812                                 /* we wont be looping on this data again so copy normals here */
813                                 if ((angle < 0.0f) != do_flip)
814                                         negate_v3(vc->no);
815
816                                 normalize_v3(vc->no);
817                                 normal_float_to_short_v3(mvert_new[i].no, vc->no);
818
819                                 /* Done with normals */
820                         }
821                 }
822         }
823         else {
824                 mv_orig = mvert_orig;
825                 mv_new = mvert_new;
826
827                 for (i = 0; i < totvert; i++, mv_new++, mv_orig++) {
828                         copy_v3_v3(mv_new->co, mv_orig->co);
829                 }
830         }
831         /* done with edge connectivity based normal flipping */
832         
833         /* Add Faces */
834         for (step = 1; step < step_tot; step++) {
835                 const unsigned int varray_stride = totvert * step;
836                 float step_angle;
837                 float nor_tx[3];
838                 float mat[4][4];
839                 /* Rotation Matrix */
840                 step_angle = (angle / (float)(step_tot - (!close))) * (float)step;
841
842                 if (ltmd->ob_axis) {
843                         axis_angle_normalized_to_mat3(mat3, axis_vec, step_angle);
844                 }
845                 else {
846                         axis_angle_to_mat3_single(mat3, axis_char, step_angle);
847                 }
848                 copy_m4_m3(mat, mat3);
849
850                 if (screw_ofs)
851                         madd_v3_v3fl(mat[3], axis_vec, screw_ofs * ((float)step / (float)(step_tot - 1)));
852
853                 /* copy a slice */
854                 CustomData_copy_data(&mesh->vdata, &result->vdata, 0, (int)varray_stride, (int)totvert);
855
856                 mv_new_base = mvert_new;
857                 mv_new = &mvert_new[varray_stride]; /* advance to the next slice */
858                 
859                 for (j = 0; j < totvert; j++, mv_new_base++, mv_new++) {
860                         /* set normal */
861                         if (vert_connect) {
862                                 mul_v3_m3v3(nor_tx, mat3, vert_connect[j].no);
863
864                                 /* set the normal now its transformed */
865                                 normal_float_to_short_v3(mv_new->no, nor_tx);
866                         }
867                         
868                         /* set location */
869                         copy_v3_v3(mv_new->co, mv_new_base->co);
870                         
871                         /* only need to set these if using non cleared memory */
872                         /*mv_new->mat_nr = mv_new->flag = 0;*/
873                                 
874                         if (ltmd->ob_axis) {
875                                 sub_v3_v3(mv_new->co, mtx_tx[3]);
876
877                                 mul_m4_v3(mat, mv_new->co);
878
879                                 add_v3_v3(mv_new->co, mtx_tx[3]);
880                         }
881                         else {
882                                 mul_m4_v3(mat, mv_new->co);
883                         }
884                         
885                         /* add the new edge */
886                         med_new->v1 = varray_stride + j;
887                         med_new->v2 = med_new->v1 - totvert;
888                         med_new->flag = ME_EDGEDRAW | ME_EDGERENDER;
889                         med_new++;
890                 }
891         }
892
893         /* we can avoid if using vert alloc trick */
894         if (vert_connect) {
895                 MEM_freeN(vert_connect);
896                 vert_connect = NULL;
897         }
898
899         if (close) {
900                 /* last loop of edges, previous loop dosnt account for the last set of edges */
901                 const unsigned int varray_stride = (step_tot - 1) * totvert;
902
903                 for (i = 0; i < totvert; i++) {
904                         med_new->v1 = i;
905                         med_new->v2 = varray_stride + i;
906                         med_new->flag = ME_EDGEDRAW | ME_EDGERENDER;
907                         med_new++;
908                 }
909         }
910         
911         mp_new = mpoly_new;
912         ml_new = mloop_new;
913         med_new_firstloop = medge_new;
914         
915         /* more of an offset in this case */
916         edge_offset = totedge + (totvert * (step_tot - (close ? 0 : 1)));
917
918         for (i = 0; i < totedge; i++, med_new_firstloop++) {
919                 const unsigned int step_last = step_tot - (close ? 1 : 2);
920                 const unsigned int mpoly_index_orig = totpoly ? edge_poly_map[i] : UINT_MAX;
921                 const bool has_mpoly_orig = (mpoly_index_orig != UINT_MAX);
922                 float uv_v_offset_a, uv_v_offset_b;
923
924                 const unsigned int mloop_index_orig[2] = {
925                     vert_loop_map ? vert_loop_map[medge_new[i].v1] : UINT_MAX,
926                     vert_loop_map ? vert_loop_map[medge_new[i].v2] : UINT_MAX,
927                 };
928                 const bool has_mloop_orig = mloop_index_orig[0] != UINT_MAX;
929
930                 short mat_nr;
931
932                 /* for each edge, make a cylinder of quads */
933                 i1 = med_new_firstloop->v1;
934                 i2 = med_new_firstloop->v2;
935
936                 if (has_mpoly_orig) {
937                         mat_nr = mpoly_orig[mpoly_index_orig].mat_nr;
938                 }
939                 else {
940                         mat_nr = 0;
941                 }
942
943                 if (has_mloop_orig == false && mloopuv_layers_tot) {
944                         uv_v_offset_a = dist_signed_to_plane_v3(mvert_new[medge_new[i].v1].co, uv_axis_plane);
945                         uv_v_offset_b = dist_signed_to_plane_v3(mvert_new[medge_new[i].v2].co, uv_axis_plane);
946
947                         if (ltmd->flag & MOD_SCREW_UV_STRETCH_V) {
948                                 uv_v_offset_a = (uv_v_offset_a - uv_v_minmax[0]) * uv_v_range_inv;
949                                 uv_v_offset_b = (uv_v_offset_b - uv_v_minmax[0]) * uv_v_range_inv;
950                         }
951                 }
952
953                 for (step = 0; step <= step_last; step++) {
954
955                         /* Polygon */
956                         if (has_mpoly_orig) {
957                                 CustomData_copy_data(&mesh->pdata, &result->pdata, (int)mpoly_index_orig, (int)mpoly_index, 1);
958                                 origindex[mpoly_index] = (int)mpoly_index_orig;
959                         }
960                         else {
961                                 origindex[mpoly_index] = ORIGINDEX_NONE;
962                                 mp_new->flag = mpoly_flag;
963                                 mp_new->mat_nr = mat_nr;
964                         }
965                         mp_new->loopstart = mpoly_index * 4;
966                         mp_new->totloop = 4;
967
968
969                         /* Loop-Custom-Data */
970                         if (has_mloop_orig) {
971                                 int l_index = (int)(ml_new - mloop_new);
972
973                                 CustomData_copy_data(&mesh->ldata, &result->ldata, (int)mloop_index_orig[0], l_index + 0, 1);
974                                 CustomData_copy_data(&mesh->ldata, &result->ldata, (int)mloop_index_orig[1], l_index + 1, 1);
975                                 CustomData_copy_data(&mesh->ldata, &result->ldata, (int)mloop_index_orig[1], l_index + 2, 1);
976                                 CustomData_copy_data(&mesh->ldata, &result->ldata, (int)mloop_index_orig[0], l_index + 3, 1);
977
978                                 if (mloopuv_layers_tot) {
979                                         unsigned int uv_lay;
980                                         const float uv_u_offset_a = (float)(step)     * uv_u_scale;
981                                         const float uv_u_offset_b = (float)(step + 1) * uv_u_scale;
982                                         for (uv_lay = 0; uv_lay < mloopuv_layers_tot; uv_lay++) {
983                                                 MLoopUV *mluv = &mloopuv_layers[uv_lay][l_index];
984
985                                                 mluv[quad_ord[0]].uv[0] += uv_u_offset_a;
986                                                 mluv[quad_ord[1]].uv[0] += uv_u_offset_a;
987                                                 mluv[quad_ord[2]].uv[0] += uv_u_offset_b;
988                                                 mluv[quad_ord[3]].uv[0] += uv_u_offset_b;
989                                         }
990                                 }
991                         }
992                         else {
993                                 if (mloopuv_layers_tot) {
994                                         int l_index = (int)(ml_new - mloop_new);
995
996                                         unsigned int uv_lay;
997                                         const float uv_u_offset_a = (float)(step)     * uv_u_scale;
998                                         const float uv_u_offset_b = (float)(step + 1) * uv_u_scale;
999                                         for (uv_lay = 0; uv_lay < mloopuv_layers_tot; uv_lay++) {
1000                                                 MLoopUV *mluv = &mloopuv_layers[uv_lay][l_index];
1001
1002                                                 copy_v2_fl2(mluv[quad_ord[0]].uv, uv_u_offset_a, uv_v_offset_a);
1003                                                 copy_v2_fl2(mluv[quad_ord[1]].uv, uv_u_offset_a, uv_v_offset_b);
1004                                                 copy_v2_fl2(mluv[quad_ord[2]].uv, uv_u_offset_b, uv_v_offset_b);
1005                                                 copy_v2_fl2(mluv[quad_ord[3]].uv, uv_u_offset_b, uv_v_offset_a);
1006                                         }
1007                                 }
1008                         }
1009
1010                         /* Loop-Data */
1011                         if (!(close && step == step_last)) {
1012                                 /* regular segments */
1013                                 ml_new[quad_ord[0]].v = i1;
1014                                 ml_new[quad_ord[1]].v = i2;
1015                                 ml_new[quad_ord[2]].v = i2 + totvert;
1016                                 ml_new[quad_ord[3]].v = i1 + totvert;
1017
1018                                 ml_new[quad_ord_ofs[0]].e = step == 0 ? i : (edge_offset + step + (i * (step_tot - 1))) - 1;
1019                                 ml_new[quad_ord_ofs[1]].e = totedge + i2;
1020                                 ml_new[quad_ord_ofs[2]].e = edge_offset + step + (i * (step_tot - 1));
1021                                 ml_new[quad_ord_ofs[3]].e = totedge + i1;
1022
1023
1024                                 /* new vertical edge */
1025                                 if (step) { /* The first set is already done */
1026                                         med_new->v1 = i1;
1027                                         med_new->v2 = i2;
1028                                         med_new->flag = med_new_firstloop->flag;
1029                                         med_new->crease = med_new_firstloop->crease;
1030                                         med_new++;
1031                                 }
1032                                 i1 += totvert;
1033                                 i2 += totvert;
1034                         }
1035                         else {
1036                                 /* last segment */
1037                                 ml_new[quad_ord[0]].v = i1;
1038                                 ml_new[quad_ord[1]].v = i2;
1039                                 ml_new[quad_ord[2]].v = med_new_firstloop->v2;
1040                                 ml_new[quad_ord[3]].v = med_new_firstloop->v1;
1041
1042                                 ml_new[quad_ord_ofs[0]].e = (edge_offset + step + (i * (step_tot - 1))) - 1;
1043                                 ml_new[quad_ord_ofs[1]].e = totedge + i2;
1044                                 ml_new[quad_ord_ofs[2]].e = i;
1045                                 ml_new[quad_ord_ofs[3]].e = totedge + i1;
1046                         }
1047
1048                         mp_new++;
1049                         ml_new += 4;
1050                         mpoly_index++;
1051                 }
1052                 
1053                 /* new vertical edge */
1054                 med_new->v1 = i1;
1055                 med_new->v2 = i2;
1056                 med_new->flag = med_new_firstloop->flag & ~ME_LOOSEEDGE;
1057                 med_new->crease = med_new_firstloop->crease;
1058                 med_new++;
1059         }
1060
1061         /* validate loop edges */
1062 #if 0
1063         {
1064                 unsigned i = 0;
1065                 printf("\n");
1066                 for (; i < maxPolys * 4; i += 4) {
1067                         unsigned int ii;
1068                         ml_new = mloop_new + i;
1069                         ii = findEd(medge_new, maxEdges, ml_new[0].v, ml_new[1].v);
1070                         printf("%d %d -- ", ii, ml_new[0].e);
1071                         ml_new[0].e = ii;
1072
1073                         ii = findEd(medge_new, maxEdges, ml_new[1].v, ml_new[2].v);
1074                         printf("%d %d -- ", ii, ml_new[1].e);
1075                         ml_new[1].e = ii;
1076
1077                         ii = findEd(medge_new, maxEdges, ml_new[2].v, ml_new[3].v);
1078                         printf("%d %d -- ", ii, ml_new[2].e);
1079                         ml_new[2].e = ii;
1080
1081                         ii = findEd(medge_new, maxEdges, ml_new[3].v, ml_new[0].v);
1082                         printf("%d %d\n", ii, ml_new[3].e);
1083                         ml_new[3].e = ii;
1084
1085                 }
1086         }
1087 #endif
1088
1089         if (edge_poly_map) {
1090                 MEM_freeN(edge_poly_map);
1091         }
1092
1093         if (vert_loop_map) {
1094                 MEM_freeN(vert_loop_map);
1095         }
1096
1097         if ((ltmd->flag & MOD_SCREW_MERGE) && (screw_ofs == 0.0f)) {
1098                 Mesh *result_prev = result;
1099                 result = mesh_remove_doubles_on_axis(
1100                         result, mvert_new, totvert, step_tot,
1101                         axis_vec, ltmd->ob_axis ? mtx_tx[3] : NULL, ltmd->merge_dist);
1102                 if (result != result_prev) {
1103                         result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
1104                 }
1105         }
1106
1107         if ((ltmd->flag & MOD_SCREW_NORMAL_CALC) == 0) {
1108                 result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
1109         }
1110
1111         return result;
1112 }
1113
1114 static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
1115 {
1116         ScrewModifierData *ltmd = (ScrewModifierData *)md;
1117         if (ltmd->ob_axis != NULL) {
1118                 DEG_add_object_relation(ctx->node, ltmd->ob_axis, DEG_OB_COMP_TRANSFORM, "Screw Modifier");
1119         }
1120 }
1121
1122 static void foreachObjectLink(
1123         ModifierData *md, Object *ob,
1124         ObjectWalkFunc walk, void *userData)
1125 {
1126         ScrewModifierData *ltmd = (ScrewModifierData *) md;
1127
1128         walk(userData, ob, &ltmd->ob_axis, IDWALK_CB_NOP);
1129 }
1130
1131 ModifierTypeInfo modifierType_Screw = {
1132         /* name */              "Screw",
1133         /* structName */        "ScrewModifierData",
1134         /* structSize */        sizeof(ScrewModifierData),
1135         /* type */              eModifierTypeType_Constructive,
1136
1137         /* flags */             eModifierTypeFlag_AcceptsMesh |
1138                                 eModifierTypeFlag_AcceptsCVs |
1139                                 eModifierTypeFlag_SupportsEditmode |
1140                                 eModifierTypeFlag_EnableInEditmode,
1141
1142         /* copyData */          modifier_copyData_generic,
1143
1144         /* deformVerts_DM */    NULL,
1145         /* deformMatrices_DM */ NULL,
1146         /* deformVertsEM_DM */  NULL,
1147         /* deformMatricesEM_DM*/NULL,
1148         /* applyModifier_DM */  NULL,
1149         /* applyModifierEM_DM */NULL,
1150
1151         /* deformVerts */       NULL,
1152         /* deformMatrices */    NULL,
1153         /* deformVertsEM */     NULL,
1154         /* deformMatricesEM */  NULL,
1155         /* applyModifier */     applyModifier,
1156         /* applyModifierEM */   NULL,
1157
1158         /* initData */          initData,
1159         /* requiredDataMask */  NULL,
1160         /* freeData */          NULL,
1161         /* isDisabled */        NULL,
1162         /* updateDepsgraph */   updateDepsgraph,
1163         /* dependsOnTime */     NULL,
1164         /* dependsOnNormals */  NULL,
1165         /* foreachObjectLink */ foreachObjectLink,
1166         /* foreachIDLink */     NULL,
1167         /* foreachTexLink */    NULL,
1168 };