diff --git a/camera/camera.py b/camera/camera.py index 344ab98c..5c74bdf8 100644 --- a/camera/camera.py +++ b/camera/camera.py @@ -547,7 +547,7 @@ class Camera(object): points[violator_indices] = rescaled return points - def transform_points_pre_display(self, points, mobject): + def transform_points_pre_display(self, mobject, points): # Subclasses (like ThreeDCamera) may want to # adjust points before they're shown return points diff --git a/camera/three_d_camera.py b/camera/three_d_camera.py index bad356e7..fd551d80 100644 --- a/camera/three_d_camera.py +++ b/camera/three_d_camera.py @@ -17,6 +17,7 @@ from utils.color import get_shaded_rgb from utils.space_ops import rotation_about_z from utils.space_ops import rotation_matrix from utils.space_ops import center_of_mass +from utils.simple_functions import fdiv class ThreeDCamera(Camera): @@ -166,9 +167,15 @@ class ThreeDCamera(Camera): points -= frame_center points = np.dot(points, rot_matrix.T) zs = points[:, 2] - zs[zs >= distance] = distance - 0.001 for i in 0, 1: - points[:, i] *= distance / (distance - zs) + # Proper projedtion would involve multiplying + # x and y by d / (d-z). But for points with high + # z value, this causes weird artifacts, and applying + # the exponential helps smooth it out. + factor = np.exp(zs / distance) + lt0 = zs < 0 + factor[lt0] = (distance / (distance - zs[lt0])) + points[:, i] *= factor points += frame_center return points diff --git a/mobject/three_d_utils.py b/mobject/three_d_utils.py index 1c4e7914..b0649f6b 100644 --- a/mobject/three_d_utils.py +++ b/mobject/three_d_utils.py @@ -35,7 +35,7 @@ def get_3d_vmob_end_corner(vmob): def get_3d_vmob_unit_normal(vmob, point_index): n_points = vmob.get_num_points() - if vmob.get_num_points() == 0: + if len(vmob.get_anchors()) <= 2: return np.array(UP) i = point_index im1 = i - 1 if i > 0 else (n_points - 2) diff --git a/mobject/three_dimensions.py b/mobject/three_dimensions.py index 91954352..e9f31bc5 100644 --- a/mobject/three_dimensions.py +++ b/mobject/three_dimensions.py @@ -96,7 +96,7 @@ class ParametricSurface(VGroup): class Sphere(ParametricSurface): CONFIG = { "resolution": (12, 24), - "radius": 3, + "radius": 1, "u_min": 0.001, "u_max": PI - 0.001, "v_min": 0, @@ -128,8 +128,9 @@ class Cube(VGroup): def generate_points(self): for vect in IN, OUT, LEFT, RIGHT, UP, DOWN: - face = ThreeDVMobject( - Square(side_length=self.side_length) + face = Square( + side_length=self.side_length, + shade_in_3d=True, ) face.make_jagged() face.flip() diff --git a/utils/config_ops.py b/utils/config_ops.py index ec6aa70f..0648fe7c 100644 --- a/utils/config_ops.py +++ b/utils/config_ops.py @@ -53,7 +53,6 @@ def digest_config(obj, kwargs, caller_locals={}): caller_locals = filtered_locals(caller_locals) all_dicts = [kwargs, caller_locals, obj.__dict__] all_dicts += static_configs - all_new_dicts = [kwargs, caller_locals] + static_configs obj.__dict__ = merge_config(all_dicts) @@ -62,7 +61,7 @@ def merge_config(all_dicts): config = dict() for c in all_config: key, value = c - if not key in config: + if key not in config: config[key] = value else: # When two dictionaries have the same key, they are merged.