Extract common modifier parameters into ModifierEvalContext struct
[blender.git] / source / blender / modifiers / intern / MOD_wireframe.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  * ***** END GPL LICENSE BLOCK *****
19  *
20  */
21
22 /** \file blender/modifiers/intern/MOD_wireframe.c
23  *  \ingroup modifiers
24  */
25
26 #include "DNA_object_types.h"
27
28 #include "BLI_utildefines.h"
29
30 #include "BKE_cdderivedmesh.h"
31 #include "BKE_deform.h"
32
33 #include "MOD_modifiertypes.h"
34
35 #include "bmesh.h"
36 #include "tools/bmesh_wireframe.h"
37
38 static void initData(ModifierData *md)
39 {
40         WireframeModifierData *wmd = (WireframeModifierData *)md;
41         wmd->offset = 0.02f;
42         wmd->flag = MOD_WIREFRAME_REPLACE | MOD_WIREFRAME_OFS_EVEN;
43         wmd->crease_weight = 1.0f;
44 }
45
46 static void copyData(ModifierData *md, ModifierData *target)
47 {
48 #if 0
49         WireframeModifierData *wmd = (WireframeModifierData *)md;
50         WireframeModifierData *twmd = (WireframeModifierData *)target;
51 #endif
52         modifier_copyData_generic(md, target);
53 }
54
55 static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
56 {
57         WireframeModifierData *wmd = (WireframeModifierData *)md;
58         CustomDataMask dataMask = 0;
59
60         /* ask for vertexgroups if we need them */
61         if (wmd->defgrp_name[0]) dataMask |= CD_MASK_MDEFORMVERT;
62
63         return dataMask;
64
65 }
66
67 static bool dependsOnNormals(ModifierData *UNUSED(md))
68 {
69         return true;
70 }
71
72 static DerivedMesh *WireframeModifier_do(WireframeModifierData *wmd, Object *ob, DerivedMesh *dm)
73 {
74         DerivedMesh *result;
75         BMesh *bm;
76
77         const int defgrp_index = defgroup_name_index(ob, wmd->defgrp_name);
78
79         bm = DM_to_bmesh(dm, true);
80
81         BM_mesh_wireframe(
82                bm,
83                wmd->offset, wmd->offset_fac, wmd->offset_fac_vg,
84                (wmd->flag & MOD_WIREFRAME_REPLACE) != 0,
85                (wmd->flag & MOD_WIREFRAME_BOUNDARY) != 0,
86                (wmd->flag & MOD_WIREFRAME_OFS_EVEN) != 0,
87                (wmd->flag & MOD_WIREFRAME_OFS_RELATIVE) != 0,
88                (wmd->flag & MOD_WIREFRAME_CREASE) != 0,
89                wmd->crease_weight,
90                defgrp_index,
91                (wmd->flag & MOD_WIREFRAME_INVERT_VGROUP) != 0,
92                wmd->mat_ofs,
93                MAX2(ob->totcol - 1, 0),
94                false);
95
96         result = CDDM_from_bmesh(bm, true);
97         BM_mesh_free(bm);
98
99         result->dirty |= DM_DIRTY_NORMALS;
100
101         return result;
102
103 }
104
105 static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx,
106                                   DerivedMesh *dm)
107 {
108         return WireframeModifier_do((WireframeModifierData *)md, ctx->object, dm);
109 }
110
111
112 ModifierTypeInfo modifierType_Wireframe = {
113         /* name */              "Wireframe",
114         /* structName */        "WireframeModifierData",
115         /* structSize */        sizeof(WireframeModifierData),
116         /* type */              eModifierTypeType_Constructive,
117         /* flags */             eModifierTypeFlag_AcceptsMesh |
118                                 eModifierTypeFlag_SupportsEditmode,
119
120         /* copyData */          copyData,
121
122         /* deformVerts_DM */    NULL,
123         /* deformMatrices_DM */ NULL,
124         /* deformVertsEM_DM */  NULL,
125         /* deformMatricesEM_DM*/NULL,
126         /* applyModifier_DM */  applyModifier,
127         /* applyModifierEM_DM */NULL,
128
129         /* deformVerts */       NULL,
130         /* deformMatrices */    NULL,
131         /* deformVertsEM */     NULL,
132         /* deformMatricesEM */  NULL,
133         /* applyModifier */     NULL,
134         /* applyModifierEM */   NULL,
135
136         /* initData */          initData,
137         /* requiredDataMask */  requiredDataMask,
138         /* freeData */          NULL,
139         /* isDisabled */        NULL,
140         /* updateDepgraph */    NULL,
141         /* dependsOnTime */     NULL,
142         /* dependsOnNormals */  dependsOnNormals,
143         /* foreachObjectLink */ NULL,
144         /* foreachIDLink */     NULL,
145         /* foreachTexLink */    NULL,
146 };