コード例 #1
0
ファイル: editmesh_bevel.c プロジェクト: dfelinto/blender
static void edbm_bevel_exit(bContext *C, wmOperator *op)
{
  BevelData *opdata = op->customdata;

  ScrArea *sa = CTX_wm_area(C);

  if (sa) {
    ED_area_status_text(sa, NULL);
  }

  if (opdata->is_modal) {
    View3D *v3d = CTX_wm_view3d(C);
    ARegion *ar = CTX_wm_region(C);
    for (uint ob_index = 0; ob_index < opdata->ob_store_len; ob_index++) {
      EDBM_redo_state_free(&opdata->ob_store[ob_index].mesh_backup, NULL, false);
    }
    ED_region_draw_cb_exit(ar->type, opdata->draw_handle_pixel);
    if (v3d) {
      v3d->gizmo_flag = opdata->gizmo_flag;
    }
    G.moving = 0;
  }
  MEM_SAFE_FREE(opdata->ob_store);
  MEM_SAFE_FREE(op->customdata);
  op->customdata = NULL;
}
コード例 #2
0
static void freeBind(CorrectiveSmoothModifierData *csmd)
{
	MEM_SAFE_FREE(csmd->bind_coords);
	MEM_SAFE_FREE(csmd->delta_cache);

	csmd->bind_coords_num = 0;
}
コード例 #3
0
ファイル: lattice.c プロジェクト: dfelinto/blender
/** Free (or release) any data used by this lattice (does not free the lattice itself). */
void BKE_lattice_free(Lattice *lt)
{
  BKE_animdata_free(&lt->id, false);

  BKE_lattice_batch_cache_free(lt);

  MEM_SAFE_FREE(lt->def);
  if (lt->dvert) {
    BKE_defvert_array_free(lt->dvert, lt->pntsu * lt->pntsv * lt->pntsw);
    lt->dvert = NULL;
  }
  if (lt->editlatt) {
    Lattice *editlt = lt->editlatt->latt;

    if (editlt->def) {
      MEM_freeN(editlt->def);
    }
    if (editlt->dvert) {
      BKE_defvert_array_free(editlt->dvert, lt->pntsu * lt->pntsv * lt->pntsw);
    }

    MEM_freeN(editlt);
    MEM_freeN(lt->editlatt);
    lt->editlatt = NULL;
  }
}
コード例 #4
0
ファイル: linestyle.c プロジェクト: rav66/blender
/** Free (or release) any data used by this linestyle (does not free the linestyle itself). */
void BKE_linestyle_free(FreestyleLineStyle *linestyle)
{
	LineStyleModifier *m;
	int a;

	BKE_animdata_free(&linestyle->id, false);

	for (a = 0; a < MAX_MTEX; a++) {
		MEM_SAFE_FREE(linestyle->mtex[a]);
	}

	/* is no lib link block, but linestyle extension */
	if (linestyle->nodetree) {
		ntreeFreeTree(linestyle->nodetree);
		MEM_freeN(linestyle->nodetree);
		linestyle->nodetree = NULL;
	}

	while ((m = (LineStyleModifier *)linestyle->color_modifiers.first))
		BKE_linestyle_color_modifier_remove(linestyle, m);
	while ((m = (LineStyleModifier *)linestyle->alpha_modifiers.first))
		BKE_linestyle_alpha_modifier_remove(linestyle, m);
	while ((m = (LineStyleModifier *)linestyle->thickness_modifiers.first))
		BKE_linestyle_thickness_modifier_remove(linestyle, m);
	while ((m = (LineStyleModifier *)linestyle->geometry_modifiers.first))
		BKE_linestyle_geometry_modifier_remove(linestyle, m);
}
コード例 #5
0
static void gizmo_preselect_elem_free(wmGizmo *gz)
{
  MeshElemGizmo3D *gz_ele = (MeshElemGizmo3D *)gz;
  EDBM_preselect_elem_destroy(gz_ele->psel);
  gz_ele->psel = NULL;
  MEM_SAFE_FREE(gz_ele->bases);
}
コード例 #6
0
ファイル: layer.c プロジェクト: dfelinto/blender
void BKE_main_collection_sync_remap(const Main *bmain)
{
  /* On remapping of object or collection pointers free caches. */
  /* TODO: try to make this faster */

  for (const Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
    for (ViewLayer *view_layer = scene->view_layers.first; view_layer;
         view_layer = view_layer->next) {
      MEM_SAFE_FREE(view_layer->object_bases_array);

      if (view_layer->object_bases_hash) {
        BLI_ghash_free(view_layer->object_bases_hash, NULL, NULL);
        view_layer->object_bases_hash = NULL;
      }
    }
  }

  for (Collection *collection = bmain->collections.first; collection;
       collection = collection->id.next) {
    BKE_collection_object_cache_free(collection);
    DEG_id_tag_update_ex((Main *)bmain, &collection->id, ID_RECALC_COPY_ON_WRITE);
  }

  BKE_main_collection_sync(bmain);
}
コード例 #7
0
ファイル: texture.c プロジェクト: mgschwan/blensor
/** Free (or release) any data used by this texture (does not free the texure itself). */
void BKE_texture_free(Tex *tex)
{
	BKE_animdata_free((ID *)tex, false);

	/* is no lib link block, but texture extension */
	if (tex->nodetree) {
		ntreeFreeTree(tex->nodetree);
		MEM_freeN(tex->nodetree);
		tex->nodetree = NULL;
	}

	MEM_SAFE_FREE(tex->coba);
	if (tex->env) {
		BKE_texture_envmap_free(tex->env);
		tex->env = NULL;
	}
	if (tex->pd) {
		BKE_texture_pointdensity_free(tex->pd);
		tex->pd = NULL;
	}
	if (tex->vd) {
		BKE_texture_voxeldata_free(tex->vd);
		tex->vd = NULL;
	}
	if (tex->ot) {
		BKE_texture_ocean_free(tex->ot);
		tex->ot = NULL;
	}
	
	BKE_icon_id_delete((ID *)tex);
	BKE_previewimg_free(&tex->preview);
}
コード例 #8
0
ファイル: eevee_lightcache.c プロジェクト: wangyxuan/blender
void EEVEE_lightbake_job_data_free(void *custom_data)
{
  EEVEE_LightBake *lbake = (EEVEE_LightBake *)custom_data;

  /* TODO reuse depsgraph. */
  /* if (lbake->own_resources) { */
  DEG_graph_free(lbake->depsgraph);
  /* } */

  MEM_SAFE_FREE(lbake->cube_prb);
  MEM_SAFE_FREE(lbake->grid_prb);

  BLI_mutex_free(lbake->mutex);

  MEM_freeN(lbake);
}
コード例 #9
0
void ED_buttons_id_unref(SpaceButs *sbuts, const ID *id)
{
	if (sbuts->pinid == id) {
		sbuts->pinid = NULL;
		sbuts->flag &= ~SB_PIN_CONTEXT;
	}

	if (sbuts->path) {
		ButsContextPath *path = sbuts->path;
		int i;

		for (i = 0; i < path->len; i++) {
			if (path->ptr[i].id.data == id) {
				break;
			}
		}

		if (i == path->len) {
			/* pass */
		}
		else if (i == 0) {
			MEM_SAFE_FREE(sbuts->path);
		}
		else {
			memset(&path->ptr[i], 0, sizeof(path->ptr[i]) * (path->len - i));
			path->len = i;
		}
	}
}
コード例 #10
0
ファイル: eevee_lightcache.c プロジェクト: wangyxuan/blender
static void eevee_lightbake_readback_irradiance(LightCache *lcache)
{
  MEM_SAFE_FREE(lcache->grid_tx.data);
  lcache->grid_tx.data = GPU_texture_read(lcache->grid_tx.tex, GPU_DATA_UNSIGNED_BYTE, 0);
  lcache->grid_tx.data_type = LIGHTCACHETEX_BYTE;
  lcache->grid_tx.components = 4;
}
コード例 #11
0
static void gizmo_preselect_edgering_free(wmGizmo *gz)
{
  MeshEdgeRingGizmo3D *gz_ring = (MeshEdgeRingGizmo3D *)gz;
  EDBM_preselect_edgering_destroy(gz_ring->psel);
  gz_ring->psel = NULL;
  MEM_SAFE_FREE(gz_ring->bases);
}
コード例 #12
0
static void rna_FCurve_convert_to_keyframes(FCurve *fcu, ReportList *reports, int start, int end)
{
	if (start >= end) {
		BKE_reportf(reports, RPT_ERROR, "Invalid frame range (%d - %d)", start, end);
	}
	else if (fcu->bezt) {
		BKE_report(reports, RPT_WARNING, "FCurve has already keyframes");
	}
	else if (!fcu->fpt) {
		BKE_report(reports, RPT_WARNING, "FCurve has no sample points");
	}
	else {
		BezTriple *bezt;
		FPoint *fpt = fcu->fpt;
		int tot_kf = end - start;
		int tot_sp = fcu->totvert;

		bezt = fcu->bezt = MEM_callocN(sizeof(*fcu->bezt) * (size_t)tot_kf, __func__);
		fcu->totvert = tot_kf;

		/* Get first sample point to 'copy' as keyframe. */
		for (; tot_sp && (fpt->vec[0] < (float)start); fpt++, tot_sp--);

		/* Add heading dummy flat points if needed. */
		for (; tot_kf && (fpt->vec[0] > (float)start); start++, bezt++, tot_kf--) {
			/* Linear interpolation, of course. */
			bezt->f1 = bezt->f2 = bezt->f3 = SELECT;
			bezt->ipo = BEZT_IPO_LIN;
			bezt->h1 = bezt->h2 = HD_AUTO_ANIM;
			bezt->vec[1][0] = (float)start;
			bezt->vec[1][1] = fpt->vec[1];
		}

		/* Copy actual sample points. */
		for (; tot_kf && tot_sp; start++, bezt++, tot_kf--, fpt++, tot_sp--) {
			/* Linear interpolation, of course. */
			bezt->f1 = bezt->f2 = bezt->f3 = SELECT;
			bezt->ipo = BEZT_IPO_LIN;
			bezt->h1 = bezt->h2 = HD_AUTO_ANIM;
			copy_v2_v2(bezt->vec[1], fpt->vec);
		}

		/* Add leading dummy flat points if needed. */
		for (fpt--; tot_kf; start++, bezt++, tot_kf--) {
			/* Linear interpolation, of course. */
			bezt->f1 = bezt->f2 = bezt->f3 = SELECT;
			bezt->ipo = BEZT_IPO_LIN;
			bezt->h1 = bezt->h2 = HD_AUTO_ANIM;
			bezt->vec[1][0] = (float)start;
			bezt->vec[1][1] = fpt->vec[1];
		}

		MEM_SAFE_FREE(fcu->fpt);

		/* Not strictly needed since we use linear interpolation, but better be consistent here. */
		calchandles_fcurve(fcu);
		WM_main_add_notifier(NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL);
	}
}
コード例 #13
0
ファイル: layer.c プロジェクト: dfelinto/blender
/**
 * Update view layer collection tree from collections used in the scene.
 * This is used when collections are removed or added, both while editing
 * and on file loaded in case linked data changed or went missing.
 */
