diff options
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_linestyle.h | 74 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_main.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/CMakeLists.txt | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/SConscript | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/BME_conversions.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/anim_sys.c | 24 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/cdderivedmesh.c | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/editderivedmesh.c | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/group.c | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/idcode.c | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/library.c | 15 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/linestyle.c | 1001 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/material.c | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/subsurf_ccg.c | 4 |
16 files changed, 1146 insertions, 11 deletions
diff --git a/source/blender/blenkernel/BKE_linestyle.h b/source/blender/blenkernel/BKE_linestyle.h new file mode 100644 index 00000000000..bb763f4e6b3 --- /dev/null +++ b/source/blender/blenkernel/BKE_linestyle.h @@ -0,0 +1,74 @@ +/* BKE_linestyle.h + * + * + * $Id: BKE_particle.h 29187 2010-06-03 15:39:02Z kjym3 $ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef BKE_LINESTYLE_H +#define BKE_LINESTYLE_H + +#include "DNA_linestyle_types.h" + +#define LS_MODIFIER_TYPE_COLOR 1 +#define LS_MODIFIER_TYPE_ALPHA 2 +#define LS_MODIFIER_TYPE_THICKNESS 3 +#define LS_MODIFIER_TYPE_GEOMETRY 4 + +struct Main; +struct Object; + +FreestyleLineStyle *FRS_new_linestyle(char *name, struct Main *main); +void FRS_free_linestyle(FreestyleLineStyle *linestyle); +FreestyleLineStyle *FRS_copy_linestyle(FreestyleLineStyle *linestyle); + +LineStyleModifier *FRS_add_linestyle_color_modifier(FreestyleLineStyle *linestyle, int type); +LineStyleModifier *FRS_add_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, int type); +LineStyleModifier *FRS_add_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, int type); +LineStyleModifier *FRS_add_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, int type); + +LineStyleModifier *FRS_copy_linestyle_color_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m); +LineStyleModifier *FRS_copy_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m); +LineStyleModifier *FRS_copy_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m); +LineStyleModifier *FRS_copy_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m); + +void FRS_remove_linestyle_color_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier); +void FRS_remove_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier); +void FRS_remove_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier); +void FRS_remove_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier); + +void FRS_move_linestyle_color_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction); +void FRS_move_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction); +void FRS_move_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction); +void FRS_move_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction); + +void FRS_list_modifier_color_ramps(FreestyleLineStyle *linestyle, ListBase *listbase); +char *FRS_path_from_ID_to_color_ramp(FreestyleLineStyle *linestyle, ColorBand *color_ramp); + +void FRS_unlink_linestyle_target_object(FreestyleLineStyle *linestyle, struct Object *ob); + +#endif diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h index ffcbb6e40bc..b5fb0aca27f 100644 --- a/source/blender/blenkernel/BKE_main.h +++ b/source/blender/blenkernel/BKE_main.h @@ -86,6 +86,7 @@ typedef struct Main { ListBase wm; ListBase gpencil; ListBase movieclip; + ListBase linestyle; char id_tag_update[256]; } Main; diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 42e6f1d8fb2..1d5bdb36de7 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -29,6 +29,7 @@ set(INC ../blenfont ../blenlib ../blenloader + ../freestyle ../gpu ../ikplugin ../imbuf @@ -109,6 +110,7 @@ set(SRC intern/lamp.c intern/lattice.c intern/library.c + intern/linestyle.c intern/material.c intern/mball.c intern/mesh.c @@ -196,6 +198,7 @@ set(SRC BKE_lamp.h BKE_lattice.h BKE_library.h + BKE_linestyle.h BKE_main.h BKE_material.h BKE_mball.h diff --git a/source/blender/blenkernel/SConscript b/source/blender/blenkernel/SConscript index 62a8aa8362f..b5d4915f8d4 100644 --- a/source/blender/blenkernel/SConscript +++ b/source/blender/blenkernel/SConscript @@ -8,7 +8,7 @@ incs = '. #/intern/guardedalloc #/intern/memutil' incs += ' ../blenlib ../blenfont ../makesdna ../windowmanager' incs += ' ../render/extern/include #/intern/decimation/extern ../makesrna' incs += ' ../imbuf ../ikplugin ../avi #/intern/elbeem/extern ../nodes ../modifiers' -incs += ' #/intern/iksolver/extern ../blenloader' +incs += ' #/intern/iksolver/extern ../blenloader ../freestyle' incs += ' #/extern/bullet2/src' incs += ' #/intern/opennl/extern #/intern/bsp/extern' incs += ' ../gpu #/extern/glew/include' diff --git a/source/blender/blenkernel/intern/BME_conversions.c b/source/blender/blenkernel/intern/BME_conversions.c index ce1da6132cd..bc87c5dbb6a 100644 --- a/source/blender/blenkernel/intern/BME_conversions.c +++ b/source/blender/blenkernel/intern/BME_conversions.c @@ -303,6 +303,7 @@ BME_Mesh *BME_editmesh_to_bmesh(EditMesh *em) { e->flag = eed->f & SELECT; if(eed->sharp) e->flag |= ME_SHARP; if(eed->seam) e->flag |= ME_SEAM; + if(eed->freestyle) e->flag |= ME_FREESTYLE_EDGE; //XXX if(eed->h & EM_FGON) e->flag |= ME_FGON; if(eed->h & 1) e->flag |= ME_HIDE; eed->tmp.e = (EditEdge*)e; @@ -395,6 +396,7 @@ void BME_bmesh_to_editmesh(BME_Mesh *bm, BME_TransData_Head *td, EditMesh *em) { eed->bweight = e->bweight; if(e->flag & ME_SEAM) eed->seam = 1; if(e->flag & ME_SHARP) eed->sharp = 1; + if(e->flag & ME_FREESTYLE_EDGE) eed->freestyle = 1; if(e->flag & SELECT) eed->f |= SELECT; //XXX if(e->flag & ME_FGON) eed->h= EM_FGON; // 2 different defines! if(e->flag & ME_HIDE) eed->h |= 1; diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index c3d2425f280..9867292d2ab 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -86,6 +86,7 @@ short id_type_can_have_animdata (ID *id) case ID_PA: case ID_MA: case ID_TE: case ID_NT: case ID_LA: case ID_CA: case ID_WO: + case ID_LS: case ID_SPK: case ID_SCE: case ID_MC: @@ -742,7 +743,7 @@ void BKE_animdata_main_cb (Main *mainptr, ID_AnimData_Edit_Callback func, void * AnimData *adt= BKE_animdata_from_id(id); \ if (adt) func(id, adt, user_data); \ } - + /* "embedded" nodetree cases (i.e. scene/material/texture->nodetree) */ #define ANIMDATA_NODETREE_IDS_CB(first, NtId_Type) \ for (id= first; id; id= id->next) { \ @@ -754,13 +755,13 @@ void BKE_animdata_main_cb (Main *mainptr, ID_AnimData_Edit_Callback func, void * } \ if (adt) func(id, adt, user_data); \ } - + /* nodes */ ANIMDATA_IDS_CB(mainptr->nodetree.first); - + /* textures */ ANIMDATA_NODETREE_IDS_CB(mainptr->tex.first, Tex); - + /* lamps */ ANIMDATA_IDS_CB(mainptr->lamp.first); @@ -805,7 +806,10 @@ void BKE_animdata_main_cb (Main *mainptr, ID_AnimData_Edit_Callback func, void * /* scenes */ ANIMDATA_NODETREE_IDS_CB(mainptr->scene.first, Scene); -} + + /* line styles */ + ANIMDATA_IDS_CB(mainptr->linestyle.first); + } /* Fix all RNA-Paths throughout the database (directly access the Global.main version) * NOTE: it is assumed that the structure we're replacing is <prefix><["><name><"]> @@ -887,10 +891,13 @@ void BKE_all_animdata_fix_paths_rename (const char *prefix, const char *oldName, /* worlds */ RENAMEFIX_ANIM_IDS(mainptr->world.first); + /* linestyles */ + RENAMEFIX_ANIM_IDS(mainptr->linestyle.first); + /* scenes */ RENAMEFIX_ANIM_NODETREE_IDS(mainptr->scene.first, Scene); -} - + } + /* *********************************** */ /* KeyingSet API */ @@ -2345,6 +2352,9 @@ void BKE_animsys_evaluate_all_animation (Main *main, Scene *scene, float ctime) /* movie clips */ EVAL_ANIM_IDS(main->movieclip.first, ADT_RECALC_ANIM); + /* linestyles */ + EVAL_ANIM_IDS(main->linestyle.first, ADT_RECALC_ANIM); + /* objects */ /* ADT_RECALC_ANIM doesn't need to be supplied here, since object AnimData gets * this tagged by Depsgraph on framechange. This optimisation means that objects diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index 5af3dc15704..8bc8faad0cc 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -1731,6 +1731,7 @@ DerivedMesh *CDDM_from_editmesh(EditMesh *em, Mesh *UNUSED(me)) if(eed->seam) med->flag |= ME_SEAM; if(eed->sharp) med->flag |= ME_SHARP; + if(eed->freestyle) med->flag |= ME_FREESTYLE_EDGE; if(!eed->f2) med->flag |= ME_LOOSEEDGE; *index = i; diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c index bb1d20f0187..cae60c22627 100644 --- a/source/blender/blenkernel/intern/editderivedmesh.c +++ b/source/blender/blenkernel/intern/editderivedmesh.c @@ -1003,6 +1003,7 @@ static void emDM_getEdge(DerivedMesh *dm, int index, MEdge *edge_r) edge_r->flag = ME_EDGEDRAW|ME_EDGERENDER; if (ee->seam) edge_r->flag |= ME_SEAM; if (ee->sharp) edge_r->flag |= ME_SHARP; + if (ee->freestyle) edge_r->flag |= ME_FREESTYLE_EDGE; #if 0 /* this needs setup of f2 field */ if (!ee->f2) edge_r->flag |= ME_LOOSEEDGE; @@ -1103,6 +1104,7 @@ static void emDM_copyEdgeArray(DerivedMesh *dm, MEdge *edge_r) edge_r->flag = ME_EDGEDRAW|ME_EDGERENDER; if (ee->seam) edge_r->flag |= ME_SEAM; if (ee->sharp) edge_r->flag |= ME_SHARP; + if (ee->freestyle) edge_r->flag |= ME_FREESTYLE_EDGE; #if 0 /* this needs setup of f2 field */ if (!ee->f2) edge_r->flag |= ME_LOOSEEDGE; diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c index 7ac395212ab..8ebac31ad95 100644 --- a/source/blender/blenkernel/intern/group.c +++ b/source/blender/blenkernel/intern/group.c @@ -80,6 +80,7 @@ void unlink_group(Group *group) Object *ob; Scene *sce; SceneRenderLayer *srl; + FreestyleLineSet *lineset; ParticleSystem *psys; for(ma= bmain->mat.first; ma; ma= ma->id.next) { @@ -104,6 +105,11 @@ void unlink_group(Group *group) for(srl= sce->r.layers.first; srl; srl= srl->next) { if (srl->light_override==group) srl->light_override= NULL; + + for(lineset= srl->freestyleConfig.linesets.first; lineset; lineset= lineset->next) { + if (lineset->group == group) + lineset->group= NULL; + } } } diff --git a/source/blender/blenkernel/intern/idcode.c b/source/blender/blenkernel/intern/idcode.c index b52576ec465..c7dec3d8f4b 100644 --- a/source/blender/blenkernel/intern/idcode.c +++ b/source/blender/blenkernel/intern/idcode.c @@ -61,6 +61,7 @@ static IDType idtypes[]= { { ID_KE, "Key", "shape_keys", 0}, { ID_LA, "Lamp", "lamps", IDTYPE_FLAGS_ISLINKABLE}, { ID_LI, "Library", "libraries", 0}, + { ID_LS, "FreestyleLineStyle", "linestyles", IDTYPE_FLAGS_ISLINKABLE}, { ID_LT, "Lattice", "lattices", IDTYPE_FLAGS_ISLINKABLE}, { ID_MA, "Material", "materials", IDTYPE_FLAGS_ISLINKABLE}, { ID_MB, "Metaball", "metaballs", IDTYPE_FLAGS_ISLINKABLE}, diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index 795cf75820f..d7985914f25 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -113,6 +113,7 @@ #include "BKE_speaker.h" #include "BKE_utildefines.h" #include "BKE_movieclip.h" +#include "BKE_linestyle.h" #include "RNA_access.h" @@ -269,6 +270,8 @@ int id_make_local(ID *id, int test) return 0; /* can't be linked */ case ID_GD: return 0; /* not implemented */ + case ID_LS: + return 0; /* not implemented */ } return 0; @@ -360,6 +363,9 @@ int id_copy(ID *id, ID **newid, int test) return 0; /* can't be copied from here */ case ID_GD: return 0; /* not implemented */ + case ID_LS: + if(!test) *newid= (ID*)FRS_copy_linestyle((FreestyleLineStyle*)id); + return 1; } return 0; @@ -488,6 +494,8 @@ ListBase *which_libbase(Main *mainlib, short type) return &(mainlib->gpencil); case ID_MC: return &(mainlib->movieclip); + case ID_LS: + return &(mainlib->linestyle); } return NULL; } @@ -570,6 +578,7 @@ int set_listbasepointers(Main *main, ListBase **lb) lb[a++]= &(main->library); lb[a++]= &(main->wm); lb[a++]= &(main->movieclip); + lb[a++]= &(main->linestyle); lb[a]= NULL; @@ -681,6 +690,9 @@ static ID *alloc_libblock_notest(short type) case ID_MC: id = MEM_callocN(sizeof(MovieClip), "Movie Clip"); break; + case ID_LS: + id = MEM_callocN(sizeof(FreestyleLineStyle), "Freestyle Line Style"); + break; } return id; } @@ -889,6 +901,9 @@ void free_libblock(ListBase *lb, void *idv) case ID_MC: free_movieclip((MovieClip *)id); break; + case ID_LS: + FRS_free_linestyle((FreestyleLineStyle *)id); + break; } if (id->properties) { diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c new file mode 100644 index 00000000000..dcacfeea5bc --- /dev/null +++ b/source/blender/blenkernel/intern/linestyle.c @@ -0,0 +1,1001 @@ +/* linestyle.c + * + * $Id$ + * + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2010 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "MEM_guardedalloc.h" + +#include "DNA_object_types.h" +#include "DNA_material_types.h" /* for ramp blend */ +#include "DNA_texture_types.h" + +#include "BKE_global.h" +#include "BKE_library.h" +#include "BKE_linestyle.h" +#include "BKE_main.h" +#include "BKE_texture.h" +#include "BKE_colortools.h" +#include "BKE_animsys.h" + +#include "BLI_blenlib.h" + +static char *modifier_name[LS_MODIFIER_NUM] = { + NULL, + "Along Stroke", + "Distance from Camera", + "Distance from Object", + "Material", + "Sampling", + "Bezier Curve", + "Sinus Displacement", + "Spatial Noise", + "Perlin Noise 1D", + "Perlin Noise 2D", + "Backbone Stretcher", + "Tip Remover", + "Calligraphy", + "Polygonalization", + "Guiding Lines", + "Blueprint", + "2D Offset", + "2D Transform"}; + +static void default_linestyle_settings(FreestyleLineStyle *linestyle) +{ + linestyle->panel = LS_PANEL_STROKES; + linestyle->r = linestyle->g = linestyle->b = 0.0; + linestyle->alpha = 1.0; + linestyle->thickness = 1.0; + linestyle->chaining = LS_CHAINING_PLAIN; + linestyle->rounds = 3; + linestyle->min_angle = 0.0f; + linestyle->max_angle = 0.0f; + linestyle->min_length = 0.0f; + linestyle->max_length = 10000.0f; + linestyle->split_length = 100; + + linestyle->color_modifiers.first = linestyle->color_modifiers.last = NULL; + linestyle->alpha_modifiers.first = linestyle->alpha_modifiers.last = NULL; + linestyle->thickness_modifiers.first = linestyle->thickness_modifiers.last = NULL; + linestyle->geometry_modifiers.first = linestyle->geometry_modifiers.last = NULL; + + FRS_add_linestyle_geometry_modifier(linestyle, LS_MODIFIER_SAMPLING); + + linestyle->caps = LS_CAPS_BUTT; +} + +FreestyleLineStyle *FRS_new_linestyle(char *name, struct Main *main) +{ + FreestyleLineStyle *linestyle; + + if (!main) + main = G.main; + + linestyle = (FreestyleLineStyle *)alloc_libblock(&main->linestyle, ID_LS, name); + + default_linestyle_settings(linestyle); + + return linestyle; +} + +void FRS_free_linestyle(FreestyleLineStyle *linestyle) +{ + LineStyleModifier *m; + + BKE_free_animdata(&linestyle->id); + while ((m = (LineStyleModifier *)linestyle->color_modifiers.first)) + FRS_remove_linestyle_color_modifier(linestyle, m); + while ((m = (LineStyleModifier *)linestyle->alpha_modifiers.first)) + FRS_remove_linestyle_alpha_modifier(linestyle, m); + while ((m = (LineStyleModifier *)linestyle->thickness_modifiers.first)) + FRS_remove_linestyle_thickness_modifier(linestyle, m); + while ((m = (LineStyleModifier *)linestyle->geometry_modifiers.first)) + FRS_remove_linestyle_geometry_modifier(linestyle, m); +} + +FreestyleLineStyle *FRS_copy_linestyle(FreestyleLineStyle *linestyle) +{ + FreestyleLineStyle *new_linestyle; + LineStyleModifier *m; + + new_linestyle = FRS_new_linestyle(linestyle->id.name+2, NULL); + FRS_free_linestyle(new_linestyle); + + new_linestyle->r = linestyle->r; + new_linestyle->g = linestyle->g; + new_linestyle->b = linestyle->b; + new_linestyle->alpha = linestyle->alpha; + new_linestyle->thickness = linestyle->thickness; + new_linestyle->flag = linestyle->flag; + new_linestyle->caps = linestyle->caps; + new_linestyle->chaining = linestyle->chaining; + new_linestyle->rounds = linestyle->rounds; + new_linestyle->min_angle = linestyle->min_angle; + new_linestyle->max_angle = linestyle->max_angle; + new_linestyle->min_length = linestyle->min_length; + new_linestyle->max_length = linestyle->max_length; + new_linestyle->split_length = linestyle->split_length; + new_linestyle->dash1 = linestyle->dash1; + new_linestyle->gap1 = linestyle->gap1; + new_linestyle->dash2 = linestyle->dash2; + new_linestyle->gap2 = linestyle->gap2; + new_linestyle->dash3 = linestyle->dash3; + new_linestyle->gap3 = linestyle->gap3; + new_linestyle->panel = linestyle->panel; + for (m = (LineStyleModifier *)linestyle->color_modifiers.first; m; m = m->next) + FRS_copy_linestyle_color_modifier(new_linestyle, m); + for (m = (LineStyleModifier *)linestyle->alpha_modifiers.first; m; m = m->next) + FRS_copy_linestyle_alpha_modifier(new_linestyle, m); + for (m = (LineStyleModifier *)linestyle->thickness_modifiers.first; m; m = m->next) + FRS_copy_linestyle_thickness_modifier(new_linestyle, m); + for (m = (LineStyleModifier *)linestyle->geometry_modifiers.first; m; m = m->next) + FRS_copy_linestyle_geometry_modifier(new_linestyle, m); + return new_linestyle; +} + +static LineStyleModifier *new_modifier(int type, size_t size) +{ + LineStyleModifier *m; + + m = (LineStyleModifier *)MEM_callocN(size, "line style modifier"); + if (m) { + m->type = type; + strcpy(m->name, modifier_name[type]); + m->influence = 1.0f; + m->flags = LS_MODIFIER_ENABLED | LS_MODIFIER_EXPANDED; + } + return m; +} + +static void add_to_modifier_list(ListBase *lb, LineStyleModifier *m) +{ + BLI_addtail(lb, (void *)m); + BLI_uniquename(lb, m, modifier_name[m->type], '.', offsetof(LineStyleModifier, name), sizeof(m->name)); +} + +static LineStyleModifier *alloc_color_modifier(int type) +{ + size_t size; + + switch (type) { + case LS_MODIFIER_ALONG_STROKE: + size = sizeof(LineStyleColorModifier_AlongStroke); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + size = sizeof(LineStyleColorModifier_DistanceFromCamera); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + size = sizeof(LineStyleColorModifier_DistanceFromObject); + break; + case LS_MODIFIER_MATERIAL: + size = sizeof(LineStyleColorModifier_Material); + break; + default: + return NULL; /* unknown modifier type */ + } + return new_modifier(type, size); +} + +LineStyleModifier *FRS_add_linestyle_color_modifier(FreestyleLineStyle *linestyle, int type) +{ + LineStyleModifier *m; + + m = alloc_color_modifier(type); + if (!m) + return NULL; + m->blend = MA_RAMP_BLEND; + switch (type) { + case LS_MODIFIER_ALONG_STROKE: + ((LineStyleColorModifier_AlongStroke *)m)->color_ramp = add_colorband(1); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp = add_colorband(1); + ((LineStyleColorModifier_DistanceFromCamera *)m)->range_min = 0.0f; + ((LineStyleColorModifier_DistanceFromCamera *)m)->range_max = 10000.0f; + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + ((LineStyleColorModifier_DistanceFromObject *)m)->target = NULL; + ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp = add_colorband(1); + ((LineStyleColorModifier_DistanceFromObject *)m)->range_min = 0.0f; + ((LineStyleColorModifier_DistanceFromObject *)m)->range_max = 10000.0f; + break; + case LS_MODIFIER_MATERIAL: + ((LineStyleColorModifier_Material *)m)->color_ramp = add_colorband(1); + ((LineStyleColorModifier_Material *)m)->mat_attr = LS_MODIFIER_MATERIAL_DIFF; + break; + default: + return NULL; /* unknown modifier type */ + } + add_to_modifier_list(&linestyle->color_modifiers, m); + + return m; +} + +LineStyleModifier *FRS_copy_linestyle_color_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m) +{ + LineStyleModifier *new_m; + + new_m = alloc_color_modifier(m->type); + if (!new_m) + return NULL; + new_m->influence = m->influence; + new_m->flags = m->flags; + new_m->blend = m->blend; + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + { + LineStyleColorModifier_AlongStroke *p = (LineStyleColorModifier_AlongStroke *)m; + ((LineStyleColorModifier_AlongStroke *)new_m)->color_ramp = MEM_dupallocN(p->color_ramp); + } + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + { + LineStyleColorModifier_DistanceFromCamera *p = (LineStyleColorModifier_DistanceFromCamera *)m; + ((LineStyleColorModifier_DistanceFromCamera *)new_m)->color_ramp = MEM_dupallocN(p->color_ramp); + ((LineStyleColorModifier_DistanceFromCamera *)new_m)->range_min = p->range_min; + ((LineStyleColorModifier_DistanceFromCamera *)new_m)->range_max = p->range_max; + } + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + { + LineStyleColorModifier_DistanceFromObject *p = (LineStyleColorModifier_DistanceFromObject *)m; + if (p->target) + p->target->id.us++; + ((LineStyleColorModifier_DistanceFromObject *)new_m)->target = p->target; + ((LineStyleColorModifier_DistanceFromObject *)new_m)->color_ramp = MEM_dupallocN(p->color_ramp); + ((LineStyleColorModifier_DistanceFromObject *)new_m)->range_min = p->range_min; + ((LineStyleColorModifier_DistanceFromObject *)new_m)->range_max = p->range_max; + } + break; + case LS_MODIFIER_MATERIAL: + { + LineStyleColorModifier_Material *p = (LineStyleColorModifier_Material *)m; + ((LineStyleColorModifier_Material *)new_m)->color_ramp = MEM_dupallocN(p->color_ramp); + ((LineStyleColorModifier_Material *)new_m)->mat_attr = p->mat_attr; + } + break; + default: + return NULL; /* unknown modifier type */ + } + add_to_modifier_list(&linestyle->color_modifiers, new_m); + + return new_m; +} + +void FRS_remove_linestyle_color_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m) +{ + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + MEM_freeN(((LineStyleColorModifier_AlongStroke *)m)->color_ramp); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + MEM_freeN(((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + MEM_freeN(((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp); + break; + case LS_MODIFIER_MATERIAL: + MEM_freeN(((LineStyleColorModifier_Material *)m)->color_ramp); + break; + } + BLI_freelinkN(&linestyle->color_modifiers, m); +} + +static LineStyleModifier *alloc_alpha_modifier(int type) +{ + size_t size; + + switch (type) { + case LS_MODIFIER_ALONG_STROKE: + size = sizeof(LineStyleAlphaModifier_AlongStroke); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + size = sizeof(LineStyleAlphaModifier_DistanceFromCamera); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + size = sizeof(LineStyleAlphaModifier_DistanceFromObject); + break; + case LS_MODIFIER_MATERIAL: + size = sizeof(LineStyleAlphaModifier_Material); + break; + default: + return NULL; /* unknown modifier type */ + } + return new_modifier(type, size); +} + +LineStyleModifier *FRS_add_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, int type) +{ + LineStyleModifier *m; + + m = alloc_alpha_modifier(type); + if (!m) + return NULL; + m->blend = LS_VALUE_BLEND; + switch (type) { + case LS_MODIFIER_ALONG_STROKE: + ((LineStyleAlphaModifier_AlongStroke *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + ((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + ((LineStyleAlphaModifier_DistanceFromCamera *)m)->range_min = 0.0f; + ((LineStyleAlphaModifier_DistanceFromCamera *)m)->range_max = 10000.0f; + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + ((LineStyleAlphaModifier_DistanceFromObject *)m)->target = NULL; + ((LineStyleAlphaModifier_DistanceFromObject *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + ((LineStyleAlphaModifier_DistanceFromObject *)m)->range_min = 0.0f; + ((LineStyleAlphaModifier_DistanceFromObject *)m)->range_max = 10000.0f; + break; + case LS_MODIFIER_MATERIAL: + ((LineStyleAlphaModifier_Material *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + ((LineStyleAlphaModifier_Material *)m)->mat_attr = LS_MODIFIER_MATERIAL_DIFF; + break; + default: + return NULL; /* unknown modifier type */ + } + add_to_modifier_list(&linestyle->alpha_modifiers, m); + + return m; +} + +LineStyleModifier *FRS_copy_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m) +{ + LineStyleModifier *new_m; + + new_m = alloc_alpha_modifier(m->type); + if (!new_m) + return NULL; + new_m->influence = m->influence; + new_m->flags = m->flags; + new_m->blend = m->blend; + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + { + LineStyleAlphaModifier_AlongStroke *p = (LineStyleAlphaModifier_AlongStroke *)m; + ((LineStyleAlphaModifier_AlongStroke *)new_m)->curve = curvemapping_copy(p->curve); + } + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + { + LineStyleAlphaModifier_DistanceFromCamera *p = (LineStyleAlphaModifier_DistanceFromCamera *)m; + ((LineStyleAlphaModifier_DistanceFromCamera *)new_m)->curve = curvemapping_copy(p->curve); + ((LineStyleAlphaModifier_DistanceFromCamera *)new_m)->range_min = p->range_min; + ((LineStyleAlphaModifier_DistanceFromCamera *)new_m)->range_max = p->range_max; + } + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + { + LineStyleAlphaModifier_DistanceFromObject *p = (LineStyleAlphaModifier_DistanceFromObject *)m; + if (p->target) + p->target->id.us++; + ((LineStyleAlphaModifier_DistanceFromObject *)new_m)->target = p->target; + ((LineStyleAlphaModifier_DistanceFromObject *)new_m)->curve = curvemapping_copy(p->curve); + ((LineStyleAlphaModifier_DistanceFromObject *)new_m)->range_min = p->range_min; + ((LineStyleAlphaModifier_DistanceFromObject *)new_m)->range_max = p->range_max; + } + break; + case LS_MODIFIER_MATERIAL: + { + LineStyleAlphaModifier_Material *p = (LineStyleAlphaModifier_Material *)m; + ((LineStyleAlphaModifier_Material *)new_m)->curve = curvemapping_copy(p->curve); + ((LineStyleAlphaModifier_Material *)new_m)->mat_attr = p->mat_attr; + } + break; + default: + return NULL; /* unknown modifier type */ + } + add_to_modifier_list(&linestyle->alpha_modifiers, new_m); + + return new_m; +} + +void FRS_remove_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m) +{ + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + curvemapping_free(((LineStyleAlphaModifier_AlongStroke *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + curvemapping_free(((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + curvemapping_free(((LineStyleAlphaModifier_DistanceFromObject *)m)->curve); + break; + case LS_MODIFIER_MATERIAL: + curvemapping_free(((LineStyleAlphaModifier_Material *)m)->curve); + break; + } + BLI_freelinkN(&linestyle->alpha_modifiers, m); +} + +static LineStyleModifier *alloc_thickness_modifier(int type) +{ + size_t size; + + switch (type) { + case LS_MODIFIER_ALONG_STROKE: + size = sizeof(LineStyleThicknessModifier_AlongStroke); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + size = sizeof(LineStyleThicknessModifier_DistanceFromCamera); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + size = sizeof(LineStyleThicknessModifier_DistanceFromObject); + break; + case LS_MODIFIER_MATERIAL: + size = sizeof(LineStyleThicknessModifier_Material); + break; + case LS_MODIFIER_CALLIGRAPHY: + size = sizeof(LineStyleThicknessModifier_Calligraphy); + break; + default: + return NULL; /* unknown modifier type */ + } + return new_modifier(type, size); +} + +LineStyleModifier *FRS_add_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, int type) +{ + LineStyleModifier *m; + + m = alloc_thickness_modifier(type); + if (!m) + return NULL; + m->blend = LS_VALUE_BLEND; + switch (type) { + case LS_MODIFIER_ALONG_STROKE: + ((LineStyleThicknessModifier_AlongStroke *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + ((LineStyleThicknessModifier_AlongStroke *)m)->value_min = 0.0f; + ((LineStyleThicknessModifier_AlongStroke *)m)->value_max = 1.0f; + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + ((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + ((LineStyleThicknessModifier_DistanceFromCamera *)m)->range_min = 0.0f; + ((LineStyleThicknessModifier_DistanceFromCamera *)m)->range_max = 1000.0f; + ((LineStyleThicknessModifier_DistanceFromCamera *)m)->value_min = 0.0f; + ((LineStyleThicknessModifier_DistanceFromCamera *)m)->value_max = 1.0f; + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + ((LineStyleThicknessModifier_DistanceFromObject *)m)->target = NULL; + ((LineStyleThicknessModifier_DistanceFromObject *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + ((LineStyleThicknessModifier_DistanceFromObject *)m)->range_min = 0.0f; + ((LineStyleThicknessModifier_DistanceFromObject *)m)->range_max = 1000.0f; + ((LineStyleThicknessModifier_DistanceFromObject *)m)->value_min = 0.0f; + ((LineStyleThicknessModifier_DistanceFromObject *)m)->value_max = 1.0f; + break; + case LS_MODIFIER_MATERIAL: + ((LineStyleThicknessModifier_Material *)m)->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + ((LineStyleThicknessModifier_Material *)m)->mat_attr = LS_MODIFIER_MATERIAL_DIFF; + ((LineStyleThicknessModifier_Material *)m)->value_min = 0.0f; + ((LineStyleThicknessModifier_Material *)m)->value_max = 1.0f; + break; + case LS_MODIFIER_CALLIGRAPHY: + ((LineStyleThicknessModifier_Calligraphy *)m)->min_thickness = 1.0f; + ((LineStyleThicknessModifier_Calligraphy *)m)->max_thickness = 10.0f; + ((LineStyleThicknessModifier_Calligraphy *)m)->orientation = 60.0f; + break; + default: + return NULL; /* unknown modifier type */ + } + add_to_modifier_list(&linestyle->thickness_modifiers, m); + + return m; +} + +LineStyleModifier *FRS_copy_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m) +{ + LineStyleModifier *new_m; + + new_m = alloc_thickness_modifier(m->type); + if (!new_m) + return NULL; + new_m->influence = m->influence; + new_m->flags = m->flags; + new_m->blend = m->blend; + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + { + LineStyleThicknessModifier_AlongStroke *p = (LineStyleThicknessModifier_AlongStroke *)m; + ((LineStyleThicknessModifier_AlongStroke *)new_m)->curve = curvemapping_copy(p->curve); + ((LineStyleThicknessModifier_AlongStroke *)new_m)->value_min = p->value_min; + ((LineStyleThicknessModifier_AlongStroke *)new_m)->value_max = p->value_max; + } + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + { + LineStyleThicknessModifier_DistanceFromCamera *p = (LineStyleThicknessModifier_DistanceFromCamera *)m; + ((LineStyleThicknessModifier_DistanceFromCamera *)new_m)->curve = curvemapping_copy(p->curve); + ((LineStyleThicknessModifier_DistanceFromCamera *)new_m)->range_min = p->range_min; + ((LineStyleThicknessModifier_DistanceFromCamera *)new_m)->range_max = p->range_max; + ((LineStyleThicknessModifier_DistanceFromCamera *)new_m)->value_min = p->value_min; + ((LineStyleThicknessModifier_DistanceFromCamera *)new_m)->value_max = p->value_max; + } + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + { + LineStyleThicknessModifier_DistanceFromObject *p = (LineStyleThicknessModifier_DistanceFromObject *)m; + if (p->target) + p->target->id.us++; + ((LineStyleThicknessModifier_DistanceFromObject *)new_m)->target = p->target; + ((LineStyleThicknessModifier_DistanceFromObject *)new_m)->curve = curvemapping_copy(p->curve); + ((LineStyleThicknessModifier_DistanceFromObject *)new_m)->range_min = p->range_min; + ((LineStyleThicknessModifier_DistanceFromObject *)new_m)->range_max = p->range_max; + ((LineStyleThicknessModifier_DistanceFromObject *)new_m)->value_min = p->value_min; + ((LineStyleThicknessModifier_DistanceFromObject *)new_m)->value_max = p->value_max; + } + break; + case LS_MODIFIER_MATERIAL: + { + LineStyleThicknessModifier_Material *p = (LineStyleThicknessModifier_Material *)m; + ((LineStyleThicknessModifier_Material *)new_m)->curve = curvemapping_copy(p->curve); + ((LineStyleThicknessModifier_Material *)new_m)->mat_attr = p->mat_attr; + ((LineStyleThicknessModifier_Material *)new_m)->value_min = p->value_min; + ((LineStyleThicknessModifier_Material *)new_m)->value_max = p->value_max; + } + break; + case LS_MODIFIER_CALLIGRAPHY: + { + LineStyleThicknessModifier_Calligraphy *p = (LineStyleThicknessModifier_Calligraphy *)m; + ((LineStyleThicknessModifier_Calligraphy *)new_m)->min_thickness = p->min_thickness; + ((LineStyleThicknessModifier_Calligraphy *)new_m)->max_thickness = p->max_thickness; + ((LineStyleThicknessModifier_Calligraphy *)new_m)->orientation = p->orientation; + } + break; + default: + return NULL; /* unknown modifier type */ + } + add_to_modifier_list(&linestyle->thickness_modifiers, new_m); + + return new_m; +} + +void FRS_remove_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m) +{ + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + curvemapping_free(((LineStyleThicknessModifier_AlongStroke *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + curvemapping_free(((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve); + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + curvemapping_free(((LineStyleThicknessModifier_DistanceFromObject *)m)->curve); + break; + case LS_MODIFIER_MATERIAL: + curvemapping_free(((LineStyleThicknessModifier_Material *)m)->curve); + break; + case LS_MODIFIER_CALLIGRAPHY: + break; + } + BLI_freelinkN(&linestyle->thickness_modifiers, m); +} + +static LineStyleModifier *alloc_geometry_modifier(int type) +{ + size_t size; + + switch (type) { + case LS_MODIFIER_SAMPLING: + size = sizeof(LineStyleGeometryModifier_Sampling); + break; + case LS_MODIFIER_BEZIER_CURVE: + size = sizeof(LineStyleGeometryModifier_BezierCurve); + break; + case LS_MODIFIER_SINUS_DISPLACEMENT: + size = sizeof(LineStyleGeometryModifier_SinusDisplacement); + break; + case LS_MODIFIER_SPATIAL_NOISE: + size = sizeof(LineStyleGeometryModifier_SpatialNoise); + break; + case LS_MODIFIER_PERLIN_NOISE_1D: + size = sizeof(LineStyleGeometryModifier_PerlinNoise1D); + break; + case LS_MODIFIER_PERLIN_NOISE_2D: + size = sizeof(LineStyleGeometryModifier_PerlinNoise2D); + break; + case LS_MODIFIER_BACKBONE_STRETCHER: + size = sizeof(LineStyleGeometryModifier_BackboneStretcher); + break; + case LS_MODIFIER_TIP_REMOVER: + size = sizeof(LineStyleGeometryModifier_TipRemover); + break; + case LS_MODIFIER_POLYGONIZATION: + size = sizeof(LineStyleGeometryModifier_Polygonalization); + break; + case LS_MODIFIER_GUIDING_LINES: + size = sizeof(LineStyleGeometryModifier_GuidingLines); + break; + case LS_MODIFIER_BLUEPRINT: + size = sizeof(LineStyleGeometryModifier_Blueprint); + break; + case LS_MODIFIER_2D_OFFSET: + size = sizeof(LineStyleGeometryModifier_2DOffset); + break; + case LS_MODIFIER_2D_TRANSFORM: + size = sizeof(LineStyleGeometryModifier_2DTransform); + break; + default: + return NULL; /* unknown modifier type */ + } + return new_modifier(type, size); +} + +LineStyleModifier *FRS_add_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, int type) +{ + LineStyleModifier *m; + + m = alloc_geometry_modifier(type); + if (!m) + return NULL; + switch (type) { + case LS_MODIFIER_SAMPLING: + ((LineStyleGeometryModifier_Sampling *)m)->sampling = 10.0; + break; + case LS_MODIFIER_BEZIER_CURVE: + ((LineStyleGeometryModifier_BezierCurve *)m)->error = 10.0; + break; + case LS_MODIFIER_SINUS_DISPLACEMENT: + ((LineStyleGeometryModifier_SinusDisplacement *)m)->wavelength = 20.0; + ((LineStyleGeometryModifier_SinusDisplacement *)m)->amplitude = 5.0; + ((LineStyleGeometryModifier_SinusDisplacement *)m)->phase = 0.0; + break; + case LS_MODIFIER_SPATIAL_NOISE: + ((LineStyleGeometryModifier_SpatialNoise *)m)->amplitude = 5.0; + ((LineStyleGeometryModifier_SpatialNoise *)m)->scale = 20.0; + ((LineStyleGeometryModifier_SpatialNoise *)m)->octaves = 4; + ((LineStyleGeometryModifier_SpatialNoise *)m)->flags = LS_MODIFIER_SPATIAL_NOISE_SMOOTH | LS_MODIFIER_SPATIAL_NOISE_PURERANDOM; + break; + case LS_MODIFIER_PERLIN_NOISE_1D: + ((LineStyleGeometryModifier_PerlinNoise1D *)m)->frequency = 10.0; + ((LineStyleGeometryModifier_PerlinNoise1D *)m)->amplitude = 10.0; + ((LineStyleGeometryModifier_PerlinNoise1D *)m)->octaves = 4; + ((LineStyleGeometryModifier_PerlinNoise1D *)m)->angle = 45.0; + break; + case LS_MODIFIER_PERLIN_NOISE_2D: + ((LineStyleGeometryModifier_PerlinNoise2D *)m)->frequency = 10.0; + ((LineStyleGeometryModifier_PerlinNoise2D *)m)->amplitude = 10.0; + ((LineStyleGeometryModifier_PerlinNoise2D *)m)->octaves = 4; + ((LineStyleGeometryModifier_PerlinNoise2D *)m)->angle = 45.0; + break; + case LS_MODIFIER_BACKBONE_STRETCHER: + ((LineStyleGeometryModifier_BackboneStretcher *)m)->backbone_length = 10.0; + break; + case LS_MODIFIER_TIP_REMOVER: + ((LineStyleGeometryModifier_TipRemover *)m)->tip_length = 10.0; + break; + case LS_MODIFIER_POLYGONIZATION: + ((LineStyleGeometryModifier_Polygonalization *)m)->error = 10.0; + break; + case LS_MODIFIER_GUIDING_LINES: + ((LineStyleGeometryModifier_GuidingLines *)m)->offset = 0.0; + break; + case LS_MODIFIER_BLUEPRINT: + ((LineStyleGeometryModifier_Blueprint *)m)->flags = LS_MODIFIER_BLUEPRINT_CIRCLES; + ((LineStyleGeometryModifier_Blueprint *)m)->rounds = 1; + ((LineStyleGeometryModifier_Blueprint *)m)->backbone_length = 10.f; + ((LineStyleGeometryModifier_Blueprint *)m)->random_radius = 3; + ((LineStyleGeometryModifier_Blueprint *)m)->random_center = 5; + ((LineStyleGeometryModifier_Blueprint *)m)->random_backbone = 5; + break; + case LS_MODIFIER_2D_OFFSET: + ((LineStyleGeometryModifier_2DOffset *)m)->start = 0.f; + ((LineStyleGeometryModifier_2DOffset *)m)->end = 0.f; + ((LineStyleGeometryModifier_2DOffset *)m)->x = 0.f; + ((LineStyleGeometryModifier_2DOffset *)m)->y = 0.f; + break; + case LS_MODIFIER_2D_TRANSFORM: + ((LineStyleGeometryModifier_2DTransform *)m)->pivot = LS_MODIFIER_2D_TRANSFORM_PIVOT_CENTER; + ((LineStyleGeometryModifier_2DTransform *)m)->scale_x = 1.f; + ((LineStyleGeometryModifier_2DTransform *)m)->scale_y = 1.f; + ((LineStyleGeometryModifier_2DTransform *)m)->angle = 0.f; + ((LineStyleGeometryModifier_2DTransform *)m)->pivot_u = 0.5f; + ((LineStyleGeometryModifier_2DTransform *)m)->pivot_x = 0.f; + ((LineStyleGeometryModifier_2DTransform *)m)->pivot_y = 0.f; + break; + default: + return NULL; /* unknown modifier type */ + } + add_to_modifier_list(&linestyle->geometry_modifiers, m); + + return m; +} + +LineStyleModifier *FRS_copy_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m) +{ + LineStyleModifier *new_m; + + new_m = alloc_geometry_modifier(m->type); + if (!new_m) + return NULL; + new_m->flags = m->flags; + switch (m->type) { + case LS_MODIFIER_SAMPLING: + { + LineStyleGeometryModifier_Sampling *p = (LineStyleGeometryModifier_Sampling *)m; + ((LineStyleGeometryModifier_Sampling *)new_m)->sampling = p->sampling; + } + break; + case LS_MODIFIER_BEZIER_CURVE: + { + LineStyleGeometryModifier_BezierCurve *p = (LineStyleGeometryModifier_BezierCurve *)m; + ((LineStyleGeometryModifier_BezierCurve *)new_m)->error = p->error; + } + break; + case LS_MODIFIER_SINUS_DISPLACEMENT: + { + LineStyleGeometryModifier_SinusDisplacement *p = (LineStyleGeometryModifier_SinusDisplacement *)m; + ((LineStyleGeometryModifier_SinusDisplacement *)new_m)->wavelength = p->wavelength; + ((LineStyleGeometryModifier_SinusDisplacement *)new_m)->amplitude = p->amplitude; + ((LineStyleGeometryModifier_SinusDisplacement *)new_m)->phase = p->phase; + } + break; + case LS_MODIFIER_SPATIAL_NOISE: + { + LineStyleGeometryModifier_SpatialNoise *p = (LineStyleGeometryModifier_SpatialNoise *)m; + ((LineStyleGeometryModifier_SpatialNoise *)new_m)->amplitude = p->amplitude; + ((LineStyleGeometryModifier_SpatialNoise *)new_m)->scale = p->scale; + ((LineStyleGeometryModifier_SpatialNoise *)new_m)->octaves = p->octaves; + ((LineStyleGeometryModifier_SpatialNoise *)new_m)->flags = p->flags; + } + break; + case LS_MODIFIER_PERLIN_NOISE_1D: + { + LineStyleGeometryModifier_PerlinNoise1D *p = (LineStyleGeometryModifier_PerlinNoise1D *)m; + ((LineStyleGeometryModifier_PerlinNoise1D *)new_m)->frequency = p->frequency; + ((LineStyleGeometryModifier_PerlinNoise1D *)new_m)->amplitude = p->amplitude; + ((LineStyleGeometryModifier_PerlinNoise1D *)new_m)->octaves = p->octaves; + ((LineStyleGeometryModifier_PerlinNoise1D *)new_m)->angle = p->angle; + } + break; + case LS_MODIFIER_PERLIN_NOISE_2D: + { + LineStyleGeometryModifier_PerlinNoise2D *p = (LineStyleGeometryModifier_PerlinNoise2D *)m; + ((LineStyleGeometryModifier_PerlinNoise2D *)new_m)->frequency = p->frequency; + ((LineStyleGeometryModifier_PerlinNoise2D *)new_m)->amplitude = p->amplitude; + ((LineStyleGeometryModifier_PerlinNoise2D *)new_m)->octaves = p->octaves; + ((LineStyleGeometryModifier_PerlinNoise2D *)new_m)->angle = p->angle; + } + break; + case LS_MODIFIER_BACKBONE_STRETCHER: + { + LineStyleGeometryModifier_BackboneStretcher *p = (LineStyleGeometryModifier_BackboneStretcher *)m; + ((LineStyleGeometryModifier_BackboneStretcher *)new_m)->backbone_length = p->backbone_length; + } + break; + case LS_MODIFIER_TIP_REMOVER: + { + LineStyleGeometryModifier_TipRemover *p = (LineStyleGeometryModifier_TipRemover *)m; + ((LineStyleGeometryModifier_TipRemover *)new_m)->tip_length = p->tip_length; + } + break; + case LS_MODIFIER_POLYGONIZATION: + { + LineStyleGeometryModifier_Polygonalization *p = (LineStyleGeometryModifier_Polygonalization *)m; + ((LineStyleGeometryModifier_Polygonalization *)new_m)->error = p->error; + } + break; + case LS_MODIFIER_GUIDING_LINES: + { + LineStyleGeometryModifier_GuidingLines *p = (LineStyleGeometryModifier_GuidingLines *)m; + ((LineStyleGeometryModifier_GuidingLines *)new_m)->offset = p->offset; + } + break; + case LS_MODIFIER_BLUEPRINT: + { + LineStyleGeometryModifier_Blueprint *p = (LineStyleGeometryModifier_Blueprint *)m; + ((LineStyleGeometryModifier_Blueprint *)new_m)->flags = p->flags; + ((LineStyleGeometryModifier_Blueprint *)new_m)->rounds = p->rounds; + ((LineStyleGeometryModifier_Blueprint *)new_m)->backbone_length = p->backbone_length; + ((LineStyleGeometryModifier_Blueprint *)new_m)->random_radius = p->random_radius; + ((LineStyleGeometryModifier_Blueprint *)new_m)->random_center = p->random_center; + ((LineStyleGeometryModifier_Blueprint *)new_m)->random_backbone = p->random_backbone; + } + break; + case LS_MODIFIER_2D_OFFSET: + { + LineStyleGeometryModifier_2DOffset *p = (LineStyleGeometryModifier_2DOffset *)m; + ((LineStyleGeometryModifier_2DOffset *)new_m)->start = p->start; + ((LineStyleGeometryModifier_2DOffset *)new_m)->end = p->end; + ((LineStyleGeometryModifier_2DOffset *)new_m)->x = p->x; + ((LineStyleGeometryModifier_2DOffset *)new_m)->y = p->y; + } + break; + case LS_MODIFIER_2D_TRANSFORM: + { + LineStyleGeometryModifier_2DTransform *p = (LineStyleGeometryModifier_2DTransform *)m; + ((LineStyleGeometryModifier_2DTransform *)new_m)->pivot = p->pivot; + ((LineStyleGeometryModifier_2DTransform *)new_m)->scale_x = p->scale_x; + ((LineStyleGeometryModifier_2DTransform *)new_m)->scale_y = p->scale_y; + ((LineStyleGeometryModifier_2DTransform *)new_m)->angle = p->angle; + ((LineStyleGeometryModifier_2DTransform *)new_m)->pivot_u = p->pivot_u; + ((LineStyleGeometryModifier_2DTransform *)new_m)->pivot_x = p->pivot_x; + ((LineStyleGeometryModifier_2DTransform *)new_m)->pivot_y = p->pivot_y; + } + break; + default: + return NULL; /* unknown modifier type */ + } + add_to_modifier_list(&linestyle->geometry_modifiers, new_m); + + return new_m; +} + +void FRS_remove_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m) +{ + switch (m->type) { + case LS_MODIFIER_SAMPLING: + break; + case LS_MODIFIER_BEZIER_CURVE: + break; + case LS_MODIFIER_SINUS_DISPLACEMENT: + break; + case LS_MODIFIER_SPATIAL_NOISE: + break; + case LS_MODIFIER_PERLIN_NOISE_1D: + break; + case LS_MODIFIER_PERLIN_NOISE_2D: + break; + case LS_MODIFIER_BACKBONE_STRETCHER: + break; + case LS_MODIFIER_TIP_REMOVER: + break; + case LS_MODIFIER_POLYGONIZATION: + break; + case LS_MODIFIER_GUIDING_LINES: + break; + case LS_MODIFIER_BLUEPRINT: + break; + case LS_MODIFIER_2D_OFFSET: + break; + case LS_MODIFIER_2D_TRANSFORM: + break; + } + BLI_freelinkN(&linestyle->geometry_modifiers, m); +} + +static void move_modifier(ListBase *lb, LineStyleModifier *modifier, int direction) +{ + BLI_remlink(lb, modifier); + if (direction > 0) + BLI_insertlinkbefore(lb, modifier->prev, modifier); + else + BLI_insertlinkafter(lb, modifier->next, modifier); +} + +void FRS_move_linestyle_color_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction) +{ + move_modifier(&linestyle->color_modifiers, modifier, direction); +} + +void FRS_move_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction) +{ + move_modifier(&linestyle->alpha_modifiers, modifier, direction); +} + +void FRS_move_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction) +{ + move_modifier(&linestyle->thickness_modifiers, modifier, direction); +} + +void FRS_move_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction) +{ + move_modifier(&linestyle->geometry_modifiers, modifier, direction); +} + +void FRS_list_modifier_color_ramps(FreestyleLineStyle *linestyle, ListBase *listbase) +{ + LineStyleModifier *m; + ColorBand *color_ramp; + LinkData *link; + + listbase->first = listbase->last = NULL; + for (m = (LineStyleModifier *)linestyle->color_modifiers.first; m; m = m->next) { + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + color_ramp = ((LineStyleColorModifier_AlongStroke *)m)->color_ramp; + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + color_ramp = ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp; + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + color_ramp = ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp; + break; + case LS_MODIFIER_MATERIAL: + color_ramp = ((LineStyleColorModifier_Material *)m)->color_ramp; + break; + default: + continue; + } + link = (LinkData *) MEM_callocN( sizeof(LinkData), "link to color ramp"); + link->data = color_ramp; + BLI_addtail(listbase, link); + } +} + +char *FRS_path_from_ID_to_color_ramp(FreestyleLineStyle *linestyle, ColorBand *color_ramp) +{ + LineStyleModifier *m; + + for (m = (LineStyleModifier *)linestyle->color_modifiers.first; m; m = m->next) { + switch (m->type) { + case LS_MODIFIER_ALONG_STROKE: + if (color_ramp == ((LineStyleColorModifier_AlongStroke *)m)->color_ramp) + goto found; + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + if (color_ramp == ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp) + goto found; + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + if (color_ramp == ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp) + goto found; + break; + case LS_MODIFIER_MATERIAL: + if (color_ramp == ((LineStyleColorModifier_Material *)m)->color_ramp) + goto found; + break; + } + } + printf("FRS_path_from_ID_to_color_ramp: No color ramps correspond to the given pointer.\n"); + return NULL; + +found: + return BLI_sprintfN("color_modifiers[\"%s\"].color_ramp", m->name); +} + +void FRS_unlink_linestyle_target_object(FreestyleLineStyle *linestyle, struct Object *ob) +{ + LineStyleModifier *m; + + for (m = (LineStyleModifier *)linestyle->color_modifiers.first; m; m = m->next) { + if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { + if (((LineStyleColorModifier_DistanceFromObject *)m)->target == ob) { + ((LineStyleColorModifier_DistanceFromObject *)m)->target = NULL; + } + } + } + for (m = (LineStyleModifier *)linestyle->alpha_modifiers.first; m; m = m->next) { + if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { + if (((LineStyleAlphaModifier_DistanceFromObject *)m)->target == ob) { + ((LineStyleAlphaModifier_DistanceFromObject *)m)->target = NULL; + } + } + } + for (m = (LineStyleModifier *)linestyle->thickness_modifiers.first; m; m = m->next) { + if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { + if (((LineStyleThicknessModifier_DistanceFromObject *)m)->target == ob) { + ((LineStyleThicknessModifier_DistanceFromObject *)m)->target = NULL; + } + } + } +} diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index f685d0ec151..5f7f7ab5920 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -146,6 +146,7 @@ void init_material(Material *ma) ma->tx_limit= 0.0; ma->tx_falloff= 1.0; ma->shad_alpha= 1.0f; + ma->vcol_alpha= 0; ma->gloss_mir = ma->gloss_tra= 1.0; ma->samp_gloss_mir = ma->samp_gloss_tra= 18; diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index d2b81a345a7..58fc3378476 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -110,6 +110,8 @@ #include "GPU_material.h" +#include "FRS_freestyle.h" + /* Local function protos */ static void solve_parenting (Scene *scene, Object *ob, Object *par, float obmat[][4], float slowmat[][4], int simul); @@ -604,6 +606,14 @@ void unlink_object(Object *ob) } SEQ_END } + + { + SceneRenderLayer *srl; + + for (srl= sce->r.layers.first; srl; srl= srl->next) { + FRS_unlink_target_object(&srl->freestyleConfig, ob); + } + } } sce= sce->id.next; diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index c8ec71d512f..2aa53e2484d 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -78,6 +78,8 @@ //XXX #include "BIF_previewrender.h" //XXX #include "BIF_editseq.h" +#include "FRS_freestyle_config.h" + #ifdef WIN32 #else #include <sys/time.h> @@ -240,7 +242,8 @@ Scene *copy_scene(Scene *sce, int type) void free_scene(Scene *sce) { Base *base; - + SceneRenderLayer *srl; + base= sce->base.first; while(base) { base->object->id.us--; @@ -280,6 +283,10 @@ void free_scene(Scene *sce) sce->r.ffcodecdata.properties = NULL; } + for(srl= sce->r.layers.first; srl; srl= srl->next) { + FRS_free_freestyle_config(srl); + } + BLI_freelistN(&sce->markers); BLI_freelistN(&sce->transform_spaces); BLI_freelistN(&sce->r.layers); @@ -1104,6 +1111,7 @@ SceneRenderLayer *scene_add_render_layer(Scene *sce, const char *name) srl->lay= (1<<20) -1; srl->layflag= 0x7FFF; /* solid ztra halo edge strand */ srl->passflag= SCE_PASS_COMBINED|SCE_PASS_Z; + FRS_add_freestyle_config( srl ); return srl; } diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c index 4e88a488530..f0dea976aa9 100644 --- a/source/blender/blenkernel/intern/subsurf_ccg.c +++ b/source/blender/blenkernel/intern/subsurf_ccg.c @@ -752,7 +752,7 @@ static void ccgDM_getFinalEdge(DerivedMesh *dm, int edgeNum, MEdge *med) edgeFlag = (ccgdm->edgeFlags)? &ccgdm->edgeFlags[i]: NULL; if(edgeFlag) - flags |= (*edgeFlag & (ME_SEAM | ME_SHARP)) + flags |= (*edgeFlag & (ME_SEAM | ME_SHARP | ME_FREESTYLE_EDGE)) | ME_EDGEDRAW | ME_EDGERENDER; else flags |= ME_EDGEDRAW | ME_EDGERENDER; @@ -937,7 +937,7 @@ static void ccgDM_copyFinalEdgeArray(DerivedMesh *dm, MEdge *medge) if(edgeFlags) { if(edgeIdx != -1) { - flags |= (edgeFlags[index] & (ME_SEAM | ME_SHARP)) + flags |= (edgeFlags[index] & (ME_SEAM | ME_SHARP | ME_FREESTYLE_EDGE)) | ME_EDGEDRAW | ME_EDGERENDER; } } else { |