Skip to content

Commit 4f6852c

Browse files
Renamed distance parameter of :class:.ThreeDScene and :class:.ThreeDCamera to focal_distance (ManimCommunity#2123)
* deprecate distance * updated deprecation Co-authored-by: Benjamin Hackl <[email protected]>
1 parent c7199fa commit 4f6852c

File tree

2 files changed

+61
-28
lines changed

2 files changed

+61
-28
lines changed

manim/camera/three_d_camera.py

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
from ..mobject.types.point_cloud_mobject import Point
1818
from ..mobject.value_tracker import ValueTracker
1919
from ..utils.color import get_shaded_rgb
20+
from ..utils.deprecation import deprecated
2021
from ..utils.family import extract_mobject_family_members
2122
from ..utils.space_ops import rotation_about_z, rotation_matrix
2223

2324

2425
class ThreeDCamera(Camera):
2526
def __init__(
2627
self,
27-
distance=20.0,
28+
focal_distance=20.0,
2829
shading_factor=0.2,
2930
default_distance=5.0,
3031
light_source_start_point=9 * DOWN + 7 * LEFT + 10 * OUT,
@@ -47,7 +48,7 @@ def __init__(
4748
"""
4849
self._frame_center = Point(kwargs.get("frame_center", ORIGIN), stroke_width=0)
4950
super().__init__(**kwargs)
50-
self.distance = distance
51+
self.focal_distance = focal_distance
5152
self.phi = phi
5253
self.theta = theta
5354
self.gamma = gamma
@@ -61,7 +62,7 @@ def __init__(
6162
self.max_allowable_norm = 3 * config["frame_width"]
6263
self.phi_tracker = ValueTracker(self.phi)
6364
self.theta_tracker = ValueTracker(self.theta)
64-
self.distance_tracker = ValueTracker(self.distance)
65+
self.focal_distance_tracker = ValueTracker(self.focal_distance)
6566
self.gamma_tracker = ValueTracker(self.gamma)
6667
self.zoom_tracker = ValueTracker(self.zoom)
6768
self.fixed_orientation_mobjects = {}
@@ -81,7 +82,7 @@ def capture_mobjects(self, mobjects, **kwargs):
8182
super().capture_mobjects(mobjects, **kwargs)
8283

8384
def get_value_trackers(self):
84-
"""Returns list of ValueTrackers of phi, theta, distance and gamma
85+
"""Returns list of ValueTrackers of phi, theta, focal_distance and gamma
8586
8687
Returns
8788
-------
@@ -91,7 +92,7 @@ def get_value_trackers(self):
9192
return [
9293
self.phi_tracker,
9394
self.theta_tracker,
94-
self.distance_tracker,
95+
self.focal_distance_tracker,
9596
self.gamma_tracker,
9697
self.zoom_tracker,
9798
]
@@ -163,15 +164,23 @@ def get_theta(self):
163164
"""
164165
return self.theta_tracker.get_value()
165166

167+
@deprecated(
168+
since="v0.11.0",
169+
until="v0.12.0",
170+
message="use focal_distance instead.",
171+
)
166172
def get_distance(self):
167-
"""Returns radial distance from ORIGIN.
173+
return self.get_focal_distance()
174+
175+
def get_focal_distance(self):
176+
"""Returns focal_distance of the Camera.
168177
169178
Returns
170179
-------
171180
float
172-
The radial distance from ORIGIN in MUnits.
181+
The focal_distance of the Camera in MUnits.
173182
"""
174-
return self.distance_tracker.get_value()
183+
return self.focal_distance_tracker.get_value()
175184

176185
def get_gamma(self):
177186
"""Returns the rotation of the camera about the vector from the ORIGIN to the Camera.
@@ -214,15 +223,23 @@ def set_theta(self, value):
214223
"""
215224
self.theta_tracker.set_value(value)
216225

226+
@deprecated(
227+
since="v0.11.0",
228+
until="v0.12.0",
229+
message="use focal_distance instead.",
230+
)
217231
def set_distance(self, value):
218-
"""Sets the radial distance between the camera and ORIGIN.
232+
return self.set_focal_distance(value)
233+
234+
def set_focal_distance(self, value):
235+
"""Sets the focal_distance of the Camera.
219236
220237
Parameters
221238
----------
222239
value : int, float
223-
The new radial distance.
240+
The focal_distance of the Camera.
224241
"""
225-
self.distance_tracker.set_value(value)
242+
self.focal_distance_tracker.set_value(value)
226243

227244
def set_gamma(self, value):
228245
"""Sets the angle of rotation of the camera about the vector from the ORIGIN to the Camera.
@@ -296,7 +313,7 @@ def project_points(self, points):
296313
The points after projecting.
297314
"""
298315
frame_center = self.frame_center
299-
distance = self.get_distance()
316+
focal_distance = self.get_focal_distance()
300317
zoom = self.get_zoom()
301318
rot_matrix = self.get_rotation_matrix()
302319

@@ -309,12 +326,12 @@ def project_points(self, points):
309326
# x and y by d / (d-z). But for points with high
310327
# z value that causes weird artifacts, and applying
311328
# the exponential helps smooth it out.
312-
factor = np.exp(zs / distance)
329+
factor = np.exp(zs / focal_distance)
313330
lt0 = zs < 0
314-
factor[lt0] = distance / (distance - zs[lt0])
331+
factor[lt0] = focal_distance / (focal_distance - zs[lt0])
315332
else:
316-
factor = distance / (distance - zs)
317-
factor[(distance - zs) < 0] = 10 ** 6
333+
factor = focal_distance / (focal_distance - zs)
334+
factor[(focal_distance - zs) < 0] = 10 ** 6
318335
points[:, i] *= factor * zoom
319336
return points
320337

manim/scene/three_d_scene.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from ..renderer.opengl_renderer import OpenGLCamera
2424
from ..scene.scene import Scene
2525
from ..utils.config_ops import merge_dicts_recursively
26+
from ..utils.deprecation import deprecated_params
2627

2728

2829
class ThreeDScene(Scene):
@@ -49,14 +50,21 @@ def __init__(
4950
)
5051
super().__init__(camera_class=camera_class, **kwargs)
5152

53+
@deprecated_params(
54+
params="distance",
55+
since="v0.11.0",
56+
until="v0.12.0",
57+
message="Use focal_distance instead.",
58+
)
5259
def set_camera_orientation(
5360
self,
5461
phi: Optional[float] = None,
5562
theta: Optional[float] = None,
5663
gamma: Optional[float] = None,
5764
zoom: Optional[float] = None,
58-
distance: Optional[float] = None,
65+
focal_distance: Optional[float] = None,
5966
frame_center: Optional[Union["Mobject", Sequence[float]]] = None,
67+
**kwargs,
6068
):
6169
"""
6270
This method sets the orientation of the camera in the scene.
@@ -69,8 +77,8 @@ def set_camera_orientation(
6977
theta : int or float, optional
7078
The azimuthal angle i.e the angle that spins the camera around the Z_AXIS.
7179
72-
distance : int or float, optional
73-
The radial distance between ORIGIN and Camera.
80+
focal_distance : int or float, optional
81+
The focal_distance of the Camera.
7482
7583
gamma : int or float, optional
7684
The rotation of the camera about the vector from the ORIGIN to the Camera.
@@ -82,12 +90,13 @@ def set_camera_orientation(
8290
The new center of the camera frame in cartesian coordinates.
8391
8492
"""
93+
focal_distance = kwargs.pop("distance", focal_distance)
8594
if phi is not None:
8695
self.renderer.camera.set_phi(phi)
8796
if theta is not None:
8897
self.renderer.camera.set_theta(theta)
89-
if distance is not None:
90-
self.renderer.camera.set_distance(distance)
98+
if focal_distance is not None:
99+
self.renderer.camera.set_focal_distance(focal_distance)
91100
if gamma is not None:
92101
self.renderer.camera.set_gamma(gamma)
93102
if zoom is not None:
@@ -188,13 +197,19 @@ def stop_3dillusion_camera_rotation(self):
188197
self.renderer.camera.phi_tracker.clear_updaters()
189198
self.remove(self.renderer.camera.phi_tracker)
190199

200+
@deprecated_params(
201+
params="distance",
202+
since="v0.11.0",
203+
until="v0.12.0",
204+
message="Use focal_distance instead.",
205+
)
191206
def move_camera(
192207
self,
193208
phi: Optional[float] = None,
194209
theta: Optional[float] = None,
195210
gamma: Optional[float] = None,
196211
zoom: Optional[float] = None,
197-
distance: Optional[float] = None,
212+
focal_distance: Optional[float] = None,
198213
frame_center: Optional[Union["Mobject", Sequence[float]]] = None,
199214
added_anims: Iterable["Animation"] = [],
200215
**kwargs,
@@ -211,8 +226,8 @@ def move_camera(
211226
theta : int or float, optional
212227
The azimuthal angle i.e the angle that spins the camera around the Z_AXIS.
213228
214-
distance : int or float, optional
215-
The radial distance between ORIGIN and Camera.
229+
focal_distance : int or float, optional
230+
The radial focal_distance between ORIGIN and Camera.
216231
217232
gamma : int or float, optional
218233
The rotation of the camera about the vector from the ORIGIN to the Camera.
@@ -228,13 +243,14 @@ def move_camera(
228243
229244
"""
230245
anims = []
246+
focal_distance = kwargs.pop("distance", focal_distance)
231247

232248
if config.renderer != "opengl":
233249
self.camera: ThreeDCamera
234250
value_tracker_pairs = [
235251
(phi, self.camera.phi_tracker),
236252
(theta, self.camera.theta_tracker),
237-
(distance, self.camera.distance_tracker),
253+
(focal_distance, self.camera.focal_distance_tracker),
238254
(gamma, self.camera.gamma_tracker),
239255
(zoom, self.camera.zoom_tracker),
240256
]
@@ -273,7 +289,7 @@ def move_camera(
273289
if value is not None:
274290
methods[method](value)
275291

276-
if distance is not None:
292+
if focal_distance is not None:
277293
warnings.warn(
278294
"focal distance of OpenGLCamera can not be adjusted.",
279295
stacklevel=2,
@@ -380,7 +396,7 @@ def set_to_default_angled_camera_orientation(self, **kwargs):
380396
Parameters
381397
----------
382398
**kwargs
383-
Some recognised kwargs are phi, theta, distance, gamma,
399+
Some recognised kwargs are phi, theta, focal_distance, gamma,
384400
which have the same meaning as the parameters in set_camera_orientation.
385401
"""
386402
config = dict(
@@ -491,7 +507,7 @@ def get_default_camera_position(self):
491507
Returns
492508
-------
493509
dict
494-
Dictionary of phi, theta, distance, and gamma.
510+
Dictionary of phi, theta, focal_distance, and gamma.
495511
"""
496512
return self.default_angled_camera_position
497513

0 commit comments

Comments
 (0)