2011-05-24 07:08:58 +00:00
|
|
|
/*
|
2011-12-28 11:08:38 +00:00
|
|
|
* ***** 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.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* Contributor(s): Miika Hämäläinen
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file blender/modifiers/intern/MOD_dynamicpaint.c
|
|
|
|
* \ingroup modifiers
|
|
|
|
*/
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-10-22 16:16:14 +00:00
|
|
|
#include <stddef.h>
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-10-28 14:46:09 +00:00
|
|
|
#include "DNA_dynamicpaint_types.h"
|
2011-05-24 07:08:58 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
2011-06-16 10:41:00 +00:00
|
|
|
#include "DNA_scene_types.h"
|
2011-05-24 07:08:58 +00:00
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2011-11-10 12:28:26 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
2011-05-24 07:08:58 +00:00
|
|
|
#include "BKE_cdderivedmesh.h"
|
|
|
|
#include "BKE_dynamicpaint.h"
|
2011-10-22 16:16:14 +00:00
|
|
|
#include "BKE_modifier.h"
|
2011-05-24 07:08:58 +00:00
|
|
|
|
|
|
|
#include "depsgraph_private.h"
|
|
|
|
|
|
|
|
#include "MOD_util.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void initData(ModifierData *md)
|
|
|
|
{
|
|
|
|
DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md;
|
|
|
|
|
|
|
|
pmd->canvas = NULL;
|
2011-06-16 10:41:00 +00:00
|
|
|
pmd->brush = NULL;
|
2011-07-08 11:03:37 +00:00
|
|
|
pmd->type = MOD_DYNAMICPAINT_TYPE_CANVAS;
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2011-10-13 20:00:22 +00:00
|
|
|
dynamicPaint_Modifier_free(pmd);
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
2011-11-10 12:28:26 +00:00
|
|
|
static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
2011-10-22 16:16:14 +00:00
|
|
|
DynamicPaintModifierData *pmd = (DynamicPaintModifierData*)md;
|
2011-05-24 07:08:58 +00:00
|
|
|
CustomDataMask dataMask = 0;
|
|
|
|
|
2011-10-22 16:16:14 +00:00
|
|
|
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) {
|
2011-10-31 13:01:06 +00:00
|
|
|
if (pmd->brush->flags & MOD_DPAINT_USE_MATERIAL) {
|
2011-10-22 16:16:14 +00:00
|
|
|
dataMask |= (1 << CD_MTFACE);
|
|
|
|
}
|
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
return dataMask;
|
|
|
|
}
|
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
|
|
|
|
DerivedMesh *dm,
|
2011-11-10 12:28:26 +00:00
|
|
|
int UNUSED(useRenderParams),
|
|
|
|
int UNUSED(isFinalCalc))
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
|
|
|
DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md;
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2011-08-03 18:31:48 +00:00
|
|
|
return dynamicPaint_Modifier_do(pmd, md->scene, ob, dm);
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void updateDepgraph(ModifierData *md, DagForest *forest,
|
|
|
|
struct Scene *scene,
|
2011-06-18 18:41:20 +00:00
|
|
|
Object *ob,
|
2011-06-16 10:41:00 +00:00
|
|
|
DagNode *obNode)
|
|
|
|
{
|
|
|
|
DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md;
|
|
|
|
|
|
|
|
/* add relation from canvases to all brush objects */
|
2012-03-06 18:40:15 +00:00
|
|
|
if (pmd && pmd->canvas) {
|
2011-06-16 10:41:00 +00:00
|
|
|
Base *base = scene->base.first;
|
|
|
|
|
2012-03-06 18:40:15 +00:00
|
|
|
for (; base; base = base->next) {
|
2011-06-16 10:41:00 +00:00
|
|
|
DynamicPaintModifierData *pmd2 = (DynamicPaintModifierData *)modifiers_findByType(base->object, eModifierType_DynamicPaint);
|
|
|
|
|
2012-03-06 18:40:15 +00:00
|
|
|
if (pmd2 && pmd2->brush && ob!=base->object) {
|
2011-06-16 10:41:00 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
}
|
|
|
|
|
2011-11-10 12:28:26 +00:00
|
|
|
static int dependsOnTime(ModifierData *UNUSED(md))
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-06-16 10:41:00 +00:00
|
|
|
static void foreachIDLink(ModifierData *md, Object *ob,
|
|
|
|
IDWalkFunc walk, void *userData)
|
|
|
|
{
|
|
|
|
DynamicPaintModifierData *pmd = (DynamicPaintModifierData*) md;
|
|
|
|
|
2011-07-08 11:03:37 +00:00
|
|
|
if(pmd->canvas) {
|
2011-06-16 10:41:00 +00:00
|
|
|
DynamicPaintSurface *surface = pmd->canvas->surfaces.first;
|
|
|
|
|
|
|
|
for(; surface; surface=surface->next) {
|
|
|
|
walk(userData, ob, (ID **)&surface->brush_group);
|
2011-09-05 16:04:15 +00:00
|
|
|
walk(userData, ob, (ID **)&surface->init_texture);
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
}
|
2011-07-22 18:37:30 +00:00
|
|
|
if (pmd->brush) {
|
|
|
|
walk(userData, ob, (ID **)&pmd->brush->mat);
|
|
|
|
}
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
2011-05-24 07:08:58 +00:00
|
|
|
|
2011-11-10 12:28:26 +00:00
|
|
|
static void foreachTexLink(ModifierData *UNUSED(md), Object *UNUSED(ob),
|
|
|
|
TexWalkFunc UNUSED(walk), void *UNUSED(userData))
|
2011-09-05 16:04:15 +00:00
|
|
|
{
|
2011-11-09 15:46:53 +00:00
|
|
|
//walk(userData, ob, md, ""); /* re-enable when possible */
|
2011-09-05 16:04:15 +00:00
|
|
|
}
|
|
|
|
|
2011-05-24 07:08:58 +00:00
|
|
|
ModifierTypeInfo modifierType_DynamicPaint = {
|
|
|
|
/* name */ "Dynamic Paint",
|
|
|
|
/* structName */ "DynamicPaintModifierData",
|
|
|
|
/* structSize */ sizeof(DynamicPaintModifierData),
|
2011-06-16 10:41:00 +00:00
|
|
|
/* type */ eModifierTypeType_Constructive,
|
2011-05-24 07:08:58 +00:00
|
|
|
/* flags */ eModifierTypeFlag_AcceptsMesh
|
Add weight preview to WeightVG modifiers, and first, simple/basic refactor of how modifiers can generate preview.
User side:
* Preview for DynamicPaint should keep the same behavior (for now). Weight preview should be somawhat quicker, though.
* Preview for WeightVG modifiers is only active in WeightPaint mode, and if the affected vgroup is the active one.
* Last active preview modifier in stack wins!
Note: that modifier preview topic is yet to be further refined, quite raw/incomplete for now.
Dev side:
* In draw code, renamed DRAW_DYNAMIC_PAINT_PREVIEW flag to DRAW_MODIFIERS_PREVIEW
* Removed use of MOD_DPAINT_PREVIEW_READY in DynamicPaint code (seems unecessary, and if it was, should be of more general scope).
* Added eModifierTypeFlag_UsesPreview to ModifierTypeFlag, for modifiers that can generate some preview data.
* Added three new modifier funcs, to handle preview modifiers in draw code / mod stack.
* For weights preview: added the generic DM_update_weight_mcol func, which can update WEIGHT_MCOL layer with either a given array of weights (currently used by DynamicPaint only), or from current active vgroup(s).
So now, draw code is fully generic (i.e. no more modifier-type checking in it). Mod stack code is generic to some extent, but will need more work.
2012-01-22 17:54:23 +00:00
|
|
|
/* |eModifierTypeFlag_SupportsMapping*/
|
|
|
|
|eModifierTypeFlag_UsesPointCache
|
|
|
|
|eModifierTypeFlag_Single
|
|
|
|
|eModifierTypeFlag_UsesPreview,
|
2011-05-24 07:08:58 +00:00
|
|
|
|
|
|
|
/* copyData */ copyData,
|
2011-11-14 16:05:44 +00:00
|
|
|
/* deformVerts */ NULL,
|
|
|
|
/* deformMatrices */ NULL,
|
|
|
|
/* deformVertsEM */ NULL,
|
|
|
|
/* deformMatricesEM */ NULL,
|
2011-06-16 10:41:00 +00:00
|
|
|
/* applyModifier */ applyModifier,
|
2011-11-14 16:05:44 +00:00
|
|
|
/* applyModifierEM */ NULL,
|
2011-05-24 07:08:58 +00:00
|
|
|
/* initData */ initData,
|
|
|
|
/* requiredDataMask */ requiredDataMask,
|
|
|
|
/* freeData */ freeData,
|
2011-11-14 16:05:44 +00:00
|
|
|
/* isDisabled */ NULL,
|
2011-06-16 10:41:00 +00:00
|
|
|
/* updateDepgraph */ updateDepgraph,
|
2011-05-24 07:08:58 +00:00
|
|
|
/* dependsOnTime */ dependsOnTime,
|
2011-11-14 16:05:44 +00:00
|
|
|
/* dependsOnNormals */ NULL,
|
|
|
|
/* foreachObjectLink */ NULL,
|
2011-06-16 10:41:00 +00:00
|
|
|
/* foreachIDLink */ foreachIDLink,
|
2011-09-05 16:04:15 +00:00
|
|
|
/* foreachTexLink */ foreachTexLink,
|
2011-05-24 07:08:58 +00:00
|
|
|
};
|