2010-04-11 22:12:30 +00:00
|
|
|
/*
|
2011-10-23 17:52:20 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2005 by the Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s): Daniel Dunbar
|
|
|
|
* Ton Roosendaal,
|
|
|
|
* Ben Batt,
|
|
|
|
* Brecht Van Lommel,
|
|
|
|
* Campbell Barton
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*
|
|
|
|
*/
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2011-02-25 13:57:17 +00:00
|
|
|
/** \file blender/modifiers/intern/MOD_subsurf.c
|
|
|
|
* \ingroup modifiers
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2011-03-09 01:25:59 +00:00
|
|
|
#include <stddef.h>
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2010-04-12 00:36:50 +00:00
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
#include "DNA_object_types.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2011-01-07 18:36:47 +00:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
2011-01-07 19:18:31 +00:00
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
#include "BKE_cdderivedmesh.h"
|
|
|
|
#include "BKE_scene.h"
|
|
|
|
#include "BKE_subsurf.h"
|
|
|
|
|
|
|
|
#include "MOD_modifiertypes.h"
|
|
|
|
|
2013-01-24 02:14:39 +00:00
|
|
|
#include "intern/CCGSubSurf.h"
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
static void initData(ModifierData *md)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
SubsurfModifierData *smd = (SubsurfModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
smd->levels = 1;
|
|
|
|
smd->renderLevels = 2;
|
|
|
|
smd->flags |= eSubsurfModifierFlag_SubsurfUv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void copyData(ModifierData *md, ModifierData *target)
|
|
|
|
{
|
2013-12-22 04:35:52 +11:00
|
|
|
#if 0
|
2012-05-06 13:38:33 +00:00
|
|
|
SubsurfModifierData *smd = (SubsurfModifierData *) md;
|
2013-12-22 04:35:52 +11:00
|
|
|
#endif
|
2012-05-06 13:38:33 +00:00
|
|
|
SubsurfModifierData *tsmd = (SubsurfModifierData *) target;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2013-12-22 04:35:52 +11:00
|
|
|
modifier_copyData_generic(md, target);
|
|
|
|
|
|
|
|
tsmd->emCache = tsmd->mCache = NULL;
|
|
|
|
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void freeData(ModifierData *md)
|
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
SubsurfModifierData *smd = (SubsurfModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (smd->mCache) {
|
2010-04-11 22:12:30 +00:00
|
|
|
ccgSubSurf_free(smd->mCache);
|
|
|
|
}
|
2012-03-24 06:24:53 +00:00
|
|
|
if (smd->emCache) {
|
2010-04-11 22:12:30 +00:00
|
|
|
ccgSubSurf_free(smd->emCache);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-02 03:59:19 +00:00
|
|
|
static bool isDisabled(ModifierData *md, int useRenderParams)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
SubsurfModifierData *smd = (SubsurfModifierData *) md;
|
|
|
|
int levels = (useRenderParams) ? smd->renderLevels : smd->levels;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2015-05-04 16:26:28 +05:00
|
|
|
return get_render_subsurf_level(&md->scene->r, levels, useRenderParams != 0) == 0;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
2011-05-19 11:24:56 +00:00
|
|
|
static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
|
2012-05-06 13:38:33 +00:00
|
|
|
DerivedMesh *derivedData,
|
2012-05-09 15:00:26 +00:00
|
|
|
ModifierApplyFlag flag)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
SubsurfModifierData *smd = (SubsurfModifierData *) md;
|
2012-05-10 20:31:55 +00:00
|
|
|
SubsurfFlags subsurf_flags = 0;
|
2010-04-11 22:12:30 +00:00
|
|
|
DerivedMesh *result;
|
2014-06-18 16:05:42 +06:00
|
|
|
const bool useRenderParams = (flag & MOD_APPLY_RENDER) != 0;
|
|
|
|
const bool isFinalCalc = (flag & MOD_APPLY_USECACHE) != 0;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-05-11 08:05:47 +00:00
|
|
|
if (useRenderParams)
|
2012-05-10 20:31:55 +00:00
|
|
|
subsurf_flags |= SUBSURF_USE_RENDER_PARAMS;
|
2012-05-11 08:05:47 +00:00
|
|
|
if (isFinalCalc)
|
2012-05-10 20:31:55 +00:00
|
|
|
subsurf_flags |= SUBSURF_IS_FINAL_CALC;
|
2013-01-14 16:05:47 +00:00
|
|
|
if (ob->mode & OB_MODE_EDIT)
|
2012-05-10 20:31:55 +00:00
|
|
|
subsurf_flags |= SUBSURF_IN_EDIT_MODE;
|
|
|
|
|
|
|
|
result = subsurf_make_derived_from_derived(derivedData, smd, NULL, subsurf_flags);
|
2013-02-26 14:32:53 +00:00
|
|
|
result->cd_flag = derivedData->cd_flag;
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2012-03-24 06:24:53 +00:00
|
|
|
if (useRenderParams || !isFinalCalc) {
|
2012-05-06 13:38:33 +00:00
|
|
|
DerivedMesh *cddm = CDDM_copy(result);
|
2010-04-11 22:12:30 +00:00
|
|
|
result->release(result);
|
2012-05-06 13:38:33 +00:00
|
|
|
result = cddm;
|
2010-04-11 22:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-10-14 06:29:17 +00:00
|
|
|
static DerivedMesh *applyModifierEM(ModifierData *md, Object *UNUSED(ob),
|
2012-05-06 13:38:33 +00:00
|
|
|
struct BMEditMesh *UNUSED(editData),
|
2013-05-02 14:42:05 +00:00
|
|
|
DerivedMesh *derivedData,
|
2013-09-12 10:41:00 +00:00
|
|
|
ModifierApplyFlag flag)
|
2010-04-11 22:12:30 +00:00
|
|
|
{
|
2012-05-06 13:38:33 +00:00
|
|
|
SubsurfModifierData *smd = (SubsurfModifierData *) md;
|
2010-04-11 22:12:30 +00:00
|
|
|
DerivedMesh *result;
|
2013-09-12 10:41:00 +00:00
|
|
|
/* 'orco' using editmode flags would cause cache to be used twice in editbmesh_calc_modifiers */
|
|
|
|
SubsurfFlags ss_flags = (flag & MOD_APPLY_ORCO) ? 0 : (SUBSURF_FOR_EDIT_MODE | SUBSURF_IN_EDIT_MODE);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
2013-09-12 10:41:00 +00:00
|
|
|
result = subsurf_make_derived_from_derived(derivedData, smd, NULL, ss_flags);
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ModifierTypeInfo modifierType_Subsurf = {
|
|
|
|
/* name */ "Subsurf",
|
|
|
|
/* structName */ "SubsurfModifierData",
|
|
|
|
/* structSize */ sizeof(SubsurfModifierData),
|
|
|
|
/* type */ eModifierTypeType_Constructive,
|
2012-05-06 13:38:33 +00:00
|
|
|
/* flags */ eModifierTypeFlag_AcceptsMesh |
|
|
|
|
eModifierTypeFlag_SupportsMapping |
|
|
|
|
eModifierTypeFlag_SupportsEditmode |
|
|
|
|
eModifierTypeFlag_EnableInEditmode |
|
|
|
|
eModifierTypeFlag_AcceptsCVs,
|
2010-04-11 22:12:30 +00:00
|
|
|
|
|
|
|
/* copyData */ copyData,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* deformVerts */ NULL,
|
|
|
|
/* deformMatrices */ NULL,
|
|
|
|
/* deformVertsEM */ NULL,
|
|
|
|
/* deformMatricesEM */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* applyModifier */ applyModifier,
|
|
|
|
/* applyModifierEM */ applyModifierEM,
|
|
|
|
/* initData */ initData,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* requiredDataMask */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
/* freeData */ freeData,
|
|
|
|
/* isDisabled */ isDisabled,
|
2011-03-05 10:29:10 +00:00
|
|
|
/* updateDepgraph */ NULL,
|
|
|
|
/* dependsOnTime */ NULL,
|
|
|
|
/* dependsOnNormals */ NULL,
|
|
|
|
/* foreachObjectLink */ NULL,
|
|
|
|
/* foreachIDLink */ NULL,
|
2011-08-12 18:11:22 +00:00
|
|
|
/* foreachTexLink */ NULL,
|
2010-04-11 22:12:30 +00:00
|
|
|
};
|
2011-08-12 18:11:22 +00:00
|
|
|
|