vertex group option for lattice, needed for applying a lattice to a beard/moustache without moving the roots about.

This commit is contained in:
2010-04-20 21:38:55 +00:00
parent 3754201720
commit 24eedb2175
7 changed files with 76 additions and 42 deletions

View File

@@ -93,7 +93,9 @@ class DATA_PT_lattice(DataButtonsPanel):
col = split.column()
col.prop(lat, "interpolation_type_w", text="")
layout.prop(lat, "outside")
row = layout.row()
row.prop(lat, "outside")
row.prop_object(lat, "vertex_group", context.object, "vertex_groups", text="")
classes = [

View File

@@ -54,6 +54,7 @@
#include "BKE_curve.h"
#include "BKE_depsgraph.h"
#include "BKE_DerivedMesh.h"
#include "BKE_deform.h"
#include "BKE_displist.h"
#include "BKE_global.h"
#include "BKE_idprop.h"
@@ -368,7 +369,7 @@ int bone_autoside_name (char *name, int strip_number, short axis, float head, fl
char extension[5]={""};
len= strlen(name);
if (len == 0) return;
if (len == 0) return 0;
strcpy(basename, name);
/* Figure out extension to append:
@@ -924,7 +925,7 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm,
int numGroups = 0; /* safety for vertexgroup index overflow */
int i, target_totvert = 0; /* safety for vertexgroup overflow */
int use_dverts = 0;
int armature_def_nr = -1;
int armature_def_nr;
int totchan;
if(arm->edbo) return;
@@ -956,9 +957,7 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm,
}
/* get the def_nr for the overall armature vertex group if present */
for(i = 0, dg = target->defbase.first; dg; i++, dg = dg->next)
if(defgrp_name && strcmp(defgrp_name, dg->name) == 0)
armature_def_nr = i;
armature_def_nr= defgroup_name_index(target, defgrp_name);
/* get a vertex-deform-index to posechannel array */
if(deformflag & ARM_DEF_VGROUP) {

View File

@@ -59,6 +59,7 @@
#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "BKE_utildefines.h"
#include "BKE_deform.h"
//XXX #include "BIF_editdeform.h"
@@ -338,19 +339,29 @@ void calc_latt_deform(Object *ob, float *co, float weight)
{
Lattice *lt= ob->data;
float u, v, w, tu[4], tv[4], tw[4];
float *fpw, *fpv, *fpu, vec[3];
float vec[3];
int idx_w, idx_v, idx_u;
int ui, vi, wi, uu, vv, ww;
/* vgroup influence */
int defgroup_nr= -1;
float co_prev[3], weight_blend= 0.0f;
MDeformVert *dvert= lattice_get_deform_verts(ob);
if(lt->editlatt) lt= lt->editlatt;
if(lt->latticedata==NULL) return;
if(lt->vgroup[0] && dvert) {
defgroup_nr= defgroup_name_index(ob, lt->vgroup);
copy_v3_v3(co_prev, co);
}
/* co is in local coords, treat with latmat */
VECCOPY(vec, co);
mul_m4_v3(lt->latmat, vec);
mul_v3_m4v3(vec, lt->latmat, co);
/* u v w coords */
if(lt->pntsu>1) {
u= (vec[0]-lt->fu)/lt->du;
ui= (int)floor(u);
@@ -361,7 +372,7 @@ void calc_latt_deform(Object *ob, float *co, float weight)
tu[0]= tu[2]= tu[3]= 0.0; tu[1]= 1.0;
ui= 0;
}
if(lt->pntsv>1) {
v= (vec[1]-lt->fv)/lt->dv;
vi= (int)floor(v);
@@ -372,7 +383,7 @@ void calc_latt_deform(Object *ob, float *co, float weight)
tv[0]= tv[2]= tv[3]= 0.0; tv[1]= 1.0;
vi= 0;
}
if(lt->pntsw>1) {
w= (vec[2]-lt->fw)/lt->dw;
wi= (int)floor(w);
@@ -383,46 +394,51 @@ void calc_latt_deform(Object *ob, float *co, float weight)
tw[0]= tw[2]= tw[3]= 0.0; tw[1]= 1.0;
wi= 0;
}
for(ww= wi-1; ww<=wi+2; ww++) {
w= tw[ww-wi+1];
if(w!=0.0) {
if(ww>0) {
if(ww<lt->pntsw) fpw= lt->latticedata + 3*ww*lt->pntsu*lt->pntsv;
else fpw= lt->latticedata + 3*(lt->pntsw-1)*lt->pntsu*lt->pntsv;
if(ww<lt->pntsw) idx_w= ww*lt->pntsu*lt->pntsv;
else idx_w= (lt->pntsw-1)*lt->pntsu*lt->pntsv;
}
else fpw= lt->latticedata;
else idx_w= 0;
for(vv= vi-1; vv<=vi+2; vv++) {
v= w*tv[vv-vi+1];
if(v!=0.0) {
if(vv>0) {
if(vv<lt->pntsv) fpv= fpw + 3*vv*lt->pntsu;
else fpv= fpw + 3*(lt->pntsv-1)*lt->pntsu;
if(vv<lt->pntsv) idx_v= idx_w + vv*lt->pntsu;
else idx_v= idx_w + (lt->pntsv-1)*lt->pntsu;
}
else fpv= fpw;
else idx_v= idx_w;
for(uu= ui-1; uu<=ui+2; uu++) {
u= weight*v*tu[uu-ui+1];
if(u!=0.0) {
if(uu>0) {
if(uu<lt->pntsu) fpu= fpv + 3*uu;
else fpu= fpv + 3*(lt->pntsu-1);
if(uu<lt->pntsu) idx_u= idx_v + uu;
else idx_u= idx_v + (lt->pntsu-1);
}
else fpu= fpv;
co[0]+= u*fpu[0];
co[1]+= u*fpu[1];
co[2]+= u*fpu[2];
else idx_u= idx_v;
madd_v3_v3fl(co, &lt->latticedata[idx_u * 3], u);
if(defgroup_nr != -1)
weight_blend += (u * defvert_find_weight(dvert + idx_u, defgroup_nr));
}
}
}
}
}
}
if(defgroup_nr != -1)
interp_v3_v3v3(co, co_prev, co, weight_blend);
}
void end_latt_deform(Object *ob)

View File

@@ -12204,9 +12204,10 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
if(G.rt==-666) {
while(fd==NULL) {
char newlib_path[240] = { 0 };
printf("Missing library: '%s', '%s'\n", mainptr->name, G.sce);
printf(" abs: %s\n", mainptr->curlib->filename);
printf(" rel: %s\n", mainptr->curlib->name);
printf("Missing library...'\n");
printf(" current file: %s\n", G.sce);
printf(" absolute lib: %s\n", mainptr->curlib->filename);
printf(" relative lib: %s\n", mainptr->curlib->name);
printf(" enter a new path:\n");
scanf("%s", newlib_path);
@@ -12217,7 +12218,7 @@ static void read_libraries(FileData *basefd, ListBase *mainlist)
fd= blo_openblenderfile(mainptr->curlib->filename, basefd->reports);
if(fd) {
printf("found: '%s', party on macuno!\n");
printf("found: '%s', party on macuno!\n", mainptr->curlib->filename);
}
}
}

View File

@@ -52,6 +52,7 @@ typedef struct Lattice {
struct Key *key;
struct MDeformVert *dvert;
char vgroup[32]; /* multiply the influence */
/* used while deforming, always free and NULL after use */
float *latticedata;

View File

@@ -41,6 +41,7 @@
#include "BKE_depsgraph.h"
#include "BKE_lattice.h"
#include "BKE_main.h"
#include "BKE_deform.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -157,6 +158,16 @@ static void rna_Lattice_points_w_set(PointerRNA *ptr, int value)
((Lattice*)ptr->data)->opntsw= CLAMPIS(value, 1, 64);
}
static void rna_Lattice_vg_name_set(PointerRNA *ptr, const char *value)
{
Lattice *lt= ptr->data;
strcpy(lt->vgroup, value);
if(lt->editlatt)
strcpy(lt->editlatt->vgroup, value);
}
#else
static void rna_def_latticepoint(BlenderRNA *brna)
@@ -245,6 +256,12 @@ static void rna_def_lattice(BlenderRNA *brna)
RNA_def_property_boolean_funcs(prop, NULL, "rna_Lattice_outside_set");
RNA_def_property_ui_text(prop, "Outside", "Only draw, and take into account, the outer vertices");
RNA_def_property_update(prop, 0, "rna_Lattice_update_data");
prop= RNA_def_property(srna, "vertex_group", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "vgroup");
RNA_def_property_ui_text(prop, "Vertex Group", "Vertex group to apply the influence of the lattice");
RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Lattice_vg_name_set");
RNA_def_property_update(prop, 0, "rna_Lattice_update_data");
prop= RNA_def_property(srna, "shape_keys", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "key");

View File

@@ -213,10 +213,8 @@ static DerivedMesh *applyModifier(ModifierData *md,
/* 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);
int defgrp_index= defgroup_name_index(ob, smd->defgrp_name);
if (defgrp_index >= 0)
dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);