- added modifiers_getVirtualModifierList, returns pointer to first modifier

but including "virtual" modifiers (for example, an object skel-parented
   to a lattice has a virtual first lattice modifier)
 - removed mesh_modifier(), all functionality has been incorporated into
   modifier stack (well, keys still don't exist as a modifier, but I am
   not sure if they should).
 - added interface option to convert a virtual modifier into a real modifier
 - added option to parent to lattice object or lattice with deform
 - bug fix, patch of hook indices patched all hooks (oops) not just ones
   for edited mesh

NOTE: Files saved with 2.38 that include an object parented to a lattice
will not load correctly, because it will look like the object is parented
only to the object (i.e. without deform). Can be simply fixed by reparenting
or adding a lattice modifier. Older files are handled automatically.
This commit is contained in:
2005-08-11 03:31:33 +00:00
parent ac3ed0f92a
commit 75bcb4cd98
11 changed files with 184 additions and 99 deletions

View File

@@ -48,7 +48,6 @@ struct bDeformGroup *get_named_vertexgroup (Object *ob, char *name);
int get_defgroup_num (struct Object *ob, struct bDeformGroup *dg); int get_defgroup_num (struct Object *ob, struct bDeformGroup *dg);
int curve_modifier(struct Object *ob, char mode); int curve_modifier(struct Object *ob, char mode);
void mesh_modifier(struct Object *ob, float (**vertexCos_r)[3]);
int lattice_modifier(struct Object *ob, char mode); int lattice_modifier(struct Object *ob, char mode);

View File

