Cleaned the apply deform code in Blender. Now also using the modifier code.

Right now, it works for Meshes (all deformers including Curve) and for
Curve/Surfaces (only hooks).

More follows.
This commit is contained in:
Ton Roosendaal 2004-09-28 16:18:22 +00:00
parent fc0c3a084d
commit 5ac0d4fd26
9 changed files with 56 additions and 45 deletions

@ -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);

@ -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;
}

@ -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)

@ -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

@ -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);

@ -29,12 +29,14 @@
*
* ***** 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);
}

@ -76,35 +76,8 @@
#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) {

@ -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;

@ -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();