Cleaned the apply deform code in Blender. Now also using the modifier code.
authorTon Roosendaal <ton@blender.org>
Tue, 28 Sep 2004 16:18:22 +0000 (16:18 +0000)
committerTon Roosendaal <ton@blender.org>
Tue, 28 Sep 2004 16:18:22 +0000 (16:18 +0000)
Right now, it works for Meshes (all deformers including Curve) and for
Curve/Surfaces (only hooks).

More follows.

source/blender/blenkernel/BKE_lattice.h
source/blender/blenkernel/intern/deform.c
source/blender/blenkernel/intern/lattice.c
source/blender/include/BIF_editdeform.h
source/blender/include/BIF_editlattice.h
source/blender/src/editdeform.c
source/blender/src/editlattice.c
source/blender/src/editobject.c
source/blender/src/toolbox.c

index a9a3ee2d6f9ff8b76cb524de72659bed699144e8..9186850e583504dc4c989ffd591a0d8a9cacdcdc 100644 (file)
@@ -51,7 +51,6 @@ void init_latt_deform(struct Object *oblatt, struct Object *ob);
 void calc_latt_deform(float *co);
 void end_latt_deform(void);
 int object_deform(struct Object *ob);
-int object_apply_deform(struct Object *ob);
 struct BPoint *latt_bp(struct Lattice *lt, int u, int v, int w);
 void outside_lattice(struct Lattice *lt);
 
index 290538013eb5d0e6f997633c6390b61fa7138d1b..8149d4540d88c34afcc15b825c9cab9f07d48761 100644 (file)
@@ -199,7 +199,7 @@ void hook_object_deform(Object *ob, int index, float *vec)
 
 
 /* modifiers: hooks, deform, softbody 
-   mode=='s' is start, 'e' end 
+   mode=='s' is start, 'e' is end , 'a' is apply
 */
 
 int mesh_modifier(Object *ob, char mode)
@@ -258,13 +258,17 @@ int mesh_modifier(Object *ob, char mode)
                }
                
        }
-       else { // end
+       else if(mode=='e') { // end
                if(mvert) {
-                       MEM_freeN(me->mvert);
+                       if(me->mvert) MEM_freeN(me->mvert);
                        me->mvert= mvert;
                        mvert= NULL;
                }
        }
+       else if(mode=='a') { // apply
+               if(mvert) MEM_freeN(mvert);
+               mvert= NULL;
+       }
        
        return done;
 }
@@ -327,11 +331,14 @@ int curve_modifier(Object *ob, char mode)
                        }
                }
        }
-       else {
+       else if(mode=='e') {
                /* paste */
                freeNurblist(&cu->nurb);
                cu->nurb= nurb;
        }
+       else if(mode=='a') {
+               freeNurblist(&nurb);
+       }
        
        return done;
 }
index 0516db04a632a5bf192d7b2f2ce63c0156a050a6..074bd8f561ba027f22b6270884a9291e1a73a30e 100644 (file)
@@ -663,10 +663,6 @@ int object_deform(Object *ob)
 {
        return _object_deform(ob, 0);
 }
-int object_apply_deform(Object *ob)
-{
-       return _object_deform(ob, 1);
-}
 
 
 BPoint *latt_bp(Lattice *lt, int u, int v, int w)
index c45bdbccd2438a63dde32c1cc3072a8239f53d52..3720e8e3d8a070c736c3a0608177c0928b9e1438 100644 (file)
@@ -61,5 +61,7 @@ void remove_vert_defgroup (struct Object *ob, struct bDeformGroup  *dg,
                                                   int vertnum);
 void create_dverts(Mesh *me);
 
+extern void object_apply_deform(struct Object *ob);
+
 #endif
 
index 738eb14847cd6c7ad81123445bd14143c750e005..c882013576ddcb88e78d9e1435ae2122c2a5ab4c 100644 (file)
@@ -33,7 +33,6 @@
 #ifndef BIF_EDITLATTICE_H
 #define BIF_EDITLATTICE_H
 
-void apply_lattice(void);
 void free_editLatt(void);
 void make_editLatt(void);
 void load_editLatt(void);
index dfdfdf943cbba5c70dcbade1d36b33612482c1b6..c42ea250f6d5854a6db1408c78357a0583da6ffb 100644 (file)
  *
  * ***** END GPL/BL DUAL LICENSE BLOCK *****
  * Creator-specific support for vertex deformation groups
