Blender  V2.59
MOD_multires.c
Go to the documentation of this file.
00001 /*
00002 * $Id: MOD_multires.c 36432 2011-05-02 10:21:07Z blendix $
00003 *
00004 * ***** BEGIN GPL LICENSE BLOCK *****
00005 *
00006 * This program is free software; you can redistribute it and/or
00007 * modify it under the terms of the GNU General Public License
00008 * as published by the Free Software Foundation; either version 2
00009 * of the License, or (at your option) any later version.
00010 *
00011 * This program is distributed in the hope that it will be useful,
00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 * GNU General Public License for more details.
00015 *
00016 * You should have received a copy of the GNU General Public License
00017 * along with this program; if not, write to the Free Software  Foundation,
00018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 *
00020 * The Original Code is Copyright (C) 2005 by the Blender Foundation.
00021 * All rights reserved.
00022 *
00023 * Contributor(s): Daniel Dunbar
00024 *                 Ton Roosendaal,
00025 *                 Ben Batt,
00026 *                 Brecht Van Lommel,
00027 *                 Campbell Barton
00028 *
00029 * ***** END GPL LICENSE BLOCK *****
00030 *
00031 */
00032 
00038 #include <stddef.h>
00039 
00040 #include "BKE_cdderivedmesh.h"
00041 #include "BKE_multires.h"
00042 #include "BKE_modifier.h"
00043 #include "BKE_paint.h"
00044 #include "BKE_particle.h"
00045 
00046 #include "DNA_mesh_types.h"
00047 
00048 #include "MOD_util.h"
00049 
00050 static void initData(ModifierData *md)
00051 {
00052         MultiresModifierData *mmd = (MultiresModifierData*)md;
00053 
00054         mmd->lvl = 0;
00055         mmd->sculptlvl = 0;
00056         mmd->renderlvl = 0;
00057         mmd->totlvl = 0;
00058 }
00059 
00060 static void copyData(ModifierData *md, ModifierData *target)
00061 {
00062         MultiresModifierData *mmd = (MultiresModifierData*) md;
00063         MultiresModifierData *tmmd = (MultiresModifierData*) target;
00064 
00065         tmmd->lvl = mmd->lvl;
00066         tmmd->sculptlvl = mmd->sculptlvl;
00067         tmmd->renderlvl = mmd->renderlvl;
00068         tmmd->totlvl = mmd->totlvl;
00069         tmmd->simple = mmd->simple;
00070         tmmd->flags = mmd->flags;
00071 }
00072 
00073 static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *dm,
00074                                                    int useRenderParams, int isFinalCalc)
00075 {
00076         SculptSession *ss= ob->sculpt;
00077         int sculpting= (ob->mode & OB_MODE_SCULPT) && ss;
00078         MultiresModifierData *mmd = (MultiresModifierData*)md;
00079         DerivedMesh *result;
00080         Mesh *me= (Mesh*)ob->data;
00081 
00082         if(mmd->totlvl) {
00083                 if(!CustomData_get_layer(&me->fdata, CD_MDISPS)) {
00084                         /* multires always needs a displacement layer */
00085                         CustomData_add_layer(&me->fdata, CD_MDISPS, CD_CALLOC, NULL, me->totface);
00086                 }
00087         }
00088 
00089         result = multires_dm_create_from_derived(mmd, 0, dm, ob, useRenderParams, isFinalCalc);
00090 
00091         if(result == dm)
00092                 return dm;
00093 
00094         if(useRenderParams || !isFinalCalc) {
00095                 DerivedMesh *cddm= CDDM_copy(result);
00096                 result->release(result);
00097                 result= cddm;
00098         }
00099         else if(sculpting) {
00100                 /* would be created on the fly too, just nicer this
00101                    way on first stroke after e.g. switching levels */
00102                 ss->pbvh= result->getPBVH(ob, result);
00103         }
00104 
00105         return result;
00106 }
00107 
00108 
00109 ModifierTypeInfo modifierType_Multires = {
00110         /* name */              "Multires",
00111         /* structName */        "MultiresModifierData",
00112         /* structSize */        sizeof(MultiresModifierData),
00113         /* type */              eModifierTypeType_Constructive,
00114         /* flags */             eModifierTypeFlag_AcceptsMesh
00115                                                         | eModifierTypeFlag_SupportsMapping
00116                                                         | eModifierTypeFlag_RequiresOriginalData,
00117 
00118         /* copyData */          copyData,
00119         /* deformVerts */       NULL,
00120         /* deformMatrices */    NULL,
00121         /* deformVertsEM */     NULL,
00122         /* deformMatricesEM */  NULL,
00123         /* applyModifier */     applyModifier,
00124         /* applyModifierEM */   NULL,
00125         /* initData */          initData,
00126         /* requiredDataMask */  NULL,
00127         /* freeData */          NULL,
00128         /* isDisabled */        NULL,
00129         /* updateDepgraph */    NULL,
00130         /* dependsOnTime */     NULL,
00131         /* dependsOnNormals */  NULL,
00132         /* foreachObjectLink */ NULL,
00133         /* foreachIDLink */     NULL,
00134 };