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