void BKE_layer_collection_sync(const Scene *scene, ViewLayer *view_layer)
{
  if (!scene->master_collection) {
    /* Happens for old files that don't have versioning applied yet. */
    return;
  }

  /* Free cache. */
  MEM_SAFE_FREE(view_layer->object_bases_array);

  /* Create object to base hash if it does not exist yet. */
  if (!view_layer->object_bases_hash) {
    view_layer_bases_hash_create(view_layer);
  }

  /* Clear visible and selectable flags to be reset. */
  for (Base *base = view_layer->object_bases.first; base; base = base->next) {
    base->flag &= ~g_base_collection_flags;
    base->flag_from_collection &= ~g_base_collection_flags;
  }

  /* Generate new layer connections and object bases when collections changed. */
  CollectionChild child = {NULL, NULL, scene->master_collection};
  const ListBase collections = {&child, &child};
  ListBase new_object_bases = {NULL, NULL};

  const short parent_exclude = 0, parent_restrict = 0, parent_layer_restrict = 0;
  layer_collection_sync(view_layer,
                        &collections,
                        &view_layer->layer_collections,
                        &new_object_bases,
                        parent_exclude,
                        parent_restrict,
                        parent_layer_restrict);

  /* Any remaning object bases are to be removed. */
  for (Base *base = view_layer->object_bases.first; base; base = base->next) {
    if (view_layer->basact == base) {
      view_layer->basact = NULL;
    }

    if (base->object) {
      BLI_ghash_remove(view_layer->object_bases_hash, base->object, NULL, NULL);
    }
  }

  BLI_freelistN(&view_layer->object_bases);
  view_layer->object_bases = new_object_bases;

  /* Always set a valid active collection. */
  LayerCollection *active = view_layer->active_collection;

  if (active && (active->flag & LAYER_COLLECTION_EXCLUDE)) {
    BKE_layer_collection_activate_parent(view_layer, active);
  }
  else if (active == NULL) {
    view_layer->active_collection = view_layer->layer_collections.first;
  }
}
コード例 #14
0
ファイル: eevee_lightcache.c プロジェクト: wangyxuan/blender
static void eevee_lightbake_readback_reflections(LightCache *lcache)
{
  MEM_SAFE_FREE(lcache->cube_tx.data);
  lcache->cube_tx.data = GPU_texture_read(lcache->cube_tx.tex, GPU_DATA_10_11_11_REV, 0);
  lcache->cube_tx.data_type = LIGHTCACHETEX_UINT;
  lcache->cube_tx.components = 1;

  for (int mip = 0; mip < lcache->mips_len; ++mip) {
    LightCacheTexture *cube_mip = lcache->cube_mips + mip;
    MEM_SAFE_FREE(cube_mip->data);
    GPU_texture_get_mipmap_size(lcache->cube_tx.tex, mip + 1, cube_mip->tex_size);

    cube_mip->data = GPU_texture_read(lcache->cube_tx.tex, GPU_DATA_10_11_11_REV, mip + 1);
    cube_mip->data_type = LIGHTCACHETEX_UINT;
    cube_mip->components = 1;
  }
}
コード例 #15
0
/* clear cache */
static void gpencil_batch_cache_clear(GpencilBatchCache *cache)
{
  if (!cache) {
    return;
  }

  GPU_BATCH_DISCARD_SAFE(cache->b_stroke.batch);
  GPU_BATCH_DISCARD_SAFE(cache->b_point.batch);
  GPU_BATCH_DISCARD_SAFE(cache->b_fill.batch);
  GPU_BATCH_DISCARD_SAFE(cache->b_edit.batch);
  GPU_BATCH_DISCARD_SAFE(cache->b_edlin.batch);

  MEM_SAFE_FREE(cache->b_stroke.batch);
  MEM_SAFE_FREE(cache->b_point.batch);
  MEM_SAFE_FREE(cache->b_fill.batch);
  MEM_SAFE_FREE(cache->b_edit.batch);
  MEM_SAFE_FREE(cache->b_edlin.batch);

  MEM_SAFE_FREE(cache->grp_cache);
  cache->grp_size = 0;
  cache->grp_used = 0;

  /* clear all frames derived data */
  for (int i = 0; i < cache->tot_layers; i++) {
    bGPDframe *derived_gpf = &cache->derived_array[i];
    BKE_gpencil_free_frame_runtime_data(derived_gpf);
    derived_gpf = NULL;
  }
  cache->tot_layers = 0;
  MEM_SAFE_FREE(cache->derived_array);
}
コード例 #16
0
ファイル: brush.c プロジェクト: wangyxuan/blender
/** Free (or release) any data used by this brush (does not free the brush itself). */
void BKE_brush_free(Brush *brush)
{
  if (brush->icon_imbuf) {
    IMB_freeImBuf(brush->icon_imbuf);
  }
  curvemapping_free(brush->curve);

  if (brush->gpencil_settings != NULL) {
    curvemapping_free(brush->gpencil_settings->curve_sensitivity);
    curvemapping_free(brush->gpencil_settings->curve_strength);
    curvemapping_free(brush->gpencil_settings->curve_jitter);
    MEM_SAFE_FREE(brush->gpencil_settings);
  }

  MEM_SAFE_FREE(brush->gradient);

  BKE_previewimg_free(&(brush->preview));
}
コード例 #17
0
static void freeData(ModifierData *md)
{
	SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *)md;

	if (smd->verts) {
		for (int i = 0; i < smd->numverts; i++) {
			if (smd->verts[i].binds) {
				for (int j = 0; j < smd->verts[i].numbinds; j++) {
					MEM_SAFE_FREE(smd->verts[i].binds[j].vert_inds);
					MEM_SAFE_FREE(smd->verts[i].binds[j].vert_weights);
				}

				MEM_SAFE_FREE(smd->verts[i].binds);
			}
		}

		MEM_SAFE_FREE(smd->verts);
	}
}
コード例 #18
0
static void freeData(ModifierData *md)
{
	LaplacianDeformModifierData *lmd = (LaplacianDeformModifierData *)md;
	LaplacianSystem *sys = (LaplacianSystem *)lmd->cache_system;
	if (sys) {
		deleteLaplacianSystem(sys);
	}
	MEM_SAFE_FREE(lmd->vertexco);
	lmd->total_verts = 0;
}
コード例 #19
0
/* wrapper to clear cache */
void DRW_gpencil_freecache(struct Object *ob)
{
  if ((ob) && (ob->type == OB_GPENCIL)) {
    gpencil_batch_cache_clear(ob->runtime.gpencil_cache);
    MEM_SAFE_FREE(ob->runtime.gpencil_cache);
    bGPdata *gpd = (bGPdata *)ob->data;
    if (gpd) {
      gpd->flag |= GP_DATA_CACHE_IS_DIRTY;
    }
  }
}
コード例 #20
0
ファイル: icons.c プロジェクト: khanhha/blender
void BKE_previewimg_clear_single(struct PreviewImage *prv, enum eIconSizes size)
{
	MEM_SAFE_FREE(prv->rect[size]);
	if (prv->gputexture[size]) {
		GPU_texture_free(prv->gputexture[size]);
	}
	prv->h[size] = prv->w[size] = 0;
	prv->flag[size] |= PRV_CHANGED;
	prv->flag[size] &= ~PRV_USER_EDITED;
	prv->changed_timestamp[size] = 0;
}
コード例 #21
0
ファイル: brush.c プロジェクト: UPBGE/blender
/** Free (or release) any data used by this brush (does not free the brush itself). */
void BKE_brush_free(Brush *brush)
{
	if (brush->icon_imbuf) {
		IMB_freeImBuf(brush->icon_imbuf);
	}

	curvemapping_free(brush->curve);

	MEM_SAFE_FREE(brush->gradient);

	BKE_previewimg_free(&(brush->preview));
}
コード例 #22
0
ファイル: bpy_app_translations.c プロジェクト: diekev/blender
static PyObject *app_translations_locale_explode(BlenderAppTranslations *UNUSED(self), PyObject *args, PyObject *kw)
{
	PyObject *ret_tuple;
	static const char *kwlist[] = {"locale", NULL};
	const char *locale;
	char *language, *country, *variant, *language_country, *language_variant;

	if (!PyArg_ParseTupleAndKeywords(args, kw, "s:bpy.app.translations.locale_explode", (char **)kwlist, &locale)) {
		return NULL;
	}

	BLT_lang_locale_explode(locale, &language, &country, &variant, &language_country, &language_variant);

	ret_tuple = Py_BuildValue("sssss", language, country, variant, language_country, language_variant);

	MEM_SAFE_FREE(language);
	MEM_SAFE_FREE(country);
	MEM_SAFE_FREE(variant);
	MEM_SAFE_FREE(language_country);
	MEM_SAFE_FREE(language_variant);

	return ret_tuple;
}
コード例 #23
0
ファイル: layer.c プロジェクト: dfelinto/blender
/**
 * Free (or release) any data used by this ViewLayer.
 */
