Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel/intern/mesh.c')
-rw-r--r--source/blender/blenkernel/intern/mesh.c154
1 files changed, 83 insertions, 71 deletions
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 8117a626c03..45a60b842a7 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -29,6 +29,11 @@
* ***** END GPL LICENSE BLOCK *****
*/
+/** \file blender/blenkernel/intern/mesh.c
+ * \ingroup bke
+ */
+
+
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@@ -98,11 +103,11 @@ void unlink_mesh(Mesh *me)
{
int a;
- if(me==0) return;
+ if(me==NULL) return;
for(a=0; a<me->totcol; a++) {
if(me->mat[a]) me->mat[a]->id.us--;
- me->mat[a]= 0;
+ me->mat[a]= NULL;
}
if(me->key) {
@@ -110,9 +115,9 @@ void unlink_mesh(Mesh *me)
if (me->key->id.us == 0 && me->key->ipo )
me->key->ipo->id.us--;
}
- me->key= 0;
+ me->key= NULL;
- if(me->texcomesh) me->texcomesh= 0;
+ if(me->texcomesh) me->texcomesh= NULL;
}
@@ -231,6 +236,8 @@ Mesh *copy_mesh(Mesh *me)
}
men->mselect= NULL;
+ men->edit_mesh= NULL;
+ men->pv= NULL; /* looks like this is no-longer supported but NULL just incase */
men->bb= MEM_dupallocN(men->bb);
@@ -240,7 +247,7 @@ Mesh *copy_mesh(Mesh *me)
return men;
}
-void make_local_tface(Mesh *me)
+static void make_local_tface(Main *bmain, Mesh *me)
{
MTFace *tface;
Image *ima;
@@ -255,9 +262,9 @@ void make_local_tface(Mesh *me)
if(tface->tpage) {
ima= tface->tpage;
if(ima->id.lib) {
- ima->id.lib= 0;
+ ima->id.lib= NULL;
ima->id.flag= LIB_LOCAL;
- new_id(0, (ID *)ima, 0);
+ new_id(&bmain->image, (ID *)ima, NULL);
}
}
}
@@ -265,58 +272,65 @@ void make_local_tface(Mesh *me)
}
}
+static void expand_local_mesh(Main *bmain, Mesh *me)
+{
+ id_lib_extern((ID *)me->texcomesh);
+
+ if(me->mtface) {
+ /* why is this an exception? - should not really make local when extern'ing - campbell */
+ make_local_tface(bmain, me);
+ }
+
+ if(me->mat) {
+ extern_local_matarar(me->mat, me->totcol);
+ }
+}
+
void make_local_mesh(Mesh *me)
{
Main *bmain= G.main;
Object *ob;
- Mesh *men;
int local=0, lib=0;
/* - only lib users: do nothing
- * - only local users: set flag
- * - mixed: make copy
- */
-
- if(me->id.lib==0) return;
+ * - only local users: set flag
+ * - mixed: make copy
+ */
+
+ if(me->id.lib==NULL) return;
if(me->id.us==1) {
- me->id.lib= 0;
+ me->id.lib= NULL;
me->id.flag= LIB_LOCAL;
- new_id(0, (ID *)me, 0);
-
- if(me->mtface) make_local_tface(me);
-
+
+ new_id(&bmain->mesh, (ID *)me, NULL);
+ expand_local_mesh(bmain, me);
return;
}
-
- ob= bmain->object.first;
- while(ob) {
- if( me==get_mesh(ob) ) {
+
+ for(ob= bmain->object.first; ob && ELEM(0, lib, local); ob= ob->id.next) {
+ if(me == ob->data) {
if(ob->id.lib) lib= 1;
else local= 1;
}
- ob= ob->id.next;
}
-
+
if(local && lib==0) {
- me->id.lib= 0;
+ me->id.lib= NULL;
me->id.flag= LIB_LOCAL;
- new_id(0, (ID *)me, 0);
-
- if(me->mtface) make_local_tface(me);
-
+
+ new_id(&bmain->mesh, (ID *)me, NULL);
+ expand_local_mesh(bmain, me);
}
else if(local && lib) {
- men= copy_mesh(me);
+ Mesh *men= copy_mesh(me);
men->id.us= 0;
-
- ob= bmain->object.first;
- while(ob) {
- if( me==get_mesh(ob) ) {
- if(ob->id.lib==0) {
+
+ for(ob= bmain->object.first; ob; ob= ob->id.next) {
+ if(me == ob->data) {
+ if(ob->id.lib==NULL) {
set_mesh(ob, men);
}
}
- ob= ob->id.next;
}
}
}
@@ -327,7 +341,7 @@ void boundbox_mesh(Mesh *me, float *loc, float *size)
float min[3], max[3];
float mloc[3], msize[3];
- if(me->bb==0) me->bb= MEM_callocN(sizeof(BoundBox), "boundbox");
+ if(me->bb==NULL) me->bb= MEM_callocN(sizeof(BoundBox), "boundbox");
bb= me->bb;
if (!loc) loc= mloc;
@@ -357,9 +371,9 @@ void tex_space_mesh(Mesh *me)
if(me->texflag & AUTOSPACE) {
for (a=0; a<3; a++) {
- if(size[a]==0.0) size[a]= 1.0;
- else if(size[a]>0.0 && size[a]<0.00001) size[a]= 0.00001;
- else if(size[a]<0.0 && size[a]> -0.00001) size[a]= -0.00001;
+ if(size[a]==0.0f) size[a]= 1.0f;
+ else if(size[a]>0.0f && size[a]<0.00001f) size[a]= 0.00001f;
+ else if(size[a]<0.0f && size[a]> -0.00001f) size[a]= -0.00001f;
}
copy_v3_v3(me->loc, loc);
@@ -512,18 +526,18 @@ int test_index_face(MFace *mface, CustomData *fdata, int mfindex, int nr)
Mesh *get_mesh(Object *ob)
{
- if(ob==0) return 0;
+ if(ob==NULL) return NULL;
if(ob->type==OB_MESH) return ob->data;
- else return 0;
+ else return NULL;
}
void set_mesh(Object *ob, Mesh *me)
{
- Mesh *old=0;
+ Mesh *old=NULL;
multires_force_update(ob);
- if(ob==0) return;
+ if(ob==NULL) return;
if(ob->type==OB_MESH) {
old= ob->data;
@@ -730,7 +744,7 @@ void mball_to_mesh(ListBase *lb, Mesh *me)
int a, *index;
dl= lb->first;
- if(dl==0) return;
+ if(dl==NULL) return;
if(dl->type==DL_INDEX4) {
me->totvert= dl->nr;
@@ -746,9 +760,7 @@ void mball_to_mesh(ListBase *lb, Mesh *me)
verts= dl->verts;
while(a--) {
VECCOPY(mvert->co, verts);
- mvert->no[0]= (short int)(nors[0]*32767.0);
- mvert->no[1]= (short int)(nors[1]*32767.0);
- mvert->no[2]= (short int)(nors[2]*32767.0);
+ normal_float_to_short_v3(mvert->no, nors);
mvert++;
nors+= 3;
verts+= 3;
@@ -832,7 +844,7 @@ int nurbs_to_mdata_customdb(Object *ob, ListBase *dispbase, MVert **allvert, int
}
*allvert= mvert= MEM_callocN(sizeof (MVert) * totvert, "nurbs_init mvert");
- *allface= mface= MEM_callocN(sizeof (MVert) * totvlak, "nurbs_init mface");
+ *allface= mface= MEM_callocN(sizeof (MFace) * totvlak, "nurbs_init mface");
/* verts and faces */
vertcount= 0;
@@ -1023,7 +1035,7 @@ void nurbs_to_mesh(Object *ob)
tex_space_mesh(me);
- cu->mat= 0;
+ cu->mat= NULL;
cu->totcol= 0;
if(ob->data) {
@@ -1265,34 +1277,37 @@ void mesh_set_smooth_flag(Object *meshOb, int enableSmooth)
mf->flag &= ~ME_SMOOTH;
}
}
+
+ mesh_calc_normals(me->mvert, me->totvert, me->mface, me->totface, NULL);
}
-void mesh_calc_normals(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, float **faceNors_r)
+void mesh_calc_normals(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, float (*faceNors_r)[3])
{
float (*tnorms)[3]= MEM_callocN(numVerts*sizeof(*tnorms), "tnorms");
- float *fnors= MEM_callocN(sizeof(*fnors)*3*numFaces, "meshnormals");
+ float (*fnors)[3]= (faceNors_r)? faceNors_r: MEM_callocN(sizeof(*fnors)*numFaces, "meshnormals");
int i;
- for (i=0; i<numFaces; i++) {
+ for(i=0; i<numFaces; i++) {
MFace *mf= &mfaces[i];
- float *f_no= &fnors[i*3];
+ float *f_no= fnors[i];
+ float *n4 = (mf->v4)? tnorms[mf->v4]: NULL;
+ float *c4 = (mf->v4)? mverts[mf->v4].co: NULL;
- if (mf->v4)
- normal_quad_v3( f_no,mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, mverts[mf->v4].co);
+ if(mf->v4)
+ normal_quad_v3(f_no, mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, mverts[mf->v4].co);
else
- normal_tri_v3( f_no,mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co);
-
- add_v3_v3(tnorms[mf->v1], f_no);
- add_v3_v3(tnorms[mf->v2], f_no);
- add_v3_v3(tnorms[mf->v3], f_no);
- if (mf->v4)
- add_v3_v3(tnorms[mf->v4], f_no);
+ normal_tri_v3(f_no, mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co);
+
+ accumulate_vertex_normals(tnorms[mf->v1], tnorms[mf->v2], tnorms[mf->v3], n4,
+ f_no, mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, c4);
}
- for (i=0; i<numVerts; i++) {
+
+ /* following Mesh convention; we use vertex coordinate itself for normal in this case */
+ for(i=0; i<numVerts; i++) {
MVert *mv= &mverts[i];
float *no= tnorms[i];
- if (normalize_v3(no)==0.0)
+ if(normalize_v3(no) == 0.0f)
normalize_v3_v3(no, mv->co);
normal_float_to_short_v3(mv->no, no);
@@ -1300,11 +1315,8 @@ void mesh_calc_normals(MVert *mverts, int numVerts, MFace *mfaces, int numFaces,
MEM_freeN(tnorms);
- if (faceNors_r) {
- *faceNors_r = fnors;
- } else {
+ if(fnors != faceNors_r)
MEM_freeN(fnors);
- }
}
float (*mesh_getVertexCos(Mesh *me, int *numVerts_r))[3]
@@ -1393,7 +1405,7 @@ UvVertMap *make_uv_vert_map(struct MFace *mface, struct MTFace *tface, unsigned
sub_v2_v2v2(uvdiff, uv2, uv);
- if(fabs(uv[0]-uv2[0]) < limit[0] && fabs(uv[1]-uv2[1]) < limit[1]) {
+ if(fabsf(uv[0]-uv2[0]) < limit[0] && fabsf(uv[1]-uv2[1]) < limit[1]) {
if(lastv) lastv->next= next;
else vlist= next;
iterv->next= newvlist;
@@ -1460,7 +1472,7 @@ void create_vert_edge_map(ListBase **map, IndexNode **mem, const MEdge *medge, c
(*map) = MEM_callocN(sizeof(ListBase) * totvert, "vert edge map");
(*mem) = MEM_callocN(sizeof(IndexNode) * totedge * 2, "vert edge map mem");
node = *mem;
-
+
/* Find the users */
for(i = 0; i < totedge; ++i){
for(j = 0; j < 2; ++j, ++node) {