Blender V2.61 - r43446

MOD_armature.c

Go to the documentation of this file.
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 <string.h>
00037 
00038 #include "DNA_armature_types.h"
00039 #include "DNA_object_types.h"
00040 #include "DNA_mesh_types.h"
00041 
00042 #include "BLI_utildefines.h"
00043 #include "BLI_string.h"
00044 
00045 
00046 #include "BKE_cdderivedmesh.h"
00047 #include "BKE_lattice.h"
00048 #include "BKE_modifier.h"
00049 
00050 #include "MEM_guardedalloc.h"
00051 
00052 #include "depsgraph_private.h"
00053 
00054 #include "MOD_util.h"
00055 
00056 
00057 static void initData(ModifierData *md)
00058 {
00059     ArmatureModifierData *amd = (ArmatureModifierData*) md;
00060     
00061     amd->deformflag = ARM_DEF_ENVELOPE | ARM_DEF_VGROUP;
00062 }
00063 
00064 static void copyData(ModifierData *md, ModifierData *target)
00065 {
00066     ArmatureModifierData *amd = (ArmatureModifierData*) md;
00067     ArmatureModifierData *tamd = (ArmatureModifierData*) target;
00068 
00069     tamd->object = amd->object;
00070     tamd->deformflag = amd->deformflag;
00071     tamd->multi = amd->multi;
00072     BLI_strncpy(tamd->defgrp_name, amd->defgrp_name, sizeof(tamd->defgrp_name));
00073 }
00074 
00075 static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *UNUSED(md))
00076 {
00077     CustomDataMask dataMask = 0;
00078 
00079     /* ask for vertexgroups */
00080     dataMask |= CD_MASK_MDEFORMVERT;
00081 
00082     return dataMask;
00083 }
00084 
00085 static int isDisabled(ModifierData *md, int UNUSED(useRenderParams))
00086 {
00087     ArmatureModifierData *amd = (ArmatureModifierData*) md;
00088 
00089     return !amd->object;
00090 }
00091 
00092 static void foreachObjectLink(
00093                            ModifierData *md, Object *ob,
00094         void (*walk)(void *userData, Object *ob, Object **obpoin),
00095            void *userData)
00096 {
00097     ArmatureModifierData *amd = (ArmatureModifierData*) md;
00098 
00099     walk(userData, ob, &amd->object);
00100 }
00101 
00102 static void updateDepgraph(ModifierData *md, DagForest *forest,
00103                         struct Scene *UNUSED(scene),
00104                         Object *UNUSED(ob),
00105                         DagNode *obNode)
00106 {
00107     ArmatureModifierData *amd = (ArmatureModifierData*) md;
00108 
00109     if (amd->object) {
00110         DagNode *curNode = dag_get_node(forest, amd->object);
00111 
00112         dag_add_relation(forest, curNode, obNode,
00113                          DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Armature Modifier");
00114     }
00115 }
00116 
00117 static void deformVerts(ModifierData *md, Object *ob,
00118                         DerivedMesh *derivedData,
00119                         float (*vertexCos)[3],
00120                         int numVerts,
00121                         int UNUSED(useRenderParams),
00122                         int UNUSED(isFinalCalc))
00123 {
00124     ArmatureModifierData *amd = (ArmatureModifierData*) md;
00125 
00126     modifier_vgroup_cache(md, vertexCos); /* if next modifier needs original vertices */
00127     
00128     armature_deform_verts(amd->object, ob, derivedData, vertexCos, NULL,
00129         numVerts, amd->deformflag, (float(*)[3])amd->prevCos, amd->defgrp_name);
00130 
00131     /* free cache */
00132     if(amd->prevCos) {
00133         MEM_freeN(amd->prevCos);
00134         amd->prevCos= NULL;
00135     }
00136 }
00137 
00138 static void deformVertsEM(
00139                        ModifierData *md, Object *ob, struct EditMesh *editData,
00140     DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
00141 {
00142     ArmatureModifierData *amd = (ArmatureModifierData*) md;
00143     DerivedMesh *dm = derivedData;
00144 
00145     if(!derivedData) dm = CDDM_from_editmesh(editData, ob->data);
00146 
00147     modifier_vgroup_cache(md, vertexCos); /* if next modifier needs original vertices */
00148 
00149     armature_deform_verts(amd->object, ob, dm, vertexCos, NULL,
00150         numVerts, amd->deformflag, (float(*)[3])amd->prevCos, amd->defgrp_name);
00151 
00152     /* free cache */
00153     if(amd->prevCos) {
00154         MEM_freeN(amd->prevCos);
00155         amd->prevCos= NULL;
00156     }
00157 
00158     if(!derivedData) dm->release(dm);
00159 }
00160 
00161 static void deformMatricesEM(
00162                           ModifierData *md, Object *ob, struct EditMesh *editData,
00163        DerivedMesh *derivedData, float (*vertexCos)[3],
00164                          float (*defMats)[3][3], int numVerts)
00165 {
00166     ArmatureModifierData *amd = (ArmatureModifierData*) md;
00167     DerivedMesh *dm = derivedData;
00168 
00169     if(!derivedData) dm = CDDM_from_editmesh(editData, ob->data);
00170 
00171     armature_deform_verts(amd->object, ob, dm, vertexCos, defMats, numVerts,
00172                           amd->deformflag, NULL, amd->defgrp_name);
00173 
00174     if(!derivedData) dm->release(dm);
00175 }
00176 
00177 static void deformMatrices(ModifierData *md, Object *ob, DerivedMesh *derivedData,
00178                            float (*vertexCos)[3], float (*defMats)[3][3], int numVerts)
00179 {
00180     ArmatureModifierData *amd = (ArmatureModifierData*) md;
00181     DerivedMesh *dm = derivedData;
00182 
00183     if(!derivedData) dm = CDDM_from_mesh((Mesh*)ob->data, ob);
00184 
00185     armature_deform_verts(amd->object, ob, dm, vertexCos, defMats, numVerts,
00186                           amd->deformflag, NULL, amd->defgrp_name);
00187 
00188     if(!derivedData) dm->release(dm);
00189 }
00190 
00191 ModifierTypeInfo modifierType_Armature = {
00192     /* name */              "Armature",
00193     /* structName */        "ArmatureModifierData",
00194     /* structSize */        sizeof(ArmatureModifierData),
00195     /* type */              eModifierTypeType_OnlyDeform,
00196     /* flags */             eModifierTypeFlag_AcceptsCVs
00197                             | eModifierTypeFlag_SupportsEditmode,
00198 
00199     /* copyData */          copyData,
00200     /* deformVerts */       deformVerts,
00201     /* deformMatrices */    deformMatrices,
00202     /* deformVertsEM */     deformVertsEM,
00203     /* deformMatricesEM */  deformMatricesEM,
00204     /* applyModifier */     NULL,
00205     /* applyModifierEM */   NULL,
00206     /* initData */          initData,
00207     /* requiredDataMask */  requiredDataMask,
00208     /* freeData */          NULL,
00209     /* isDisabled */        isDisabled,
00210     /* updateDepgraph */    updateDepgraph,
00211     /* dependsOnTime */     NULL,
00212     /* dependsOnNormals */  NULL,
00213     /* foreachObjectLink */ foreachObjectLink,
00214     /* foreachIDLink */     NULL,
00215     /* foreachTexLink */    NULL,
00216 };