+ * Added: apply deform function (ton)
  */
 
 #include <string.h>
 
 #include "MEM_guardedalloc.h"
 
+#include "DNA_curve_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_object_types.h"
@@ -44,6 +46,7 @@
 
 #include "BKE_global.h"
 #include "BKE_deform.h"
+#include "BKE_displist.h"
 #include "BKE_mesh.h"
 
 #include "BIF_editdeform.h"
@@ -645,3 +648,33 @@ void unique_vertexgroup_name (bDeformGroup *dg, Object *ob)
                }
        }       
 }
+
+/* ******************* other deform edit stuff ********** */
+
+void object_apply_deform(Object *ob)
+{
+       char *err= NULL;
+       
+       if(ob->type==OB_MESH) {
+               Mesh *me= ob->data;
+               if(me->id.us>1) {
+                       err= "Can't apply deformation to Mesh with other users";
+               }
+               mesh_modifier(ob, 's'); // start
+               mesh_modifier(ob, 'a'); // apply and end
+               freedisplist(&ob->disp);
+       }
+       else if (ob->type==OB_CURVE || ob->type==OB_SURF) {
+               Curve *cu= ob->data;
+               if(cu->id.us>1) {
+                       err= "Can't apply deformation to Curve with other users";
+               }
+               curve_modifier(ob, 's'); // start
+               curve_modifier(ob, 'a'); // apply and end
+               freedisplist(&ob->disp);
+       }
+
+       if(err) error(err);
+
+}
+
index 8aebfdfedc54b571d0167fec89a6cb33ec84bec3..18bed249da47a980e9a29410af55ea43d746aa55 100644 (file)
 
 #include "BKE_armature.h"
 
-void apply_lattice(void)
-{
-       Base *base;
-       Object *par;
-       
-       if(okee("Apply lattice deformation")==0) return;
-       
-       base= FIRSTBASE;
-       while(base) {
-               if TESTBASELIB(base) {
-                       if( (par= base->object->parent) ) {
-                               if(par->type==OB_LATTICE) {
-                                       object_apply_deform(base->object);
-                                       
-                                       base->object->parent= 0;
-                               }
-                       }
-               }
-               base= base->next;
-       }
-       
-       allqueue(REDRAWVIEW3D, 0);
-}
-
 /* ***************************** */
 
-
-
-
 void free_editLatt(void)
 {
        if(editLatt) {
index 27c562b3aa9084d01f0c7ed583d7d5f07c66d334..6b58e260e2d0f5e66219e2d4f309ce5b5369abc9 100644 (file)
@@ -812,9 +812,7 @@ void clear_parent(void)
                        }
                        
                        if(par) {
-                               if(par->type==OB_LATTICE) makeDispList(base->object);
-                               if(par->type==OB_IKA) makeDispList(base->object);
-                               if(par->type==OB_ARMATURE) makeDispList(base->object);
+                               makeDispList(base->object);     // just always..., checks are not available well (ton)
                        }
                }
                base= base->next;
@@ -2865,9 +2863,13 @@ void apply_object()
                if(ob==0) return;
                
                if(ob->transflag & OB_DUPLI) make_duplilist_real();
-               else if(ob->parent && ob->parent->type==OB_LATTICE) apply_lattice();
-               
-               return;
+               else {
+                       if(okee("Apply deformation")==0) return;
+                       object_apply_deform(ob);
+                       allqueue(REDRAWVIEW3D, 0);
+
+                       return;
+               }
        }
 
        if(okee("Apply size and rotation")==0) return;
index 646c1d5f4313138817df7558e2b5b592deb21ec6..bfa411639348094de5234d0429853622e871b9f5 100644 (file)
@@ -82,6 +82,7 @@
 #include "BIF_toolbox.h"
 #include "BIF_mywindow.h"
 #include "BIF_editarmature.h"
+#include "BIF_editdeform.h"
 #include "BIF_editfont.h"
 #include "BIF_editmesh.h"
 #include "BIF_editseq.h"
@@ -1943,8 +1944,7 @@ static void tb_do_transform_clearapply(void *arg, int event)
                        apply_object();
                        break;
                case 4: /* apply deformation */
-                       if (ob->parent && ob->parent->type==OB_LATTICE) apply_lattice();
-                       else error("The active object is not the child of a lattice");
+                       object_apply_deform(ob);
                        break;
                case 5: /* make duplicates real */
                        if (ob->transflag & OB_DUPLI) make_duplilist_real();