void BKE_view_layer_free_ex(ViewLayer *view_layer, const bool do_id_user)
{
  view_layer->basact = NULL;

  BLI_freelistN(&view_layer->object_bases);

  if (view_layer->object_bases_hash) {
    BLI_ghash_free(view_layer->object_bases_hash, NULL, NULL);
  }

  for (LayerCollection *lc = view_layer->layer_collections.first; lc; lc = lc->next) {
    layer_collection_free(view_layer, lc);
  }
  BLI_freelistN(&view_layer->layer_collections);

  for (ViewLayerEngineData *sled = view_layer->drawdata.first; sled; sled = sled->next) {
    if (sled->storage) {
      if (sled->free) {
        sled->free(sled->storage);
      }
      MEM_freeN(sled->storage);
    }
  }
  BLI_freelistN(&view_layer->drawdata);

  MEM_SAFE_FREE(view_layer->stats);

  BKE_freestyle_config_free(&view_layer->freestyle_config, do_id_user);

  if (view_layer->id_properties) {
    IDP_FreeProperty(view_layer->id_properties);
  }

  MEM_SAFE_FREE(view_layer->object_bases_array);

  MEM_freeN(view_layer);
}
コード例 #24
0
void render_result_rect_from_ibuf(RenderResult *rr, RenderData *UNUSED(rd), ImBuf *ibuf, const int view_id)
{
	RenderView *rv = RE_RenderViewGetById(rr, view_id);

	if (ibuf->rect_float) {
		if (!rv->rectf)
			rv->rectf = MEM_mallocN(4 * sizeof(float) * rr->rectx * rr->recty, "render_seq rectf");
		
		memcpy(rv->rectf, ibuf->rect_float, 4 * sizeof(float) * rr->rectx * rr->recty);

		/* TSK! Since sequence render doesn't free the *rr render result, the old rect32
		 * can hang around when sequence render has rendered a 32 bits one before */
		MEM_SAFE_FREE(rv->rect32);
	}
	else if (ibuf->rect) {
		if (!rv->rect32)
			rv->rect32 = MEM_mallocN(sizeof(int) * rr->rectx * rr->recty, "render_seq rect");

		memcpy(rv->rect32, ibuf->rect, 4 * rr->rectx * rr->recty);

		/* Same things as above, old rectf can hang around from previous render. */
		MEM_SAFE_FREE(rv->rectf);
	}
}
コード例 #25
0
ファイル: layer.c プロジェクト: dfelinto/blender
static void layer_eval_view_layer(struct Depsgraph *depsgraph,
                                  struct Scene *UNUSED(scene),
                                  ViewLayer *view_layer)
{
  DEG_debug_print_eval(depsgraph, __func__, view_layer->name, view_layer);

  /* Create array of bases, for fast index-based lookup. */
  const int num_object_bases = BLI_listbase_count(&view_layer->object_bases);
  MEM_SAFE_FREE(view_layer->object_bases_array);
  view_layer->object_bases_array = MEM_malloc_arrayN(
      num_object_bases, sizeof(Base *), "view_layer->object_bases_array");
  int base_index = 0;
  for (Base *base = view_layer->object_bases.first; base; base = base->next) {
    view_layer->object_bases_array[base_index++] = base;
  }
}
コード例 #26
0
ファイル: filelist.c プロジェクト: bitfusionio/blender
void filelist_free(struct FileList *filelist)
{
	if (!filelist) {
		printf("Attempting to delete empty filelist.\n");
		return;
	}
	
	MEM_SAFE_FREE(filelist->fidx);
	filelist->numfiltered = 0;
	memset(&filelist->filter_data, 0, sizeof(filelist->filter_data));

	filelist->need_sorting = false;
	filelist->sort = FILE_SORT_NONE;

	BLI_filelist_free(filelist->filelist, filelist->numfiles, NULL);
	filelist->numfiles = 0;
	filelist->filelist = NULL;
}
コード例 #27
0
/**
 * This calculates #CorrectiveSmoothModifierData.delta_cache
 * It's not run on every update (during animation for example).
 */
