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