- change modifier applyModifier[EM] function to not free derived argument
authorDaniel Dunbar <daniel@zuster.org>
Wed, 3 Aug 2005 04:04:05 +0000 (04:04 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Wed, 3 Aug 2005 04:04:05 +0000 (04:04 +0000)
 - added modifier_supportsMapping function
 - update CCG to set actual vertex normal (and not just
   interior face vertex normal, bla bla bla no one knows
   what this means nevermind).
 - renamed modifierType_get_info to modifierType_getInfo for
   consistency and to increase my commit line count.
 - update EditMeshDerivedMesh to calculate (and use new) normals
   when given deformed vertices
 - added
 - update editmode modifier calculation to also calculate a cage,
   not working 100% atm, in particular if a deformer follows a modifier
   that returns a DerivedMesh the cage is not accurate.
 - added ccg derivedmesh drawMapped{Vert,Face]NormalsEM functions
 - currently UI for selecting the cage mesh is rather irritating,
   will be updated

source/blender/blenkernel/BKE_modifier.h
source/blender/blenkernel/intern/CCGSubSurf.c
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/depsgraph.c
source/blender/blenkernel/intern/modifier.c
source/blender/blenkernel/intern/subsurf_ccg.c
source/blender/blenloader/intern/writefile.c
source/blender/makesdna/DNA_modifier_types.h
source/blender/src/buttons_object.c
source/blender/src/editobject.c

index 94e174f0e0ea6c6c9f4d9db3185e73504038be42..b584fca68e16fee36d42aec51f6899c4757f5834 100644 (file)
@@ -155,7 +155,7 @@ typedef struct ModifierTypeInfo {
                 * at the moment, it is meant so subsurf can know if it is safe to reuse its
                 * internal cache.
                 *
-                * The modifier is expected to release (or reuse) the _derivedData_ argument
+                * The modifier *MAY NOT* reuse or release the _derivedData_ argument
                 * if non-NULL. The modifier *MAY NOT* share the _vertexCos_ argument.
                 */
        void *(*applyModifier)(struct ModifierData *md, struct Object *ob, void *derivedData, float (*vertexCos)[3], int useRenderParams, int isFinalCalc);
@@ -169,7 +169,7 @@ typedef struct ModifierTypeInfo {
        void *(*applyModifierEM)(struct ModifierData *md, struct Object *ob, void *editData, void *derivedData, float (*vertexCos)[3]);
 } ModifierTypeInfo;
 
-ModifierTypeInfo *modifierType_get_info(ModifierType type);
+ModifierTypeInfo*              modifierType_getInfo    (ModifierType type);
 
        /* Modifier utility calls, do call through type pointer and return
         * default values if pointer is optional.
@@ -179,6 +179,7 @@ void                                        modifier_free                   (struct ModifierData *md);
 
 void                                   modifier_copyData               (struct ModifierData *md, struct ModifierData *target);
 int                                            modifier_dependsOnTime  (struct ModifierData *md);
+int                                            modifier_supportsMapping(struct ModifierData *md);
 
 struct ModifierData*   modifiers_findByType    (struct ListBase *lb, ModifierType type);
 
index ccc214284ac2561eeacf32ff27eecd3bd126fa6e..e88137bc1c9a02554fdadc63c95a0cb3ae6cd01f 100644 (file)
@@ -389,6 +389,9 @@ static int _vert_isBoundary(CCGVert *v) {
 static void *_vert_getCo(CCGVert *v, int lvl, int dataSize) {
        return &VERT_getLevelData(v)[lvl*dataSize];
 }
+static float *_vert_getNo(CCGVert *v, int lvl, int dataSize, int normalDataOffset) {
+       return (float*) &VERT_getLevelData(v)[lvl*dataSize + normalDataOffset];
+}
 
 static void _vert_free(CCGVert *v, CCGSubSurf *ss) {
        CCGSUBSURF_free(ss, v->edges);
@@ -1839,15 +1842,29 @@ static void ccgSubSurf__sync(CCGSubSurf *ss) {
                                }
                        }
                }
+                       // XXX can I reduce the number of normalisations here?
                for (ptrIdx=0; ptrIdx<numEffectedV; ptrIdx++) {
                        CCGVert *v = (CCGVert*) effectedV[ptrIdx];
-                       float no[3] = {0};
+                       float length, *no = _vert_getNo(v, lvl, vertDataSize, normalDataOffset);
+
+                       NormZero(no);
 
                        for (i=0; i<v->numFaces; i++) {
                                CCGFace *f = v->faces[i];
                                NormAdd(no, FACE_getIFNo(f, lvl, _face_getVertIndex(f,v), gridSize-1, gridSize-1));
                        }
 
+                       length = sqrt(no[0]*no[0] + no[1]*no[1] + no[2]*no[2]);
+
+                       if (length>FLT_EPSILON) {
+                               float invLength = 1.0f/length;
+                               no[0] *= invLength;
+                               no[1] *= invLength;
+                               no[2] *= invLength;
+                       } else {
+                               NormZero(no);
+                       }
+
                        for (i=0; i<v->numFaces; i++) {
                                CCGFace *f = v->faces[i];
                                NormCopy(FACE_getIFNo(f, lvl, _face_getVertIndex(f,v), gridSize-1, gridSize-1), no);
index 615429bee9f48f48711baae7b5d56fb7ec46bc67..6f1289a49c2ebc540e9416b325d049d269063ac2 100644 (file)
@@ -494,15 +494,33 @@ typedef struct {
 
        EditMesh *em;
        float (*vertexCos)[3];
+       float (*vertexNos)[3];
+       float (*faceNos)[3];
 } EditMeshDerivedMesh;
 
 static void emDM_getMappedVertCoEM(DerivedMesh *dm, void *vert, float co_r[3])
 {
-       EditVert *eve = vert;
+       EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
+
+       if (emdm->vertexCos) {
+               EditVert *eve;
+               int i;
+
+               for (i=0,eve= emdm->em->verts.first; eve; i++,eve=eve->next) {
+                       if (eve==vert) {
+                               co_r[0] = emdm->vertexCos[i][0];
+                               co_r[1] = emdm->vertexCos[i][1];
+                               co_r[2] = emdm->vertexCos[i][2];
+                               break;
+                       }
+               }
+       } else {
+               EditVert *eve = vert;
 
-       co_r[0] = eve->co[0];
-       co_r[1] = eve->co[1];
-       co_r[2] = eve->co[2];
+               co_r[0] = eve->co[0];
+               co_r[1] = eve->co[1];
+               co_r[2] = eve->co[2];
+       }
 }
 static void emDM_drawMappedVertsEM(DerivedMesh *dm, int (*setDrawOptions)(void *userData, EditVert *vert), void *userData)
 {
@@ -678,14 +696,16 @@ static void emDM_drawMappedFaceNormalsEM(DerivedMesh *dm, float length, int (*se
        }
 
 
-       for (efa= emdm->em->faces.first; efa; efa= efa->next) {
+       for (i=0,efa= emdm->em->faces.first; efa; i++,efa= efa->next) {
                if(!setDrawOptions || setDrawOptions(userData, efa)) {
+                       float *no = emdm->vertexCos?emdm->faceNos[i]:efa->n;
+
                        emDM__calcFaceCent(efa, cent, emdm->vertexCos);
 
-                       glVertex3fv(efa->cent);
-                       glVertex3f(     efa->cent[0] + length*efa->n[0],
-                                               efa->cent[1] + length*efa->n[1],
-                                               efa->cent[2] + length*efa->n[2]);
+                       glVertex3fv(cent);
+                       glVertex3f(     cent[0] + length*no[0],
+                                               cent[1] + length*no[1],
+                                               cent[2] + length*no[2]);
                }
        }
 
@@ -707,9 +727,9 @@ static void emDM_drawMappedVertNormalsEM(DerivedMesh *dm, float length, int (*se
                if(!setDrawOptions || setDrawOptions(userData, eve)) {
                        if (emdm->vertexCos) {
                                glVertex3fv(emdm->vertexCos[i]);
-                               glVertex3f(     emdm->vertexCos[i][0] + length*eve->no[0],
-                                                       emdm->vertexCos[i][1] + length*eve->no[1],
-                                                       emdm->vertexCos[i][2] + length*eve->no[2]);
+                               glVertex3f(     emdm->vertexCos[i][0] + length*emdm->vertexNos[i][0],
+                                                       emdm->vertexCos[i][1] + length*emdm->vertexNos[i][1],
+                                                       emdm->vertexCos[i][2] + length*emdm->vertexNos[i][2]);
                        } else {
                                glVertex3fv(eve->co);
                                glVertex3f(     eve->co[0] + length*eve->no[0],
@@ -732,9 +752,9 @@ static void emDM_drawMappedFacesEM(DerivedMesh *dm, int (*setDrawOptions)(void *
                for (i=0,eve=emdm->em->verts.first; eve; eve= eve->next)
                        eve->prev = (EditVert*) i++;
 
-               for (efa= emdm->em->faces.first; efa; efa= efa->next) {
+               for (i=0,efa= emdm->em->faces.first; efa; i++,efa= efa->next) {
                        if(!setDrawOptions || setDrawOptions(userData, efa)) {
-                               glNormal3fv(efa->n);
+                               glNormal3fv(emdm->faceNos[i]);
                                glBegin(efa->v4?GL_QUADS:GL_TRIANGLES);
                                glVertex3fv(emdm->vertexCos[(int) efa->v1->prev]);
                                glVertex3fv(emdm->vertexCos[(int) efa->v2->prev]);
@@ -771,10 +791,10 @@ static void emDM_drawFacesSolid(DerivedMesh *dm, int (*setMaterial)(int))
                for (i=0,eve=emdm->em->verts.first; eve; eve= eve->next)
                        eve->prev = (EditVert*) i++;
 
-               for (efa= emdm->em->faces.first; efa; efa= efa->next) {
+               for (i=0,efa= emdm->em->faces.first; efa; i++,efa= efa->next) {
                        if(efa->h==0) {
                                if (setMaterial(efa->mat_nr+1)) {
-                                       glNormal3fv(efa->n);
+                                       glNormal3fv(emdm->faceNos[i]);
                                        glBegin(efa->v4?GL_QUADS:GL_TRIANGLES);
                                        glVertex3fv(emdm->vertexCos[(int) efa->v1->prev]);
                                        glVertex3fv(emdm->vertexCos[(int) efa->v2->prev]);
@@ -839,8 +859,11 @@ static void emDM_release(DerivedMesh *dm)
 {
        EditMeshDerivedMesh *emdm= (EditMeshDerivedMesh*) dm;
 
-       if (emdm->vertexCos)
+       if (emdm->vertexCos) {
                MEM_freeN(emdm->vertexCos);
+               MEM_freeN(emdm->vertexNos);
+               MEM_freeN(emdm->faceNos);
+       }
 
        MEM_freeN(emdm);
 }
@@ -875,6 +898,52 @@ static DerivedMesh *getEditMeshDerivedMesh(EditMesh *em, float (*vertexCos)[3])
        emdm->em = em;
        emdm->vertexCos = vertexCos;
 
+       if (vertexCos) {
+               EditVert *eve, *preveve;
+               EditFace *efa;
+               int totface = BLI_countlist(&em->faces);
+               int i;
+
+               for (i=0,eve=em->verts.first; eve; eve= eve->next)
+                       eve->prev = (EditVert*) i++;
+
+               emdm->vertexNos = MEM_callocN(sizeof(*emdm->vertexNos)*i, "emdm_vno");
+               emdm->faceNos = MEM_mallocN(sizeof(*emdm->faceNos)*totface, "emdm_vno");
+
+               for(i=0, efa= em->faces.first; efa; i++, efa=efa->next) {
+                       float *v1 = vertexCos[(int) efa->v1->prev];
+                       float *v2 = vertexCos[(int) efa->v2->prev];
+                       float *v3 = vertexCos[(int) efa->v3->prev];
+                       float *no = emdm->faceNos[i];
+                       
+                       if(efa->v4) {
+                               float *v4 = vertexCos[(int) efa->v3->prev];
+
+                               CalcNormFloat4(v1, v2, v3, v4, no);
+                               VecAddf(emdm->vertexNos[(int) efa->v4->prev], emdm->vertexNos[(int) efa->v4->prev], no);
+                       }
+                       else {
+                               CalcNormFloat(v1, v2, v3, no);
+                       }
+
+                       VecAddf(emdm->vertexNos[(int) efa->v1->prev], emdm->vertexNos[(int) efa->v1->prev], no);
+                       VecAddf(emdm->vertexNos[(int) efa->v2->prev], emdm->vertexNos[(int) efa->v2->prev], no);
+                       VecAddf(emdm->vertexNos[(int) efa->v3->prev], emdm->vertexNos[(int) efa->v3->prev], no);
+               }
+
+               for(i=0, eve= em->verts.first; eve; i++, eve=eve->next) {
+                       float *no = emdm->vertexNos[i];
+
+                       if (Normalise(no)==0.0) {
+                               VECCOPY(no, vertexCos[i]);
+                               Normalise(no);
+                       }
+               }
+
+               for (preveve=NULL, eve=emdm->em->verts.first; eve; preveve=eve, eve= eve->next)
+                       eve->prev = preveve;
+       }
+
        return (DerivedMesh*) emdm;
 }
 
@@ -1213,7 +1282,7 @@ typedef float vec3f[3];
 DerivedMesh *mesh_create_derived_for_modifier(Object *ob, ModifierData *md)
 {
        Mesh *me = ob->data;
-       ModifierTypeInfo *mti = modifierType_get_info(md->type);
+       ModifierTypeInfo *mti = modifierType_getInfo(md->type);
        DerivedMesh *dm;
 
        if (!(md->mode&eModifierMode_Realtime)) return NULL;
@@ -1250,7 +1319,7 @@ static void mesh_calc_modifiers(Object *ob, float (*inputVertexCos)[3], DerivedM
 
                        /* Apply all leading deforming modifiers */
                for (; md; md=md->next) {
-                       ModifierTypeInfo *mti = modifierType_get_info(md->type);
+                       ModifierTypeInfo *mti = modifierType_getInfo(md->type);
 
                        if (!(md->mode&(1<<useRenderParams))) continue;
                        if (mti->isDisabled && mti->isDisabled(md)) continue;
@@ -1277,7 +1346,7 @@ static void mesh_calc_modifiers(Object *ob, float (*inputVertexCos)[3], DerivedM
                 */
        dm = NULL;
        for (; md; md=md->next) {
-               ModifierTypeInfo *mti = modifierType_get_info(md->type);
+               ModifierTypeInfo *mti = modifierType_getInfo(md->type);
 
                if (!(md->mode&(1<<useRenderParams))) continue;
                if (mti->type==eModifierTypeType_OnlyDeform && !useDeform) continue;
@@ -1312,6 +1381,8 @@ static void mesh_calc_modifiers(Object *ob, float (*inputVertexCos)[3], DerivedM
                        DerivedMesh *ndm = mti->applyModifier(md, ob, dm, deformedVerts, useRenderParams, !inputVertexCos);
 
                        if (ndm) {
+                               if (dm) dm->release(dm);
+
                                dm = ndm;
 
                                if (deformedVerts) {
@@ -1377,21 +1448,34 @@ static void editmesh_calc_modifiers(DerivedMesh **cage_r, DerivedMesh **final_r)
 {
        Object *ob = G.obedit;
        EditMesh *em = G.editMesh;
-       ModifierData *md= ob->modifiers.first;
+       ModifierData *md, *cageModifier;
        float (*deformedVerts)[3] = NULL;
        DerivedMesh *dm;
        int numVerts;
 
-       if (cage_r) *cage_r = NULL;
-       *final_r = NULL;
+               /* Find the last modifier acting on the cage. */
+       cageModifier = NULL;
+       for (md= ob->modifiers.first; md; md=md->next) {
+               ModifierTypeInfo *mti = modifierType_getInfo(md->type);
+
+               if (!(md->mode&eModifierMode_Realtime)) continue;
+               if (!(md->mode&eModifierMode_Editmode)) continue;
+               if (mti->isDisabled && mti->isDisabled(md)) continue;
+               if (!(mti->flags&eModifierTypeFlag_SupportsEditmode)) continue;
 
-       *cage_r = getEditMeshDerivedMesh(em, NULL);
+               if (!modifier_supportsMapping(md) || !(md->mode&eModifierMode_OnCage))
+                       break;
+
+               cageModifier = md;
+       }
 
-//     mesh_modifier(ob, &deformedVerts);
+       if (cage_r && !cageModifier) {
+               *cage_r = getEditMeshDerivedMesh(em, NULL);
+       }
 
        dm = NULL;
-       for (; md; md=md->next) {
-               ModifierTypeInfo *mti = modifierType_get_info(md->type);
+       for (md= ob->modifiers.first; md; md=md->next) {
+               ModifierTypeInfo *mti = modifierType_getInfo(md->type);
 
                if (!(md->mode&eModifierMode_Realtime)) continue;
                if (!(md->mode&eModifierMode_Editmode)) continue;
@@ -1424,11 +1508,28 @@ static void editmesh_calc_modifiers(DerivedMesh **cage_r, DerivedMesh **final_r)
                                 * by the modifier apply function, which will also free the DerivedMesh if
                                 * it exists.
                                 */
-                       dm = mti->applyModifierEM(md, ob, em, dm, deformedVerts);
+                       DerivedMesh *ndm = mti->applyModifierEM(md, ob, em, dm, deformedVerts);
+
+                       if (ndm) {
+                               if (dm && (!cage_r || dm!=*cage_r)) dm->release(dm);
+
+                               dm = ndm;
+
+                               if (deformedVerts) {
+                                       MEM_freeN(deformedVerts);
+                                       deformedVerts = NULL;
+                               }
+                       }
+               }
 
-                       if (deformedVerts) {
-                               MEM_freeN(deformedVerts);
-                               deformedVerts = NULL;
+               if (cage_r && md==cageModifier) {
+                       if (dm && deformedVerts) {
+                                       // XXX  this is not right, need to convert the dm
+                               *cage_r = dm;
+                       } else if (dm) {
+                               *cage_r = dm;
+                       } else {
+                               *cage_r = getEditMeshDerivedMesh(em, deformedVerts?MEM_dupallocN(deformedVerts):NULL);
                        }
                }
        }
@@ -1448,7 +1549,7 @@ static void editmesh_calc_modifiers(DerivedMesh **cage_r, DerivedMesh **final_r)
                        VECCOPY(dlm->mvert[i].co, deformedVerts[i]);
                }
 
-               dm->release(dm);
+               if (!cage_r || dm!=*cage_r) dm->release(dm);
 
                if (dlm->nors && !dlm->dontFreeNors) {
                        MEM_freeN(dlm->nors);
@@ -1527,6 +1628,8 @@ static void editmesh_build_data(void)
 
        editmesh_calc_modifiers(&em->derivedCage, &em->derivedFinal);
 
+       INIT_MINMAX(min, max);
+
        em->derivedFinal->getMinMax(em->derivedFinal, min, max);
 
        boundbox_set_from_min_max(mesh_get_bb(G.obedit->data), min, max);
index 16b9b63f5e6ac684bd306a60a9a0001ed14a900b..c3428d865fe5b2e989b0894bca45f63f26cdaaf1 100644 (file)
@@ -366,7 +366,7 @@ struct DagForest *build_dag(struct Scene *sce, short mask)
                        ModifierData *md;
 
                        for(md=ob->modifiers.first; md; md=md->next) {
-                               ModifierTypeInfo *mti = modifierType_get_info(md->type);
+                               ModifierTypeInfo *mti = modifierType_getInfo(md->type);
 
                                if (mti->updateDepgraph) mti->updateDepgraph(md, dag, ob, node);
                        }
index 0c43b128141d72040cce86af88d5755e0e671f0e..d86b429193bdd555e719e37478a07c73cc272468 100644 (file)
@@ -171,7 +171,6 @@ static void *subsurfModifier_applyModifier(ModifierData *md, Object *ob, void *d
                                VECCOPY(dlm->mvert[i].co, vertexCos[i]);
                        }
                }
-               dm->release(dm);
 
                dm = subsurf_make_derived_from_mesh(me, dlm, smd, useRenderParams, NULL, isFinalCalc);
 
@@ -198,7 +197,6 @@ static void *subsurfModifier_applyModifierEM(ModifierData *md, Object *ob, void
                                VECCOPY(dlm->mvert[i].co, vertexCos[i]);
                        }
                }
-               dm->release(dm);
 
                        // XXX, should I worry about reuse of mCache in editmode?
                dm = subsurf_make_derived_from_mesh(NULL, dlm, smd, 0, NULL, 1);
@@ -442,7 +440,6 @@ static void *buildModifier_applyModifier(ModifierData *md, Object *ob, void *der
                }
        }
 
-       if (dm) dm->release(dm);
        if (dlm) displistmesh_free(dlm);
 
        mesh_calc_normals(ndlm->mvert, ndlm->totvert, ndlm->mface, ndlm->totface, &ndlm->nors);
@@ -693,7 +690,6 @@ static void *mirrorModifier_applyModifier(ModifierData *md, Object *ob, void *de
        mirrorModifier__doMirror(mmd, ndlm, vertexCos);
 
        if (dlm) displistmesh_free(dlm);
-       if (dm) dm->release(dm);
 
        mesh_calc_normals(ndlm->mvert, ndlm->totvert, ndlm->mface, ndlm->totface, &ndlm->nors);
        
@@ -895,8 +891,6 @@ static void *decimateModifier_applyModifier(ModifierData *md, Object *ob, void *
        if (dlm) displistmesh_free(dlm);
 
        if (ndlm) {
-               if (dm) dm->release(dm);
-
                mesh_calc_normals(ndlm->mvert, ndlm->totvert, ndlm->mface, ndlm->totface, &ndlm->nors);
 
                return derivedmesh_from_displistmesh(ndlm);
@@ -1007,7 +1001,7 @@ static void waveModifier_deformVertsEM(ModifierData *md, Object *ob, void *editD
 static ModifierTypeInfo typeArr[NUM_MODIFIER_TYPES];
 static int typeArrInit = 1;
 
-ModifierTypeInfo *modifierType_get_info(ModifierType type)
+ModifierTypeInfo *modifierType_getInfo(ModifierType type)
 {
        if (typeArrInit) {
                ModifierTypeInfo *mti;
@@ -1104,7 +1098,7 @@ ModifierTypeInfo *modifierType_get_info(ModifierType type)
 
 ModifierData *modifier_new(int type)
 {
-       ModifierTypeInfo *mti = modifierType_get_info(type);
+       ModifierTypeInfo *mti = modifierType_getInfo(type);
        ModifierData *md = MEM_callocN(mti->structSize, mti->structName);
 
        md->type = type;
@@ -1120,7 +1114,7 @@ ModifierData *modifier_new(int type)
 
 void modifier_free(ModifierData *md) 
 {
-       ModifierTypeInfo *mti = modifierType_get_info(md->type);
+       ModifierTypeInfo *mti = modifierType_getInfo(md->type);
 
        if (mti->freeData) mti->freeData(md);
 
@@ -1129,11 +1123,20 @@ void modifier_free(ModifierData *md)
 
 int modifier_dependsOnTime(ModifierData *md) 
 {
-       ModifierTypeInfo *mti = modifierType_get_info(md->type);
+       ModifierTypeInfo *mti = modifierType_getInfo(md->type);
 
        return mti->dependsOnTime && mti->dependsOnTime(md);
 }
 
+int modifier_supportsMapping(ModifierData *md)
+{
+       ModifierTypeInfo *mti = modifierType_getInfo(md->type);
+
+       return (        (mti->flags&eModifierTypeFlag_SupportsEditmode) &&
+                               (       (mti->type==eModifierTypeType_OnlyDeform ||
+                                       (mti->flags&eModifierTypeFlag_SupportsMapping))) );
+}
+
 ModifierData *modifiers_findByType(struct ListBase *lb, ModifierType type)
 {
        ModifierData *md = lb->first;
@@ -1147,7 +1150,7 @@ ModifierData *modifiers_findByType(struct ListBase *lb, ModifierType type)
 
 void modifier_copyData(ModifierData *md, ModifierData *target)
 {
-       ModifierTypeInfo *mti = modifierType_get_info(md->type);
+       ModifierTypeInfo *mti = modifierType_getInfo(md->type);
 
        target->mode = md->mode;
 
index ca2690a51774866811f1adfc43eff519043dc2c7..5e10bfcf7b13681386c44649609ca354a16095c8 100644 (file)
@@ -34,6 +34,8 @@
 #include <string.h>
 #include <stdio.h>
 #include <math.h>
+#include <float.h>
+
 #include "MEM_guardedalloc.h"
 
 #include "DNA_mesh_types.h"
@@ -418,7 +420,9 @@ static DispListMesh *ss_to_displistmesh(CCGSubSurf *ss, int ssFromEditmesh, Mesh
                }
 
                for (S=0; S<numVerts; S++) {
+                       VertData *gridData = ccgSubSurf_getFaceGridDataArray(ss, f, S);
                        int prevS= (S-1+numVerts)%numVerts;
+
                        for (y=0; y<gridSize-1; y++) {
                                for (x=0; x<gridSize-1; x++) {
                                        MFace *mf = &dlm->mface[i];
@@ -1142,6 +1146,29 @@ static void ccgDM_drawMappedVertsEM(DerivedMesh *dm, int (*setDrawOptions)(void
 
        ccgVertIterator_free(vi);
 }
+static void ccgDM_drawMappedVertNormalsEM(DerivedMesh *dm, float length, int (*setDrawOptions)(void *userData, struct EditVert *eve), void *userData) {
+       CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
+       CCGSubSurf *ss = ccgdm->ss;
+       CCGVertIterator *vi = ccgSubSurf_getVertIterator(ss);
+
+       glBegin(GL_LINES);
+       for (; !ccgVertIterator_isStopped(vi); ccgVertIterator_next(vi)) {
+               CCGVert *v = ccgVertIterator_getCurrent(vi);
+               EditVert *vert = ccgSubSurf_getVertVertHandle(ss,v);
+
+               if (!setDrawOptions || setDrawOptions(userData, vert)) {
+                       VertData *vd = ccgSubSurf_getVertData(ss, v);
+
+                       glVertex3fv(vd->co);
+                       glVertex3f(     vd->co[0] + length*vd->no[0],
+                                               vd->co[1] + length*vd->no[1],
+                                               vd->co[2] + length*vd->no[2]);
+               }
+       }
+       glEnd();
+
+       ccgVertIterator_free(vi);
+}
 static void ccgDM_drawMappedEdgeEM(DerivedMesh *dm, void *edge) {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
        CCGSubSurf *ss = ccgdm->ss;
@@ -1245,6 +1272,30 @@ static void ccgDM_drawMappedFacesEM(DerivedMesh *dm, int (*setDrawOptions)(void
 
        ccgFaceIterator_free(fi);
 }
+static void ccgDM_drawMappedFaceNormalsEM(DerivedMesh *dm, float length, int (*setDrawOptions)(void *userData, struct EditFace *efa), void *userData) {
+       CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
+       CCGSubSurf *ss = ccgdm->ss;
+       CCGFaceIterator *fi = ccgSubSurf_getFaceIterator(ss);
+       int gridSize = ccgSubSurf_getGridSize(ss);
+
+       glBegin(GL_LINES);
+       for (; !ccgFaceIterator_isStopped(fi); ccgFaceIterator_next(fi)) {
+               CCGFace *f = ccgFaceIterator_getCurrent(fi);
+               EditFace *efa = ccgSubSurf_getFaceFaceHandle(ss, f);
+               if (!setDrawOptions || setDrawOptions(userData, efa)) {
+                               /* Face center data normal isn't updated atm. */
+                       VertData *vd = ccgSubSurf_getFaceGridData(ss, f, 0, 0, 0);
+
+                       glVertex3fv(vd->co);
+                       glVertex3f(     vd->co[0] + length*vd->no[0],
+                                               vd->co[1] + length*vd->no[1],
+                                               vd->co[2] + length*vd->no[2]);
+               }
+       }
+       glEnd();
+
+       ccgFaceIterator_free(fi);
+}
 
 static void ccgDM_release(DerivedMesh *dm) {
        CCGDerivedMesh *ccgdm = (CCGDerivedMesh*) dm;
@@ -1273,10 +1324,12 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss, int fromEditmesh, Mesh
        ccgdm->dm.drawFacesTex = ccgDM_drawFacesTex;
 
        ccgdm->dm.drawMappedVertsEM = ccgDM_drawMappedVertsEM;
+       ccgdm->dm.drawMappedVertNormalsEM = ccgDM_drawMappedVertNormalsEM;
        ccgdm->dm.drawMappedEdgeEM = ccgDM_drawMappedEdgeEM;
        ccgdm->dm.drawMappedEdgesInterpEM = ccgDM_drawMappedEdgesInterpEM;
        ccgdm->dm.drawMappedEdgesEM = ccgDM_drawMappedEdgesEM;
        ccgdm->dm.drawMappedFacesEM = ccgDM_drawMappedFacesEM;
+       ccgdm->dm.drawMappedFaceNormalsEM = ccgDM_drawMappedFaceNormalsEM;
 
        ccgdm->dm.release = ccgDM_release;
        
index 647e03da23bdee0245832e38106544b802185c7b..fe6b0c5662990ffec339173455be7b2d94494c09 100644 (file)
@@ -661,7 +661,7 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
        ModifierData *md;
 
        for (md=modbase->first; md; md= md->next) {
-               ModifierTypeInfo *mti = modifierType_get_info(md->type);
+               ModifierTypeInfo *mti = modifierType_getInfo(md->type);
 
                writestruct(wd, DATA, mti->structName, 1, md);
        }
index 66732fe0dc4eb59c8b5d6c8f805cf51d194f50e5..d2c0c96887095bbd35bf265935a1d568b9b8912e 100644 (file)
@@ -27,6 +27,7 @@ typedef enum ModifierMode {
        eModifierMode_Realtime = (1<<0),
        eModifierMode_Render = (1<<1),
        eModifierMode_Editmode = (1<<2),
+       eModifierMode_OnCage = (1<<3),
 } ModifierMode;
 
 typedef struct ModifierData {
index 76e55d201b2a2fc56f15494a4a6822460c1f5be4..e6487c6a291d838446d9bf9d24a93c4acaeb77cd 100644 (file)
@@ -1716,7 +1716,7 @@ static uiBlock *modifier_add_menu(void *ob_v)
        uiBlockSetButmFunc(block, modifiers_add, ob);
 
        for (i=eModifierType_None+1; i<NUM_MODIFIER_TYPES; i++) {
-               ModifierTypeInfo *mti = modifierType_get_info(i);
+               ModifierTypeInfo *mti = modifierType_getInfo(i);
 
                if (    (mti->flags&eModifierTypeFlag_AcceptsCVs) || 
                                (ob->type==OB_MESH && (mti->flags&eModifierTypeFlag_AcceptsMesh))) {
@@ -1869,29 +1869,36 @@ static void object_panel_modifiers(Object *ob)
        uiButSetFunc(but, modifiers_del, ob, NULL);
 
        if (ob->modifiers.first) {
-               int i, numModifiers = BLI_countlist(&ob->modifiers);
+               int i, canCage=1, numModifiers = BLI_countlist(&ob->modifiers);
                ModifierData *md;
 
                CLAMP(actModifier, 1, numModifiers);
                uiDefButI(block, NUM, B_REDR, "Modifier", 740,380,180,27, &actModifier, 1, numModifiers, 0, 0, "Index of current modifier");
 
-               for (i=0, md=ob->modifiers.first; md && i<actModifier-1; i++)
+               for (i=0, md=ob->modifiers.first; md && i<actModifier-1; i++) {
+                       if (!modifier_supportsMapping(md) || !(md->mode&eModifierMode_OnCage))
+                               canCage = 0;
+
                        md = md->next;
+               }
 
                if (md) {
-                       ModifierTypeInfo *mti = modifierType_get_info(md->type);
+                       ModifierTypeInfo *mti = modifierType_getInfo(md->type);
                        char str[128];
 
                        but = uiDefBut(block, BUT, B_MAKEDISP, "Move Up", 740, 360, 90, 19, 0, 0, 0, 0, 0, "Move modifier up in stack");
                        uiButSetFunc(but, modifiers_moveUp, ob, md);
                        but = uiDefBut(block, BUT, B_MAKEDISP, "Move Down", 830, 360, 90, 19, 0, 0, 0, 0, 0, "Move modifier down in stack");
                        uiButSetFunc(but, modifiers_moveDown, ob, md);
-                       uiDefButBitI(block, TOG, eModifierMode_Render, B_NOP, "Render", 740,340,60,19,&md->mode, 0, 0, 1, 0, "");
-                       uiDefButBitI(block, TOG, eModifierMode_Realtime, B_MAKEDISP, "Realtime", 810,340,60,19,&md->mode, 0, 0, 1, 0, "");
+                       uiDefButBitI(block, TOG, eModifierMode_Render, B_NOP, "Render", 740,340,90,19,&md->mode, 0, 0, 1, 0, "Enable modifier during rendering");
+                       uiDefButBitI(block, TOG, eModifierMode_Realtime, B_MAKEDISP, "3D View", 830,340,90,19,&md->mode, 0, 0, 1, 0, "Enable modifier during interactive display");
                        if (mti->flags&eModifierTypeFlag_SupportsEditmode) {
-                               uiDefButBitI(block, TOG, eModifierMode_Editmode, B_MAKEDISP, "Editmode", 860,340,60,19,&md->mode, 0, 0, 1, 0, "");
+                               uiDefButBitI(block, TOG, eModifierMode_Editmode, B_MAKEDISP, "Editmode", 740,320,90,19,&md->mode, 0, 0, 1, 0, "Enable modifier during Editmode");
+                               if (canCage && modifier_supportsMapping(md)) {
+                                       uiDefButBitI(block, TOG, eModifierMode_OnCage, B_MAKEDISP, "On Cage", 830,320,90,19,&md->mode, 0, 0, 1, 0, "Apply modifier to editing cage during Editmode");
+                               }
                        }
-                       but = uiDefBut(block, BUT, B_MAKEDISP, "Apply Modifier",        740,320,180,19, 0, 0, 0, 0, 0, "Apply the currnt modifier and remove from the stack");
+                       but = uiDefBut(block, BUT, B_MAKEDISP, "Apply Modifier",        740,300,180,19, 0, 0, 0, 0, 0, "Apply the currnt modifier and remove from the stack");
                        uiButSetFunc(but, modifiers_applyModifier, ob, md);
 
                        uiBlockBeginAlign(block);
index 9590be53b1ecf3136268972f1f319254210ff59f..c2046239f48428ea768a58a1abef200f07c28f8f 100644 (file)
@@ -2461,7 +2461,7 @@ static void copymenu_modifiers(Object *ob)
        sprintf(str+strlen(str), "|All%%x%d|%%l", NUM_MODIFIER_TYPES);
 
        for (i=eModifierType_None+1; i<NUM_MODIFIER_TYPES; i++) {
-               ModifierTypeInfo *mti = modifierType_get_info(i);
+               ModifierTypeInfo *mti = modifierType_getInfo(i);
 
                if (    (mti->flags&eModifierTypeFlag_AcceptsCVs) || 
                                (ob->type==OB_MESH && (mti->flags&eModifierTypeFlag_AcceptsMesh))) {