diff options
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenkernel/intern/modifier.c | 93 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_modifier_types.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_modifier.c | 13 |
3 files changed, 92 insertions, 16 deletions
diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c index acab22abde4..76e49c0726b 100644 --- a/source/blender/blenkernel/intern/modifier.c +++ b/source/blender/blenkernel/intern/modifier.c @@ -5718,6 +5718,7 @@ static void solidifyModifier_copyData(ModifierData *md, ModifierData *target) SolidifyModifierData *smd = (SolidifyModifierData*) md; SolidifyModifierData *tsmd = (SolidifyModifierData*) target; tsmd->offset = smd->offset; + tsmd->offset_fac = smd->offset_fac; tsmd->crease_inner = smd->crease_inner; tsmd->crease_outer = smd->crease_outer; tsmd->crease_rim = smd->crease_rim; @@ -5755,6 +5756,19 @@ static DerivedMesh *solidifyModifier_applyModifier(ModifierData *md, float (*vert_nors)[3]= NULL; + float ofs_orig= - (((-smd->offset_fac + 1.0f) * 0.5f) * smd->offset); + float ofs_new= smd->offset - (((-smd->offset_fac + 1.0f) * 0.5f) * smd->offset); + + /* weights */ + MDeformVert *dvert= NULL, *dv= NULL; + int defgrp_index= -1; + int defgrp_invert = ((smd->flag & MOD_SOLIDIFY_VGROUP_INV) != 0); + + defgrp_index= defgroup_name_index(ob, smd->defgrp_name); + + if (defgrp_index >= 0) + dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); + orig_mface = dm->getFaceArray(dm); orig_medge = dm->getEdgeArray(dm); orig_mvert = dm->getVertArray(dm); @@ -5888,16 +5902,38 @@ static DerivedMesh *solidifyModifier_applyModifier(ModifierData *md, if((smd->flag & MOD_SOLIDIFY_EVEN) == 0) { /* no even thickness, very simple */ - float scalar_short = smd->offset / 32767.0f; - - if(smd->offset < 0.0f) mv= mvert+numVerts; - else mv= mvert; + float scalar_short; + float scalar_short_vgroup; + + + if(ofs_new != 0.0f) { + scalar_short= scalar_short_vgroup= ofs_new / 32767.0f; + mv= mvert + ((ofs_new >= ofs_orig) ? 0 : numVerts); + dv= dvert; + for(i=0; i<numVerts; i++, mv++) { + if(dv) { + if(defgrp_invert) scalar_short_vgroup = scalar_short * (1.0f - defvert_find_weight(dv, defgrp_index)); + else scalar_short_vgroup = scalar_short * defvert_find_weight(dv, defgrp_index); + dv++; + } + VECADDFAC(mv->co, mv->co, mv->no, scalar_short_vgroup); + } + } - for(i=0; i<numVerts; i++, mv++) { - mv->co[0] += mv->no[0] * scalar_short; - mv->co[1] += mv->no[1] * scalar_short; - mv->co[2] += mv->no[2] * scalar_short; + if(ofs_orig != 0.0f) { + scalar_short= scalar_short_vgroup= ofs_orig / 32767.0f; + mv= mvert + ((ofs_new >= ofs_orig) ? numVerts : 0); /* same as above but swapped, intentional use of 'ofs_new' */ + dv= dvert; + for(i=0; i<numVerts; i++, mv++) { + if(dv) { + if(defgrp_invert) scalar_short_vgroup = scalar_short * (1.0f - defvert_find_weight(dv, defgrp_index)); + else scalar_short_vgroup = scalar_short * defvert_find_weight(dv, defgrp_index); + dv++; + } + VECADDFAC(mv->co, mv->co, mv->no, scalar_short_vgroup); + } } + } else { /* make a face normal layer if not present */ @@ -5949,12 +5985,38 @@ static DerivedMesh *solidifyModifier_applyModifier(ModifierData *md, } } - if(smd->offset < 0.0f) mv= mvert+numVerts; - else mv= mvert; + /* vertex group support */ + if(dvert) { + dv= dvert; + if(defgrp_invert) { + for(i=0; i<numVerts; i++, dv++) { + vert_angles[i] *= (1.0f - defvert_find_weight(dv, defgrp_index)); + } + } + else { + for(i=0; i<numVerts; i++, dv++) { + vert_angles[i] *= defvert_find_weight(dv, defgrp_index); + } + } + } + + if(ofs_new) { + mv= mvert + ((ofs_new >= ofs_orig) ? 0 : numVerts); - for(i=0; i<numVerts; i++, mv++) { - if(vert_accum[i]) { /* zero if unselected */ - madd_v3_v3fl(mv->co, vert_nors[i], smd->offset * (vert_angles[i] / vert_accum[i])); + for(i=0; i<numVerts; i++, mv++) { + if(vert_accum[i]) { /* zero if unselected */ + madd_v3_v3fl(mv->co, vert_nors[i], ofs_new * (vert_angles[i] / vert_accum[i])); + } + } + } + + if(ofs_orig) { + mv= mvert + ((ofs_new >= ofs_orig) ? numVerts : 0); /* same as above but swapped, intentional use of 'ofs_new' */ + + for(i=0; i<numVerts; i++, mv++) { + if(vert_accum[i]) { /* zero if unselected */ + madd_v3_v3fl(mv->co, vert_nors[i], ofs_orig * (vert_angles[i] / vert_accum[i])); + } } } @@ -7943,10 +8005,11 @@ static void explodeModifier_createFacepa(ExplodeModifierData *emd, MDeformVert *dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT); float val; if(dvert){ - for(i=0; i<totvert; i++){ + int defgrp_index= emd->vgroup-1; + for(i=0; i<totvert; i++, dvert++){ val = BLI_frand(); val = (1.0f-emd->protect)*val + emd->protect*0.5f; - if(val < defvert_find_weight(dvert+i,emd->vgroup-1)) + if(val < defvert_find_weight(dvert, defgrp_index)) vertpa[i] = -1; } } diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h index f5b80266e5c..a9178a392f4 100644 --- a/source/blender/makesdna/DNA_modifier_types.h +++ b/source/blender/makesdna/DNA_modifier_types.h @@ -683,6 +683,7 @@ typedef struct SolidifyModifierData { char defgrp_name[32]; /* name of vertex group to use */ float offset; /* new surface offset level*/ + float offset_fac; /* midpoint of the offset */ float crease_inner; float crease_outer; float crease_rim; @@ -692,6 +693,7 @@ typedef struct SolidifyModifierData { #define MOD_SOLIDIFY_RIM (1<<0) #define MOD_SOLIDIFY_EVEN (1<<1) #define MOD_SOLIDIFY_NORMAL_CALC (1<<2) +#define MOD_SOLIDIFY_VGROUP_INV (1<<3) typedef struct ScrewModifierData { ModifierData modifier; diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index 4abf9793e72..14be3665adc 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -2040,13 +2040,20 @@ static void rna_def_modifier_solidify(BlenderRNA *brna) RNA_def_struct_sdna(srna, "SolidifyModifierData"); RNA_def_struct_ui_icon(srna, ICON_MOD_SOLIDIFY); - prop= RNA_def_property(srna, "offset", PROP_FLOAT, PROP_DISTANCE); + prop= RNA_def_property(srna, "thickness", PROP_FLOAT, PROP_DISTANCE); RNA_def_property_float_sdna(prop, NULL, "offset"); RNA_def_property_range(prop, -FLT_MAX, FLT_MAX); RNA_def_property_ui_range(prop, -10, 10, 0.1, 4); RNA_def_property_ui_text(prop, "Thickness", "Thickness of the shell"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); + prop= RNA_def_property(srna, "offset", PROP_FLOAT, PROP_DISTANCE); + RNA_def_property_float_sdna(prop, NULL, "offset_fac"); + RNA_def_property_range(prop, -FLT_MAX, FLT_MAX); + RNA_def_property_ui_range(prop, -1, 1, 0.1, 4); + RNA_def_property_ui_text(prop, "Offset", ""); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); + prop= RNA_def_property(srna, "edge_crease_inner", PROP_FLOAT, PROP_FACTOR); RNA_def_property_float_sdna(prop, NULL, "crease_inner"); RNA_def_property_range(prop, 0, 1); @@ -2089,6 +2096,10 @@ static void rna_def_modifier_solidify(BlenderRNA *brna) RNA_def_property_ui_text(prop, "High Quality Normals", "Calculate normals which result in more even thickness (slow, disable when not needed)"); RNA_def_property_update(prop, 0, "rna_Modifier_update"); + prop= RNA_def_property(srna, "invert", PROP_BOOLEAN, PROP_NONE); + RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_SOLIDIFY_VGROUP_INV); + RNA_def_property_ui_text(prop, "Vertex Group Invert", "Invert the vertex group influence"); + RNA_def_property_update(prop, 0, "rna_Modifier_update"); } static void rna_def_modifier_screw(BlenderRNA *brna) |