mirror of
https://github.com/3b1b/manim.git
synced 2025-07-30 21:44:19 +08:00
Simplify get_unit_normal to always recompute
This commit is contained in:
@ -100,7 +100,6 @@ class VMobject(Mobject):
|
|||||||
self.flat_stroke = flat_stroke
|
self.flat_stroke = flat_stroke
|
||||||
|
|
||||||
self.needs_new_triangulation = True
|
self.needs_new_triangulation = True
|
||||||
self.needs_new_unit_normal = True
|
|
||||||
self.triangulation = np.zeros(0, dtype='i4')
|
self.triangulation = np.zeros(0, dtype='i4')
|
||||||
|
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
@ -776,10 +775,7 @@ class VMobject(Mobject):
|
|||||||
sum((p0[:, 0] + p1[:, 0]) * (p1[:, 1] - p0[:, 1])), # Add up (x1 + x2)*(y2 - y1)
|
sum((p0[:, 0] + p1[:, 0]) * (p1[:, 1] - p0[:, 1])), # Add up (x1 + x2)*(y2 - y1)
|
||||||
])
|
])
|
||||||
|
|
||||||
def get_unit_normal(self, recompute: bool = False) -> Vect3:
|
def get_unit_normal(self) -> Vect3:
|
||||||
if not self.needs_new_unit_normal and not recompute:
|
|
||||||
return self.data["unit_normal"][0]
|
|
||||||
|
|
||||||
if self.get_num_points() < 3:
|
if self.get_num_points() < 3:
|
||||||
return OUT
|
return OUT
|
||||||
|
|
||||||
@ -794,12 +790,11 @@ class VMobject(Mobject):
|
|||||||
points[2] - points[1],
|
points[2] - points[1],
|
||||||
)
|
)
|
||||||
self.data["unit_normal"][:] = normal
|
self.data["unit_normal"][:] = normal
|
||||||
self.needs_new_unit_normal = False
|
|
||||||
return normal
|
return normal
|
||||||
|
|
||||||
def refresh_unit_normal(self):
|
def refresh_unit_normal(self):
|
||||||
for mob in self.get_family():
|
for mob in self.get_family():
|
||||||
mob.needs_new_unit_normal = True
|
mob.get_unit_normal()
|
||||||
return self
|
return self
|
||||||
|
|
||||||
# Alignment
|
# Alignment
|
||||||
@ -963,7 +958,7 @@ class VMobject(Mobject):
|
|||||||
# how to send the points as to the vertex shader.
|
# how to send the points as to the vertex shader.
|
||||||
# First triangles come directly from the points
|
# First triangles come directly from the points
|
||||||
if normal_vector is None:
|
if normal_vector is None:
|
||||||
normal_vector = self.get_unit_normal(recompute=True)
|
normal_vector = self.get_unit_normal()
|
||||||
|
|
||||||
if not self.needs_new_triangulation:
|
if not self.needs_new_triangulation:
|
||||||
return self.triangulation
|
return self.triangulation
|
||||||
@ -977,6 +972,7 @@ class VMobject(Mobject):
|
|||||||
|
|
||||||
if not np.isclose(normal_vector, OUT).all():
|
if not np.isclose(normal_vector, OUT).all():
|
||||||
# Rotate points such that unit normal vector is OUT
|
# Rotate points such that unit normal vector is OUT
|
||||||
|
# Note, transpose of z_to_vector is its inverse
|
||||||
points = np.dot(points, z_to_vector(normal_vector))
|
points = np.dot(points, z_to_vector(normal_vector))
|
||||||
indices = np.arange(len(points), dtype=int)
|
indices = np.arange(len(points), dtype=int)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user