Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/linestyle.cc
- This file was moved from source/blender/blenkernel/intern/linestyle.c.
| Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
| static void linestyle_init_data(ID *id) | static void linestyle_init_data(ID *id) | ||||
| { | { | ||||
| FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id; | FreestyleLineStyle *linestyle = (FreestyleLineStyle *)id; | ||||
| BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(linestyle, id)); | BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(linestyle, id)); | ||||
| MEMCPY_STRUCT_AFTER(linestyle, DNA_struct_default_get(FreestyleLineStyle), id); | MEMCPY_STRUCT_AFTER(linestyle, DNA_struct_default_get(FreestyleLineStyle), id); | ||||
| BKE_linestyle_geometry_modifier_add(linestyle, NULL, LS_MODIFIER_SAMPLING); | BKE_linestyle_geometry_modifier_add(linestyle, nullptr, LS_MODIFIER_SAMPLING); | ||||
| } | } | ||||
| static void linestyle_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int flag) | static void linestyle_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int flag) | ||||
| { | { | ||||
| FreestyleLineStyle *linestyle_dst = (FreestyleLineStyle *)id_dst; | FreestyleLineStyle *linestyle_dst = (FreestyleLineStyle *)id_dst; | ||||
| const FreestyleLineStyle *linestyle_src = (const FreestyleLineStyle *)id_src; | const FreestyleLineStyle *linestyle_src = (const FreestyleLineStyle *)id_src; | ||||
| /* We never handle user-count here for own data. */ | /* We never handle user-count here for own data. */ | ||||
| const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT; | const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT; | ||||
| /* We always need allocation of our private ID data. */ | /* We always need allocation of our private ID data. */ | ||||
| const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE; | const int flag_private_id_data = flag & ~LIB_ID_CREATE_NO_ALLOCATE; | ||||
| for (int a = 0; a < MAX_MTEX; a++) { | for (int a = 0; a < MAX_MTEX; a++) { | ||||
| if (linestyle_src->mtex[a]) { | if (linestyle_src->mtex[a]) { | ||||
| linestyle_dst->mtex[a] = MEM_mallocN(sizeof(*linestyle_dst->mtex[a]), __func__); | linestyle_dst->mtex[a] = MEM_new<MTex>(__func__); | ||||
| *linestyle_dst->mtex[a] = *linestyle_src->mtex[a]; | *linestyle_dst->mtex[a] = blender::dna::shallow_copy(*linestyle_src->mtex[a]); | ||||
| } | } | ||||
| } | } | ||||
| if (linestyle_src->nodetree) { | if (linestyle_src->nodetree) { | ||||
| BKE_id_copy_ex(bmain, | BKE_id_copy_ex(bmain, | ||||
| (ID *)linestyle_src->nodetree, | (ID *)linestyle_src->nodetree, | ||||
| (ID **)&linestyle_dst->nodetree, | (ID **)&linestyle_dst->nodetree, | ||||
| flag_private_id_data); | flag_private_id_data); | ||||
| Show All 38 Lines | static void linestyle_free_data(ID *id) | ||||
| for (int material_slot_index = 0; material_slot_index < MAX_MTEX; material_slot_index++) { | for (int material_slot_index = 0; material_slot_index < MAX_MTEX; material_slot_index++) { | ||||
| MEM_SAFE_FREE(linestyle->mtex[material_slot_index]); | MEM_SAFE_FREE(linestyle->mtex[material_slot_index]); | ||||
| } | } | ||||
| /* is no lib link block, but linestyle extension */ | /* is no lib link block, but linestyle extension */ | ||||
| if (linestyle->nodetree) { | if (linestyle->nodetree) { | ||||
| ntreeFreeEmbeddedTree(linestyle->nodetree); | ntreeFreeEmbeddedTree(linestyle->nodetree); | ||||
| MEM_freeN(linestyle->nodetree); | MEM_freeN(linestyle->nodetree); | ||||
| linestyle->nodetree = NULL; | linestyle->nodetree = nullptr; | ||||
| } | } | ||||
| while ((linestyle_modifier = (LineStyleModifier *)linestyle->color_modifiers.first)) { | while ((linestyle_modifier = (LineStyleModifier *)linestyle->color_modifiers.first)) { | ||||
| BKE_linestyle_color_modifier_remove(linestyle, linestyle_modifier); | BKE_linestyle_color_modifier_remove(linestyle, linestyle_modifier); | ||||
| } | } | ||||
| while ((linestyle_modifier = (LineStyleModifier *)linestyle->alpha_modifiers.first)) { | while ((linestyle_modifier = (LineStyleModifier *)linestyle->alpha_modifiers.first)) { | ||||
| BKE_linestyle_alpha_modifier_remove(linestyle, linestyle_modifier); | BKE_linestyle_alpha_modifier_remove(linestyle, linestyle_modifier); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | LISTBASE_FOREACH (LineStyleModifier *, lsm, &linestyle->thickness_modifiers) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void write_linestyle_color_modifiers(BlendWriter *writer, ListBase *modifiers) | static void write_linestyle_color_modifiers(BlendWriter *writer, ListBase *modifiers) | ||||
| { | { | ||||
| LineStyleModifier *m; | LineStyleModifier *m; | ||||
| for (m = modifiers->first; m; m = m->next) { | for (m = static_cast<LineStyleModifier *>(modifiers->first); m; m = m->next) { | ||||
| int struct_nr; | int struct_nr; | ||||
| switch (m->type) { | switch (m->type) { | ||||
| case LS_MODIFIER_ALONG_STROKE: | case LS_MODIFIER_ALONG_STROKE: | ||||
| struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_AlongStroke); | struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_AlongStroke); | ||||
| break; | break; | ||||
| case LS_MODIFIER_DISTANCE_FROM_CAMERA: | case LS_MODIFIER_DISTANCE_FROM_CAMERA: | ||||
| struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_DistanceFromCamera); | struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_DistanceFromCamera); | ||||
| break; | break; | ||||
| Show All 15 Lines | switch (m->type) { | ||||
| case LS_MODIFIER_CURVATURE_3D: | case LS_MODIFIER_CURVATURE_3D: | ||||
| struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Curvature_3D); | struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleColorModifier_Curvature_3D); | ||||
| break; | break; | ||||
| default: | default: | ||||
| struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ | struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ | ||||
| } | } | ||||
| BLO_write_struct_by_id(writer, struct_nr, m); | BLO_write_struct_by_id(writer, struct_nr, m); | ||||
| } | } | ||||
| for (m = modifiers->first; m; m = m->next) { | for (m = static_cast<LineStyleModifier *>(modifiers->first); m; m = m->next) { | ||||
| switch (m->type) { | switch (m->type) { | ||||
| case LS_MODIFIER_ALONG_STROKE: | case LS_MODIFIER_ALONG_STROKE: | ||||
| BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_AlongStroke *)m)->color_ramp); | BLO_write_struct(writer, ColorBand, ((LineStyleColorModifier_AlongStroke *)m)->color_ramp); | ||||
| break; | break; | ||||
| case LS_MODIFIER_DISTANCE_FROM_CAMERA: | case LS_MODIFIER_DISTANCE_FROM_CAMERA: | ||||
| BLO_write_struct( | BLO_write_struct( | ||||
| writer, ColorBand, ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp); | writer, ColorBand, ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp); | ||||
| break; | break; | ||||
| Show All 20 Lines | for (m = static_cast<LineStyleModifier *>(modifiers->first); m; m = m->next) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void write_linestyle_alpha_modifiers(BlendWriter *writer, ListBase *modifiers) | static void write_linestyle_alpha_modifiers(BlendWriter *writer, ListBase *modifiers) | ||||
| { | { | ||||
| LineStyleModifier *m; | LineStyleModifier *m; | ||||
| for (m = modifiers->first; m; m = m->next) { | for (m = static_cast<LineStyleModifier *>(modifiers->first); m; m = m->next) { | ||||
| int struct_nr; | int struct_nr; | ||||
| switch (m->type) { | switch (m->type) { | ||||
| case LS_MODIFIER_ALONG_STROKE: | case LS_MODIFIER_ALONG_STROKE: | ||||
| struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_AlongStroke); | struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_AlongStroke); | ||||
| break; | break; | ||||
| case LS_MODIFIER_DISTANCE_FROM_CAMERA: | case LS_MODIFIER_DISTANCE_FROM_CAMERA: | ||||
| struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_DistanceFromCamera); | struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_DistanceFromCamera); | ||||
| break; | break; | ||||
| Show All 15 Lines | switch (m->type) { | ||||
| case LS_MODIFIER_CURVATURE_3D: | case LS_MODIFIER_CURVATURE_3D: | ||||
| struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Curvature_3D); | struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleAlphaModifier_Curvature_3D); | ||||
| break; | break; | ||||
| default: | default: | ||||
| struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ | struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ | ||||
| } | } | ||||
| BLO_write_struct_by_id(writer, struct_nr, m); | BLO_write_struct_by_id(writer, struct_nr, m); | ||||
| } | } | ||||
| for (m = modifiers->first; m; m = m->next) { | for (m = static_cast<LineStyleModifier *>(modifiers->first); m; m = m->next) { | ||||
| switch (m->type) { | switch (m->type) { | ||||
| case LS_MODIFIER_ALONG_STROKE: | case LS_MODIFIER_ALONG_STROKE: | ||||
| BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_AlongStroke *)m)->curve); | BKE_curvemapping_blend_write(writer, ((LineStyleAlphaModifier_AlongStroke *)m)->curve); | ||||
| break; | break; | ||||
| case LS_MODIFIER_DISTANCE_FROM_CAMERA: | case LS_MODIFIER_DISTANCE_FROM_CAMERA: | ||||
| BKE_curvemapping_blend_write(writer, | BKE_curvemapping_blend_write(writer, | ||||
| ((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve); | ((LineStyleAlphaModifier_DistanceFromCamera *)m)->curve); | ||||
| break; | break; | ||||
| Show All 19 Lines | for (m = static_cast<LineStyleModifier *>(modifiers->first); m; m = m->next) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void write_linestyle_thickness_modifiers(BlendWriter *writer, ListBase *modifiers) | static void write_linestyle_thickness_modifiers(BlendWriter *writer, ListBase *modifiers) | ||||
| { | { | ||||
| LineStyleModifier *m; | LineStyleModifier *m; | ||||
| for (m = modifiers->first; m; m = m->next) { | for (m = static_cast<LineStyleModifier *>(modifiers->first); m; m = m->next) { | ||||
| int struct_nr; | int struct_nr; | ||||
| switch (m->type) { | switch (m->type) { | ||||
| case LS_MODIFIER_ALONG_STROKE: | case LS_MODIFIER_ALONG_STROKE: | ||||
| struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_AlongStroke); | struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_AlongStroke); | ||||
| break; | break; | ||||
| case LS_MODIFIER_DISTANCE_FROM_CAMERA: | case LS_MODIFIER_DISTANCE_FROM_CAMERA: | ||||
| struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_DistanceFromCamera); | struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_DistanceFromCamera); | ||||
| break; | break; | ||||
| Show All 18 Lines | switch (m->type) { | ||||
| case LS_MODIFIER_CURVATURE_3D: | case LS_MODIFIER_CURVATURE_3D: | ||||
| struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Curvature_3D); | struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleThicknessModifier_Curvature_3D); | ||||
| break; | break; | ||||
| default: | default: | ||||
| struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ | struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleModifier); /* this should not happen */ | ||||
| } | } | ||||
| BLO_write_struct_by_id(writer, struct_nr, m); | BLO_write_struct_by_id(writer, struct_nr, m); | ||||
| } | } | ||||
| for (m = modifiers->first; m; m = m->next) { | for (m = static_cast<LineStyleModifier *>(modifiers->first); m; m = m->next) { | ||||
| switch (m->type) { | switch (m->type) { | ||||
| case LS_MODIFIER_ALONG_STROKE: | case LS_MODIFIER_ALONG_STROKE: | ||||
| BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_AlongStroke *)m)->curve); | BKE_curvemapping_blend_write(writer, ((LineStyleThicknessModifier_AlongStroke *)m)->curve); | ||||
| break; | break; | ||||
| case LS_MODIFIER_DISTANCE_FROM_CAMERA: | case LS_MODIFIER_DISTANCE_FROM_CAMERA: | ||||
| BKE_curvemapping_blend_write(writer, | BKE_curvemapping_blend_write(writer, | ||||
| ((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve); | ((LineStyleThicknessModifier_DistanceFromCamera *)m)->curve); | ||||
| break; | break; | ||||
| Show All 17 Lines | for (m = static_cast<LineStyleModifier *>(modifiers->first); m; m = m->next) { | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void write_linestyle_geometry_modifiers(BlendWriter *writer, ListBase *modifiers) | static void write_linestyle_geometry_modifiers(BlendWriter *writer, ListBase *modifiers) | ||||
| { | { | ||||
| LineStyleModifier *m; | LineStyleModifier *m; | ||||
| for (m = modifiers->first; m; m = m->next) { | for (m = static_cast<LineStyleModifier *>(modifiers->first); m; m = m->next) { | ||||
| int struct_nr; | int struct_nr; | ||||
| switch (m->type) { | switch (m->type) { | ||||
| case LS_MODIFIER_SAMPLING: | case LS_MODIFIER_SAMPLING: | ||||
| struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Sampling); | struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_Sampling); | ||||
| break; | break; | ||||
| case LS_MODIFIER_BEZIER_CURVE: | case LS_MODIFIER_BEZIER_CURVE: | ||||
| struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_BezierCurve); | struct_nr = SDNA_TYPE_FROM_STRUCT(LineStyleGeometryModifier_BezierCurve); | ||||
| break; | break; | ||||
| ▲ Show 20 Lines • Show All 325 Lines • ▼ Show 20 Lines | static void linestyle_blend_read_expand(BlendExpander *expander, ID *id) | ||||
| LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->thickness_modifiers) { | LISTBASE_FOREACH (LineStyleModifier *, m, &linestyle->thickness_modifiers) { | ||||
| if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { | if (m->type == LS_MODIFIER_DISTANCE_FROM_OBJECT) { | ||||
| BLO_expand(expander, ((LineStyleThicknessModifier_DistanceFromObject *)m)->target); | BLO_expand(expander, ((LineStyleThicknessModifier_DistanceFromObject *)m)->target); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| IDTypeInfo IDType_ID_LS = { | IDTypeInfo IDType_ID_LS = { | ||||
| .id_code = ID_LS, | /* id_code */ ID_LS, | ||||
| .id_filter = FILTER_ID_LS, | /* id_filter */ FILTER_ID_LS, | ||||
| .main_listbase_index = INDEX_ID_LS, | /* main_listbase_index */ INDEX_ID_LS, | ||||
| .struct_size = sizeof(FreestyleLineStyle), | /* struct_size */ sizeof(FreestyleLineStyle), | ||||
| .name = "FreestyleLineStyle", | /* name */ "FreestyleLineStyle", | ||||
| .name_plural = "linestyles", | /* name_plural */ "linestyles", | ||||
| .translation_context = BLT_I18NCONTEXT_ID_FREESTYLELINESTYLE, | /* translation_context */ BLT_I18NCONTEXT_ID_FREESTYLELINESTYLE, | ||||
| .flags = IDTYPE_FLAGS_APPEND_IS_REUSABLE, | /* flags */ IDTYPE_FLAGS_APPEND_IS_REUSABLE, | ||||
| .asset_type_info = NULL, | /* asset_type_info */ nullptr, | ||||
| .init_data = linestyle_init_data, | /* init_data */ linestyle_init_data, | ||||
| .copy_data = linestyle_copy_data, | /* copy_data */ linestyle_copy_data, | ||||
| .free_data = linestyle_free_data, | /* free_data */ linestyle_free_data, | ||||
| .make_local = NULL, | /* make_local */ nullptr, | ||||
| .foreach_id = linestyle_foreach_id, | /* foreach_id */ linestyle_foreach_id, | ||||
| .foreach_cache = NULL, | /* foreach_cache */ nullptr, | ||||
| .foreach_path = NULL, | /* foreach_path */ nullptr, | ||||
| .owner_pointer_get = NULL, | /* owner_pointer_get */ nullptr, | ||||
| .blend_write = linestyle_blend_write, | /* blend_write */ linestyle_blend_write, | ||||
| .blend_read_data = linestyle_blend_read_data, | /* blend_read_data */ linestyle_blend_read_data, | ||||
| .blend_read_lib = linestyle_blend_read_lib, | /* blend_read_lib */ linestyle_blend_read_lib, | ||||
| .blend_read_expand = linestyle_blend_read_expand, | /* blend_read_expand */ linestyle_blend_read_expand, | ||||
| .blend_read_undo_preserve = NULL, | /* blend_read_undo_preserve */ nullptr, | ||||
| .lib_override_apply_post = NULL, | /* lib_override_apply_post */ nullptr, | ||||
| }; | }; | ||||
| static const char *modifier_name[LS_MODIFIER_NUM] = { | static const char *modifier_name[LS_MODIFIER_NUM] = { | ||||
| NULL, | nullptr, "Along Stroke", "Distance from Camera", "Distance from Object", | ||||
| "Along Stroke", | "Material", "Sampling", "Bezier Curve", "Sinus Displacement", | ||||
| "Distance from Camera", | "Spatial Noise", "Perlin Noise 1D", "Perlin Noise 2D", "Backbone Stretcher", | ||||
| "Distance from Object", | "Tip Remover", "Calligraphy", "Polygonalization", "Guiding Lines", | ||||
| "Material", | "Blueprint", "2D Offset", "2D Transform", "Tangent", | ||||
| "Sampling", | "Noise", "Crease Angle", "Simplification", "Curvature 3D", | ||||
| "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", | |||||
| "Tangent", | |||||
| "Noise", | |||||
| "Crease Angle", | |||||
| "Simplification", | |||||
| "Curvature 3D", | |||||
| }; | }; | ||||
| void BKE_linestyle_init(FreestyleLineStyle *linestyle) | void BKE_linestyle_init(FreestyleLineStyle *linestyle) | ||||
| { | { | ||||
| linestyle_init_data(&linestyle->id); | linestyle_init_data(&linestyle->id); | ||||
| } | } | ||||
| FreestyleLineStyle *BKE_linestyle_new(struct Main *bmain, const char *name) | FreestyleLineStyle *BKE_linestyle_new(struct Main *bmain, const char *name) | ||||
| { | { | ||||
| FreestyleLineStyle *linestyle; | FreestyleLineStyle *linestyle; | ||||
| linestyle = (FreestyleLineStyle *)BKE_libblock_alloc(bmain, ID_LS, name, 0); | linestyle = (FreestyleLineStyle *)BKE_libblock_alloc(bmain, ID_LS, name, 0); | ||||
| BKE_linestyle_init(linestyle); | BKE_linestyle_init(linestyle); | ||||
| return linestyle; | return linestyle; | ||||
| } | } | ||||
| FreestyleLineStyle *BKE_linestyle_active_from_view_layer(ViewLayer *view_layer) | FreestyleLineStyle *BKE_linestyle_active_from_view_layer(ViewLayer *view_layer) | ||||
| { | { | ||||
| FreestyleConfig *config = &view_layer->freestyle_config; | FreestyleConfig *config = &view_layer->freestyle_config; | ||||
| FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config); | FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config); | ||||
| return (lineset) ? lineset->linestyle : NULL; | return (lineset) ? lineset->linestyle : nullptr; | ||||
| } | } | ||||
| static LineStyleModifier *new_modifier(const char *name, int type, size_t size) | static LineStyleModifier *new_modifier(const char *name, int type, size_t size) | ||||
| { | { | ||||
| LineStyleModifier *m; | LineStyleModifier *m; | ||||
| if (!name) { | if (!name) { | ||||
| name = modifier_name[type]; | name = modifier_name[type]; | ||||
| Show All 39 Lines | case LS_MODIFIER_NOISE: | ||||
| break; | break; | ||||
| case LS_MODIFIER_CREASE_ANGLE: | case LS_MODIFIER_CREASE_ANGLE: | ||||
| size = sizeof(LineStyleColorModifier_CreaseAngle); | size = sizeof(LineStyleColorModifier_CreaseAngle); | ||||
| break; | break; | ||||
| case LS_MODIFIER_CURVATURE_3D: | case LS_MODIFIER_CURVATURE_3D: | ||||
| size = sizeof(LineStyleColorModifier_Curvature_3D); | size = sizeof(LineStyleColorModifier_Curvature_3D); | ||||
| break; | break; | ||||
| default: | default: | ||||
| return NULL; /* unknown modifier type */ | return nullptr; /* unknown modifier type */ | ||||
| } | } | ||||
| return new_modifier(name, type, size); | return new_modifier(name, type, size); | ||||
| } | } | ||||
| LineStyleModifier *BKE_linestyle_color_modifier_add(FreestyleLineStyle *linestyle, | LineStyleModifier *BKE_linestyle_color_modifier_add(FreestyleLineStyle *linestyle, | ||||
| const char *name, | const char *name, | ||||
| int type) | int type) | ||||
| { | { | ||||
| LineStyleModifier *m; | LineStyleModifier *m; | ||||
| m = alloc_color_modifier(name, type); | m = alloc_color_modifier(name, type); | ||||
| if (UNLIKELY(m == NULL)) { | if (UNLIKELY(m == nullptr)) { | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| m->blend = MA_RAMP_BLEND; | m->blend = MA_RAMP_BLEND; | ||||
| switch (type) { | switch (type) { | ||||
| case LS_MODIFIER_ALONG_STROKE: | case LS_MODIFIER_ALONG_STROKE: | ||||
| ((LineStyleColorModifier_AlongStroke *)m)->color_ramp = BKE_colorband_add(true); | ((LineStyleColorModifier_AlongStroke *)m)->color_ramp = BKE_colorband_add(true); | ||||
| break; | break; | ||||
| case LS_MODIFIER_DISTANCE_FROM_CAMERA: | case LS_MODIFIER_DISTANCE_FROM_CAMERA: | ||||
| ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp = BKE_colorband_add(true); | ((LineStyleColorModifier_DistanceFromCamera *)m)->color_ramp = BKE_colorband_add(true); | ||||
| ((LineStyleColorModifier_DistanceFromCamera *)m)->range_min = 0.0f; | ((LineStyleColorModifier_DistanceFromCamera *)m)->range_min = 0.0f; | ||||
| ((LineStyleColorModifier_DistanceFromCamera *)m)->range_max = 10000.0f; | ((LineStyleColorModifier_DistanceFromCamera *)m)->range_max = 10000.0f; | ||||
| break; | break; | ||||
| case LS_MODIFIER_DISTANCE_FROM_OBJECT: | case LS_MODIFIER_DISTANCE_FROM_OBJECT: | ||||
| ((LineStyleColorModifier_DistanceFromObject *)m)->target = NULL; | ((LineStyleColorModifier_DistanceFromObject *)m)->target = nullptr; | ||||
| ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp = BKE_colorband_add(true); | ((LineStyleColorModifier_DistanceFromObject *)m)->color_ramp = BKE_colorband_add(true); | ||||
| ((LineStyleColorModifier_DistanceFromObject *)m)->range_min = 0.0f; | ((LineStyleColorModifier_DistanceFromObject *)m)->range_min = 0.0f; | ||||
| ((LineStyleColorModifier_DistanceFromObject *)m)->range_max = 10000.0f; | ((LineStyleColorModifier_DistanceFromObject *)m)->range_max = 10000.0f; | ||||
| break; | break; | ||||
| case LS_MODIFIER_MATERIAL: | case LS_MODIFIER_MATERIAL: | ||||
| ((LineStyleColorModifier_Material *)m)->color_ramp = BKE_colorband_add(true); | ((LineStyleColorModifier_Material *)m)->color_ramp = BKE_colorband_add(true); | ||||
| ((LineStyleColorModifier_Material *)m)->mat_attr = LS_MODIFIER_MATERIAL_LINE; | ((LineStyleColorModifier_Material *)m)->mat_attr = LS_MODIFIER_MATERIAL_LINE; | ||||
| break; | break; | ||||
| Show All 12 Lines | case LS_MODIFIER_CREASE_ANGLE: | ||||
| ((LineStyleColorModifier_CreaseAngle *)m)->max_angle = DEG2RADF(180.0f); | ((LineStyleColorModifier_CreaseAngle *)m)->max_angle = DEG2RADF(180.0f); | ||||
| break; | break; | ||||
| case LS_MODIFIER_CURVATURE_3D: | case LS_MODIFIER_CURVATURE_3D: | ||||
| ((LineStyleColorModifier_Curvature_3D *)m)->color_ramp = BKE_colorband_add(true); | ((LineStyleColorModifier_Curvature_3D *)m)->color_ramp = BKE_colorband_add(true); | ||||
| ((LineStyleColorModifier_Curvature_3D *)m)->min_curvature = 0.0f; | ((LineStyleColorModifier_Curvature_3D *)m)->min_curvature = 0.0f; | ||||
| ((LineStyleColorModifier_Curvature_3D *)m)->max_curvature = 0.5f; | ((LineStyleColorModifier_Curvature_3D *)m)->max_curvature = 0.5f; | ||||
| break; | break; | ||||
| default: | default: | ||||
| return NULL; /* unknown modifier type */ | return nullptr; /* unknown modifier type */ | ||||
| } | } | ||||
| add_to_modifier_list(&linestyle->color_modifiers, m); | add_to_modifier_list(&linestyle->color_modifiers, m); | ||||
| return m; | return m; | ||||
| } | } | ||||
| LineStyleModifier *BKE_linestyle_color_modifier_copy(FreestyleLineStyle *linestyle, | LineStyleModifier *BKE_linestyle_color_modifier_copy(FreestyleLineStyle *linestyle, | ||||
| const LineStyleModifier *m, | const LineStyleModifier *m, | ||||
| const int flag) | const int flag) | ||||
| { | { | ||||
| LineStyleModifier *new_m; | LineStyleModifier *new_m; | ||||
| new_m = alloc_color_modifier(m->name, m->type); | new_m = alloc_color_modifier(m->name, m->type); | ||||
| if (UNLIKELY(new_m == NULL)) { | if (UNLIKELY(new_m == nullptr)) { | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| new_m->influence = m->influence; | new_m->influence = m->influence; | ||||
| new_m->flags = m->flags; | new_m->flags = m->flags; | ||||
| new_m->blend = m->blend; | new_m->blend = m->blend; | ||||
| switch (m->type) { | switch (m->type) { | ||||
| case LS_MODIFIER_ALONG_STROKE: { | case LS_MODIFIER_ALONG_STROKE: { | ||||
| LineStyleColorModifier_AlongStroke *p = (LineStyleColorModifier_AlongStroke *)m; | LineStyleColorModifier_AlongStroke *p = (LineStyleColorModifier_AlongStroke *)m; | ||||
| LineStyleColorModifier_AlongStroke *q = (LineStyleColorModifier_AlongStroke *)new_m; | LineStyleColorModifier_AlongStroke *q = (LineStyleColorModifier_AlongStroke *)new_m; | ||||
| q->color_ramp = MEM_dupallocN(p->color_ramp); | q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp)); | ||||
| break; | break; | ||||
| } | } | ||||
| case LS_MODIFIER_DISTANCE_FROM_CAMERA: { | case LS_MODIFIER_DISTANCE_FROM_CAMERA: { | ||||
| LineStyleColorModifier_DistanceFromCamera *p = (LineStyleColorModifier_DistanceFromCamera *) | LineStyleColorModifier_DistanceFromCamera *p = (LineStyleColorModifier_DistanceFromCamera *) | ||||
| m; | m; | ||||
| LineStyleColorModifier_DistanceFromCamera *q = (LineStyleColorModifier_DistanceFromCamera *) | LineStyleColorModifier_DistanceFromCamera *q = (LineStyleColorModifier_DistanceFromCamera *) | ||||
| new_m; | new_m; | ||||
| q->color_ramp = MEM_dupallocN(p->color_ramp); | q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp)); | ||||
| q->range_min = p->range_min; | q->range_min = p->range_min; | ||||
| q->range_max = p->range_max; | q->range_max = p->range_max; | ||||
| break; | break; | ||||
| } | } | ||||
| case LS_MODIFIER_DISTANCE_FROM_OBJECT: { | case LS_MODIFIER_DISTANCE_FROM_OBJECT: { | ||||
| LineStyleColorModifier_DistanceFromObject *p = (LineStyleColorModifier_DistanceFromObject *) | LineStyleColorModifier_DistanceFromObject *p = (LineStyleColorModifier_DistanceFromObject *) | ||||
| m; | m; | ||||
| LineStyleColorModifier_DistanceFromObject *q = (LineStyleColorModifier_DistanceFromObject *) | LineStyleColorModifier_DistanceFromObject *q = (LineStyleColorModifier_DistanceFromObject *) | ||||
| new_m; | new_m; | ||||
| q->target = p->target; | q->target = p->target; | ||||
| if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) { | if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) { | ||||
| id_us_plus((ID *)q->target); | id_us_plus((ID *)q->target); | ||||
| } | } | ||||
| q->color_ramp = MEM_dupallocN(p->color_ramp); | q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp)); | ||||
| q->range_min = p->range_min; | q->range_min = p->range_min; | ||||
| q->range_max = p->range_max; | q->range_max = p->range_max; | ||||
| break; | break; | ||||
| } | } | ||||
| case LS_MODIFIER_MATERIAL: { | case LS_MODIFIER_MATERIAL: { | ||||
| LineStyleColorModifier_Material *p = (LineStyleColorModifier_Material *)m; | LineStyleColorModifier_Material *p = (LineStyleColorModifier_Material *)m; | ||||
| LineStyleColorModifier_Material *q = (LineStyleColorModifier_Material *)new_m; | LineStyleColorModifier_Material *q = (LineStyleColorModifier_Material *)new_m; | ||||
| q->color_ramp = MEM_dupallocN(p->color_ramp); | q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp)); | ||||
| q->flags = p->flags; | q->flags = p->flags; | ||||
| q->mat_attr = p->mat_attr; | q->mat_attr = p->mat_attr; | ||||
| break; | break; | ||||
| } | } | ||||
| case LS_MODIFIER_TANGENT: { | case LS_MODIFIER_TANGENT: { | ||||
| LineStyleColorModifier_Tangent *p = (LineStyleColorModifier_Tangent *)m; | LineStyleColorModifier_Tangent *p = (LineStyleColorModifier_Tangent *)m; | ||||
| LineStyleColorModifier_Tangent *q = (LineStyleColorModifier_Tangent *)new_m; | LineStyleColorModifier_Tangent *q = (LineStyleColorModifier_Tangent *)new_m; | ||||
| q->color_ramp = MEM_dupallocN(p->color_ramp); | q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp)); | ||||
| break; | break; | ||||
| } | } | ||||
| case LS_MODIFIER_NOISE: { | case LS_MODIFIER_NOISE: { | ||||
| LineStyleColorModifier_Noise *p = (LineStyleColorModifier_Noise *)m; | LineStyleColorModifier_Noise *p = (LineStyleColorModifier_Noise *)m; | ||||
| LineStyleColorModifier_Noise *q = (LineStyleColorModifier_Noise *)new_m; | LineStyleColorModifier_Noise *q = (LineStyleColorModifier_Noise *)new_m; | ||||
| q->color_ramp = MEM_dupallocN(p->color_ramp); | q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp)); | ||||
| q->amplitude = p->amplitude; | q->amplitude = p->amplitude; | ||||
| q->period = p->period; | q->period = p->period; | ||||
| q->seed = p->seed; | q->seed = p->seed; | ||||
| break; | break; | ||||
| } | } | ||||
| case LS_MODIFIER_CREASE_ANGLE: { | case LS_MODIFIER_CREASE_ANGLE: { | ||||
| LineStyleColorModifier_CreaseAngle *p = (LineStyleColorModifier_CreaseAngle *)m; | LineStyleColorModifier_CreaseAngle *p = (LineStyleColorModifier_CreaseAngle *)m; | ||||
| LineStyleColorModifier_CreaseAngle *q = (LineStyleColorModifier_CreaseAngle *)new_m; | LineStyleColorModifier_CreaseAngle *q = (LineStyleColorModifier_CreaseAngle *)new_m; | ||||
| q->color_ramp = MEM_dupallocN(p->color_ramp); | q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp)); | ||||
| q->min_angle = p->min_angle; | q->min_angle = p->min_angle; | ||||
| q->max_angle = p->max_angle; | q->max_angle = p->max_angle; | ||||
| break; | break; | ||||
| } | } | ||||
| case LS_MODIFIER_CURVATURE_3D: { | case LS_MODIFIER_CURVATURE_3D: { | ||||
| LineStyleColorModifier_Curvature_3D *p = (LineStyleColorModifier_Curvature_3D *)m; | LineStyleColorModifier_Curvature_3D *p = (LineStyleColorModifier_Curvature_3D *)m; | ||||
| LineStyleColorModifier_Curvature_3D *q = (LineStyleColorModifier_Curvature_3D *)new_m; | LineStyleColorModifier_Curvature_3D *q = (LineStyleColorModifier_Curvature_3D *)new_m; | ||||
| q->color_ramp = MEM_dupallocN(p->color_ramp); | q->color_ramp = static_cast<ColorBand *>(MEM_dupallocN(p->color_ramp)); | ||||
| q->min_curvature = p->min_curvature; | q->min_curvature = p->min_curvature; | ||||
| q->max_curvature = p->max_curvature; | q->max_curvature = p->max_curvature; | ||||
| break; | break; | ||||
| } | } | ||||
| default: | default: | ||||
| return NULL; /* unknown modifier type */ | return nullptr; /* unknown modifier type */ | ||||
| } | } | ||||
| add_to_modifier_list(&linestyle->color_modifiers, new_m); | add_to_modifier_list(&linestyle->color_modifiers, new_m); | ||||
| return new_m; | return new_m; | ||||
| } | } | ||||
| int BKE_linestyle_color_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *m) | int BKE_linestyle_color_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *m) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | case LS_MODIFIER_NOISE: | ||||
| break; | break; | ||||
| case LS_MODIFIER_CREASE_ANGLE: | case LS_MODIFIER_CREASE_ANGLE: | ||||
| size = sizeof(LineStyleAlphaModifier_CreaseAngle); | size = sizeof(LineStyleAlphaModifier_CreaseAngle); | ||||
| break; | break; | ||||
| case LS_MODIFIER_CURVATURE_3D: | case LS_MODIFIER_CURVATURE_3D: | ||||
| size = sizeof(LineStyleAlphaModifier_Curvature_3D); | size = sizeof(LineStyleAlphaModifier_Curvature_3D); | ||||
| break; | break; | ||||
| default: | default: | ||||
| return NULL; /* unknown modifier type */ | return nullptr; /* unknown modifier type */ | ||||
| } | } | ||||
| return new_modifier(name, type, size); | return new_modifier(name, type, size); | ||||
| } | } | ||||
| LineStyleModifier *BKE_linestyle_alpha_modifier_add(FreestyleLineStyle *linestyle, | LineStyleModifier *BKE_linestyle_alpha_modifier_add(FreestyleLineStyle *linestyle, | ||||
| const char *name, | const char *name, | ||||
| int type) | int type) | ||||
| { | { | ||||
| Show All 14 Lines | case LS_MODIFIER_DISTANCE_FROM_CAMERA: { | ||||
| p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); | p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); | ||||
| p->range_min = 0.0f; | p->range_min = 0.0f; | ||||
| p->range_max = 10000.0f; | p->range_max = 10000.0f; | ||||
| break; | break; | ||||
| } | } | ||||
| case LS_MODIFIER_DISTANCE_FROM_OBJECT: { | case LS_MODIFIER_DISTANCE_FROM_OBJECT: { | ||||
| LineStyleAlphaModifier_DistanceFromObject *p = (LineStyleAlphaModifier_DistanceFromObject *) | LineStyleAlphaModifier_DistanceFromObject *p = (LineStyleAlphaModifier_DistanceFromObject *) | ||||
| m; | m; | ||||
| p->target = NULL; | p->target = nullptr; | ||||
| p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); | p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); | ||||
| p->range_min = 0.0f; | p->range_min = 0.0f; | ||||
| p->range_max = 10000.0f; | p->range_max = 10000.0f; | ||||
| break; | break; | ||||
| } | } | ||||
| case LS_MODIFIER_MATERIAL: { | case LS_MODIFIER_MATERIAL: { | ||||
| LineStyleAlphaModifier_Material *p = (LineStyleAlphaModifier_Material *)m; | LineStyleAlphaModifier_Material *p = (LineStyleAlphaModifier_Material *)m; | ||||
| p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); | p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); | ||||
| Show All 23 Lines | switch (type) { | ||||
| case LS_MODIFIER_CURVATURE_3D: { | case LS_MODIFIER_CURVATURE_3D: { | ||||
| LineStyleAlphaModifier_Curvature_3D *p = (LineStyleAlphaModifier_Curvature_3D *)m; | LineStyleAlphaModifier_Curvature_3D *p = (LineStyleAlphaModifier_Curvature_3D *)m; | ||||
| p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); | p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); | ||||
| ((LineStyleAlphaModifier_Curvature_3D *)m)->min_curvature = 0.0f; | ((LineStyleAlphaModifier_Curvature_3D *)m)->min_curvature = 0.0f; | ||||
| ((LineStyleAlphaModifier_Curvature_3D *)m)->max_curvature = 0.5f; | ((LineStyleAlphaModifier_Curvature_3D *)m)->max_curvature = 0.5f; | ||||
| break; | break; | ||||
| } | } | ||||
| default: | default: | ||||
| return NULL; /* unknown modifier type */ | return nullptr; /* unknown modifier type */ | ||||
| } | } | ||||
| add_to_modifier_list(&linestyle->alpha_modifiers, m); | add_to_modifier_list(&linestyle->alpha_modifiers, m); | ||||
| return m; | return m; | ||||
| } | } | ||||
| LineStyleModifier *BKE_linestyle_alpha_modifier_copy(FreestyleLineStyle *linestyle, | LineStyleModifier *BKE_linestyle_alpha_modifier_copy(FreestyleLineStyle *linestyle, | ||||
| const LineStyleModifier *m, | const LineStyleModifier *m, | ||||
| ▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | case LS_MODIFIER_CURVATURE_3D: { | ||||
| LineStyleAlphaModifier_Curvature_3D *q = (LineStyleAlphaModifier_Curvature_3D *)new_m; | LineStyleAlphaModifier_Curvature_3D *q = (LineStyleAlphaModifier_Curvature_3D *)new_m; | ||||
| q->curve = BKE_curvemapping_copy(p->curve); | q->curve = BKE_curvemapping_copy(p->curve); | ||||
| q->flags = p->flags; | q->flags = p->flags; | ||||
| q->min_curvature = p->min_curvature; | q->min_curvature = p->min_curvature; | ||||
| q->max_curvature = p->max_curvature; | q->max_curvature = p->max_curvature; | ||||
| break; | break; | ||||
| } | } | ||||
| default: | default: | ||||
| return NULL; /* unknown modifier type */ | return nullptr; /* unknown modifier type */ | ||||
| } | } | ||||
| add_to_modifier_list(&linestyle->alpha_modifiers, new_m); | add_to_modifier_list(&linestyle->alpha_modifiers, new_m); | ||||
| return new_m; | return new_m; | ||||
| } | } | ||||
| int BKE_linestyle_alpha_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *m) | int BKE_linestyle_alpha_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *m) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | case LS_MODIFIER_NOISE: | ||||
| break; | break; | ||||
| case LS_MODIFIER_CREASE_ANGLE: | case LS_MODIFIER_CREASE_ANGLE: | ||||
| size = sizeof(LineStyleThicknessModifier_CreaseAngle); | size = sizeof(LineStyleThicknessModifier_CreaseAngle); | ||||
| break; | break; | ||||
| case LS_MODIFIER_CURVATURE_3D: | case LS_MODIFIER_CURVATURE_3D: | ||||
| size = sizeof(LineStyleThicknessModifier_Curvature_3D); | size = sizeof(LineStyleThicknessModifier_Curvature_3D); | ||||
| break; | break; | ||||
| default: | default: | ||||
| return NULL; /* unknown modifier type */ | return nullptr; /* unknown modifier type */ | ||||
| } | } | ||||
| return new_modifier(name, type, size); | return new_modifier(name, type, size); | ||||
| } | } | ||||
| LineStyleModifier *BKE_linestyle_thickness_modifier_add(FreestyleLineStyle *linestyle, | LineStyleModifier *BKE_linestyle_thickness_modifier_add(FreestyleLineStyle *linestyle, | ||||
| const char *name, | const char *name, | ||||
| int type) | int type) | ||||
| Show All 19 Lines | case LS_MODIFIER_DISTANCE_FROM_CAMERA: { | ||||
| p->range_max = 1000.0f; | p->range_max = 1000.0f; | ||||
| p->value_min = 0.0f; | p->value_min = 0.0f; | ||||
| p->value_max = 1.0f; | p->value_max = 1.0f; | ||||
| break; | break; | ||||
| } | } | ||||
| case LS_MODIFIER_DISTANCE_FROM_OBJECT: { | case LS_MODIFIER_DISTANCE_FROM_OBJECT: { | ||||
| LineStyleThicknessModifier_DistanceFromObject *p = | LineStyleThicknessModifier_DistanceFromObject *p = | ||||
| (LineStyleThicknessModifier_DistanceFromObject *)m; | (LineStyleThicknessModifier_DistanceFromObject *)m; | ||||
| p->target = NULL; | p->target = nullptr; | ||||
| p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); | p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); | ||||
| p->range_min = 0.0f; | p->range_min = 0.0f; | ||||
| p->range_max = 1000.0f; | p->range_max = 1000.0f; | ||||
| p->value_min = 0.0f; | p->value_min = 0.0f; | ||||
| p->value_max = 1.0f; | p->value_max = 1.0f; | ||||
| break; | break; | ||||
| } | } | ||||
| case LS_MODIFIER_MATERIAL: { | case LS_MODIFIER_MATERIAL: { | ||||
| Show All 40 Lines | case LS_MODIFIER_CURVATURE_3D: { | ||||
| p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); | p->curve = BKE_curvemapping_add(1, 0.0f, 0.0f, 1.0f, 1.0f); | ||||
| p->min_curvature = 0.0f; | p->min_curvature = 0.0f; | ||||
| p->max_curvature = 0.5f; | p->max_curvature = 0.5f; | ||||
| p->min_thickness = 1.0f; | p->min_thickness = 1.0f; | ||||
| p->max_thickness = 10.0f; | p->max_thickness = 10.0f; | ||||
| break; | break; | ||||
| } | } | ||||
| default: | default: | ||||
| return NULL; /* unknown modifier type */ | return nullptr; /* unknown modifier type */ | ||||
| } | } | ||||
| add_to_modifier_list(&linestyle->thickness_modifiers, m); | add_to_modifier_list(&linestyle->thickness_modifiers, m); | ||||
| return m; | return m; | ||||
| } | } | ||||
| LineStyleModifier *BKE_linestyle_thickness_modifier_copy(FreestyleLineStyle *linestyle, | LineStyleModifier *BKE_linestyle_thickness_modifier_copy(FreestyleLineStyle *linestyle, | ||||
| const LineStyleModifier *m, | const LineStyleModifier *m, | ||||
| const int flag) | const int flag) | ||||
| { | { | ||||
| LineStyleModifier *new_m; | LineStyleModifier *new_m; | ||||
| new_m = alloc_thickness_modifier(m->name, m->type); | new_m = alloc_thickness_modifier(m->name, m->type); | ||||
| if (!new_m) { | if (!new_m) { | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| new_m->influence = m->influence; | new_m->influence = m->influence; | ||||
| new_m->flags = m->flags; | new_m->flags = m->flags; | ||||
| new_m->blend = m->blend; | new_m->blend = m->blend; | ||||
| switch (m->type) { | switch (m->type) { | ||||
| case LS_MODIFIER_ALONG_STROKE: { | case LS_MODIFIER_ALONG_STROKE: { | ||||
| LineStyleThicknessModifier_AlongStroke *p = (LineStyleThicknessModifier_AlongStroke *)m; | LineStyleThicknessModifier_AlongStroke *p = (LineStyleThicknessModifier_AlongStroke *)m; | ||||
| ▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | case LS_MODIFIER_CREASE_ANGLE: { | ||||
| q->flags = p->flags; | q->flags = p->flags; | ||||
| q->min_angle = p->min_angle; | q->min_angle = p->min_angle; | ||||
| q->max_angle = p->max_angle; | q->max_angle = p->max_angle; | ||||
| q->min_thickness = p->min_thickness; | q->min_thickness = p->min_thickness; | ||||
| q->max_thickness = p->max_thickness; | q->max_thickness = p->max_thickness; | ||||
| break; | break; | ||||
| } | } | ||||
| default: | default: | ||||
| return NULL; /* unknown modifier type */ | return nullptr; /* unknown modifier type */ | ||||
| } | } | ||||
| add_to_modifier_list(&linestyle->thickness_modifiers, new_m); | add_to_modifier_list(&linestyle->thickness_modifiers, new_m); | ||||
| return new_m; | return new_m; | ||||
| } | } | ||||
| int BKE_linestyle_thickness_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *m) | int BKE_linestyle_thickness_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *m) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | case LS_MODIFIER_2D_OFFSET: | ||||
| break; | break; | ||||
| case LS_MODIFIER_2D_TRANSFORM: | case LS_MODIFIER_2D_TRANSFORM: | ||||
| size = sizeof(LineStyleGeometryModifier_2DTransform); | size = sizeof(LineStyleGeometryModifier_2DTransform); | ||||
| break; | break; | ||||
| case LS_MODIFIER_SIMPLIFICATION: | case LS_MODIFIER_SIMPLIFICATION: | ||||
| size = sizeof(LineStyleGeometryModifier_Simplification); | size = sizeof(LineStyleGeometryModifier_Simplification); | ||||
| break; | break; | ||||
| default: | default: | ||||
| return NULL; /* unknown modifier type */ | return nullptr; /* unknown modifier type */ | ||||
| } | } | ||||
| return new_modifier(name, type, size); | return new_modifier(name, type, size); | ||||
| } | } | ||||
| LineStyleModifier *BKE_linestyle_geometry_modifier_add(FreestyleLineStyle *linestyle, | LineStyleModifier *BKE_linestyle_geometry_modifier_add(FreestyleLineStyle *linestyle, | ||||
| const char *name, | const char *name, | ||||
| int type) | int type) | ||||
| ▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | case LS_MODIFIER_2D_TRANSFORM: { | ||||
| break; | break; | ||||
| } | } | ||||
| case LS_MODIFIER_SIMPLIFICATION: { | case LS_MODIFIER_SIMPLIFICATION: { | ||||
| LineStyleGeometryModifier_Simplification *p = (LineStyleGeometryModifier_Simplification *)m; | LineStyleGeometryModifier_Simplification *p = (LineStyleGeometryModifier_Simplification *)m; | ||||
| p->tolerance = 0.1f; | p->tolerance = 0.1f; | ||||
| break; | break; | ||||
| } | } | ||||
| default: | default: | ||||
| return NULL; /* unknown modifier type */ | return nullptr; /* unknown modifier type */ | ||||
| } | } | ||||
| add_to_modifier_list(&linestyle->geometry_modifiers, m); | add_to_modifier_list(&linestyle->geometry_modifiers, m); | ||||
| return m; | return m; | ||||
| } | } | ||||
| LineStyleModifier *BKE_linestyle_geometry_modifier_copy(FreestyleLineStyle *linestyle, | LineStyleModifier *BKE_linestyle_geometry_modifier_copy(FreestyleLineStyle *linestyle, | ||||
| const LineStyleModifier *m, | const LineStyleModifier *m, | ||||
| ▲ Show 20 Lines • Show All 121 Lines • ▼ Show 20 Lines | switch (m->type) { | ||||
| case LS_MODIFIER_SIMPLIFICATION: { | case LS_MODIFIER_SIMPLIFICATION: { | ||||
| LineStyleGeometryModifier_Simplification *p = (LineStyleGeometryModifier_Simplification *)m; | LineStyleGeometryModifier_Simplification *p = (LineStyleGeometryModifier_Simplification *)m; | ||||
| LineStyleGeometryModifier_Simplification *q = (LineStyleGeometryModifier_Simplification *) | LineStyleGeometryModifier_Simplification *q = (LineStyleGeometryModifier_Simplification *) | ||||
| new_m; | new_m; | ||||
| q->tolerance = p->tolerance; | q->tolerance = p->tolerance; | ||||
| break; | break; | ||||
| } | } | ||||
| default: | default: | ||||
| return NULL; /* unknown modifier type */ | return nullptr; /* unknown modifier type */ | ||||
| } | } | ||||
| add_to_modifier_list(&linestyle->geometry_modifiers, new_m); | add_to_modifier_list(&linestyle->geometry_modifiers, new_m); | ||||
| return new_m; | return new_m; | ||||
| } | } | ||||
| int BKE_linestyle_geometry_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *m) | int BKE_linestyle_geometry_modifier_remove(FreestyleLineStyle *linestyle, LineStyleModifier *m) | ||||
| { | { | ||||
| ▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | for (m = (LineStyleModifier *)linestyle->color_modifiers.first; m; m = m->next) { | ||||
| if (found) { | if (found) { | ||||
| char name_esc[sizeof(m->name) * 2]; | char name_esc[sizeof(m->name) * 2]; | ||||
| BLI_str_escape(name_esc, m->name, sizeof(name_esc)); | BLI_str_escape(name_esc, m->name, sizeof(name_esc)); | ||||
| return BLI_sprintfN("color_modifiers[\"%s\"].color_ramp", name_esc); | return BLI_sprintfN("color_modifiers[\"%s\"].color_ramp", name_esc); | ||||
| } | } | ||||
| } | } | ||||
| printf("BKE_linestyle_path_to_color_ramp: No color ramps correspond to the given pointer.\n"); | printf("BKE_linestyle_path_to_color_ramp: No color ramps correspond to the given pointer.\n"); | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| bool BKE_linestyle_use_textures(FreestyleLineStyle *linestyle, const bool use_shading_nodes) | bool BKE_linestyle_use_textures(FreestyleLineStyle *linestyle, const bool use_shading_nodes) | ||||
| { | { | ||||
| if (use_shading_nodes) { | if (use_shading_nodes) { | ||||
| if (linestyle && linestyle->use_nodes && linestyle->nodetree) { | if (linestyle && linestyle->use_nodes && linestyle->nodetree) { | ||||
| bNode *node; | bNode *node; | ||||
| for (node = linestyle->nodetree->nodes.first; node; node = node->next) { | for (node = static_cast<bNode *>(linestyle->nodetree->nodes.first); node; | ||||
| node = node->next) { | |||||
| if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) { | if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| if (linestyle && (linestyle->flag & LS_TEXTURE)) { | if (linestyle && (linestyle->flag & LS_TEXTURE)) { | ||||
| return (linestyle->mtex[0] != NULL); | return (linestyle->mtex[0] != nullptr); | ||||
| } | } | ||||
| } | } | ||||
| return false; | return false; | ||||
| } | } | ||||
| void BKE_linestyle_default_shader(const bContext *C, FreestyleLineStyle *linestyle) | void BKE_linestyle_default_shader(const bContext *C, FreestyleLineStyle *linestyle) | ||||
| { | { | ||||
| bNode *uv_along_stroke, *input_texture, *output_linestyle; | bNode *uv_along_stroke, *input_texture, *output_linestyle; | ||||
| bNodeSocket *fromsock, *tosock; | bNodeSocket *fromsock, *tosock; | ||||
| bNodeTree *ntree; | bNodeTree *ntree; | ||||
| BLI_assert(linestyle->nodetree == NULL); | BLI_assert(linestyle->nodetree == nullptr); | ||||
| ntree = ntreeAddTreeEmbedded(NULL, &linestyle->id, "stroke_shader", "ShaderNodeTree"); | ntree = ntreeAddTreeEmbedded(nullptr, &linestyle->id, "stroke_shader", "ShaderNodeTree"); | ||||
| uv_along_stroke = nodeAddStaticNode(C, ntree, SH_NODE_UVALONGSTROKE); | uv_along_stroke = nodeAddStaticNode(C, ntree, SH_NODE_UVALONGSTROKE); | ||||
| uv_along_stroke->locx = 0.0f; | uv_along_stroke->locx = 0.0f; | ||||
| uv_along_stroke->locy = 300.0f; | uv_along_stroke->locy = 300.0f; | ||||
| uv_along_stroke->custom1 = 0; /* use_tips */ | uv_along_stroke->custom1 = 0; /* use_tips */ | ||||
| input_texture = nodeAddStaticNode(C, ntree, SH_NODE_TEX_IMAGE); | input_texture = nodeAddStaticNode(C, ntree, SH_NODE_TEX_IMAGE); | ||||
| input_texture->locx = 200.0f; | input_texture->locx = 200.0f; | ||||
| input_texture->locy = 300.0f; | input_texture->locy = 300.0f; | ||||
| output_linestyle = nodeAddStaticNode(C, ntree, SH_NODE_OUTPUT_LINESTYLE); | output_linestyle = nodeAddStaticNode(C, ntree, SH_NODE_OUTPUT_LINESTYLE); | ||||
| output_linestyle->locx = 400.0f; | output_linestyle->locx = 400.0f; | ||||
| output_linestyle->locy = 300.0f; | output_linestyle->locy = 300.0f; | ||||
| output_linestyle->custom1 = MA_RAMP_BLEND; | output_linestyle->custom1 = MA_RAMP_BLEND; | ||||
| output_linestyle->custom2 = 0; /* use_clamp */ | output_linestyle->custom2 = 0; /* use_clamp */ | ||||
| nodeSetActive(ntree, input_texture); | nodeSetActive(ntree, input_texture); | ||||
| fromsock = BLI_findlink(&uv_along_stroke->outputs, 0); /* UV */ | fromsock = static_cast<bNodeSocket *>(BLI_findlink(&uv_along_stroke->outputs, 0)); /* UV */ | ||||
| tosock = BLI_findlink(&input_texture->inputs, 0); /* UV */ | tosock = static_cast<bNodeSocket *>(BLI_findlink(&input_texture->inputs, 0)); /* UV */ | ||||
| nodeAddLink(ntree, uv_along_stroke, fromsock, input_texture, tosock); | nodeAddLink(ntree, uv_along_stroke, fromsock, input_texture, tosock); | ||||
| fromsock = BLI_findlink(&input_texture->outputs, 0); /* Color */ | fromsock = static_cast<bNodeSocket *>(BLI_findlink(&input_texture->outputs, 0)); /* Color */ | ||||
| tosock = BLI_findlink(&output_linestyle->inputs, 0); /* Color */ | tosock = static_cast<bNodeSocket *>(BLI_findlink(&output_linestyle->inputs, 0)); /* Color */ | ||||
| nodeAddLink(ntree, input_texture, fromsock, output_linestyle, tosock); | nodeAddLink(ntree, input_texture, fromsock, output_linestyle, tosock); | ||||
| BKE_ntree_update_main_tree(CTX_data_main(C), ntree, NULL); | BKE_ntree_update_main_tree(CTX_data_main(C), ntree, nullptr); | ||||
| } | } | ||||