void BKE_linestyle_init(FreestyleLineStyle *linestyle) { BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(linestyle, id)); 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->flag = LS_SAME_OBJECT | LS_NO_SORTING | LS_TEXTURE; 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->chain_count = 10; linestyle->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA; linestyle->integration_type = LS_INTEGRATION_MEAN; linestyle->texstep = 1.0f; linestyle->pr_texture = TEX_PR_TEXTURE; BLI_listbase_clear(&linestyle->color_modifiers); BLI_listbase_clear(&linestyle->alpha_modifiers); BLI_listbase_clear(&linestyle->thickness_modifiers); BLI_listbase_clear(&linestyle->geometry_modifiers); BKE_linestyle_geometry_modifier_add(linestyle, NULL, LS_MODIFIER_SAMPLING); linestyle->caps = LS_CAPS_BUTT; }
/** * Only copy internal data of Collection ID from source * to already allocated/initialized destination. * You probably never want to use that directly, * use #BKE_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_collection_copy_data(Main *bmain, Collection *collection_dst, const Collection *collection_src, const int flag) { /* Do not copy collection's preview (same behavior as for objects). */ if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0 && false) { /* XXX TODO temp hack */ BKE_previewimg_id_copy(&collection_dst->id, &collection_src->id); } else { collection_dst->preview = NULL; } collection_dst->flag &= ~COLLECTION_HAS_OBJECT_CACHE; BLI_listbase_clear(&collection_dst->object_cache); BLI_listbase_clear(&collection_dst->gobject); BLI_listbase_clear(&collection_dst->children); BLI_listbase_clear(&collection_dst->parents); for (CollectionChild *child = collection_src->children.first; child; child = child->next) { collection_child_add(collection_dst, child->collection, flag, false); } for (CollectionObject *cob = collection_src->gobject.first; cob; cob = cob->next) { collection_object_add(bmain, collection_dst, cob->ob, flag, false); } }
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->flag = LS_SAME_OBJECT | LS_NO_SORTING; 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->sort_key = LS_SORT_KEY_DISTANCE_FROM_CAMERA; linestyle->integration_type = LS_INTEGRATION_MEAN; BLI_listbase_clear(&linestyle->color_modifiers); BLI_listbase_clear(&linestyle->alpha_modifiers); BLI_listbase_clear(&linestyle->thickness_modifiers); BLI_listbase_clear(&linestyle->geometry_modifiers); BKE_add_linestyle_geometry_modifier(linestyle, LS_MODIFIER_SAMPLING); linestyle->caps = LS_CAPS_BUTT; }
void BLI_scanfill_end(ScanFillContext *sf_ctx) { BLI_memarena_free(sf_ctx->arena); sf_ctx->arena = NULL; BLI_listbase_clear(&sf_ctx->fillvertbase); BLI_listbase_clear(&sf_ctx->filledgebase); BLI_listbase_clear(&sf_ctx->fillfacebase); }
void BLI_scanfill_end_arena(ScanFillContext *sf_ctx, MemArena *arena) { BLI_memarena_clear(arena); BLI_assert(sf_ctx->arena == arena); BLI_listbase_clear(&sf_ctx->fillvertbase); BLI_listbase_clear(&sf_ctx->filledgebase); BLI_listbase_clear(&sf_ctx->fillfacebase); }
static void copy_particle_edit(Scene *scene, Object *ob, ParticleSystem *psys, ParticleSystem *psys_from) { PTCacheEdit *edit_from = psys_from->edit, *edit; ParticleData *pa; KEY_K; POINT_P; if (!edit_from) return; edit = MEM_dupallocN(edit_from); edit->psys = psys; psys->edit = edit; edit->pathcache = NULL; BLI_listbase_clear(&edit->pathcachebufs); edit->emitter_field = NULL; edit->emitter_cosnos = NULL; BLI_listbase_clear(&edit->undo); edit->curundo = NULL; edit->points = MEM_dupallocN(edit_from->points); pa = psys->particles; LOOP_POINTS { HairKey *hkey = pa->hair; point->keys= MEM_dupallocN(point->keys); LOOP_KEYS { key->co = hkey->co; key->time = &hkey->time; key->flag = hkey->editflag; if (!(psys->flag & PSYS_GLOBAL_HAIR)) { key->flag |= PEK_USE_WCO; hkey->editflag |= PEK_USE_WCO; } hkey++; } pa++; } update_world_cos(ob, edit); UI_GetThemeColor3ubv(TH_EDGE_SELECT, edit->sel_col); UI_GetThemeColor3ubv(TH_WIRE, edit->nosel_col); recalc_lengths(edit); recalc_emitter_field(ob, psys); PE_update_object(scene, ob, true); PTCacheUndo_clear(edit); PE_undo_push(scene, "Original"); }
/* Bake */ void RE_bake_engine_set_engine_parameters(Render *re, Main *bmain, Scene *scene) { re->scene = scene; re->main = bmain; re->r = scene->r; /* prevent crash when freeing the scene * but it potentially leaves unfreed memory blocks * not sure how to fix this yet -- dfelinto */ BLI_listbase_clear(&re->r.layers); BLI_listbase_clear(&re->r.views); }
/* make a copy of a given gpencil datablock */ bGPdata *gpencil_data_duplicate(bGPdata *src, bool internal_copy) { bGPDlayer *gpl, *gpld; bGPdata *dst; /* error checking */ if (src == NULL) return NULL; /* make a copy of the base-data */ if (internal_copy) { /* make a straight copy for undo buffers used during stroke drawing */ dst = MEM_dupallocN(src); } else { /* make a copy when others use this */ dst = BKE_libblock_copy(&src->id); } /* copy layers */ BLI_listbase_clear(&dst->layers); for (gpl = src->layers.first; gpl; gpl = gpl->next) { /* make a copy of source layer and its data */ gpld = gpencil_layer_duplicate(gpl); BLI_addtail(&dst->layers, gpld); } /* return new */ return dst; }
// XXX find some header to put this in! void free_anim_copybuf(void) { tAnimCopybufItem *aci, *acn; /* free each buffer element */ for (aci = animcopybuf.first; aci; aci = acn) { acn = aci->next; /* free keyframes */ if (aci->bezt) MEM_freeN(aci->bezt); /* free RNA-path */ if (aci->rna_path) MEM_freeN(aci->rna_path); /* free ourself */ BLI_freelinkN(&animcopybuf, aci); } /* restore initial state */ BLI_listbase_clear(&animcopybuf); animcopy_firstframe = 999999999.0f; animcopy_lastframe = -999999999.0f; }
World *localize_world(World *wrld) { World *wrldn; int a; wrldn = BKE_libblock_copy_nolib(&wrld->id, false); for (a = 0; a < MAX_MTEX; a++) { if (wrld->mtex[a]) { wrldn->mtex[a] = MEM_mallocN(sizeof(MTex), "localize_world"); memcpy(wrldn->mtex[a], wrld->mtex[a], sizeof(MTex)); /* free world decrements */ id_us_plus((ID *)wrldn->mtex[a]->tex); } } if (wrld->nodetree) wrldn->nodetree = ntreeLocalize(wrld->nodetree); wrldn->preview = NULL; BLI_listbase_clear(&wrldn->gpumaterial); return wrldn; }
World *BKE_world_copy(World *wrld) { World *wrldn; int a; wrldn = BKE_libblock_copy(&wrld->id); for (a = 0; a < MAX_MTEX; a++) { if (wrld->mtex[a]) { wrldn->mtex[a] = MEM_mallocN(sizeof(MTex), "BKE_world_copy"); memcpy(wrldn->mtex[a], wrld->mtex[a], sizeof(MTex)); id_us_plus((ID *)wrldn->mtex[a]->tex); } } if (wrld->nodetree) { wrldn->nodetree = ntreeCopyTree(wrld->nodetree); } if (wrld->preview) wrldn->preview = BKE_previewimg_copy(wrld->preview); BLI_listbase_clear(&wrldn->gpumaterial); if (wrld->id.lib) { BKE_id_lib_local_paths(G.main, wrld->id.lib, &wrldn->id); } return wrldn; }
/* Duplicate all of the F-Modifiers in the Modifier stacks */ void copy_fmodifiers(ListBase *dst, const ListBase *src) { FModifier *fcm, *srcfcm; if (ELEM(NULL, dst, src)) { return; } BLI_listbase_clear(dst); BLI_duplicatelist(dst, src); for (fcm = dst->first, srcfcm = src->first; fcm && srcfcm; srcfcm = srcfcm->next, fcm = fcm->next) { const FModifierTypeInfo *fmi = fmodifier_get_typeinfo(fcm); /* make a new copy of the F-Modifier's data */ fcm->data = MEM_dupallocN(fcm->data); fcm->curve = NULL; /* only do specific constraints if required */ if (fmi && fmi->copy_data) { fmi->copy_data(fcm, srcfcm); } } }
void BLI_init_threads(ListBase *threadbase, void *(*do_thread)(void *), int tot) { int a; if (threadbase != NULL && tot > 0) { BLI_listbase_clear(threadbase); if (tot > RE_MAX_THREAD) tot = RE_MAX_THREAD; else if (tot < 1) tot = 1; for (a = 0; a < tot; a++) { ThreadSlot *tslot = MEM_callocN(sizeof(ThreadSlot), "threadslot"); BLI_addtail(threadbase, tslot); tslot->do_thread = do_thread; tslot->avail = 1; } } if (thread_levels == 0) { MEM_set_lock_callback(BLI_lock_malloc_thread, BLI_unlock_malloc_thread); #ifdef USE_APPLE_OMP_FIX /* workaround for Apple gcc 4.2.1 omp vs background thread bug, * we copy gomp thread local storage pointer to setting it again * inside the thread that we start */ thread_tls_data = pthread_getspecific(gomp_tls_key); #endif } thread_levels++; }
static void userdef_free_keymaps(UserDef *userdef) { for (wmKeyMap *km = userdef->user_keymaps.first, *km_next; km; km = km_next) { km_next = km->next; for (wmKeyMapDiffItem *kmdi = km->diff_items.first; kmdi; kmdi = kmdi->next) { if (kmdi->add_item) { keymap_item_free(kmdi->add_item); MEM_freeN(kmdi->add_item); } if (kmdi->remove_item) { keymap_item_free(kmdi->remove_item); MEM_freeN(kmdi->remove_item); } } for (wmKeyMapItem *kmi = km->items.first; kmi; kmi = kmi->next) { keymap_item_free(kmi); } BLI_freelistN(&km->diff_items); BLI_freelistN(&km->items); MEM_freeN(km); } BLI_listbase_clear(&userdef->user_keymaps); }
/* part of wm_window.c api */ wmWindow *wm_window_copy(bContext *C, wmWindow *win_src) { wmWindow *win_dst = wm_window_new(C); win_dst->posx = win_src->posx + 10; win_dst->posy = win_src->posy; win_dst->sizex = win_src->sizex; win_dst->sizey = win_src->sizey; /* duplicate assigns to window */ win_dst->screen = ED_screen_duplicate(win_dst, win_src->screen); BLI_strncpy(win_dst->screenname, win_dst->screen->id.name + 2, sizeof(win_dst->screenname)); win_dst->screen->winid = win_dst->winid; win_dst->screen->do_refresh = true; win_dst->screen->do_draw = true; win_dst->drawmethod = U.wmdrawmethod; BLI_listbase_clear(&win_dst->drawdata); *win_dst->stereo3d_format = *win_src->stereo3d_format; return win_dst; }
void BKE_list_modifier_color_ramps(FreestyleLineStyle *linestyle, ListBase *listbase) { LineStyleModifier *m; ColorBand *color_ramp; LinkData *link; BLI_listbase_clear(listbase); 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); } }
void wm_history_file_read(void) { char name[FILE_MAX]; LinkNode *l, *lines; struct RecentFile *recent; const char *line; int num; const char * const cfgdir = BKE_appdir_folder_id(BLENDER_USER_CONFIG, NULL); if (!cfgdir) return; BLI_make_file_string("/", name, cfgdir, BLENDER_HISTORY_FILE); lines = BLI_file_read_as_lines(name); BLI_listbase_clear(&G.recent_files); /* read list of recent opened files from recent-files.txt to memory */ for (l = lines, num = 0; l && (num < U.recent_files); l = l->next) { line = l->link; /* don't check if files exist, causes slow startup for remote/external drives */ if (line[0]) { recent = (RecentFile *)MEM_mallocN(sizeof(RecentFile), "RecentFile"); BLI_addtail(&(G.recent_files), recent); recent->filepath = BLI_strdup(line); num++; } } BLI_file_free_lines(lines); }
/* make a copy of a given gpencil layer */ bGPDlayer *gpencil_layer_duplicate(bGPDlayer *src) { bGPDframe *gpf, *gpfd; bGPDlayer *dst; /* error checking */ if (src == NULL) return NULL; /* make a copy of source layer */ dst = MEM_dupallocN(src); dst->prev = dst->next = NULL; /* copy frames */ BLI_listbase_clear(&dst->frames); for (gpf = src->frames.first; gpf; gpf = gpf->next) { /* make a copy of source frame */ gpfd = gpencil_frame_duplicate(gpf); BLI_addtail(&dst->frames, gpfd); /* if source frame was the current layer's 'active' frame, reassign that too */ if (gpf == dst->actframe) dst->actframe = gpfd; } /* return new layer */ return dst; }
/* Remove the given channel from all groups */ void action_groups_remove_channel(bAction *act, FCurve *fcu) { /* sanity checks */ if (ELEM(NULL, act, fcu)) return; /* check if any group used this directly */ if (fcu->grp) { bActionGroup *agrp = fcu->grp; if (agrp->channels.first == agrp->channels.last) { if (agrp->channels.first == fcu) { BLI_listbase_clear(&agrp->channels); } } else if (agrp->channels.first == fcu) { if ((fcu->next) && (fcu->next->grp == agrp)) agrp->channels.first = fcu->next; else agrp->channels.first = NULL; } else if (agrp->channels.last == fcu) { if ((fcu->prev) && (fcu->prev->grp == agrp)) agrp->channels.last = fcu->prev; else agrp->channels.last = NULL; } fcu->grp = NULL; } /* now just remove from list */ BLI_remlink(&act->curves, fcu); }
/* make a copy of a given gpencil frame */ bGPDframe *gpencil_frame_duplicate(bGPDframe *src) { bGPDstroke *gps, *gpsd; bGPDframe *dst; /* error checking */ if (src == NULL) return NULL; /* make a copy of the source frame */ dst = MEM_dupallocN(src); dst->prev = dst->next = NULL; /* copy strokes */ BLI_listbase_clear(&dst->strokes); for (gps = src->strokes.first; gps; gps = gps->next) { /* make copy of source stroke, then adjust pointer to points too */ gpsd = MEM_dupallocN(gps); gpsd->points = MEM_dupallocN(gps->points); BLI_addtail(&dst->strokes, gpsd); } /* return new frame */ return dst; }
void screen_data_copy(bScreen *to, bScreen *from) { ScrVert *s1, *s2; ScrEdge *se; ScrArea *sa, *saf; /* free contents of 'to', is from blenkernel screen.c */ BKE_screen_free(to); to->flag = from->flag; BLI_duplicatelist(&to->vertbase, &from->vertbase); BLI_duplicatelist(&to->edgebase, &from->edgebase); BLI_duplicatelist(&to->areabase, &from->areabase); BLI_listbase_clear(&to->regionbase); s2 = to->vertbase.first; for (s1 = from->vertbase.first; s1; s1 = s1->next, s2 = s2->next) { s1->newv = s2; } for (se = to->edgebase.first; se; se = se->next) { se->v1 = se->v1->newv; se->v2 = se->v2->newv; BKE_screen_sort_scrvert(&(se->v1), &(se->v2)); } saf = from->areabase.first; for (sa = to->areabase.first; sa; sa = sa->next, saf = saf->next) { sa->v1 = sa->v1->newv; sa->v2 = sa->v2->newv; sa->v3 = sa->v3->newv; sa->v4 = sa->v4->newv; BLI_listbase_clear(&sa->spacedata); BLI_listbase_clear(&sa->regionbase); BLI_listbase_clear(&sa->actionzones); BLI_listbase_clear(&sa->handlers); ED_area_data_copy(sa, saf, true); } /* put at zero (needed?) */ for (s1 = from->vertbase.first; s1; s1 = s1->next) { s1->newv = NULL; } }
void BKE_blender_user_menu_item_free_list(ListBase *lb) { for (bUserMenuItem *umi = lb->first, *umi_next; umi; umi = umi_next) { umi_next = umi->next; BKE_blender_user_menu_item_free(umi); } BLI_listbase_clear(lb); }
static void userdef_free_addons(UserDef *userdef) { for (bAddon *addon = userdef->addons.first, *addon_next; addon; addon = addon_next) { addon_next = addon->next; BKE_addon_free(addon); } BLI_listbase_clear(&userdef->addons); }
/* This function frees any MEM_calloc'ed copy/paste buffer data */ void ED_gpencil_anim_copybuf_free(void) { free_gpencil_layers(&gp_anim_copybuf); BLI_listbase_clear(&gp_anim_copybuf); gp_anim_copy_firstframe = 999999999; gp_anim_copy_lastframe = -999999999; gp_anim_copy_cfra = 0; }
static void node_group_output_update(bNodeTree *ntree, bNode *node) { bNodeSocket *extsock = node->inputs.last; bNodeLink *link, *linknext, *exposelink; /* Adding a tree socket and verifying will remove the extension socket! * This list caches the existing links to the extension socket * so they can be recreated after verification. */ ListBase tmplinks; /* find links to the extension socket and store them */ BLI_listbase_clear(&tmplinks); for (link = ntree->links.first; link; link = linknext) { linknext = link->next; if (nodeLinkIsHidden(link)) continue; if (link->tosock == extsock) { bNodeLink *tlink = MEM_callocN(sizeof(bNodeLink), "temporary link"); *tlink = *link; BLI_addtail(&tmplinks, tlink); nodeRemLink(ntree, link); } } /* find valid link to expose */ exposelink = NULL; for (link = tmplinks.first; link; link = link->next) { /* XXX Multiple sockets can be connected to the extension socket at once, * in that case the arbitrary first link determines name and type. * This could be improved by choosing the "best" type among all links, * whatever that means. */ if (link->fromsock->type != SOCK_CUSTOM) { exposelink = link; break; } } if (exposelink) { bNodeSocket *gsock, *newsock; /* XXX what if connecting virtual to virtual socket?? */ gsock = ntreeAddSocketInterfaceFromSocket(ntree, exposelink->fromnode, exposelink->fromsock); node_group_output_verify(ntree, node, (ID *)ntree); newsock = node_group_output_find_socket(node, gsock->identifier); /* redirect links to the extension socket */ for (link = tmplinks.first; link; link = link->next) { nodeAddLink(ntree, link->fromnode, link->fromsock, node, newsock); } } BLI_freelistN(&tmplinks); }
VChar *BLI_vfontchar_copy(const VChar *vchar_src, const int UNUSED(flag)) { VChar *vchar_dst = MEM_dupallocN(vchar_src); BLI_listbase_clear(&vchar_dst->nurbsbase); BKE_nurbList_duplicate(&vchar_dst->nurbsbase, &vchar_src->nurbsbase); return vchar_dst; }
/* Paste the variables in the buffer to the given FCurve */ bool ANIM_driver_vars_paste(ReportList *reports, FCurve *fcu, bool replace) { ChannelDriver *driver = (fcu) ? fcu->driver : NULL; ListBase tmp_list = {NULL, NULL}; /* sanity checks */ if (BLI_listbase_is_empty(&driver_vars_copybuf)) { BKE_report(reports, RPT_ERROR, "No driver variables in clipboard to paste"); return false; } if (ELEM(NULL, fcu, fcu->driver)) { BKE_report(reports, RPT_ERROR, "Cannot paste driver variables without a driver"); return false; } /* 1) Make a new copy of the variables in the buffer - these will get pasted later... */ driver_variables_copy(&tmp_list, &driver_vars_copybuf); /* 2) Prepare destination array */ if (replace) { DriverVar *dvar, *dvarn; /* Free all existing vars first - We aren't retaining anything */ for (dvar = driver->variables.first; dvar; dvar = dvarn) { dvarn = dvar->next; driver_free_variable_ex(driver, dvar); } BLI_listbase_clear(&driver->variables); } /* 3) Add new vars */ if (driver->variables.last) { DriverVar *last = driver->variables.last; DriverVar *first = tmp_list.first; last->next = first; first->prev = last; driver->variables.last = tmp_list.last; } else { driver->variables.first = tmp_list.first; driver->variables.last = tmp_list.last; } #ifdef WITH_PYTHON /* since driver variables are cached, the expression needs re-compiling too */ if (driver->type == DRIVER_TYPE_PYTHON) driver->flag |= DRIVER_FLAG_RENAMEVAR; #endif return true; }
static void envmap_free_render_copy(Render *envre) { envre->totvlak = 0; envre->totvert = 0; envre->tothalo = 0; envre->totstrand = 0; envre->totlamp = 0; envre->totinstance = 0; envre->sortedhalos = NULL; BLI_listbase_clear(&envre->lights); BLI_listbase_clear(&envre->objecttable); BLI_listbase_clear(&envre->customdata_names); envre->raytree = NULL; BLI_listbase_clear(&envre->instancetable); envre->objectinstance = NULL; envre->qmcsamplers = NULL; RE_FreeRender(envre); }
void defgroup_copy_list(ListBase *outbase, ListBase *inbase) { bDeformGroup *defgroup, *defgroupn; BLI_listbase_clear(outbase); for (defgroup = inbase->first; defgroup; defgroup = defgroup->next) { defgroupn = defgroup_duplicate(defgroup); BLI_addtail(outbase, defgroupn); } }
void BKE_sequence_modifier_clear(Sequence *seq) { SequenceModifierData *smd, *smd_next; for (smd = seq->modifiers.first; smd; smd = smd_next) { smd_next = smd->next; BKE_sequence_modifier_free(smd); } BLI_listbase_clear(&seq->modifiers); }