|
Blender
V2.59
|
00001 /* 00002 * $Id: MOD_lattice.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_object_types.h" 00041 00042 #include "BLI_utildefines.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 00054 static void copyData(ModifierData *md, ModifierData *target) 00055 { 00056 LatticeModifierData *lmd = (LatticeModifierData*) md; 00057 LatticeModifierData *tlmd = (LatticeModifierData*) target; 00058 00059 tlmd->object = lmd->object; 00060 strncpy(tlmd->name, lmd->name, 32); 00061 } 00062 00063 static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) 00064 { 00065 LatticeModifierData *lmd = (LatticeModifierData *)md; 00066 CustomDataMask dataMask = 0; 00067 00068 /* ask for vertexgroups if we need them */ 00069 if(lmd->name[0]) dataMask |= CD_MASK_MDEFORMVERT; 00070 00071 return dataMask; 00072 } 00073 00074 static int isDisabled(ModifierData *md, int UNUSED(userRenderParams)) 00075 { 00076 LatticeModifierData *lmd = (LatticeModifierData*) md; 00077 00078 return !lmd->object; 00079 } 00080 00081 static void foreachObjectLink( 00082 ModifierData *md, Object *ob, 00083 void (*walk)(void *userData, Object *ob, Object **obpoin), 00084 void *userData) 00085 { 00086 LatticeModifierData *lmd = (LatticeModifierData*) md; 00087 00088 walk(userData, ob, &lmd->object); 00089 } 00090 00091 static void updateDepgraph(ModifierData *md, DagForest *forest, 00092 struct Scene *UNUSED(scene), 00093 Object *UNUSED(ob), 00094 DagNode *obNode) 00095 { 00096 LatticeModifierData *lmd = (LatticeModifierData*) md; 00097 00098 if(lmd->object) { 00099 DagNode *latNode = dag_get_node(forest, lmd->object); 00100 00101 dag_add_relation(forest, latNode, obNode, 00102 DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Lattice Modifier"); 00103 } 00104 } 00105 00106 static void deformVerts(ModifierData *md, Object *ob, 00107 DerivedMesh *derivedData, 00108 float (*vertexCos)[3], 00109 int numVerts, 00110 int UNUSED(useRenderParams), 00111 int UNUSED(isFinalCalc)) 00112 { 00113 LatticeModifierData *lmd = (LatticeModifierData*) md; 00114 00115 00116 modifier_vgroup_cache(md, vertexCos); /* if next modifier needs original vertices */ 00117 00118 lattice_deform_verts(lmd->object, ob, derivedData, 00119 vertexCos, numVerts, lmd->name); 00120 } 00121 00122 static void deformVertsEM( 00123 ModifierData *md, Object *ob, struct EditMesh *editData, 00124 DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts) 00125 { 00126 DerivedMesh *dm = derivedData; 00127 00128 if(!derivedData) dm = CDDM_from_editmesh(editData, ob->data); 00129 00130 deformVerts(md, ob, dm, vertexCos, numVerts, 0, 0); 00131 00132 if(!derivedData) dm->release(dm); 00133 } 00134 00135 00136 ModifierTypeInfo modifierType_Lattice = { 00137 /* name */ "Lattice", 00138 /* structName */ "LatticeModifierData", 00139 /* structSize */ sizeof(LatticeModifierData), 00140 /* type */ eModifierTypeType_OnlyDeform, 00141 /* flags */ eModifierTypeFlag_AcceptsCVs 00142 | eModifierTypeFlag_SupportsEditmode, 00143 /* copyData */ copyData, 00144 /* deformVerts */ deformVerts, 00145 /* deformMatrices */ NULL, 00146 /* deformVertsEM */ deformVertsEM, 00147 /* deformMatricesEM */ NULL, 00148 /* applyModifier */ NULL, 00149 /* applyModifierEM */ NULL, 00150 /* initData */ NULL, 00151 /* requiredDataMask */ requiredDataMask, 00152 /* freeData */ NULL, 00153 /* isDisabled */ isDisabled, 00154 /* updateDepgraph */ updateDepgraph, 00155 /* dependsOnTime */ NULL, 00156 /* dependsOnNormals */ NULL, 00157 /* foreachObjectLink */ foreachObjectLink, 00158 /* foreachIDLink */ NULL, 00159 };