Fix #104706: Imported FBX shape key values outside the 0.0 to 1.0 range are clamped #104740

Merged
Bastien Montagne merged 1 commits from Mysteryem/blender-addons:fbx_extend_deformpercent_range_pr into main 2023-07-24 15:20:07 +02:00
Member

This patch changes the FBX import of shape keys by decreasing/increasing
their slider_min/slider_max to fit the imported Value (DeformPercent in
FBX). If the imported Value already fits within the slider range, no
changes are made.

To fit the imported Value, the slider_min/slider_max is set to double
the imported Value if that would fit it within the slider range,
otherwise the slider_min/slider_max is decreased/increased by double the
distance from the imported Value to the current slider_min/slider_max.

Expanded slider_min/slider_max values are rounded down/up to the nearest
integer to produce a more visually pleasing result.

The animated values of shape keys are also checked when animations are
imported and decrease/increase slider_min/slider_max in the same way.

Blender has a hard minimum of -10.0 for slider_min and hard max of 10.0
for slider_max (the importer gets these values from the ShapeKey type's
bl_rna rather than being hardcoded). If a shape key's current or
animated value goes outside that range, a warning is printed to the
system console.

This patch changes the FBX import of shape keys by decreasing/increasing their slider_min/slider_max to fit the imported Value (DeformPercent in FBX). If the imported Value already fits within the slider range, no changes are made. To fit the imported Value, the slider_min/slider_max is set to double the imported Value if that would fit it within the slider range, otherwise the slider_min/slider_max is decreased/increased by double the distance from the imported Value to the current slider_min/slider_max. Expanded slider_min/slider_max values are rounded down/up to the nearest integer to produce a more visually pleasing result. The animated values of shape keys are also checked when animations are imported and decrease/increase slider_min/slider_max in the same way. Blender has a hard minimum of -10.0 for slider_min and hard max of 10.0 for slider_max (the importer gets these values from the ShapeKey type's bl_rna rather than being hardcoded). If a shape key's current or animated value goes outside that range, a warning is printed to the system console.
Author
Member

Setting slider_min/slider_max to double the imported Value when it's outside the default 0.0 to 1.0 range was what was suggested in the issue, but I think there are many different ways this could be handled. Two alternatives for setting slider_min/slider_max that stand out to me are:

  1. Value-1.0/Value+1.0, or some other fixed amount
  2. floor(Value)/ceil(Value), because it results in nice whole numbers
Setting slider_min/slider_max to double the imported Value when it's outside the default 0.0 to 1.0 range was what was suggested in the issue, but I think there are many different ways this could be handled. Two alternatives for setting slider_min/slider_max that stand out to me are: 1. Value-1.0/Value+1.0, or some other fixed amount 1. floor(Value)/ceil(Value), because it results in nice whole numbers
Thomas Barlow requested review from Bastien Montagne 2023-07-06 02:49:26 +02:00
Bastien Montagne requested changes 2023-07-06 10:04:49 +02:00
Bastien Montagne left a comment
Owner

Besides comment below, LGTM.

I do not have a strong opinion regarding computing of new min/max range values... I kinda do like the idea of setting to whole values though, maybe floor(value * 2)/ceil(value * 2) ? floor(value + 1)/ceil(value + 1) ;)

Besides comment below, LGTM. I do not have a strong opinion regarding computing of new min/max range values... I kinda do like the idea of setting to whole values though, maybe `floor(value * 2)`/`ceil(value * 2)` ? `floor(value + 1)`/`ceil(value + 1)` ;)
@ -1644,6 +1677,17 @@ def blen_read_shapes(fbx_tmpl, fbx_data, objects, me, scene):
shape_cos[indices] += dvcos
kb.data.foreach_set("co", shape_cos.ravel())
# The default slider_min is 0.0 and slider_max is 1.0. If the imported weight is outside this range, attempt to

This block of code is essentially the same as the one in the animation handling above? Think both could be factorized into a single utility function, would also help tweaking the min/max slider values behavior without having two edit two different pieces of code.

This block of code is essentially the same as the one in the animation handling above? Think both could be factorized into a single utility function, would also help tweaking the min/max slider values behavior without having two edit two different pieces of code.
Thomas Barlow force-pushed fbx_extend_deformpercent_range_pr from 9d71c330d3 to bda669f05c 2023-07-22 17:39:09 +02:00 Compare
Author
Member

Expanding the slider range has been moved to a separate expand_shape_key_range function in fbx_utils.py.

The method of expanding slider_min/slider_max is now setting the min/max to floor(value * 2)/ceil(value * 2) if that will fit the value within the slider range. This covers all current import cases, but to ensure the function works for generic input, e.g. a current slider_min of 1.0 and value of 2.0, if setting to value * 2 does not work, the function will instead decrease/increase the slider_min/slider_max by double the distance between the slider_min/slider_max and the value, and then perform the same floor/ceil as before.

Expanding the slider range has been moved to a separate `expand_shape_key_range` function in fbx_utils.py. The method of expanding slider_min/slider_max is now setting the min/max to `floor(value * 2)`/`ceil(value * 2)` if that will fit the value within the slider range. This covers all current import cases, but to ensure the function works for generic input, e.g. a current slider_min of 1.0 and value of 2.0, if setting to `value * 2` does not work, the function will instead decrease/increase the slider_min/slider_max by double the distance between the slider_min/slider_max and the value, and then perform the same `floor`/`ceil` as before.
Thomas Barlow requested review from Bastien Montagne 2023-07-22 17:57:37 +02:00
Bastien Montagne approved these changes 2023-07-24 15:19:46 +02:00
Bastien Montagne left a comment
Owner

LGTM, thanks!

LGTM, thanks!
Bastien Montagne merged commit 89bd09391a into main 2023-07-24 15:20:07 +02:00
Bastien Montagne deleted branch fbx_extend_deformpercent_range_pr 2023-07-24 15:20:09 +02:00
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#104740
No description provided.