[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11925] trunk/blender/source/blender: adding 2 new functions
Campbell Barton
cbarton at metavr.com
Mon Sep 3 00:54:00 CEST 2007
Revision: 11925
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11925
Author: campbellbarton
Date: 2007-09-03 00:53:59 +0200 (Mon, 03 Sep 2007)
Log Message:
-----------
adding 2 new functions
Mat3ToScalef and Mat4ToScalef
These return a floating point scale value which is the average of the 3 axies.
Use this to adjust curve radius when applying scale/rot
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_arithb.h
trunk/blender/source/blender/blenlib/intern/arithb.c
trunk/blender/source/blender/src/editarmature.c
trunk/blender/source/blender/src/editobject.c
Modified: trunk/blender/source/blender/blenlib/BLI_arithb.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_arithb.h 2007-09-02 21:03:59 UTC (rev 11924)
+++ trunk/blender/source/blender/blenlib/BLI_arithb.h 2007-09-02 22:53:59 UTC (rev 11925)
@@ -333,6 +333,9 @@
void SizeToMat3(float *size, float mat[][3]);
void SizeToMat4(float *size, float mat[][4]);
+float Mat3ToScalef(float mat[][3]);
+float Mat4ToScalef(float mat[][4]);
+
void printmatrix3(char *str, float m[][3]);
void printmatrix4(char *str, float m[][4]);
Modified: trunk/blender/source/blender/blenlib/intern/arithb.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/arithb.c 2007-09-02 21:03:59 UTC (rev 11924)
+++ trunk/blender/source/blender/blenlib/intern/arithb.c 2007-09-02 22:53:59 UTC (rev 11925)
@@ -2866,6 +2866,25 @@
size[2]= VecLength(mat[2]);
}
+/* this gets the average scale of a matrix, only use when your scaling
+ * data that has no idea of scale axis, examples are bone-envelope-radius
+ * and curve radius */
+float Mat3ToScalef(float mat[][3])
+{
+ /* unit length vector */
+ float unit_vec[3] = {0.577350269189626, 0.577350269189626, 0.577350269189626};
+ Mat3MulVecfl(mat, unit_vec);
+ return VecLength(unit_vec);
+}
+
+float Mat4ToScalef(float mat[][4])
+{
+ float tmat[3][3];
+ Mat3CpyMat4(tmat, mat);
+ return Mat3ToScalef(tmat);
+}
+
+
/* ************* SPECIALS ******************* */
void triatoquat( float *v1, float *v2, float *v3, float *quat)
@@ -3581,4 +3600,3 @@
mat[3][1] = loc[1];
mat[3][2] = loc[2];
}
-
Modified: trunk/blender/source/blender/src/editarmature.c
===================================================================
--- trunk/blender/source/blender/src/editarmature.c 2007-09-02 21:03:59 UTC (rev 11924)
+++ trunk/blender/source/blender/src/editarmature.c 2007-09-02 22:53:59 UTC (rev 11925)
@@ -346,16 +346,11 @@
ListBase list;
EditBone *ebone;
bArmature *arm;
- float scale; /* store the scale of the matrix here to use on envelopes */
+ float scale = Mat3ToScalef(mat); /* store the scale of the matrix here to use on envelopes */
arm = get_armature(ob);
- if (!arm) {
- return;
- } else {
- float tmp[3] = {1.0, 1.0, 1.0};
- Mat3MulVecfl(mat, tmp);
- scale = (fabs(tmp[0]) + fabs(tmp[1]) + fabs(tmp[2])) / 3.0f;
- }
+ if (!arm)
+ return;
/* Put the armature into editmode */
list.first= list.last = NULL;
@@ -2653,22 +2648,13 @@
}
/* compute the weights based on gathered vertices and bones */
- if (heat) {
+ if (heat)
heat_bone_weighting(ob, mesh, verts, numbones, dgrouplist, dgroupflip,
root, tip, selected);
- } else {
- float scale;
- float tmp[3] = {1.0, 1.0, 1.0};
- float mat[3][3];
-
- /* scale value from matrix, wont account for non uniform scale but ok */
- Mat3CpyMat4(mat, par->obmat);
- Mat3MulVecfl(mat, tmp);
- scale = (fabs(tmp[0]) + fabs(tmp[1]) + fabs(tmp[2])) / 3.0f;
-
+ else
envelope_bone_weighting(ob, mesh, verts, numbones, bonelist, dgrouplist,
- dgroupflip, root, tip, selected, scale);
- }
+ dgroupflip, root, tip, selected, Mat4ToScalef(par->obmat));
+
/* free the memory allocated */
MEM_freeN(bonelist);
MEM_freeN(dgrouplist);
Modified: trunk/blender/source/blender/src/editobject.c
===================================================================
--- trunk/blender/source/blender/src/editobject.c 2007-09-02 21:03:59 UTC (rev 11924)
+++ trunk/blender/source/blender/src/editobject.c 2007-09-02 22:53:59 UTC (rev 11925)
@@ -3728,7 +3728,9 @@
where_is_object(ob);
}
else if ELEM(ob->type, OB_CURVE, OB_SURF) {
+ float scale;
object_to_mat3(ob, mat);
+ scale = Mat3ToScalef(mat);
cu= ob->data;
if(cu->id.us>1) {
@@ -3749,6 +3751,7 @@
Mat3MulVecfl(mat, bezt->vec[0]);
Mat3MulVecfl(mat, bezt->vec[1]);
Mat3MulVecfl(mat, bezt->vec[2]);
+ bezt->radius *= scale;
bezt++;
}
}
More information about the Bf-blender-cvs
mailing list