|
Blender
V2.59
|
00001 /* 00002 * $Id: MOD_bevel.c 35362 2011-03-05 10:29:10Z campbellbarton $ 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 00037 #include "MEM_guardedalloc.h" 00038 00039 #include "BLI_utildefines.h" 00040 00041 #include "BKE_bmesh.h" 00042 #include "BKE_cdderivedmesh.h" 00043 #include "BKE_modifier.h" 00044 #include "BKE_particle.h" 00045 00046 #include "MOD_util.h" 00047 00048 00049 static void initData(ModifierData *md) 00050 { 00051 BevelModifierData *bmd = (BevelModifierData*) md; 00052 00053 bmd->value = 0.1f; 00054 bmd->res = 1; 00055 bmd->flags = 0; 00056 bmd->val_flags = 0; 00057 bmd->lim_flags = 0; 00058 bmd->e_flags = 0; 00059 bmd->bevel_angle = 30; 00060 bmd->defgrp_name[0] = '\0'; 00061 } 00062 00063 static void copyData(ModifierData *md, ModifierData *target) 00064 { 00065 BevelModifierData *bmd = (BevelModifierData*) md; 00066 BevelModifierData *tbmd = (BevelModifierData*) target; 00067 00068 tbmd->value = bmd->value; 00069 tbmd->res = bmd->res; 00070 tbmd->flags = bmd->flags; 00071 tbmd->val_flags = bmd->val_flags; 00072 tbmd->lim_flags = bmd->lim_flags; 00073 tbmd->e_flags = bmd->e_flags; 00074 tbmd->bevel_angle = bmd->bevel_angle; 00075 strncpy(tbmd->defgrp_name, bmd->defgrp_name, 32); 00076 } 00077 00078 static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md) 00079 { 00080 BevelModifierData *bmd = (BevelModifierData *)md; 00081 CustomDataMask dataMask = 0; 00082 00083 /* ask for vertexgroups if we need them */ 00084 if(bmd->defgrp_name[0]) dataMask |= CD_MASK_MDEFORMVERT; 00085 00086 return dataMask; 00087 } 00088 00089 static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob), 00090 DerivedMesh *derivedData, 00091 int UNUSED(useRenderParams), 00092 int UNUSED(isFinalCalc)) 00093 { 00094 DerivedMesh *result; 00095 BME_Mesh *bm; 00096 00097 /*bDeformGroup *def;*/ 00098 int /*i,*/ options, defgrp_index = -1; 00099 BevelModifierData *bmd = (BevelModifierData*) md; 00100 00101 options = bmd->flags|bmd->val_flags|bmd->lim_flags|bmd->e_flags; 00102 00103 /*if ((options & BME_BEVEL_VWEIGHT) && bmd->defgrp_name[0]) { 00104 defgrp_index = defgroup_name_index(ob, bmd->defgrp_name); 00105 if (defgrp_index < 0) { 00106 options &= ~BME_BEVEL_VWEIGHT; 00107 } 00108 }*/ 00109 00110 bm = BME_derivedmesh_to_bmesh(derivedData); 00111 BME_bevel(bm,bmd->value,bmd->res,options,defgrp_index,bmd->bevel_angle,NULL); 00112 result = BME_bmesh_to_derivedmesh(bm,derivedData); 00113 BME_free_mesh(bm); 00114 00115 CDDM_calc_normals(result); 00116 00117 return result; 00118 } 00119 00120 static DerivedMesh *applyModifierEM(ModifierData *md, Object *ob, 00121 EditMesh *UNUSED(editData), 00122 DerivedMesh *derivedData) 00123 { 00124 return applyModifier(md, ob, derivedData, 0, 1); 00125 } 00126 00127 00128 ModifierTypeInfo modifierType_Bevel = { 00129 /* name */ "Bevel", 00130 /* structName */ "BevelModifierData", 00131 /* structSize */ sizeof(BevelModifierData), 00132 /* type */ eModifierTypeType_Constructive, 00133 /* flags */ eModifierTypeFlag_AcceptsMesh 00134 | eModifierTypeFlag_SupportsEditmode 00135 | eModifierTypeFlag_EnableInEditmode, 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 */ requiredDataMask, 00146 /* freeData */ NULL, 00147 /* isDisabled */ NULL, 00148 /* updateDepgraph */ NULL, 00149 /* dependsOnTime */ NULL, 00150 /* dependsOnNormals */ NULL, 00151 /* foreachObjectLink */ NULL, 00152 /* foreachIDLink */ NULL, 00153 };