Skip to content

Commit 3fd1aee

Browse files
camerasolver - Change how the attribute percentage
1 parent d816920 commit 3fd1aee

1 file changed

Lines changed: 41 additions & 6 deletions

File tree

python/mmSolver/tools/camerasolver/lib/defaults.py

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from __future__ import print_function
2929

3030
import mmSolver.utils.time as time_utils
31+
import mmSolver.utils.math as math_utils
3132
import mmSolver.utils.python_compat as pycompat
3233

3334
import mmSolver.tools.camerasolver.constant as const
@@ -52,12 +53,46 @@ def compute_focal_length_min_max_from_percentage(focal_length_mm, percentage_val
5253
# type: (...) -> tuple
5354
assert isinstance(focal_length_mm, float)
5455
assert isinstance(percentage_value, float)
55-
factor = percentage_value / 100.0
56-
# TODO: Define a "standard" range and then create range of values
57-
# from that.
58-
focal_length_min = focal_length_mm * (1.0 - factor)
59-
focal_length_max = focal_length_mm * (1.0 + factor)
60-
return max(0.1, focal_length_min), focal_length_max
56+
57+
factor = max(0.0, percentage_value / 100.0)
58+
59+
# The first standard range of values.
60+
#
61+
# This range of values is what the majority of users will need.
62+
std1_range_min = 8.0
63+
std1_range_max = 120.0
64+
65+
# The second standard range of values (outside the first range).
66+
std2_range_min = 2.0
67+
std2_range_max = 500.0
68+
69+
# The absolute bounds of what can be solved.
70+
#
71+
# These values are limitations of Maya itself.
72+
bound_range_min = 0.1
73+
bound_range_max = 10000.0
74+
75+
focal_length_min = focal_length_mm
76+
focal_length_max = focal_length_mm
77+
if factor <= 1.0:
78+
# Between 0 and 100.
79+
factor1 = max(0.0, min(percentage_value / 100.0, 1.0))
80+
focal_length_min = math_utils.lerp(focal_length_mm, std1_range_min, factor1)
81+
focal_length_max = math_utils.lerp(focal_length_mm, std1_range_max, factor1)
82+
elif factor > 1.0 and factor <= 2.0:
83+
# Between 100 and 200.
84+
factor2 = max(0.0, min((percentage_value / 100.0) - 1.0, 1.0))
85+
focal_length_min = math_utils.lerp(std1_range_min, std2_range_min, factor2)
86+
focal_length_max = math_utils.lerp(std1_range_max, std2_range_max, factor2)
87+
else:
88+
# Between 200 and 300.
89+
factor3 = max(0.0, min((percentage_value / 100.0) - 2.0, 1.0))
90+
focal_length_min = math_utils.lerp(std2_range_min, bound_range_min, factor3)
91+
focal_length_max = math_utils.lerp(std2_range_max, bound_range_max, factor3)
92+
93+
focal_length_min = max(bound_range_min, focal_length_min)
94+
focal_length_max = min(bound_range_max, focal_length_max)
95+
return focal_length_min, focal_length_max
6196

6297

6398
def make_adjustment_solver(

0 commit comments

Comments
 (0)