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