Blender  V2.59
MOD_shapekey.c
Go to the documentation of this file.
00001 /*
00002 * $Id: MOD_shapekey.c 35178 2011-02-25 13:57:17Z jesterking $
00003 *
00004 * ***** BEGIN GPL LICENSE BLOCK *****
00005 *
00006 * This program is free software; you can redistribute it and/or
00007 * modify it under the terms of the GNU General Public License
00008 * as published by the Free Software Foundation; either version 2
00009 * of the License, or (at your option) any later version.
00010 *
00011 * This program is distributed in the hope that it will be useful,
00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 * GNU General Public License for more details.
00015 *
00016 * You should have received a copy of the GNU General Public License
00017 * along with this program; if not, write to the Free Software  Foundation,
00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 *
00020 * The Original Code is Copyright (C) 2005 by the Blender Foundation.
00021 * All rights reserved.
00022 *
00023 * Contributor(s): Daniel Dunbar
00024 *                 Ton Roosendaal,
00025 *                 Ben Batt,
00026 *                 Brecht Van Lommel,
00027 *                 Campbell Barton
00028 *
00029 * ***** END GPL LICENSE BLOCK *****
00030 *
00031 */
00032 
00038 #include "BLI_math.h"
00039 
00040 #include "DNA_key_types.h"
00041 
00042 #include "BLI_utildefines.h"
00043 
00044 
00045 #include "BKE_cdderivedmesh.h"
00046 #include "BKE_key.h"
00047 #include "BKE_particle.h"
00048 
00049 #include "MOD_modifiertypes.h"
00050 
00051 #include "MEM_guardedalloc.h"
00052 
00053 static void deformVerts(ModifierData *md, Object *ob,
00054                                                 DerivedMesh *UNUSED(derivedData),
00055                                                 float (*vertexCos)[3],
00056                                                 int numVerts,
00057                                                 int UNUSED(useRenderParams),
00058                                                 int UNUSED(isFinalCalc))
00059 {
00060         KeyBlock *kb= ob_get_keyblock(ob);
00061         float (*deformedVerts)[3];
00062 
00063         if(kb && kb->totelem == numVerts) {
00064                 deformedVerts= (float(*)[3])do_ob_key(md->scene, ob);
00065                 if(deformedVerts) {
00066                         memcpy(vertexCos, deformedVerts, sizeof(float)*3*numVerts);
00067                         MEM_freeN(deformedVerts);
00068                 }
00069         }
00070 }
00071 
00072 static void deformMatrices(ModifierData *md, Object *ob, DerivedMesh *derivedData,
00073                                                    float (*vertexCos)[3], float (*defMats)[3][3], int numVerts)
00074 {
00075         Key *key= ob_get_key(ob);
00076         KeyBlock *kb= ob_get_keyblock(ob);
00077         float scale[3][3];
00078 
00079         (void)vertexCos; /* unused */
00080 
00081         if(kb && kb->totelem==numVerts && kb!=key->refkey) {
00082                 int a;
00083 
00084                 if(ob->shapeflag & OB_SHAPE_LOCK) scale_m3_fl(scale, 1);
00085                 else scale_m3_fl(scale, kb->curval);
00086 
00087                 for(a=0; a<numVerts; a++)
00088                         copy_m3_m3(defMats[a], scale);
00089         }
00090 
00091         deformVerts(md, ob, derivedData, vertexCos, numVerts, 0, 0);
00092 }
00093 
00094 static void deformVertsEM(ModifierData *md, Object *ob,
00095                                                 struct EditMesh *UNUSED(editData),
00096                                                 DerivedMesh *derivedData,
00097                                                 float (*vertexCos)[3],
00098                                                 int numVerts)
00099 {
00100         Key *key= ob_get_key(ob);
00101 
00102         if(key && key->type == KEY_RELATIVE)
00103                 deformVerts(md, ob, derivedData, vertexCos, numVerts, 0, 0);
00104 }
00105 
00106 static void deformMatricesEM(ModifierData *UNUSED(md), Object *ob,
00107                                                 struct EditMesh *UNUSED(editData),
00108                                                 DerivedMesh *UNUSED(derivedData),
00109                                                 float (*vertexCos)[3],
00110                                                 float (*defMats)[3][3],
00111                                                 int numVerts)
00112 {
00113         Key *key= ob_get_key(ob);
00114         KeyBlock *kb= ob_get_keyblock(ob);
00115         float scale[3][3];
00116 
00117         (void)vertexCos; /* unused */
00118 
00119         if(kb && kb->totelem==numVerts && kb!=key->refkey) {
00120                 int a;
00121                 scale_m3_fl(scale, kb->curval);
00122 
00123                 for(a=0; a<numVerts; a++)
00124                         copy_m3_m3(defMats[a], scale);
00125         }
00126 }
00127 
00128 ModifierTypeInfo modifierType_ShapeKey = {
00129         /* name */              "ShapeKey",
00130         /* structName */        "ShapeKeyModifierData",
00131         /* structSize */        sizeof(ShapeKeyModifierData),
00132         /* type */              eModifierTypeType_OnlyDeform,
00133         /* flags */             eModifierTypeFlag_AcceptsCVs
00134                                                         | eModifierTypeFlag_SupportsEditmode,
00135 
00136         /* copyData */          NULL,
00137         /* deformVerts */       deformVerts,
00138         /* deformMatrices */    deformMatrices,
00139         /* deformVertsEM */     deformVertsEM,
00140         /* deformMatricesEM */  deformMatricesEM,
00141         /* applyModifier */     NULL,
00142         /* applyModifierEM */   NULL,
00143         /* initData */          NULL,
00144         /* requiredDataMask */  NULL,
00145         /* freeData */          NULL,
00146         /* isDisabled */        NULL,
00147         /* updateDepgraph */    NULL,
00148         /* dependsOnTime */     NULL,
00149         /* dependsOnNormals */  NULL,
00150         /* foreachObjectLink */ NULL,
00151         /* foreachIDLink */     NULL
00152 };