Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-12-15 02:54:38 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-12-15 02:54:38 +0400
commit40a2c1a2921b50edd8b798e79b6bd2a6d94d7bba (patch)
treef28bc2e08718bbf7e8fee729330c5c1e675c180e /source/blender/blenkernel
parent3d5330f789c287666b875706c84228520473add5 (diff)
more vertex weight edits,
* replace inline loops with api calls. * change constraints so verts with 0.0 weight are ignored like they are everywhere else.
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/intern/armature.c9
-rw-r--r--source/blender/blenkernel/intern/constraint.c71
-rw-r--r--source/blender/blenkernel/intern/deform.c6
3 files changed, 42 insertions, 44 deletions
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index e10c4b24458..4035db36a39 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -924,7 +924,6 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm,
float contrib = 0.0f;
float armature_weight = 1.0f; /* default to 1 if no overall def group */
float prevco_weight = 1.0f; /* weight for optional cached vertexcos */
- int j;
if(use_quaternion) {
memset(&sumdq, 0, sizeof(DualQuat));
@@ -971,12 +970,14 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm,
mul_m4_v3(premat, co);
if(use_dverts && dvert && dvert->totweight) { // use weight groups ?
+ MDeformWeight *dw= dvert->dw;
int deformed = 0;
+ unsigned int j;
- for(j = 0; j < dvert->totweight; j++){
- int index = dvert->dw[j].def_nr;
+ for (j= dvert->totweight; j != 0; j--, dw++) {
+ const int index = dw->def_nr;
if(index < defbase_tot && (pchan= defnrToPC[index])) {
- float weight = dvert->dw[j].weight;
+ float weight = dw->weight;
Bone *bone= pchan->bone;
pdef_info= pdef_info_array + defnrToPCIndex[index];
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 6f29594f811..87a50b89547 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -436,16 +436,15 @@ static void contarget_get_mesh_mat (Object *ob, const char *substring, float mat
float vec[3] = {0.0f, 0.0f, 0.0f};
float normal[3] = {0.0f, 0.0f, 0.0f}, plane[3];
float imat[3][3], tmat[3][3];
- int dgroup;
+ const int defgroup= defgroup_name_index(ob, substring);
short freeDM = 0;
/* initialize target matrix using target matrix */
copy_m4_m4(mat, ob->obmat);
/* get index of vertex group */
- dgroup = defgroup_name_index(ob, substring);
- if (dgroup < 0) return;
-
+ if (defgroup == -1) return;
+
/* get DerivedMesh */
if (em) {
/* target is in editmode, so get a special derived mesh */
@@ -463,28 +462,25 @@ static void contarget_get_mesh_mat (Object *ob, const char *substring, float mat
if (dm) {
MDeformVert *dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
int numVerts = dm->getNumVerts(dm);
- int i, j, count = 0;
+ int i, count = 0;
float co[3], nor[3];
/* check that dvert is a valid pointers (just in case) */
if (dvert) {
+ MDeformVert *dv= dvert;
/* get the average of all verts with that are in the vertex-group */
- for (i = 0; i < numVerts; i++) {
- for (j = 0; j < dvert[i].totweight; j++) {
- /* does this vertex belong to nominated vertex group? */
- if (dvert[i].dw[j].def_nr == dgroup) {
- dm->getVertCo(dm, i, co);
- dm->getVertNo(dm, i, nor);
- add_v3_v3(vec, co);
- add_v3_v3(normal, nor);
- count++;
- break;
- }
+ for (i = 0; i < numVerts; i++, dv++) {
+ MDeformWeight *dw= defvert_find_index(dv, defgroup);
+ if (dw && dw->weight != 0.0f) {
+ dm->getVertCo(dm, i, co);
+ dm->getVertNo(dm, i, nor);
+ add_v3_v3(vec, co);
+ add_v3_v3(normal, nor);
+ count++;
}
}
-
-
+
/* calculate averages of normal and coordinates */
if (count > 0) {
mul_v3_fl(vec, 1.0f / count);
@@ -535,43 +531,38 @@ static void contarget_get_lattice_mat (Object *ob, const char *substring, float
float *co = dl?dl->verts:NULL;
BPoint *bp = lt->def;
- MDeformVert *dvert = lt->dvert;
+ MDeformVert *dv = lt->dvert;
int tot_verts= lt->pntsu*lt->pntsv*lt->pntsw;
float vec[3]= {0.0f, 0.0f, 0.0f}, tvec[3];
- int dgroup=0, grouped=0;
+ int grouped=0;
int i, n;
+ const int defgroup= defgroup_name_index(ob, substring);
/* initialize target matrix using target matrix */
copy_m4_m4(mat, ob->obmat);
-
+
/* get index of vertex group */
- dgroup = defgroup_name_index(ob, substring);
- if (dgroup < 0) return;
- if (dvert == NULL) return;
+ if (defgroup == -1) return;
+ if (dv == NULL) return;
/* 1. Loop through control-points checking if in nominated vertex-group.
* 2. If it is, add it to vec to find the average point.
*/
- for (i=0; i < tot_verts; i++, dvert++) {
- for (n= 0; n < dvert->totweight; n++) {
- /* found match - vert is in vgroup */
- if (dvert->dw[n].def_nr == dgroup) {
+ for (i=0; i < tot_verts; i++, dv++) {
+ for (n= 0; n < dv->totweight; n++) {
+ MDeformWeight *dw= defvert_find_index(dv, defgroup);
+ if (dw && dw->weight > 0.0f) {
/* copy coordinates of point to temporary vector, then add to find average */
- if (co)
- memcpy(tvec, co, 3*sizeof(float));
- else
- memcpy(tvec, bp->vec, 3*sizeof(float));
-
+ memcpy(tvec, co ? co : bp->vec, 3 * sizeof(float));
+
add_v3_v3(vec, tvec);
grouped++;
-
- break;
}
}
/* advance pointer to coordinate data */
- if (co) co+= 3;
- else bp++;
+ if (co) co += 3;
+ else bp++;
}
/* find average location, then multiply by ob->obmat to find world-space location */
@@ -1106,10 +1097,10 @@ static void kinematic_new_data (void *cdata)
{
bKinematicConstraint *data= (bKinematicConstraint *)cdata;
- data->weight= (float)1.0;
- data->orientweight= (float)1.0;
+ data->weight= 1.0f;
+ data->orientweight= 1.0f;
data->iterations = 500;
- data->dist= (float)1.0;
+ data->dist= 1.0f;
data->flag= CONSTRAINT_IK_TIP|CONSTRAINT_IK_STRETCH|CONSTRAINT_IK_POS;
}
diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c
index 4d3af172b22..e14fd6827af 100644
--- a/source/blender/blenkernel/intern/deform.c
+++ b/source/blender/blenkernel/intern/deform.c
@@ -539,6 +539,12 @@ float defvert_find_weight(const struct MDeformVert *dvert, const int defgroup)
return dw ? dw->weight : 0.0f;
}
+/* take care with this the rationale is:
+ * - if the object has no vertex group. act like vertex group isnt set and return 1.0,
+ * - if the vertex group exists but the 'defgroup' isnt found on this vertex, _still_ return 0.0
+ *
+ * This is a bit confusing, just saves some checks from the caller.
+ */
float defvert_array_find_weight_safe(const struct MDeformVert *dvert, const int index, const int defgroup)
{
if (defgroup == -1 || dvert == NULL)