merge with trunk at r31523
[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 #include "MEM_guardedalloc.h"
33
34 #include "BKE_bmesh.h"
35 #include "BKE_cdderivedmesh.h"
36 #include "BKE_modifier.h"
37 #include "BKE_particle.h"
38
39
40 static void initData(ModifierData *md)
41 {
42         BevelModifierData *bmd = (BevelModifierData*) md;
43
44         bmd->value = 0.1f;
45         bmd->res = 1;
46         bmd->flags = 0;
47         bmd->val_flags = 0;
48         bmd->lim_flags = 0;
49         bmd->e_flags = 0;
50         bmd->bevel_angle = 30;
51         bmd->defgrp_name[0] = '\0';
52 }
53
54 static void copyData(ModifierData *md, ModifierData *target)
55 {
56         BevelModifierData *bmd = (BevelModifierData*) md;
57         BevelModifierData *tbmd = (BevelModifierData*) target;
58
59         tbmd->value = bmd->value;
60         tbmd->res = bmd->res;
61         tbmd->flags = bmd->flags;
62         tbmd->val_flags = bmd->val_flags;
63         tbmd->lim_flags = bmd->lim_flags;
64         tbmd->e_flags = bmd->e_flags;
65         tbmd->bevel_angle = bmd->bevel_angle;
66         strncpy(tbmd->defgrp_name, bmd->defgrp_name, 32);
67 }
68
69 static CustomDataMask requiredDataMask(Object *ob, ModifierData *md)
70 {
71         BevelModifierData *bmd = (BevelModifierData *)md;
72         CustomDataMask dataMask = 0;
73
74         /* ask for vertexgroups if we need them */
75         if(bmd->defgrp_name[0]) dataMask |= (1 << CD_MDEFORMVERT);
76
77         return dataMask;
78 }
79
80 static DerivedMesh *applyModifier(
81                 ModifierData *md, Object *ob, DerivedMesh *derivedData,
82   int useRenderParams, int isFinalCalc)
83 {
84 #if 0
85         DerivedMesh *result;
86         BME_Mesh *bm;
87
88         /*bDeformGroup *def;*/
89         int /*i,*/ options, defgrp_index = -1;
90         BevelModifierData *bmd = (BevelModifierData*) md;
91
92         options = bmd->flags|bmd->val_flags|bmd->lim_flags|bmd->e_flags;
93
94         /*if ((options & BME_BEVEL_VWEIGHT) && bmd->defgrp_name[0]) {
95                 defgrp_index = defgroup_name_index(ob, bmd->defgrp_name);
96                 if (defgrp_index < 0) {
97                         options &= ~BME_BEVEL_VWEIGHT;
98                 }
99         }*/
100
101         bm = BME_derivedmesh_to_bmesh(derivedData);
102         BME_bevel(bm,bmd->value,bmd->res,options,defgrp_index,bmd->bevel_angle,NULL);
103         result = BME_bmesh_to_derivedmesh(bm,derivedData);
104         BME_free_mesh(bm);
105
106         CDDM_calc_normals(result);
107 #endif
108
109         return CDDM_copy(derivedData, 0);
110 }
111
112 static DerivedMesh *applyModifierEM(
113                 ModifierData *md, Object *ob, EditMesh *editData,
114   DerivedMesh *derivedData)
115 {
116         return applyModifier(md, ob, derivedData, 0, 1);
117 }
118
119
120 ModifierTypeInfo modifierType_Bevel = {
121         /* name */              "Bevel",
122         /* structName */        "BevelModifierData",
123         /* structSize */        sizeof(BevelModifierData),
124         /* type */              eModifierTypeType_Constructive,
125         /* flags */             eModifierTypeFlag_AcceptsMesh
126                                                         | eModifierTypeFlag_SupportsEditmode
127                                                         | eModifierTypeFlag_EnableInEditmode,
128
129         /* copyData */          copyData,
130         /* deformVerts */       0,
131         /* deformVertsEM */     0,
132         /* deformMatricesEM */  0,
133         /* applyModifier */     applyModifier,
134         /* applyModifierEM */   applyModifierEM,
135         /* initData */          initData,
136         /* requiredDataMask */  requiredDataMask,
137         /* freeData */          0,
138         /* isDisabled */        0,
139         /* updateDepgraph */    0,
140         /* dependsOnTime */     0,
141         /* foreachObjectLink */ 0,
142         /* foreachIDLink */     0,
143 };