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 * Contributor(s): Miika Hämäläinen 00019 * 00020 * ***** END GPL LICENSE BLOCK ***** 00021 * 00022 */ 00023 00028 #include <stddef.h> 00029 00030 #include "DNA_dynamicpaint_types.h" 00031 #include "DNA_meshdata_types.h" 00032 #include "DNA_object_types.h" 00033 #include "DNA_scene_types.h" 00034 00035 #include "MEM_guardedalloc.h" 00036 00037 #include "BLI_utildefines.h" 00038 00039 #include "BKE_cdderivedmesh.h" 00040 #include "BKE_dynamicpaint.h" 00041 #include "BKE_modifier.h" 00042 00043 #include "depsgraph_private.h" 00044 00045 #include "MOD_util.h" 00046 00047 00048 static void initData(ModifierData *md) 00049 { 00050 DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md; 00051 00052 pmd->canvas = NULL; 00053 pmd->brush = NULL; 00054 pmd->type = MOD_DYNAMICPAINT_TYPE_CANVAS; 00055 } 00056 00057 static void copyData(ModifierData *md, ModifierData *target) 00058 { 00059 DynamicPaintModifierData *pmd = (DynamicPaintModifierData*)md; 00060 DynamicPaintModifierData *tpmd = (DynamicPaintModifierData*)target; 00061 00062 dynamicPaint_Modifier_copy(pmd, tpmd); 00063 } 00064 00065 static void freeData(ModifierData *md) 00066 { 00067 DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md; 00068 dynamicPaint_Modifier_free(pmd); 00069 } 00070 00071 static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) 00072 { 00073 DynamicPaintModifierData *pmd = (DynamicPaintModifierData*)md; 00074 CustomDataMask dataMask = 0; 00075 00076 if (pmd->canvas) { 00077 DynamicPaintSurface *surface = pmd->canvas->surfaces.first; 00078 for(; surface; surface=surface->next) { 00079 /* tface */ 00080 if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ || 00081 surface->init_color_type == MOD_DPAINT_INITIAL_TEXTURE) { 00082 dataMask |= (1 << CD_MTFACE); 00083 } 00084 /* mcol */ 00085 if (surface->type == MOD_DPAINT_SURFACE_T_PAINT || 00086 surface->init_color_type == MOD_DPAINT_INITIAL_VERTEXCOLOR) { 00087 dataMask |= (1 << CD_MCOL); 00088 } 00089 /* CD_MDEFORMVERT */ 00090 if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) { 00091 dataMask |= (1 << CD_MDEFORMVERT); 00092 } 00093 } 00094 } 00095 00096 if (pmd->brush) { 00097 if (pmd->brush->flags & MOD_DPAINT_USE_MATERIAL) { 00098 dataMask |= (1 << CD_MTFACE); 00099 } 00100 } 00101 return dataMask; 00102 } 00103 00104 static DerivedMesh *applyModifier(ModifierData *md, Object *ob, 00105 DerivedMesh *dm, 00106 int UNUSED(useRenderParams), 00107 int UNUSED(isFinalCalc)) 00108 { 00109 DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md; 00110 00111 return dynamicPaint_Modifier_do(pmd, md->scene, ob, dm); 00112 } 00113 00114 static void updateDepgraph(ModifierData *md, DagForest *forest, 00115 struct Scene *scene, 00116 Object *ob, 00117 DagNode *obNode) 00118 { 00119 DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md; 00120 00121 /* add relation from canvases to all brush objects */ 00122 if(pmd && pmd->canvas) 00123 { 00124 Base *base = scene->base.first; 00125 00126 for(; base; base = base->next) { 00127 DynamicPaintModifierData *pmd2 = (DynamicPaintModifierData *)modifiers_findByType(base->object, eModifierType_DynamicPaint); 00128 00129 if(pmd2 && pmd2->brush && ob!=base->object) 00130 { 00131 DagNode *brushNode = dag_get_node(forest, base->object); 00132 dag_add_relation(forest, brushNode, obNode, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Dynamic Paint Brush"); 00133 } 00134 } 00135 } 00136 } 00137 00138 static int dependsOnTime(ModifierData *UNUSED(md)) 00139 { 00140 return 1; 00141 } 00142 00143 static void foreachIDLink(ModifierData *md, Object *ob, 00144 IDWalkFunc walk, void *userData) 00145 { 00146 DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md; 00147 00148 if(pmd->canvas) { 00149 DynamicPaintSurface *surface = pmd->canvas->surfaces.first; 00150 00151 for(; surface; surface=surface->next) { 00152 walk(userData, ob, (ID **)&surface->brush_group); 00153 walk(userData, ob, (ID **)&surface->init_texture); 00154 } 00155 } 00156 if (pmd->brush) { 00157 walk(userData, ob, (ID **)&pmd->brush->mat); 00158 } 00159 } 00160 00161 static void foreachTexLink(ModifierData *UNUSED(md), Object *UNUSED(ob), 00162 TexWalkFunc UNUSED(walk), void *UNUSED(userData)) 00163 { 00164 //walk(userData, ob, md, ""); /* re-enable when possible */ 00165 } 00166 00167 ModifierTypeInfo modifierType_DynamicPaint = { 00168 /* name */ "Dynamic Paint", 00169 /* structName */ "DynamicPaintModifierData", 00170 /* structSize */ sizeof(DynamicPaintModifierData), 00171 /* type */ eModifierTypeType_Constructive, 00172 /* flags */ eModifierTypeFlag_AcceptsMesh 00173 | eModifierTypeFlag_UsesPointCache 00174 | eModifierTypeFlag_Single, 00175 00176 /* copyData */ copyData, 00177 /* deformVerts */ NULL, 00178 /* deformMatrices */ NULL, 00179 /* deformVertsEM */ NULL, 00180 /* deformMatricesEM */ NULL, 00181 /* applyModifier */ applyModifier, 00182 /* applyModifierEM */ NULL, 00183 /* initData */ initData, 00184 /* requiredDataMask */ requiredDataMask, 00185 /* freeData */ freeData, 00186 /* isDisabled */ NULL, 00187 /* updateDepgraph */ updateDepgraph, 00188 /* dependsOnTime */ dependsOnTime, 00189 /* dependsOnNormals */ NULL, 00190 /* foreachObjectLink */ NULL, 00191 /* foreachIDLink */ foreachIDLink, 00192 /* foreachTexLink */ foreachTexLink, 00193 };