diff options
author | Matt Ebb <matt@mke3.net> | 2009-11-22 16:44:09 +0300 |
---|---|---|
committer | Matt Ebb <matt@mke3.net> | 2009-11-22 16:44:09 +0300 |
commit | 8be7b757e3a467e464f59d2de42ccac85d2cc47d (patch) | |
tree | 5760eacb5db3bf1c025680e96cd8379c2249177a /source/blender/blenkernel | |
parent | 8fdaa263c0a2e9e85a86aa9ef5159b1554bc9aab (diff) |
* New option on modifiers that don't change topology: Apply as Shape
Rather than applying the modifier to the object data, it will create a new shape
with the deformed vertices in there. Only mesh at the moment, other object
types on the todo.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_DerivedMesh.h | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_key.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_modifier.h | 1 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/DerivedMesh.c | 20 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/key.c | 43 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/modifier.c | 6 |
6 files changed, 76 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h index 076747cb845..514411e137d 100644 --- a/source/blender/blenkernel/BKE_DerivedMesh.h +++ b/source/blender/blenkernel/BKE_DerivedMesh.h @@ -54,6 +54,7 @@ struct Object; struct Scene; struct Mesh; struct EditMesh; +struct KeyBlock; struct ModifierData; struct MCol; struct ColorBand; @@ -318,6 +319,10 @@ int DM_release(DerivedMesh *dm); */ void DM_to_mesh(DerivedMesh *dm, struct Mesh *me); +/* utility function to convert a DerivedMesh to a shape key block + */ +void DM_to_meshkey(DerivedMesh *dm, struct Mesh *me, struct KeyBlock *kb); + /* set the CD_FLAG_NOCOPY flag in custom data layers where the mask is * zero for the layer type, so only layer types specified by the mask * will be copied diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h index c81d837689f..d5bae00d32e 100644 --- a/source/blender/blenkernel/BKE_key.h +++ b/source/blender/blenkernel/BKE_key.h @@ -59,6 +59,7 @@ void key_curve_normal_weights(float t, float *data, int type); float *do_ob_key(struct Scene *scene, struct Object *ob); struct Key *ob_get_key(struct Object *ob); +struct KeyBlock *add_keyblock(struct Scene *scene, struct Key *key); struct KeyBlock *ob_get_keyblock(struct Object *ob); struct KeyBlock *ob_get_reference_keyblock(struct Object *ob); struct KeyBlock *key_get_keyblock(struct Key *key, int index); diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h index 245db7e35ff..c30bfa3e247 100644 --- a/source/blender/blenkernel/BKE_modifier.h +++ b/source/blender/blenkernel/BKE_modifier.h @@ -281,6 +281,7 @@ int modifier_dependsOnTime(struct ModifierData *md); int modifier_supportsMapping(struct ModifierData *md); int modifier_couldBeCage(struct ModifierData *md); int modifier_isDeformer(struct ModifierData *md); +int modifier_sameTopology(ModifierData *md); int modifier_isEnabled(struct ModifierData *md, int required_mode); void modifier_setError(struct ModifierData *md, char *format, ...); diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c index f9abaa9da02..209e4610c6a 100644 --- a/source/blender/blenkernel/intern/DerivedMesh.c +++ b/source/blender/blenkernel/intern/DerivedMesh.c @@ -277,6 +277,26 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me) *me = tmp; } +void DM_to_meshkey(DerivedMesh *dm, Mesh *me, KeyBlock *kb) +{ + int a, totvert = dm->getNumVerts(dm); + float *fp; + MVert *mvert; + + if(totvert==0 || me->totvert==0 || me->totvert!=totvert) return; + + if(kb->data) MEM_freeN(kb->data); + kb->data= MEM_callocN(me->key->elemsize*me->totvert, "kb->data"); + kb->totelem= totvert; + + fp= kb->data; + mvert=dm->getVertDataArray(dm, CD_MVERT); + + for(a=0; a<kb->totelem; a++, fp+=3, mvert++) { + VECCOPY(fp, mvert->co); + } +} + void DM_set_only_copy(DerivedMesh *dm, CustomDataMask mask) { CustomData_set_only_copy(&dm->vertData, mask); diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index 3822e0322f7..c7b79756263 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -1395,6 +1395,49 @@ Key *ob_get_key(Object *ob) return NULL; } +KeyBlock *add_keyblock(Scene *scene, Key *key) +{ + KeyBlock *kb; + float curpos= -0.1; + int tot; + + kb= key->block.last; + if(kb) curpos= kb->pos; + + kb= MEM_callocN(sizeof(KeyBlock), "Keyblock"); + BLI_addtail(&key->block, kb); + kb->type= KEY_CARDINAL; + + tot= BLI_countlist(&key->block); + if(tot==1) strcpy(kb->name, "Basis"); + else sprintf(kb->name, "Key %d", tot-1); + + // XXX this is old anim system stuff? (i.e. the 'index' of the shapekey) + kb->adrcode= tot-1; + + key->totkey++; + if(key->totkey==1) key->refkey= kb; + + kb->slidermin= 0.0f; + kb->slidermax= 1.0f; + + // XXX kb->pos is the confusing old horizontal-line RVK crap in old IPO Editor... + if(key->type == KEY_RELATIVE) + kb->pos= curpos+0.1; + else { +#if 0 // XXX old animation system + curpos= bsystem_time(scene, 0, (float)CFRA, 0.0); + if(calc_ipo_spec(key->ipo, KEY_SPEED, &curpos)==0) { + curpos /= 100.0; + } + kb->pos= curpos; + + sort_keys(key); +#endif // XXX old animation system + } + return kb; +} + /* only the active keyblock */ KeyBlock *ob_get_keyblock(Object *ob) { diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index ed7fbe58ea4..b5e0ca9ea5c 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -8924,6 +8924,12 @@ int modifier_couldBeCage(ModifierData *md) modifier_supportsMapping(md)); } +int modifier_sameTopology(ModifierData *md) +{ + ModifierTypeInfo *mti = modifierType_getInfo(md->type); + return ( mti->type == eModifierTypeType_OnlyDeform || mti->type == eModifierTypeType_Nonconstructive); +} + void modifier_setError(ModifierData *md, char *format, ...) { char buffer[2048]; |