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