@@ -37,6 +37,7 @@ struct DerivedMesh;
struct DagForest; struct DagForest;
struct DagNode; struct DagNode;
struct Object; struct Object;
struct ListBase;
typedef enum { typedef enum {
/* Should not be used, only for None modifier type */ /* Should not be used, only for None modifier type */
@@ -201,5 +202,7 @@ int modifiers_getCageIndex (struct Object *ob, int *lastPossibleCageIndex_r)
int modifiers_isSoftbodyEnabled (struct Object *ob); int modifiers_isSoftbodyEnabled (struct Object *ob);
ModifierData* modifiers_getVirtualModifierList (struct Object *ob);
#endif #endif

View File

@@ -60,6 +60,7 @@
#include "BKE_subsurf.h" #include "BKE_subsurf.h"
#include "BKE_deform.h" #include "BKE_deform.h"
#include "BKE_modifier.h" #include "BKE_modifier.h"
#include "BKE_key.h"
#include "BIF_gl.h" #include "BIF_gl.h"
#include "BIF_glutil.h" #include "BIF_glutil.h"
@@ -1388,8 +1389,8 @@ DerivedMesh *mesh_create_derived_for_modifier(Object *ob, ModifierData *md)
static void mesh_calc_modifiers(Object *ob, float (*inputVertexCos)[3], DerivedMesh **deform_r, DerivedMesh **final_r, int useRenderParams, int useDeform) static void mesh_calc_modifiers(Object *ob, float (*inputVertexCos)[3], DerivedMesh **deform_r, DerivedMesh **final_r, int useRenderParams, int useDeform)
{ {
Mesh *me = ob->data; Mesh *me = ob->data;
ModifierData *md= ob->modifiers.first; ModifierData *md= modifiers_getVirtualModifierList(ob);
float (*deformedVerts)[3]; float (*deformedVerts)[3] = NULL;
DerivedMesh *dm; DerivedMesh *dm;
int numVerts = me->totvert; int numVerts = me->totvert;
@@ -1399,7 +1400,7 @@ static void mesh_calc_modifiers(Object *ob, float (*inputVertexCos)[3], DerivedM
*final_r = NULL; *final_r = NULL;
if (useDeform) { if (useDeform) {
mesh_modifier(ob, &deformedVerts); do_mesh_key(me);
/* Apply all leading deforming modifiers */ /* Apply all leading deforming modifiers */
for (; md; md=md->next) { for (; md; md=md->next) {

View File

@@ -156,31 +156,6 @@ int get_defgroup_num (Object *ob, bDeformGroup *dg)
/* *************** HOOK ****************** */ /* *************** HOOK ****************** */
void mesh_modifier(Object *ob, float (**vertexCos_r)[3])
{
Mesh *me= ob->data;
float (*vertexCos)[3] = NULL;
do_mesh_key(me);
if (ob->parent && me->totvert) {
if(ob->parent->type==OB_CURVE && ob->partype==PARSKEL) {
if (!vertexCos) vertexCos = mesh_getVertexCos(me, NULL);
curve_deform_verts(ob->parent, ob, vertexCos, me->totvert);
}
else if(ob->parent->type==OB_LATTICE) {
if (!vertexCos) vertexCos = mesh_getVertexCos(me, NULL);
lattice_deform_verts(ob->parent, ob, vertexCos, me->totvert);
}
else if(ob->parent->type==OB_ARMATURE && ob->partype==PARSKEL) {
if (!vertexCos) vertexCos = mesh_getVertexCos(me, NULL);
armature_deform_verts(ob->parent, ob, vertexCos, me->totvert);
}
}
*vertexCos_r = vertexCos;
}
int curve_modifier(Object *ob, char mode) int curve_modifier(Object *ob, char mode)
{ {
static ListBase nurb={NULL, NULL}; static ListBase nurb={NULL, NULL};

View File

@@ -1468,3 +1468,54 @@ int modifiers_isSoftbodyEnabled(Object *ob)
return (md && md->mode&(eModifierMode_Realtime|eModifierMode_Render)); return (md && md->mode&(eModifierMode_Realtime|eModifierMode_Render));
} }
ModifierData *modifiers_getVirtualModifierList(Object *ob)
{
/* Kinda hacky, but should be fine since we are never
* reentrant and avoid free hassles.
*/
static ArmatureModifierData amd;
static CurveModifierData cmd;
static LatticeModifierData lmd;
static int init = 1;
if (init) {
ModifierData *md;
md = modifier_new(eModifierType_Armature);
amd = *((ArmatureModifierData*) md);
modifier_free(md);
md = modifier_new(eModifierType_Curve);
cmd = *((CurveModifierData*) md);
modifier_free(md);
md = modifier_new(eModifierType_Lattice);
lmd = *((LatticeModifierData*) md);
modifier_free(md);
amd.modifier.mode |= eModifierMode_Virtual;
cmd.modifier.mode |= eModifierMode_Virtual;
lmd.modifier.mode |= eModifierMode_Virtual;
init = 0;
}
if (ob->parent) {
if(ob->parent->type==OB_ARMATURE && ob->partype==PARSKEL) {
amd.object = ob->parent;
amd.modifier.next = ob->modifiers.first;
return &amd.modifier;
} else if(ob->parent->type==OB_CURVE && ob->partype==PARSKEL) {
cmd.object = ob->parent;
cmd.modifier.next = ob->modifiers.first;
return &cmd.modifier;
} else if(ob->parent->type==OB_LATTICE && ob->partype==PARSKEL) {
lmd.object = ob->parent;
lmd.modifier.next = ob->modifiers.first;
return &lmd.modifier;
}
}
return ob->modifiers.first;
}

View File

@@ -4801,6 +4801,10 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
where_is_armature(arm); where_is_armature(arm);
} }
for(ob= main->object.first; ob; ob= ob->id.next) { for(ob= main->object.first; ob; ob= ob->id.next) {
if (ob->parent && ob->parent->type==OB_LATTICE) {
ob->partype = PARSKEL;
}
if (ob->softflag&OB_SB_ENABLE) { if (ob->softflag&OB_SB_ENABLE) {
if (ob->softflag&OB_SB_POSTDEF) { if (ob->softflag&OB_SB_POSTDEF) {
ModifierData *md = ob->modifiers.first; ModifierData *md = ob->modifiers.first;

View File

@@ -31,6 +31,7 @@ typedef enum ModifierMode {
eModifierMode_Editmode = (1<<2), eModifierMode_Editmode = (1<<2),
eModifierMode_OnCage = (1<<3), eModifierMode_OnCage = (1<<3),
eModifierMode_Expanded = (1<<4), eModifierMode_Expanded = (1<<4),
eModifierMode_Virtual = (1<<5),
} ModifierMode; } ModifierMode;
typedef struct ModifierData { typedef struct ModifierData {

View File

@@ -786,12 +786,33 @@ static void modifiers_clearHookOffset(void *ob_v, void *md_v)
} }
} }
static void modifiers_convertToReal(void *ob_v, void *md_v)
{
Object *ob = ob_v;
ModifierData *md = md_v;
ModifierData *nmd = modifier_new(md->type);
modifier_copyData(md, nmd);
nmd->mode &= ~eModifierMode_Virtual;
BLI_addhead(&ob->modifiers, nmd);
ob->partype = PAROBJECT;
}
static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco, int *yco, int index, int cageIndex, int lastCageIndex) static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco, int *yco, int index, int cageIndex, int lastCageIndex)
{ {
ModifierTypeInfo *mti = modifierType_getInfo(md->type); ModifierTypeInfo *mti = modifierType_getInfo(md->type);
uiBut *but; int isVirtual = md->mode&eModifierMode_Virtual;
int x = *xco, y = *yco, color = md->error?TH_REDALERT:TH_BUT_NEUTRAL; int x = *xco, y = *yco, color = md->error?TH_REDALERT:TH_BUT_NEUTRAL;
short height, width = 295; short height, width = 295;
char str[128];
uiBut *but;
if (isVirtual) {
uiSetButLock(1, "Modifier is virtual and cannot be edited.");
color = TH_BUT_SETTING1;
}
uiBlockSetEmboss(block, UI_EMBOSSN); uiBlockSetEmboss(block, UI_EMBOSSN);
uiDefIconButBitI(block, ICONTOG, eModifierMode_Expanded, B_MODIFIER_REDRAW, VICON_DISCLOSURE_TRI_RIGHT, x-10, y-2, 20, 20, &md->mode, 0.0, 0.0, 0.0, 0.0, "Collapse/Expand Modifier"); uiDefIconButBitI(block, ICONTOG, eModifierMode_Expanded, B_MODIFIER_REDRAW, VICON_DISCLOSURE_TRI_RIGHT, x-10, y-2, 20, 20, &md->mode, 0.0, 0.0, 0.0, 0.0, "Collapse/Expand Modifier");
@@ -805,62 +826,72 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco
uiRoundBox(x+4+10, y-18, x+width+10, y+6, 5.0); uiRoundBox(x+4+10, y-18, x+width+10, y+6, 5.0);
BIF_ThemeColor(color); BIF_ThemeColor(color);
uiBlockBeginAlign(block); if (isVirtual) {
uiDefBut(block, TEX, B_MODIFIER_REDRAW, "", x+10, y-1, width-120-60-10, 19, md->name, 0.0, sizeof(md->name)-1, 0.0, 0.0, "Modifier name"); sprintf(str, "%s (virtual)", md->name);
uiDefBut(block, LABEL, 0, str, x+10, y-1, width-120-60-10, 19, NULL, 0.0, 0.0, 0.0, 0.0, "Modifier name");
/* Softbody not allowed in this situation, enforce! */ uiClearButLock();
if (md->type!=eModifierType_Softbody || !(ob->pd && ob->pd->deflect)) {
uiDefIconButBitI(block, TOG, eModifierMode_Render, B_MODIFIER_RECALC, ICON_SCENE, x+width-120-60, y-1, 19, 19,&md->mode, 0, 0, 1, 0, "Enable modifier during rendering"); but = uiDefBut(block, BUT, B_MODIFIER_RECALC, "Make Real", x+width-80, y, 60, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Convert virtual modifier to a real modifier");
uiDefIconButBitI(block, TOG, eModifierMode_Realtime, B_MODIFIER_RECALC, VICON_VIEW3D, x+width-120-60+20, y-1, 19, 19,&md->mode, 0, 0, 1, 0, "Enable modifier during interactive display"); uiButSetFunc(but, modifiers_convertToReal, ob, md);
if (mti->flags&eModifierTypeFlag_SupportsEditmode) { uiSetButLock(1, "Modifier is virtual and cannot be edited.");
uiDefIconButBitI(block, TOG, eModifierMode_Editmode, B_MODIFIER_RECALC, VICON_EDIT, x+width-120-60+40, y-1, 19, 19,&md->mode, 0, 0, 1, 0, "Enable modifier during Editmode (only if enabled for display)"); } else {
uiBlockBeginAlign(block);
uiDefBut(block, TEX, B_MODIFIER_REDRAW, "", x+10, y-1, width-120-60-10, 19, md->name, 0.0, sizeof(md->name)-1, 0.0, 0.0, "Modifier name");
/* Softbody not allowed in this situation, enforce! */
if (md->type!=eModifierType_Softbody || !(ob->pd && ob->pd->deflect)) {
uiDefIconButBitI(block, TOG, eModifierMode_Render, B_MODIFIER_RECALC, ICON_SCENE, x+width-120-60, y-1, 19, 19,&md->mode, 0, 0, 1, 0, "Enable modifier during rendering");
uiDefIconButBitI(block, TOG, eModifierMode_Realtime, B_MODIFIER_RECALC, VICON_VIEW3D, x+width-120-60+20, y-1, 19, 19,&md->mode, 0, 0, 1, 0, "Enable modifier during interactive display");
if (mti->flags&eModifierTypeFlag_SupportsEditmode) {
uiDefIconButBitI(block, TOG, eModifierMode_Editmode, B_MODIFIER_RECALC, VICON_EDIT, x+width-120-60+40, y-1, 19, 19,&md->mode, 0, 0, 1, 0, "Enable modifier during Editmode (only if enabled for display)");
}
} }
} uiBlockEndAlign(block);
uiBlockEndAlign(block);
uiBlockSetEmboss(block, UI_EMBOSSR); uiBlockSetEmboss(block, UI_EMBOSSR);
if (modifier_couldBeCage(md) && index<=lastCageIndex) { if (modifier_couldBeCage(md) && index<=lastCageIndex) {
int icon, color; int icon, color;
uiSetRoundBox(15); uiSetRoundBox(15);
if (index==cageIndex) { if (index==cageIndex) {
color = TH_BUT_SETTING; color = TH_BUT_SETTING;
icon = VICON_EDITMODE_HLT; icon = VICON_EDITMODE_HLT;
} else if (index<cageIndex) { } else if (index<cageIndex) {
color = TH_BUT_NEUTRAL; color = TH_BUT_NEUTRAL;
icon = VICON_EDITMODE_DEHLT; icon = VICON_EDITMODE_DEHLT;
} else { } else {
color = TH_BUT_NEUTRAL; color = TH_BUT_NEUTRAL;
icon = ICON_BLANK1; icon = ICON_BLANK1;
}
uiBlockSetCol(block, color);
but = uiDefIconBut(block, BUT, B_MODIFIER_RECALC, icon, x+width-105, y, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Apply modifier to editing cage during Editmode");
uiButSetFunc(but, modifiers_setOnCage, ob, md);
uiBlockSetCol(block, TH_AUTO);
} }
uiBlockSetCol(block, color);
but = uiDefIconBut(block, BUT, B_MODIFIER_RECALC, icon, x+width-105, y, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Apply modifier to editing cage during Editmode"); uiBlockSetCol(block, TH_BUT_ACTION);
uiButSetFunc(but, modifiers_setOnCage, ob, md);
but = uiDefIconBut(block, BUT, B_MODIFIER_RECALC, VICON_MOVE_UP, x+width-70, y, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Move modifier up in stack");
uiButSetFunc(but, modifiers_moveUp, ob, md);
but = uiDefIconBut(block, BUT, B_MODIFIER_RECALC, VICON_MOVE_DOWN, x+width-70+20, y, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Move modifier down in stack");
uiButSetFunc(but, modifiers_moveDown, ob, md);
uiBlockSetEmboss(block, UI_EMBOSSN);
but = uiDefIconBut(block, BUT, B_MODIFIER_RECALC, VICON_X, x+width-70+40, y, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Delete modifier");
uiButSetFunc(but, modifiers_del, ob, md);
uiBlockSetCol(block, TH_AUTO); uiBlockSetCol(block, TH_AUTO);
} }
uiBlockSetCol(block, TH_BUT_ACTION);
but = uiDefIconBut(block, BUT, B_MODIFIER_RECALC, VICON_MOVE_UP, x+width-70, y, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Move modifier up in stack");
uiButSetFunc(but, modifiers_moveUp, ob, md);
but = uiDefIconBut(block, BUT, B_MODIFIER_RECALC, VICON_MOVE_DOWN, x+width-70+20, y, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Move modifier down in stack");
uiButSetFunc(but, modifiers_moveDown, ob, md);
uiBlockSetEmboss(block, UI_EMBOSSN);
but = uiDefIconBut(block, BUT, B_MODIFIER_RECALC, VICON_X, x+width-70+40, y, 16, 16, NULL, 0.0, 0.0, 0.0, 0.0, "Delete modifier");
uiButSetFunc(but, modifiers_del, ob, md);
uiBlockSetCol(block, TH_AUTO);
BIF_ThemeColor(color); BIF_ThemeColor(color);
uiBlockSetEmboss(block, UI_EMBOSS); uiBlockSetEmboss(block, UI_EMBOSS);
if (!(md->mode&eModifierMode_Expanded)) { if (!(md->mode&eModifierMode_Expanded)) {
y -= 18; y -= 18;
} else { } else {
char str[128];
int cy = y - 8; int cy = y - 8;
int lx = x + width - 60 - 15; int lx = x + width - 60 - 15;
@@ -892,14 +923,16 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco
uiSetRoundBox(12); uiSetRoundBox(12);
uiRoundBox(x+4+10, y-height, x+width+10, y, 5.0); uiRoundBox(x+4+10, y-height, x+width+10, y, 5.0);
uiBlockBeginAlign(block); if (!isVirtual) {
but = uiDefBut(block, BUT, B_MODIFIER_RECALC, "Apply", lx,(cy-=19),60,19, 0, 0, 0, 0, 0, "Apply the current modifier and remove from the stack"); uiBlockBeginAlign(block);
uiButSetFunc(but, modifiers_applyModifier, ob, md); but = uiDefBut(block, BUT, B_MODIFIER_RECALC, "Apply", lx,(cy-=19),60,19, 0, 0, 0, 0, 0, "Apply the current modifier and remove from the stack");
if (md->type!=eModifierType_Softbody) { uiButSetFunc(but, modifiers_applyModifier, ob, md);
but = uiDefBut(block, BUT, B_MODIFIER_RECALC, "Copy", lx,(cy-=19),60,19, 0, 0, 0, 0, 0, "Duplicate the current modifier at the same position in the stack"); if (md->type!=eModifierType_Softbody) {
uiButSetFunc(but, modifiers_copyModifier, ob, md); but = uiDefBut(block, BUT, B_MODIFIER_RECALC, "Copy", lx,(cy-=19),60,19, 0, 0, 0, 0, 0, "Duplicate the current modifier at the same position in the stack");
uiButSetFunc(but, modifiers_copyModifier, ob, md);
}
uiBlockEndAlign(block);
} }
uiBlockEndAlign(block);
// uiDefButBitI(block, TOG, eModifierMode_Render, B_MODIFIER_RECALC, "Render", lx,(cy-=19),60,19,&md->mode, 0, 0, 1, 0, "Enable modifier during rendering"); // uiDefButBitI(block, TOG, eModifierMode_Render, B_MODIFIER_RECALC, "Render", lx,(cy-=19),60,19,&md->mode, 0, 0, 1, 0, "Enable modifier during rendering");
// uiDefButBitI(block, TOG, eModifierMode_Realtime, B_MODIFIER_RECALC, "3D View", lx,(cy-=19),60,19,&md->mode, 0, 0, 1, 0, "Enable modifier during interactive display"); // uiDefButBitI(block, TOG, eModifierMode_Realtime, B_MODIFIER_RECALC, "3D View", lx,(cy-=19),60,19,&md->mode, 0, 0, 1, 0, "Enable modifier during interactive display");
@@ -997,6 +1030,10 @@ static void draw_modifier(uiBlock *block, Object *ob, ModifierData *md, int *xco
*xco = x; *xco = x;
*yco = y; *yco = y;
if (isVirtual) {
uiClearButLock();
}
} }
static void editing_panel_modifiers(Object *ob) static void editing_panel_modifiers(Object *ob)
@@ -1019,8 +1056,10 @@ static void editing_panel_modifiers(Object *ob)
xco = 0; xco = 0;
yco = 160; yco = 160;
md = modifiers_getVirtualModifierList(ob);
uiPanelPush(block); uiPanelPush(block);
for (i=0,md=ob->modifiers.first; md; i++, md=md->next) { for (i=0; md; i++, md=md->next) {
draw_modifier(block, ob, md, &xco, &yco, i, cageIndex, lastCageIndex); draw_modifier(block, ob, md, &xco, &yco, i, cageIndex, lastCageIndex);
} }
uiPanelPop(block); uiPanelPop(block);

View File

@@ -1203,28 +1203,30 @@ void load_editMesh(void)
int i,j; int i,j;
for (ob=G.main->object.first; ob; ob=ob->id.next) { for (ob=G.main->object.first; ob; ob=ob->id.next) {
for (md=ob->modifiers.first; md; md=md->next) { if (ob->data==me) {
if (md->type==eModifierType_Hook) { for (md=ob->modifiers.first; md; md=md->next) {
HookModifierData *hmd = (HookModifierData*) md; if (md->type==eModifierType_Hook) {
HookModifierData *hmd = (HookModifierData*) md;
if (!vertMap) { if (!vertMap) {
vertMap = MEM_callocN(sizeof(*vertMap)*ototvert, "vertMap"); vertMap = MEM_callocN(sizeof(*vertMap)*ototvert, "vertMap");
for (eve=em->verts.first; eve; eve=eve->next) { for (eve=em->verts.first; eve; eve=eve->next) {
if (eve->keyindex!=-1) if (eve->keyindex!=-1)
vertMap[eve->keyindex] = eve; vertMap[eve->keyindex] = eve;
}
} }
}
for (i=j=0; i<hmd->totindex; i++) {
eve = vertMap[hmd->indexar[i]];
if (eve) { for (i=j=0; i<hmd->totindex; i++) {
hmd->indexar[j++] = (long) eve->vn; eve = vertMap[hmd->indexar[i]];
if (eve) {
hmd->indexar[j++] = (long) eve->vn;
}
} }
}
hmd->totindex = j; hmd->totindex = j;
}
} }
} }
} }

View File

@@ -5145,8 +5145,6 @@ void subdivideflag(int flag, float rad, int beauty)
float fac, vec[3], vec1[3], len1, len2, len3, percent; float fac, vec[3], vec1[3], len1, len2, len3, percent;
short test; short test;
printf("in old subdivideflag\n");
if(beauty & B_SMOOTH) { if(beauty & B_SMOOTH) {
short perc= 100; short perc= 100;

View File

@@ -1141,7 +1141,19 @@ void make_parent(void)
qual= G.qual; qual= G.qual;
par= BASACT->object; par= BASACT->object;
if(par->type == OB_CURVE){ if(par->type == OB_LATTICE){
mode= pupmenu("Make Parent %t|Normal Parent %x1|Lattice Deform %x2");
if(mode<=0){
return;
}
else if(mode==1) {
mode= PAROBJECT;
}
else if(mode==2) {
mode= PARSKEL;
}
}
else if(par->type == OB_CURVE){
bConstraint *con; bConstraint *con;
bFollowPathConstraint *data; bFollowPathConstraint *data;
@@ -1303,7 +1315,7 @@ void make_parent(void)
if(qual & LR_ALTKEY) { if(qual & LR_ALTKEY) {
base->object->partype= PARVERT1; base->object->partype= PARVERT1;
} }
else if(par->type==OB_CURVE) { else if(ELEM(par->type, OB_CURVE, OB_LATTICE)) {
base->object->partype= mode; base->object->partype= mode;
} }
else { else {