- made make_edge mark edges with LOOSEEDGE appropriately
authorDaniel Dunbar <daniel@zuster.org>
Sat, 20 Aug 2005 09:16:09 +0000 (09:16 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Sat, 20 Aug 2005 09:16:09 +0000 (09:16 +0000)
 - added user settable defaultEdgeData (for auto edge creation
   in CCGSubSurf)
 - bug fix, possible crash on meshes with loose edges but
   in mface not in medge
 - missed file in last commit, for proper updating in image
   window

source/blender/blenkernel/intern/CCGSubSurf.c
source/blender/blenkernel/intern/CCGSubSurf.h
source/blender/blenkernel/intern/mesh.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/src/drawobject.c

index 75099157fd712752a557e257d906b0a6fbc0e950..dc6543858c17f54f6629a981b26e186cb6720922 100644 (file)
@@ -297,6 +297,7 @@ struct _CCGSubSurf {
        int numGrids;
        int allowEdgeCreation;
        float defaultCreaseValue;
+       void *defaultEdgeUserData;
 
        void *q, *r;
                
@@ -637,6 +638,7 @@ CCGSubSurf *ccgSubSurf_new(CCGMeshIFC *ifc, int subdivLevels, CCGAllocatorIFC *a
                ss->numGrids = 0;
                ss->allowEdgeCreation = 0;
                ss->defaultCreaseValue = 0;
+               ss->defaultEdgeUserData = NULL;
 
                ss->useAgeCounts = 0;
                ss->vertUserAgeOffset = ss->edgeUserAgeOffset = ss->faceUserAgeOffset = 0;
@@ -675,6 +677,7 @@ void ccgSubSurf_free(CCGSubSurf *ss) {
 
        CCGSUBSURF_free(ss, ss->r);
        CCGSUBSURF_free(ss, ss->q);
+       if (ss->defaultEdgeUserData) CCGSUBSURF_free(ss, ss->defaultEdgeUserData);
 
        _ehash_free(ss->fMap, (EHEntryFreeFP) _face_free, ss);
        _ehash_free(ss->eMap, (EHEntryFreeFP) _edge_free, ss);
@@ -687,15 +690,29 @@ void ccgSubSurf_free(CCGSubSurf *ss) {
        }
 }
 
-CCGError ccgSubSurf_setAllowEdgeCreation(CCGSubSurf *ss, int allowEdgeCreation, float defaultCreaseValue) {
+CCGError ccgSubSurf_setAllowEdgeCreation(CCGSubSurf *ss, int allowEdgeCreation, float defaultCreaseValue, void *defaultUserData) {
+       if (ss->defaultEdgeUserData) {
+               CCGSUBSURF_free(ss, ss->defaultEdgeUserData);
+       }
+
        ss->allowEdgeCreation = !!allowEdgeCreation;
        ss->defaultCreaseValue = defaultCreaseValue;
+       ss->defaultEdgeUserData = CCGSUBSURF_alloc(ss, ss->meshIFC.edgeUserSize);
+
+       if (defaultUserData) {
+               memcpy(ss->defaultEdgeUserData, defaultUserData, ss->meshIFC.edgeUserSize);
+       } else {
+               memset(ss->defaultEdgeUserData, 0, ss->meshIFC.edgeUserSize);
+       }
 
        return eCCGError_None;
 }
-void ccgSubSurf_getAllowEdgeCreation(CCGSubSurf *ss, int *allowEdgeCreation_r, float *defaultCreaseValue_r) {
+void ccgSubSurf_getAllowEdgeCreation(CCGSubSurf *ss, int *allowEdgeCreation_r, float *defaultCreaseValue_r, void *defaultUserData_r) {
        if (allowEdgeCreation_r) *allowEdgeCreation_r = ss->allowEdgeCreation;
-       if (defaultCreaseValue_r) *defaultCreaseValue_r = ss->defaultCreaseValue;
+       if (ss->allowEdgeCreation) {
+               if (defaultCreaseValue_r) *defaultCreaseValue_r = ss->defaultCreaseValue;
+               if (defaultUserData_r) memcpy(defaultUserData_r, ss->defaultEdgeUserData, ss->meshIFC.edgeUserSize);
+       }
 }
 
 CCGError ccgSubSurf_setSubdivisionLevels(CCGSubSurf *ss, int subdivisionLevels) {
@@ -1035,6 +1052,9 @@ CCGError ccgSubSurf_syncFace(CCGSubSurf *ss, CCGFaceHDL fHDL, int numVerts, CCGV
                                        _ehash_insert(ss->eMap, (EHEntry*) e);
                                        e->v0->flags |= Vert_eEffected;
                                        e->v1->flags |= Vert_eEffected;
+                                       if (ss->meshIFC.edgeUserSize) {
+                                               memcpy(ccgSubSurf_getEdgeUserData(ss, e), ss->defaultEdgeUserData, ss->meshIFC.edgeUserSize);
+                                       }
                                } else {
                                        return eCCGError_InvalidValue;
                                }
index f6469866d32512d17f2d0218d5ec5fadc0a22208..9f276989bc52bba40df8dc8ca78d0c66bcf1f7fc 100644 (file)
@@ -61,8 +61,8 @@ CCGError      ccgSubSurf_processSync  (CCGSubSurf *ss);
 
 CCGError       ccgSubSurf_setSubdivisionLevels         (CCGSubSurf *ss, int subdivisionLevels);
 
-CCGError       ccgSubSurf_setAllowEdgeCreation         (CCGSubSurf *ss, int allowEdgeCreation, float defaultCreaseValue);
-void           ccgSubSurf_getAllowEdgeCreation         (CCGSubSurf *ss, int *allowEdgeCreation_r, float *defaultCreaseValue_r);
+CCGError       ccgSubSurf_setAllowEdgeCreation         (CCGSubSurf *ss, int allowEdgeCreation, float defaultCreaseValue, void *defaultUserData);
+void           ccgSubSurf_getAllowEdgeCreation         (CCGSubSurf *ss, int *allowEdgeCreation_r, float *defaultCreaseValue_r, void *defaultUserData_r);
 
 void           ccgSubSurf_getUseAgeCounts                      (CCGSubSurf *ss, int *useAgeCounts_r, int *vertUserOffset_r, int *edgeUserOffset_r, int *faceUserOffset_r);
 CCGError       ccgSubSurf_setUseAgeCounts                      (CCGSubSurf *ss, int useAgeCounts, int vertUserOffset, int edgeUserOffset, int faceUserOffset);
index e1c1f337bb6cad93f452b41189779ac6f8adb360..b91b2356cc3d158eaf5f378bde32f3819cea6724 100644 (file)
@@ -597,10 +597,11 @@ void set_mesh(Object *ob, Mesh *me)
 struct edgesort {
        int v1, v2;
        int flag;
+       int is_loose;
 };
 
 /* edges have to be added with lowest index first for sorting */
-static void to_edgesort(struct edgesort *ed, int v1, int v2, int flag)
+static void to_edgesort(struct edgesort *ed, int v1, int v2, int flag, int is_loose)
 {
        if(v1<v2) {
                ed->v1= v1; ed->v2= v2;
@@ -609,6 +610,7 @@ static void to_edgesort(struct edgesort *ed, int v1, int v2, int flag)
                ed->v1= v2; ed->v2= v1;
        }
        ed->flag= flag;
+       ed->is_loose= is_loose;
 }
 
 static int vergedgesort(const void *v1, const void *v2)
@@ -649,21 +651,20 @@ void make_edges(Mesh *me)
        ed= edsort= MEM_mallocN(totedge*sizeof(struct edgesort), "edgesort");
        
        for(a= me->totface, mface= me->mface; a>0; a--, mface++) {
-               
-               to_edgesort(ed, mface->v1, mface->v2, mface->edcode & ME_V1V2);
+               to_edgesort(ed, mface->v1, mface->v2, mface->edcode & ME_V1V2, !mface->v3);
                ed++;
                if(mface->v4) {
-                       to_edgesort(ed, mface->v2, mface->v3, mface->edcode & ME_V2V3);
+                       to_edgesort(ed, mface->v2, mface->v3, mface->edcode & ME_V2V3, 0);
                        ed++;
-                       to_edgesort(ed, mface->v3, mface->v4, mface->edcode & ME_V3V4);
+                       to_edgesort(ed, mface->v3, mface->v4, mface->edcode & ME_V3V4, 0);
                        ed++;
-                       to_edgesort(ed, mface->v4, mface->v1, mface->edcode & ME_V4V1);
+                       to_edgesort(ed, mface->v4, mface->v1, mface->edcode & ME_V4V1, 0);
                        ed++;
                }
                else if(mface->v3) {
-                       to_edgesort(ed, mface->v2, mface->v3, mface->edcode & ME_V2V3);
+                       to_edgesort(ed, mface->v2, mface->v3, mface->edcode & ME_V2V3, 0);
                        ed++;
-                       to_edgesort(ed, mface->v3, mface->v1, mface->edcode & ME_V3V1);
+                       to_edgesort(ed, mface->v3, mface->v1, mface->edcode & ME_V3V1, 0);
                        ed++;
                }
        }
@@ -691,6 +692,7 @@ void make_edges(Mesh *me)
                        medge->v1= ed->v1;
                        medge->v2= ed->v2;
                        if(ed->flag) medge->flag= ME_EDGEDRAW;
+                       if(ed->is_loose) medge->flag|= ME_LOOSEEDGE;
                        medge->flag |= ME_EDGERENDER;
                        medge++;
                }
@@ -699,6 +701,7 @@ void make_edges(Mesh *me)
        medge->v1= ed->v1;
        medge->v2= ed->v2;
        if(ed->flag) medge->flag= ME_EDGEDRAW;
+       if(ed->is_loose) medge->flag|= ME_LOOSEEDGE;
        medge->flag |= ME_EDGERENDER;
 
        MEM_freeN(edsort);
index f324a046c5fc157649c2e6ca1a1ceba8aed2ca9f..dab0ddd5d8be87a1a1b1ec052e2e0daf7d451e3f 100644 (file)
@@ -137,7 +137,9 @@ static CCGSubSurf *_getSubSurf(CCGSubSurf *prevSS, int subdivLevels, int useAgin
                ccgSubSurf_setUseAgeCounts(ccgSS, 1, 8, 8, 8);
        }
        if (useEdgeCreation) {
-               ccgSubSurf_setAllowEdgeCreation(ccgSS, 1, useFlatSubdiv?subdivLevels:0.0f);
+               int defaultUserData[3] = {0, -1, 0};
+
+               ccgSubSurf_setAllowEdgeCreation(ccgSS, 1, useFlatSubdiv?subdivLevels:0.0f, defaultUserData);
        }
 
        ccgSubSurf_setCalcVertexNormals(ccgSS, 1, BLI_STRUCT_OFFSET(VertData, no));
@@ -218,7 +220,7 @@ static unsigned int ss_getEdgeFlags(CCGSubSurf *ss, CCGEdge *e, int ssFromEditme
                        if (!medge) {
                                makeFlags = 1;
                        }
-               } else {
+               } else if (medge) { // can happen for loose edges on mesh with no medge
                        MEdge *origMed = &medge[edgeIdx];
 
                        if (dlm) {
@@ -227,6 +229,8 @@ static unsigned int ss_getEdgeFlags(CCGSubSurf *ss, CCGEdge *e, int ssFromEditme
                                flags |= (origMed->flag&ME_SEAM);
                                makeFlags = 1;
                        }
+               } else {
+                       makeFlags = 1;
                }
                
                if (makeFlags) {
@@ -281,7 +285,7 @@ static DispListMesh *ss_to_displistmesh(CCGSubSurf *ss, CCGDerivedMesh *ccgdm, i
        CCGVert **vertMap2;
        int totvert, totedge, totface, useEdgeCreation;
        
-       ccgSubSurf_getAllowEdgeCreation(ss, &useEdgeCreation, NULL);
+       ccgSubSurf_getAllowEdgeCreation(ss, &useEdgeCreation, NULL, NULL);
 
        totvert = ccgSubSurf_getNumVerts(ss);
        vertMap2 = MEM_mallocN(totvert*sizeof(*vertMap2), "vertmap");
@@ -652,10 +656,13 @@ static void ss_sync_from_mesh(CCGSubSurf *ss, Mesh *me, DispListMesh *dlm, float
                }
        } else {
                for (i=0; i<totface; i++) {
+                       CCGEdge *e;
                        MFace *mf = &((MFace*) mface)[i];
 
                        if (!mf->v3) {
-                               ccgSubSurf_syncEdge(ss, (CCGEdgeHDL) i, (CCGVertHDL) mf->v1, (CCGVertHDL) mf->v2, useFlatSubdiv?creaseFactor:0.0f, NULL);
+                               ccgSubSurf_syncEdge(ss, (CCGEdgeHDL) i, (CCGVertHDL) mf->v1, (CCGVertHDL) mf->v2, useFlatSubdiv?creaseFactor:0.0f, &e);
+
+                               ((int*) ccgSubSurf_getEdgeUserData(ss, e))[1] = -1;
                        }
                }
        }
index 7e72f6f737f51d741709ae357cb0df4d05011fff..90898e96f254d2625c8232f5e97f35f6ed6914b5 100644 (file)
@@ -1790,7 +1790,7 @@ static void draw_mesh_fancy(Object *ob, DerivedMesh *baseDM, DerivedMesh *dm, in
                if (G.f & (G_VERTEXPAINT|G_WEIGHTPAINT|G_TEXTUREPAINT)) {
                        baseDM->drawEdges(baseDM, dt==OB_WIRE);
                } else {
-                       dm->drawEdges(dm, dt==OB_WIRE);
+                       dm->drawEdges(dm, (dt==OB_WIRE || me->totface==0));
                }
 
                if (dt!=OB_WIRE) {