Blender V2.61 - r43446

MOD_curve.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_scene_types.h"
00039 #include "DNA_object_types.h"
00040 
00041 #include "BLI_utildefines.h"
00042 #include "BLI_string.h"
00043 
00044 
00045 #include "BKE_cdderivedmesh.h"
00046 #include "BKE_lattice.h"
00047 #include "BKE_modifier.h"
00048 
00049 #include "depsgraph_private.h"
00050 
00051 #include "MOD_util.h"
00052 
00053 static void initData(ModifierData *md)
00054 {
00055     CurveModifierData *cmd = (CurveModifierData*) md;
00056 
00057     cmd->defaxis = MOD_CURVE_POSX;
00058 }
00059 
00060 static void copyData(ModifierData *md, ModifierData *target)
00061 {
00062     CurveModifierData *cmd = (CurveModifierData*) md;
00063     CurveModifierData *tcmd = (CurveModifierData*) target;
00064 
00065     tcmd->defaxis = cmd->defaxis;
00066     tcmd->object = cmd->object;
00067     BLI_strncpy(tcmd->name, cmd->name, sizeof(tcmd->name));
00068 }
00069 
00070 static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
00071 {
00072     CurveModifierData *cmd = (CurveModifierData *)md;
00073     CustomDataMask dataMask = 0;
00074 
00075     /* ask for vertexgroups if we need them */
00076     if(cmd->name[0]) dataMask |= CD_MASK_MDEFORMVERT;
00077 
00078     return dataMask;
00079 }
00080 
00081 static int isDisabled(ModifierData *md, int UNUSED(userRenderParams))
00082 {
00083     CurveModifierData *cmd = (CurveModifierData*) md;
00084 
00085     return !cmd->object;
00086 }
00087 
00088 static void foreachObjectLink(
00089                         ModifierData *md, Object *ob,
00090      void (*walk)(void *userData, Object *ob, Object **obpoin),
00091         void *userData)
00092 {
00093     CurveModifierData *cmd = (CurveModifierData*) md;
00094 
00095     walk(userData, ob, &cmd->object);
00096 }
00097 
00098 static void updateDepgraph(ModifierData *md, DagForest *forest,
00099                         Scene *UNUSED(scene),
00100                         Object *UNUSED(ob),
00101                         DagNode *obNode)
00102 {
00103     CurveModifierData *cmd = (CurveModifierData*) md;
00104 
00105     if (cmd->object) {
00106         DagNode *curNode = dag_get_node(forest, cmd->object);
00107 
00108         dag_add_relation(forest, curNode, obNode,
00109                          DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Curve Modifier");
00110     }
00111 }
00112 
00113 static void deformVerts(ModifierData *md, Object *ob,
00114                         DerivedMesh *derivedData,
00115                         float (*vertexCos)[3],
00116                         int numVerts,
00117                         int UNUSED(useRenderParams),
00118                         int UNUSED(isFinalCalc))
00119 {
00120     CurveModifierData *cmd = (CurveModifierData*) md;
00121 
00122     curve_deform_verts(md->scene, cmd->object, ob, derivedData, vertexCos, numVerts,
00123                        cmd->name, cmd->defaxis);
00124 }
00125 
00126 static void deformVertsEM(
00127                     ModifierData *md, Object *ob, struct EditMesh *editData,
00128      DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
00129 {
00130     DerivedMesh *dm = derivedData;
00131 
00132     if(!derivedData) dm = CDDM_from_editmesh(editData, ob->data);
00133 
00134     deformVerts(md, ob, dm, vertexCos, numVerts, 0, 0);
00135 
00136     if(!derivedData) dm->release(dm);
00137 }
00138 
00139 
00140 ModifierTypeInfo modifierType_Curve = {
00141     /* name */              "Curve",
00142     /* structName */        "CurveModifierData",
00143     /* structSize */        sizeof(CurveModifierData),
00144     /* type */              eModifierTypeType_OnlyDeform,
00145     /* flags */             eModifierTypeFlag_AcceptsCVs
00146                             | eModifierTypeFlag_SupportsEditmode,
00147 
00148     /* copyData */          copyData,
00149     /* deformVerts */       deformVerts,
00150     /* deformMatrices */    NULL,
00151     /* deformVertsEM */     deformVertsEM,
00152     /* deformMatricesEM */  NULL,
00153     /* applyModifier */     NULL,
00154     /* applyModifierEM */   NULL,
00155     /* initData */          initData,
00156     /* requiredDataMask */  requiredDataMask,
00157     /* freeData */          NULL,
00158     /* isDisabled */        isDisabled,
00159     /* updateDepgraph */    updateDepgraph,
00160     /* dependsOnTime */     NULL,
00161     /* dependsOnNormals */  NULL,
00162     /* foreachObjectLink */ foreachObjectLink,
00163     /* foreachIDLink */     NULL,
00164     /* foreachTexLink */    NULL,
00165 };