mirror of
https://github.com/3b1b/manim.git
synced 2025-08-21 05:44:04 +00:00
commit
ce06e58505
5 changed files with 16 additions and 9 deletions
|
@ -547,7 +547,7 @@ class Camera(object):
|
||||||
points[violator_indices] = rescaled
|
points[violator_indices] = rescaled
|
||||||
return points
|
return points
|
||||||
|
|
||||||
def transform_points_pre_display(self, points, mobject):
|
def transform_points_pre_display(self, mobject, points):
|
||||||
# Subclasses (like ThreeDCamera) may want to
|
# Subclasses (like ThreeDCamera) may want to
|
||||||
# adjust points before they're shown
|
# adjust points before they're shown
|
||||||
return points
|
return points
|
||||||
|
|
|
@ -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_about_z
|
||||||
from utils.space_ops import rotation_matrix
|
from utils.space_ops import rotation_matrix
|
||||||
from utils.space_ops import center_of_mass
|
from utils.space_ops import center_of_mass
|
||||||
|
from utils.simple_functions import fdiv
|
||||||
|
|
||||||
|
|
||||||
class ThreeDCamera(Camera):
|
class ThreeDCamera(Camera):
|
||||||
|
@ -166,9 +167,15 @@ class ThreeDCamera(Camera):
|
||||||
points -= frame_center
|
points -= frame_center
|
||||||
points = np.dot(points, rot_matrix.T)
|
points = np.dot(points, rot_matrix.T)
|
||||||
zs = points[:, 2]
|
zs = points[:, 2]
|
||||||
zs[zs >= distance] = distance - 0.001
|
|
||||||
for i in 0, 1:
|
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
|
points += frame_center
|
||||||
return points
|
return points
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ def get_3d_vmob_end_corner(vmob):
|
||||||
|
|
||||||
def get_3d_vmob_unit_normal(vmob, point_index):
|
def get_3d_vmob_unit_normal(vmob, point_index):
|
||||||
n_points = vmob.get_num_points()
|
n_points = vmob.get_num_points()
|
||||||
if vmob.get_num_points() == 0:
|
if len(vmob.get_anchors()) <= 2:
|
||||||
return np.array(UP)
|
return np.array(UP)
|
||||||
i = point_index
|
i = point_index
|
||||||
im1 = i - 1 if i > 0 else (n_points - 2)
|
im1 = i - 1 if i > 0 else (n_points - 2)
|
||||||
|
|
|
@ -96,7 +96,7 @@ class ParametricSurface(VGroup):
|
||||||
class Sphere(ParametricSurface):
|
class Sphere(ParametricSurface):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
"resolution": (12, 24),
|
"resolution": (12, 24),
|
||||||
"radius": 3,
|
"radius": 1,
|
||||||
"u_min": 0.001,
|
"u_min": 0.001,
|
||||||
"u_max": PI - 0.001,
|
"u_max": PI - 0.001,
|
||||||
"v_min": 0,
|
"v_min": 0,
|
||||||
|
@ -128,8 +128,9 @@ class Cube(VGroup):
|
||||||
|
|
||||||
def generate_points(self):
|
def generate_points(self):
|
||||||
for vect in IN, OUT, LEFT, RIGHT, UP, DOWN:
|
for vect in IN, OUT, LEFT, RIGHT, UP, DOWN:
|
||||||
face = ThreeDVMobject(
|
face = Square(
|
||||||
Square(side_length=self.side_length)
|
side_length=self.side_length,
|
||||||
|
shade_in_3d=True,
|
||||||
)
|
)
|
||||||
face.make_jagged()
|
face.make_jagged()
|
||||||
face.flip()
|
face.flip()
|
||||||
|
|
|
@ -53,7 +53,6 @@ def digest_config(obj, kwargs, caller_locals={}):
|
||||||
caller_locals = filtered_locals(caller_locals)
|
caller_locals = filtered_locals(caller_locals)
|
||||||
all_dicts = [kwargs, caller_locals, obj.__dict__]
|
all_dicts = [kwargs, caller_locals, obj.__dict__]
|
||||||
all_dicts += static_configs
|
all_dicts += static_configs
|
||||||
all_new_dicts = [kwargs, caller_locals] + static_configs
|
|
||||||
obj.__dict__ = merge_config(all_dicts)
|
obj.__dict__ = merge_config(all_dicts)
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,7 +61,7 @@ def merge_config(all_dicts):
|
||||||
config = dict()
|
config = dict()
|
||||||
for c in all_config:
|
for c in all_config:
|
||||||
key, value = c
|
key, value = c
|
||||||
if not key in config:
|
if key not in config:
|
||||||
config[key] = value
|
config[key] = value
|
||||||
else:
|
else:
|
||||||
# When two dictionaries have the same key, they are merged.
|
# When two dictionaries have the same key, they are merged.
|
||||||
|
|
Loading…
Add table
Reference in a new issue