97
92
case MESHCMP_DVERT_WEIGHTMISMATCH:
98
93
return "Vertex Weight Mismatch";
99
94
case MESHCMP_DVERT_GROUPMISMATCH:
100
return "Vertex Group Mismatch";
95
return "Vertex Group Mismatch";
101
96
case MESHCMP_DVERT_TOTGROUPMISMATCH:
102
return "Vertex Doesn't Belong To Same Number Of Groups";
97
return "Vertex Doesn't Belong To Same Number Of Groups";
103
98
case MESHCMP_LOOPCOLMISMATCH:
104
return "Vertex Color Mismatch";
99
return "Vertex Color Mismatch";
105
100
case MESHCMP_LOOPUVMISMATCH:
106
return "UV Mismatch";
101
return "UV Mismatch";
107
102
case MESHCMP_LOOPMISMATCH:
108
return "Loop Mismatch";
103
return "Loop Mismatch";
109
104
case MESHCMP_POLYVERTMISMATCH:
110
return "Loop Vert Mismatch In Poly Test";
105
return "Loop Vert Mismatch In Poly Test";
111
106
case MESHCMP_POLYMISMATCH:
112
return "Loop Vert Mismatch";
107
return "Loop Vert Mismatch";
113
108
case MESHCMP_EDGEUNKNOWN:
114
return "Edge Mismatch";
109
return "Edge Mismatch";
115
110
case MESHCMP_VERTCOMISMATCH:
116
return "Vertex Coordinate Mismatch";
111
return "Vertex Coordinate Mismatch";
117
112
case MESHCMP_CDLAYERS_MISMATCH:
118
return "CustomData Layer Count Mismatch";
113
return "CustomData Layer Count Mismatch";
120
return "Mesh Comparison Code Unknown";
115
return "Mesh Comparison Code Unknown";
124
119
/* thresh is threshold for comparing vertices, uvs, vertex colors,
126
121
static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2, float thresh)
128
123
CustomDataLayer *l1, *l2;
129
int i, i1=0, i2=0, tot, j;
124
int i, i1 = 0, i2 = 0, tot, j;
131
for (i=0; i<c1->totlayer; i++) {
132
if (ELEM7(c1->layers[i].type, CD_MVERT, CD_MEDGE, CD_MPOLY,
133
CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT))
126
for (i = 0; i < c1->totlayer; i++) {
127
if (ELEM7(c1->layers[i].type, CD_MVERT, CD_MEDGE, CD_MPOLY,
128
CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT))
137
for (i=0; i<c2->totlayer; i++) {
138
if (ELEM7(c2->layers[i].type, CD_MVERT, CD_MEDGE, CD_MPOLY,
139
CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT))
134
for (i = 0; i < c2->totlayer; i++) {
135
if (ELEM7(c2->layers[i].type, CD_MVERT, CD_MEDGE, CD_MPOLY,
136
CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT))
144
143
return MESHCMP_CDLAYERS_MISMATCH;
146
145
l1 = c1->layers; l2 = c2->layers;
149
for (i=0; i < tot; i++) {
148
for (i = 0; i < tot; i++) {
150
149
while (i1 < c1->totlayer && !ELEM7(l1->type, CD_MVERT, CD_MEDGE, CD_MPOLY,
151
CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT))
150
CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT))
154
while (i2 < c2->totlayer && !ELEM7(l2->type, CD_MVERT, CD_MEDGE, CD_MPOLY,
155
CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT))
155
while (i2 < c2->totlayer && !ELEM7(l2->type, CD_MVERT, CD_MEDGE, CD_MPOLY,
156
CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT))
158
161
if (l1->type == CD_MVERT) {
159
162
MVert *v1 = l1->data;
160
163
MVert *v2 = l2->data;
161
164
int vtot = m1->totvert;
163
for (j=0; j<vtot; j++, v1++, v2++) {
166
for (j = 0; j < vtot; j++, v1++, v2++) {
164
167
if (len_v3v3(v1->co, v2->co) > thresh)
165
168
return MESHCMP_VERTCOMISMATCH;
166
/*I don't care about normals, let's just do coodinates*/
169
/* I don't care about normals, let's just do coodinates */
427
430
if (me->edit_btmesh) MEM_freeN(me->edit_btmesh);
430
void copy_dverts(MDeformVert *dst, MDeformVert *src, int copycount)
432
/* Assumes dst is already set up */
438
memcpy (dst, src, copycount * sizeof(MDeformVert));
440
for (i=0; i<copycount; i++) {
442
dst[i].dw = MEM_callocN (sizeof(MDeformWeight)*src[i].totweight, "copy_deformWeight");
443
memcpy (dst[i].dw, src[i].dw, sizeof (MDeformWeight)*src[i].totweight);
449
void free_dverts(MDeformVert *dvert, int totvert)
451
/* Instead of freeing the verts directly,
452
* call this function to delete any special
459
/* Free any special data from the verts */
460
for (i=0; i<totvert; i++) {
461
if (dvert[i].dw) MEM_freeN (dvert[i].dw);
466
433
static void mesh_tessface_clear_intern(Mesh *mesh, int free_customdata)
435
if (free_customdata) {
469
436
CustomData_free(&mesh->fdata, mesh->totface);
439
CustomData_reset(&mesh->fdata);
471
442
mesh->mface = NULL;
472
443
mesh->mtface = NULL;
473
444
mesh->mcol = NULL;
474
445
mesh->totface = 0;
476
memset(&mesh->fdata, 0, sizeof(mesh->fdata));
479
Mesh *add_mesh(const char *name)
448
Mesh *BKE_mesh_add(Main *bmain, const char *name)
483
me= alloc_libblock(&G.main->mesh, ID_ME, name);
485
me->size[0]= me->size[1]= me->size[2]= 1.0;
487
me->texflag= ME_AUTOSPACE;
488
me->flag= ME_TWOSIDED;
489
me->bb= unit_boundbox();
490
me->drawflag= ME_DRAWEDGES|ME_DRAWFACES|ME_DRAWCREASES;
452
me = BKE_libblock_alloc(&bmain->mesh, ID_ME, name);
454
me->size[0] = me->size[1] = me->size[2] = 1.0;
456
me->texflag = ME_AUTOSPACE;
457
me->flag = ME_TWOSIDED;
458
me->drawflag = ME_DRAWEDGES | ME_DRAWFACES | ME_DRAWCREASES;
460
CustomData_reset(&me->vdata);
461
CustomData_reset(&me->edata);
462
CustomData_reset(&me->fdata);
463
CustomData_reset(&me->pdata);
464
CustomData_reset(&me->ldata);
495
Mesh *copy_mesh(Mesh *me)
469
Mesh *BKE_mesh_copy_ex(Main *bmain, Mesh *me)
522
496
mesh_update_customdata_pointers(men, do_tessface);
524
498
/* ensure indirect linked data becomes lib-extern */
525
for (i=0; i<me->fdata.totlayer; i++) {
499
for (i = 0; i < me->fdata.totlayer; i++) {
526
500
if (me->fdata.layers[i].type == CD_MTFACE) {
527
tface= (MTFace*)me->fdata.layers[i].data;
501
tface = (MTFace *)me->fdata.layers[i].data;
529
for (a=0; a<me->totface; a++, tface++)
503
for (a = 0; a < me->totface; a++, tface++)
530
504
if (tface->tpage)
531
id_lib_extern((ID*)tface->tpage);
505
id_lib_extern((ID *)tface->tpage);
535
for (i=0; i<me->pdata.totlayer; i++) {
509
for (i = 0; i < me->pdata.totlayer; i++) {
536
510
if (me->pdata.layers[i].type == CD_MTEXPOLY) {
537
txface= (MTexPoly*)me->pdata.layers[i].data;
511
txface = (MTexPoly *)me->pdata.layers[i].data;
539
for (a=0; a<me->totpoly; a++, txface++)
513
for (a = 0; a < me->totpoly; a++, txface++)
540
514
if (txface->tpage)
541
id_lib_extern((ID*)txface->tpage);
515
id_lib_extern((ID *)txface->tpage);
546
men->edit_btmesh= NULL;
520
men->edit_btmesh = NULL;
548
men->bb= MEM_dupallocN(men->bb);
522
men->bb = MEM_dupallocN(men->bb);
550
men->key= copy_key(me->key);
551
if (men->key) men->key->from= (ID *)men;
524
men->key = BKE_key_copy(me->key);
525
if (men->key) men->key->from = (ID *)men;
530
Mesh *BKE_mesh_copy(Mesh *me)
532
return BKE_mesh_copy_ex(G.main, me);
556
535
BMesh *BKE_mesh_to_bmesh(Mesh *me, Object *ob)
560
539
bm = BM_mesh_create(&bm_mesh_allocsize_default);
562
BM_mesh_bm_from_me(bm, me, TRUE, ob->shapenr);
541
BM_mesh_bm_from_me(bm, me, true, ob->shapenr);
653
void boundbox_mesh(Mesh *me, float *loc, float *size)
632
void BKE_mesh_boundbox_calc(Mesh *me, float r_loc[3], float r_size[3])
656
635
float min[3], max[3];
657
636
float mloc[3], msize[3];
659
if (me->bb==NULL) me->bb= MEM_callocN(sizeof(BoundBox), "boundbox");
638
if (me->bb == NULL) me->bb = MEM_callocN(sizeof(BoundBox), "boundbox");
663
if (!size) size= msize;
641
if (!r_loc) r_loc = mloc;
642
if (!r_size) r_size = msize;
665
644
INIT_MINMAX(min, max);
666
if (!minmax_mesh(me, min, max)) {
645
if (!BKE_mesh_minmax(me, min, max)) {
667
646
min[0] = min[1] = min[2] = -1.0f;
668
647
max[0] = max[1] = max[2] = 1.0f;
671
mid_v3_v3v3(loc, min, max);
650
mid_v3_v3v3(r_loc, min, max);
673
size[0]= (max[0]-min[0])/2.0f;
674
size[1]= (max[1]-min[1])/2.0f;
675
size[2]= (max[2]-min[2])/2.0f;
652
r_size[0] = (max[0] - min[0]) / 2.0f;
653
r_size[1] = (max[1] - min[1]) / 2.0f;
654
r_size[2] = (max[2] - min[2]) / 2.0f;
677
boundbox_set_from_min_max(bb, min, max);
656
BKE_boundbox_init_from_minmax(bb, min, max);
680
void tex_space_mesh(Mesh *me)
659
void BKE_mesh_texspace_calc(Mesh *me)
682
661
float loc[3], size[3];
685
boundbox_mesh(me, loc, size);
664
BKE_mesh_boundbox_calc(me, loc, size);
687
666
if (me->texflag & ME_AUTOSPACE) {
688
for (a=0; a<3; a++) {
689
if (size[a]==0.0f) size[a]= 1.0f;
690
else if (size[a]>0.0f && size[a]<0.00001f) size[a]= 0.00001f;
691
else if (size[a]<0.0f && size[a]> -0.00001f) size[a]= -0.00001f;
667
for (a = 0; a < 3; a++) {
668
if (size[a] == 0.0f) size[a] = 1.0f;
669
else if (size[a] > 0.0f && size[a] < 0.00001f) size[a] = 0.00001f;
670
else if (size[a] < 0.0f && size[a] > -0.00001f) size[a] = -0.00001f;
694
673
copy_v3_v3(me->loc, loc);
700
BoundBox *mesh_get_bb(Object *ob)
679
BoundBox *BKE_mesh_boundbox_get(Object *ob)
687
BKE_mesh_texspace_calc(me);
713
void mesh_get_texspace(Mesh *me, float r_loc[3], float r_rot[3], float r_size[3])
692
void BKE_mesh_texspace_get(Mesh *me, float r_loc[3], float r_rot[3], float r_size[3])
695
BKE_mesh_texspace_calc(me);
719
if (r_loc) copy_v3_v3(r_loc, me->loc);
720
if (r_rot) copy_v3_v3(r_rot, me->rot);
698
if (r_loc) copy_v3_v3(r_loc, me->loc);
699
if (r_rot) copy_v3_v3(r_rot, me->rot);
721
700
if (r_size) copy_v3_v3(r_size, me->size);
724
float *get_mesh_orco_verts(Object *ob)
703
float (*BKE_mesh_orco_verts_get(Object *ob))[3]
726
705
Mesh *me = ob->data;
727
706
MVert *mvert = NULL;
728
Mesh *tme = me->texcomesh?me->texcomesh:me;
707
Mesh *tme = me->texcomesh ? me->texcomesh : me;
730
709
float (*vcos)[3] = NULL;
732
711
/* Get appropriate vertex coordinates */
733
vcos = MEM_callocN(sizeof(*vcos)*me->totvert, "orco mesh");
712
vcos = MEM_callocN(sizeof(*vcos) * me->totvert, "orco mesh");
734
713
mvert = tme->mvert;
735
totvert = MIN2(tme->totvert, me->totvert);
714
totvert = min_ii(tme->totvert, me->totvert);
737
for (a=0; a<totvert; a++, mvert++) {
716
for (a = 0; a < totvert; a++, mvert++) {
738
717
copy_v3_v3(vcos[a], mvert->co);
744
void transform_mesh_orco_verts(Mesh *me, float (*orco)[3], int totvert, int invert)
723
void BKE_mesh_orco_verts_transform(Mesh *me, float (*orco)[3], int totvert, int invert)
746
725
float loc[3], size[3];
749
mesh_get_texspace(me->texcomesh?me->texcomesh:me, loc, NULL, size);
728
BKE_mesh_texspace_get(me->texcomesh ? me->texcomesh : me, loc, NULL, size);
752
for (a=0; a<totvert; a++) {
731
for (a = 0; a < totvert; a++) {
753
732
float *co = orco[a];
754
733
madd_v3_v3v3v3(co, loc, co, size);
758
for (a=0; a<totvert; a++) {
737
for (a = 0; a < totvert; a++) {
759
738
float *co = orco[a];
760
co[0] = (co[0]-loc[0])/size[0];
761
co[1] = (co[1]-loc[1])/size[1];
762
co[2] = (co[2]-loc[2])/size[2];
739
co[0] = (co[0] - loc[0]) / size[0];
740
co[1] = (co[1] - loc[1]) / size[1];
741
co[2] = (co[2] - loc[2]) / size[2];
769
748
int test_index_face(MFace *mface, CustomData *fdata, int mfindex, int nr)
771
750
/* first test if the face is legal */
772
if ((mface->v3 || nr==4) && mface->v3==mface->v4) {
776
if ((mface->v2 || mface->v4) && mface->v2==mface->v3) {
777
mface->v3= mface->v4;
781
if (mface->v1==mface->v2) {
782
mface->v2= mface->v3;
783
mface->v3= mface->v4;
751
if ((mface->v3 || nr == 4) && mface->v3 == mface->v4) {
755
if ((mface->v2 || mface->v4) && mface->v2 == mface->v3) {
756
mface->v3 = mface->v4;
760
if (mface->v1 == mface->v2) {
761
mface->v2 = mface->v3;
762
mface->v3 = mface->v4;
788
/* check corrupt cases, bowtie geometry, cant handle these because edge data wont exist so just return 0 */
767
/* check corrupt cases, bow-tie geometry, cant handle these because edge data wont exist so just return 0 */
792
mface->v1==mface->v2 ||
793
mface->v2==mface->v3 ||
771
mface->v1 == mface->v2 ||
772
mface->v2 == mface->v3 ||
773
mface->v3 == mface->v1)
802
mface->v1==mface->v2 ||
803
mface->v2==mface->v3 ||
804
mface->v3==mface->v4 ||
805
mface->v4==mface->v1 ||
806
/* across the face */
807
mface->v1==mface->v3 ||
781
mface->v1 == mface->v2 ||
782
mface->v2 == mface->v3 ||
783
mface->v3 == mface->v4 ||
784
mface->v4 == mface->v1 ||
785
/* across the face */
786
mface->v1 == mface->v3 ||
787
mface->v2 == mface->v4)
814
793
/* prevent a zero at wrong index location */
795
if (mface->v3 == 0) {
817
796
static int corner_indices[4] = {1, 2, 0, 3};
819
798
SWAP(unsigned int, mface->v1, mface->v2);
905
884
/* Create edges based on known verts and faces */
906
885
static void make_edges_mdata(MVert *UNUSED(allvert), MFace *allface, MLoop *allloop,
907
MPoly *allpoly, int UNUSED(totvert), int totface, int UNUSED(totloop), int totpoly,
908
int old, MEdge **alledge, int *_totedge)
886
MPoly *allpoly, int UNUSED(totvert), int totface, int UNUSED(totloop), int totpoly,
887
int old, MEdge **alledge, int *_totedge)
914
892
EdgeHash *hash = BLI_edgehash_new();
915
893
struct edgesort *edsort, *ed;
916
int a, b, totedge=0, final=0;
894
int a, totedge = 0, final = 0;
918
896
/* we put all edges in array, sort them, and detect doubles that way */
920
for (a= totface, mface= allface; a>0; a--, mface++) {
921
if (mface->v4) totedge+=4;
922
else if (mface->v3) totedge+=3;
898
for (a = totface, mface = allface; a > 0; a--, mface++) {
899
if (mface->v4) totedge += 4;
900
else if (mface->v3) totedge += 3;
927
905
/* flag that mesh has edges */
928
(*alledge)= MEM_callocN(0, "make mesh edges");
906
(*alledge) = MEM_callocN(0, "make mesh edges");
933
ed= edsort= MEM_mallocN(totedge*sizeof(struct edgesort), "edgesort");
911
ed = edsort = MEM_mallocN(totedge * sizeof(struct edgesort), "edgesort");
935
for (a= totface, mface= allface; a>0; a--, mface++) {
913
for (a = totface, mface = allface; a > 0; a--, mface++) {
936
914
to_edgesort(ed++, mface->v1, mface->v2, !mface->v3, mface->edcode & ME_V1V2);
938
916
to_edgesort(ed++, mface->v2, mface->v3, 0, mface->edcode & ME_V2V3);
948
926
qsort(edsort, totedge, sizeof(struct edgesort), vergedgesort);
950
928
/* count final amount */
951
for (a=totedge, ed=edsort; a>1; a--, ed++) {
929
for (a = totedge, ed = edsort; a > 1; a--, ed++) {
952
930
/* edge is unique when it differs from next edge, or is last */
953
if (ed->v1 != (ed+1)->v1 || ed->v2 != (ed+1)->v2) final++;
931
if (ed->v1 != (ed + 1)->v1 || ed->v2 != (ed + 1)->v2) final++;
957
(*alledge)= medge= MEM_callocN(sizeof (MEdge) * final, "make_edges mdge");
935
(*alledge) = medge = MEM_callocN(sizeof(MEdge) * final, "BKE_mesh_make_edges mdge");
960
for (a=totedge, ed=edsort; a>1; a--, ed++) {
938
for (a = totedge, ed = edsort; a > 1; a--, ed++) {
961
939
/* edge is unique when it differs from next edge, or is last */
962
if (ed->v1 != (ed+1)->v1 || ed->v2 != (ed+1)->v2) {
965
if (old==0 || ed->is_draw) medge->flag= ME_EDGEDRAW|ME_EDGERENDER;
966
if (ed->is_loose) medge->flag|= ME_LOOSEEDGE;
940
if (ed->v1 != (ed + 1)->v1 || ed->v2 != (ed + 1)->v2) {
943
if (old == 0 || ed->is_draw) medge->flag = ME_EDGEDRAW | ME_EDGERENDER;
944
if (ed->is_loose) medge->flag |= ME_LOOSEEDGE;
968
946
/* order is swapped so extruding this edge as a surface wont flip face normals
969
947
* with cyclic curves */
970
if (ed->v1+1 != ed->v2) {
948
if (ed->v1 + 1 != ed->v2) {
971
949
SWAP(unsigned int, medge->v1, medge->v2);
976
954
/* equal edge, we merge the drawflag */
977
(ed+1)->is_draw |= ed->is_draw;
955
(ed + 1)->is_draw |= ed->is_draw;
983
medge->flag= ME_EDGEDRAW;
984
if (ed->is_loose) medge->flag|= ME_LOOSEEDGE;
961
medge->flag = ME_EDGEDRAW;
962
if (ed->is_loose) medge->flag |= ME_LOOSEEDGE;
985
963
medge->flag |= ME_EDGERENDER;
987
965
MEM_freeN(edsort);
989
/*set edge members of mloops*/
991
for (a=0; a<*_totedge; a++, medge++) {
967
/* set edge members of mloops */
969
for (a = 0; a < *_totedge; a++, medge++) {
992
970
BLI_edgehash_insert(hash, medge->v1, medge->v2, SET_INT_IN_POINTER(a));
996
for (a=0; a<totpoly; a++, mpoly++) {
997
mloop = allloop + mpoly->loopstart;
998
for (b=0; b<mpoly->totloop; b++) {
1002
v2 = ME_POLY_LOOP_NEXT(mloop, mpoly, b)->v;
1003
mloop[b].e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(hash, v1, v2));
974
for (a = 0; a < totpoly; a++, mpoly++) {
976
int i = mpoly->totloop;
978
ml_next = allloop + mpoly->loopstart; /* first loop */
979
ml = &ml_next[i - 1]; /* last loop */
982
ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(hash, ml->v, ml_next->v));
1007
988
BLI_edgehash_free(hash, NULL);
1010
void make_edges(Mesh *me, int old)
991
void BKE_mesh_make_edges(Mesh *me, int old)
1015
996
make_edges_mdata(me->mvert, me->mface, me->mloop, me->mpoly, me->totvert, me->totface, me->totloop, me->totpoly, old, &medge, &totedge);
1017
998
/* flag that mesh has edges */
1018
999
me->medge = medge;
1019
1000
me->totedge = 0;
1023
medge= CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, medge, totedge);
1025
me->totedge= totedge;
1004
medge = CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, medge, totedge);
1006
me->totedge = totedge;
1027
mesh_strip_loose_faces(me);
1008
BKE_mesh_strip_loose_faces(me);
1030
1011
/* We need to keep this for edge creation (for now?), and some old readfile code... */
1031
void mesh_strip_loose_faces(Mesh *me)
1012
void BKE_mesh_strip_loose_faces(Mesh *me)
1167
1148
float *nors, *verts;
1171
if (dl==NULL) return;
1173
if (dl->type==DL_INDEX4) {
1174
mvert= CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, dl->nr);
1175
allloop= mloop= CustomData_add_layer(&me->ldata, CD_MLOOP, CD_CALLOC, NULL, dl->parts * 4);
1176
mpoly= CustomData_add_layer(&me->pdata, CD_MPOLY, CD_CALLOC, NULL, dl->parts);
1180
me->totvert= dl->nr;
1181
me->totpoly= dl->parts;
1152
if (dl == NULL) return;
1154
if (dl->type == DL_INDEX4) {
1155
mvert = CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, NULL, dl->nr);
1156
allloop = mloop = CustomData_add_layer(&me->ldata, CD_MLOOP, CD_CALLOC, NULL, dl->parts * 4);
1157
mpoly = CustomData_add_layer(&me->pdata, CD_MPOLY, CD_CALLOC, NULL, dl->parts);
1161
me->totvert = dl->nr;
1162
me->totpoly = dl->parts;
1187
1168
copy_v3_v3(mvert->co, verts);
1188
1169
normal_float_to_short_v3(mvert->no, nors);
1197
int count= index[2] != index[3] ? 4 : 3;
1178
int count = index[2] != index[3] ? 4 : 3;
1199
mloop[0].v= index[0];
1200
mloop[1].v= index[1];
1201
mloop[2].v= index[2];
1180
mloop[0].v = index[0];
1181
mloop[1].v = index[1];
1182
mloop[2].v = index[2];
1202
1183
if (count == 4)
1203
mloop[3].v= index[3];
1184
mloop[3].v = index[3];
1205
mpoly->totloop= count;
1206
mpoly->loopstart= (int)(mloop - allloop);
1207
mpoly->flag= ME_SMOOTH;
1186
mpoly->totloop = count;
1187
mpoly->loopstart = (int)(mloop - allloop);
1188
mpoly->flag = ME_SMOOTH;
1212
me->totloop+= count;
1193
me->totloop += count;
1216
1197
mesh_update_customdata_pointers(me, TRUE);
1218
mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL);
1199
BKE_mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL);
1220
1201
BKE_mesh_calc_edges(me, TRUE);
1224
1205
/* Initialize mverts, medges and, faces for converting nurbs to mesh and derived mesh */
1225
1206
/* return non-zero on error */
1226
int nurbs_to_mdata(Object *ob, MVert **allvert, int *totvert,
1227
MEdge **alledge, int *totedge, MLoop **allloop, MPoly **allpoly,
1228
int *totloop, int *totpoly)
1207
int BKE_mesh_nurbs_to_mdata(Object *ob, MVert **allvert, int *totvert,
1208
MEdge **alledge, int *totedge, MLoop **allloop, MPoly **allpoly,
1209
int *totloop, int *totpoly)
1230
return nurbs_to_mdata_customdb(ob, &ob->disp,
1211
return BKE_mesh_nurbs_displist_to_mdata(ob, &ob->disp,
1214
allloop, allpoly, NULL,
1237
1218
/* BMESH: this doesn't calculate all edges from polygons,
1238
1219
* only free standing edges are calculated */
1240
1221
/* Initialize mverts, medges and, faces for converting nurbs to mesh and derived mesh */
1241
/* use specified dispbase */
1242
int nurbs_to_mdata_customdb(Object *ob, ListBase *dispbase,
1243
MVert **allvert, int *_totvert,
1244
MEdge **alledge, int *_totedge,
1245
MLoop **allloop, MPoly **allpoly,
1246
int *_totloop, int *_totpoly)
1222
/* use specified dispbase */
1223
int BKE_mesh_nurbs_displist_to_mdata(Object *ob, ListBase *dispbase,
1224
MVert **allvert, int *_totvert,
1225
MEdge **alledge, int *_totedge,
1226
MLoop **allloop, MPoly **allpoly,
1228
int *_totloop, int *_totpoly)
1235
MLoopUV *mloopuv = NULL;
1255
int a, b, ofs, vertcount, startvert, totvert=0, totedge=0, totloop=0, totvlak=0;
1238
int a, b, ofs, vertcount, startvert, totvert = 0, totedge = 0, totloop = 0, totvlak = 0;
1256
1239
int p1, p2, p3, p4, *index;
1261
conv_polys|= cu->flag & CU_3D; /* 2d polys are filled with DL_INDEX3 displists */
1262
conv_polys|= ob->type == OB_SURF; /* surf polys are never filled */
1244
conv_polys |= cu->flag & CU_3D; /* 2d polys are filled with DL_INDEX3 displists */
1245
conv_polys |= ob->type == OB_SURF; /* surf polys are never filled */
1265
dl= dispbase->first;
1248
dl = dispbase->first;
1267
if (dl->type==DL_SEGM) {
1268
totvert+= dl->parts*dl->nr;
1269
totedge+= dl->parts*(dl->nr-1);
1250
if (dl->type == DL_SEGM) {
1251
totvert += dl->parts * dl->nr;
1252
totedge += dl->parts * (dl->nr - 1);
1271
else if (dl->type==DL_POLY) {
1254
else if (dl->type == DL_POLY) {
1272
1255
if (conv_polys) {
1273
totvert+= dl->parts*dl->nr;
1274
totedge+= dl->parts*dl->nr;
1256
totvert += dl->parts * dl->nr;
1257
totedge += dl->parts * dl->nr;
1277
else if (dl->type==DL_SURF) {
1260
else if (dl->type == DL_SURF) {
1279
totvert+= dl->parts*dl->nr;
1280
tot = (dl->parts-1+((dl->flag & DL_CYCL_V)==2))*(dl->nr-1+(dl->flag & DL_CYCL_U));
1262
totvert += dl->parts * dl->nr;
1263
tot = (dl->parts - 1 + ((dl->flag & DL_CYCL_V) == 2)) * (dl->nr - 1 + (dl->flag & DL_CYCL_U));
1281
1264
totvlak += tot;
1282
1265
totloop += tot * 4;
1284
else if (dl->type==DL_INDEX3) {
1267
else if (dl->type == DL_INDEX3) {
1287
1270
tot = dl->parts;
1289
1272
totloop += tot * 3;
1295
1278
/* error("can't convert"); */
1296
1279
/* Make Sure you check ob->data is a curve */
1335
else if (dl->type==DL_POLY) {
1321
else if (dl->type == DL_POLY) {
1336
1322
if (conv_polys) {
1337
startvert= vertcount;
1338
a= dl->parts*dl->nr;
1323
startvert = vertcount;
1324
a = dl->parts * dl->nr;
1341
1327
copy_v3_v3(mvert->co, data);
1347
for (a=0; a<dl->parts; a++) {
1349
for (b=0; b<dl->nr; b++) {
1350
medge->v1= startvert+ofs+b;
1351
if (b==dl->nr-1) medge->v2= startvert+ofs;
1352
else medge->v2= startvert+ofs+b+1;
1333
for (a = 0; a < dl->parts; a++) {
1335
for (b = 0; b < dl->nr; b++) {
1336
medge->v1 = startvert + ofs + b;
1337
if (b == dl->nr - 1) medge->v2 = startvert + ofs;
1338
else medge->v2 = startvert + ofs + b + 1;
1353
1339
medge->flag = ME_LOOSEEDGE | ME_EDGERENDER | ME_EDGEDRAW;
1359
else if (dl->type==DL_INDEX3) {
1360
startvert= vertcount;
1345
else if (dl->type == DL_INDEX3) {
1346
startvert = vertcount;
1364
1350
copy_v3_v3(mvert->co, data);
1373
mloop[0].v = startvert+index[0];
1374
mloop[1].v = startvert+index[2];
1375
mloop[2].v = startvert+index[1];
1359
mloop[0].v = startvert + index[0];
1360
mloop[1].v = startvert + index[2];
1361
mloop[2].v = startvert + index[1];
1376
1362
mpoly->loopstart = (int)(mloop - (*allloop));
1377
1363
mpoly->totloop = 3;
1378
1364
mpoly->mat_nr = dl->col;
1369
for (i = 0; i < 3; i++, mloopuv++) {
1370
mloopuv->uv[0] = (mloop[i].v - startvert) / (float)(dl->nr - 1);
1371
mloopuv->uv[1] = 0.0f;
1380
1375
if (smooth) mpoly->flag |= ME_SMOOTH;
1388
else if (dl->type==DL_SURF) {
1389
startvert= vertcount;
1390
a= dl->parts*dl->nr;
1381
else if (dl->type == DL_SURF) {
1382
startvert = vertcount;
1383
a = dl->parts * dl->nr;
1393
1386
copy_v3_v3(mvert->co, data);
1399
for (a=0; a<dl->parts; a++) {
1401
if ( (dl->flag & DL_CYCL_V)==0 && a==dl->parts-1) break;
1403
if (dl->flag & DL_CYCL_U) { /* p2 -> p1 -> */
1404
p1= startvert+ dl->nr*a; /* p4 -> p3 -> */
1405
p2= p1+ dl->nr-1; /* -----> next row */
1392
for (a = 0; a < dl->parts; a++) {
1394
if ( (dl->flag & DL_CYCL_V) == 0 && a == dl->parts - 1) break;
1396
if (dl->flag & DL_CYCL_U) { /* p2 -> p1 -> */
1397
p1 = startvert + dl->nr * a; /* p4 -> p3 -> */
1398
p2 = p1 + dl->nr - 1; /* -----> next row */
1411
p2= startvert+ dl->nr*a;
1404
p2 = startvert + dl->nr * a;
1417
if ( (dl->flag & DL_CYCL_V) && a==dl->parts-1) {
1418
p3-= dl->parts*dl->nr;
1419
p4-= dl->parts*dl->nr;
1410
if ( (dl->flag & DL_CYCL_V) && a == dl->parts - 1) {
1411
p3 -= dl->parts * dl->nr;
1412
p4 -= dl->parts * dl->nr;
1422
for (; b<dl->nr; b++) {
1415
for (; b < dl->nr; b++) {
1427
1420
mpoly->loopstart = (int)(mloop - (*allloop));
1428
1421
mpoly->totloop = 4;
1429
1422
mpoly->mat_nr = dl->col;
1425
int orco_sizeu = dl->nr - 1;
1426
int orco_sizev = dl->parts - 1;
1429
/* exception as handled in convertblender.c too */
1430
if (dl->flag & DL_CYCL_U) {
1432
if (dl->flag & DL_CYCL_V)
1436
for (i = 0; i < 4; i++, mloopuv++) {
1437
/* find uv based on vertex index into grid array */
1438
int v = mloop[i].v - startvert;
1440
mloopuv->uv[0] = (v / dl->nr) / (float)orco_sizev;
1441
mloopuv->uv[1] = (v % dl->nr) / (float)orco_sizeu;
1443
/* cyclic correction */
1444
if ((i == 0 || i == 1) && mloopuv->uv[1] == 0.0f)
1445
mloopuv->uv[1] = 1.0f;
1431
1449
if (smooth) mpoly->flag |= ME_SMOOTH;
1464
*_totpoly = totvlak;
1465
*_totloop = totloop;
1466
*_totedge = totedge;
1467
*_totvert = totvert;
1452
1469
/* not uded for bmesh */
1461
1479
/* this may fail replacing ob->data, be sure to check ob->type */
1462
void nurbs_to_mesh(Object *ob)
1480
void BKE_mesh_from_nurbs_displist(Object *ob, ListBase *dispbase, int use_orco_uv)
1464
Main *bmain= G.main;
1482
Main *bmain = G.main;
1466
DerivedMesh *dm= ob->derivedFinal;
1484
DerivedMesh *dm = ob->derivedFinal;
1469
MVert *allvert= NULL;
1470
MEdge *alledge= NULL;
1487
MVert *allvert = NULL;
1488
MEdge *alledge = NULL;
1471
1489
MLoop *allloop = NULL;
1490
MLoopUV *alluv = NULL;
1472
1491
MPoly *allpoly = NULL;
1473
1492
int totvert, totedge, totloop, totpoly;
1477
1496
if (dm == NULL) {
1478
if (nurbs_to_mdata(ob, &allvert, &totvert, &alledge, &totedge, &allloop, &allpoly, &totloop, &totpoly) != 0) {
1497
if (BKE_mesh_nurbs_displist_to_mdata(ob, dispbase, &allvert, &totvert,
1498
&alledge, &totedge, &allloop,
1499
&allpoly, (use_orco_uv) ? &alluv : NULL,
1500
&totloop, &totpoly) != 0)
1479
1502
/* Error initializing */
1483
1506
/* make mesh */
1484
me= add_mesh("Mesh");
1485
me->totvert= totvert;
1486
me->totedge= totedge;
1507
me = BKE_mesh_add(G.main, "Mesh");
1508
me->totvert = totvert;
1509
me->totedge = totedge;
1487
1510
me->totloop = totloop;
1488
1511
me->totpoly = totpoly;
1490
me->mvert= CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, allvert, me->totvert);
1491
me->medge= CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, alledge, me->totedge);
1492
me->mloop= CustomData_add_layer(&me->ldata, CD_MLOOP, CD_ASSIGN, allloop, me->totloop);
1493
me->mpoly= CustomData_add_layer(&me->pdata, CD_MPOLY, CD_ASSIGN, allpoly, me->totpoly);
1495
mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL);
1513
me->mvert = CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, allvert, me->totvert);
1514
me->medge = CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, alledge, me->totedge);
1515
me->mloop = CustomData_add_layer(&me->ldata, CD_MLOOP, CD_ASSIGN, allloop, me->totloop);
1516
me->mpoly = CustomData_add_layer(&me->pdata, CD_MPOLY, CD_ASSIGN, allpoly, me->totpoly);
1519
const char *uvname = "Orco";
1520
me->mtpoly = CustomData_add_layer_named(&me->pdata, CD_MTEXPOLY, CD_DEFAULT, NULL, me->totpoly, uvname);
1521
me->mloopuv = CustomData_add_layer_named(&me->ldata, CD_MLOOPUV, CD_ASSIGN, alluv, me->totloop, uvname);
1524
BKE_mesh_calc_normals(me->mvert, me->totvert, me->mloop, me->mpoly, me->totloop, me->totpoly, NULL);
1497
1526
BKE_mesh_calc_edges(me, TRUE);
1500
me= add_mesh("Mesh");
1529
me = BKE_mesh_add(G.main, "Mesh");
1501
1530
DM_to_mesh(dm, me, ob);
1504
me->totcol= cu->totcol;
1533
me->totcol = cu->totcol;
1536
BKE_mesh_texspace_calc(me);
1512
1541
if (ob->data) {
1513
free_libblock(&bmain->curve, ob->data);
1542
BKE_libblock_free(&bmain->curve, ob->data);
1518
1547
/* other users */
1519
ob1= bmain->object.first;
1548
ob1 = bmain->object.first;
1521
if (ob1->data==cu) {
1550
if (ob1->data == cu) {
1551
ob1->type = OB_MESH;
1524
ob1->data= ob->data;
1553
ob1->data = ob->data;
1525
1554
id_us_plus((ID *)ob->data);
1560
void BKE_mesh_from_nurbs(Object *ob)
1562
BKE_mesh_from_nurbs_displist(ob, &ob->disp, false);
1531
1565
typedef struct EdgeLink {
1532
1566
Link *next, *prev;
1541
1575
static void prependPolyLineVert(ListBase *lb, unsigned int index)
1543
VertLink *vl= MEM_callocN(sizeof(VertLink), "VertLink");
1577
VertLink *vl = MEM_callocN(sizeof(VertLink), "VertLink");
1544
1578
vl->index = index;
1545
1579
BLI_addhead(lb, vl);
1548
1582
static void appendPolyLineVert(ListBase *lb, unsigned int index)
1550
VertLink *vl= MEM_callocN(sizeof(VertLink), "VertLink");
1584
VertLink *vl = MEM_callocN(sizeof(VertLink), "VertLink");
1551
1585
vl->index = index;
1552
1586
BLI_addtail(lb, vl);
1555
void mesh_to_curve(Scene *scene, Object *ob)
1589
void BKE_mesh_from_curve(Scene *scene, Object *ob)
1557
1591
/* make new mesh data from the original copy */
1558
DerivedMesh *dm= mesh_get_derived_final(scene, ob, CD_MASK_MESH);
1592
DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_MESH);
1560
MVert *mverts= dm->getVertArray(dm);
1561
MEdge *med, *medge= dm->getEdgeArray(dm);
1562
MFace *mf, *mface= dm->getTessFaceArray(dm);
1594
MVert *mverts = dm->getVertArray(dm);
1595
MEdge *med, *medge = dm->getEdgeArray(dm);
1596
MFace *mf, *mface = dm->getTessFaceArray(dm);
1564
1598
int totedge = dm->getNumEdges(dm);
1565
1599
int totface = dm->getNumTessFaces(dm);
1617
1651
ListBase polyline = {NULL, NULL}; /* store a list of VertLink's */
1618
1652
int closed = FALSE;
1620
MEdge *med_current= ((EdgeLink *)edges.last)->edge;
1621
unsigned int startVert= med_current->v1;
1622
unsigned int endVert= med_current->v2;
1654
MEdge *med_current = ((EdgeLink *)edges.last)->edge;
1655
unsigned int startVert = med_current->v1;
1656
unsigned int endVert = med_current->v2;
1625
appendPolyLineVert(&polyline, startVert); totpoly++;
1626
appendPolyLineVert(&polyline, endVert); totpoly++;
1627
BLI_freelinkN(&edges, edges.last); totedges--;
1659
appendPolyLineVert(&polyline, startVert); totpoly++;
1660
appendPolyLineVert(&polyline, endVert); totpoly++;
1661
BLI_freelinkN(&edges, edges.last); totedges--;
1629
1663
while (ok) { /* while connected edges are found... */
1636
edl= BLI_findlink(&edges, i);
1670
edl = BLI_findlink(&edges, i);
1639
if (med->v1==endVert) {
1673
if (med->v1 == endVert) {
1640
1674
endVert = med->v2;
1641
appendPolyLineVert(&polyline, med->v2); totpoly++;
1642
BLI_freelinkN(&edges, edl); totedges--;
1675
appendPolyLineVert(&polyline, med->v2); totpoly++;
1676
BLI_freelinkN(&edges, edl); totedges--;
1645
else if (med->v2==endVert) {
1679
else if (med->v2 == endVert) {
1646
1680
endVert = med->v1;
1647
appendPolyLineVert(&polyline, endVert); totpoly++;
1648
BLI_freelinkN(&edges, edl); totedges--;
1681
appendPolyLineVert(&polyline, endVert); totpoly++;
1682
BLI_freelinkN(&edges, edl); totedges--;
1651
else if (med->v1==startVert) {
1685
else if (med->v1 == startVert) {
1652
1686
startVert = med->v2;
1653
prependPolyLineVert(&polyline, startVert); totpoly++;
1654
BLI_freelinkN(&edges, edl); totedges--;
1687
prependPolyLineVert(&polyline, startVert); totpoly++;
1688
BLI_freelinkN(&edges, edl); totedges--;
1657
else if (med->v2==startVert) {
1691
else if (med->v2 == startVert) {
1658
1692
startVert = med->v1;
1659
prependPolyLineVert(&polyline, startVert); totpoly++;
1660
BLI_freelinkN(&edges, edl); totedges--;
1693
prependPolyLineVert(&polyline, startVert); totpoly++;
1694
BLI_freelinkN(&edges, edl); totedges--;
1666
1700
/* Now we have a polyline, make into a curve */
1667
if (startVert==endVert) {
1701
if (startVert == endVert) {
1668
1702
BLI_freelinkN(&polyline, polyline.last);
1719
1753
/* curve object could have got bounding box only in special cases */
1721
1755
MEM_freeN(ob->bb);
1727
void mesh_delete_material_index(Mesh *me, short index)
1761
void BKE_mesh_delete_material_index(Mesh *me, short index)
1731
for (i=0; i<me->totpoly; i++) {
1732
MPoly *mp = &((MPoly*) me->mpoly)[i];
1733
if (mp->mat_nr && mp->mat_nr>=index)
1765
for (i = 0; i < me->totpoly; i++) {
1766
MPoly *mp = &((MPoly *) me->mpoly)[i];
1767
if (mp->mat_nr && mp->mat_nr >= index)
1737
for (i=0; i<me->totface; i++) {
1738
MFace *mf = &((MFace*) me->mface)[i];
1739
if (mf->mat_nr && mf->mat_nr>=index)
1771
for (i = 0; i < me->totface; i++) {
1772
MFace *mf = &((MFace *) me->mface)[i];
1773
if (mf->mat_nr && mf->mat_nr >= index)
1744
void mesh_set_smooth_flag(Object *meshOb, int enableSmooth)
1778
void BKE_mesh_smooth_flag_set(Object *meshOb, int enableSmooth)
1746
1780
Mesh *me = meshOb->data;
1749
for (i=0; i<me->totpoly; i++) {
1750
MPoly *mp = &((MPoly*) me->mpoly)[i];
1783
for (i = 0; i < me->totpoly; i++) {
1784
MPoly *mp = &((MPoly *) me->mpoly)[i];
1752
1786
if (enableSmooth) {
1753
1787
mp->flag |= ME_SMOOTH;
1772
void mesh_calc_normals_mapping(MVert *mverts, int numVerts,
1773
MLoop *mloop, MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3],
1774
MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3])
1806
void BKE_mesh_calc_normals_mapping(MVert *mverts, int numVerts,
1807
MLoop *mloop, MPoly *mpolys, int numLoops, int numPolys, float (*polyNors_r)[3],
1808
MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3])
1776
mesh_calc_normals_mapping_ex(mverts, numVerts, mloop, mpolys,
1777
numLoops, numPolys, polyNors_r, mfaces, numFaces,
1778
origIndexFace, faceNors_r, FALSE);
1810
BKE_mesh_calc_normals_mapping_ex(mverts, numVerts, mloop, mpolys,
1811
numLoops, numPolys, polyNors_r, mfaces, numFaces,
1812
origIndexFace, faceNors_r, FALSE);
1781
void mesh_calc_normals_mapping_ex(MVert *mverts, int numVerts,
1782
MLoop *mloop, MPoly *mpolys,
1783
int numLoops, int numPolys, float (*polyNors_r)[3],
1784
MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3],
1785
const short only_face_normals)
1815
void BKE_mesh_calc_normals_mapping_ex(MVert *mverts, int numVerts,
1816
MLoop *mloop, MPoly *mpolys,
1817
int numLoops, int numPolys, float (*polyNors_r)[3],
1818
MFace *mfaces, int numFaces, int *origIndexFace, float (*faceNors_r)[3],
1819
const short only_face_normals)
1787
1821
float (*pnors)[3] = polyNors_r, (*fnors)[3] = faceNors_r;
1806
1840
if (only_face_normals == FALSE) {
1807
1841
/* vertex normals are optional, they require some extra calculations,
1808
1842
* so make them optional */
1809
mesh_calc_normals(mverts, numVerts, mloop, mpolys, numLoops, numPolys, pnors);
1843
BKE_mesh_calc_normals(mverts, numVerts, mloop, mpolys, numLoops, numPolys, pnors);
1812
1846
/* only calc poly normals */
1814
for (i=0; i<numPolys; i++, mp++) {
1815
mesh_calc_poly_normal(mp, mloop+mp->loopstart, mverts, pnors[i]);
1848
for (i = 0; i < numPolys; i++, mp++) {
1849
BKE_mesh_calc_poly_normal(mp, mloop + mp->loopstart, mverts, pnors[i]);
1819
if ( origIndexFace &&
1820
/* fnors==faceNors_r */ /* NO NEED TO ALLOC YET */
1853
if (origIndexFace &&
1854
/* fnors == faceNors_r */ /* NO NEED TO ALLOC YET */
1825
for (i=0; i<numFaces; i++, mf++, origIndexFace++) {
1859
for (i = 0; i < numFaces; i++, mf++, origIndexFace++) {
1826
1860
if (*origIndexFace < numPolys) {
1827
1861
copy_v3_v3(fnors[i], pnors[*origIndexFace]);
1830
1864
/* eek, we're not corresponding to polys */
1831
printf("error in mesh_calc_normals; tessellation face indices are incorrect. normals may look bad.\n");
1865
printf("error in BKE_mesh_calc_normals; tessellation face indices are incorrect. normals may look bad.\n");
1858
1892
if (!pnors) pnors = MEM_callocN(sizeof(float) * 3 * numPolys, "poly_nors mesh.c");
1860
/*first go through and calculate normals for all the polys*/
1861
tnorms = MEM_callocN(sizeof(float)*3*numVerts, "tnorms mesh.c");
1894
/* first go through and calculate normals for all the polys */
1895
tnorms = MEM_callocN(sizeof(float) * 3 * numVerts, "tnorms mesh.c");
1864
for (i=0; i<numPolys; i++, mp++) {
1865
mesh_calc_poly_normal(mp, mloop+mp->loopstart, mverts, pnors[i]);
1898
for (i = 0; i < numPolys; i++, mp++) {
1899
BKE_mesh_calc_poly_normal(mp, mloop + mp->loopstart, mverts, pnors[i]);
1866
1900
ml = mloop + mp->loopstart;
1868
1902
BLI_array_empty(vertcos);
1869
1903
BLI_array_empty(vertnos);
1870
BLI_array_growitems(vertcos, mp->totloop);
1871
BLI_array_growitems(vertnos, mp->totloop);
1904
BLI_array_grow_items(vertcos, mp->totloop);
1905
BLI_array_grow_items(vertnos, mp->totloop);
1873
for (j=0; j < mp->totloop; j++) {
1907
for (j = 0; j < mp->totloop; j++) {
1874
1908
int vindex = ml[j].v;
1875
1909
vertcos[j] = mverts[vindex].co;
1876
1910
vertnos[j] = tnorms[vindex];
1879
1913
BLI_array_empty(edgevecbuf);
1880
BLI_array_growitems(edgevecbuf, mp->totloop);
1914
BLI_array_grow_items(edgevecbuf, mp->totloop);
1882
1916
accumulate_vertex_normals_poly(vertnos, pnors[i], vertcos, edgevecbuf, mp->totloop);
1902
1937
if (pnors != polyNors_r) MEM_freeN(pnors);
1905
void mesh_calc_normals_tessface(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, float (*faceNors_r)[3])
1940
void BKE_mesh_calc_normals_tessface(MVert *mverts, int numVerts, MFace *mfaces, int numFaces, float (*faceNors_r)[3])
1907
float (*tnorms)[3]= MEM_callocN(numVerts*sizeof(*tnorms), "tnorms");
1908
float (*fnors)[3]= (faceNors_r)? faceNors_r: MEM_callocN(sizeof(*fnors)*numFaces, "meshnormals");
1942
float (*tnorms)[3] = MEM_callocN(numVerts * sizeof(*tnorms), "tnorms");
1943
float (*fnors)[3] = (faceNors_r) ? faceNors_r : MEM_callocN(sizeof(*fnors) * numFaces, "meshnormals");
1911
for (i=0; i<numFaces; i++) {
1912
MFace *mf= &mfaces[i];
1913
float *f_no= fnors[i];
1914
float *n4 = (mf->v4)? tnorms[mf->v4]: NULL;
1915
float *c4 = (mf->v4)? mverts[mf->v4].co: NULL;
1946
for (i = 0; i < numFaces; i++) {
1947
MFace *mf = &mfaces[i];
1948
float *f_no = fnors[i];
1949
float *n4 = (mf->v4) ? tnorms[mf->v4] : NULL;
1950
float *c4 = (mf->v4) ? mverts[mf->v4].co : NULL;
1918
1953
normal_quad_v3(f_no, mverts[mf->v1].co, mverts[mf->v2].co, mverts[mf->v3].co, mverts[mf->v4].co);
1954
mf = me->mface + findex;
1956
for (i=0; i < numTex; i++) {
1957
texface = CustomData_get_n(&me->fdata, CD_MTFACE, findex, i);
1958
texpoly = CustomData_get_n(&me->pdata, CD_MTEXPOLY, findex, i);
1990
mf = mface + findex;
1992
for (i = 0; i < numTex; i++) {
1993
texface = CustomData_get_n(fdata, CD_MTFACE, findex, i);
1994
texpoly = CustomData_get_n(pdata, CD_MTEXPOLY, findex, i);
1960
1996
ME_MTEXFACE_CPY(texpoly, texface);
1962
mloopuv = CustomData_get_n(&me->ldata, CD_MLOOPUV, loopstart, i);
1998
mloopuv = CustomData_get_n(ldata, CD_MLOOPUV, loopstart, i);
1963
1999
copy_v2_v2(mloopuv->uv, texface->uv[0]); mloopuv++;
1964
2000
copy_v2_v2(mloopuv->uv, texface->uv[1]); mloopuv++;
1965
2001
copy_v2_v2(mloopuv->uv, texface->uv[2]); mloopuv++;
1980
2016
MESH_MLOOPCOL_FROM_MCOL(mloopcol, &mcol[3]); mloopcol++;
1984
if (CustomData_has_layer(&me->fdata, CD_MDISPS)) {
1985
MDisps *ld = CustomData_get(&me->ldata, loopstart, CD_MDISPS);
1986
MDisps *fd = CustomData_get(&me->fdata, findex, CD_MDISPS);
2020
if (CustomData_has_layer(fdata, CD_MDISPS)) {
2021
MDisps *ld = CustomData_get(ldata, loopstart, CD_MDISPS);
2022
MDisps *fd = CustomData_get(fdata, findex, CD_MDISPS);
1987
2023
float (*disps)[3] = fd->disps;
1988
int i, tot = mf->v4 ? 4 : 3;
2024
int tot = mf->v4 ? 4 : 3;
1989
2025
int side, corners;
1991
if (CustomData_external_test(&me->fdata, CD_MDISPS)) {
1992
CustomData_external_add(&me->ldata, &me->id, CD_MDISPS,
1993
me->totloop, me->fdata.external->filename);
2027
if (CustomData_external_test(fdata, CD_MDISPS)) {
2028
if (id && fdata->external) {
2029
CustomData_external_add(ldata, id, CD_MDISPS,
2030
totloop, fdata->external->filename);
1996
2034
corners = multires_mdisp_corners(fd);
1998
2036
if (corners == 0) {
1999
2037
/* Empty MDisp layers appear in at least one of the sintel.blend files.
2000
2038
* Not sure why this happens, but it seems fine to just ignore them here.
2001
* If corners==0 for a non-empty layer though, something went wrong. */
2039
* If (corners == 0) for a non-empty layer though, something went wrong. */
2002
2040
BLI_assert(fd->totdisp == 0);
2005
2043
side = sqrt(fd->totdisp / corners);
2007
for (i=0; i<tot; i++, disps += side*side, ld++) {
2008
ld->totdisp = side*side;
2009
ld->level = (int)(logf(side - 1.0f) / M_LN2) + 1;
2045
for (i = 0; i < tot; i++, disps += side * side, ld++) {
2046
ld->totdisp = side * side;
2047
ld->level = (int)(logf(side - 1.0f) / (float)M_LN2) + 1;
2012
2050
MEM_freeN(ld->disps);
2014
ld->disps = MEM_callocN(sizeof(float)*3*side*side, "converted loop mdisps");
2052
ld->disps = MEM_callocN(sizeof(float) * 3 * side * side, "converted loop mdisps");
2015
2053
if (fd->disps) {
2016
memcpy(ld->disps, disps, sizeof(float)*3*side*side);
2054
memcpy(ld->disps, disps, sizeof(float) * 3 * side * side);
2023
2061
void BKE_mesh_convert_mfaces_to_mpolys(Mesh *mesh)
2063
BKE_mesh_convert_mfaces_to_mpolys_ex(&mesh->id, &mesh->fdata, &mesh->ldata, &mesh->pdata,
2064
mesh->totedge, mesh->totface, mesh->totloop, mesh->totpoly,
2065
mesh->medge, mesh->mface,
2066
&mesh->totloop, &mesh->totpoly, &mesh->mloop, &mesh->mpoly);
2068
mesh_update_customdata_pointers(mesh, TRUE);
2071
/* the same as BKE_mesh_convert_mfaces_to_mpolys but oriented to be used in do_versions from readfile.c
2072
* the difference is how active/render/clone/stencil indices are handled here
2074
* normally thay're being set from pdata which totally makes sense for meshes which are already
2075
* converted to bmesh structures, but when loading older files indices shall be updated in other
2076
* way around, so newly added pdata and ldata would have this indices set based on fdata layer
2078
* this is normally only needed when reading older files, in all other cases BKE_mesh_convert_mfaces_to_mpolys
2079
* shall be always used
2081
void BKE_mesh_do_versions_convert_mfaces_to_mpolys(Mesh *mesh)
2083
BKE_mesh_convert_mfaces_to_mpolys_ex(&mesh->id, &mesh->fdata, &mesh->ldata, &mesh->pdata,
2084
mesh->totedge, mesh->totface, mesh->totloop, mesh->totpoly,
2085
mesh->medge, mesh->mface,
2086
&mesh->totloop, &mesh->totpoly, &mesh->mloop, &mesh->mpoly);
2088
CustomData_bmesh_do_versions_update_active_layers(&mesh->fdata, &mesh->pdata, &mesh->ldata);
2090
mesh_update_customdata_pointers(mesh, TRUE);
2093
void BKE_mesh_convert_mfaces_to_mpolys_ex(ID *id, CustomData *fdata, CustomData *ldata, CustomData *pdata,
2094
int totedge_i, int totface_i, int totloop_i, int totpoly_i,
2095
MEdge *medge, MFace *mface,
2096
int *totloop_r, int *totpoly_r,
2097
MLoop **mloop_r, MPoly **mpoly_r)
2030
2104
int numTex, numCol;
2105
int i, j, totloop, totpoly, *polyindex;
2033
2107
/* just in case some of these layers are filled in (can happen with python created meshes) */
2034
CustomData_free(&mesh->ldata, mesh->totloop);
2035
CustomData_free(&mesh->pdata, mesh->totpoly);
2036
memset(&mesh->ldata, 0, sizeof(mesh->ldata));
2037
memset(&mesh->pdata, 0, sizeof(mesh->pdata));
2039
mesh->totpoly = mesh->totface;
2040
mesh->mpoly = MEM_callocN(sizeof(MPoly)*mesh->totpoly, "mpoly converted");
2041
CustomData_add_layer(&mesh->pdata, CD_MPOLY, CD_ASSIGN, mesh->mpoly, mesh->totpoly);
2043
numTex = CustomData_number_of_layers(&mesh->fdata, CD_MTFACE);
2044
numCol = CustomData_number_of_layers(&mesh->fdata, CD_MCOL);
2108
CustomData_free(ldata, totloop_i);
2109
CustomData_free(pdata, totpoly_i);
2111
totpoly = totface_i;
2112
mpoly = MEM_callocN(sizeof(MPoly) * totpoly, "mpoly converted");
2113
CustomData_add_layer(pdata, CD_MPOLY, CD_ASSIGN, mpoly, totpoly);
2115
numTex = CustomData_number_of_layers(fdata, CD_MTFACE);
2116
numCol = CustomData_number_of_layers(fdata, CD_MCOL);
2048
for (i=0; i<mesh->totface; i++, mf++) {
2120
for (i = 0; i < totface_i; i++, mf++) {
2049
2121
totloop += mf->v4 ? 4 : 3;
2052
mesh->totloop = totloop;
2053
mesh->mloop = MEM_callocN(sizeof(MLoop)*mesh->totloop, "mloop converted");
2055
CustomData_add_layer(&mesh->ldata, CD_MLOOP, CD_ASSIGN, mesh->mloop, totloop);
2056
CustomData_to_bmeshpoly(&mesh->fdata, &mesh->pdata, &mesh->ldata,
2057
mesh->totloop, mesh->totpoly);
2059
/* ensure external data is transferred */
2060
CustomData_external_read(&mesh->fdata, &mesh->id, CD_MASK_MDISPS, mesh->totface);
2124
mloop = MEM_callocN(sizeof(MLoop) * totloop, "mloop converted");
2126
CustomData_add_layer(ldata, CD_MLOOP, CD_ASSIGN, mloop, totloop);
2128
CustomData_to_bmeshpoly(fdata, pdata, ldata, totloop, totpoly);
2131
/* ensure external data is transferred */
2132
CustomData_external_read(fdata, id, CD_MASK_MDISPS, totface_i);
2062
2135
eh = BLI_edgehash_new();
2066
for (i = 0; i < mesh->totedge; i++, me++) {
2137
/* build edge hash */
2139
for (i = 0; i < totedge_i; i++, me++) {
2067
2140
BLI_edgehash_insert(eh, me->v1, me->v2, SET_INT_IN_POINTER(i));
2069
2142
/* unrelated but avoid having the FGON flag enabled, so we can reuse it later for something else */
2070
2143
me->flag &= ~ME_FGON;
2073
j = 0; /*current loop index*/
2077
for (i=0; i<mesh->totface; i++, mf++, mp++) {
2146
polyindex = CustomData_get_layer(fdata, CD_ORIGINDEX);
2148
j = 0; /* current loop index */
2152
for (i = 0; i < totface_i; i++, mf++, mp++) {
2078
2153
mp->loopstart = j;
2080
2155
mp->totloop = mf->v4 ? 4 : 3;
2082
2157
mp->mat_nr = mf->mat_nr;
2083
2158
mp->flag = mf->flag;
2085
# define ML(v1, v2) {ml->v = mf->v1; ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v1, mf->v2)); ml++; j++;}
2160
# define ML(v1, v2) { \
2161
ml->v = mf->v1; ml->e = GET_INT_FROM_POINTER(BLI_edgehash_lookup(eh, mf->v1, mf->v2)); ml++; j++; \
2099
bm_corners_to_loops(mesh, i, mp->loopstart, numTex, numCol);
2176
bm_corners_to_loops_ex(id, fdata, ldata, pdata, mface, totloop, i, mp->loopstart, numTex, numCol);
2102
/* note, we don't convert FGons at all, these are not even real ngons,
2184
/* note, we don't convert NGons at all, these are not even real ngons,
2103
2185
* they have their own UV's, colors etc - its more an editing feature. */
2105
mesh_update_customdata_pointers(mesh, TRUE);
2107
2187
BLI_edgehash_free(eh, NULL);
2189
*totpoly_r = totpoly;
2190
*totloop_r = totloop;
2110
float (*mesh_getVertexCos(Mesh *me, int *numVerts_r))[3]
2195
float (*mesh_getVertexCos(Mesh * me, int *numVerts_r))[3]
2112
2197
int i, numVerts = me->totvert;
2113
float (*cos)[3] = MEM_mallocN(sizeof(*cos)*numVerts, "vertexcos1");
2198
float (*cos)[3] = MEM_mallocN(sizeof(*cos) * numVerts, "vertexcos1");
2115
2200
if (numVerts_r) *numVerts_r = numVerts;
2116
for (i=0; i<numVerts; i++)
2201
for (i = 0; i < numVerts; i++)
2117
2202
copy_v3_v3(cos[i], me->mvert[i].co);
2124
2209
/* this replaces the non bmesh function (in trunk) which takes MTFace's, if we ever need it back we could
2125
2210
* but for now this replaces it because its unused. */
2127
UvVertMap *make_uv_vert_map(struct MPoly *mpoly, struct MLoop *mloop, struct MLoopUV *mloopuv, unsigned int totpoly, unsigned int totvert, int selected, float *limit)
2212
UvVertMap *BKE_mesh_uv_vert_map_make(struct MPoly *mpoly, struct MLoop *mloop, struct MLoopUV *mloopuv, unsigned int totpoly, unsigned int totvert, int selected, float *limit)
2129
2214
UvVertMap *vmap;
2130
2215
UvMapVert *buf;
2132
2217
unsigned int a;
2133
int i, totuv, nverts;
2218
int i, totuv, nverts;
2137
2222
/* generate UvMapVert array */
2139
for (a=0; a<totpoly; a++, mp++)
2224
for (a = 0; a < totpoly; a++, mp++)
2140
2225
if (!selected || (!(mp->flag & ME_HIDE) && (mp->flag & ME_FACE_SEL)))
2141
2226
totuv += mp->totloop;
2146
vmap= (UvVertMap*)MEM_callocN(sizeof(*vmap), "UvVertMap");
2231
vmap = (UvVertMap *)MEM_callocN(sizeof(*vmap), "UvVertMap");
2150
vmap->vert= (UvMapVert**)MEM_callocN(sizeof(*vmap->vert)*totvert, "UvMapVert*");
2151
buf= vmap->buf= (UvMapVert*)MEM_callocN(sizeof(*vmap->buf)*totuv, "UvMapVert");
2235
vmap->vert = (UvMapVert **)MEM_callocN(sizeof(*vmap->vert) * totvert, "UvMapVert*");
2236
buf = vmap->buf = (UvMapVert *)MEM_callocN(sizeof(*vmap->buf) * totuv, "UvMapVert");
2153
2238
if (!vmap->vert || !vmap->buf) {
2154
free_uv_vert_map(vmap);
2239
BKE_mesh_uv_vert_map_free(vmap);
2159
for (a=0; a<totpoly; a++, mp++) {
2244
for (a = 0; a < totpoly; a++, mp++) {
2160
2245
if (!selected || (!(mp->flag & ME_HIDE) && (mp->flag & ME_FACE_SEL))) {
2161
nverts= mp->totloop;
2246
nverts = mp->totloop;
2163
for (i=0; i<nverts; i++) {
2248
for (i = 0; i < nverts; i++) {
2166
2251
buf->separate = 0;
2167
buf->next= vmap->vert[mloop[mp->loopstart + i].v];
2168
vmap->vert[mloop[mp->loopstart + i].v]= buf;
2252
buf->next = vmap->vert[mloop[mp->loopstart + i].v];
2253
vmap->vert[mloop[mp->loopstart + i].v] = buf;
2174
2259
/* sort individual uvs for each vert */
2175
for (a=0; a<totvert; a++) {
2176
UvMapVert *newvlist= NULL, *vlist=vmap->vert[a];
2260
for (a = 0; a < totvert; a++) {
2261
UvMapVert *newvlist = NULL, *vlist = vmap->vert[a];
2177
2262
UvMapVert *iterv, *v, *lastv, *next;
2178
2263
float *uv, *uv2, uvdiff[2];
2180
2265
while (vlist) {
2267
vlist = vlist->next;
2186
uv= mloopuv[mpoly[v->f].loopstart + v->tfindex].uv;
2271
uv = mloopuv[mpoly[v->f].loopstart + v->tfindex].uv;
2190
2275
while (iterv) {
2193
uv2= mloopuv[mpoly[iterv->f].loopstart + iterv->tfindex].uv;
2278
uv2 = mloopuv[mpoly[iterv->f].loopstart + iterv->tfindex].uv;
2194
2279
sub_v2_v2v2(uvdiff, uv2, uv);
2197
if (fabsf(uv[0]-uv2[0]) < limit[0] && fabsf(uv[1]-uv2[1]) < limit[1]) {
2198
if (lastv) lastv->next= next;
2200
iterv->next= newvlist;
2282
if (fabsf(uv[0] - uv2[0]) < limit[0] && fabsf(uv[1] - uv2[1]) < limit[1]) {
2283
if (lastv) lastv->next = next;
2285
iterv->next = newvlist;
2209
2294
newvlist->separate = 1;
2212
vmap->vert[a]= newvlist;
2297
vmap->vert[a] = newvlist;
2218
UvMapVert *get_uv_map_vert(UvVertMap *vmap, unsigned int v)
2303
UvMapVert *BKE_mesh_uv_vert_map_get_vert(UvVertMap *vmap, unsigned int v)
2220
2305
return vmap->vert[v];
2223
void free_uv_vert_map(UvVertMap *vmap)
2308
void BKE_mesh_uv_vert_map_free(UvVertMap *vmap)
2226
2311
if (vmap->vert) MEM_freeN(vmap->vert);
2276
2361
/* Generates a map where the key is the vertex and the value is a list
2277
2362
* of edges that use that vertex as an endpoint. The lists are allocated
2278
2363
* from one memory pool. */
2279
void create_vert_edge_map(ListBase **map, IndexNode **mem, const MEdge *medge, const int totvert, const int totedge)
2364
void create_vert_edge_map(MeshElemMap **map, int **mem,
2365
const MEdge *medge, int totvert, int totedge)
2282
IndexNode *node = NULL;
2284
(*map) = MEM_callocN(sizeof(ListBase) * totvert, "vert edge map");
2285
(*mem) = MEM_callocN(sizeof(IndexNode) * totedge * 2, "vert edge map mem");
2369
(*map) = MEM_callocN(sizeof(MeshElemMap) * totvert, "vert-edge map");
2370
(*mem) = MEM_mallocN(sizeof(int) * totedge * 2, "vert-edge map mem");
2372
/* Count number of edges for each vertex */
2373
for (i = 0; i < totedge; i++) {
2374
(*map)[medge[i].v1].count++;
2375
(*map)[medge[i].v2].count++;
2378
/* Assign indices mem */
2380
for (i = 0; i < totvert; i++) {
2381
(*map)[i].indices = indices;
2382
indices += (*map)[i].count;
2384
/* Reset 'count' for use as index in last loop */
2385
(*map)[i].count = 0;
2288
2388
/* Find the users */
2289
for (i = 0; i < totedge; ++i) {
2290
for (j = 0; j < 2; ++j, ++node) {
2292
BLI_addtail(&(*map)[((unsigned int*)(&medge[i].v1))[j]], node);
2389
for (i = 0; i < totedge; i++) {
2390
const int v[2] = {medge[i].v1, medge[i].v2};
2392
(*map)[v[0]].indices[(*map)[v[0]].count] = i;
2393
(*map)[v[1]].indices[(*map)[v[1]].count] = i;
2395
(*map)[v[0]].count++;
2396
(*map)[v[1]].count++;
2297
void mesh_loops_to_mface_corners(CustomData *fdata, CustomData *ldata,
2298
CustomData *pdata, int lindex[4], int findex,
2299
const int polyindex,
2300
const int mf_len, /* 3 or 4 */
2400
void BKE_mesh_loops_to_mface_corners(CustomData *fdata, CustomData *ldata,
2401
CustomData *pdata, int lindex[4], int findex,
2402
const int polyindex,
2403
const int mf_len, /* 3 or 4 */
2302
/* cache values to avoid lookups every time */
2303
const int numTex, /* CustomData_number_of_layers(pdata, CD_MTEXPOLY) */
2304
const int numCol, /* CustomData_number_of_layers(ldata, CD_MLOOPCOL) */
2305
const int hasPCol, /* CustomData_has_layer(ldata, CD_PREVIEW_MLOOPCOL) */
2306
const int hasOrigSpace /* CustomData_has_layer(ldata, CD_ORIGSPACE_MLOOP) */
2405
/* cache values to avoid lookups every time */
2406
const int numTex, /* CustomData_number_of_layers(pdata, CD_MTEXPOLY) */
2407
const int numCol, /* CustomData_number_of_layers(ldata, CD_MLOOPCOL) */
2408
const int hasPCol, /* CustomData_has_layer(ldata, CD_PREVIEW_MLOOPCOL) */
2409
const int hasOrigSpace /* CustomData_has_layer(ldata, CD_ORIGSPACE_MLOOP) */
2309
2412
MTFace *texface;
2310
2413
MTexPoly *texpoly;
2313
2416
MLoopUV *mloopuv;
2316
for (i=0; i < numTex; i++) {
2419
for (i = 0; i < numTex; i++) {
2317
2420
texface = CustomData_get_n(fdata, CD_MTFACE, findex, i);
2318
2421
texpoly = CustomData_get_n(pdata, CD_MTEXPOLY, polyindex, i);
2320
2423
ME_MTEXFACE_CPY(texface, texpoly);
2322
for (j=0; j < mf_len; j++) {
2425
for (j = 0; j < mf_len; j++) {
2323
2426
mloopuv = CustomData_get_n(ldata, CD_MLOOPUV, lindex[j], i);
2324
2427
copy_v2_v2(texface->uv[j], mloopuv->uv);
2328
for (i=0; i < numCol; i++) {
2431
for (i = 0; i < numCol; i++) {
2329
2432
mcol = CustomData_get_n(fdata, CD_MCOL, findex, i);
2331
for (j=0; j < mf_len; j++) {
2434
for (j = 0; j < mf_len; j++) {
2332
2435
mloopcol = CustomData_get_n(ldata, CD_MLOOPCOL, lindex[j], i);
2333
2436
MESH_MLOOPCOL_TO_MCOL(mloopcol, &mcol[j]);
2358
2461
* this function recreates a tessellation.
2359
2462
* returns number of tessellation faces.
2361
int mesh_recalcTessellation(CustomData *fdata,
2362
CustomData *ldata, CustomData *pdata,
2363
MVert *mvert, int totface, int UNUSED(totloop),
2365
/* when tessellating to recalculate normals after
2366
* we can skip copying here */
2367
const int do_face_nor_cpy)
2464
int BKE_mesh_recalc_tessellation(CustomData *fdata,
2465
CustomData *ldata, CustomData *pdata,
2466
MVert *mvert, int totface, int totloop,
2468
/* when tessellating to recalculate normals after
2469
* we can skip copying here */
2470
const int do_face_nor_cpy)
2369
2472
/* use this to avoid locking pthread for _every_ polygon
2370
2473
* and calling the fill function */
2372
2475
#define USE_TESSFACE_SPEEDUP
2373
2476
#define USE_TESSFACE_QUADS // NEEDS FURTHER TESTING
2375
#define TESSFACE_SCANFILL (1<<0)
2376
#define TESSFACE_IS_QUAD (1<<1)
2478
#define TESSFACE_SCANFILL (1 << 0)
2479
#define TESSFACE_IS_QUAD (1 << 1)
2481
const int looptris_tot = poly_to_tri_count(totpoly, totloop);
2378
2483
MPoly *mp, *mpoly;
2379
2484
MLoop *ml, *mloop;
2380
MFace *mface = NULL, *mf;
2381
BLI_array_declare(mface);
2382
2486
ScanFillContext sf_ctx;
2383
ScanFillVert *v, *lastv, *firstv;
2385
int *mface_orig_index = NULL;
2386
BLI_array_declare(mface_orig_index);
2387
int *mface_to_poly_map = NULL;
2388
BLI_array_declare(mface_to_poly_map);
2487
ScanFillVert *sf_vert, *sf_vert_last, *sf_vert_first;
2488
ScanFillFace *sf_tri;
2489
int *mface_to_poly_map;
2389
2490
int lindex[4]; /* only ever use 3 in this case */
2390
int *poly_orig_index;
2391
2491
int poly_index, j, mface_index;
2393
2493
const int numTex = CustomData_number_of_layers(pdata, CD_MTEXPOLY);
2474
2563
ml = mloop + mp->loopstart;
2476
BLI_begin_edgefill(&sf_ctx);
2479
for (j=0; j<mp->totloop; j++, ml++) {
2480
v = BLI_addfillvert(&sf_ctx, mvert[ml->v].co);
2482
v->keyindex = mp->loopstart + j;
2485
BLI_addfilledge(&sf_ctx, lastv, v);
2565
BLI_scanfill_begin(&sf_ctx);
2566
sf_vert_first = NULL;
2567
sf_vert_last = NULL;
2568
for (j = 0; j < mp->totloop; j++, ml++) {
2569
sf_vert = BLI_scanfill_vert_add(&sf_ctx, mvert[ml->v].co);
2571
sf_vert->keyindex = mp->loopstart + j;
2574
BLI_scanfill_edge_add(&sf_ctx, sf_vert_last, sf_vert);
2577
sf_vert_first = sf_vert;
2578
sf_vert_last = sf_vert;
2491
BLI_addfilledge(&sf_ctx, lastv, firstv);
2580
BLI_scanfill_edge_add(&sf_ctx, sf_vert_last, sf_vert_first);
2493
totfilltri = BLI_edgefill(&sf_ctx, FALSE);
2495
BLI_array_growitems(mface_to_poly_map, totfilltri);
2496
BLI_array_growitems(mface, totfilltri);
2497
if (poly_orig_index) {
2498
BLI_array_growitems(mface_orig_index, totfilltri);
2501
for (f = sf_ctx.fillfacebase.first; f; f = f->next, mf++) {
2502
mface_to_poly_map[mface_index] = poly_index;
2503
mf= &mface[mface_index];
2505
/* set loop indices, transformed to vert indices later */
2506
mf->v1 = f->v1->keyindex;
2507
mf->v2 = f->v2->keyindex;
2508
mf->v3 = f->v3->keyindex;
2511
mf->mat_nr = mp->mat_nr;
2512
mf->flag = mp->flag;
2582
totfilltri = BLI_scanfill_calc(&sf_ctx, 0);
2583
BLI_assert(totfilltri <= mp->totloop - 2);
2586
for (sf_tri = sf_ctx.fillfacebase.first; sf_tri; sf_tri = sf_tri->next, mf++) {
2587
mface_to_poly_map[mface_index] = poly_index;
2588
mf = &mface[mface_index];
2590
/* set loop indices, transformed to vert indices later */
2591
mf->v1 = sf_tri->v1->keyindex;
2592
mf->v2 = sf_tri->v2->keyindex;
2593
mf->v3 = sf_tri->v3->keyindex;
2596
mf->mat_nr = mp->mat_nr;
2597
mf->flag = mp->flag;
2514
2599
#ifdef USE_TESSFACE_SPEEDUP
2515
mf->edcode |= TESSFACE_SCANFILL; /* tag for sorting loop indices */
2600
mf->edcode = TESSFACE_SCANFILL; /* tag for sorting loop indices */
2518
if (poly_orig_index) {
2519
mface_orig_index[mface_index] = poly_orig_index[poly_index];
2526
BLI_end_edgefill(&sf_ctx);
2606
BLI_scanfill_end(&sf_ctx);
2530
2610
CustomData_free(fdata, totface);
2531
memset(fdata, 0, sizeof(CustomData));
2532
2611
totface = mface_index;
2613
BLI_assert(totface <= looptris_tot);
2535
2615
/* not essential but without this we store over-alloc'd memory in the CustomData layers */
2536
if (LIKELY((MEM_allocN_len(mface) / sizeof(*mface)) != totface)) {
2616
if (LIKELY(looptris_tot != totface)) {
2537
2617
mface = MEM_reallocN(mface, sizeof(*mface) * totface);
2538
2618
mface_to_poly_map = MEM_reallocN(mface_to_poly_map, sizeof(*mface_to_poly_map) * totface);
2539
if (mface_orig_index) {
2540
mface_orig_index = MEM_reallocN(mface_orig_index, sizeof(*mface_orig_index) * totface);
2544
2621
CustomData_add_layer(fdata, CD_MFACE, CD_ASSIGN, mface, totface);
2546
/* CD_POLYINDEX will contain an array of indices from tessfaces to the polygons
2623
/* CD_ORIGINDEX will contain an array of indices from tessfaces to the polygons
2547
2624
* they are directly tessellated from */
2548
CustomData_add_layer(fdata, CD_POLYINDEX, CD_ASSIGN, mface_to_poly_map, totface);
2549
if (mface_orig_index) {
2550
/* If polys had a CD_ORIGINDEX layer, then the tessellated faces will get this
2551
* layer as well, pointing to polys from the original mesh (not the polys
2552
* that just got tessellated) */
2553
CustomData_add_layer(fdata, CD_ORIGINDEX, CD_ASSIGN, mface_orig_index, totface);
2625
CustomData_add_layer(fdata, CD_ORIGINDEX, CD_ASSIGN, mface_to_poly_map, totface);
2556
2626
CustomData_from_bmeshpoly(fdata, pdata, ldata, totface);
2558
2628
if (do_face_nor_cpy) {
2582
2652
/* sort loop indices to ensure winding is correct */
2583
if (mf->v1 > mf->v2) SWAP(int, mf->v1, mf->v2);
2584
if (mf->v2 > mf->v3) SWAP(int, mf->v2, mf->v3);
2585
if (mf->v1 > mf->v2) SWAP(int, mf->v1, mf->v2);
2653
if (mf->v1 > mf->v2) SWAP(unsigned int, mf->v1, mf->v2);
2654
if (mf->v2 > mf->v3) SWAP(unsigned int, mf->v2, mf->v3);
2655
if (mf->v1 > mf->v2) SWAP(unsigned int, mf->v1, mf->v2);
2587
if (mf->v1 > mf->v2) SWAP(int, mf->v1, mf->v2);
2588
if (mf->v2 > mf->v3) SWAP(int, mf->v2, mf->v3);
2589
if (mf->v1 > mf->v2) SWAP(int, mf->v1, mf->v2);
2657
if (mf->v1 > mf->v2) SWAP(unsigned int, mf->v1, mf->v2);
2658
if (mf->v2 > mf->v3) SWAP(unsigned int, mf->v2, mf->v3);
2659
if (mf->v1 > mf->v2) SWAP(unsigned int, mf->v1, mf->v2);
2592
2662
/* end abusing the edcode */
2758
2827
static void mesh_calc_ngon_normal(MPoly *mpoly, MLoop *loopstart,
2759
2828
MVert *mvert, float normal[3])
2762
MVert *v1, *v2, *v3;
2763
double u[3], v[3], w[3];
2764
double n[3] = {0.0, 0.0, 0.0}, l;
2830
const int nverts = mpoly->totloop;
2831
float const *v_prev = mvert[loopstart[nverts - 1].v].co;
2832
float const *v_curr;
2767
for (i = 0; i < mpoly->totloop; i++) {
2768
v1 = mvert + loopstart[i].v;
2769
v2 = mvert + loopstart[(i+1)%mpoly->totloop].v;
2770
v3 = mvert + loopstart[(i+2)%mpoly->totloop].v;
2772
copy_v3db_v3fl(u, v1->co);
2773
copy_v3db_v3fl(v, v2->co);
2774
copy_v3db_v3fl(w, v3->co);
2776
/*this fixes some weird numerical error*/
2786
* (a[1] - b[1]) * (a[2] + b[2]);
2787
* a[1]*b[2] - b[1]*a[2] - b[1]*b[2] + a[1]*a[2]
2789
* odd. half of that is the cross product. . .what's the
2792
* also could be like a[1]*(b[2] + a[2]) - b[1]*(a[2] - b[2])
2795
n[0] += (u[1] - v[1]) * (u[2] + v[2]);
2796
n[1] += (u[2] - v[2]) * (u[0] + v[0]);
2797
n[2] += (u[0] - v[0]) * (u[1] + v[1]);
2800
l = n[0]*n[0]+n[1]*n[1]+n[2]*n[2];
2816
normal[0] = (float) n[0];
2817
normal[1] = (float) n[1];
2818
normal[2] = (float) n[2];
2837
/* Newell's Method */
2838
for (i = 0; i < nverts; i++) {
2839
v_curr = mvert[loopstart[i].v].co;
2840
add_newell_cross_v3_v3v3(normal, v_prev, v_curr);
2844
if (UNLIKELY(normalize_v3(normal) == 0.0f)) {
2845
normal[2] = 1.0f; /* other axis set to 0.0 */
2821
void mesh_calc_poly_normal(MPoly *mpoly, MLoop *loopstart,
2822
MVert *mvarray, float no[3])
2849
void BKE_mesh_calc_poly_normal(MPoly *mpoly, MLoop *loopstart,
2850
MVert *mvarray, float no[3])
2824
2852
if (mpoly->totloop > 4) {
2825
2853
mesh_calc_ngon_normal(mpoly, loopstart, mvarray, no);
2849
2877
static void mesh_calc_ngon_normal_coords(MPoly *mpoly, MLoop *loopstart,
2850
2878
const float (*vertex_coords)[3], float normal[3])
2853
const float *v1, *v2, *v3;
2854
double u[3], v[3], w[3];
2855
double n[3] = {0.0, 0.0, 0.0}, l;
2880
const int nverts = mpoly->totloop;
2881
float const *v_prev = vertex_coords[loopstart[nverts - 1].v];
2882
float const *v_curr;
2858
for (i = 0; i < mpoly->totloop; i++) {
2859
v1 = (const float *)(vertex_coords + loopstart[i].v);
2860
v2 = (const float *)(vertex_coords + loopstart[(i+1)%mpoly->totloop].v);
2861
v3 = (const float *)(vertex_coords + loopstart[(i+2)%mpoly->totloop].v);
2863
copy_v3db_v3fl(u, v1);
2864
copy_v3db_v3fl(v, v2);
2865
copy_v3db_v3fl(w, v3);
2867
/*this fixes some weird numerical error*/
2874
n[0] += (u[1] - v[1]) * (u[2] + v[2]);
2875
n[1] += (u[2] - v[2]) * (u[0] + v[0]);
2876
n[2] += (u[0] - v[0]) * (u[1] + v[1]);
2879
l = n[0]*n[0]+n[1]*n[1]+n[2]*n[2];
2897
normal[0] = (float) n[0];
2898
normal[1] = (float) n[1];
2899
normal[2] = (float) n[2];
2887
/* Newell's Method */
2888
for (i = 0; i < nverts; i++) {
2889
v_curr = vertex_coords[loopstart[i].v];
2890
add_newell_cross_v3_v3v3(normal, v_prev, v_curr);
2894
if (UNLIKELY(normalize_v3(normal) == 0.0f)) {
2895
normal[2] = 1.0f; /* other axis set to 0.0 */
2902
void mesh_calc_poly_normal_coords(MPoly *mpoly, MLoop *loopstart,
2903
const float (*vertex_coords)[3], float no[3])
2899
void BKE_mesh_calc_poly_normal_coords(MPoly *mpoly, MLoop *loopstart,
2900
const float (*vertex_coords)[3], float no[3])
2905
2902
if (mpoly->totloop > 4) {
2906
2903
mesh_calc_ngon_normal_coords(mpoly, loopstart, vertex_coords, no);
2995
2992
/* need normal for area_poly_v3 as well */
2996
2993
if (polynormal == NULL) {
2997
mesh_calc_poly_normal(mpoly, loopstart, mvarray, no);
2994
BKE_mesh_calc_poly_normal(mpoly, loopstart, mvarray, polynorm_local);
3000
2997
/* finally calculate the area */
3001
2998
area = area_poly_v3(mpoly->totloop, vertexcos, no);
3003
BLI_array_fixedstack_free(vertexcos);
3004
/* note, results won't be correct if polygon is non-planar */
3005
static float mesh_calc_poly_planar_area_centroid(MPoly *mpoly, MLoop *loopstart, MVert *mvarray, float cent[3])
3009
float total_area = 0.0f;
3010
float v1[3], v2[3], v3[3], normal[3], tri_cent[3];
3012
BKE_mesh_calc_poly_normal(mpoly, loopstart, mvarray, normal);
3013
copy_v3_v3(v1, mvarray[loopstart[0].v].co);
3014
copy_v3_v3(v2, mvarray[loopstart[1].v].co);
3017
for (i = 2; i < mpoly->totloop; i++) {
3018
copy_v3_v3(v3, mvarray[loopstart[i].v].co);
3020
tri_area = area_tri_signed_v3(v1, v2, v3, normal);
3021
total_area += tri_area;
3023
cent_tri_v3(tri_cent, v1, v2, v3);
3024
madd_v3_v3fl(cent, tri_cent, tri_area);
3029
mul_v3_fl(cent, 1.0f / total_area);
3035
* This function takes the difference between 2 vertex-coord-arrays
3036
* (\a vert_cos_src, \a vert_cos_dst),
3037
* and applies the difference to \a vert_cos_new relative to \a vert_cos_org.
3039
* \param vert_cos_src reference deform source.
3040
* \param vert_cos_dst reference deform destination.
3042
* \param vert_cos_org reference for the output location.
3043
* \param vert_cos_new resulting coords.
3045
void BKE_mesh_calc_relative_deform(
3046
const MPoly *mpoly, const int totpoly,
3047
const MLoop *mloop, const int totvert,
3049
const float (*vert_cos_src)[3],
3050
const float (*vert_cos_dst)[3],
3052
const float (*vert_cos_org)[3],
3053
float (*vert_cos_new)[3])
3058
int *vert_accum = MEM_callocN(sizeof(*vert_accum) * totvert, __func__);
3060
memset(vert_cos_new, '\0', sizeof(*vert_cos_new) * totvert);
3062
for (i = 0, mp = mpoly; i < totpoly; i++, mp++) {
3063
const MLoop *loopstart = mloop + mp->loopstart;
3066
for (j = 0; j < mp->totloop; j++) {
3067
int v_prev = (loopstart + ((mp->totloop + (j - 1)) % mp->totloop))->v;
3068
int v_curr = (loopstart + j)->v;
3069
int v_next = (loopstart + ((j + 1) % mp->totloop))->v;
3073
barycentric_transform(
3074
tvec, vert_cos_dst[v_curr],
3075
vert_cos_org[v_prev], vert_cos_org[v_curr], vert_cos_org[v_next],
3076
vert_cos_src[v_prev], vert_cos_src[v_curr], vert_cos_src[v_next]
3079
add_v3_v3(vert_cos_new[v_curr], tvec);
3080
vert_accum[v_curr] += 1;
3084
for (i = 0; i < totvert; i++) {
3085
if (vert_accum[i]) {
3086
mul_v3_fl(vert_cos_new[i], 1.0f / (float)vert_accum[i]);
3089
copy_v3_v3(vert_cos_new[i], vert_cos_org[i]);
3093
MEM_freeN(vert_accum);
3009
3096
/* Find the index of the loop in 'poly' which references vertex,
3010
3097
* returns -1 if not found */
3011
3098
int poly_find_loop_from_vert(const MPoly *poly, const MLoop *loopstart,
3015
3102
for (j = 0; j < poly->totloop; j++, loopstart++) {
3175
* simple poly -> vert/edge selection.
3177
void BKE_mesh_flush_select_from_polys_ex(MVert *mvert, const int totvert,
3179
MEdge *medge, const int totedge,
3180
const MPoly *mpoly, const int totpoly)
3188
for (mv = mvert; i--; mv++) {
3189
mv->flag &= ~SELECT;
3193
for (med = medge; i--; med++) {
3194
med->flag &= ~SELECT;
3198
for (mp = mpoly; i--; mp++) {
3199
/* assume if its selected its not hidden and none of its verts/edges are hidden
3200
* (a common assumption)*/
3201
if (mp->flag & ME_FACE_SEL) {
3205
for (ml = &mloop[mp->loopstart]; j--; ml++) {
3206
mvert[ml->v].flag |= SELECT;
3207
medge[ml->e].flag |= SELECT;
3212
void BKE_mesh_flush_select_from_polys(Mesh *me)
3214
BKE_mesh_flush_select_from_polys_ex(me->mvert, me->totvert,
3216
me->medge, me->totedge,
3217
me->mpoly, me->totpoly);
3220
void BKE_mesh_flush_select_from_verts_ex(const MVert *mvert, const int UNUSED(totvert),
3222
MEdge *medge, const int totedge,
3223
MPoly *mpoly, const int totpoly)
3231
for (med = medge; i--; med++) {
3232
if ((med->flag & ME_HIDE) == 0) {
3233
if ((mvert[med->v1].flag & SELECT) && (mvert[med->v2].flag & SELECT)) {
3234
med->flag |= SELECT;
3237
med->flag &= ~SELECT;
3244
for (mp = mpoly; i--; mp++) {
3245
if ((mp->flag & ME_HIDE) == 0) {
3250
for (ml = &mloop[mp->loopstart]; j--; ml++) {
3251
if ((mvert[ml->v].flag & SELECT) == 0) {
3258
mp->flag |= ME_FACE_SEL;
3261
mp->flag &= ~ME_FACE_SEL;
3266
void BKE_mesh_flush_select_from_verts(Mesh *me)
3268
BKE_mesh_flush_select_from_verts_ex(me->mvert, me->totvert,
3270
me->medge, me->totedge,
3271
me->mpoly, me->totpoly);
3072
3275
/* basic vertex data functions */
3073
int minmax_mesh(Mesh *me, float min[3], float max[3])
3276
int BKE_mesh_minmax(Mesh *me, float r_min[3], float r_max[3])
3278
int i = me->totvert;
3077
for (mvert= me->mvert; i--; mvert++) {
3078
DO_MINMAX(mvert->co, min, max);
3280
for (mvert = me->mvert; i--; mvert++) {
3281
minmax_v3v3_v3(r_min, r_max, mvert->co);
3081
3284
return (me->totvert != 0);
3084
int mesh_center_median(Mesh *me, float cent[3])
3287
int BKE_mesh_center_median(Mesh *me, float cent[3])
3289
int i = me->totvert;
3089
for (mvert= me->mvert; i--; mvert++) {
3292
for (mvert = me->mvert; i--; mvert++) {
3090
3293
add_v3_v3(cent, mvert->co);
3092
3295
/* otherwise we get NAN for 0 verts */
3093
3296
if (me->totvert) {
3094
mul_v3_fl(cent, 1.0f/(float)me->totvert);
3297
mul_v3_fl(cent, 1.0f / (float)me->totvert);
3097
3300
return (me->totvert != 0);
3100
int mesh_center_bounds(Mesh *me, float cent[3])
3303
int BKE_mesh_center_bounds(Mesh *me, float cent[3])
3102
3305
float min[3], max[3];
3103
3306
INIT_MINMAX(min, max);
3104
if (minmax_mesh(me, min, max)) {
3307
if (BKE_mesh_minmax(me, min, max)) {
3105
3308
mid_v3_v3v3(cent, min, max);
3112
void mesh_translate(Mesh *me, float offset[3], int do_keys)
3315
int BKE_mesh_center_centroid(Mesh *me, float cent[3])
3317
int i = me->totpoly;
3320
float total_area = 0.0f;
3325
/* calculate a weighted average of polygon centroids */
3326
for (mpoly = me->mpoly; i--; mpoly++) {
3327
poly_area = mesh_calc_poly_planar_area_centroid(mpoly, me->mloop + mpoly->loopstart, me->mvert, poly_cent);
3329
madd_v3_v3fl(cent, poly_cent, poly_area);
3330
total_area += poly_area;
3332
/* otherwise we get NAN for 0 polys */
3334
mul_v3_fl(cent, 1.0f / total_area);
3337
return (me->totpoly != 0);
3340
void BKE_mesh_translate(Mesh *me, float offset[3], int do_keys)
3342
int i = me->totvert;
3116
for (mvert= me->mvert; i--; mvert++) {
3344
for (mvert = me->mvert; i--; mvert++) {
3117
3345
add_v3_v3(mvert->co, offset);
3120
3348
if (do_keys && me->key) {
3122
for (kb=me->key->block.first; kb; kb=kb->next) {
3123
float *fp= kb->data;
3124
for (i= kb->totelem; i--; fp+=3) {
3350
for (kb = me->key->block.first; kb; kb = kb->next) {
3351
float *fp = kb->data;
3352
for (i = kb->totelem; i--; fp += 3) {
3125
3353
add_v3_v3(fp, offset);
3132
3359
void BKE_mesh_ensure_navmesh(Mesh *me)
3134
3361
if (!CustomData_has_layer(&me->pdata, CD_RECAST)) {
3136
3363
int numFaces = me->totpoly;
3137
3364
int *recastData;
3138
CustomData_add_layer_named(&me->pdata, CD_RECAST, CD_CALLOC, NULL, numFaces, "recastData");
3139
recastData = (int*)CustomData_get_layer(&me->pdata, CD_RECAST);
3140
for (i=0; i<numFaces; i++) {
3141
recastData[i] = i+1;
3365
recastData = (int *)MEM_mallocN(numFaces * sizeof(int), __func__);
3366
for (i = 0; i < numFaces; i++) {
3367
recastData[i] = i + 1;
3143
CustomData_add_layer_named(&me->pdata, CD_RECAST, CD_REFERENCE, recastData, numFaces, "recastData");
3369
CustomData_add_layer_named(&me->pdata, CD_RECAST, CD_ASSIGN, recastData, numFaces, "recastData");
3147
3373
void BKE_mesh_tessface_calc(Mesh *mesh)
3149
mesh->totface = mesh_recalcTessellation(&mesh->fdata, &mesh->ldata, &mesh->pdata,
3151
mesh->totface, mesh->totloop, mesh->totpoly,
3152
/* calc normals right after, don't copy from polys here */
3375
mesh->totface = BKE_mesh_recalc_tessellation(&mesh->fdata, &mesh->ldata, &mesh->pdata,
3377
mesh->totface, mesh->totloop, mesh->totpoly,
3378
/* calc normals right after, don't copy from polys here */
3155
3381
mesh_update_customdata_pointers(mesh, TRUE);
3167
3393
mesh_tessface_clear_intern(mesh, TRUE);
3396
#if 0 /* slow version of the function below */
3397
void BKE_mesh_poly_calc_angles(MVert *mvert, MLoop *mloop,
3398
MPoly *mp, float angles[])
3403
for (j = 0, ml = mloop + mp->loopstart; j < mp->totloop; j++, ml++) {
3404
MLoop *ml_prev = ME_POLY_LOOP_PREV(mloop, mp, j);
3405
MLoop *ml_next = ME_POLY_LOOP_NEXT(mloop, mp, j);
3409
sub_v3_v3v3(e1, mvert[ml_next->v].co, mvert[ml->v].co);
3410
sub_v3_v3v3(e2, mvert[ml_prev->v].co, mvert[ml->v].co);
3412
angles[j] = (float)M_PI - angle_v3v3(e1, e2);
3416
#else /* equivalent the function above but avoid multiple subtractions + normalize */
3418
void BKE_mesh_poly_calc_angles(MVert *mvert, MLoop *mloop,
3419
MPoly *mp, float angles[])
3421
MLoop *ml = mloop + mp->loopstart;
3425
int i_this = mp->totloop - 1;
3428
sub_v3_v3v3(nor_prev, mvert[ml[i_this - 1].v].co, mvert[ml[i_this].v].co);
3429
normalize_v3(nor_prev);
3431
while (i_next < mp->totloop) {
3432
sub_v3_v3v3(nor_next, mvert[ml[i_this].v].co, mvert[ml[i_next].v].co);
3433
normalize_v3(nor_next);
3434
angles[i_this] = angle_normalized_v3v3(nor_prev, nor_next);
3437
copy_v3_v3(nor_prev, nor_next);
3445
void BKE_mesh_do_versions_cd_flag_init(Mesh *mesh)
3447
if (UNLIKELY(mesh->cd_flag)) {
3455
for (mv = mesh->mvert, i = 0; i < mesh->totvert; mv++, i++) {
3456
if (mv->bweight != 0) {
3457
mesh->cd_flag |= ME_CDFLAG_VERT_BWEIGHT;
3462
for (med = mesh->medge, i = 0; i < mesh->totedge; med++, i++) {
3463
if (med->bweight != 0) {
3464
mesh->cd_flag |= ME_CDFLAG_EDGE_BWEIGHT;
3465
if (mesh->cd_flag & ME_CDFLAG_EDGE_CREASE) {
3469
if (med->crease != 0) {
3470
mesh->cd_flag |= ME_CDFLAG_EDGE_CREASE;
3471
if (mesh->cd_flag & ME_CDFLAG_EDGE_BWEIGHT) {