static void calc_deltas(CorrectiveSmoothModifierData *csmd,
                        Mesh *mesh,
                        MDeformVert *dvert,
                        const int defgrp_index,
                        const float (*rest_coords)[3],
                        unsigned int numVerts)
{
  float(*smooth_vertex_coords)[3] = MEM_dupallocN(rest_coords);
  float(*tangent_spaces)[3][3];
  unsigned int i;

  tangent_spaces = MEM_calloc_arrayN(numVerts, sizeof(float[3][3]), __func__);

  if (csmd->delta_cache_num != numVerts) {
    MEM_SAFE_FREE(csmd->delta_cache);
  }

  /* allocate deltas if they have not yet been allocated, otheriwse we will just write over them */
  if (!csmd->delta_cache) {
    csmd->delta_cache_num = numVerts;
    csmd->delta_cache = MEM_malloc_arrayN(numVerts, sizeof(float[3]), __func__);
  }

  smooth_verts(csmd, mesh, dvert, defgrp_index, smooth_vertex_coords, numVerts);

  calc_tangent_spaces(mesh, smooth_vertex_coords, tangent_spaces);

  for (i = 0; i < numVerts; i++) {
    float imat[3][3], delta[3];

#ifdef USE_TANGENT_CALC_INLINE
    calc_tangent_ortho(tangent_spaces[i]);
#endif

    sub_v3_v3v3(delta, rest_coords[i], smooth_vertex_coords[i]);
    if (UNLIKELY(!invert_m3_m3(imat, tangent_spaces[i]))) {
      transpose_m3_m3(imat, tangent_spaces[i]);
    }
    mul_v3_m3v3(csmd->delta_cache[i], imat, delta);
  }

  MEM_freeN(tangent_spaces);
  MEM_freeN(smooth_vertex_coords);
}
コード例 #28
0
static void delete_laplacian_system(LaplacianSystem *sys)
{
	MEM_SAFE_FREE(sys->eweights);
	MEM_SAFE_FREE(sys->fweights);
	MEM_SAFE_FREE(sys->numNeEd);
	MEM_SAFE_FREE(sys->numNeFa);
	MEM_SAFE_FREE(sys->ring_areas);
	MEM_SAFE_FREE(sys->vlengths);
	MEM_SAFE_FREE(sys->vweights);
	MEM_SAFE_FREE(sys->zerola);

	if (sys->context) {
		EIG_linear_solver_delete(sys->context);
	}
	sys->vertexCos = NULL;
	sys->mpoly = NULL;
	sys->mloop = NULL;
	sys->medges = NULL;
	MEM_freeN(sys);
}
コード例 #29
0
ファイル: MOD_normal_edit.c プロジェクト: mgschwan/blensor
/* Note this modifies nos_new in-place. */
static void mix_normals(
        const float mix_factor, MDeformVert *dvert, const int defgrp_index, const bool use_invert_vgroup,
        const float mix_limit, const short mix_mode,
        const int num_verts, MLoop *mloop, float (*nos_old)[3], float (*nos_new)[3], const int num_loops)
{
	/* Mix with org normals... */
	float *facs = NULL, *wfac;
	float (*no_new)[3], (*no_old)[3];
	int i;

	if (dvert) {
		facs = MEM_malloc_arrayN((size_t)num_loops, sizeof(*facs), __func__);
		BKE_defvert_extract_vgroup_to_loopweights(
		            dvert, defgrp_index, num_verts, mloop, num_loops, facs, use_invert_vgroup);
	}

	for (i = num_loops, no_new = nos_new, no_old = nos_old, wfac = facs; i--; no_new++, no_old++, wfac++) {
		const float fac = facs ? *wfac * mix_factor : mix_factor;

		switch (mix_mode) {
			case MOD_NORMALEDIT_MIX_ADD:
				add_v3_v3(*no_new, *no_old);
				normalize_v3(*no_new);
				break;
			case MOD_NORMALEDIT_MIX_SUB:
				sub_v3_v3(*no_new, *no_old);
				normalize_v3(*no_new);
				break;
			case MOD_NORMALEDIT_MIX_MUL:
				mul_v3_v3(*no_new, *no_old);
				normalize_v3(*no_new);
				break;
			case MOD_NORMALEDIT_MIX_COPY:
				break;
		}

		interp_v3_v3v3_slerp_safe(
		        *no_new, *no_old, *no_new,
		        (mix_limit < (float)M_PI) ? min_ff(fac, mix_limit / angle_v3v3(*no_new, *no_old)) : fac);
	}

	MEM_SAFE_FREE(facs);
}
コード例 #30
0
/**
 * Clear and reset \a gh buckets, reserve again buckets for given number of entries.
 */
BLI_INLINE void ghash_buckets_reset(GHash *gh, const unsigned int nentries)
{
	MEM_SAFE_FREE(gh->buckets);

#ifdef GHASH_USE_MODULO_BUCKETS
	gh->cursize = 0;
	gh->size_min = 0;
	gh->nbuckets = hashsizes[gh->cursize];
#else
	gh->bucket_bit = GHASH_BUCKET_BIT_MIN;
	gh->bucket_bit_min = GHASH_BUCKET_BIT_MIN;
	gh->nbuckets = 1u << gh->bucket_bit;
	gh->bucket_mask = gh->nbuckets - 1;
#endif

	gh->limit_grow   = GHASH_LIMIT_GROW(gh->nbuckets);
	gh->limit_shrink = GHASH_LIMIT_SHRINK(gh->nbuckets);

	gh->nentries = 0;

	ghash_buckets_expand(gh, nentries, (nentries != 0));
}