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:
authorRoland Hess <me@harkyman.com>2010-03-16 15:55:56 +0300
committerRoland Hess <me@harkyman.com>2010-03-16 15:55:56 +0300
commitd617294c49912b1b0473bbbe58f62a3549641482 (patch)
treebbbb6645fb501d566047a43a0222137aacd50f93 /source/blender/blenkernel/intern/constraint.c
parent1cf95d2494ab82af61153abc3c45fa1a4fd3a4ed (diff)
New "Maintain Volume" constraint. When attached to a bone, you specify a "free" axis. Upon scaling, this free axis scales normally, but the constraint forces the other two axes to adjust themselves appropriately so that overall bone volume is maintained. So, setting "Y" as the free axis (the default) creates a bone that automatically squashes and stretches when scaling. Thanks to Aligorith, Fweeb, Cessen and others for the feedback.
Diffstat (limited to 'source/blender/blenkernel/intern/constraint.c')
-rw-r--r--source/blender/blenkernel/intern/constraint.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 91bf4b8d8b2..08ac5e6acce 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -1859,6 +1859,64 @@ static bConstraintTypeInfo CTI_TRANSLIKE = {
translike_evaluate /* evaluate */
};
+/* ---------- Maintain Volume ---------- */
+
+static void samevolume_new_data (void *cdata)
+{
+ bSameVolumeConstraint *data= (bSameVolumeConstraint *)cdata;
+
+ data->flag = SAMEVOL_Y;
+ data->volume = 1.0f;
+}
+
+static void samevolume_evaluate (bConstraint *con, bConstraintOb *cob)
+{
+ bSameVolumeConstraint *data= con->data;
+
+ float obsize[3];
+ float volume=data->volume;
+
+ mat4_to_size(obsize, cob->matrix);
+
+ switch (data->flag) {
+ case SAMEVOL_X:
+ if (obsize[0]!=0) {
+ mul_v3_fl(cob->matrix[1], sqrt(volume/obsize[0])/obsize[0]);
+ mul_v3_fl(cob->matrix[2], sqrt(volume/obsize[0])/obsize[0]);
+ }
+ break;
+ case SAMEVOL_Y:
+ if (obsize[1]!=0) {
+ mul_v3_fl(cob->matrix[0], sqrt(volume/obsize[1])/obsize[1]);
+ mul_v3_fl(cob->matrix[2], sqrt(volume/obsize[1])/obsize[1]);
+ }
+ break;
+ case SAMEVOL_Z:
+ if (obsize[2]!=0) {
+ mul_v3_fl(cob->matrix[0], sqrt(volume/obsize[2])/obsize[2]);
+ mul_v3_fl(cob->matrix[1], sqrt(volume/obsize[2])/obsize[2]);
+ }
+ break;
+ }
+
+}
+
+static bConstraintTypeInfo CTI_SAMEVOL = {
+ CONSTRAINT_TYPE_SAMEVOL, /* type */
+ sizeof(bSameVolumeConstraint), /* size */
+ "Maintain Volume", /* name */
+ "bSameVolumeConstraint", /* struct name */
+ NULL, /* free data */
+ NULL, /* relink data */
+ NULL, /* id looper */
+ NULL, /* copy data */
+ samevolume_new_data, /* new data */
+ NULL, /* get constraint targets */
+ NULL, /* flush constraint targets */
+ NULL, /* get target matrix */
+ samevolume_evaluate /* evaluate */
+};
+
/* ----------- Python Constraint -------------- */
static void pycon_free (bConstraint *con)
@@ -3805,6 +3863,7 @@ static void constraints_init_typeinfo () {
constraintsTypeInfo[21]= &CTI_DAMPTRACK; /* Damped TrackTo Constraint */
constraintsTypeInfo[22]= &CTI_SPLINEIK; /* Spline IK Constraint */
constraintsTypeInfo[23]= &CTI_TRANSLIKE; /* Copy Transforms Constraint */
+ constraintsTypeInfo[24]= &CTI_SAMEVOL; /* Maintain Volume Constraint */
}
/* This function should be used for getting the appropriate type-info when only