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