Freestyle: New options for sorting to arrange the stacking order of lines.
[blender.git] / source / blender / blenkernel / intern / linestyle.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) 2010 Blender Foundation.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file blender/blenkernel/intern/linestyle.c
29  *  \ingroup bke
30  */
31
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <string.h>
35
36 #include "MEM_guardedalloc.h"
37
38 #include "DNA_object_types.h"
39 #include "DNA_material_types.h" /* for ramp blend */
40 #include "DNA_texture_types.h"
41
42 #include "BLI_blenlib.h"
43 #include "BLI_math.h"
44 #include "BLI_utildefines.h"
45
46 #include "BKE_global.h"
47 #include "BKE_library.h"
48 #include "BKE_linestyle.h"
49 #include "BKE_main.h"
50 #include "BKE_texture.h"
51 #include "BKE_colortools.h"
52 #include "BKE_animsys.h"
53
54 static const char *modifier_name[LS_MODIFIER_NUM] = {
55         NULL,
56         "Along Stroke",
57         "Distance from Camera",
58         "Distance from Object",
59         "Material",
60         "Sampling",
61         "Bezier Curve",
62         "Sinus Displacement",
63         "Spatial Noise",
64         "Perlin Noise 1D",
65         "Perlin Noise 2D",
66         "Backbone Stretcher",
67         "Tip Remover",
68         "Calligraphy",
69         "Polygonalization",
70         "Guiding Lines",
71         "Blueprint",
72         "2D Offset",
73         "2D Transform",
74 };
75
76 static void default_linestyle_settings(FreestyleLineStyle *linestyle)
77 {
78         linestyle->panel = LS_PANEL_STROKES;
79         linestyle->r = linestyle->g = linestyle->b = 0.0f;
80         linestyle->alpha = 1.0f;
81         linestyle->thickness = 3.0f;
82         linestyle->thickness_position = LS_THICKNESS_CENTER;
83         linestyle->thickness_ratio = 0.5f;
84         linestyle->flag = LS_SAME_OBJECT | LS_NO_SORTING;
85         linestyle->chaining = LS_CHAINING_PLAIN;
86         linestyle->rounds = 3;
87         linestyle->min_angle = DEG2RADF(0.0f);
88         linestyle->max_angle = DEG2RADF(0.0f);
89         linestyle->min_length = 0.0f;
90         linestyle->max_length = 10000.0f;
91         linestyle->split_length = 100;
92         linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA;
93         linestyle->integration_type = LS_INTEGRATION_MEAN;
94
95         BLI_listbase_clear(&linestyle->color_modifiers);
96         BLI_listbase_clear(&linestyle->alpha_modifiers);
97         BLI_listbase_clear(&linestyle->thickness_modifiers);
98         BLI_listbase_clear(&linestyle->geometry_modifiers);
99
100         BKE_add_linestyle_geometry_modifier(linestyle, LS_MODIFIER_SAMPLING);
101
102         linestyle->caps = LS_CAPS_BUTT;
103 }
104
105 FreestyleLineStyle *BKE_new_linestyle(const char *name, struct Main *main)
106 {
107         FreestyleLineStyle *linestyle;
108
109         if (!main)
110                 main = G.main;
111
112         linestyle = (FreestyleLineStyle *)BKE_libblock_alloc(main, ID_LS, name);
113
114         default_linestyle_settings(linestyle);
115
116         return linestyle;
117 }
118
119 void BKE_free_linestyle(FreestyleLineStyle *linestyle)
120 {
121         LineStyleModifier *m;
122
123         BKE_free_animdata(&linestyle->id);
124         while ((m = (LineStyleModifier *)linestyle->color_modifiers.first))
125                 BKE_remove_linestyle_color_modifier(linestyle, m);
126         while ((m = (LineStyleModifier *)linestyle->alpha_modifiers.first))
127                 BKE_remove_linestyle_alpha_modifier(linestyle, m);
128         while ((m = (LineStyleModifier *)linestyle->thickness_modifiers.first))
129                 BKE_remove_linestyle_thickness_modifier(linestyle, m);
130         while ((m = (LineStyleModifier *)linestyle->geometry_modifiers.first))
131                 BKE_remove_linestyle_geometry_modifier(linestyle, m);
132 }
133
134 FreestyleLineStyle *BKE_copy_linestyle(FreestyleLineStyle *linestyle)
135 {
136         FreestyleLineStyle *new_linestyle;
137         LineStyleModifier *m;
138
139         new_linestyle = BKE_new_linestyle(linestyle->id.name + 2, NULL);
140         BKE_free_linestyle(new_linestyle);
141
142         new_linestyle->r = linestyle->r;
143         new_linestyle->g = linestyle->g;
144         new_linestyle->b = linestyle->b;
145         new_linestyle->alpha = linestyle->alpha;
146         new_linestyle->thickness = linestyle->thickness;
147         new_linestyle->thickness_position = linestyle->thickness_position;
148         new_linestyle->thickness_ratio = linestyle->thickness_ratio;
149         new_linestyle->flag = linestyle->flag;
150         new_linestyle->caps = linestyle->caps;
151         new_linestyle->chaining = linestyle->chaining;
152         new_linestyle->rounds = linestyle->rounds;
153         new_linestyle->split_length = linestyle->split_length;
154         new_linestyle->min_angle = linestyle->min_angle;
155         new_linestyle->max_angle = linestyle->max_angle;
156         new_linestyle->min_length = linestyle->min_length;
157         new_linestyle->max_length = linestyle->max_length;
158         new_linestyle->split_dash1 = linestyle->split_dash1;
159         new_linestyle->split_gap1 = linestyle->split_gap1;
160         new_linestyle->split_dash2 = linestyle->split_dash2;
161         new_linestyle->split_gap2 = linestyle->split_gap2;
162         new_linestyle->split_dash3 = linestyle->split_dash3;
163         new_linestyle->split_gap3 = linestyle->split_gap3;
164         new_linestyle->dash1 = linestyle->dash1;
165         new_linestyle->gap1 = linestyle->gap1;
166         new_linestyle->dash2 = linestyle->dash2;
167         new_linestyle->gap2 = linestyle->gap2;
168         new_linestyle->dash3 = linestyle->dash3;
169         new_linestyle->gap3 = linestyle->gap3;
170         new_linestyle->panel = linestyle->panel;
171         for (m = (LineStyleModifier *)linestyle->color_modifiers.first; m; m = m->next)
172                 BKE_copy_linestyle_color_modifier(new_linestyle, m);
173         for (m = (LineStyleModifier *)linestyle->alpha_modifiers.first; m; m = m->next)
174                 BKE_copy_linestyle_alpha_modifier(new_linestyle, m);
175         for (m = (LineStyleModifier *)linestyle->thickness_modifiers.first; m; m = m->next)
176                 BKE_copy_linestyle_thickness_modifier(new_linestyle, m);
177         for (m = (LineStyleModifier *)linestyle->geometry_modifiers.first; m; m = m->next)
178                 BKE_copy_linestyle_geometry_modifier(new_linestyle, m);
179
180         return new_linestyle;
181 }
182
183 static LineStyleModifier *new_modifier(int type, size_t size)
184 {
185         LineStyleModifier *m;
186
187         m = (LineStyleModifier *)MEM_callocN(size, "line style modifier");
188         m->type = type;
189         BLI_strncpy(m->name, modifier_name[type], sizeof(m->name));
190         m->influence = 1.0f;
191         m->flags = LS_MODIFIER_ENABLED | LS_MODIFIER_EXPANDED;
192
193         return m;
194 }
195
196 static void add_to_modifier_list(ListBase *lb, LineStyleModifier *m)
197 {
198         BLI_addtail(lb, (void *)m);
199         BLI_uniquename(lb, m, modifier_name[m->type], '.', offsetof(LineStyleModifier, name), sizeof(m->name));
200 }
201
202 static LineStyleModifier *alloc_color_modifier(int type)
203 {
204         size_t size;
205
206         switch (type) {
207                 case LS_MODIFIER_ALONG_STROKE:
208                         size = sizeof(LineStyleColorModifier_AlongStroke);
209                         break;
210                 case LS_MODIFIER_DISTANCE_FROM_CAMERA:
211                         size = sizeof(LineStyleColorModifier_DistanceFromCamera);
212                         break;
213                 case LS_MODIFIER_DISTANCE_FROM_OBJECT:
214                         size = sizeof(LineStyleColorModifier_DistanceFromObject);
215                         break;
216                 case LS_MODIFIER_MATERIAL:
217                         size = sizeof(LineStyleColorModifier_Material);
218                         break;
219                 default:
220                         return NULL; /* unknown modifier type */
221         }
222
223         return new_modifier(type, size);
224 }
225
226 LineStyleModifier *BKE_add_linestyle_color_modifier(FreestyleLineStyle *linestyle, int type)
227 {
228         LineStyleModifier *m;
229
230         m = alloc_color_modifier(type);
231         m->blend = MA_RAMP_BLEND;
232
233         switch (type) {
234                 case LS_MODIFIER_ALONG_STROKE:
235                         ((LineStyleColorModifier_AlongStroke *)m)->color_ramp = add_colorband(1);
236                         break;
237                 case LS_MODIFIER_DISTANCE_FROM_CAMERA:
238                         ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp = add_colorband(1);
239                         ((LineStyleColorModifier_DistanceFromCamera *)m)->range_min = 0.0f;
240                         ((LineStyleColorModifier_DistanceFromCamera *)m)->range_max = 10000.0f;
241                         break;
242                 case LS_MODIFIER_DISTANCE_FROM_OBJECT:
243                         ((LineStyleColorModifier_DistanceFromObject *)m)->target = NULL;
244                         ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp = add_colorband(1);
245                         ((LineStyleColorModifier_DistanceFromObject *)m)->range_min = 0.0f;
246                         ((LineStyleColorModifier_DistanceFromObject *)m)->range_max = 10000.0f;
247                         break;
248                 case LS_MODIFIER_MATERIAL:
249                         ((LineStyleColorModifier_Material *)m)->color_ramp = add_colorband(1);
250                         ((LineStyleColorModifier_Material *)m)->mat_attr = LS_MODIFIER_MATERIAL_DIFF;
251                         break;
252                 default:
253                         return NULL; /* unknown modifier type */
254         }
255         add_to_modifier_list(&linestyle->color_modifiers, m);
256
257         return m;
258 }
259
260 LineStyleModifier *BKE_copy_linestyle_color_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m)
261 {
262         LineStyleModifier *new_m;
263
264         new_m = alloc_color_modifier(m->type);
265         new_m->influence = m->influence;
266         new_m->flags = m->flags;
267         new_m->blend = m->blend;
268
269         switch (m->type) {
270                 case LS_MODIFIER_ALONG_STROKE:
271                 {
272                         LineStyleColorModifier_AlongStroke *p = (LineStyleColorModifier_AlongStroke *)m;
273                         LineStyleColorModifier_AlongStroke *q = (LineStyleColorModifier_AlongStroke *)new_m;
274                         q->color_ramp = MEM_dupallocN(p->color_ramp);
275                         break;
276                 }
277                 case LS_MODIFIER_DISTANCE_FROM_CAMERA:
278                 {
279                         LineStyleColorModifier_DistanceFromCamera *p = (LineStyleColorModifier_DistanceFromCamera *)m;
280                         LineStyleColorModifier_DistanceFromCamera *q = (LineStyleColorModifier_DistanceFromCamera *)new_m;
281                         q->color_ramp = MEM_dupallocN(p->color_ramp);
282                         q->range_min = p->range_min;
283                         q->range_max = p->range_max;
284                         break;
285                 }
286                 case LS_MODIFIER_DISTANCE_FROM_OBJECT:
287                 {
288                         LineStyleColorModifier_DistanceFromObject *p = (LineStyleColorModifier_DistanceFromObject *)m;
289                         LineStyleColorModifier_DistanceFromObject *q = (LineStyleColorModifier_DistanceFromObject *)new_m;
290                         if (p->target)
291                                 p->target->id.us++;
292                         q->target = p->target;
293                         q->color_ramp = MEM_dupallocN(p->color_ramp);
294                         q->range_min = p->range_min;
295                         q->range_max = p->range_max;
296                         break;
297                 }
298                 case LS_MODIFIER_MATERIAL:
299                 {
300                         LineStyleColorModifier_Material *p = (LineStyleColorModifier_Material *)m;
301                         LineStyleColorModifier_Material *q = (LineStyleColorModifier_Material *)new_m;
302                         q->color_ramp = MEM_dupallocN(p->color_ramp);
303                         q->flags = p->flags;
304                         q->mat_attr = p->mat_attr;
305                         break;
306                 }
307                 default:
308                         return NULL; /* unknown modifier type */
309         }
310         add_to_modifier_list(&linestyle->color_modifiers, new_m);
311
312         return new_m;
313 }
314
315 void BKE_remove_linestyle_color_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m)
316 {
317         switch (m->type) {
318                 case LS_MODIFIER_ALONG_STROKE:
319                         MEM_freeN(((LineStyleColorModifier_AlongStroke *)m)->color_ramp);
320                         break;
321                 case LS_MODIFIER_DISTANCE_FROM_CAMERA:
322                         MEM_freeN(((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp);
323                         break;
324                 case LS_MODIFIER_DISTANCE_FROM_OBJECT:
325                         MEM_freeN(((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp);
326                         break;
327                 case LS_MODIFIER_MATERIAL:
328                         MEM_freeN(((LineStyleColorModifier_Material *)m)->color_ramp);
329                         break;
330         }
331         BLI_freelinkN(&linestyle->color_modifiers, m);
332 }
333
334 static LineStyleModifier *alloc_alpha_modifier(int type)
335 {
336         size_t size;
337
338         switch (type) {
339                 case LS_MODIFIER_ALONG_STROKE:
340                         size = sizeof(LineStyleAlphaModifier_AlongStroke);
341                         break;
342                 case LS_MODIFIER_DISTANCE_FROM_CAMERA:
343                         size = sizeof(LineStyleAlphaModifier_DistanceFromCamera);
344                         break;
345                 case LS_MODIFIER_DISTANCE_FROM_OBJECT:
346                         size = sizeof(LineStyleAlphaModifier_DistanceFromObject);
347                         break;
348                 case LS_MODIFIER_MATERIAL:
349                         size = sizeof(LineStyleAlphaModifier_Material);
350                         break;
351                 default:
352                         return NULL; /* unknown modifier type */
353         }
354         return new_modifier(type, size);
355 }
356
357 LineStyleModifier *BKE_add_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, int type)
358 {
359         LineStyleModifier *m;
360
361         m = alloc_alpha_modifier(type);
362         m->blend = LS_VALUE_BLEND;
363
364         switch (type) {
365                 case LS_MODIFIER_ALONG_STROKE:
366                 {
367                         LineStyleAlphaModifier_AlongStroke *p = (LineStyleAlphaModifier_AlongStroke *)m;
368                         p->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
369                         break;
370                 }
371                 case LS_MODIFIER_DISTANCE_FROM_CAMERA:
372                 {
373                         LineStyleAlphaModifier_DistanceFromCamera *p = (LineStyleAlphaModifier_DistanceFromCamera *)m;
374                         p->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
375                         p->range_min = 0.0f;
376                         p->range_max = 10000.0f;
377                         break;
378                 }
379                 case LS_MODIFIER_DISTANCE_FROM_OBJECT:
380                 {
381                         LineStyleAlphaModifier_DistanceFromObject *p = (LineStyleAlphaModifier_DistanceFromObject *)m;
382                         p->target = NULL;
383                         p->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
384                         p->range_min = 0.0f;
385                         p->range_max = 10000.0f;
386                         break;
387                 }
388                 case LS_MODIFIER_MATERIAL:
389                 {
390                         LineStyleAlphaModifier_Material *p = (LineStyleAlphaModifier_Material *)m;
391                         p->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
392                         p->mat_attr = LS_MODIFIER_MATERIAL_DIFF;
393                         break;
394                 }
395                 default:
396                         return NULL; /* unknown modifier type */
397         }
398         add_to_modifier_list(&linestyle->alpha_modifiers, m);
399
400         return m;
401 }
402
403 LineStyleModifier *BKE_copy_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m)
404 {
405         LineStyleModifier *new_m;
406
407         new_m = alloc_alpha_modifier(m->type);
408         new_m->influence = m->influence;
409         new_m->flags = m->flags;
410         new_m->blend = m->blend;
411
412         switch (m->type) {
413                 case LS_MODIFIER_ALONG_STROKE:
414                 {
415                         LineStyleAlphaModifier_AlongStroke *p = (LineStyleAlphaModifier_AlongStroke *)m;
416                         LineStyleAlphaModifier_AlongStroke *q = (LineStyleAlphaModifier_AlongStroke *)new_m;
417                         q->curve = curvemapping_copy(p->curve);
418                         q->flags = p->flags;
419                         break;
420                 }
421                 case LS_MODIFIER_DISTANCE_FROM_CAMERA:
422                 {
423                         LineStyleAlphaModifier_DistanceFromCamera *p = (LineStyleAlphaModifier_DistanceFromCamera *)m;
424                         LineStyleAlphaModifier_DistanceFromCamera *q = (LineStyleAlphaModifier_DistanceFromCamera *)new_m;
425                         q->curve = curvemapping_copy(p->curve);
426                         q->flags = p->flags;
427                         q->range_min = p->range_min;
428                         q->range_max = p->range_max;
429                         break;
430                 }
431                 case LS_MODIFIER_DISTANCE_FROM_OBJECT:
432                 {
433                         LineStyleAlphaModifier_DistanceFromObject *p = (LineStyleAlphaModifier_DistanceFromObject *)m;
434                         LineStyleAlphaModifier_DistanceFromObject *q = (LineStyleAlphaModifier_DistanceFromObject *)new_m;
435                         if (p->target)
436                                 p->target->id.us++;
437                         q->target = p->target;
438                         q->curve = curvemapping_copy(p->curve);
439                         q->flags = p->flags;
440                         q->range_min = p->range_min;
441                         q->range_max = p->range_max;
442                         break;
443                 }
444                 case LS_MODIFIER_MATERIAL:
445                 {
446                         LineStyleAlphaModifier_Material *p = (LineStyleAlphaModifier_Material *)m;
447                         LineStyleAlphaModifier_Material *q = (LineStyleAlphaModifier_Material *)new_m;
448                         q->curve = curvemapping_copy(p->curve);
449                         q->flags = p->flags;
450                         q->mat_attr = p->mat_attr;
451                         break;
452                 }
453                 default:
454                         return NULL; /* unknown modifier type */
455         }
456         add_to_modifier_list(&linestyle->alpha_modifiers, new_m);
457
458         return new_m;
459 }
460
461 void BKE_remove_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m)
462 {
463         switch (m->type) {
464                 case LS_MODIFIER_ALONG_STROKE:
465                         curvemapping_free(((LineStyleAlphaModifier_AlongStroke *)m)->curve);
466                         break;
467                 case LS_MODIFIER_DISTANCE_FROM_CAMERA:
468                         curvemapping_free(((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve);
469                         break;
470                 case LS_MODIFIER_DISTANCE_FROM_OBJECT:
471                         curvemapping_free(((LineStyleAlphaModifier_DistanceFromObject *)m)->curve);
472                         break;
473                 case LS_MODIFIER_MATERIAL:
474                         curvemapping_free(((LineStyleAlphaModifier_Material *)m)->curve);
475                         break;
476         }
477         BLI_freelinkN(&linestyle->alpha_modifiers, m);
478 }
479
480 static LineStyleModifier *alloc_thickness_modifier(int type)
481 {
482         size_t size;
483
484         switch (type) {
485                 case LS_MODIFIER_ALONG_STROKE:
486                         size = sizeof(LineStyleThicknessModifier_AlongStroke);
487                         break;
488                 case LS_MODIFIER_DISTANCE_FROM_CAMERA:
489                         size = sizeof(LineStyleThicknessModifier_DistanceFromCamera);
490                         break;
491                 case LS_MODIFIER_DISTANCE_FROM_OBJECT:
492                         size = sizeof(LineStyleThicknessModifier_DistanceFromObject);
493                         break;
494                 case LS_MODIFIER_MATERIAL:
495                         size = sizeof(LineStyleThicknessModifier_Material);
496                         break;
497                 case LS_MODIFIER_CALLIGRAPHY:
498                         size = sizeof(LineStyleThicknessModifier_Calligraphy);
499                         break;
500                 default:
501                         return NULL; /* unknown modifier type */
502         }
503
504         return new_modifier(type, size);
505 }
506
507 LineStyleModifier *BKE_add_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, int type)
508 {
509         LineStyleModifier *m;
510
511         m = alloc_thickness_modifier(type);
512         m->blend = LS_VALUE_BLEND;
513
514         switch (type) {
515                 case LS_MODIFIER_ALONG_STROKE:
516                 {
517                         LineStyleThicknessModifier_AlongStroke *p = (LineStyleThicknessModifier_AlongStroke *)m;
518                         p->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
519                         p->value_min = 0.0f;
520                         p->value_max = 1.0f;
521                         break;
522                 }
523                 case LS_MODIFIER_DISTANCE_FROM_CAMERA:
524                 {
525                         LineStyleThicknessModifier_DistanceFromCamera *p = (LineStyleThicknessModifier_DistanceFromCamera *)m;
526                         p->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
527                         p->range_min = 0.0f;
528                         p->range_max = 1000.0f;
529                         p->value_min = 0.0f;
530                         p->value_max = 1.0f;
531                         break;
532                 }
533                 case LS_MODIFIER_DISTANCE_FROM_OBJECT:
534                 {
535                         LineStyleThicknessModifier_DistanceFromObject *p = (LineStyleThicknessModifier_DistanceFromObject *)m;
536                         p->target = NULL;
537                         p->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
538                         p->range_min = 0.0f;
539                         p->range_max = 1000.0f;
540                         p->value_min = 0.0f;
541                         p->value_max = 1.0f;
542                         break;
543                 }
544                 case LS_MODIFIER_MATERIAL:
545                 {
546                         LineStyleThicknessModifier_Material *p = (LineStyleThicknessModifier_Material *)m;
547                         p->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f);
548                         p->mat_attr = LS_MODIFIER_MATERIAL_DIFF;
549                         p->value_min = 0.0f;
550                         p->value_max = 1.0f;
551                         break;
552                 }
553                 case LS_MODIFIER_CALLIGRAPHY:
554                 {
555                         LineStyleThicknessModifier_Calligraphy *p = (LineStyleThicknessModifier_Calligraphy *)m;
556                         p->min_thickness = 1.0f;
557                         p->max_thickness = 10.0f;
558                         p->orientation = DEG2RADF(60.0f);
559                         break;
560                 }
561                 default:
562                         return NULL; /* unknown modifier type */
563         }
564         add_to_modifier_list(&linestyle->thickness_modifiers, m);
565
566         return m;
567 }
568
569 LineStyleModifier *BKE_copy_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m)
570 {
571         LineStyleModifier *new_m;
572
573         new_m = alloc_thickness_modifier(m->type);
574         if (!new_m)
575                 return NULL;
576         new_m->influence = m->influence;
577         new_m->flags = m->flags;
578         new_m->blend = m->blend;
579
580         switch (m->type) {
581                 case LS_MODIFIER_ALONG_STROKE:
582                 {
583                         LineStyleThicknessModifier_AlongStroke *p = (LineStyleThicknessModifier_AlongStroke *)m;
584                         LineStyleThicknessModifier_AlongStroke *q = (LineStyleThicknessModifier_AlongStroke *)new_m;
585                         q->curve = curvemapping_copy(p->curve);
586                         q->flags = p->flags;
587                         q->value_min = p->value_min;
588                         q->value_max = p->value_max;
589                         break;
590                 }
591                 case LS_MODIFIER_DISTANCE_FROM_CAMERA:
592                 {
593                         LineStyleThicknessModifier_DistanceFromCamera *p = (LineStyleThicknessModifier_DistanceFromCamera *)m;
594                         LineStyleThicknessModifier_DistanceFromCamera *q = (LineStyleThicknessModifier_DistanceFromCamera *)new_m;
595                         q->curve = curvemapping_copy(p->curve);
596                         q->flags = p->flags;
597                         q->range_min = p->range_min;
598                         q->range_max = p->range_max;
599                         q->value_min = p->value_min;
600                         q->value_max = p->value_max;
601                         break;
602                 }
603                 case LS_MODIFIER_DISTANCE_FROM_OBJECT:
604                 {
605                         LineStyleThicknessModifier_DistanceFromObject *p = (LineStyleThicknessModifier_DistanceFromObject *)m;
606                         LineStyleThicknessModifier_DistanceFromObject *q = (LineStyleThicknessModifier_DistanceFromObject *)new_m;
607                         if (p->target)
608                                 p->target->id.us++;
609                         q->target = p->target;
610                         q->curve = curvemapping_copy(p->curve);
611                         q->flags = p->flags;
612                         q->range_min = p->range_min;
613                         q->range_max = p->range_max;
614                         q->value_min = p->value_min;
615                         q->value_max = p->value_max;
616                         break;
617                 }
618                 case LS_MODIFIER_MATERIAL:
619                 {
620                         LineStyleThicknessModifier_Material *p = (LineStyleThicknessModifier_Material *)m;
621                         LineStyleThicknessModifier_Material *q = (LineStyleThicknessModifier_Material *)new_m;
622                         q->curve = curvemapping_copy(p->curve);
623                         q->flags = p->flags;
624                         q->mat_attr = p->mat_attr;
625                         q->value_min = p->value_min;
626                         q->value_max = p->value_max;
627                         break;
628                 }
629                 case LS_MODIFIER_CALLIGRAPHY:
630                 {
631                         LineStyleThicknessModifier_Calligraphy *p = (LineStyleThicknessModifier_Calligraphy *)m;
632                         LineStyleThicknessModifier_Calligraphy *q = (LineStyleThicknessModifier_Calligraphy *)new_m;
633                         q->min_thickness = p->min_thickness;
634                         q->max_thickness = p->max_thickness;
635                         q->orientation = p->orientation;
636                         break;
637                 }
638                 default:
639                         return NULL; /* unknown modifier type */
640         }
641         add_to_modifier_list(&linestyle->thickness_modifiers, new_m);
642
643         return new_m;
644 }
645
646 void BKE_remove_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m)
647 {
648         switch (m->type) {
649                 case LS_MODIFIER_ALONG_STROKE:
650                         curvemapping_free(((LineStyleThicknessModifier_AlongStroke *)m)->curve);
651                         break;
652                 case LS_MODIFIER_DISTANCE_FROM_CAMERA:
653                         curvemapping_free(((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve);
654                         break;
655                 case LS_MODIFIER_DISTANCE_FROM_OBJECT:
656                         curvemapping_free(((LineStyleThicknessModifier_DistanceFromObject *)m)->curve);
657                         break;
658                 case LS_MODIFIER_MATERIAL:
659                         curvemapping_free(((LineStyleThicknessModifier_Material *)m)->curve);
660                         break;
661                 case LS_MODIFIER_CALLIGRAPHY:
662                         break;
663         }
664         BLI_freelinkN(&linestyle->thickness_modifiers, m);
665 }
666
667 static LineStyleModifier *alloc_geometry_modifier(int type)
668 {
669         size_t size;
670
671         switch (type) {
672                 case LS_MODIFIER_SAMPLING:
673                         size = sizeof(LineStyleGeometryModifier_Sampling);
674                         break;
675                 case LS_MODIFIER_BEZIER_CURVE:
676                         size = sizeof(LineStyleGeometryModifier_BezierCurve);
677                         break;
678                 case LS_MODIFIER_SINUS_DISPLACEMENT:
679                         size = sizeof(LineStyleGeometryModifier_SinusDisplacement);
680                         break;
681                 case LS_MODIFIER_SPATIAL_NOISE:
682                         size = sizeof(LineStyleGeometryModifier_SpatialNoise);
683                         break;
684                 case LS_MODIFIER_PERLIN_NOISE_1D:
685                         size = sizeof(LineStyleGeometryModifier_PerlinNoise1D);
686                         break;
687                 case LS_MODIFIER_PERLIN_NOISE_2D:
688                         size = sizeof(LineStyleGeometryModifier_PerlinNoise2D);
689                         break;
690                 case LS_MODIFIER_BACKBONE_STRETCHER:
691                         size = sizeof(LineStyleGeometryModifier_BackboneStretcher);
692                         break;
693                 case LS_MODIFIER_TIP_REMOVER:
694                         size = sizeof(LineStyleGeometryModifier_TipRemover);
695                         break;
696                 case LS_MODIFIER_POLYGONIZATION:
697                         size = sizeof(LineStyleGeometryModifier_Polygonalization);
698                         break;
699                 case LS_MODIFIER_GUIDING_LINES:
700                         size = sizeof(LineStyleGeometryModifier_GuidingLines);
701                         break;
702                 case LS_MODIFIER_BLUEPRINT:
703                         size = sizeof(LineStyleGeometryModifier_Blueprint);
704                         break;
705                 case LS_MODIFIER_2D_OFFSET:
706                         size = sizeof(LineStyleGeometryModifier_2DOffset);
707                         break;
708                 case LS_MODIFIER_2D_TRANSFORM:
709                         size = sizeof(LineStyleGeometryModifier_2DTransform);
710                         break;
711                 default:
712                         return NULL; /* unknown modifier type */
713         }
714
715         return new_modifier(type, size);
716 }
717
718 LineStyleModifier *BKE_add_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, int type)
719 {
720         LineStyleModifier *m;
721
722         m = alloc_geometry_modifier(type);
723
724         switch (type) {
725                 case LS_MODIFIER_SAMPLING:
726                 {
727                         LineStyleGeometryModifier_Sampling *p = (LineStyleGeometryModifier_Sampling *)m;
728                         p->sampling = 10.0f;
729                         break;
730                 }
731                 case LS_MODIFIER_BEZIER_CURVE:
732                 {
733                         LineStyleGeometryModifier_BezierCurve *p = (LineStyleGeometryModifier_BezierCurve *)m;
734                         p->error = 10.0f;
735                         break;
736                 }
737                 case LS_MODIFIER_SINUS_DISPLACEMENT:
738                 {
739                         LineStyleGeometryModifier_SinusDisplacement *p = (LineStyleGeometryModifier_SinusDisplacement *)m;
740                         p->wavelength = 20.0f;
741                         p->amplitude = 5.0f;
742                         p->phase = 0.0f;
743                         break;
744                 }
745                 case LS_MODIFIER_SPATIAL_NOISE:
746                 {
747                         LineStyleGeometryModifier_SpatialNoise *p = (LineStyleGeometryModifier_SpatialNoise *)m;
748                         p->amplitude = 5.0f;
749                         p->scale = 20.0f;
750                         p->octaves = 4;
751                         p->flags = LS_MODIFIER_SPATIAL_NOISE_SMOOTH | LS_MODIFIER_SPATIAL_NOISE_PURERANDOM;
752                         break;
753                 }
754                 case LS_MODIFIER_PERLIN_NOISE_1D:
755                 {
756                         LineStyleGeometryModifier_PerlinNoise1D *p = (LineStyleGeometryModifier_PerlinNoise1D *)m;
757                         p->frequency = 10.0f;
758                         p->amplitude = 10.0f;
759                         p->octaves = 4;
760                         p->angle = DEG2RADF(45.0f);
761                         break;
762                 }
763                 case LS_MODIFIER_PERLIN_NOISE_2D:
764                 {
765                         LineStyleGeometryModifier_PerlinNoise2D *p = (LineStyleGeometryModifier_PerlinNoise2D *)m;
766                         p->frequency = 10.0f;
767                         p->amplitude = 10.0f;
768                         p->octaves = 4;
769                         p->angle = DEG2RADF(45.0f);
770                         break;
771                 }
772                 case LS_MODIFIER_BACKBONE_STRETCHER:
773                 {
774                         LineStyleGeometryModifier_BackboneStretcher *p = (LineStyleGeometryModifier_BackboneStretcher *)m;
775                         p->backbone_length = 10.0f;
776                         break;
777                 }
778                 case LS_MODIFIER_TIP_REMOVER:
779                 {
780                         LineStyleGeometryModifier_TipRemover *p = (LineStyleGeometryModifier_TipRemover *)m;
781                         p->tip_length = 10.0f;
782                         break;
783                 }
784                 case LS_MODIFIER_POLYGONIZATION:
785                 {
786                         LineStyleGeometryModifier_Polygonalization *p = (LineStyleGeometryModifier_Polygonalization *)m;
787                         p->error = 10.0f;
788                         break;
789                 }
790                 case LS_MODIFIER_GUIDING_LINES:
791                 {
792                         LineStyleGeometryModifier_GuidingLines *p = (LineStyleGeometryModifier_GuidingLines *)m;
793                         p->offset = 0.0f;
794                         break;
795                 }
796                 case LS_MODIFIER_BLUEPRINT:
797                 {
798                         LineStyleGeometryModifier_Blueprint *p = (LineStyleGeometryModifier_Blueprint *)m;
799                         p->flags = LS_MODIFIER_BLUEPRINT_CIRCLES;
800                         p->rounds = 1;
801                         p->backbone_length = 10.0f;
802                         p->random_radius = 3;
803                         p->random_center = 5;
804                         p->random_backbone = 5;
805                         break;
806                 }
807                 case LS_MODIFIER_2D_OFFSET:
808                 {
809                         LineStyleGeometryModifier_2DOffset *p = (LineStyleGeometryModifier_2DOffset *)m;
810                         p->start = 0.0f;
811                         p->end = 0.0f;
812                         p->x = 0.0f;
813                         p->y = 0.0f;
814                         break;
815                 }
816                 case LS_MODIFIER_2D_TRANSFORM:
817                 {
818                         LineStyleGeometryModifier_2DTransform *p = (LineStyleGeometryModifier_2DTransform *)m;
819                         p->pivot = LS_MODIFIER_2D_TRANSFORM_PIVOT_CENTER;
820                         p->scale_x = 1.0f;
821                         p->scale_y = 1.0f;
822                         p->angle = DEG2RADF(0.0f);
823                         p->pivot_u = 0.5f;
824                         p->pivot_x = 0.0f;
825                         p->pivot_y = 0.0f;
826                         break;
827                 }
828                 default:
829                         return NULL; /* unknown modifier type */
830         }
831         add_to_modifier_list(&linestyle->geometry_modifiers, m);
832
833         return m;
834 }
835
836 LineStyleModifier *BKE_copy_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m)
837 {
838         LineStyleModifier *new_m;
839
840         new_m = alloc_geometry_modifier(m->type);
841         new_m->flags = m->flags;
842
843         switch (m->type) {
844                 case LS_MODIFIER_SAMPLING:
845                 {
846                         LineStyleGeometryModifier_Sampling *p = (LineStyleGeometryModifier_Sampling *)m;
847                         LineStyleGeometryModifier_Sampling *q = (LineStyleGeometryModifier_Sampling *)new_m;
848                         q->sampling = p->sampling;
849                         break;
850                 }
851                 case LS_MODIFIER_BEZIER_CURVE:
852                 {
853                         LineStyleGeometryModifier_BezierCurve *p = (LineStyleGeometryModifier_BezierCurve *)m;
854                         LineStyleGeometryModifier_BezierCurve *q = (LineStyleGeometryModifier_BezierCurve *)new_m;
855                         q->error = p->error;
856                         break;
857                 }
858                 case LS_MODIFIER_SINUS_DISPLACEMENT:
859                 {
860                         LineStyleGeometryModifier_SinusDisplacement *p = (LineStyleGeometryModifier_SinusDisplacement *)m;
861                         LineStyleGeometryModifier_SinusDisplacement *q = (LineStyleGeometryModifier_SinusDisplacement *)new_m;
862                         q->wavelength = p->wavelength;
863                         q->amplitude = p->amplitude;
864                         q->phase = p->phase;
865                         break;
866                 }
867                 case LS_MODIFIER_SPATIAL_NOISE:
868                 {
869                         LineStyleGeometryModifier_SpatialNoise *p = (LineStyleGeometryModifier_SpatialNoise *)m;
870                         LineStyleGeometryModifier_SpatialNoise *q = (LineStyleGeometryModifier_SpatialNoise *)new_m;
871                         q->amplitude = p->amplitude;
872                         q->scale = p->scale;
873                         q->octaves = p->octaves;
874                         q->flags = p->flags;
875                         break;
876                 }
877                 case LS_MODIFIER_PERLIN_NOISE_1D:
878                 {
879                         LineStyleGeometryModifier_PerlinNoise1D *p = (LineStyleGeometryModifier_PerlinNoise1D *)m;
880                         LineStyleGeometryModifier_PerlinNoise1D *q = (LineStyleGeometryModifier_PerlinNoise1D *)new_m;
881                         q->frequency = p->frequency;
882                         q->amplitude = p->amplitude;
883                         q->angle = p->angle;
884                         q->octaves = p->octaves;
885                         q->seed = p->seed;
886                         break;
887                 }
888                 case LS_MODIFIER_PERLIN_NOISE_2D:
889                 {
890                         LineStyleGeometryModifier_PerlinNoise2D *p = (LineStyleGeometryModifier_PerlinNoise2D *)m;
891                         LineStyleGeometryModifier_PerlinNoise2D *q = (LineStyleGeometryModifier_PerlinNoise2D *)new_m;
892                         q->frequency = p->frequency;
893                         q->amplitude = p->amplitude;
894                         q->angle = p->angle;
895                         q->octaves = p->octaves;
896                         q->seed = p->seed;
897                         break;
898                 }
899                 case LS_MODIFIER_BACKBONE_STRETCHER:
900                 {
901                         LineStyleGeometryModifier_BackboneStretcher *p = (LineStyleGeometryModifier_BackboneStretcher *)m;
902                         LineStyleGeometryModifier_BackboneStretcher *q = (LineStyleGeometryModifier_BackboneStretcher *)new_m;
903                         q->backbone_length = p->backbone_length;
904                         break;
905                 }
906                 case LS_MODIFIER_TIP_REMOVER:
907                 {
908                         LineStyleGeometryModifier_TipRemover *p = (LineStyleGeometryModifier_TipRemover *)m;
909                         LineStyleGeometryModifier_TipRemover *q = (LineStyleGeometryModifier_TipRemover *)new_m;
910                         q->tip_length = p->tip_length;
911                         break;
912                 }
913                 case LS_MODIFIER_POLYGONIZATION:
914                 {
915                         LineStyleGeometryModifier_Polygonalization *p = (LineStyleGeometryModifier_Polygonalization *)m;
916                         LineStyleGeometryModifier_Polygonalization *q = (LineStyleGeometryModifier_Polygonalization *)new_m;
917                         q->error = p->error;
918                         break;
919                 }
920                 case LS_MODIFIER_GUIDING_LINES:
921                 {
922                         LineStyleGeometryModifier_GuidingLines *p = (LineStyleGeometryModifier_GuidingLines *)m;
923                         LineStyleGeometryModifier_GuidingLines *q = (LineStyleGeometryModifier_GuidingLines *)new_m;
924                         q->offset = p->offset;
925                         break;
926                 }
927                 case LS_MODIFIER_BLUEPRINT:
928                 {
929                         LineStyleGeometryModifier_Blueprint *p = (LineStyleGeometryModifier_Blueprint *)m;
930                         LineStyleGeometryModifier_Blueprint *q = (LineStyleGeometryModifier_Blueprint *)new_m;
931                         q->flags = p->flags;
932                         q->rounds = p->rounds;
933                         q->backbone_length = p->backbone_length;
934                         q->random_radius = p->random_radius;
935                         q->random_center = p->random_center;
936                         q->random_backbone = p->random_backbone;
937                         break;
938                 }
939                 case LS_MODIFIER_2D_OFFSET:
940                 {
941                         LineStyleGeometryModifier_2DOffset *p = (LineStyleGeometryModifier_2DOffset *)m;
942                         LineStyleGeometryModifier_2DOffset *q = (LineStyleGeometryModifier_2DOffset *)new_m;
943                         q->start = p->start;
944                         q->end = p->end;
945                         q->x = p->x;
946                         q->y = p->y;
947                         break;
948                 }
949                 case LS_MODIFIER_2D_TRANSFORM:
950                 {
951                         LineStyleGeometryModifier_2DTransform *p = (LineStyleGeometryModifier_2DTransform *)m;
952                         LineStyleGeometryModifier_2DTransform *q = (LineStyleGeometryModifier_2DTransform *)new_m;
953                         q->pivot = p->pivot;
954                         q->scale_x = p->scale_x;
955                         q->scale_y = p->scale_y;
956                         q->angle = p->angle;
957                         q->pivot_u = p->pivot_u;
958                         q->pivot_x = p->pivot_x;
959                         q->pivot_y = p->pivot_y;
960                         break;
961                 }
962                 default:
963                         return NULL; /* unknown modifier type */
964         }
965         add_to_modifier_list(&linestyle->geometry_modifiers, new_m);
966
967         return new_m;
968 }
969
970 void BKE_remove_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m)
971 {
972         BLI_freelinkN(&linestyle->geometry_modifiers, m);
973 }
974
975 static void move_modifier(ListBase *lb, LineStyleModifier *modifier, int direction)
976 {
977         BLI_remlink(lb, modifier);
978         if (direction > 0)
979                 BLI_insertlinkbefore(lb, modifier->prev, modifier);
980         else
981                 BLI_insertlinkafter(lb, modifier->next, modifier);
982 }
983
984 void BKE_move_linestyle_color_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction)
985 {
986         move_modifier(&linestyle->color_modifiers, modifier, direction);
987 }
988
989 void BKE_move_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction)
990 {
991         move_modifier(&linestyle->alpha_modifiers, modifier, direction);
992 }
993
994 void BKE_move_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction)
995 {
996         move_modifier(&linestyle->thickness_modifiers, modifier, direction);
997 }
998
999 void BKE_move_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction)
1000 {
1001         move_modifier(&linestyle->geometry_modifiers, modifier, direction);
1002 }
1003
1004 void BKE_list_modifier_color_ramps(FreestyleLineStyle *linestyle, ListBase *listbase)
1005 {
1006         LineStyleModifier *m;
1007         ColorBand *color_ramp;
1008         LinkData *link;
1009
1010         BLI_listbase_clear(listbase);
1011
1012         for (m = (LineStyleModifier *)linestyle->color_modifiers.first; m; m = m->next) {
1013                 switch (m->type) {
1014                         case LS_MODIFIER_ALONG_STROKE:
1015                                 color_ramp = ((LineStyleColorModifier_AlongStroke *)m)->color_ramp;
1016                                 break;
1017                         case LS_MODIFIER_DISTANCE_FROM_CAMERA:
1018                                 color_ramp = ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp;
1019                                 break;
1020                         case LS_MODIFIER_DISTANCE_FROM_OBJECT:
1021                                 color_ramp = ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp;
1022                                 break;
1023                         case LS_MODIFIER_MATERIAL:
1024                                 color_ramp = ((LineStyleColorModifier_Material *)m)->color_ramp;
1025                                 break;
1026                         default:
1027                                 continue;
1028                 }
1029                 link = (LinkData *) MEM_callocN(sizeof(LinkData), "link to color ramp");
1030                 link->data = color_ramp;
1031                 BLI_addtail(listbase, link);
1032         }
1033 }
1034
1035 char *BKE_path_from_ID_to_color_ramp(FreestyleLineStyle *linestyle, ColorBand *color_ramp)
1036 {
1037         LineStyleModifier *m;
1038         bool found = false;
1039
1040         for (m = (LineStyleModifier *)linestyle->color_modifiers.first; m; m = m->next) {
1041                 switch (m->type) {
1042                         case LS_MODIFIER_ALONG_STROKE:
1043                                 if (color_ramp == ((LineStyleColorModifier_AlongStroke *)m)->color_ramp)
1044                                         found = true;
1045                                 break;
1046                         case LS_MODIFIER_DISTANCE_FROM_CAMERA:
1047                                 if (color_ramp == ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp)
1048                                         found = true;
1049                                 break;
1050                         case LS_MODIFIER_DISTANCE_FROM_OBJECT:
1051                                 if (color_ramp == ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp)
1052                                         found = true;
1053                                 break;
1054                         case LS_MODIFIER_MATERIAL:
1055                                 if (color_ramp == ((LineStyleColorModifier_Material *)m)->color_ramp)
1056                                         found = true;
1057                                 break;
1058                 }
1059
1060                 if (found) {
1061                         char name_esc[sizeof(m->name) * 2];
1062                         BLI_strescape(name_esc, m->name, sizeof(name_esc));
1063                         return BLI_sprintfN("color_modifiers[\"%s\"].color_ramp", name_esc);
1064                 }
1065         }
1066         printf("BKE_path_from_ID_to_color_ramp: No color ramps correspond to the given pointer.\n");
1067         return NULL;
1068 }
1069
1070 void BKE_unlink_linestyle_target_object(FreestyleLineStyle *linestyle, struct Object *ob)
1071 {
1072         LineStyleModifier *m;
1073
1074         for (m = (LineStyleModifier *)linestyle->color_modifiers.first; m; m = m->next) {
1075                 if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
1076                         if (((LineStyleColorModifier_DistanceFromObject *)m)->target == ob) {
1077                                 ((LineStyleColorModifier_DistanceFromObject *)m)->target = NULL;
1078                         }
1079                 }
1080         }
1081         for (m = (LineStyleModifier *)linestyle->alpha_modifiers.first; m; m = m->next) {
1082                 if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
1083                         if (((LineStyleAlphaModifier_DistanceFromObject *)m)->target == ob) {
1084                                 ((LineStyleAlphaModifier_DistanceFromObject *)m)->target = NULL;
1085                         }
1086                 }
1087         }
1088         for (m = (LineStyleModifier *)linestyle->thickness_modifiers.first; m; m = m->next) {
1089                 if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) {
1090                         if (((LineStyleThicknessModifier_DistanceFromObject *)m)->target == ob) {
1091                                 ((LineStyleThicknessModifier_DistanceFromObject *)m)->target = NULL;
1092                         }
1093                 }
1094         }
1095 }