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)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
DynamicPaintModifierData *pmd = (DynamicPaintModifierData *) md;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md;
|
|
|
|
DynamicPaintModifierData *tpmd = (DynamicPaintModifierData *)target;
|
2011-05-24 07:08:58 +00:00
|
|
|
|
|
|
|
dynamicPaint_Modifier_copy(pmd, tpmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void freeData(ModifierData *md)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
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
|
|
|
{
|
2012-05-06 13:38:33 +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;
|
2012-05-06 13:38:33 +00:00
|
|
|
for (; surface; surface = surface->next) {
|
2011-10-22 16:16:14 +00:00
|
|
|
/* tface */
|
|
|
|
if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ ||
|
2012-05-20 19:49:27 +00:00
|
|
|
surface->init_color_type == MOD_DPAINT_INITIAL_TEXTURE)
|
|
|
|
{
|
2011-10-22 16:16:14 +00:00
|
|
|
dataMask |= (1 << CD_MTFACE);
|
|
|
|
}
|
|
|
|
/* mcol */
|
|
|
|
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT ||
|
2012-05-20 19:49:27 +00:00
|
|
|
surface->init_color_type == MOD_DPAINT_INITIAL_VERTEXCOLOR)
|
|
|
|
{
|
2011-10-22 16:16:14 +00:00
|
|
|
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,
|
2012-05-06 13:38:33 +00:00
|
|
|
DerivedMesh *dm,
|
2013-04-29 15:02:54 +00:00
|
|
|
ModifierApplyFlag flag)
|
2011-05-24 07:08:58 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
DynamicPaintModifierData *pmd = (DynamicPaintModifierData *) md;
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2013-04-29 15:02:54 +00:00
|
|
|
/* dont apply dynamic paint on orco dm stack */
|
2013-05-02 14:42:05 +00:00
|
|
|
if (!(flag & MOD_APPLY_ORCO)) {
|
2013-04-29 15:02:54 +00:00
|
|
|
return dynamicPaint_Modifier_do(pmd, md->scene, ob, dm);
|
|
|
|
}
|
|
|
|
return dm;
|
2011-06-16 10:41:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void updateDepgraph(ModifierData *md, DagForest *forest,
|
2012-05-06 13:38:33 +00:00
|
|
|
struct Scene *scene,
|
|
|
|
Object *ob,
|
|
|
|
DagNode *obNode)
|
2011-06-16 10:41:00 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
DynamicPaintModifierData *pmd = (DynamicPaintModifierData *) md;
|
2011-06-16 10:41:00 +00:00
|
|
|
|
|
|
|
/* 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) {
|
2012-05-06 13:38:33 +00:00
|
|
|
DynamicPaintModifierData *pmd2 =
|
|
|
|
(DynamicPaintModifierData *)modifiers_findByType(base->object, eModifierType_DynamicPaint);
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2012-05-06 13:38:33 +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);
|
2012-05-06 13:38:33 +00:00
|
|
|
dag_add_relation(forest, brushNode, obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Dynamic Paint Brush");
|
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 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,
|
2012-05-06 13:38:33 +00:00
|
|
|
IDWalkFunc walk, void *userData)
|
2011-06-16 10:41:00 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
DynamicPaintModifierData *pmd = (DynamicPaintModifierData *) md;
|
2011-06-16 10:41:00 +00:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (pmd->canvas) {
|
2011-06-16 10:41:00 +00:00
|
|
|
DynamicPaintSurface *surface = pmd->canvas->surfaces.first;
|
|
|
|
|
2012-05-06 13:38:33 +00:00
|
|
|
for (; surface; surface = surface->next) {
|
2011-06-16 10:41:00 +00:00
|
|
|
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),
|
2012-05-06 13:38:33 +00:00
|
|
|
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,
|
2012-05-06 13:38:33 +00:00
|
|
|
/* flags */ eModifierTypeFlag_AcceptsMesh |
|
2012-10-24 05:45:54 +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
|
|
|
};
|