/* frees all */ void cloth_free_modifier(ClothModifierData *clmd ) { Cloth *cloth = NULL; if ( !clmd ) return; cloth = clmd->clothObject; if ( cloth ) { BPH_cloth_solver_free(clmd); // Free the verts. if ( cloth->verts != NULL ) MEM_freeN ( cloth->verts ); cloth->verts = NULL; cloth->mvert_num = 0; // Free the springs. if ( cloth->springs != NULL ) { LinkNode *search = cloth->springs; while (search) { ClothSpring *spring = search->link; MEM_freeN ( spring ); search = search->next; } BLI_linklist_free(cloth->springs, NULL); cloth->springs = NULL; } cloth->springs = NULL; cloth->numsprings = 0; // free BVH collision tree if ( cloth->bvhtree ) BLI_bvhtree_free ( cloth->bvhtree ); if ( cloth->bvhselftree ) BLI_bvhtree_free ( cloth->bvhselftree ); // we save our faces for collision objects if (cloth->tri) MEM_freeN(cloth->tri); if (cloth->edgeset) BLI_edgeset_free(cloth->edgeset); /* if (clmd->clothObject->facemarks) MEM_freeN(clmd->clothObject->facemarks); */ MEM_freeN ( cloth ); clmd->clothObject = NULL; } }
/* Frees data allocated by a call to bvhtree_from_mesh_*. */ void free_bvhtree_from_mesh(struct BVHTreeFromMesh *data) { if (data->tree) { if (!data->cached) { BLI_bvhtree_free(data->tree); } if (data->vert_allocated) { MEM_freeN((void *)data->vert); } if (data->edge_allocated) { MEM_freeN((void *)data->edge); } if (data->face_allocated) { MEM_freeN((void *)data->face); } if (data->loop_allocated) { MEM_freeN((void *)data->loop); } if (data->looptri_allocated) { MEM_freeN((void *)data->looptri); } memset(data, 0, sizeof(*data)); } }
static void cache_pointdensity(Render *re, Tex *tex) { PointDensity *pd = tex->pd; if(!pd) return; if (pd->point_tree) { BLI_bvhtree_free(pd->point_tree); pd->point_tree = NULL; } if (pd->source == TEX_PD_PSYS) { Object *ob = pd->object; ParticleSystem *psys; if (!ob || !pd->psys) return; psys= BLI_findlink(&ob->particlesystem, pd->psys-1); if (!psys) return; pointdensity_cache_psys(re, pd, ob, psys); } else if (pd->source == TEX_PD_OBJECT) { Object *ob = pd->object; if (ob && ob->type == OB_MESH) pointdensity_cache_object(re, pd, ob); } }
static void freeData(ModifierData *md) { CollisionModifierData *collmd = (CollisionModifierData *) md; if (collmd) { if (collmd->bvhtree) BLI_bvhtree_free(collmd->bvhtree); if (collmd->x) MEM_freeN(collmd->x); if (collmd->xnew) MEM_freeN(collmd->xnew); if (collmd->current_x) MEM_freeN(collmd->current_x); if (collmd->current_xnew) MEM_freeN(collmd->current_xnew); if (collmd->current_v) MEM_freeN(collmd->current_v); if (collmd->mfaces) MEM_freeN(collmd->mfaces); collmd->x = NULL; collmd->xnew = NULL; collmd->current_x = NULL; collmd->current_xnew = NULL; collmd->current_v = NULL; collmd->time_x = collmd->time_xnew = -1000; collmd->numverts = 0; collmd->bvhtree = NULL; collmd->mfaces = NULL; } }
static void bvhcacheitem_free(void *_item) { BVHCacheItem *item = (BVHCacheItem *)_item; BLI_bvhtree_free(item->tree); MEM_freeN(item); }
/* Frees data allocated by a call to bvhtree_from_mesh_*. */ void free_bvhtree_from_mesh(struct BVHTreeFromMesh *data) { if (data->tree) { if (!data->cached) BLI_bvhtree_free(data->tree); memset(data, 0, sizeof(*data)); } }
void smokeModifier_reset(struct SmokeModifierData *smd) { if(smd) { if(smd->domain) { if(smd->domain->shadow) MEM_freeN(smd->domain->shadow); smd->domain->shadow = NULL; if(smd->domain->fluid) { smoke_free(smd->domain->fluid); smd->domain->fluid = NULL; } smd->domain->point_cache[0]->flag |= PTCACHE_OUTDATED; smd->domain->point_cache[1]->flag |= PTCACHE_OUTDATED; smokeModifier_reset_turbulence(smd); smd->time = -1; // printf("reset domain end\n"); } else if(smd->flow) { /* if(smd->flow->bvh) { free_bvhtree_from_mesh(smd->flow->bvh); MEM_freeN(smd->flow->bvh); } smd->flow->bvh = NULL; */ } else if(smd->coll) { if(smd->coll->points) { MEM_freeN(smd->coll->points); smd->coll->points = NULL; } if(smd->coll->bvhtree) { BLI_bvhtree_free(smd->coll->bvhtree); smd->coll->bvhtree = NULL; } if(smd->coll->dm) smd->coll->dm->release(smd->coll->dm); smd->coll->dm = NULL; } } }
void BKE_bmbvh_free(BMBVHTree *bmtree) { BLI_bvhtree_free(bmtree->tree); if (bmtree->cos_cage && bmtree->cos_cage_free) { MEM_freeN((void *)bmtree->cos_cage); } MEM_freeN(bmtree); }
static void heat_system_free(LaplacianSystem *sys) { BLI_bvhtree_free(sys->heat.bvhtree); MEM_freeN(sys->heat.vface); MEM_freeN(sys->heat.mindist); MEM_freeN(sys->heat.H); MEM_freeN(sys->heat.p); MEM_freeN(sys->heat.vnors); }
static void RE_rayobject_blibvh_free(RayObject *o) { BVHObject *obj = (BVHObject*)o; if (obj->bvh) BLI_bvhtree_free(obj->bvh); if (obj->leafs) MEM_freeN(obj->leafs); MEM_freeN(obj); }
static void free_pointdensity(Render *UNUSED(re), Tex *tex) { PointDensity *pd = tex->pd; if (!pd) return; if (pd->point_tree) { BLI_bvhtree_free(pd->point_tree); pd->point_tree = NULL; } if (pd->point_data) { MEM_freeN(pd->point_data); pd->point_data = NULL; } pd->totpoints = 0; }
void free_pointdensity(PointDensity *pd) { if (pd == NULL) { return; } if (pd->point_tree) { BLI_bvhtree_free(pd->point_tree); pd->point_tree = NULL; } if (pd->point_data) { MEM_freeN(pd->point_data); pd->point_data = NULL; } pd->totpoints = 0; }
void BKE_free_pointdensitydata(PointDensity *pd) { if (pd->point_tree) { BLI_bvhtree_free(pd->point_tree); pd->point_tree = NULL; } if (pd->point_data) { MEM_freeN(pd->point_data); pd->point_data = NULL; } if (pd->coba) { MEM_freeN(pd->coba); pd->coba = NULL; } curvemapping_free(pd->falloff_curve); /* can be NULL */ }
static void cache_pointdensity_ex(Scene *scene, PointDensity *pd, float viewmat[4][4], float winmat[4][4], int winx, int winy) { if (pd == NULL) { return; } if (pd->point_tree) { BLI_bvhtree_free(pd->point_tree); pd->point_tree = NULL; } if (pd->source == TEX_PD_PSYS) { Object *ob = pd->object; ParticleSystem *psys; if (!ob || !pd->psys) { return; } psys = BLI_findlink(&ob->particlesystem, pd->psys - 1); if (!psys) { return; } pointdensity_cache_psys(scene, pd, ob, psys, viewmat, winmat, winx, winy); } else if (pd->source == TEX_PD_OBJECT) { Object *ob = pd->object; if (ob && ob->type == OB_MESH) pointdensity_cache_object(scene, pd, ob); } }
static void smokeModifier_freeCollision(SmokeModifierData *smd) { if(smd->coll) { if(smd->coll->points) { MEM_freeN(smd->coll->points); smd->coll->points = NULL; } if(smd->coll->bvhtree) { BLI_bvhtree_free(smd->coll->bvhtree); smd->coll->bvhtree = NULL; } if(smd->coll->dm) smd->coll->dm->release(smd->coll->dm); smd->coll->dm = NULL; MEM_freeN(smd->coll); smd->coll = NULL; } }
static void deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3], int UNUSED(numVerts), ModifierApplyFlag UNUSED(flag)) { CollisionModifierData *collmd = (CollisionModifierData *) md; DerivedMesh *dm = NULL; MVert *tempVert = NULL; /* if possible use/create DerivedMesh */ if (derivedData) dm = CDDM_copy(derivedData); else if (ob->type == OB_MESH) dm = CDDM_from_mesh(ob->data, ob); if (!ob->pd) { printf("CollisionModifier deformVerts: Should not happen!\n"); return; } if (dm) { float current_time = 0; unsigned int numverts = 0; CDDM_apply_vert_coords(dm, vertexCos); CDDM_calc_normals(dm); current_time = BKE_scene_frame_get(md->scene); if (G.debug_value > 0) printf("current_time %f, collmd->time_xnew %f\n", current_time, collmd->time_xnew); numverts = dm->getNumVerts(dm); if (current_time > collmd->time_xnew) { unsigned int i; /* check if mesh has changed */ if (collmd->x && (numverts != collmd->numverts)) freeData((ModifierData *)collmd); if (collmd->time_xnew == -1000) { /* first time */ collmd->x = dm->dupVertArray(dm); /* frame start position */ for (i = 0; i < numverts; i++) { /* we save global positions */ mul_m4_v3(ob->obmat, collmd->x[i].co); } collmd->xnew = MEM_dupallocN(collmd->x); // frame end position collmd->current_x = MEM_dupallocN(collmd->x); // inter-frame collmd->current_xnew = MEM_dupallocN(collmd->x); // inter-frame collmd->current_v = MEM_dupallocN(collmd->x); // inter-frame collmd->numverts = numverts; DM_ensure_tessface(dm); /* BMESH - UNTIL MODIFIER IS UPDATED FOR MPoly */ collmd->mfaces = dm->dupTessFaceArray(dm); collmd->numfaces = dm->getNumTessFaces(dm); /* create bounding box hierarchy */ collmd->bvhtree = bvhtree_build_from_mvert(collmd->mfaces, collmd->numfaces, collmd->x, numverts, ob->pd->pdef_sboft); collmd->time_x = collmd->time_xnew = current_time; } else if (numverts == collmd->numverts) { /* put positions to old positions */ tempVert = collmd->x; collmd->x = collmd->xnew; collmd->xnew = tempVert; collmd->time_x = collmd->time_xnew; memcpy(collmd->xnew, dm->getVertArray(dm), numverts * sizeof(MVert)); for (i = 0; i < numverts; i++) { /* we save global positions */ mul_m4_v3(ob->obmat, collmd->xnew[i].co); } memcpy(collmd->current_xnew, collmd->x, numverts * sizeof(MVert)); memcpy(collmd->current_x, collmd->x, numverts * sizeof(MVert)); /* check if GUI setting has changed for bvh */ if (collmd->bvhtree) { if (ob->pd->pdef_sboft != BLI_bvhtree_getepsilon(collmd->bvhtree)) { BLI_bvhtree_free(collmd->bvhtree); collmd->bvhtree = bvhtree_build_from_mvert(collmd->mfaces, collmd->numfaces, collmd->current_x, numverts, ob->pd->pdef_sboft); } } /* happens on file load (ONLY when i decomment changes in readfile.c) */ if (!collmd->bvhtree) { collmd->bvhtree = bvhtree_build_from_mvert(collmd->mfaces, collmd->numfaces, collmd->current_x, numverts, ob->pd->pdef_sboft); } else { /* recalc static bounding boxes */ bvhtree_update_from_mvert(collmd->bvhtree, collmd->mfaces, collmd->numfaces, collmd->current_x, collmd->current_xnew, collmd->numverts, 1); } collmd->time_xnew = current_time; } else if (numverts != collmd->numverts) { freeData((ModifierData *)collmd); } } else if (current_time < collmd->time_xnew) { freeData((ModifierData *)collmd); } else { if (numverts != collmd->numverts) { freeData((ModifierData *)collmd); } } } if (dm) dm->release(dm); }
/* frees all */ void cloth_free_modifier_extern ( ClothModifierData *clmd ) { Cloth *cloth = NULL; if(G.rt > 0) printf("cloth_free_modifier_extern\n"); if ( !clmd ) return; cloth = clmd->clothObject; if ( cloth ) { if(G.rt > 0) printf("cloth_free_modifier_extern in\n"); // If our solver provides a free function, call it if ( solvers [clmd->sim_parms->solver_type].free ) { solvers [clmd->sim_parms->solver_type].free ( clmd ); } // Free the verts. if ( cloth->verts != NULL ) MEM_freeN ( cloth->verts ); cloth->verts = NULL; cloth->numverts = 0; // Free the springs. if ( cloth->springs != NULL ) { LinkNode *search = cloth->springs; while(search) { ClothSpring *spring = search->link; MEM_freeN ( spring ); search = search->next; } BLI_linklist_free(cloth->springs, NULL); cloth->springs = NULL; } cloth->springs = NULL; cloth->numsprings = 0; // free BVH collision tree if ( cloth->bvhtree ) BLI_bvhtree_free ( cloth->bvhtree ); if ( cloth->bvhselftree ) BLI_bvhtree_free ( cloth->bvhselftree ); // we save our faces for collision objects if ( cloth->mfaces ) MEM_freeN ( cloth->mfaces ); if(cloth->edgehash) BLI_edgehash_free ( cloth->edgehash, NULL ); /* if(clmd->clothObject->facemarks) MEM_freeN(clmd->clothObject->facemarks); */ MEM_freeN ( cloth ); clmd->clothObject = NULL; } }