diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2013-04-06 19:45:02 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2013-04-06 19:45:02 +0400 |
commit | 464a149b2120f65aef4a667ae27e608e82775497 (patch) | |
tree | e45545ed49357fc4332916b458d6f287abd00827 /source/blender/blenkernel | |
parent | f62d2669def640f2e448e8d677af0c04b5b53439 (diff) | |
parent | 4c16d3e2316f910b636fc63a20a385ea0dbf6436 (diff) |
Part I of the Freestyle branch merger: new 'freestyle' folders.
This commit is the first part of a two-part merger of the soc-2008-mxcurioni
(Freestyle) branch. New 'freestyle' folders were added to the source/blender/
and release/script/ directories through a couple of svn copy operations
(instead of svn merge, due to broken svn:mergeinfo properties of the branch).
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_freestyle.h | 64 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_global.h | 6 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_linestyle.h | 76 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_main.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/CMakeLists.txt | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/SConscript | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/anim_sys.c | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/bpath.c | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/customdata.c | 15 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/freestyle.c | 230 | ||||
-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 | 1070 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/material.c | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/object.c | 11 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 15 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 13 |
18 files changed, 1539 insertions, 7 deletions
diff --git a/source/blender/blenkernel/BKE_freestyle.h b/source/blender/blenkernel/BKE_freestyle.h new file mode 100644 index 00000000000..84a4bc255af --- /dev/null +++ b/source/blender/blenkernel/BKE_freestyle.h @@ -0,0 +1,64 @@ +/* + * ***** 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) 2013 Blender Foundation + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __BKE_FREESTYLE_H__ +#define __BKE_FREESTYLE_H__ + +/** \file BKE_freestyle.h + * \ingroup bke + */ + +#include "DNA_scene_types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* FreestyleConfig */ +void BKE_freestyle_config_init(FreestyleConfig *config); +void BKE_freestyle_config_free(FreestyleConfig *config); +void BKE_freestyle_config_copy(FreestyleConfig *new_config, FreestyleConfig *config); + +/* FreestyleConfig.modules */ +void BKE_freestyle_module_add(FreestyleConfig *config); +void BKE_freestyle_module_delete(FreestyleConfig *config, FreestyleModuleConfig *module_conf); +void BKE_freestyle_module_move_up(FreestyleConfig *config, FreestyleModuleConfig *module_conf); +void BKE_freestyle_module_move_down(FreestyleConfig *config, FreestyleModuleConfig *module_conf); + +/* FreestyleConfig.linesets */ +FreestyleLineSet *BKE_freestyle_lineset_add(FreestyleConfig *config); +FreestyleLineSet *BKE_freestyle_lineset_get_active(FreestyleConfig *config); +short BKE_freestyle_lineset_get_active_index(FreestyleConfig *config); +void BKE_freestyle_lineset_set_active_index(FreestyleConfig *config, short index); +void BKE_freestyle_lineset_unique_name(FreestyleConfig *config, FreestyleLineSet *lineset); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h index 5458568433d..5d8b6983aad 100644 --- a/source/blender/blenkernel/BKE_global.h +++ b/source/blender/blenkernel/BKE_global.h @@ -132,10 +132,12 @@ enum { G_DEBUG_EVENTS = (1 << 3), /* input/window/screen events */ G_DEBUG_HANDLERS = (1 << 4), /* events handling */ G_DEBUG_WM = (1 << 5), /* operator, undo */ - G_DEBUG_JOBS = (1 << 6) /* jobs time profiling */ + G_DEBUG_JOBS = (1 << 6), /* jobs time profiling */ + G_DEBUG_FREESTYLE = (1 << 7), /* freestyle messages */ }; -#define G_DEBUG_ALL (G_DEBUG | G_DEBUG_FFMPEG | G_DEBUG_PYTHON | G_DEBUG_EVENTS | G_DEBUG_WM | G_DEBUG_JOBS) +#define G_DEBUG_ALL (G_DEBUG | G_DEBUG_FFMPEG | G_DEBUG_PYTHON | G_DEBUG_EVENTS | G_DEBUG_WM | G_DEBUG_JOBS | \ + G_DEBUG_FREESTYLE) /* G.fileflags */ diff --git a/source/blender/blenkernel/BKE_linestyle.h b/source/blender/blenkernel/BKE_linestyle.h new file mode 100644 index 00000000000..13d111cb93b --- /dev/null +++ b/source/blender/blenkernel/BKE_linestyle.h @@ -0,0 +1,76 @@ +/* + * ***** 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__ + +/** \file BKE_linestyle.h + * \ingroup bke + * \brief Blender kernel freestyle line style functionality. + */ + +#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; +struct ColorBand; + +FreestyleLineStyle *BKE_new_linestyle(const char *name, struct Main *main); +void BKE_free_linestyle(FreestyleLineStyle *linestyle); +FreestyleLineStyle *BKE_copy_linestyle(FreestyleLineStyle *linestyle); + +LineStyleModifier *BKE_add_linestyle_color_modifier(FreestyleLineStyle *linestyle, int type); +LineStyleModifier *BKE_add_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, int type); +LineStyleModifier *BKE_add_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, int type); +LineStyleModifier *BKE_add_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, int type); + +LineStyleModifier *BKE_copy_linestyle_color_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m); +LineStyleModifier *BKE_copy_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m); +LineStyleModifier *BKE_copy_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m); +LineStyleModifier *BKE_copy_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m); + +void BKE_remove_linestyle_color_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier); +void BKE_remove_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier); +void BKE_remove_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier); +void BKE_remove_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier); + +void BKE_move_linestyle_color_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction); +void BKE_move_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction); +void BKE_move_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction); +void BKE_move_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction); + +void BKE_list_modifier_color_ramps(FreestyleLineStyle *linestyle, ListBase *listbase); +char *BKE_path_from_ID_to_color_ramp(FreestyleLineStyle *linestyle, struct ColorBand *color_ramp); + +void BKE_unlink_linestyle_target_object(FreestyleLineStyle *linestyle, struct Object *ob); + +#endif /* __BKE_LINESTYLE_H__ */ diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h index 2dc0a36adb6..264a7421e91 100644 --- a/source/blender/blenkernel/BKE_main.h +++ b/source/blender/blenkernel/BKE_main.h @@ -88,6 +88,7 @@ typedef struct Main { ListBase gpencil; ListBase movieclip; ListBase mask; + ListBase linestyle; char id_tag_update[256]; } Main; diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt index 674bfcdf2ca..875f02def13 100644 --- a/source/blender/blenkernel/CMakeLists.txt +++ b/source/blender/blenkernel/CMakeLists.txt @@ -89,6 +89,7 @@ set(SRC intern/fluidsim.c intern/fmodifier.c intern/font.c + intern/freestyle.c intern/gpencil.c intern/group.c intern/icons.c @@ -102,6 +103,7 @@ set(SRC intern/lamp.c intern/lattice.c intern/library.c + intern/linestyle.c intern/mask.c intern/mask_evaluate.c intern/mask_rasterize.c @@ -186,6 +188,7 @@ set(SRC BKE_fcurve.h BKE_fluidsim.h BKE_font.h + BKE_freestyle.h BKE_global.h BKE_gpencil.h BKE_group.h @@ -198,6 +201,7 @@ set(SRC BKE_lamp.h BKE_lattice.h BKE_library.h + BKE_linestyle.h BKE_main.h BKE_mask.h BKE_material.h @@ -422,6 +426,10 @@ if(WITH_INTERNATIONAL) add_definitions(-DWITH_INTERNATIONAL) endif() +if(WITH_FREESTYLE) + add_definitions(-DWITH_FREESTYLE) +endif() + ## Warnings as errors, this is too strict! #if(MSVC) # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX") diff --git a/source/blender/blenkernel/SConscript b/source/blender/blenkernel/SConscript index aa7d8a51b8c..c21cd168874 100644 --- a/source/blender/blenkernel/SConscript +++ b/source/blender/blenkernel/SConscript @@ -148,6 +148,9 @@ if env['WITH_BF_FFTW3']: if env['WITH_BF_INTERNATIONAL']: defs.append('WITH_INTERNATIONAL') +if env['WITH_BF_FREESTYLE']: + defs.append('WITH_FREESTYLE') + if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw', 'linuxcross', 'win64-vc', 'win64-mingw'): incs += ' ' + env['BF_PTHREADS_INC'] diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 2c7339122f4..9cdb35586ce 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -88,6 +88,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: @@ -829,6 +830,9 @@ void BKE_animdata_main_cb(Main *mainptr, ID_AnimData_Edit_Callback func, void *u /* 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) @@ -914,6 +918,9 @@ void BKE_all_animdata_fix_paths_rename(ID *ref_id, const char *prefix, const cha /* worlds */ RENAMEFIX_ANIM_NODETREE_IDS(mainptr->world.first, World); + /* linestyles */ + RENAMEFIX_ANIM_IDS(mainptr->linestyle.first); + /* scenes */ RENAMEFIX_ANIM_NODETREE_IDS(mainptr->scene.first, Scene); } @@ -2399,6 +2406,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 optimization means that objects diff --git a/source/blender/blenkernel/intern/bpath.c b/source/blender/blenkernel/intern/bpath.c index da8b97976f3..fe86b413a99 100644 --- a/source/blender/blenkernel/intern/bpath.c +++ b/source/blender/blenkernel/intern/bpath.c @@ -70,6 +70,7 @@ #include "DNA_vfont_types.h" #include "DNA_scene_types.h" #include "DNA_smoke_types.h" +#include "DNA_freestyle_types.h" #include "BLI_blenlib.h" #include "BLI_utildefines.h" diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 74ad1ab4c0b..2118bbcd42b 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -1143,7 +1143,11 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = { layerFree_grid_paint_mask, NULL, NULL, NULL}, /* 36: CD_SKIN_NODE */ {sizeof(MVertSkin), "MVertSkin", 1, NULL, NULL, NULL, - layerInterp_mvert_skin, NULL, layerDefault_mvert_skin} + layerInterp_mvert_skin, NULL, layerDefault_mvert_skin}, + /* 37: CD_FREESTYLE_EDGE */ + {sizeof(FreestyleEdge), "FreestyleEdge", 1, NULL, NULL, NULL, NULL, NULL, NULL}, + /* 38: CD_FREESTYLE_FACE */ + {sizeof(FreestyleFace), "FreestyleFace", 1, NULL, NULL, NULL, NULL, NULL, NULL} }; /* note, numbers are from trunk and need updating for bmesh */ @@ -1158,7 +1162,8 @@ static const char *LAYERTYPENAMES[CD_NUMTYPES] = { /* BMESH ONLY */ /* 25-29 */ "CDMPoly", "CDMLoop", "CDShapeKeyIndex", "CDShapeKey", "CDBevelWeight", /* 30-34 */ "CDSubSurfCrease", "CDOrigSpaceLoop", "CDPreviewLoopCol", "CDBMElemPyPtr", "CDPaintMask", - /* 35-36 */ "CDGridPaintMask", "CDMVertSkin" + /* 35-36 */ "CDGridPaintMask", "CDMVertSkin", + /* 37-38 */ "CDFreestyleEdge", "CDFreestyleFace" }; @@ -1170,7 +1175,7 @@ const CustomDataMask CD_MASK_MESH = CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MPOLY | CD_MASK_MLOOP | CD_MASK_MTEXPOLY | CD_MASK_RECAST | CD_MASK_PAINT_MASK | - CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN; + CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE; const CustomDataMask CD_MASK_EDITMESH = CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MTFACE | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_SHAPE_KEYINDEX | @@ -1183,13 +1188,13 @@ const CustomDataMask CD_MASK_DERIVEDMESH = CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_PREVIEW_MLOOPCOL | CD_MASK_PROP_STR | CD_MASK_ORIGSPACE | CD_MASK_ORIGSPACE_MLOOP | CD_MASK_ORCO | CD_MASK_TANGENT | CD_MASK_PREVIEW_MCOL | CD_MASK_NORMAL | CD_MASK_SHAPEKEY | CD_MASK_RECAST | - CD_MASK_ORIGINDEX | CD_MASK_MVERT_SKIN; + CD_MASK_ORIGINDEX | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE; const CustomDataMask CD_MASK_BMESH = CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_SHAPEKEY | CD_MASK_SHAPE_KEYINDEX | CD_MASK_MDISPS | CD_MASK_CREASE | CD_MASK_BWEIGHT | CD_MASK_RECAST | CD_MASK_PAINT_MASK | - CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN; + CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE; const CustomDataMask CD_MASK_FACECORNERS = CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_MTEXPOLY | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL; diff --git a/source/blender/blenkernel/intern/freestyle.c b/source/blender/blenkernel/intern/freestyle.c new file mode 100644 index 00000000000..b514b004170 --- /dev/null +++ b/source/blender/blenkernel/intern/freestyle.c @@ -0,0 +1,230 @@ +/* + * ***** 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) 2013 Blender Foundation + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/blenkernel/intern/freestyle.c + * \ingroup bke + */ + +#include "MEM_guardedalloc.h" + +#include "DNA_freestyle_types.h" +#include "DNA_group_types.h" + +#include "BKE_freestyle.h" +#include "BKE_linestyle.h" + +#include "BLI_blenlib.h" +#include "BLI_math.h" + +// function declarations +static FreestyleLineSet *alloc_lineset(void); +static void copy_lineset(FreestyleLineSet *new_lineset, FreestyleLineSet *lineset); +static FreestyleModuleConfig *alloc_module(void); +static void copy_module(FreestyleModuleConfig *new_module, FreestyleModuleConfig *module); + +void BKE_freestyle_config_init(FreestyleConfig *config) +{ + config->mode = FREESTYLE_CONTROL_EDITOR_MODE; + + config->modules.first = config->modules.last = NULL; + config->flags = 0; + config->sphere_radius = 1.0f; + config->dkr_epsilon = 0.0f; + config->crease_angle = DEG2RADF(134.43f); + + config->linesets.first = config->linesets.last = NULL; +} + +void BKE_freestyle_config_free(FreestyleConfig *config) +{ + FreestyleLineSet *lineset; + + for (lineset = (FreestyleLineSet *)config->linesets.first; lineset; lineset = lineset->next) { + if (lineset->group) { + lineset->group->id.us--; + lineset->group = NULL; + } + lineset->linestyle->id.us--; + lineset->linestyle = NULL; + } + BLI_freelistN(&config->linesets); + BLI_freelistN(&config->modules); +} + +void BKE_freestyle_config_copy(FreestyleConfig *new_config, FreestyleConfig *config) +{ + FreestyleLineSet *lineset, *new_lineset; + FreestyleModuleConfig *module, *new_module; + + new_config->mode = config->mode; + new_config->raycasting_algorithm = config->raycasting_algorithm; /* deprecated */ + new_config->flags = config->flags; + new_config->sphere_radius = config->sphere_radius; + new_config->dkr_epsilon = config->dkr_epsilon; + new_config->crease_angle = config->crease_angle; + + new_config->linesets.first = new_config->linesets.last = NULL; + for (lineset = (FreestyleLineSet *)config->linesets.first; lineset; lineset = lineset->next) { + new_lineset = alloc_lineset(); + copy_lineset(new_lineset, lineset); + BLI_addtail(&new_config->linesets, (void *)new_lineset); + } + + new_config->modules.first = new_config->modules.last = NULL; + for (module = (FreestyleModuleConfig *)config->modules.first; module; module = module->next) { + new_module = alloc_module(); + copy_module(new_module, module); + BLI_addtail(&new_config->modules, (void *)new_module); + } +} + +static void copy_lineset(FreestyleLineSet *new_lineset, FreestyleLineSet *lineset) +{ + new_lineset->linestyle = lineset->linestyle; + new_lineset->linestyle->id.us++; + new_lineset->flags = lineset->flags; + new_lineset->selection = lineset->selection; + new_lineset->qi = lineset->qi; + new_lineset->qi_start = lineset->qi_start; + new_lineset->qi_end = lineset->qi_end; + new_lineset->edge_types = lineset->edge_types; + new_lineset->exclude_edge_types = lineset->exclude_edge_types; + new_lineset->group = lineset->group; + if (new_lineset->group) { + new_lineset->group->id.us++; + } + strcpy(new_lineset->name, lineset->name); +} + +static FreestyleModuleConfig *alloc_module(void) +{ + return (FreestyleModuleConfig *)MEM_callocN(sizeof(FreestyleModuleConfig), "style module configuration"); +} + +void BKE_freestyle_module_add(FreestyleConfig *config) +{ + FreestyleModuleConfig *module_conf = alloc_module(); + BLI_addtail(&config->modules, (void *)module_conf); + module_conf->script = NULL; + module_conf->is_displayed = 1; +} + +static void copy_module(FreestyleModuleConfig *new_module, FreestyleModuleConfig *module) +{ + new_module->script = module->script; + new_module->is_displayed = module->is_displayed; +} + +void BKE_freestyle_module_delete(FreestyleConfig *config, FreestyleModuleConfig *module_conf) +{ + BLI_freelinkN(&config->modules, module_conf); +} + +void BKE_freestyle_module_move_up(FreestyleConfig *config, FreestyleModuleConfig *module_conf) +{ + BLI_remlink(&config->modules, module_conf); + BLI_insertlinkbefore(&config->modules, module_conf->prev, module_conf); +} + +void BKE_freestyle_module_move_down(FreestyleConfig *config, FreestyleModuleConfig *module_conf) +{ + BLI_remlink(&config->modules, module_conf); + BLI_insertlinkafter(&config->modules, module_conf->next, module_conf); +} + +void BKE_freestyle_lineset_unique_name(FreestyleConfig *config, FreestyleLineSet *lineset) +{ + BLI_uniquename(&config->linesets, lineset, "FreestyleLineSet", '.', offsetof(FreestyleLineSet, name), + sizeof(lineset->name)); +} + +static FreestyleLineSet *alloc_lineset(void) +{ + return (FreestyleLineSet *)MEM_callocN(sizeof(FreestyleLineSet), "Freestyle line set"); +} + +FreestyleLineSet *BKE_freestyle_lineset_add(FreestyleConfig *config) +{ + int lineset_index = BLI_countlist(&config->linesets); + + FreestyleLineSet *lineset = alloc_lineset(); + BLI_addtail(&config->linesets, (void *)lineset); + BKE_freestyle_lineset_set_active_index(config, lineset_index); + + lineset->linestyle = BKE_new_linestyle("LineStyle", NULL); + lineset->flags |= FREESTYLE_LINESET_ENABLED; + lineset->selection = FREESTYLE_SEL_VISIBILITY | FREESTYLE_SEL_EDGE_TYPES | FREESTYLE_SEL_IMAGE_BORDER; + lineset->qi = FREESTYLE_QI_VISIBLE; + lineset->qi_start = 0; + lineset->qi_end = 100; + lineset->edge_types = FREESTYLE_FE_SILHOUETTE | FREESTYLE_FE_BORDER | FREESTYLE_FE_CREASE; + lineset->exclude_edge_types = 0; + lineset->group = NULL; + if (lineset_index > 0) + sprintf(lineset->name, "LineSet %i", lineset_index + 1); + else + strcpy(lineset->name, "LineSet"); + BKE_freestyle_lineset_unique_name(config, lineset); + + return lineset; +} + +FreestyleLineSet *BKE_freestyle_lineset_get_active(FreestyleConfig *config) +{ + FreestyleLineSet *lineset; + + for (lineset = (FreestyleLineSet *)config->linesets.first; lineset; lineset = lineset->next) { + if (lineset->flags & FREESTYLE_LINESET_CURRENT) + return lineset; + } + return NULL; +} + +short BKE_freestyle_lineset_get_active_index(FreestyleConfig *config) +{ + FreestyleLineSet *lineset; + short i; + + for (lineset = (FreestyleLineSet *)config->linesets.first, i = 0; lineset; lineset = lineset->next, i++) { + if (lineset->flags & FREESTYLE_LINESET_CURRENT) + return i; + } + return 0; +} + +void BKE_freestyle_lineset_set_active_index(FreestyleConfig *config, short index) +{ + FreestyleLineSet *lineset; + short i; + + for (lineset = (FreestyleLineSet *)config->linesets.first, i = 0; lineset; lineset = lineset->next, i++) { + if (i == index) + lineset->flags |= FREESTYLE_LINESET_CURRENT; + else + lineset->flags &= ~FREESTYLE_LINESET_CURRENT; + } +} diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c index b5dac71858b..b1d0e8df754 100644 --- a/source/blender/blenkernel/intern/group.c +++ b/source/blender/blenkernel/intern/group.c @@ -103,8 +103,14 @@ void BKE_group_unlink(Group *group) } for (srl = sce->r.layers.first; srl; srl = srl->next) { + FreestyleLineSet *lineset; + 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 4e39025e48e..c64c261b9b0 100644 --- a/source/blender/blenkernel/intern/idcode.c +++ b/source/blender/blenkernel/intern/idcode.c @@ -63,6 +63,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 8cee97ee930..3a59f578446 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -95,6 +95,7 @@ #include "BKE_lamp.h" #include "BKE_lattice.h" #include "BKE_library.h" +#include "BKE_linestyle.h" #include "BKE_mesh.h" #include "BKE_material.h" #include "BKE_main.h" @@ -281,6 +282,8 @@ bool id_make_local(ID *id, bool test) return false; /* can't be linked */ case ID_GD: return false; /* not implemented */ + case ID_LS: + return 0; /* not implemented */ } return false; @@ -379,6 +382,9 @@ bool id_copy(ID *id, ID **newid, bool test) case ID_MSK: if (!test) *newid = (ID *)BKE_mask_copy((Mask *)id); return true; + case ID_LS: + if (!test) *newid = (ID *)BKE_copy_linestyle((FreestyleLineStyle *)id); + return 1; } return false; @@ -509,6 +515,8 @@ ListBase *which_libbase(Main *mainlib, short type) return &(mainlib->movieclip); case ID_MSK: return &(mainlib->mask); + case ID_LS: + return &(mainlib->linestyle); } return NULL; } @@ -599,6 +607,7 @@ int set_listbasepointers(Main *main, ListBase **lb) lb[a++] = &(main->wm); lb[a++] = &(main->movieclip); lb[a++] = &(main->mask); + lb[a++] = &(main->linestyle); lb[a] = NULL; @@ -717,6 +726,9 @@ static ID *alloc_libblock_notest(short type) case ID_MSK: id = MEM_callocN(sizeof(Mask), "Mask"); break; + case ID_LS: + id = MEM_callocN(sizeof(FreestyleLineStyle), "Freestyle Line Style"); + break; } return id; } @@ -952,6 +964,9 @@ void BKE_libblock_free(ListBase *lb, void *idv) case ID_MSK: BKE_mask_free(bmain, (Mask *)id); break; + case ID_LS: + BKE_free_linestyle((FreestyleLineStyle *)id); + break; } BLI_remlink(lb, id); diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c new file mode 100644 index 00000000000..6a8061274f8 --- /dev/null +++ b/source/blender/blenkernel/intern/linestyle.c @@ -0,0 +1,1070 @@ +/* + * ***** 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 ***** + */ + +/** \file blender/blenkernel/intern/linestyle.c + * \ingroup bke + */ + +#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 "BLI_blenlib.h" +#include "BLI_math.h" +#include "BLI_utildefines.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" + +static const 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.0f; + linestyle->alpha = 1.0f; + linestyle->thickness = 3.0f; + linestyle->thickness_position = LS_THICKNESS_CENTER; + linestyle->thickness_ratio = 0.5f; + linestyle->chaining = LS_CHAINING_PLAIN; + linestyle->rounds = 3; + linestyle->min_angle = DEG2RADF(0.0f); + linestyle->max_angle = DEG2RADF(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; + + BKE_add_linestyle_geometry_modifier(linestyle, LS_MODIFIER_SAMPLING); + + linestyle->caps = LS_CAPS_BUTT; +} + +FreestyleLineStyle *BKE_new_linestyle(const char *name, struct Main *main) +{ + FreestyleLineStyle *linestyle; + + if (!main) + main = G.main; + + linestyle = (FreestyleLineStyle *)BKE_libblock_alloc(&main->linestyle, ID_LS, name); + + default_linestyle_settings(linestyle); + + return linestyle; +} + +void BKE_free_linestyle(FreestyleLineStyle *linestyle) +{ + LineStyleModifier *m; + + BKE_free_animdata(&linestyle->id); + while ((m = (LineStyleModifier *)linestyle->color_modifiers.first)) + BKE_remove_linestyle_color_modifier(linestyle, m); + while ((m = (LineStyleModifier *)linestyle->alpha_modifiers.first)) + BKE_remove_linestyle_alpha_modifier(linestyle, m); + while ((m = (LineStyleModifier *)linestyle->thickness_modifiers.first)) + BKE_remove_linestyle_thickness_modifier(linestyle, m); + while ((m = (LineStyleModifier *)linestyle->geometry_modifiers.first)) + BKE_remove_linestyle_geometry_modifier(linestyle, m); +} + +FreestyleLineStyle *BKE_copy_linestyle(FreestyleLineStyle *linestyle) +{ + FreestyleLineStyle *new_linestyle; + LineStyleModifier *m; + + new_linestyle = BKE_new_linestyle(linestyle->id.name + 2, NULL); + BKE_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->thickness_position = linestyle->thickness_position; + new_linestyle->thickness_ratio = linestyle->thickness_ratio; + 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) + BKE_copy_linestyle_color_modifier(new_linestyle, m); + for (m = (LineStyleModifier *)linestyle->alpha_modifiers.first; m; m = m->next) + BKE_copy_linestyle_alpha_modifier(new_linestyle, m); + for (m = (LineStyleModifier *)linestyle->thickness_modifiers.first; m; m = m->next) + BKE_copy_linestyle_thickness_modifier(new_linestyle, m); + for (m = (LineStyleModifier *)linestyle->geometry_modifiers.first; m; m = m->next) + BKE_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"); + 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 *BKE_add_linestyle_color_modifier(FreestyleLineStyle *linestyle, int type) +{ + LineStyleModifier *m; + + m = alloc_color_modifier(type); + 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 *BKE_copy_linestyle_color_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m) +{ + LineStyleModifier *new_m; + + new_m = alloc_color_modifier(m->type); + 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 *q = (LineStyleColorModifier_AlongStroke *)new_m; + q->color_ramp = MEM_dupallocN(p->color_ramp); + } + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + { + LineStyleColorModifier_DistanceFromCamera *p = (LineStyleColorModifier_DistanceFromCamera *)m; + LineStyleColorModifier_DistanceFromCamera *q = (LineStyleColorModifier_DistanceFromCamera *)new_m; + q->color_ramp = MEM_dupallocN(p->color_ramp); + q->range_min = p->range_min; + q->range_max = p->range_max; + } + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + { + LineStyleColorModifier_DistanceFromObject *p = (LineStyleColorModifier_DistanceFromObject *)m; + LineStyleColorModifier_DistanceFromObject *q = (LineStyleColorModifier_DistanceFromObject *)new_m; + if (p->target) + p->target->id.us++; + q->target = p->target; + q->color_ramp = MEM_dupallocN(p->color_ramp); + q->range_min = p->range_min; + q->range_max = p->range_max; + } + break; + case LS_MODIFIER_MATERIAL: + { + LineStyleColorModifier_Material *p = (LineStyleColorModifier_Material *)m; + LineStyleColorModifier_Material *q = (LineStyleColorModifier_Material *)new_m; + q->color_ramp = MEM_dupallocN(p->color_ramp); + q->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 BKE_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 *BKE_add_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, int type) +{ + LineStyleModifier *m; + + m = alloc_alpha_modifier(type); + m->blend = LS_VALUE_BLEND; + + switch (type) { + case LS_MODIFIER_ALONG_STROKE: + { + LineStyleAlphaModifier_AlongStroke *p = (LineStyleAlphaModifier_AlongStroke *)m; + p->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + } + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + { + LineStyleAlphaModifier_DistanceFromCamera *p = (LineStyleAlphaModifier_DistanceFromCamera *)m; + p->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + p->range_min = 0.0f; + p->range_max = 10000.0f; + } + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + { + LineStyleAlphaModifier_DistanceFromObject *p = (LineStyleAlphaModifier_DistanceFromObject *)m; + p->target = NULL; + p->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + p->range_min = 0.0f; + p->range_max = 10000.0f; + } + break; + case LS_MODIFIER_MATERIAL: + { + LineStyleAlphaModifier_Material *p = (LineStyleAlphaModifier_Material *)m; + p->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + p->mat_attr = LS_MODIFIER_MATERIAL_DIFF; + } + break; + default: + return NULL; /* unknown modifier type */ + } + add_to_modifier_list(&linestyle->alpha_modifiers, m); + + return m; +} + +LineStyleModifier *BKE_copy_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m) +{ + LineStyleModifier *new_m; + + new_m = alloc_alpha_modifier(m->type); + 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 *q = (LineStyleAlphaModifier_AlongStroke *)new_m; + q->curve = curvemapping_copy(p->curve); + } + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + { + LineStyleAlphaModifier_DistanceFromCamera *p = (LineStyleAlphaModifier_DistanceFromCamera *)m; + LineStyleAlphaModifier_DistanceFromCamera *q = (LineStyleAlphaModifier_DistanceFromCamera *)new_m; + q->curve = curvemapping_copy(p->curve); + q->range_min = p->range_min; + q->range_max = p->range_max; + } + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + { + LineStyleAlphaModifier_DistanceFromObject *p = (LineStyleAlphaModifier_DistanceFromObject *)m; + LineStyleAlphaModifier_DistanceFromObject *q = (LineStyleAlphaModifier_DistanceFromObject *)new_m; + if (p->target) + p->target->id.us++; + q->target = p->target; + q->curve = curvemapping_copy(p->curve); + q->range_min = p->range_min; + q->range_max = p->range_max; + } + break; + case LS_MODIFIER_MATERIAL: + { + LineStyleAlphaModifier_Material *p = (LineStyleAlphaModifier_Material *)m; + LineStyleAlphaModifier_Material *q = (LineStyleAlphaModifier_Material *)new_m; + q->curve = curvemapping_copy(p->curve); + q->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 BKE_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 *BKE_add_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, int type) +{ + LineStyleModifier *m; + + m = alloc_thickness_modifier(type); + m->blend = LS_VALUE_BLEND; + + switch (type) { + case LS_MODIFIER_ALONG_STROKE: + { + LineStyleThicknessModifier_AlongStroke *p = (LineStyleThicknessModifier_AlongStroke *)m; + p->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + p->value_min = 0.0f; + p->value_max = 1.0f; + } + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + { + LineStyleThicknessModifier_DistanceFromCamera *p = (LineStyleThicknessModifier_DistanceFromCamera *)m; + p->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + p->range_min = 0.0f; + p->range_max = 1000.0f; + p->value_min = 0.0f; + p->value_max = 1.0f; + } + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + { + LineStyleThicknessModifier_DistanceFromObject *p = (LineStyleThicknessModifier_DistanceFromObject *)m; + p->target = NULL; + p->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + p->range_min = 0.0f; + p->range_max = 1000.0f; + p->value_min = 0.0f; + p->value_max = 1.0f; + } + break; + case LS_MODIFIER_MATERIAL: + { + LineStyleThicknessModifier_Material *p = (LineStyleThicknessModifier_Material *)m; + p->curve = curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); + p->mat_attr = LS_MODIFIER_MATERIAL_DIFF; + p->value_min = 0.0f; + p->value_max = 1.0f; + } + break; + case LS_MODIFIER_CALLIGRAPHY: + { + LineStyleThicknessModifier_Calligraphy *p = (LineStyleThicknessModifier_Calligraphy *)m; + p->min_thickness = 1.0f; + p->max_thickness = 10.0f; + p->orientation = DEG2RADF(60.0f); + } + break; + default: + return NULL; /* unknown modifier type */ + } + add_to_modifier_list(&linestyle->thickness_modifiers, m); + + return m; +} + +LineStyleModifier *BKE_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 *q = (LineStyleThicknessModifier_AlongStroke *)new_m; + q->curve = curvemapping_copy(p->curve); + q->value_min = p->value_min; + q->value_max = p->value_max; + } + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + { + LineStyleThicknessModifier_DistanceFromCamera *p = (LineStyleThicknessModifier_DistanceFromCamera *)m; + LineStyleThicknessModifier_DistanceFromCamera *q = (LineStyleThicknessModifier_DistanceFromCamera *)new_m; + q->curve = curvemapping_copy(p->curve); + q->range_min = p->range_min; + q->range_max = p->range_max; + q->value_min = p->value_min; + q->value_max = p->value_max; + } + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + { + LineStyleThicknessModifier_DistanceFromObject *p = (LineStyleThicknessModifier_DistanceFromObject *)m; + LineStyleThicknessModifier_DistanceFromObject *q = (LineStyleThicknessModifier_DistanceFromObject *)new_m; + if (p->target) + p->target->id.us++; + q->target = p->target; + q->curve = curvemapping_copy(p->curve); + q->range_min = p->range_min; + q->range_max = p->range_max; + q->value_min = p->value_min; + q->value_max = p->value_max; + } + break; + case LS_MODIFIER_MATERIAL: + { + LineStyleThicknessModifier_Material *p = (LineStyleThicknessModifier_Material *)m; + LineStyleThicknessModifier_Material *q = (LineStyleThicknessModifier_Material *)new_m; + q->curve = curvemapping_copy(p->curve); + q->mat_attr = p->mat_attr; + q->value_min = p->value_min; + q->value_max = p->value_max; + } + break; + case LS_MODIFIER_CALLIGRAPHY: + { + LineStyleThicknessModifier_Calligraphy *p = (LineStyleThicknessModifier_Calligraphy *)m; + LineStyleThicknessModifier_Calligraphy *q = (LineStyleThicknessModifier_Calligraphy *)new_m; + q->min_thickness = p->min_thickness; + q->max_thickness = p->max_thickness; + q->orientation = p->orientation; + } + break; + default: + return NULL; /* unknown modifier type */ + } + add_to_modifier_list(&linestyle->thickness_modifiers, new_m); + + return new_m; +} + +void BKE_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 *BKE_add_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, int type) +{ + LineStyleModifier *m; + + m = alloc_geometry_modifier(type); + + switch (type) { + case LS_MODIFIER_SAMPLING: + { + LineStyleGeometryModifier_Sampling *p = (LineStyleGeometryModifier_Sampling *)m; + p->sampling = 10.0f; + } + break; + case LS_MODIFIER_BEZIER_CURVE: + { + LineStyleGeometryModifier_BezierCurve *p = (LineStyleGeometryModifier_BezierCurve *)m; + p->error = 10.0f; + } + break; + case LS_MODIFIER_SINUS_DISPLACEMENT: + { + LineStyleGeometryModifier_SinusDisplacement *p = (LineStyleGeometryModifier_SinusDisplacement *)m; + p->wavelength = 20.0f; + p->amplitude = 5.0f; + p->phase = 0.0f; + } + break; + case LS_MODIFIER_SPATIAL_NOISE: + { + LineStyleGeometryModifier_SpatialNoise *p = (LineStyleGeometryModifier_SpatialNoise *)m; + p->amplitude = 5.0f; + p->scale = 20.0f; + p->octaves = 4; + p->flags = LS_MODIFIER_SPATIAL_NOISE_SMOOTH | LS_MODIFIER_SPATIAL_NOISE_PURERANDOM; + } + break; + case LS_MODIFIER_PERLIN_NOISE_1D: + { + LineStyleGeometryModifier_PerlinNoise1D *p = (LineStyleGeometryModifier_PerlinNoise1D *)m; + p->frequency = 10.0f; + p->amplitude = 10.0f; + p->octaves = 4; + p->angle = DEG2RADF(45.0f); + } + break; + case LS_MODIFIER_PERLIN_NOISE_2D: + { + LineStyleGeometryModifier_PerlinNoise2D *p = (LineStyleGeometryModifier_PerlinNoise2D *)m; + p->frequency = 10.0f; + p->amplitude = 10.0f; + p->octaves = 4; + p->angle = DEG2RADF(45.0f); + } + break; + case LS_MODIFIER_BACKBONE_STRETCHER: + { + LineStyleGeometryModifier_BackboneStretcher *p = (LineStyleGeometryModifier_BackboneStretcher *)m; + p->backbone_length = 10.0f; + } + break; + case LS_MODIFIER_TIP_REMOVER: + { + LineStyleGeometryModifier_TipRemover *p = (LineStyleGeometryModifier_TipRemover *)m; + p->tip_length = 10.0f; + } + break; + case LS_MODIFIER_POLYGONIZATION: + { + LineStyleGeometryModifier_Polygonalization *p = (LineStyleGeometryModifier_Polygonalization *)m; + p->error = 10.0f; + } + break; + case LS_MODIFIER_GUIDING_LINES: + { + LineStyleGeometryModifier_GuidingLines *p = (LineStyleGeometryModifier_GuidingLines *)m; + p->offset = 0.0f; + } + break; + case LS_MODIFIER_BLUEPRINT: + { + LineStyleGeometryModifier_Blueprint *p = (LineStyleGeometryModifier_Blueprint *)m; + p->flags = LS_MODIFIER_BLUEPRINT_CIRCLES; + p->rounds = 1; + p->backbone_length = 10.0f; + p->random_radius = 3; + p->random_center = 5; + p->random_backbone = 5; + } + break; + case LS_MODIFIER_2D_OFFSET: + { + LineStyleGeometryModifier_2DOffset *p = (LineStyleGeometryModifier_2DOffset *)m; + p->start = 0.0f; + p->end = 0.0f; + p->x = 0.0f; + p->y = 0.0f; + } + break; + case LS_MODIFIER_2D_TRANSFORM: + { + LineStyleGeometryModifier_2DTransform *p = (LineStyleGeometryModifier_2DTransform *)m; + p->pivot = LS_MODIFIER_2D_TRANSFORM_PIVOT_CENTER; + p->scale_x = 1.0f; + p->scale_y = 1.0f; + p->angle = DEG2RADF(0.0f); + p->pivot_u = 0.5f; + p->pivot_x = 0.0f; + p->pivot_y = 0.0f; + } + break; + default: + return NULL; /* unknown modifier type */ + } + add_to_modifier_list(&linestyle->geometry_modifiers, m); + + return m; +} + +LineStyleModifier *BKE_copy_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m) +{ + LineStyleModifier *new_m; + + new_m = alloc_geometry_modifier(m->type); + new_m->flags = m->flags; + + switch (m->type) { + case LS_MODIFIER_SAMPLING: + { + LineStyleGeometryModifier_Sampling *p = (LineStyleGeometryModifier_Sampling *)m; + LineStyleGeometryModifier_Sampling *q = (LineStyleGeometryModifier_Sampling *)new_m; + q->sampling = p->sampling; + } + break; + case LS_MODIFIER_BEZIER_CURVE: + { + LineStyleGeometryModifier_BezierCurve *p = (LineStyleGeometryModifier_BezierCurve *)m; + LineStyleGeometryModifier_BezierCurve *q = (LineStyleGeometryModifier_BezierCurve *)new_m; + q->error = p->error; + } + break; + case LS_MODIFIER_SINUS_DISPLACEMENT: + { + LineStyleGeometryModifier_SinusDisplacement *p = (LineStyleGeometryModifier_SinusDisplacement *)m; + LineStyleGeometryModifier_SinusDisplacement *q = (LineStyleGeometryModifier_SinusDisplacement *)new_m; + q->wavelength = p->wavelength; + q->amplitude = p->amplitude; + q->phase = p->phase; + } + break; + case LS_MODIFIER_SPATIAL_NOISE: + { + LineStyleGeometryModifier_SpatialNoise *p = (LineStyleGeometryModifier_SpatialNoise *)m; + LineStyleGeometryModifier_SpatialNoise *q = (LineStyleGeometryModifier_SpatialNoise *)new_m; + q->amplitude = p->amplitude; + q->scale = p->scale; + q->octaves = p->octaves; + q->flags = p->flags; + } + break; + case LS_MODIFIER_PERLIN_NOISE_1D: + { + LineStyleGeometryModifier_PerlinNoise1D *p = (LineStyleGeometryModifier_PerlinNoise1D *)m; + LineStyleGeometryModifier_PerlinNoise1D *q = (LineStyleGeometryModifier_PerlinNoise1D *)new_m; + q->frequency = p->frequency; + q->amplitude = p->amplitude; + q->octaves = p->octaves; + q->angle = p->angle; + } + break; + case LS_MODIFIER_PERLIN_NOISE_2D: + { + LineStyleGeometryModifier_PerlinNoise2D *p = (LineStyleGeometryModifier_PerlinNoise2D *)m; + LineStyleGeometryModifier_PerlinNoise2D *q = (LineStyleGeometryModifier_PerlinNoise2D *)new_m; + q->frequency = p->frequency; + q->amplitude = p->amplitude; + q->octaves = p->octaves; + q->angle = p->angle; + } + break; + case LS_MODIFIER_BACKBONE_STRETCHER: + { + LineStyleGeometryModifier_BackboneStretcher *p = (LineStyleGeometryModifier_BackboneStretcher *)m; + LineStyleGeometryModifier_BackboneStretcher *q = (LineStyleGeometryModifier_BackboneStretcher *)new_m; + q->backbone_length = p->backbone_length; + } + break; + case LS_MODIFIER_TIP_REMOVER: + { + LineStyleGeometryModifier_TipRemover *p = (LineStyleGeometryModifier_TipRemover *)m; + LineStyleGeometryModifier_TipRemover *q = (LineStyleGeometryModifier_TipRemover *)new_m; + q->tip_length = p->tip_length; + } + break; + case LS_MODIFIER_POLYGONIZATION: + { + LineStyleGeometryModifier_Polygonalization *p = (LineStyleGeometryModifier_Polygonalization *)m; + LineStyleGeometryModifier_Polygonalization *q = (LineStyleGeometryModifier_Polygonalization *)new_m; + q->error = p->error; + } + break; + case LS_MODIFIER_GUIDING_LINES: + { + LineStyleGeometryModifier_GuidingLines *p = (LineStyleGeometryModifier_GuidingLines *)m; + LineStyleGeometryModifier_GuidingLines *q = (LineStyleGeometryModifier_GuidingLines *)new_m; + q->offset = p->offset; + } + break; + case LS_MODIFIER_BLUEPRINT: + { + LineStyleGeometryModifier_Blueprint *p = (LineStyleGeometryModifier_Blueprint *)m; + LineStyleGeometryModifier_Blueprint *q = (LineStyleGeometryModifier_Blueprint *)new_m; + q->flags = p->flags; + q->rounds = p->rounds; + q->backbone_length = p->backbone_length; + q->random_radius = p->random_radius; + q->random_center = p->random_center; + q->random_backbone = p->random_backbone; + } + break; + case LS_MODIFIER_2D_OFFSET: + { + LineStyleGeometryModifier_2DOffset *p = (LineStyleGeometryModifier_2DOffset *)m; + LineStyleGeometryModifier_2DOffset *q = (LineStyleGeometryModifier_2DOffset *)new_m; + q->start = p->start; + q->end = p->end; + q->x = p->x; + q->y = p->y; + } + break; + case LS_MODIFIER_2D_TRANSFORM: + { + LineStyleGeometryModifier_2DTransform *p = (LineStyleGeometryModifier_2DTransform *)m; + LineStyleGeometryModifier_2DTransform *q = (LineStyleGeometryModifier_2DTransform *)new_m; + q->pivot = p->pivot; + q->scale_x = p->scale_x; + q->scale_y = p->scale_y; + q->angle = p->angle; + q->pivot_u = p->pivot_u; + q->pivot_x = p->pivot_x; + q->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 BKE_remove_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *m) +{ + 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 BKE_move_linestyle_color_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction) +{ + move_modifier(&linestyle->color_modifiers, modifier, direction); +} + +void BKE_move_linestyle_alpha_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction) +{ + move_modifier(&linestyle->alpha_modifiers, modifier, direction); +} + +void BKE_move_linestyle_thickness_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction) +{ + move_modifier(&linestyle->thickness_modifiers, modifier, direction); +} + +void BKE_move_linestyle_geometry_modifier(FreestyleLineStyle *linestyle, LineStyleModifier *modifier, int direction) +{ + move_modifier(&linestyle->geometry_modifiers, modifier, direction); +} + +void BKE_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 *BKE_path_from_ID_to_color_ramp(FreestyleLineStyle *linestyle, ColorBand *color_ramp) +{ + LineStyleModifier *m; + bool found = false; + + 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) + found = true; + break; + case LS_MODIFIER_DISTANCE_FROM_CAMERA: + if (color_ramp == ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp) + found = true; + break; + case LS_MODIFIER_DISTANCE_FROM_OBJECT: + if (color_ramp == ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp) + found = true; + break; + case LS_MODIFIER_MATERIAL: + if (color_ramp == ((LineStyleColorModifier_Material *)m)->color_ramp) + found = true; + break; + } + if (found) + return BLI_sprintfN("color_modifiers[\"%s\"].color_ramp", m->name); + } + printf("BKE_path_from_ID_to_color_ramp: No color ramps correspond to the given pointer.\n"); + return NULL; +} + +void BKE_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 c47eb7eac45..a4f147a4fac 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -153,6 +153,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 5e0ed369733..a5f05053bfc 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -92,6 +92,7 @@ #include "BKE_lamp.h" #include "BKE_lattice.h" #include "BKE_library.h" +#include "BKE_linestyle.h" #include "BKE_mesh.h" #include "BKE_tessmesh.h" #include "BKE_mball.h" @@ -425,6 +426,8 @@ void BKE_object_unlink(Object *ob) World *wrld; bScreen *sc; Scene *sce; + SceneRenderLayer *srl; + FreestyleLineSet *lineset; Curve *cu; Tex *tex; Group *group; @@ -677,6 +680,14 @@ void BKE_object_unlink(Object *ob) } SEQ_END } + + for (srl = sce->r.layers.first; srl; srl = srl->next) { + for (lineset = (FreestyleLineSet *)srl->freestyleConfig.linesets.first; + lineset; lineset = lineset->next) + { + BKE_unlink_linestyle_target_object(lineset->linestyle, ob); + } + } } sce = sce->id.next; diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 56e48d8f6eb..c2d25ce54db 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -65,6 +65,7 @@ #include "BKE_colortools.h" #include "BKE_depsgraph.h" #include "BKE_fcurve.h" +#include "BKE_freestyle.h" #include "BKE_global.h" #include "BKE_group.h" #include "BKE_idprop.h" @@ -141,6 +142,7 @@ static void remove_sequencer_fcurves(Scene *sce) Scene *BKE_scene_copy(Scene *sce, int type) { Scene *scen; + SceneRenderLayer *srl, *new_srl; ToolSettings *ts; Base *base, *obase; @@ -208,6 +210,13 @@ Scene *BKE_scene_copy(Scene *sce, int type) /* remove animation used by sequencer */ if (type != SCE_COPY_FULL) remove_sequencer_fcurves(scen); + + /* copy Freestyle settings */ + new_srl = scen->r.layers.first; + for (srl = sce->r.layers.first; srl; srl = srl->next) { + BKE_freestyle_config_copy(&new_srl->freestyleConfig, &srl->freestyleConfig); + new_srl = new_srl->next; + } } /* tool settings */ @@ -290,6 +299,7 @@ Scene *BKE_scene_copy(Scene *sce, int type) void BKE_scene_free(Scene *sce) { Base *base; + SceneRenderLayer *srl; /* check all sequences */ BKE_sequencer_clear_scene_in_allseqs(G.main, sce); @@ -336,6 +346,10 @@ void BKE_scene_free(Scene *sce) sce->r.ffcodecdata.properties = NULL; } + for (srl = sce->r.layers.first; srl; srl = srl->next) { + BKE_freestyle_config_free(&srl->freestyleConfig); + } + BLI_freelistN(&sce->markers); BLI_freelistN(&sce->transform_spaces); BLI_freelistN(&sce->r.layers); @@ -1274,6 +1288,7 @@ SceneRenderLayer *BKE_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; + BKE_freestyle_config_init(&srl->freestyleConfig); return srl; } diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 29f16775598..842f495dffe 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -519,6 +519,9 @@ void BKE_text_unlink(Main *bmain, Text *text) bNodeTree *ntree; bNode *node; Material *mat; + Scene *sce; + SceneRenderLayer *srl; + FreestyleModuleConfig *module; short update; for (ob = bmain->object.first; ob; ob = ob->id.next) { @@ -608,6 +611,16 @@ void BKE_text_unlink(Main *bmain, Text *text) } } + /* Freestyle */ + for (sce = bmain->scene.first; sce; sce = sce->id.next) { + for (srl = sce->r.layers.first; srl; srl = srl->next) { + for (module = srl->freestyleConfig.modules.first; module; module = module->next) { + if (module->script == text) + module->script = NULL; + } + } + } + text->id.us = 0; } |