diff options
Diffstat (limited to 'source/blender/blenkernel/intern/mball.c')
-rw-r--r-- | source/blender/blenkernel/intern/mball.c | 68 |
1 files changed, 40 insertions, 28 deletions
diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index e6e32be9634..555d35726bc 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -67,6 +67,7 @@ #include "BKE_displist.h" #include "BKE_mball.h" #include "BKE_object.h" +#include "BKE_material.h" /* Global variables */ @@ -132,14 +133,24 @@ MetaBall *copy_mball(MetaBall *mb) id_us_plus((ID *)mbn->mat[a]); } mbn->bb= MEM_dupallocN(mb->bb); + + mbn->editelems= NULL; + mbn->lastelem= NULL; return mbn; } +static void extern_local_mball(MetaBall *mb) +{ + if(mb->mat) { + extern_local_matarar(mb->mat, mb->totcol); + } +} + void make_local_mball(MetaBall *mb) { + Main *bmain= G.main; Object *ob; - MetaBall *mbn; int local=0, lib=0; /* - only lib users: do nothing @@ -151,43 +162,44 @@ void make_local_mball(MetaBall *mb) if(mb->id.us==1) { mb->id.lib= NULL; mb->id.flag= LIB_LOCAL; + new_id(&bmain->mball, (ID *)mb, NULL); + extern_local_mball(mb); + return; } - - ob= G.main->object.first; - while(ob) { - if(ob->data==mb) { + + for(ob= G.main->object.first; ob && ELEM(0, lib, local); ob= ob->id.next) { + if(ob->data == mb) { if(ob->id.lib) lib= 1; else local= 1; } - ob= ob->id.next; } if(local && lib==0) { mb->id.lib= NULL; mb->id.flag= LIB_LOCAL; + + new_id(&bmain->mball, (ID *)mb, NULL); + extern_local_mball(mb); } else if(local && lib) { - mbn= copy_mball(mb); + MetaBall *mbn= copy_mball(mb); mbn->id.us= 0; - - ob= G.main->object.first; - while(ob) { - if(ob->data==mb) { - + + for(ob= G.main->object.first; ob; ob= ob->id.next) { + if(ob->data == mb) { if(ob->id.lib==NULL) { ob->data= mbn; mbn->id.us++; mb->id.us--; } } - ob= ob->id.next; } } } /* most simple meta-element adding function - * dont do context menipulation here (rna uses) */ + * don't do context manipulation here (rna uses) */ MetaElem *add_metaball_element(MetaBall *mb, const int type) { MetaElem *ml= MEM_callocN(sizeof(MetaElem), "metaelem"); @@ -237,14 +249,14 @@ MetaElem *add_metaball_element(MetaBall *mb, const int type) /** Compute bounding box of all MetaElems/MetaBalls. * * Bounding box is computed from polygonized surface. Object *ob is - * basic MetaBall (usaualy with name Meta). All other MetaBalls (whith + * basic MetaBall (usually with name Meta). All other MetaBalls (with * names Meta.001, Meta.002, etc) are included in this Bounding Box. */ void tex_space_mball(Object *ob) { DispList *dl; BoundBox *bb; - float *data, min[3], max[3], loc[3], size[3]; + float *data, min[3], max[3] /*, loc[3], size[3] */; int tot, doit=0; if(ob->bb==NULL) ob->bb= MEM_callocN(sizeof(BoundBox), "mb boundbox"); @@ -272,7 +284,7 @@ void tex_space_mball(Object *ob) min[0] = min[1] = min[2] = -1.0f; max[0] = max[1] = max[2] = 1.0f; } - + /* loc[0]= (min[0]+max[0])/2.0f; loc[1]= (min[1]+max[1])/2.0f; loc[2]= (min[2]+max[2])/2.0f; @@ -280,7 +292,7 @@ void tex_space_mball(Object *ob) size[0]= (max[0]-min[0])/2.0f; size[1]= (max[1]-min[1])/2.0f; size[2]= (max[2]-min[2])/2.0f; - + */ boundbox_set_from_min_max(bb, min, max); } @@ -320,14 +332,14 @@ float *make_orco_mball(Object *ob, ListBase *dispbase) } /* Note on mball basis stuff 2.5x (this is a can of worms) - * This really needs a rewrite/refactorm its totally broken in anything other then basic cases + * This really needs a rewrite/refactor its totally broken in anything other then basic cases * Multiple Scenes + Set Scenes & mixing mball basis SHOULD work but fails to update the depsgraph on rename * and linking into scenes or removal of basis mball. so take care when changing this code. * * Main idiot thing here is that the system returns find_basis_mball() objects which fail a is_basis_mball() test. * - * Not only that but the depsgraph and ther areas depend on this behavior!, so making small fixes here isnt worth it. - * - campbell + * Not only that but the depsgraph and their areas depend on this behavior!, so making small fixes here isn't worth it. + * - Campbell */ @@ -725,7 +737,7 @@ void accum_mballfaces(int i1, int i2, int i3, int i4) cur= indices+4*curindex; - /* diplists now support array drawing, we treat trias as fake quad */ + /* displists now support array drawing, we treat tri's as fake quad */ cur[0]= i1; cur[1]= i2; @@ -1315,7 +1327,7 @@ void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2, dy = pos.y - neg.y; dz = pos.z - neg.z; -/* Aproximation by linear interpolation is faster then binary subdivision, +/* Approximation by linear interpolation is faster then binary subdivision, * but it results sometimes (mb->thresh < 0.2) into the strange results */ if((mb->thresh > 0.2f) && (f==1)){ if((dy == 0.0f) && (dz == 0.0f)){ @@ -1373,7 +1385,7 @@ void converge (MB_POINT *p1, MB_POINT *p2, float v1, float v2, p->x = 0.5f*(pos.x + neg.x); p->y = 0.5f*(pos.y + neg.y); p->z = 0.5f*(pos.z + neg.z); - + if (i++ == RES) return; if ((function(p->x, p->y, p->z)) > 0.0f){ @@ -1625,7 +1637,7 @@ float init_meta(Scene *scene, Object *ob) /* return totsize */ } } - /* when metaball object hase zero scale, then MetaElem ot this MetaBall + /* when metaball object has zero scale, then MetaElem to this MetaBall * will not be put to mainb array */ if(bob->size[0]==0.0f || bob->size[1]==0.0f || bob->size[2]==0.0f) { zero_size= 1; @@ -1688,11 +1700,11 @@ float init_meta(Scene *scene, Object *ob) /* return totsize */ mul_m4_m4m4(temp2, bob->obmat, obinv); /* MetaBall transformation */ mul_m4_m4m4(mat, temp1, temp2); - + invert_m4_m4(imat,mat); - + mainb[a]->rad2= ml->rad*ml->rad; - + mainb[a]->mat= (float*) mat; mainb[a]->imat= (float*) imat; |