[Bf-blender-cvs] [a9509a2f8a9] master: Maintain scaling ratio of non-free axes in Maintain Volume T48079 fix.

Alexander Gavrilov noreply at git.blender.org
Fri Mar 2 09:06:27 CET 2018


Commit: a9509a2f8a9abfdd12bb21153879af05924db2b5
Author: Alexander Gavrilov
Date:   Fri Mar 2 11:01:49 2018 +0300
Branches: master
https://developer.blender.org/rBa9509a2f8a9abfdd12bb21153879af05924db2b5

Maintain scaling ratio of non-free axes in Maintain Volume T48079 fix.

This is probably a better way to handle it: instead of totally
discarding scaling of non-free axes, keep the ratio between them.
Basically the logic of the constraint is now that it rescales the
object uniformly in the non-free axis plane in order to force the
total volume change to the desired value.

===================================================================

M	source/blender/blenkernel/intern/constraint.c

===================================================================

diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 5d8053e0036..06817133382 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -1926,28 +1926,29 @@ static void samevolume_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *
 	bSameVolumeConstraint *data = con->data;
 
 	float volume = data->volume;
-	float fac = 1.0f;
+	float fac = 1.0f, total_scale;
 	float obsize[3];
 
 	mat4_to_size(obsize, cob->matrix);
 	
 	/* calculate normalizing scale factor for non-essential values */
-	if (obsize[data->flag] != 0) 
-		fac = sqrtf(volume / obsize[data->flag]);
+	total_scale = obsize[0] * obsize[1] * obsize[2];
+	if (total_scale != 0)
+		fac = sqrtf(volume / total_scale);
 	
 	/* apply scaling factor to the channels not being kept */
 	switch (data->flag) {
 		case SAMEVOL_X:
-			mul_v3_fl(cob->matrix[1], fac / obsize[1]);
-			mul_v3_fl(cob->matrix[2], fac / obsize[2]);
+			mul_v3_fl(cob->matrix[1], fac);
+			mul_v3_fl(cob->matrix[2], fac);
 			break;
 		case SAMEVOL_Y:
-			mul_v3_fl(cob->matrix[0], fac / obsize[0]);
-			mul_v3_fl(cob->matrix[2], fac / obsize[2]);
+			mul_v3_fl(cob->matrix[0], fac);
+			mul_v3_fl(cob->matrix[2], fac);
 			break;
 		case SAMEVOL_Z:
-			mul_v3_fl(cob->matrix[0], fac / obsize[0]);
-			mul_v3_fl(cob->matrix[1], fac / obsize[1]);
+			mul_v3_fl(cob->matrix[0], fac);
+			mul_v3_fl(cob->matrix[1], fac);
 			break;
 	}
 }



More information about the Bf-blender-cvs mailing list