mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
Added option for projection type to ThreeDCamera
This commit is contained in:
parent
8ea4f8fda8
commit
9960ae177c
1 changed files with 29 additions and 9 deletions
|
@ -18,6 +18,7 @@ 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
|
from utils.simple_functions import fdiv
|
||||||
|
from utils.simple_functions import clip_in_place
|
||||||
|
|
||||||
|
|
||||||
class ThreeDCamera(Camera):
|
class ThreeDCamera(Camera):
|
||||||
|
@ -32,6 +33,7 @@ class ThreeDCamera(Camera):
|
||||||
"light_source_start_point": 9 * DOWN + 7 * LEFT + 10 * OUT,
|
"light_source_start_point": 9 * DOWN + 7 * LEFT + 10 * OUT,
|
||||||
"frame_center": ORIGIN,
|
"frame_center": ORIGIN,
|
||||||
"should_apply_shading": True,
|
"should_apply_shading": True,
|
||||||
|
"exponential_projection": False,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
@ -168,13 +170,17 @@ class ThreeDCamera(Camera):
|
||||||
points = np.dot(points, rot_matrix.T)
|
points = np.dot(points, rot_matrix.T)
|
||||||
zs = points[:, 2]
|
zs = points[:, 2]
|
||||||
for i in 0, 1:
|
for i in 0, 1:
|
||||||
# Proper projedtion would involve multiplying
|
if self.exponential_projection:
|
||||||
# x and y by d / (d-z). But for points with high
|
# Proper projedtion would involve multiplying
|
||||||
# z value, this causes weird artifacts, and applying
|
# x and y by d / (d-z). But for points with high
|
||||||
# the exponential helps smooth it out.
|
# z value that causes weird artifacts, and applying
|
||||||
factor = np.exp(zs / distance)
|
# the exponential helps smooth it out.
|
||||||
lt0 = zs < 0
|
factor = np.exp(zs / distance)
|
||||||
factor[lt0] = (distance / (distance - zs[lt0]))
|
lt0 = zs < 0
|
||||||
|
factor[lt0] = (distance / (distance - zs[lt0]))
|
||||||
|
else:
|
||||||
|
factor = (distance / (distance - zs))
|
||||||
|
clip_in_place(factor, 0, 10**6)
|
||||||
points[:, i] *= factor
|
points[:, i] *= factor
|
||||||
points += frame_center
|
points += frame_center
|
||||||
return points
|
return points
|
||||||
|
@ -197,9 +203,23 @@ class ThreeDCamera(Camera):
|
||||||
else:
|
else:
|
||||||
return self.project_points(points)
|
return self.project_points(points)
|
||||||
|
|
||||||
def add_fixed_orientation_mobjects(self, *mobjects, center_func=None):
|
def add_fixed_orientation_mobjects(
|
||||||
|
self, *mobjects,
|
||||||
|
use_static_center_func=False,
|
||||||
|
center_func=None):
|
||||||
|
# This prevents the computation of mobject.get_center
|
||||||
|
# every single time a projetion happens
|
||||||
|
def get_static_center_func(mobject):
|
||||||
|
point = mobject.get_center()
|
||||||
|
return (lambda: point)
|
||||||
|
|
||||||
for mobject in mobjects:
|
for mobject in mobjects:
|
||||||
func = center_func or mobject.get_center
|
if center_func:
|
||||||
|
func = center_func
|
||||||
|
elif use_static_center_func:
|
||||||
|
func = get_static_center_func(mobject)
|
||||||
|
else:
|
||||||
|
func = mobject.get_center
|
||||||
for submob in mobject.get_family():
|
for submob in mobject.get_family():
|
||||||
self.fixed_orientation_mobjects[submob] = func
|
self.fixed_orientation_mobjects[submob] = func
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue