2 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
18 * The Original Code is Copyright (C) 2005 by the Blender Foundation.
19 * All rights reserved.
21 * Contributor(s): Daniel Dunbar
27 * ***** END GPL LICENSE BLOCK *****
31 /** \file blender/modifiers/intern/MOD_multires.c
38 #include "DNA_mesh_types.h"
39 #include "DNA_object_types.h"
41 #include "BKE_cdderivedmesh.h"
43 #include "BKE_multires.h"
44 #include "BKE_modifier.h"
45 #include "BKE_paint.h"
46 #include "BKE_subsurf.h"
50 static void initData(ModifierData *md)
52 MultiresModifierData *mmd = (MultiresModifierData *)md;
60 static void copyData(ModifierData *md, ModifierData *target)
62 MultiresModifierData *mmd = (MultiresModifierData *) md;
63 MultiresModifierData *tmmd = (MultiresModifierData *) target;
66 tmmd->sculptlvl = mmd->sculptlvl;
67 tmmd->renderlvl = mmd->renderlvl;
68 tmmd->totlvl = mmd->totlvl;
69 tmmd->simple = mmd->simple;
70 tmmd->flags = mmd->flags;
73 static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *dm,
74 ModifierApplyFlag flag)
76 MultiresModifierData *mmd = (MultiresModifierData *)md;
78 Mesh *me = (Mesh *)ob->data;
79 const int useRenderParams = flag & MOD_APPLY_RENDER;
80 MultiresFlags flags = 0;
83 if (!CustomData_get_layer(&me->ldata, CD_MDISPS)) {
84 /* multires always needs a displacement layer */
85 CustomData_add_layer(&me->ldata, CD_MDISPS, CD_CALLOC, NULL, me->totloop);
89 flags = MULTIRES_ALLOC_PAINT_MASK;
91 flags |= MULTIRES_USE_RENDER_PARAMS;
93 result = multires_make_derived_from_derived(dm, mmd, ob, flags);
98 if (useRenderParams || !(flag & MOD_APPLY_USECACHE)) {
101 cddm = CDDM_copy(result);
103 /* copy hidden/masks to vertices */
104 if (!useRenderParams) {
105 struct MDisps *mdisps;
106 struct GridPaintMask *grid_paint_mask;
108 mdisps = CustomData_get_layer(&me->ldata, CD_MDISPS);
109 grid_paint_mask = CustomData_get_layer(&me->ldata, CD_GRID_PAINT_MASK);
112 subsurf_copy_grid_hidden(result, me->mpoly,
113 cddm->getVertArray(cddm),
116 BKE_mesh_flush_hidden_from_verts(cddm->getVertArray(cddm),
117 cddm->getLoopArray(cddm),
118 cddm->getEdgeArray(cddm),
119 cddm->getNumEdges(cddm),
120 cddm->getPolyArray(cddm),
121 cddm->getNumPolys(cddm));
123 if (grid_paint_mask) {
124 float *paint_mask = CustomData_add_layer(&cddm->vertData,
127 cddm->getNumVerts(cddm));
129 subsurf_copy_grid_paint_mask(result, me->mpoly,
130 paint_mask, grid_paint_mask);
134 result->release(result);
142 ModifierTypeInfo modifierType_Multires = {
143 /* name */ "Multires",
144 /* structName */ "MultiresModifierData",
145 /* structSize */ sizeof(MultiresModifierData),
146 /* type */ eModifierTypeType_Constructive,
147 /* flags */ eModifierTypeFlag_AcceptsMesh |
148 eModifierTypeFlag_SupportsMapping |
149 eModifierTypeFlag_RequiresOriginalData,
151 /* copyData */ copyData,
152 /* deformVerts */ NULL,
153 /* deformMatrices */ NULL,
154 /* deformVertsEM */ NULL,
155 /* deformMatricesEM */ NULL,
156 /* applyModifier */ applyModifier,
157 /* applyModifierEM */ NULL,
158 /* initData */ initData,
159 /* requiredDataMask */ NULL,
161 /* isDisabled */ NULL,
162 /* updateDepgraph */ NULL,
163 /* dependsOnTime */ NULL,
164 /* dependsOnNormals */ NULL,
165 /* foreachObjectLink */ NULL,
166 /* foreachIDLink */ NULL,
167 /* foreachTexLink */ NULL,