code cleanup: make bmesh operator names more consistant since python has access to...
[blender.git] / source / blender / modifiers / intern / MOD_subsurf.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_subsurf.c
32  *  \ingroup modifiers
33  */
34
35
36 #include <stddef.h>
37
38 #include "DNA_scene_types.h"
39 #include "DNA_object_types.h"
40
41 #include "BLI_utildefines.h"
42
43
44 #include "BKE_cdderivedmesh.h"
45 #include "BKE_scene.h"
46 #include "BKE_subsurf.h"
47
48 #include "MOD_modifiertypes.h"
49
50 #include "CCGSubSurf.h"
51
52 static void initData(ModifierData *md)
53 {
54         SubsurfModifierData *smd = (SubsurfModifierData *) md;
55
56         smd->levels = 1;
57         smd->renderLevels = 2;
58         smd->flags |= eSubsurfModifierFlag_SubsurfUv;
59 }
60
61 static void copyData(ModifierData *md, ModifierData *target)
62 {
63         SubsurfModifierData *smd = (SubsurfModifierData *) md;
64         SubsurfModifierData *tsmd = (SubsurfModifierData *) target;
65
66         tsmd->flags = smd->flags;
67         tsmd->levels = smd->levels;
68         tsmd->renderLevels = smd->renderLevels;
69         tsmd->subdivType = smd->subdivType;
70 }
71
72 static void freeData(ModifierData *md)
73 {
74         SubsurfModifierData *smd = (SubsurfModifierData *) md;
75
76         if (smd->mCache) {
77                 ccgSubSurf_free(smd->mCache);
78         }
79         if (smd->emCache) {
80                 ccgSubSurf_free(smd->emCache);
81         }
82 }
83
84 static int isDisabled(ModifierData *md, int useRenderParams)
85 {
86         SubsurfModifierData *smd = (SubsurfModifierData *) md;
87         int levels = (useRenderParams) ? smd->renderLevels : smd->levels;
88
89         return get_render_subsurf_level(&md->scene->r, levels) == 0;
90 }
91
92 static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
93                                   DerivedMesh *derivedData,
94                                   ModifierApplyFlag flag)
95 {
96         SubsurfModifierData *smd = (SubsurfModifierData *) md;
97         SubsurfFlags subsurf_flags = 0;
98         DerivedMesh *result;
99         const int useRenderParams = flag & MOD_APPLY_RENDER;
100         const int isFinalCalc = flag & MOD_APPLY_USECACHE;
101
102         if (useRenderParams)
103                 subsurf_flags |= SUBSURF_USE_RENDER_PARAMS;
104         if (isFinalCalc)
105                 subsurf_flags |= SUBSURF_IS_FINAL_CALC;
106         if (ob->flag & OB_MODE_EDIT)
107                 subsurf_flags |= SUBSURF_IN_EDIT_MODE;
108         
109         result = subsurf_make_derived_from_derived(derivedData, smd, NULL, subsurf_flags);
110         
111         if (useRenderParams || !isFinalCalc) {
112                 DerivedMesh *cddm = CDDM_copy(result);
113                 result->release(result);
114                 result = cddm;
115         }
116
117         return result;
118 }
119
120 static DerivedMesh *applyModifierEM(ModifierData *md, Object *UNUSED(ob),
121                                     struct BMEditMesh *UNUSED(editData),
122                                     DerivedMesh *derivedData)
123 {
124         SubsurfModifierData *smd = (SubsurfModifierData *) md;
125         DerivedMesh *result;
126
127         result = subsurf_make_derived_from_derived(derivedData, smd,
128                                                    NULL, (SUBSURF_FOR_EDIT_MODE |
129                                                           SUBSURF_IN_EDIT_MODE));
130
131         return result;
132 }
133
134
135 ModifierTypeInfo modifierType_Subsurf = {
136         /* name */              "Subsurf",
137         /* structName */        "SubsurfModifierData",
138         /* structSize */        sizeof(SubsurfModifierData),
139         /* type */              eModifierTypeType_Constructive,
140         /* flags */             eModifierTypeFlag_AcceptsMesh |
141                                 eModifierTypeFlag_SupportsMapping |
142                                 eModifierTypeFlag_SupportsEditmode |
143                                 eModifierTypeFlag_EnableInEditmode |
144                                 eModifierTypeFlag_AcceptsCVs,
145
146         /* copyData */          copyData,
147         /* deformVerts */       NULL,
148         /* deformMatrices */    NULL,
149         /* deformVertsEM */     NULL,
150         /* deformMatricesEM */  NULL,
151         /* applyModifier */     applyModifier,
152         /* applyModifierEM */   applyModifierEM,
153         /* initData */          initData,
154         /* requiredDataMask */  NULL,
155         /* freeData */          freeData,
156         /* isDisabled */        isDisabled,
157         /* updateDepgraph */    NULL,
158         /* dependsOnTime */     NULL,
159         /* dependsOnNormals */  NULL,
160         /* foreachObjectLink */ NULL,
161         /* foreachIDLink */     NULL,
162         /* foreachTexLink */    NULL,
163 };
164