Brush *BKE_brush_copy(Main *bmain, Brush *brush) { Brush *brushn; brushn = BKE_libblock_copy(bmain, &brush->id); if (brush->mtex.tex) id_us_plus((ID *)brush->mtex.tex); if (brush->mask_mtex.tex) id_us_plus((ID *)brush->mask_mtex.tex); if (brush->paint_curve) id_us_plus((ID *)brush->paint_curve); if (brush->icon_imbuf) brushn->icon_imbuf = IMB_dupImBuf(brush->icon_imbuf); brushn->preview = NULL; brushn->curve = curvemapping_copy(brush->curve); /* enable fake user by default */ id_fake_user_set(&brush->id); BKE_id_copy_ensure_local(bmain, &brush->id, &brushn->id); return brushn; }
bAction *BKE_action_copy(Main *bmain, bAction *src) { bAction *dst = NULL; bActionGroup *dgrp, *sgrp; FCurve *dfcu, *sfcu; if (src == NULL) return NULL; dst = BKE_libblock_copy(bmain, &src->id); /* duplicate the lists of groups and markers */ BLI_duplicatelist(&dst->groups, &src->groups); BLI_duplicatelist(&dst->markers, &src->markers); /* copy F-Curves, fixing up the links as we go */ BLI_listbase_clear(&dst->curves); for (sfcu = src->curves.first; sfcu; sfcu = sfcu->next) { /* duplicate F-Curve */ dfcu = copy_fcurve(sfcu); BLI_addtail(&dst->curves, dfcu); /* fix group links (kindof bad list-in-list search, but this is the most reliable way) */ for (dgrp = dst->groups.first, sgrp = src->groups.first; dgrp && sgrp; dgrp = dgrp->next, sgrp = sgrp->next) { if (sfcu->grp == sgrp) { dfcu->grp = dgrp; if (dgrp->channels.first == sfcu) dgrp->channels.first = dfcu; if (dgrp->channels.last == sfcu) dgrp->channels.last = dfcu; break; } } } BKE_id_copy_ensure_local(bmain, &src->id, &dst->id); return dst; }
FreestyleLineStyle *BKE_linestyle_copy(struct Main *bmain, FreestyleLineStyle *linestyle) { FreestyleLineStyle *new_linestyle; LineStyleModifier *m; int a; new_linestyle = BKE_linestyle_new(bmain, linestyle->id.name + 2); BKE_linestyle_free(new_linestyle); for (a = 0; a < MAX_MTEX; a++) { if (linestyle->mtex[a]) { new_linestyle->mtex[a] = MEM_mallocN(sizeof(MTex), "BKE_linestyle_copy"); memcpy(new_linestyle->mtex[a], linestyle->mtex[a], sizeof(MTex)); id_us_plus((ID *)new_linestyle->mtex[a]->tex); } } if (linestyle->nodetree) { new_linestyle->nodetree = ntreeCopyTree(bmain, linestyle->nodetree); } 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->split_length = linestyle->split_length; 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->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; }