Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/linestyle.c
| Show First 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | void BKE_linestyle_free(FreestyleLineStyle *linestyle) | ||||
| while ((m = (LineStyleModifier *)linestyle->alpha_modifiers.first)) | while ((m = (LineStyleModifier *)linestyle->alpha_modifiers.first)) | ||||
| BKE_linestyle_alpha_modifier_remove(linestyle, m); | BKE_linestyle_alpha_modifier_remove(linestyle, m); | ||||
| while ((m = (LineStyleModifier *)linestyle->thickness_modifiers.first)) | while ((m = (LineStyleModifier *)linestyle->thickness_modifiers.first)) | ||||
| BKE_linestyle_thickness_modifier_remove(linestyle, m); | BKE_linestyle_thickness_modifier_remove(linestyle, m); | ||||
| while ((m = (LineStyleModifier *)linestyle->geometry_modifiers.first)) | while ((m = (LineStyleModifier *)linestyle->geometry_modifiers.first)) | ||||
| BKE_linestyle_geometry_modifier_remove(linestyle, m); | BKE_linestyle_geometry_modifier_remove(linestyle, m); | ||||
| } | } | ||||
| FreestyleLineStyle *BKE_linestyle_copy(struct Main *bmain, const FreestyleLineStyle *linestyle) | /** | ||||
| * Only copy internal data of Linestyle ID from source to already allocated/initialized destination. | |||||
| * You probably nerver want to use that directly, use id_copy or BKE_id_copy_ex for typical needs. | |||||
| * | |||||
| * WARNING! This function will not handle ID user count! | |||||
| * | |||||
| * \param flag Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more). | |||||
| */ | |||||
| void BKE_linestyle_copy_data( | |||||
| struct Main *bmain, FreestyleLineStyle *linestyle_dst, const FreestyleLineStyle *linestyle_src, const int flag) | |||||
| { | { | ||||
| FreestyleLineStyle *new_linestyle; | /* We never handle usercount here for own data. */ | ||||
| LineStyleModifier *m; | const int flag_subdata = flag | LIB_ID_COPY_NO_USER_REFCOUNT; | ||||
| int a; | |||||
| new_linestyle = BKE_linestyle_new(bmain, linestyle->id.name + 2); | |||||
| BKE_linestyle_free(new_linestyle); | |||||
| for (a = 0; a < MAX_MTEX; a++) { | for (int a = 0; a < MAX_MTEX; a++) { | ||||
| if (linestyle->mtex[a]) { | if (linestyle_src->mtex[a]) { | ||||
| new_linestyle->mtex[a] = MEM_mallocN(sizeof(MTex), "BKE_linestyle_copy"); | linestyle_dst->mtex[a] = MEM_mallocN(sizeof(*linestyle_dst->mtex[a]), __func__); | ||||
| memcpy(new_linestyle->mtex[a], linestyle->mtex[a], sizeof(MTex)); | *linestyle_dst->mtex[a] = *linestyle_src->mtex[a]; | ||||
| id_us_plus((ID *)new_linestyle->mtex[a]->tex); | |||||
| } | } | ||||
| } | } | ||||
| if (linestyle->nodetree) { | if (linestyle_src->nodetree) { | ||||
| new_linestyle->nodetree = ntreeCopyTree(bmain, linestyle->nodetree); | BKE_id_copy_ex(bmain, (ID *)linestyle_src->nodetree, (ID **)&linestyle_dst->nodetree, flag, false); | ||||
| } | } | ||||
| new_linestyle->r = linestyle->r; | LineStyleModifier *m; | ||||
| new_linestyle->g = linestyle->g; | BLI_listbase_clear(&linestyle_dst->color_modifiers); | ||||
| new_linestyle->b = linestyle->b; | for (m = (LineStyleModifier *)linestyle_src->color_modifiers.first; m; m = m->next) { | ||||
| new_linestyle->alpha = linestyle->alpha; | BKE_linestyle_color_modifier_copy(linestyle_dst, m, flag_subdata); | ||||
| new_linestyle->thickness = linestyle->thickness; | } | ||||
| new_linestyle->thickness_position = linestyle->thickness_position; | BLI_listbase_clear(&linestyle_dst->alpha_modifiers); | ||||
| new_linestyle->thickness_ratio = linestyle->thickness_ratio; | for (m = (LineStyleModifier *)linestyle_src->alpha_modifiers.first; m; m = m->next) { | ||||
| new_linestyle->flag = linestyle->flag; | BKE_linestyle_alpha_modifier_copy(linestyle_dst, m, flag_subdata); | ||||
| new_linestyle->caps = linestyle->caps; | } | ||||
| new_linestyle->chaining = linestyle->chaining; | BLI_listbase_clear(&linestyle_dst->thickness_modifiers); | ||||
| new_linestyle->rounds = linestyle->rounds; | for (m = (LineStyleModifier *)linestyle_src->thickness_modifiers.first; m; m = m->next) { | ||||
| new_linestyle->split_length = linestyle->split_length; | BKE_linestyle_thickness_modifier_copy(linestyle_dst, m, flag_subdata); | ||||
| new_linestyle->min_angle = linestyle->min_angle; | } | ||||
| new_linestyle->max_angle = linestyle->max_angle; | BLI_listbase_clear(&linestyle_dst->geometry_modifiers); | ||||
| new_linestyle->min_length = linestyle->min_length; | for (m = (LineStyleModifier *)linestyle_src->geometry_modifiers.first; m; m = m->next) { | ||||
| new_linestyle->max_length = linestyle->max_length; | BKE_linestyle_geometry_modifier_copy(linestyle_dst, m, flag_subdata); | ||||
| new_linestyle->chain_count = linestyle->chain_count; | } | ||||
| new_linestyle->split_dash1 = linestyle->split_dash1; | } | ||||
| new_linestyle->split_gap1 = linestyle->split_gap1; | |||||
| new_linestyle->split_dash2 = linestyle->split_dash2; | |||||
| new_linestyle->split_gap2 = linestyle->split_gap2; | |||||
| new_linestyle->split_dash3 = linestyle->split_dash3; | |||||
| new_linestyle->split_gap3 = linestyle->split_gap3; | |||||
| 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; | |||||
| new_linestyle->sort_key = linestyle->sort_key; | |||||
| new_linestyle->integration_type = linestyle->integration_type; | |||||
| new_linestyle->texstep = linestyle->texstep; | |||||
| new_linestyle->pr_texture = linestyle->pr_texture; | |||||
| new_linestyle->use_nodes = linestyle->use_nodes; | |||||
| for (m = (LineStyleModifier *)linestyle->color_modifiers.first; m; m = m->next) | |||||
| BKE_linestyle_color_modifier_copy(new_linestyle, m); | |||||
| for (m = (LineStyleModifier *)linestyle->alpha_modifiers.first; m; m = m->next) | |||||
| BKE_linestyle_alpha_modifier_copy(new_linestyle, m); | |||||
| for (m = (LineStyleModifier *)linestyle->thickness_modifiers.first; m; m = m->next) | |||||
| BKE_linestyle_thickness_modifier_copy(new_linestyle, m); | |||||
| for (m = (LineStyleModifier *)linestyle->geometry_modifiers.first; m; m = m->next) | |||||
| BKE_linestyle_geometry_modifier_copy(new_linestyle, m); | |||||
| BKE_id_copy_ensure_local(bmain, &linestyle->id, &new_linestyle->id); | |||||
| return new_linestyle; | FreestyleLineStyle *BKE_linestyle_copy(struct Main *bmain, const FreestyleLineStyle *linestyle) | ||||
| { | |||||
| FreestyleLineStyle *linestyle_copy; | |||||
| BKE_id_copy_ex(bmain, &linestyle->id, (ID **)&linestyle_copy, 0, false); | |||||
| return linestyle_copy; | |||||
| } | } | ||||
| void BKE_linestyle_make_local(struct Main *bmain, FreestyleLineStyle *linestyle, const bool lib_local) | void BKE_linestyle_make_local(struct Main *bmain, FreestyleLineStyle *linestyle, const bool lib_local) | ||||
| { | { | ||||
| BKE_id_make_local_generic(bmain, &linestyle->id, true, lib_local); | BKE_id_make_local_generic(bmain, &linestyle->id, true, lib_local); | ||||
| } | } | ||||
| FreestyleLineStyle *BKE_linestyle_active_from_scene(Scene *scene) | FreestyleLineStyle *BKE_linestyle_active_from_scene(Scene *scene) | ||||
| ▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | switch (type) { | ||||
| default: | default: | ||||
| return NULL; /* unknown modifier type */ | return NULL; /* 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, const LineStyleModifier *m) | LineStyleModifier *BKE_linestyle_color_modifier_copy( | ||||
| FreestyleLineStyle *linestyle, const LineStyleModifier *m, 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 == NULL)) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| new_m->influence = m->influence; | new_m->influence = m->influence; | ||||
| Show All 16 Lines | case LS_MODIFIER_DISTANCE_FROM_CAMERA: | ||||
| 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 *)m; | LineStyleColorModifier_DistanceFromObject *p = (LineStyleColorModifier_DistanceFromObject *)m; | ||||
| LineStyleColorModifier_DistanceFromObject *q = (LineStyleColorModifier_DistanceFromObject *)new_m; | LineStyleColorModifier_DistanceFromObject *q = (LineStyleColorModifier_DistanceFromObject *)new_m; | ||||
| if (p->target) | |||||
| id_us_plus(&p->target->id); | |||||
| q->target = p->target; | q->target = p->target; | ||||
| if ((flag & LIB_ID_COPY_NO_USER_REFCOUNT) == 0) { | |||||
| id_us_plus((ID *)q->target); | |||||
| } | |||||
| q->color_ramp = MEM_dupallocN(p->color_ramp); | q->color_ramp = 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; | ||||
| ▲ Show 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | switch (type) { | ||||
| default: | default: | ||||
| return NULL; /* unknown modifier type */ | return NULL; /* 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, const LineStyleModifier *m) | LineStyleModifier *BKE_linestyle_alpha_modifier_copy( | ||||
| FreestyleLineStyle *linestyle, const LineStyleModifier *m, const int UNUSED(flag)) | |||||
| { | { | ||||
| LineStyleModifier *new_m; | LineStyleModifier *new_m; | ||||
| new_m = alloc_alpha_modifier(m->name, m->type); | new_m = alloc_alpha_modifier(m->name, m->type); | ||||
| 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; | ||||
| ▲ Show 20 Lines • Show All 252 Lines • ▼ Show 20 Lines | switch (type) { | ||||
| default: | default: | ||||
| return NULL; /* unknown modifier type */ | return NULL; /* 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, const LineStyleModifier *m) | LineStyleModifier *BKE_linestyle_thickness_modifier_copy( | ||||
| FreestyleLineStyle *linestyle, const LineStyleModifier *m, 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 NULL; | ||||
| new_m->influence = m->influence; | new_m->influence = m->influence; | ||||
| new_m->flags = m->flags; | new_m->flags = m->flags; | ||||
| Show All 21 Lines | case LS_MODIFIER_DISTANCE_FROM_CAMERA: | ||||
| q->value_min = p->value_min; | q->value_min = p->value_min; | ||||
| q->value_max = p->value_max; | q->value_max = p->value_max; | ||||
| break; | break; | ||||
| } | } | ||||
| case LS_MODIFIER_DISTANCE_FROM_OBJECT: | case LS_MODIFIER_DISTANCE_FROM_OBJECT: | ||||
| { | { | ||||
| LineStyleThicknessModifier_DistanceFromObject *p = (LineStyleThicknessModifier_DistanceFromObject *)m; | LineStyleThicknessModifier_DistanceFromObject *p = (LineStyleThicknessModifier_DistanceFromObject *)m; | ||||
| LineStyleThicknessModifier_DistanceFromObject *q = (LineStyleThicknessModifier_DistanceFromObject *)new_m; | LineStyleThicknessModifier_DistanceFromObject *q = (LineStyleThicknessModifier_DistanceFromObject *)new_m; | ||||
| if (p->target) | |||||
| id_us_plus(&p->target->id); | |||||
| q->target = p->target; | q->target = p->target; | ||||
| if ((flag & LIB_ID_COPY_NO_USER_REFCOUNT) == 0) { | |||||
| id_us_plus((ID *)q->target); | |||||
| } | |||||
| q->curve = curvemapping_copy(p->curve); | q->curve = curvemapping_copy(p->curve); | ||||
| q->flags = p->flags; | q->flags = p->flags; | ||||
| q->range_min = p->range_min; | q->range_min = p->range_min; | ||||
| q->range_max = p->range_max; | q->range_max = p->range_max; | ||||
| q->value_min = p->value_min; | q->value_min = p->value_min; | ||||
| q->value_max = p->value_max; | q->value_max = p->value_max; | ||||
| break; | break; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 275 Lines • ▼ Show 20 Lines | switch (type) { | ||||
| default: | default: | ||||
| return NULL; /* unknown modifier type */ | return NULL; /* 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, const LineStyleModifier *m) | LineStyleModifier *BKE_linestyle_geometry_modifier_copy( | ||||
| FreestyleLineStyle *linestyle, const LineStyleModifier *m, const int UNUSED(flag)) | |||||
| { | { | ||||
| LineStyleModifier *new_m; | LineStyleModifier *new_m; | ||||
| new_m = alloc_geometry_modifier(m->name, m->type); | new_m = alloc_geometry_modifier(m->name, m->type); | ||||
| new_m->flags = m->flags; | new_m->flags = m->flags; | ||||
| switch (m->type) { | switch (m->type) { | ||||
| case LS_MODIFIER_SAMPLING: | case LS_MODIFIER_SAMPLING: | ||||
| ▲ Show 20 Lines • Show All 303 Lines • Show Last 20 Lines | |||||