- split {curve,lattice,armature}_deform_verts out of mesh_deform

- removed mesh_deform (merge into mesh_modifier)
 - switch python lattice_apply function to use object_apply_deform,
   this isn't exactly equivalent but the python system shouldn't
   have been calling that deep into the kernel anyway.

New feature: Modifier stack
 - added Object.modifiers (list of ModifierData elements)
 - added DNA_modifier_types.h
     o contains type definition for the file data for the various
       modifier types
 - added BKE_modifier.h
     o contains modifierType_get_info (access to modifier type registry)
     o structs and defines for runtime modifier usage
 - updated mesh_calc_modifiers to evaluate modifier stack (note that
   for the time being it also evaluates the old style modifiers so files
   should load and work as normal).
 - add file handling modifier code (todo: don't replicate on object copy)
 - add modifier stack UI code (lives in object panel)


Only real new feature at the moment is that you can apply lattices and
curves *after* a subdivision surface which was never possible before.

Todo:
 - DEP graph updating does not work correctly yet, so you generally have
   to tab cycle to see results.
 - editmode calculation does not use modifier stack.
 - bug fixes (there must be a few in there somewhere)
This commit is contained in:
2005-07-19 20:14:17 +00:00
parent f1763b2f08
commit 1df154d140
17 changed files with 830 additions and 103 deletions

View File

@@ -0,0 +1,181 @@
#include "string.h"
#include "MEM_guardedalloc.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_modifier_types.h"
#include "DNA_object_types.h"
#include "BKE_utildefines.h"
#include "BKE_DerivedMesh.h"
#include "BKE_displist.h"
#include "BKE_modifier.h"
#include "BKE_lattice.h"
#include "BKE_subsurf.h"
/***/
static void *allocModifierData(int type, int size)
{
ModifierData *md = MEM_callocN(size, "md");
md->type = type;
md->mode = eModifierMode_RealtimeAndRender;
return md;
}
static ModifierData *noneModifier_allocData(void)
{
return allocModifierData(eModifierType_None, sizeof(ModifierData));
}
static int noneModifier_isDisabled(ModifierData *md)
{
return 1;
}
/* Curve */
static ModifierData *curveModifier_allocData(void)
{
return allocModifierData(eModifierType_Curve, sizeof(CurveModifierData));
}
static int curveModifier_isDisabled(ModifierData *md)
{
CurveModifierData *cmd = (CurveModifierData*) md;
return !cmd->object;
}
static void curveModifier_deformVerts(ModifierData *md, Object *ob, float (*vertexCos)[3], int numVerts)
{
CurveModifierData *cmd = (CurveModifierData*) md;
curve_deform_verts(cmd->object, ob, vertexCos, numVerts);
}
/* Lattice */
static ModifierData *latticeModifier_allocData(void)
{
return allocModifierData(eModifierType_Lattice, sizeof(LatticeModifierData));
}
static int latticeModifier_isDisabled(ModifierData *md)
{
LatticeModifierData *lmd = (LatticeModifierData*) md;
return !lmd->object;
}
static void latticeModifier_deformVerts(ModifierData *md, Object *ob, float (*vertexCos)[3], int numVerts)
{
LatticeModifierData *lmd = (LatticeModifierData*) md;
lattice_deform_verts(lmd->object, ob, vertexCos, numVerts);
}
/* Subsurf */
static ModifierData *subsurfModifier_allocData(void)
{
SubsurfModifierData *smd = allocModifierData(eModifierType_Subsurf, sizeof(SubsurfModifierData));
smd->levels = 1;
smd->renderLevels = 2;
return (ModifierData*) smd;
}
static int subsurfModifier_isDisabled(ModifierData *md)
{
return 0;
}
static void *subsurfModifier_applyModifier(ModifierData *md, void *data, Object *ob, DerivedMesh *dm, float (*vertexCos)[3], int useRenderParams)
{
SubsurfModifierData *smd = (SubsurfModifierData*) md;
int levels = useRenderParams?smd->renderLevels:smd->levels;
Mesh *me = data;
if (dm) {
DispListMesh *dlm = dm->convertToDispListMesh(dm); // XXX what if verts were shared
int i;
if (vertexCos) {
int numVerts = dm->getNumVerts(dm);
for (i=0; i<numVerts; i++) {
VECCOPY(dlm->mvert[i].co, vertexCos[i]);
}
}
dm->release(dm);
dm = subsurf_make_derived_from_dlm(dlm, smd->subdivType, levels);
displistmesh_free(dlm);
return dm;
} else {
return subsurf_make_derived_from_mesh(me, smd->subdivType, levels, vertexCos);
}
}
/***/
static ModifierTypeInfo typeArr[NUM_MODIFIER_TYPES];
static int typeArrInit = 1;
ModifierTypeInfo *modifierType_get_info(ModifierType type)
{
if (typeArrInit) {
ModifierTypeInfo *mti;
memset(typeArr, 0, sizeof(typeArr));
mti = &typeArr[eModifierType_None];
strcpy(mti->name, "None");
strcpy(mti->structName, "ModifierData");
mti->type = eModifierType_None;
mti->flags = eModifierTypeFlag_AcceptsMesh|eModifierTypeFlag_AcceptsCVs;
mti->allocData = noneModifier_allocData;
mti->isDisabled = noneModifier_isDisabled;
mti = &typeArr[eModifierType_Curve];
strcpy(mti->name, "Curve");
strcpy(mti->structName, "CurveModifierData");
mti->type = eModifierTypeType_OnlyDeform;
mti->flags = eModifierTypeFlag_AcceptsCVs;
mti->allocData = curveModifier_allocData;
mti->isDisabled = curveModifier_isDisabled;
mti->deformVerts = curveModifier_deformVerts;
mti = &typeArr[eModifierType_Lattice];
strcpy(mti->name, "Lattice");
strcpy(mti->structName, "LatticeModifierData");
mti->type = eModifierTypeType_OnlyDeform;
mti->flags = eModifierTypeFlag_AcceptsCVs;
mti->allocData = latticeModifier_allocData;
mti->isDisabled = latticeModifier_isDisabled;
mti->deformVerts = latticeModifier_deformVerts;
mti = &typeArr[eModifierType_Subsurf];
strcpy(mti->name, "Subsurf");
strcpy(mti->structName, "SubsurfModifierData");
mti->type = eModifierTypeType_Constructive;
mti->flags = eModifierTypeFlag_AcceptsMesh|eModifierTypeFlag_SupportsMapping;
mti->allocData = subsurfModifier_allocData;
mti->isDisabled = subsurfModifier_isDisabled;
mti->applyModifier = subsurfModifier_applyModifier;
typeArrInit = 0;
}
if (type>=0 && type<NUM_MODIFIER_TYPES && typeArr[type].name[0]!='\0') {
return &typeArr[type];
} else {
return NULL;
}
}