diff options
author | Miika Hamalainen <blender@miikah.org> | 2011-11-10 14:24:34 +0400 |
---|---|---|
committer | Miika Hamalainen <blender@miikah.org> | 2011-11-10 14:24:34 +0400 |
commit | afeb0eeaf0e8caf5e46a5dd6fbea3786e9fb1354 (patch) | |
tree | 36ab74ff3fa36d27c0f35527d3b55e68e3d27fe5 /source/blender/modifiers | |
parent | 1e035381d10068eb17345a88d42cebc0d579adf3 (diff) | |
parent | 1b4a54ad73c058baa59ffdc9e5f18b0b79030fb0 (diff) |
Dynamic Paint merge:
Commit Dynamic Paint from "soc-2011-carrot" branch into trunk.
End-user documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Modifiers/Simulation/Dynamic_Paint
GSoC wiki page:
http://wiki.blender.org/index.php/User:MiikaH/GSoC-2011-DynamicPaint
Diffstat (limited to 'source/blender/modifiers')
-rw-r--r-- | source/blender/modifiers/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/modifiers/MOD_modifiertypes.h | 1 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_dynamicpaint.c | 178 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_util.c | 22 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_util.h | 1 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_uvproject.c | 2 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_wave.c | 2 |
7 files changed, 184 insertions, 23 deletions
diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt index 805cd913aa0..e8ecc75ca60 100644 --- a/source/blender/modifiers/CMakeLists.txt +++ b/source/blender/modifiers/CMakeLists.txt @@ -55,6 +55,7 @@ set(SRC intern/MOD_curve.c intern/MOD_decimate.c intern/MOD_displace.c + intern/MOD_dynamicpaint.c intern/MOD_edgesplit.c intern/MOD_explode.c intern/MOD_fluidsim.c diff --git a/source/blender/modifiers/MOD_modifiertypes.h b/source/blender/modifiers/MOD_modifiertypes.h index 1feee9ccf8a..8ffb7803bb1 100644 --- a/source/blender/modifiers/MOD_modifiertypes.h +++ b/source/blender/modifiers/MOD_modifiertypes.h @@ -74,6 +74,7 @@ extern ModifierTypeInfo modifierType_NavMesh; extern ModifierTypeInfo modifierType_WeightVGEdit; extern ModifierTypeInfo modifierType_WeightVGMix; extern ModifierTypeInfo modifierType_WeightVGProximity; +extern ModifierTypeInfo modifierType_DynamicPaint; /* MOD_util.c */ void modifier_type_init(ModifierTypeInfo *types[]); diff --git a/source/blender/modifiers/intern/MOD_dynamicpaint.c b/source/blender/modifiers/intern/MOD_dynamicpaint.c new file mode 100644 index 00000000000..f697f149ce4 --- /dev/null +++ b/source/blender/modifiers/intern/MOD_dynamicpaint.c @@ -0,0 +1,178 @@ +/* +* ***** BEGIN GPL LICENSE BLOCK ***** +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* Contributor(s): Miika Hämäläinen +* +* ***** END GPL LICENSE BLOCK ***** +* +*/ + +#include <stddef.h> + +#include "DNA_dynamicpaint_types.h" +#include "DNA_meshdata_types.h" +#include "DNA_object_types.h" +#include "DNA_scene_types.h" + +#include "MEM_guardedalloc.h" + +#include "BKE_cdderivedmesh.h" +#include "BKE_dynamicpaint.h" +#include "BKE_modifier.h" + +#include "depsgraph_private.h" + +#include "MOD_util.h" + + +static void initData(ModifierData *md) +{ + DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md; + + pmd->canvas = NULL; + pmd->brush = NULL; + pmd->type = MOD_DYNAMICPAINT_TYPE_CANVAS; +} + +static void copyData(ModifierData *md, ModifierData *target) +{ + DynamicPaintModifierData *pmd = (DynamicPaintModifierData*)md; + DynamicPaintModifierData *tpmd = (DynamicPaintModifierData*)target; + + dynamicPaint_Modifier_copy(pmd, tpmd); +} + +static void freeData(ModifierData *md) +{ + DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md; + dynamicPaint_Modifier_free(pmd); +} + +static CustomDataMask requiredDataMask(Object *ob, ModifierData *md) +{ + DynamicPaintModifierData *pmd = (DynamicPaintModifierData*)md; + CustomDataMask dataMask = 0; + + if (pmd->canvas) { + DynamicPaintSurface *surface = pmd->canvas->surfaces.first; + for(; surface; surface=surface->next) { + /* tface */ + if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ || + surface->init_color_type == MOD_DPAINT_INITIAL_TEXTURE) { + dataMask |= (1 << CD_MTFACE); + } + /* mcol */ + if (surface->type == MOD_DPAINT_SURFACE_T_PAINT || + surface->init_color_type == MOD_DPAINT_INITIAL_VERTEXCOLOR) { + dataMask |= (1 << CD_MCOL); + } + /* CD_MDEFORMVERT */ + if (surface->type == MOD_DPAINT_SURFACE_T_WEIGHT) { + dataMask |= (1 << CD_MDEFORMVERT); + } + } + } + + if (pmd->brush) { + if (pmd->brush->flags & MOD_DPAINT_USE_MATERIAL) { + dataMask |= (1 << CD_MTFACE); + } + } + return dataMask; +} + +static DerivedMesh *applyModifier(ModifierData *md, Object *ob, + DerivedMesh *dm, + int useRenderParams, + int isFinalCalc) +{ + DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md; + + return dynamicPaint_Modifier_do(pmd, md->scene, ob, dm); +} + +static void updateDepgraph(ModifierData *md, DagForest *forest, + struct Scene *scene, + Object *ob, + DagNode *obNode) +{ + DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md; + + /* add relation from canvases to all brush objects */ + if(pmd && pmd->canvas) + { + Base *base = scene->base.first; + + for(; base; base = base->next) { + DynamicPaintModifierData *pmd2 = (DynamicPaintModifierData *)modifiers_findByType(base->object, eModifierType_DynamicPaint); + + if(pmd2 && pmd2->brush && ob!=base->object) + { + DagNode *brushNode = dag_get_node(forest, base->object); + dag_add_relation(forest, brushNode, obNode, DAG_RL_DATA_DATA|DAG_RL_OB_DATA, "Dynamic Paint Brush"); + } + } + } +} + +static int dependsOnTime(ModifierData *md) +{ + return 1; +} + +static void foreachIDLink(ModifierData *md, Object *ob, + IDWalkFunc walk, void *userData) +{ + DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md; + + if(pmd->canvas) { + DynamicPaintSurface *surface = pmd->canvas->surfaces.first; + + for(; surface; surface=surface->next) { + walk(userData, ob, (ID **)&surface->brush_group); + walk(userData, ob, (ID **)&surface->init_texture); + } + } + if (pmd->brush) { + walk(userData, ob, (ID **)&pmd->brush->mat); + } +} + +static void foreachTexLink(ModifierData *md, Object *ob, + TexWalkFunc walk, void *userData) +{ + //walk(userData, ob, md, ""); /* re-enable when possible */ +} + +ModifierTypeInfo modifierType_DynamicPaint = { + /* name */ "Dynamic Paint", + /* structName */ "DynamicPaintModifierData", + /* structSize */ sizeof(DynamicPaintModifierData), + /* type */ eModifierTypeType_Constructive, + /* flags */ eModifierTypeFlag_AcceptsMesh + | eModifierTypeFlag_UsesPointCache + | eModifierTypeFlag_Single, + + /* copyData */ copyData, + /* deformVerts */ 0, + /* deformMatrices */ 0, + /* deformVertsEM */ 0, + /* deformMatricesEM */ 0, + /* applyModifier */ applyModifier, + /* applyModifierEM */ 0, + /* initData */ initData, + /* requiredDataMask */ requiredDataMask, + /* freeData */ freeData, + /* isDisabled */ 0, + /* updateDepgraph */ updateDepgraph, + /* dependsOnTime */ dependsOnTime, + /* dependsOnNormals */ 0, + /* foreachObjectLink */ 0, + /* foreachIDLink */ foreachIDLink, + /* foreachTexLink */ foreachTexLink, +}; diff --git a/source/blender/modifiers/intern/MOD_util.c b/source/blender/modifiers/intern/MOD_util.c index b7883eea4d8..38abb96aa7c 100644 --- a/source/blender/modifiers/intern/MOD_util.c +++ b/source/blender/modifiers/intern/MOD_util.c @@ -105,7 +105,7 @@ void get_texture_coords(MappingInfoModifierData *dmd, Object *ob, char uvname[32]; MTFace *tf; - validate_layer_name(&dm->faceData, CD_MTFACE, dmd->uvlayer_name, uvname); + CustomData_validate_layer_name(&dm->faceData, CD_MTFACE, dmd->uvlayer_name, uvname); tf = CustomData_get_layer_named(&dm->faceData, CD_MTFACE, uvname); /* verts are given the UV from the first face that uses them */ @@ -176,25 +176,6 @@ void modifier_vgroup_cache(ModifierData *md, float (*vertexCos)[3]) /* lattice/mesh modifier too */ } -void validate_layer_name(const CustomData *data, int type, char *name, char *outname) -{ - int index = -1; - - /* if a layer name was given, try to find that layer */ - if(name[0]) - index = CustomData_get_named_layer_index(data, type, name); - - if(index < 0) { - /* either no layer was specified, or the layer we want has been - * deleted, so assign the active layer to name - */ - index = CustomData_get_active_layer_index(data, type); - strcpy(outname, data->layers[index].name); - } - else - strcpy(outname, name); -} - /* returns a cdderivedmesh if dm == NULL or is another type of derivedmesh */ DerivedMesh *get_cddm(Object *ob, struct EditMesh *em, DerivedMesh *dm, float (*vertexCos)[3]) { @@ -296,5 +277,6 @@ void modifier_type_init(ModifierTypeInfo *types[]) INIT_TYPE(WeightVGEdit); INIT_TYPE(WeightVGMix); INIT_TYPE(WeightVGProximity); + INIT_TYPE(DynamicPaint); #undef INIT_TYPE } diff --git a/source/blender/modifiers/intern/MOD_util.h b/source/blender/modifiers/intern/MOD_util.h index 4de767358e4..262f27f0f1b 100644 --- a/source/blender/modifiers/intern/MOD_util.h +++ b/source/blender/modifiers/intern/MOD_util.h @@ -47,7 +47,6 @@ struct TexResult; void get_texture_value(struct Tex *texture, float *tex_co, struct TexResult *texres); void get_texture_coords(struct MappingInfoModifierData *dmd, struct Object *ob, struct DerivedMesh *dm, float (*co)[3], float (*texco)[3], int numVerts); void modifier_vgroup_cache(struct ModifierData *md, float (*vertexCos)[3]); -void validate_layer_name(const struct CustomData *data, int type, char *name, char *outname); struct DerivedMesh *get_cddm(struct Object *ob, struct EditMesh *em, struct DerivedMesh *dm, float (*vertexCos)[3]); struct DerivedMesh *get_dm(struct Object *ob, struct EditMesh *em, struct DerivedMesh *dm, float (*vertexCos)[3], int orco); void modifier_get_vgroup(struct Object *ob, struct DerivedMesh *dm, const char *name, struct MDeformVert **dvert, int *defgrp_index); diff --git a/source/blender/modifiers/intern/MOD_uvproject.c b/source/blender/modifiers/intern/MOD_uvproject.c index d5dd0078a80..df528a0cb11 100644 --- a/source/blender/modifiers/intern/MOD_uvproject.c +++ b/source/blender/modifiers/intern/MOD_uvproject.c @@ -174,7 +174,7 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, if(!CustomData_has_layer(&dm->faceData, CD_MTFACE)) return dm; /* make sure we're using an existing layer */ - validate_layer_name(&dm->faceData, CD_MTFACE, umd->uvlayer_name, uvname); + CustomData_validate_layer_name(&dm->faceData, CD_MTFACE, umd->uvlayer_name, uvname); /* calculate a projection matrix and normal for each projector */ for(i = 0; i < num_projectors; ++i) { diff --git a/source/blender/modifiers/intern/MOD_wave.c b/source/blender/modifiers/intern/MOD_wave.c index 6aac7077447..80dd0c0a720 100644 --- a/source/blender/modifiers/intern/MOD_wave.c +++ b/source/blender/modifiers/intern/MOD_wave.c @@ -196,7 +196,7 @@ static void wavemod_get_texture_coords(WaveModifierData *wmd, Object *ob, char uvname[32]; MTFace *tf; - validate_layer_name(&dm->faceData, CD_MTFACE, wmd->uvlayer_name, uvname); + CustomData_validate_layer_name(&dm->faceData, CD_MTFACE, wmd->uvlayer_name, uvname); tf = CustomData_get_layer_named(&dm->faceData, CD_MTFACE, uvname); /* verts are given the UV from the first face that uses them */ |