Merge branch 'master' into blender2.8
[blender.git] / source / blender / modifiers / intern / MOD_softbody.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software  Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2005 by the Blender Foundation.
19  * All rights reserved.
20  *
21  * Contributor(s): Daniel Dunbar
22  *                 Ton Roosendaal,
23  *                 Ben Batt,
24  *                 Brecht Van Lommel,
25  *                 Campbell Barton
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  *
29  */
30
31 /** \file blender/modifiers/intern/MOD_softbody.c
32  *  \ingroup modifiers
33  */
34
35 #include <stdio.h>
36
37 #include "DNA_scene_types.h"
38 #include "DNA_object_force_types.h"
39
40 #include "BLI_utildefines.h"
41
42 #include "BKE_cdderivedmesh.h"
43 #include "BKE_layer.h"
44 #include "BKE_particle.h"
45 #include "BKE_softbody.h"
46
47 #include "DEG_depsgraph.h"
48 #include "DEG_depsgraph_build.h"
49
50 #include "MOD_modifiertypes.h"
51
52 static void deformVerts(ModifierData *md, const EvaluationContext *eval_ctx, Object *ob,
53                         DerivedMesh *UNUSED(derivedData),
54                         float (*vertexCos)[3],
55                         int numVerts,
56                         ModifierApplyFlag UNUSED(flag))
57 {
58         sbObjectStep(eval_ctx, md->scene, ob, (float)md->scene->r.cfra, vertexCos, numVerts);
59 }
60
61 static bool dependsOnTime(ModifierData *UNUSED(md))
62 {
63         return true;
64 }
65
66 static void updateDepsgraph(ModifierData *UNUSED(md),
67                             struct Main *UNUSED(bmain),
68                             struct Scene *scene,
69                             Object *ob,
70                             struct DepsNodeHandle *node)
71 {
72         if (ob->soft) {
73                 /* Actual code uses ccd_build_deflector_hash */
74                 DEG_add_collision_relations(node, scene, ob, ob->soft->collision_group, eModifierType_Collision, NULL, false, "Softbody Collision");
75
76                 DEG_add_forcefield_relations(node, scene, ob, ob->soft->effector_weights, true, 0, "Softbody Field");
77         }
78 }
79
80 ModifierTypeInfo modifierType_Softbody = {
81         /* name */              "Softbody",
82         /* structName */        "SoftbodyModifierData",
83         /* structSize */        sizeof(SoftbodyModifierData),
84         /* type */              eModifierTypeType_OnlyDeform,
85         /* flags */             eModifierTypeFlag_AcceptsCVs |
86                                 eModifierTypeFlag_AcceptsLattice |
87                                 eModifierTypeFlag_RequiresOriginalData |
88                                 eModifierTypeFlag_Single,
89
90         /* copyData */          NULL,
91         /* deformVerts */       deformVerts,
92         /* deformMatrices */    NULL,
93         /* deformVertsEM */     NULL,
94         /* deformMatricesEM */  NULL,
95         /* applyModifier */     NULL,
96         /* applyModifierEM */   NULL,
97         /* initData */          NULL,
98         /* requiredDataMask */  NULL,
99         /* freeData */          NULL,
100         /* isDisabled */        NULL,
101         /* updateDepsgraph */   updateDepsgraph,
102         /* dependsOnTime */     dependsOnTime,
103         /* dependsOnNormals */  NULL,
104         /* foreachObjectLink */ NULL,
105         /* foreachIDLink */     NULL,
106         /* foreachTexLink */    NULL,
107 };