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