[Bf-blender-cvs] [12591ea] temp_constraint_volume: Generalizing constraint volume preservation.
Lukas Tönne
noreply at git.blender.org
Thu Jan 15 13:54:04 CET 2015
Commit: 12591ea55e5ebe8c60cbdb119d3dc8d0d0898ccb
Author: Lukas Tönne
Date: Fri Jan 9 08:49:53 2015 +0100
Branches: temp_constraint_volume
https://developer.blender.org/rB12591ea55e5ebe8c60cbdb119d3dc8d0d0898ccb
Generalizing constraint volume preservation.
Moved settings for volume adjustment, limits and smoothing out of the
StretchTo constraint, so they can be reused by other constraints.
===================================================================
M release/scripts/startup/bl_ui/properties_constraint.py
M source/blender/blenkernel/BKE_blender.h
M source/blender/blenkernel/intern/armature.c
M source/blender/blenkernel/intern/constraint.c
M source/blender/blenloader/intern/versioning_270.c
M source/blender/makesdna/DNA_constraint_types.h
M source/blender/makesrna/intern/rna_constraint.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_constraint.py b/release/scripts/startup/bl_ui/properties_constraint.py
index 0c5aae1..6f8f321 100644
--- a/release/scripts/startup/bl_ui/properties_constraint.py
+++ b/release/scripts/startup/bl_ui/properties_constraint.py
@@ -89,6 +89,27 @@ class ConstraintButtonsPanel():
col = split.column()
col.prop(con, "chain_count")
+ def volume_settings_template(self, layout, volume):
+ layout.prop(volume, "bulge", text="Volume Variation")
+ split = layout.split()
+ col = split.column(align=True)
+ col.prop(volume, "use_bulge_min", text="Volume Min")
+ sub = col.column()
+ sub.active = volume.use_bulge_min
+ sub.prop(volume, "bulge_min", text="")
+ col = split.column(align=True)
+ col.prop(volume, "use_bulge_max", text="Volume Max")
+ sub = col.column()
+ sub.active = volume.use_bulge_max
+ sub.prop(volume, "bulge_max", text="")
+ col = layout.column()
+ col.active = volume.use_bulge_min or volume.use_bulge_max
+ col.prop(volume, "bulge_smooth", text="Smooth")
+
+ row = layout.row()
+ row.label(text="Volume:")
+ row.prop(volume, "mode", expand=True)
+
def CHILD_OF(self, context, layout, con):
self.target_template(layout, con)
@@ -501,25 +522,7 @@ class ConstraintButtonsPanel():
row.prop(con, "rest_length", text="Rest Length")
row.operator("constraint.stretchto_reset", text="Reset")
- layout.prop(con, "bulge", text="Volume Variation")
- split = layout.split()
- col = split.column(align=True)
- col.prop(con, "use_bulge_min", text="Volume Min")
- sub = col.column()
- sub.active = con.use_bulge_min
- sub.prop(con, "bulge_min", text="")
- col = split.column(align=True)
- col.prop(con, "use_bulge_max", text="Volume Max")
- sub = col.column()
- sub.active = con.use_bulge_max
- sub.prop(con, "bulge_max", text="")
- col = layout.column()
- col.active = con.use_bulge_min or con.use_bulge_max
- col.prop(con, "bulge_smooth", text="Smooth")
-
- row = layout.row()
- row.label(text="Volume:")
- row.prop(con, "volume", expand=True)
+ self.volume_settings_template(layout, con.volume)
row.label(text="Plane:")
row.prop(con, "keep_axis", expand=True)
diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h
index 0215bec..3053c99 100644
--- a/source/blender/blenkernel/BKE_blender.h
+++ b/source/blender/blenkernel/BKE_blender.h
@@ -42,7 +42,7 @@ extern "C" {
* and keep comment above the defines.
* Use STRINGIFY() rather than defining with quotes */
#define BLENDER_VERSION 273
-#define BLENDER_SUBVERSION 2
+#define BLENDER_SUBVERSION 3
/* 262 was the last editmesh release but it has compatibility code for bmesh data */
#define BLENDER_MINVERSION 270
#define BLENDER_MINSUBVERSION 5
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 03372b9..431c24d 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -2200,7 +2200,7 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o
float bulge = powf(1.0f / fabsf(scaleFac), ikData->bulge);
if (bulge > 1.0f) {
- if (ikData->flag & STRETCHTOCON_USE_BULGE_MAX) {
+ if (ikData->flag & CONSTRAINT_SPLINEIK_USE_BULGE_MAX) {
float bulge_max = max_ff(ikData->bulge_max, 1.0f);
float hard = min_ff(bulge, bulge_max);
@@ -2212,7 +2212,7 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o
}
}
if (bulge < 1.0f) {
- if (ikData->flag & STRETCHTOCON_USE_BULGE_MIN) {
+ if (ikData->flag & CONSTRAINT_SPLINEIK_USE_BULGE_MIN) {
float bulge_min = CLAMPIS(ikData->bulge_min, 0.0f, 1.0f);
float hard = max_ff(bulge, bulge_min);
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index f591fe8..1c3c3c6 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -578,6 +578,72 @@ static void constraint_target_to_mat4(Object *ob, const char *substring, float m
}
}
+/* ------------ Volume Preservation ---------- */
+
+static void constraint_volume_init(bConstraintVolumeSettings *vol)
+{
+ vol->mode = CONSTRAINT_VOLUME_XZ;
+ vol->bulge = 1.0f;
+ vol->bulge_min = 1.0f;
+ vol->bulge_max = 1.0f;
+ vol->bulge_smooth = 0.0f;
+ vol->flag = 0;
+}
+
+static void constraint_volume_eval_scale(float result[3], bConstraintVolumeSettings *vol, float factor)
+{
+ float bulge = powf(factor, vol->bulge);
+
+ if (bulge > 1.0f) {
+ if (vol->flag & CONSTRAINT_VOLUME_USE_MAX) {
+ float bulge_max = max_ff(vol->bulge_max, 1.0f);
+ float hard = min_ff(bulge, bulge_max);
+
+ float range = bulge_max - 1.0f;
+ float scale = (range > 0.0f) ? 1.0f / range : 0.0f;
+ float soft = 1.0f + range * atanf((bulge - 1.0f) * scale) / (0.5f * M_PI);
+
+ bulge = interpf(soft, hard, vol->bulge_smooth);
+ }
+ }
+ if (bulge < 1.0f) {
+ if (vol->flag & CONSTRAINT_VOLUME_USE_MIN) {
+ float bulge_min = CLAMPIS(vol->bulge_max, 0.0f, 1.0f); /* bulge_max is not a mistake: used as upper limit for bulge_min! */
+ float hard = max_ff(bulge, bulge_min);
+
+ float range = 1.0f - bulge_min;
+ float scale = (range > 0.0f) ? 1.0f / range : 0.0f;
+ float soft = 1.0f - range * atanf((1.0f - bulge) * scale) / (0.5f * M_PI);
+
+ bulge = interpf(soft, hard, vol->bulge_smooth);
+ }
+ }
+
+ result[1] = factor;
+ switch (vol->mode) {
+ /* volume preserving scaling */
+ case CONSTRAINT_VOLUME_XZ:
+ result[0] = result[2] = sqrtf(bulge);
+ break;
+ case CONSTRAINT_VOLUME_X:
+ result[0] = bulge;
+ result[2] = 1.0f;
+ break;
+ case CONSTRAINT_VOLUME_Z:
+ result[0] = 1.0f;
+ result[2] = bulge;
+ break;
+ /* don't care for volume */
+ case CONSTRAINT_NONE:
+ result[0] = 1.0f;
+ result[2] = 1.0f;
+ break;
+ default: /* should not happen */
+ BLI_assert(false);
+ break;
+ }
+}
+
/* ************************* Specific Constraints ***************************** */
/* Each constraint defines a set of functions, which will be called at the appropriate
* times. In addition to this, each constraint should have a type-info struct, where
@@ -2626,12 +2692,9 @@ static void stretchto_new_data(void *cdata)
{
bStretchToConstraint *data = (bStretchToConstraint *)cdata;
- data->volmode = 0;
data->plane = 0;
data->orglength = 0.0;
- data->bulge = 1.0;
- data->bulge_max = 1.0f;
- data->bulge_min = 1.0f;
+ constraint_volume_init(&data->volume);
}
static void stretchto_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
@@ -2677,7 +2740,7 @@ static void stretchto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
if (VALID_CONS_TARGET(ct)) {
float size[3], scale[3], vec[3], xx[3], zz[3], orth[3];
float totmat[3][3];
- float dist, bulge;
+ float dist;
/* store scaling before destroying obmat */
mat4_to_size(size, cob->matrix);
@@ -2704,57 +2767,7 @@ static void stretchto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
if (data->orglength == 0)
data->orglength = dist;
- scale[1] = dist / data->orglength;
-
- bulge = powf(data->orglength / dist, data->bulge);
-
- if (bulge > 1.0f) {
- if (data->flag & STRETCHTOCON_USE_BULGE_MAX) {
- float bulge_max = max_ff(data->bulge_max, 1.0f);
- float hard = min_ff(bulge, bulge_max);
-
- float range = bulge_max - 1.0f;
- float scale = (range > 0.0f) ? 1.0f / range : 0.0f;
- float soft = 1.0f + range * atanf((bulge - 1.0f) * scale) / (0.5f * M_PI);
-
- bulge = interpf(soft, hard, data->bulge_smooth);
- }
- }
- if (bulge < 1.0f) {
- if (data->flag & STRETCHTOCON_USE_BULGE_MIN) {
- float bulge_min = CLAMPIS(data->bulge_min, 0.0f, 1.0f);
- float hard = max_ff(bulge, bulge_min);
-
- float range = 1.0f - bulge_min;
- float scale = (range > 0.0f) ? 1.0f / range : 0.0f;
- float soft = 1.0f - range * atanf((1.0f - bulge) * scale) / (0.5f * M_PI);
-
- bulge = interpf(soft, hard, data->bulge_smooth);
- }
- }
-
- switch (data->volmode) {
- /* volume preserving scaling */
- case VOLUME_XZ:
- scale[0] = sqrtf(bulge);
- scale[2] = scale[0];
- break;
- case VOLUME_X:
- scale[0] = bulge;
- scale[2] = 1.0;
- break;
- case VOLUME_Z:
- scale[0] = 1.0;
- scale[2] = bulge;
- break;
- /* don't care for volume */
- case NO_VOLUME:
- scale[0] = 1.0;
- scale[2] = 1.0;
- break;
- default: /* should not happen, but in case*/
- return;
- } /* switch (data->volmode) */
+ constraint_volume_eval_scale(scale, &data->volume, dist / data->orglength);
/* Clear the object's rotation and scale */
cob->matrix[0][0] = size[0] * scale[0];
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index ca54f06..536540b 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -126,6 +126,29 @@ static void do_version_constraints_stretch_to_limits(ListBase *lb)
}
}
+/* transfer volume settings to new struct */
+static void do_version_constraints_volume_settings(ListBase *lb)
+{
+ bConstraint *con;
+
+ for (con = lb->first; con; con = con->next) {
+ if (con->type == CONSTRAINT_TYPE_STRETCHTO) {
+ bStretchToConstraint *data = (bStretchToConstraint *)con->data;
+
+ data->volume.mode = data->volmode;
+ data->volume.flag = 0;
+ if (data->flag & _STRETCHTOCON_USE_BULGE_MIN)
+ data->volume.flag |= CONSTRAINT_VOLUME_USE_MIN;
+ if (data->flag & _STRETCHTOCON_USE_BULGE_MAX)
+ data->volume.flag |= CONSTRAINT_VOLUME_USE_MAX;
+ data->volume.bulge = data->bulge;
+ data->volume.bulge_min = data->bulge_min;
+ data->volume.bulge_max = data->bulge_max;
+ data->volume.bulge_smooth = data->bulge_smooth;
+ }
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list