[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43869] branches/bmesh/blender/source/ blender/blenkernel: fix for crash converting a curve into a mesh ( Alt+C conversion), this would crash on entering editmode.
Campbell Barton
ideasman42 at gmail.com
Fri Feb 3 05:59:02 CET 2012
Revision: 43869
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43869
Author: campbellbarton
Date: 2012-02-03 04:58:55 +0000 (Fri, 03 Feb 2012)
Log Message:
-----------
fix for crash converting a curve into a mesh (Alt+C conversion), this would crash on entering editmode.
now curves convert to polygons directly, rather then faces, and polygons after.
Modified Paths:
--------------
branches/bmesh/blender/source/blender/blenkernel/BKE_mesh.h
branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c
branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c
Modified: branches/bmesh/blender/source/blender/blenkernel/BKE_mesh.h
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/BKE_mesh.h 2012-02-03 02:36:03 UTC (rev 43868)
+++ branches/bmesh/blender/source/blender/blenkernel/BKE_mesh.h 2012-02-03 04:58:55 UTC (rev 43869)
@@ -115,11 +115,11 @@
void set_mesh(struct Object *ob, struct Mesh *me);
void mball_to_mesh(struct ListBase *lb, struct Mesh *me);
int nurbs_to_mdata(struct Object *ob, struct MVert **allvert, int *totvert,
- struct MEdge **alledge, int *totedge, struct MFace **allface, struct MLoop **allloop, struct MPoly **allpoly,
- int *totface, int *totloop, int *totpoly);
+ struct MEdge **alledge, int *totedge, struct MLoop **allloop, struct MPoly **allpoly,
+ int *totloop, int *totpoly);
int nurbs_to_mdata_customdb(struct Object *ob, struct ListBase *dispbase, struct MVert **allvert, int *_totvert,
- struct MEdge **alledge, int *_totedge, struct MFace **allface, struct MLoop **allloop, struct MPoly **allpoly,
- int *_totface, int *_totloop, int *_totpoly);
+ struct MEdge **alledge, int *_totedge, struct MLoop **allloop, struct MPoly **allpoly,
+ int *_totloop, int *_totpoly);
void nurbs_to_mesh(struct Object *ob);
void mesh_to_curve(struct Scene *scene, struct Object *ob);
void free_dverts(struct MDeformVert *dvert, int totvert);
Modified: branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c 2012-02-03 02:36:03 UTC (rev 43868)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/cdderivedmesh.c 2012-02-03 04:58:55 UTC (rev 43869)
@@ -1879,34 +1879,33 @@
CDDerivedMesh *cddm;
MVert *allvert;
MEdge *alledge;
- MFace *allface;
MLoop *allloop;
MPoly *allpoly;
- int totvert, totedge, totface, totloop, totpoly;
+ int totvert, totedge, totloop, totpoly;
if (nurbs_to_mdata_customdb(ob, dispbase, &allvert, &totvert, &alledge,
- &totedge, &allface, &allloop, &allpoly, &totface, &totloop, &totpoly) != 0) {
+ &totedge, &allloop, &allpoly, &totloop, &totpoly) != 0) {
/* Error initializing mdata. This often happens when curve is empty */
return CDDM_new(0, 0, 0, 0, 0);
}
- dm = CDDM_new(totvert, totedge, totface, totloop, totpoly);
+ dm = CDDM_new(totvert, totedge, 0, totloop, totpoly);
dm->deformedOnly = 1;
cddm = (CDDerivedMesh*)dm;
memcpy(cddm->mvert, allvert, totvert*sizeof(MVert));
memcpy(cddm->medge, alledge, totedge*sizeof(MEdge));
- memcpy(cddm->mface, allface, totface*sizeof(MFace));
memcpy(cddm->mloop, allloop, totloop*sizeof(MLoop));
memcpy(cddm->mpoly, allpoly, totpoly*sizeof(MPoly));
MEM_freeN(allvert);
MEM_freeN(alledge);
- MEM_freeN(allface);
MEM_freeN(allloop);
MEM_freeN(allpoly);
+ CDDM_calc_edges(dm);
+
return dm;
}
Modified: branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c
===================================================================
--- branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c 2012-02-03 02:36:03 UTC (rev 43868)
+++ branches/bmesh/blender/source/blender/blenkernel/intern/mesh.c 2012-02-03 04:58:55 UTC (rev 43869)
@@ -883,6 +883,10 @@
return 0;
}
+
+/* TODO: remove after bmesh merge */
+#if 0
+
static void mfaces_strip_loose(MFace *mface, int *totface)
{
int a,b;
@@ -899,6 +903,8 @@
*totface= b;
}
+#endif
+
/* Create edges based on known verts and faces */
static void make_edges_mdata(MVert *UNUSED(allvert), MFace *allface, MLoop *allloop,
MPoly *allpoly, int UNUSED(totvert), int totface, int UNUSED(totloop), int totpoly,
@@ -1117,30 +1123,32 @@
/* Initialize mverts, medges and, faces for converting nurbs to mesh and derived mesh */
/* return non-zero on error */
int nurbs_to_mdata(Object *ob, MVert **allvert, int *totvert,
- MEdge **alledge, int *totedge, MFace **allface, MLoop **allloop, MPoly **allpoly,
- int *totface, int *totloop, int *totpoly)
+ MEdge **alledge, int *totedge, MLoop **allloop, MPoly **allpoly,
+ int *totloop, int *totpoly)
{
return nurbs_to_mdata_customdb(ob, &ob->disp,
- allvert, totvert, alledge, totedge, allface, allloop, allpoly, totface, totloop, totpoly);
+ allvert, totvert, alledge, totedge, allloop, allpoly, totloop, totpoly);
}
+/* BMESH: this doesn't calculate all edges from polygons,
+ * only free standing edges are calculated */
+
/* Initialize mverts, medges and, faces for converting nurbs to mesh and derived mesh */
/* use specified dispbase */
int nurbs_to_mdata_customdb(Object *ob, ListBase *dispbase, MVert **allvert, int *_totvert,
- MEdge **alledge, int *_totedge, MFace **allface, MLoop **allloop, MPoly **allpoly,
- int *_totface, int *_totloop, int *_totpoly)
+ MEdge **alledge, int *_totedge, MLoop **allloop, MPoly **allpoly,
+ int *_totloop, int *_totpoly)
{
DispList *dl;
Curve *cu;
MVert *mvert;
- MFace *mface;
MPoly *mpoly;
MLoop *mloop;
+ MEdge *medge;
float *data;
- int a, b, ofs, vertcount, startvert, totvert=0, totvlak=0;
+ int a, b, ofs, vertcount, startvert, totvert=0, totedge=0, totloop=0, totvlak=0;
int p1, p2, p3, p4, *index;
int conv_polys= 0;
- int i, j;
cu= ob->data;
@@ -1152,21 +1160,27 @@
while(dl) {
if(dl->type==DL_SEGM) {
totvert+= dl->parts*dl->nr;
- totvlak+= dl->parts*(dl->nr-1);
+ totedge+= dl->parts*(dl->nr-1);
}
else if(dl->type==DL_POLY) {
if(conv_polys) {
totvert+= dl->parts*dl->nr;
- totvlak+= dl->parts*dl->nr;
+ totedge+= dl->parts*dl->nr;
}
}
else if(dl->type==DL_SURF) {
+ int tot;
totvert+= dl->parts*dl->nr;
- totvlak+= (dl->parts-1+((dl->flag & DL_CYCL_V)==2))*(dl->nr-1+(dl->flag & DL_CYCL_U));
+ tot = (dl->parts-1+((dl->flag & DL_CYCL_V)==2))*(dl->nr-1+(dl->flag & DL_CYCL_U));
+ totvlak += tot;
+ totloop += tot * 4;
}
else if(dl->type==DL_INDEX3) {
+ int tot;
totvert+= dl->nr;
- totvlak+= dl->parts;
+ tot = dl->parts;
+ totvlak+= tot;
+ totloop += tot * 3;
}
dl= dl->next;
}
@@ -1177,10 +1191,10 @@
return -1;
}
- *allvert= mvert= MEM_callocN(sizeof (MVert) * totvert, "nurbs_init mvert");
- *allface= mface= MEM_callocN(sizeof (MFace) * totvlak, "nurbs_init mface");
- *allloop = mloop = MEM_callocN(sizeof(MLoop) * totvlak * 4, "nurbs_init mloop");
- *allpoly = mpoly = MEM_callocN(sizeof(MPoly) * totvlak * 4, "nurbs_init mloop");
+ *allvert = mvert = MEM_callocN(sizeof(MVert) * totvert, "nurbs_init mvert");
+ *alledge = medge = MEM_callocN(sizeof(MEdge) * totedge, "nurbs_init medge");
+ *allloop = mloop = MEM_callocN(sizeof(MLoop) * totvlak * 4, "nurbs_init mloop"); // totloop
+ *allpoly = mpoly = MEM_callocN(sizeof(MPoly) * totvlak, "nurbs_init mloop");
/* verts and faces */
vertcount= 0;
@@ -1203,10 +1217,11 @@
for(a=0; a<dl->parts; a++) {
ofs= a*dl->nr;
for(b=1; b<dl->nr; b++) {
- mface->v1= startvert+ofs+b-1;
- mface->v2= startvert+ofs+b;
- if(smooth) mface->flag |= ME_SMOOTH;
- mface++;
+ medge->v1= startvert+ofs+b-1;
+ medge->v2= startvert+ofs+b;
+ medge->flag = ME_LOOSEEDGE|ME_EDGERENDER;
+
+ medge++;
}
}
@@ -1226,11 +1241,11 @@
for(a=0; a<dl->parts; a++) {
ofs= a*dl->nr;
for(b=0; b<dl->nr; b++) {
- mface->v1= startvert+ofs+b;
- if(b==dl->nr-1) mface->v2= startvert+ofs;
- else mface->v2= startvert+ofs+b+1;
- if(smooth) mface->flag |= ME_SMOOTH;
- mface++;
+ medge->v1= startvert+ofs+b;
+ if(b==dl->nr-1) medge->v2= startvert+ofs;
+ else medge->v2= startvert+ofs+b+1;
+ medge->flag = ME_LOOSEEDGE|ME_EDGERENDER;
+ medge++;
}
}
}
@@ -1249,15 +1264,16 @@
a= dl->parts;
index= dl->index;
while(a--) {
- mface->v1= startvert+index[0];
- mface->v2= startvert+index[2];
- mface->v3= startvert+index[1];
- mface->v4= 0;
- mface->mat_nr= dl->col;
- test_index_face(mface, NULL, 0, 3);
+ mloop[0].v = startvert+index[0];
+ mloop[1].v = startvert+index[2];
+ mloop[2].v = startvert+index[1];
+ mpoly->loopstart = (int)(mloop - (*allloop));
+ mpoly->totloop = 3;
+ mpoly->mat_nr = dl->col;
- if(smooth) mface->flag |= ME_SMOOTH;
- mface++;
+ if(smooth) mpoly->flag |= ME_SMOOTH;
+ mpoly++;
+ mloop+= 3;
index+= 3;
}
@@ -1298,15 +1314,17 @@
}
for(; b<dl->nr; b++) {
- mface->v1= p1;
- mface->v2= p3;
- mface->v3= p4;
- mface->v4= p2;
- mface->mat_nr= dl->col;
- test_index_face(mface, NULL, 0, 4);
+ mloop[0].v= p1;
+ mloop[1].v= p3;
+ mloop[2].v= p4;
+ mloop[3].v= p2;
+ mpoly->loopstart = (int)(mloop - (*allloop));
+ mpoly->totloop = 4;
+ mpoly->mat_nr = dl->col;
- if(smooth) mface->flag |= ME_SMOOTH;
- mface++;
+ if(smooth) mpoly->flag |= ME_SMOOTH;
+ mpoly++;
+ mloop+= 4;
p4= p3;
p3++;
@@ -1320,35 +1338,16 @@
dl= dl->next;
}
- mface= *allface;
- j = 0;
- for (i=0; i<totvert; i++, mpoly++, mface++) {
- int k;
-
- if (!mface->v3) {
- mpoly--;
- i--;
- continue;
- }
-
- if (mface >= *allface + totvlak)
- break;
-
- mpoly->flag |= mface->flag & ME_SMOOTH;
- mpoly->loopstart= j;
- mpoly->totloop= mface->v4 ? 4 : 3;
- for (k=0; k<mpoly->totloop; k++, mloop++, j++) {
- mloop->v = (&mface->v1)[k];
- }
- }
-
- *_totpoly= i;
- *_totloop= j;
+ *_totpoly= totvlak;
+ *_totloop= totloop;
+ *_totedge= totedge;
*_totvert= totvert;
- *_totface= totvlak;
+ /* not uded for bmesh */
+#if 0
make_edges_mdata(*allvert, *allface, *allloop, *allpoly, totvert, totvlak, *_totloop, *_totpoly, 0, alledge, _totedge);
mfaces_strip_loose(*allface, _totface);
+#endif
return 0;
}
@@ -1363,15 +1362,14 @@
Curve *cu;
MVert *allvert= NULL;
MEdge *alledge= NULL;
- MFace *allface= NULL;
MLoop *allloop = NULL;
MPoly *allpoly = NULL;
- int totvert, totedge, totface, totloop, totpoly;
+ int totvert, totedge, totloop, totpoly;
cu= ob->data;
if (dm == NULL) {
- if (nurbs_to_mdata (ob, &allvert, &totvert, &alledge, &totedge, &allface, &allloop, &allpoly, &totface, &totloop, &totpoly) != 0) {
+ if (nurbs_to_mdata (ob, &allvert, &totvert, &alledge, &totedge, &allloop, &allpoly, &totloop, &totpoly) != 0) {
/* Error initializing */
return;
}
@@ -1379,18 +1377,18 @@
/* make mesh */
me= add_mesh("Mesh");
me->totvert= totvert;
- me->totface= totface;
me->totedge= totedge;
me->totloop = totloop;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list