[Bf-committers] [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28376] trunk/blender/source/blender: Mesh Deform Modifier: compress static binding weights better, threshold

Daniel Salazar - 3Developer.com zanqdo at gmail.com
Fri Apr 23 23:50:31 CEST 2010


This broke mdef binding in trunk

cheers

Daniel Salazar
www.3developer.com


On Fri, Apr 23, 2010 at 5:19 AM, Brecht Van Lommel <brecht at blender.org>wrote:

> Revision: 28376
>
> http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28376
> Author:   blendix
> Date:     2010-04-23 13:19:06 +0200 (Fri, 23 Apr 2010)
>
> Log Message:
> -----------
> Mesh Deform Modifier: compress static binding weights better, threshold
> is still set very low so in many cases it could be even smaller, but being
> a bit conservative here to try to avoid breaking rigs.
>
> This is not forward-compatible, i.e. loading new files in older blender
> versions will loose the binding.
>
> Modified Paths:
> --------------
>    trunk/blender/source/blender/blenkernel/BKE_modifier.h
>    trunk/blender/source/blender/blenloader/intern/readfile.c
>    trunk/blender/source/blender/editors/armature/meshlaplacian.c
>    trunk/blender/source/blender/makesdna/DNA_modifier_types.h
>    trunk/blender/source/blender/modifiers/intern/MOD_meshdeform.c
>
> Modified: trunk/blender/source/blender/blenkernel/BKE_modifier.h
> ===================================================================
> --- trunk/blender/source/blender/blenkernel/BKE_modifier.h      2010-04-23
> 10:47:57 UTC (rev 28375)
> +++ trunk/blender/source/blender/blenkernel/BKE_modifier.h      2010-04-23
> 11:19:06 UTC (rev 28376)
> @@ -321,5 +321,8 @@
>
>     int required_mode);
>  struct ModifierData  *modifiers_getVirtualModifierList(struct Object *ob);
>
> +/* here for do_versions */
> +void modifier_mdef_compact_influences(struct ModifierData *md);
> +
>  #endif
>
>
> Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
> ===================================================================
> --- trunk/blender/source/blender/blenloader/intern/readfile.c   2010-04-23
> 10:47:57 UTC (rev 28375)
> +++ trunk/blender/source/blender/blenloader/intern/readfile.c   2010-04-23
> 11:19:06 UTC (rev 28376)
> @@ -3852,24 +3852,35 @@
>                else if (md->type==eModifierType_MeshDeform) {
>                        MeshDeformModifierData *mmd =
> (MeshDeformModifierData*) md;
>
> -                       mmd->bindweights= newdataadr(fd, mmd->bindweights);
> -                       mmd->bindcos= newdataadr(fd, mmd->bindcos);
> +                       mmd->bindinfluences= newdataadr(fd,
> mmd->bindinfluences);
> +                       mmd->bindoffsets= newdataadr(fd, mmd->bindoffsets);
> +                       mmd->bindcagecos= newdataadr(fd, mmd->bindcagecos);
>                        mmd->dyngrid= newdataadr(fd, mmd->dyngrid);
>                        mmd->dyninfluences= newdataadr(fd,
> mmd->dyninfluences);
>                        mmd->dynverts= newdataadr(fd, mmd->dynverts);
>
> +                       mmd->bindweights= newdataadr(fd, mmd->bindweights);
> +                       mmd->bindcos= newdataadr(fd, mmd->bindcos);
> +
>                        if(fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
>                                int a;
>
> +                               if(mmd->bindoffsets)
> +                                       for(a=0; a<mmd->totvert+1; a++)
> +
> SWITCH_INT(mmd->bindoffsets[a])
> +                               if(mmd->bindcagecos)
> +                                       for(a=0; a<mmd->totcagevert*3; a++)
> +
> SWITCH_INT(mmd->bindcagecos[a])
> +                               if(mmd->dynverts)
> +                                       for(a=0; a<mmd->totvert; a++)
> +
> SWITCH_INT(mmd->dynverts[a])
> +
>                                if(mmd->bindweights)
>                                        for(a=0;
> a<mmd->totcagevert*mmd->totvert; a++)
>
>  SWITCH_INT(mmd->bindweights[a])
>                                if(mmd->bindcos)
>                                        for(a=0; a<mmd->totcagevert*3; a++)
>                                                SWITCH_INT(mmd->bindcos[a])
> -                               if(mmd->dynverts)
> -                                       for(a=0; a<mmd->totvert; a++)
> -
> SWITCH_INT(mmd->dynverts[a])
>                        }
>                }
>        }
> @@ -5169,7 +5180,7 @@
>                                /*comma expressions, (e.g. expr1, expr2,
> expr3) evalutate each expression,
>                                  from left to right.  the right-most
> expression sets the result of the comma
>                                  expression as a whole*/
> -                               for(cl= sconsole->history.first; cl &&
> (clnext=cl->next), cl; cl= clnext) {
> +                               for(cl= sconsole->history.first; cl &&
> (clnext=cl->next); cl= clnext) {
>                                        cl->line= newdataadr(fd, cl->line);
>                                        if (!cl->line) {
>
>  BLI_remlink(&sconsole->history, cl);
> @@ -6451,6 +6462,30 @@
>        }
>  }
>
> +static void do_version_mdef_250(FileData *fd, Library *lib, Main *main)
> +{
> +       Object *ob;
> +       ModifierData *md;
> +       MeshDeformModifierData *mmd;
> +
> +       for(ob= main->object.first; ob; ob=ob->id.next) {
> +               for(md=ob->modifiers.first; md; md=md->next) {
> +                       if(md->type == eModifierType_MeshDeform) {
> +                               mmd= (MeshDeformModifierData*)md;
> +
> +                               if(mmd->bindcos) {
> +                                       /* make bindcos NULL in order to
> trick older versions
> +                                          into thinking that the mesh was
> not bound yet */
> +                                       mmd->bindcagecos= mmd->bindcos;
> +                                       mmd->bindcos= NULL;
> +
> +
> modifier_mdef_compact_influences(md);
> +                               }
> +                       }
> +               }
> +       }
> +}
> +
>  static void do_version_constraints_radians_degrees_250(ListBase *lb)
>  {
>        bConstraint *con;
> @@ -10780,7 +10815,7 @@
>
>        /* put 2.50 compatibility code here until next subversion bump */
>        {
> -
> +               do_version_mdef_250(fd, lib, main);
>        }
>
>        /* WATCH IT!!!: pointers from libdata have not been converted yet
> here! */
> @@ -12219,16 +12254,17 @@
>                                                        printf("
>  absolute lib: %s\n", mainptr->curlib->filename);
>                                                        printf("
>  relative lib: %s\n", mainptr->curlib->name);
>                                                        printf("  enter a
> new path:\n");
> -                                                       scanf("%s",
> newlib_path);
>
> -
> strcpy(mainptr->curlib->name, newlib_path);
> -
> strcpy(mainptr->curlib->filename, newlib_path);
> -                                                       cleanup_path(G.sce,
> mainptr->curlib->filename);
> -
> -                                                       fd=
> blo_openblenderfile(mainptr->curlib->filename, basefd->reports);
> +                                                       if(scanf("%s",
> newlib_path) > 0) {
> +
> strcpy(mainptr->curlib->name, newlib_path);
> +
> strcpy(mainptr->curlib->filename, newlib_path);
> +
> cleanup_path(G.sce, mainptr->curlib->filename);
> +
> +                                                               fd=
> blo_openblenderfile(mainptr->curlib->filename, basefd->reports);
>
> -                                                       if(fd) {
> -
> printf("found: '%s', party on macuno!\n", mainptr->curlib->filename);
> +                                                               if(fd) {
> +
> printf("found: '%s', party on macuno!\n", mainptr->curlib->filename);
> +                                                               }
>                                                        }
>                                                }
>                                        }
>
> Modified: trunk/blender/source/blender/editors/armature/meshlaplacian.c
> ===================================================================
> --- trunk/blender/source/blender/editors/armature/meshlaplacian.c
> 2010-04-23 10:47:57 UTC (rev 28375)
> +++ trunk/blender/source/blender/editors/armature/meshlaplacian.c
> 2010-04-23 11:19:06 UTC (rev 28376)
> @@ -44,6 +44,7 @@
>  #include "BLI_memarena.h"
>
>  #include "BKE_DerivedMesh.h"
> +#include "BKE_modifier.h"
>  #include "BKE_utildefines.h"
>
>  #ifdef RIGID_DEFORM
> @@ -1991,19 +1992,22 @@
>  #endif
>
>        /* assign bind variables */
> -       mmd->bindcos= (float*)mdb.cagecos;
> +       mmd->bindcagecos= (float*)mdb.cagecos;
>        mmd->totvert= mdb.totvert;
>        mmd->totcagevert= mdb.totcagevert;
>        copy_m4_m4(mmd->bindmat, mmd->object->obmat);
>
> -       /* transform bindcos to world space */
> +       /* transform bindcagecos to world space */
>        for(a=0; a<mdb.totcagevert; a++)
> -               mul_m4_v3(mmd->object->obmat, mmd->bindcos+a*3);
> +               mul_m4_v3(mmd->object->obmat, mmd->bindcagecos+a*3);
>
>        /* free */
>        mdb.cagedm->release(mdb.cagedm);
>        MEM_freeN(mdb.vertexcos);
>
> +       /* compact weights */
> +       modifier_mdef_compact_influences((ModifierData*)mmd);
> +
>        end_progress_bar();
>        waitcursor(0);
>  }
>
> Modified: trunk/blender/source/blender/makesdna/DNA_modifier_types.h
> ===================================================================
> --- trunk/blender/source/blender/makesdna/DNA_modifier_types.h  2010-04-23
> 10:47:57 UTC (rev 28375)
> +++ trunk/blender/source/blender/makesdna/DNA_modifier_types.h  2010-04-23
> 11:19:06 UTC (rev 28376)
> @@ -516,9 +516,13 @@
>
>        short gridsize, flag, mode, pad;
>
> -       /* variables filled in when bound */
> -       float *bindweights, *bindcos;   /* computed binding weights */
> +       /* result of static binding */
> +       MDefInfluence *bindinfluences;  /* influences */
> +       int *bindoffsets;                               /* offsets into
> influences array */
> +       float *bindcagecos;                             /* coordinates that
> cage was bound with */
>        int totvert, totcagevert;               /* total vertices in mesh
> and cage */
> +
> +       /* result of dynamic binding */
>        MDefCell *dyngrid;                              /* grid with dynamic
> binding cell points */
>        MDefInfluence *dyninfluences;   /* dynamic binding vertex influences
> */
>        int *dynverts, *pad2;                   /* is this vertex bound or
> not? */
> @@ -528,6 +532,10 @@
>        float dyncellwidth;                             /* width of dynamic
> bind cell */
>        float bindmat[4][4];                    /* matrix of cage at binding
> time */
>
> +       /* deprecated storage */
> +       float *bindweights;                             /* deprecated
> inefficient storage */
> +       float *bindcos;                                 /* deprecated
> storage of cage coords */
> +
>        /* runtime */
>        void (*bindfunc)(struct Scene *scene, struct DerivedMesh *dm,
>                struct MeshDeformModifierData *mmd,
>
> Modified: trunk/blender/source/blender/modifiers/intern/MOD_meshdeform.c
> ===================================================================
> --- trunk/blender/source/blender/modifiers/intern/MOD_meshdeform.c
>  2010-04-23 10:47:57 UTC (rev 28375)
> +++ trunk/blender/source/blender/modifiers/intern/MOD_meshdeform.c
>  2010-04-23 11:19:06 UTC (rev 28376)
> @@ -352,7 +352,69 @@
>                dm->release(dm);
>  }
>
> +#define MESHDEFORM_MIN_INFLUENCE 0.00001
>
> +void modifier_mdef_compact_influences(ModifierData *md)
> +{
> +       MeshDeformModifierData *mmd= (MeshDeformModifierData*)md;
> +       float weight, *weights, totweight;
> +       int totinfluence, totvert, totcagevert, a, b;
> +
> +       weights= mmd->bindweights;
> +       if(!weights)
> +               return;
> +
> +       totvert= mmd->totvert;
> +       totcagevert= mmd->totcagevert;
> +
> +       /* count number of influences above threshold */
> +       for(b=0; b<totvert; b++) {
> +               for(a=0; a<totcagevert; a++) {
> +                       weight= weights[a + b*totcagevert];
> +
> +                       if(weight > MESHDEFORM_MIN_INFLUENCE)
> +                               mmd->totinfluence++;
> +               }
> +       }
> +
> +       /* allocate bind influences */
> +       mmd->bindinfluences=
> MEM_callocN(sizeof(MDefInfluence)*mmd->totinfluence, "MDefBindInfluence");
> +       mmd->bindoffsets= MEM_callocN(sizeof(int)*(totvert+1),
> "MDefBindOffset");
> +
> +       /* write influences */
> +       totinfluence= 0;
> +
> +       for(b=0; b<totvert; b++) {
> +               mmd->bindoffsets[b]= totinfluence;
> +               totweight= 0.0f;
> +
> +               /* sum total weight */
> +               for(a=0; a<totcagevert; a++) {
> +                       weight= weights[a + b*totcagevert];
> +
> +                       if(weight > MESHDEFORM_MIN_INFLUENCE)
> +                               totweight += weight;
> +               }
> +
> +               /* assign weights normalized */
> +               for(a=0; a<totcagevert; a++) {
> +                       weight= weights[a + b*totcagevert];
> +
> +                       if(weight > MESHDEFORM_MIN_INFLUENCE) {
> +                               mmd->bindinfluences[totinfluence].weight=
> weight/totweight;
> +                               mmd->bindinfluences[totinfluence].vertex=
> a;
> +                               totinfluence++;
> +                       }
> +               }
> +       }
> +
> +       mmd->bindoffsets[b]= totinfluence;
> +
> +       /* free */
> +       MEM_freeN(mmd->bindweights);
> +       mmd->bindweights= NULL;
> +}
> +
>  ModifierTypeInfo modifierType_MeshDeform = {
>        /* name */              "MeshDeform",
>        /* structName */        "MeshDeformModifierData",
>
>
> _______________________________________________
> Bf-blender-cvs mailing list
> Bf-blender-cvs at blender.org
> http://lists.blender.org/mailman/listinfo/bf-blender-cvs
>


More information about the Bf-committers mailing list