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