Blender V2.61 - r43446
|
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_mesh_types.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 "MOD_util.h" 00047 00048 static void initData(ModifierData *md) 00049 { 00050 MultiresModifierData *mmd = (MultiresModifierData*)md; 00051 00052 mmd->lvl = 0; 00053 mmd->sculptlvl = 0; 00054 mmd->renderlvl = 0; 00055 mmd->totlvl = 0; 00056 } 00057 00058 static void copyData(ModifierData *md, ModifierData *target) 00059 { 00060 MultiresModifierData *mmd = (MultiresModifierData*) md; 00061 MultiresModifierData *tmmd = (MultiresModifierData*) target; 00062 00063 tmmd->lvl = mmd->lvl; 00064 tmmd->sculptlvl = mmd->sculptlvl; 00065 tmmd->renderlvl = mmd->renderlvl; 00066 tmmd->totlvl = mmd->totlvl; 00067 tmmd->simple = mmd->simple; 00068 tmmd->flags = mmd->flags; 00069 } 00070 00071 static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *dm, 00072 int useRenderParams, int isFinalCalc) 00073 { 00074 SculptSession *ss= ob->sculpt; 00075 int sculpting= (ob->mode & OB_MODE_SCULPT) && ss; 00076 MultiresModifierData *mmd = (MultiresModifierData*)md; 00077 DerivedMesh *result; 00078 Mesh *me= (Mesh*)ob->data; 00079 00080 if(mmd->totlvl) { 00081 if(!CustomData_get_layer(&me->fdata, CD_MDISPS)) { 00082 /* multires always needs a displacement layer */ 00083 CustomData_add_layer(&me->fdata, CD_MDISPS, CD_CALLOC, NULL, me->totface); 00084 } 00085 } 00086 00087 result = multires_dm_create_from_derived(mmd, 0, dm, ob, useRenderParams, isFinalCalc); 00088 00089 if(result == dm) 00090 return dm; 00091 00092 if(useRenderParams || !isFinalCalc) { 00093 DerivedMesh *cddm= CDDM_copy(result); 00094 result->release(result); 00095 result= cddm; 00096 } 00097 else if(sculpting) { 00098 /* would be created on the fly too, just nicer this 00099 way on first stroke after e.g. switching levels */ 00100 ss->pbvh= result->getPBVH(ob, result); 00101 } 00102 00103 return result; 00104 } 00105 00106 00107 ModifierTypeInfo modifierType_Multires = { 00108 /* name */ "Multires", 00109 /* structName */ "MultiresModifierData", 00110 /* structSize */ sizeof(MultiresModifierData), 00111 /* type */ eModifierTypeType_Constructive, 00112 /* flags */ eModifierTypeFlag_AcceptsMesh 00113 | eModifierTypeFlag_SupportsMapping 00114 | eModifierTypeFlag_RequiresOriginalData, 00115 00116 /* copyData */ copyData, 00117 /* deformVerts */ NULL, 00118 /* deformMatrices */ NULL, 00119 /* deformVertsEM */ NULL, 00120 /* deformMatricesEM */ NULL, 00121 /* applyModifier */ applyModifier, 00122 /* applyModifierEM */ NULL, 00123 /* initData */ initData, 00124 /* requiredDataMask */ NULL, 00125 /* freeData */ NULL, 00126 /* isDisabled */ NULL, 00127 /* updateDepgraph */ NULL, 00128 /* dependsOnTime */ NULL, 00129 /* dependsOnNormals */ NULL, 00130 /* foreachObjectLink */ NULL, 00131 /* foreachIDLink */ NULL, 00132 /* foreachTexLink */ NULL, 00133 };