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