- work-in-progress: subsurf level 0 now just acts like a regular mesh,
authorDaniel Dunbar <daniel@zuster.org>
Mon, 4 Apr 2005 03:38:21 +0000 (03:38 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Mon, 4 Apr 2005 03:38:21 +0000 (03:38 +0000)
   before it would follow subsurf code path by creating fake displistmesh,
   etc... kinda fun for testing but just annoying now.
 - change to creasing behavior, to make sure that with full creasing effect
   is just simple subdivision.

source/blender/blenkernel/BKE_subsurf.h
source/blender/blenkernel/intern/CCGSubSurf.c
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/mesh.c
source/blender/blenkernel/intern/subsurf.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/python/api2_2x/NMesh.c
source/blender/renderconverter/intern/convertBlenderScene.c

index 1dddec2da1f476b067d3e568561539525ac2ba36..6e2cd74d455cb7b709c140583c45f82b08dfa5d1 100644 (file)
@@ -39,9 +39,6 @@ struct EditMesh;
 struct DerivedMesh *subsurf_make_derived_from_editmesh(struct EditMesh *em, int subdivLevels, short type, struct DerivedMesh *oldDerived);
 struct DerivedMesh *subsurf_make_derived_from_mesh(struct Mesh *me, int subdivLevels);
 
-struct DerivedMesh *subsurf_ccg_make_derived_from_editmesh(struct EditMesh *em, int useFlatSubdiv, int subdivLevels, struct DerivedMesh *oldDerived);
-struct DerivedMesh *subsurf_ccg_make_derived_from_mesh(struct Mesh *me, int useFlatSubdiv, int subdivLevels);
-
 void subsurf_calculate_limit_positions(Mesh *me, float (*positions_r)[3]);
 
 #endif
index 2f6c95414e295b0bef3c5988801bd17871ddc91e..9dd5e7340c49b8fa5db13f34ce9b36f01d9d9855 100644 (file)
@@ -1131,7 +1131,7 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
                CCGVert *v = effectedV[ptrIdx];
                void *co = VERT_getCo(v, curLvl);
                void *nCo = VERT_getCo(v, nextLvl);
-               int sharpCount = 0;
+               int sharpCount = 0, allSharp = 1;
                float avgSharpness = 0.0;
 
                for (i=0; i<v->numEdges; i++) {
@@ -1141,6 +1141,8 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
                        if (sharpness!=0.0f) {
                                sharpCount++;
                                avgSharpness += sharpness;
+                       } else {
+                               allSharp = 0;
                        }
                }
 
@@ -1206,7 +1208,7 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
 
                        ss->meshIFC.vertDataMulN(ss->meshData, q, (float) 1/sharpCount);
 
-                       if (sharpCount!=2) {
+                       if (sharpCount!=2 || allSharp) {
                                        // q = q + (co-q)*avgSharpness
                                ss->meshIFC.vertDataCopy(ss->meshData, r, co);
                                ss->meshIFC.vertDataSub(ss->meshData, r, q);
@@ -1409,7 +1411,7 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
                        CCGVert *v = (CCGVert*) effectedV[ptrIdx];
                        void *co = VERT_getCo(v, curLvl);
                        void *nCo = VERT_getCo(v, nextLvl);
-                       int sharpCount = 0;
+                       int sharpCount = 0, allSharp = 1;
                        float avgSharpness = 0.0;
 
                        for (i=0; i<v->numEdges; i++) {
@@ -1419,6 +1421,8 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
                                if (sharpness!=0.0f) {
                                        sharpCount++;
                                        avgSharpness += sharpness;
+                               } else {
+                                       allSharp = 0;
                                }
                        }
 
@@ -1485,7 +1489,7 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
 
                                ss->meshIFC.vertDataMulN(ss->meshData, q, (float) 1/sharpCount);
 
-                               if (sharpCount!=2) {
+                               if (sharpCount!=2 || allSharp) {
                                                // q = q + (co-q)*avgSharpness
                                        ss->meshIFC.vertDataCopy(ss->meshData, r, co);
                                        ss->meshIFC.vertDataSub(ss->meshData, r, q);
index a0752a241e78e940277f5450e3bece7eb40ccb2e..566a6004a075a324307a27a0b1ae3b6f83a0126c 100644 (file)
@@ -969,7 +969,7 @@ static void build_mesh_data(Object *ob, int inEditMode)
                        if(eff->type==EFF_WAVE) makeDispList(ob);
                }
        }
-       if(mesh_uses_displist(me)) {
+       if(me->flag&ME_SUBSURF) {
                if(inEditMode && !G.editMesh->derived) {
                        makeDispList(ob);
                } else if (!inEditMode && !me->derived) {
@@ -986,8 +986,7 @@ DerivedMesh *mesh_get_derived(Object *ob)
 {
        Mesh *me= ob->data;
 
-       if (mesh_uses_displist(me)) {
-
+       if ((me->flag&ME_SUBSURF) && me->subdiv) {
                if(G.obedit && me==G.obedit->data) {
                        build_mesh_data(ob, 1);
                        return G.editMesh->derived;
@@ -1004,8 +1003,7 @@ DerivedMesh *mesh_get_derived_render(Object *ob, int *needsFree)
 {
        Mesh *me= ob->data;
 
-       if (mesh_uses_displist(me)) {
-                       // XXX, assumes was created earlier... is this for sure?
+       if ((me->flag&ME_SUBSURF) && me->subdivr) {
                if (me->subdiv==me->subdivr) {
                        *needsFree = 0;
                        if(G.obedit && me==G.obedit->data) {
@@ -1013,13 +1011,13 @@ DerivedMesh *mesh_get_derived_render(Object *ob, int *needsFree)
                        } else {
                                return me->derived;
                        }
+               } 
+
+               *needsFree = 1;
+               if(G.obedit && me==G.obedit->data) {
+                       return subsurf_make_derived_from_editmesh(G.editMesh, me->subdivr, me->subsurftype, NULL);
                } else {
-                       *needsFree = 1;
-                       if(G.obedit && me==G.obedit->data) {
-                               return subsurf_make_derived_from_editmesh(G.editMesh, me->subdivr, me->subsurftype, NULL);
-                       } else {
-                               return subsurf_make_derived_from_mesh(me, me->subdivr);
-                       }
+                       return subsurf_make_derived_from_mesh(me, me->subdivr);
                }
        }
 
index a04c39f467d2b68b544e6a340581f36432e583c1..c9a96f7e11677eddacd6f31c287110d1b7754579 100644 (file)
@@ -1203,7 +1203,7 @@ void mcol_to_tface(Mesh *me, int freedata)
 }
 
 int mesh_uses_displist(Mesh *me) {
-       return (me->flag&ME_SUBSURF);
+       return (me->flag&ME_SUBSURF) && me->subdiv;
 }
 
 void mesh_calculate_vertex_normals(Mesh *me)
index 60011c084b0b1e168b7f62b2019bac8b258263ec..7359555da455e61ab73d21b0d21bdfe8c28d986a 100644 (file)
@@ -1082,37 +1082,6 @@ static DispListMesh *subsurf_subdivide_to_displistmesh(HyperMesh *hme, short sub
        return dlm;
 }
 
-DerivedMesh *subsurf_make_derived_from_editmesh(EditMesh *em, int subdivLevels, short type, DerivedMesh *oldDerived) {
-       if (subdivLevels<1) {
-               if (oldDerived) {
-                       oldDerived->release(oldDerived);
-               }
-               return derivedmesh_from_displistmesh(em, displistmesh_from_editmesh(em));
-       } else if (type==ME_CCG_SUBSURF || type==ME_SIMPLE_SUBSURF) {
-               return subsurf_ccg_make_derived_from_editmesh(em, type==ME_SIMPLE_SUBSURF, subdivLevels, oldDerived);
-       } else {
-               HyperMesh *hme= hypermesh_from_editmesh(em, subdivLevels);
-       
-               if (oldDerived) {
-                       oldDerived->release(oldDerived);
-               }
-
-               return derivedmesh_from_displistmesh(em, subsurf_subdivide_to_displistmesh(hme, subdivLevels, type));
-       }
-}
-
-DerivedMesh *subsurf_make_derived_from_mesh(Mesh *me, int subdivLevels) {
-       if (subdivLevels<1) {
-               return derivedmesh_from_displistmesh(NULL, displistmesh_from_mesh(me, NULL));
-       } else if (me->subsurftype==ME_CCG_SUBSURF || me->subsurftype==ME_SIMPLE_SUBSURF) {
-               return subsurf_ccg_make_derived_from_mesh(me, me->subsurftype==ME_SIMPLE_SUBSURF, subdivLevels);
-       } else {
-               HyperMesh *hme= hypermesh_from_mesh(me, subdivLevels);
-
-               return derivedmesh_from_displistmesh(NULL, subsurf_subdivide_to_displistmesh(hme, subdivLevels, me->subsurftype));
-       }
-}
-
        // editarmature.c
 void subsurf_calculate_limit_positions(Mesh *me, float (*positions_r)[3]) 
 {
index ad556082153f3220013f631b38f3ef6eb09cabb1..61ee47375769fc51ae8a3d89a62ca81f2b47029f 100644 (file)
@@ -988,7 +988,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(SubSurf *ss) {
 
 /***/
 
-DerivedMesh *subsurf_ccg_make_derived_from_editmesh(EditMesh *em, int useFlatSubdiv, int subdivLevels, DerivedMesh *oldDerived) {
+DerivedMesh *subsurf_make_derived_from_editmesh(EditMesh *em, int subdivLevels, short type, DerivedMesh *oldDerived) {
        CCGDerivedMesh *ccgdm;
 
        if (oldDerived) {
@@ -998,12 +998,13 @@ DerivedMesh *subsurf_ccg_make_derived_from_editmesh(EditMesh *em, int useFlatSub
                ccgdm = getCCGDerivedMesh(ss);
        }
 
-       subSurf_sync(ccgdm->ss, useFlatSubdiv);
+       subSurf_sync(ccgdm->ss, type==ME_SIMPLE_SUBSURF);
 
        return (DerivedMesh*) ccgdm;
 }
 
-DerivedMesh *subsurf_ccg_make_derived_from_mesh(Mesh *me, int useFlatSubdiv, int subdivLevels) {
+DerivedMesh *subsurf_make_derived_from_mesh(Mesh *me, int subdivLevels) {
+       int useFlatSubdiv = me->subsurftype==ME_SIMPLE_SUBSURF;
        SubSurf *ss = subSurf_fromMesh(me, useFlatSubdiv, subdivLevels);
        DispListMesh *dlm;
 
@@ -1015,3 +1016,4 @@ DerivedMesh *subsurf_ccg_make_derived_from_mesh(Mesh *me, int useFlatSubdiv, int
        
        return derivedmesh_from_displistmesh(NULL, dlm);
 }
+
index c760e92cae3880370e68e92c50fb51aaeb6bb03d..f2bf3aa31e417efdc4ad9ae43e77acf06293fbab 100644 (file)
@@ -2164,7 +2164,7 @@ static PyObject *M_NMesh_GetRawFromObject( PyObject * self, PyObject * args )
                Mesh *me = ( Mesh * ) ob->data;
                DispList *dl;
 
-               if( mesh_uses_displist( me ) ) {
+               if( mesh_uses_displist( me )) {
                        DerivedMesh *dm = mesh_get_derived(ob);
                        DispListMesh *dlm = dm->convertToDispListMesh(dm);
                        nmesh = new_NMesh_internal( me, dlm, NULL );
index 334d1d860e23f6e2bef58cdc5d6727aad3d1a4ff..6c73044b150a5b3b4e42cd7b755b0bb69bc397ac 100644 (file)
@@ -1344,7 +1344,7 @@ static void init_render_mesh(Object *ob)
        
        /* we do this before deform */
        if(need_orco) {
-               if (mesh_uses_displist(me)
+               if ((me->flag&ME_SUBSURF) && me->subdivr
                        make_orco_displist_mesh(ob, me->subdivr);
                else
                        make_orco_mesh(me);
@@ -1353,7 +1353,7 @@ static void init_render_mesh(Object *ob)
        /* after orco, because this changes mesh vertices (too) */
        do_puno= mesh_modifier(ob, 's');
        
-       if (mesh_uses_displist(me)) {
+       if ((me->flag&ME_SUBSURF) && me->subdivr) {
                int needsFree;
                DerivedMesh *dm = mesh_get_derived_render(ob, &needsFree);
                dlm = dm->convertToDispListMesh(dm);
@@ -2734,7 +2734,7 @@ void RE_freeRotateBlenderScene(void)
                                MEM_freeN(me->orco);
                                me->orco= 0;
                        }
-                       if (mesh_uses_displist(me) && ((me->subdiv!=me->subdivr) || (ob->effect.first != NULL) || ob==G.obedit) ) { 
+                       if ((me->flag&ME_SUBSURF) && ((me->subdiv!=me->subdivr) || (ob->effect.first != NULL) || ob==G.obedit) ) { 
                            /* Need to recalc for effects since they are time dependant */
                                makeDispList(ob);  /* XXX this should be replaced with proper caching */
                        }
@@ -2956,7 +2956,7 @@ void RE_rotateBlenderScene(void)
                                else if(ob->parent && ob->parent->type==OB_LATTICE) makeDispList(ob);
                                else if(ob->hooks.first) makeDispList(ob);
                                else if(ob->softflag & 0x01) makeDispList(ob);
-                               else if(me->disp.first==NULL && mesh_uses_displist(me)) makeDispList(ob);
+                               else if(me->disp.first==NULL && (me->flag&ME_SUBSURF)) makeDispList(ob);
                                else if(ob->effect.first) {     // as last check
                                        Effect *eff= ob->effect.first;
                                        if(eff->type==EFF_WAVE) makeDispList(ob);