Blender V2.61 - r43446

MOD_subsurf.c

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software  Foundation,
00016  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  *
00018  * The Original Code is Copyright (C) 2005 by the Blender Foundation.
00019  * All rights reserved.
00020  *
00021  * Contributor(s): Daniel Dunbar
00022  *                 Ton Roosendaal,
00023  *                 Ben Batt,
00024  *                 Brecht Van Lommel,
00025  *                 Campbell Barton
00026  *
00027  * ***** END GPL LICENSE BLOCK *****
00028  *
00029  */
00030 
00036 #include <stddef.h>
00037 
00038 #include "DNA_scene_types.h"
00039 #include "DNA_object_types.h"
00040 
00041 #include "BLI_utildefines.h"
00042 
00043 
00044 #include "BKE_cdderivedmesh.h"
00045 #include "BKE_scene.h"
00046 #include "BKE_subsurf.h"
00047 
00048 #include "MOD_modifiertypes.h"
00049 
00050 #include "CCGSubSurf.h"
00051 
00052 static void initData(ModifierData *md)
00053 {
00054     SubsurfModifierData *smd = (SubsurfModifierData*) md;
00055 
00056     smd->levels = 1;
00057     smd->renderLevels = 2;
00058     smd->flags |= eSubsurfModifierFlag_SubsurfUv;
00059 }
00060 
00061 static void copyData(ModifierData *md, ModifierData *target)
00062 {
00063     SubsurfModifierData *smd = (SubsurfModifierData*) md;
00064     SubsurfModifierData *tsmd = (SubsurfModifierData*) target;
00065 
00066     tsmd->flags = smd->flags;
00067     tsmd->levels = smd->levels;
00068     tsmd->renderLevels = smd->renderLevels;
00069     tsmd->subdivType = smd->subdivType;
00070 }
00071 
00072 static void freeData(ModifierData *md)
00073 {
00074     SubsurfModifierData *smd = (SubsurfModifierData*) md;
00075 
00076     if(smd->mCache) {
00077         ccgSubSurf_free(smd->mCache);
00078     }
00079     if(smd->emCache) {
00080         ccgSubSurf_free(smd->emCache);
00081     }
00082 }
00083 
00084 static int isDisabled(ModifierData *md, int useRenderParams)
00085 {
00086     SubsurfModifierData *smd = (SubsurfModifierData*) md;
00087     int levels= (useRenderParams)? smd->renderLevels: smd->levels;
00088 
00089     return get_render_subsurf_level(&md->scene->r, levels) == 0;
00090 }
00091 
00092 static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
00093                         DerivedMesh *derivedData,
00094                         int useRenderParams,
00095                         int isFinalCalc)
00096 {
00097     SubsurfModifierData *smd = (SubsurfModifierData*) md;
00098     DerivedMesh *result;
00099 
00100     result = subsurf_make_derived_from_derived(derivedData, smd,
00101             useRenderParams, NULL, isFinalCalc, 0, (ob->flag & OB_MODE_EDIT));
00102     
00103     if(useRenderParams || !isFinalCalc) {
00104         DerivedMesh *cddm= CDDM_copy(result);
00105         result->release(result);
00106         result= cddm;
00107     }
00108 
00109     return result;
00110 }
00111 
00112 static DerivedMesh *applyModifierEM(ModifierData *md, Object *UNUSED(ob),
00113                         struct EditMesh *UNUSED(editData),
00114                         DerivedMesh *derivedData)
00115 {
00116     SubsurfModifierData *smd = (SubsurfModifierData*) md;
00117     DerivedMesh *result;
00118 
00119     result = subsurf_make_derived_from_derived(derivedData, smd, 0,
00120             NULL, 0, 1, 1);
00121 
00122     return result;
00123 }
00124 
00125 
00126 ModifierTypeInfo modifierType_Subsurf = {
00127     /* name */              "Subsurf",
00128     /* structName */        "SubsurfModifierData",
00129     /* structSize */        sizeof(SubsurfModifierData),
00130     /* type */              eModifierTypeType_Constructive,
00131     /* flags */             eModifierTypeFlag_AcceptsMesh
00132                             | eModifierTypeFlag_SupportsMapping
00133                             | eModifierTypeFlag_SupportsEditmode
00134                             | eModifierTypeFlag_EnableInEditmode
00135                             | eModifierTypeFlag_AcceptsCVs,
00136 
00137     /* copyData */          copyData,
00138     /* deformVerts */       NULL,
00139     /* deformMatrices */    NULL,
00140     /* deformVertsEM */     NULL,
00141     /* deformMatricesEM */  NULL,
00142     /* applyModifier */     applyModifier,
00143     /* applyModifierEM */   applyModifierEM,
00144     /* initData */          initData,
00145     /* requiredDataMask */  NULL,
00146     /* freeData */          freeData,
00147     /* isDisabled */        isDisabled,
00148     /* updateDepgraph */    NULL,
00149     /* dependsOnTime */     NULL,
00150     /* dependsOnNormals */  NULL,
00151     /* foreachObjectLink */ NULL,
00152     /* foreachIDLink */     NULL,
00153     /* foreachTexLink */    NULL,
00154 };
00155