merge with/from trunk at r35190
[blender.git] / source / blender / modifiers / intern / MOD_bevel.c
1 /*
2 * $Id$
3 *
4 * ***** BEGIN GPL LICENSE BLOCK *****
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software  Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *
20 * The Original Code is Copyright (C) 2005 by the Blender Foundation.
21 * All rights reserved.
22 *
23 * Contributor(s): Daniel Dunbar
24 *                 Ton Roosendaal,
25 *                 Ben Batt,
26 *                 Brecht Van Lommel,
27 *                 Campbell Barton
28 *
29 * ***** END GPL LICENSE BLOCK *****
30 *
31 */
32
33 /** \file blender/modifiers/intern/MOD_bevel.c
34  *  \ingroup modifiers
35  */
36
37 #include "MEM_guardedalloc.h"
38
39 #include "BLI_utildefines.h"
40
41 #include "BKE_bmesh.h"
42 #include "BKE_cdderivedmesh.h"
43 #include "BKE_modifier.h"
44 #include "BKE_particle.h"
45
46 #include "MOD_util.h"
47
48
49 static void initData(ModifierData *md)
50 {
51         BevelModifierData *bmd = (BevelModifierData*) md;
52
53         bmd->value = 0.1f;
54         bmd->res = 1;
55         bmd->flags = 0;
56         bmd->val_flags = 0;
57         bmd->lim_flags = 0;
58         bmd->e_flags = 0;
59         bmd->bevel_angle = 30;
60         bmd->defgrp_name[0] = '\0';
61 }
62
63 static void copyData(ModifierData *md, ModifierData *target)
64 {
65         BevelModifierData *bmd = (BevelModifierData*) md;
66         BevelModifierData *tbmd = (BevelModifierData*) target;
67
68         tbmd->value = bmd->value;
69         tbmd->res = bmd->res;
70         tbmd->flags = bmd->flags;
71         tbmd->val_flags = bmd->val_flags;
72         tbmd->lim_flags = bmd->lim_flags;
73         tbmd->e_flags = bmd->e_flags;
74         tbmd->bevel_angle = bmd->bevel_angle;
75         strncpy(tbmd->defgrp_name, bmd->defgrp_name, 32);
76 }
77
78 static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
79 {
80         BevelModifierData *bmd = (BevelModifierData *)md;
81         CustomDataMask dataMask = 0;
82
83         /* ask for vertexgroups if we need them */
84         if(bmd->defgrp_name[0]) dataMask |= CD_MASK_MDEFORMVERT;
85
86         return dataMask;
87 }
88
89 static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
90                                                 DerivedMesh *derivedData,
91                                                 int UNUSED(useRenderParams),
92                                                 int UNUSED(isFinalCalc))
93 {
94 #if 0
95         DerivedMesh *result;
96         BME_Mesh *bm;
97
98         /*bDeformGroup *def;*/
99         int /*i,*/ options, defgrp_index = -1;
100         BevelModifierData *bmd = (BevelModifierData*) md;
101
102         options = bmd->flags|bmd->val_flags|bmd->lim_flags|bmd->e_flags;
103
104         /*if ((options & BME_BEVEL_VWEIGHT) && bmd->defgrp_name[0]) {
105                 defgrp_index = defgroup_name_index(ob, bmd->defgrp_name);
106                 if (defgrp_index < 0) {
107                         options &= ~BME_BEVEL_VWEIGHT;
108                 }
109         }*/
110
111         bm = BME_derivedmesh_to_bmesh(derivedData);
112         BME_bevel(bm,bmd->value,bmd->res,options,defgrp_index,bmd->bevel_angle,NULL);
113         result = BME_bmesh_to_derivedmesh(bm,derivedData);
114         BME_free_mesh(bm);
115
116         CDDM_calc_normals(result);
117 #endif
118
119         return CDDM_copy(derivedData, 0);
120 }
121
122 static DerivedMesh *applyModifierEM(ModifierData *md, Object *ob,
123                                                 EditMesh *UNUSED(editData),
124                                                 DerivedMesh *derivedData)
125 {
126         return applyModifier(md, ob, derivedData, 0, 1);
127 }
128
129
130 ModifierTypeInfo modifierType_Bevel = {
131         /* name */              "Bevel",
132         /* structName */        "BevelModifierData",
133         /* structSize */        sizeof(BevelModifierData),
134         /* type */              eModifierTypeType_Constructive,
135         /* flags */             eModifierTypeFlag_AcceptsMesh
136                                                         | eModifierTypeFlag_SupportsEditmode
137                                                         | eModifierTypeFlag_EnableInEditmode,
138
139         /* copyData */          copyData,
140         /* deformVerts */       0,
141         /* deformMatrices */    0,
142         /* deformVertsEM */     0,
143         /* deformMatricesEM */  0,
144         /* applyModifier */     applyModifier,
145         /* applyModifierEM */   applyModifierEM,
146         /* initData */          initData,
147         /* requiredDataMask */  requiredDataMask,
148         /* freeData */          0,
149         /* isDisabled */        0,
150         /* updateDepgraph */    0,
151         /* dependsOnTime */     0,
152         /* dependsOnNormals */  0,
153         /* foreachObjectLink */ 0,
154         /* foreachIDLink */     0,
155 };