diff options
-rw-r--r-- | release/scripts/startup/bl_ui/properties_constraint.py | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/constraint.c | 19 | ||||
-rw-r--r-- | source/blender/blenloader/intern/versioning_280.c | 20 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_constraint_types.h | 20 | ||||
-rw-r--r-- | source/blender/makesdna/intern/dna_rename_defs.h | 1 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_constraint.c | 34 |
6 files changed, 85 insertions, 11 deletions
diff --git a/release/scripts/startup/bl_ui/properties_constraint.py b/release/scripts/startup/bl_ui/properties_constraint.py index a5353a4e29e..fec90fef590 100644 --- a/release/scripts/startup/bl_ui/properties_constraint.py +++ b/release/scripts/startup/bl_ui/properties_constraint.py @@ -430,6 +430,8 @@ class ConstraintButtonsPanel: def MAINTAIN_VOLUME(self, _context, layout, con): + layout.prop(con, "mode") + row = layout.row() row.label(text="Free:") row.prop(con, "free_axis", expand=True) diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c index 0e29f165992..282847fe220 100644 --- a/source/blender/blenkernel/intern/constraint.c +++ b/source/blender/blenkernel/intern/constraint.c @@ -2037,7 +2037,7 @@ static void samevolume_new_data(void *cdata) { bSameVolumeConstraint *data = (bSameVolumeConstraint *)cdata; - data->flag = SAMEVOL_Y; + data->free_axis = SAMEVOL_Y; data->volume = 1.0f; } @@ -2046,19 +2046,30 @@ static void samevolume_evaluate(bConstraint *con, bConstraintOb *cob, ListBase * bSameVolumeConstraint *data = con->data; float volume = data->volume; - float fac = 1.0f, total_scale; + float fac = 1.0f, total_scale = 1.0f; float obsize[3]; mat4_to_size(obsize, cob->matrix); /* calculate normalizing scale factor for non-essential values */ - total_scale = obsize[0] * obsize[1] * obsize[2]; + switch (data->mode) { + case SAMEVOL_STRICT: + total_scale = obsize[0] * obsize[1] * obsize[2]; + break; + case SAMEVOL_UNIFORM: + total_scale = pow3f(obsize[data->free_axis]); + break; + case SAMEVOL_SINGLE_AXIS: + total_scale = obsize[data->free_axis]; + break; + } + if (total_scale != 0) { fac = sqrtf(volume / total_scale); } /* apply scaling factor to the channels not being kept */ - switch (data->flag) { + switch (data->free_axis) { case SAMEVOL_X: mul_v3_fl(cob->matrix[1], fac); mul_v3_fl(cob->matrix[2], fac); diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c index afbb512fe2f..194459a1eda 100644 --- a/source/blender/blenloader/intern/versioning_280.c +++ b/source/blender/blenloader/intern/versioning_280.c @@ -692,6 +692,16 @@ static void do_version_bbone_scale_animdata_cb(ID *UNUSED(id), } } +static void do_version_constraints_maintain_volume_mode_uniform(ListBase *lb) +{ + for (bConstraint *con = lb->first; con; con = con->next) { + if (con->type == CONSTRAINT_TYPE_SAMEVOL) { + bSameVolumeConstraint *data = (bSameVolumeConstraint *)con->data; + data->mode = SAMEVOL_UNIFORM; + } + } +} + void do_versions_after_linking_280(Main *bmain) { bool use_collection_compat_28 = true; @@ -1290,6 +1300,16 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain) } } } + + /* 2.79 style Maintain Volume mode. */ + LISTBASE_FOREACH (Object *, ob, &bmain->objects) { + do_version_constraints_maintain_volume_mode_uniform(&ob->constraints); + if (ob->pose) { + LISTBASE_FOREACH (bPoseChannel *, pchan, &ob->pose->chanbase) { + do_version_constraints_maintain_volume_mode_uniform(&pchan->constraints); + } + } + } } #ifdef USE_COLLECTION_COMPAT_28 diff --git a/source/blender/makesdna/DNA_constraint_types.h b/source/blender/makesdna/DNA_constraint_types.h index f839f22ec9f..d3165efb647 100644 --- a/source/blender/makesdna/DNA_constraint_types.h +++ b/source/blender/makesdna/DNA_constraint_types.h @@ -296,7 +296,9 @@ typedef struct bSizeLikeConstraint { /* Maintain Volume Constraint */ typedef struct bSameVolumeConstraint { - int flag; + char free_axis; + char mode; + char _pad[2]; float volume; } bSameVolumeConstraint; @@ -758,12 +760,22 @@ typedef enum eTransform_ToFrom { TRANS_SCALE = 2, } eTransform_ToFrom; -/* bSameVolumeConstraint.flag */ -typedef enum eSameVolume_Modes { +/* bSameVolumeConstraint.free_axis */ +typedef enum eSameVolume_Axis { SAMEVOL_X = 0, SAMEVOL_Y = 1, SAMEVOL_Z = 2, -} eSameVolume_Modes; +} eSameVolume_Axis; + +/* bSameVolumeConstraint.mode */ +typedef enum eSameVolume_Mode { + /* Strictly maintain the volume, overriding non-free axis scale. */ + SAMEVOL_STRICT = 0, + /* Maintain the volume when scale is uniform, pass non-uniform other axis scale through. */ + SAMEVOL_UNIFORM = 1, + /* Maintain the volume when scaled only on the free axis, pass other axis scale through. */ + SAMEVOL_SINGLE_AXIS = 2, +} eSameVolume_Mode; /* bActionConstraint.flag */ typedef enum eActionConstraint_Flags { diff --git a/source/blender/makesdna/intern/dna_rename_defs.h b/source/blender/makesdna/intern/dna_rename_defs.h index b9e0853b1ab..c02512d2e6b 100644 --- a/source/blender/makesdna/intern/dna_rename_defs.h +++ b/source/blender/makesdna/intern/dna_rename_defs.h @@ -83,6 +83,7 @@ DNA_STRUCT_RENAME_ELEM(bPoseChannel, curveInX, curve_in_x) DNA_STRUCT_RENAME_ELEM(bPoseChannel, curveInY, curve_in_y) DNA_STRUCT_RENAME_ELEM(bPoseChannel, curveOutX, curve_out_x) DNA_STRUCT_RENAME_ELEM(bPoseChannel, curveOutY, curve_out_y) +DNA_STRUCT_RENAME_ELEM(bSameVolumeConstraint, flag, free_axis) DNA_STRUCT_RENAME_ELEM(bTheme, tact, space_action) DNA_STRUCT_RENAME_ELEM(bTheme, tbuts, space_properties) DNA_STRUCT_RENAME_ELEM(bTheme, tclip, space_clip) diff --git a/source/blender/makesrna/intern/rna_constraint.c b/source/blender/makesrna/intern/rna_constraint.c index c1c235d497b..49c1fa779ab 100644 --- a/source/blender/makesrna/intern/rna_constraint.c +++ b/source/blender/makesrna/intern/rna_constraint.c @@ -1346,13 +1346,34 @@ static void rna_def_constraint_same_volume(BlenderRNA *brna) StructRNA *srna; PropertyRNA *prop; - static const EnumPropertyItem volume_items[] = { + static const EnumPropertyItem axis_items[] = { {SAMEVOL_X, "SAMEVOL_X", 0, "X", ""}, {SAMEVOL_Y, "SAMEVOL_Y", 0, "Y", ""}, {SAMEVOL_Z, "SAMEVOL_Z", 0, "Z", ""}, {0, NULL, 0, NULL, NULL}, }; + static const EnumPropertyItem mode_items[] = { + {SAMEVOL_STRICT, + "STRICT", + 0, + "Strict", + "Volume is strictly preserved, overriding the scaling of non-free axes"}, + {SAMEVOL_UNIFORM, + "UNIFORM", + 0, + "Uniform", + "Volume is preserved when the object is scaled uniformly. " + "Deviations from uniform scale on non-free axes are passed through"}, + {SAMEVOL_SINGLE_AXIS, + "SINGLE_AXIS", + 0, + "Single Axis", + "Volume is preserved when the object is scaled only on the free axis. " + "Non-free axis scaling is passed through"}, + {0, NULL, 0, NULL, NULL}, + }; + srna = RNA_def_struct(brna, "MaintainVolumeConstraint", "Constraint"); RNA_def_struct_ui_text(srna, "Maintain Volume Constraint", @@ -1360,11 +1381,18 @@ static void rna_def_constraint_same_volume(BlenderRNA *brna) RNA_def_struct_sdna_from(srna, "bSameVolumeConstraint", "data"); prop = RNA_def_property(srna, "free_axis", PROP_ENUM, PROP_NONE); - RNA_def_property_enum_sdna(prop, NULL, "flag"); - RNA_def_property_enum_items(prop, volume_items); + RNA_def_property_enum_sdna(prop, NULL, "free_axis"); + RNA_def_property_enum_items(prop, axis_items); RNA_def_property_ui_text(prop, "Free Axis", "The free scaling axis of the object"); RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update"); + prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE); + RNA_def_property_enum_sdna(prop, NULL, "mode"); + RNA_def_property_enum_items(prop, mode_items); + RNA_def_property_ui_text( + prop, "Mode", "The way the constraint treats original non-free axis scaling"); + RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update"); + prop = RNA_def_property(srna, "volume", PROP_FLOAT, PROP_DISTANCE); RNA_def_property_range(prop, 0.001f, 100.0f); RNA_def_property_ui_text(prop, "Volume", "Volume of the bone at rest"); |