mirror of
https://github.com/3b1b/manim.git
synced 2025-11-13 19:57:48 +00:00
Stop tracking unit_normal in data
Track orientation of each curve instead
This commit is contained in:
parent
3878b8c077
commit
40bf1fd6a9
5 changed files with 22 additions and 30 deletions
|
|
@ -53,7 +53,7 @@ class VMobject(Mobject):
|
|||
fill_shader_folder: str = "quadratic_bezier_fill"
|
||||
fill_dtype: Sequence[Tuple[str, type, Tuple[int]]] = [
|
||||
('point', np.float32, (3,)),
|
||||
('unit_normal', np.float32, (3,)),
|
||||
('orientation', np.float32, (1,)),
|
||||
('color', np.float32, (4,)),
|
||||
('vert_index', np.float32, (1,)),
|
||||
]
|
||||
|
|
@ -61,7 +61,6 @@ class VMobject(Mobject):
|
|||
("point", np.float32, (3,)),
|
||||
("prev_point", np.float32, (3,)),
|
||||
("next_point", np.float32, (3,)),
|
||||
('unit_normal', np.float32, (3,)),
|
||||
("stroke_width", np.float32, (1,)),
|
||||
("color", np.float32, (4,)),
|
||||
]
|
||||
|
|
@ -100,7 +99,6 @@ class VMobject(Mobject):
|
|||
self.flat_stroke = flat_stroke
|
||||
|
||||
self.needs_new_triangulation = True
|
||||
self.needs_new_unit_normal = True
|
||||
self.triangulation = np.zeros(0, dtype='i4')
|
||||
|
||||
super().__init__(**kwargs)
|
||||
|
|
@ -115,7 +113,7 @@ class VMobject(Mobject):
|
|||
"fill_rgba": np.zeros((1, 4)),
|
||||
"stroke_rgba": np.zeros((1, 4)),
|
||||
"stroke_width": np.zeros((1, 1)),
|
||||
"unit_normal": np.array(OUT, ndmin=2),
|
||||
"orientation": np.zeros((1, 1)),
|
||||
})
|
||||
|
||||
# These are here just to make type checkers happy
|
||||
|
|
@ -776,10 +774,7 @@ class VMobject(Mobject):
|
|||
sum((p0[:, 0] + p1[:, 0]) * (p1[:, 1] - p0[:, 1])), # Add up (x1 + x2)*(y2 - y1)
|
||||
])
|
||||
|
||||
def get_unit_normal(self, recompute: bool = False) -> Vect3:
|
||||
if not self.needs_new_unit_normal and not recompute:
|
||||
return self.data["unit_normal"][0]
|
||||
|
||||
def get_unit_normal(self) -> Vect3:
|
||||
if self.get_num_points() < 3:
|
||||
return OUT
|
||||
|
||||
|
|
@ -793,13 +788,9 @@ class VMobject(Mobject):
|
|||
points[1] - points[0],
|
||||
points[2] - points[1],
|
||||
)
|
||||
self.data["unit_normal"][:] = normal
|
||||
self.needs_new_unit_normal = False
|
||||
return normal
|
||||
|
||||
def refresh_unit_normal(self):
|
||||
for mob in self.get_family():
|
||||
mob.needs_new_unit_normal = True
|
||||
def refresh_unit_normal(self): # TODO, Delete
|
||||
return self
|
||||
|
||||
# Alignment
|
||||
|
|
@ -958,13 +949,10 @@ class VMobject(Mobject):
|
|||
mob.needs_new_triangulation = True
|
||||
return self
|
||||
|
||||
def get_triangulation(self, normal_vector: Vect3 | None = None):
|
||||
def get_triangulation(self):
|
||||
# Figure out how to triangulate the interior to know
|
||||
# how to send the points as to the vertex shader.
|
||||
# First triangles come directly from the points
|
||||
if normal_vector is None:
|
||||
normal_vector = self.get_unit_normal(recompute=True)
|
||||
|
||||
if not self.needs_new_triangulation:
|
||||
return self.triangulation
|
||||
|
||||
|
|
@ -975,6 +963,7 @@ class VMobject(Mobject):
|
|||
self.needs_new_triangulation = False
|
||||
return self.triangulation
|
||||
|
||||
normal_vector = self.get_unit_normal()
|
||||
if not np.isclose(normal_vector, OUT).all():
|
||||
# Rotate points such that unit normal vector is OUT
|
||||
points = np.dot(points, z_to_vector(normal_vector))
|
||||
|
|
@ -988,6 +977,8 @@ class VMobject(Mobject):
|
|||
|
||||
crosses = cross2d(v01s, v12s)
|
||||
convexities = np.sign(crosses)
|
||||
orientations = np.sign(convexities.repeat(3))
|
||||
self.data["orientation"] = orientations.reshape((len(orientations), 1))
|
||||
|
||||
atol = self.tolerance_for_point_equality
|
||||
end_of_loop = np.zeros(len(b0s), dtype=bool)
|
||||
|
|
@ -1155,7 +1146,6 @@ class VMobject(Mobject):
|
|||
|
||||
self.read_data_to_shader(self.stroke_data, "color", "stroke_rgba")
|
||||
self.read_data_to_shader(self.stroke_data, "stroke_width", "stroke_width")
|
||||
self.read_data_to_shader(self.stroke_data, "unit_normal", "unit_normal")
|
||||
|
||||
return self.stroke_data
|
||||
|
||||
|
|
@ -1167,7 +1157,7 @@ class VMobject(Mobject):
|
|||
|
||||
self.read_data_to_shader(self.fill_data, "point", "points")
|
||||
self.read_data_to_shader(self.fill_data, "color", "fill_rgba")
|
||||
self.read_data_to_shader(self.fill_data, "unit_normal", "unit_normal")
|
||||
self.read_data_to_shader(self.fill_data, "orientation", "orientation")
|
||||
|
||||
return self.fill_data
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ uniform float gloss;
|
|||
uniform float shadow;
|
||||
|
||||
in vec3 bp[3];
|
||||
in vec3 v_global_unit_normal[3];
|
||||
in float v_orientation[3];
|
||||
in vec4 v_color[3];
|
||||
in float v_vert_index[3];
|
||||
|
||||
|
|
@ -32,6 +32,8 @@ out vec2 uv_coords;
|
|||
out vec2 uv_b2;
|
||||
out float bezier_degree;
|
||||
|
||||
vec3 local_unit_normal;
|
||||
|
||||
|
||||
// Analog of import for manim only
|
||||
#INSERT quadratic_bezier_geometry_functions.glsl
|
||||
|
|
@ -44,7 +46,7 @@ void emit_vertex_wrapper(vec3 point, int index){
|
|||
color = finalize_color(
|
||||
v_color[index],
|
||||
point,
|
||||
v_global_unit_normal[index],
|
||||
local_unit_normal,
|
||||
light_source_position,
|
||||
camera_position,
|
||||
reflectiveness,
|
||||
|
|
@ -128,7 +130,7 @@ void main(){
|
|||
vec3 new_bp[3];
|
||||
bezier_degree = get_reduced_control_points(vec3[3](bp[0], bp[1], bp[2]), new_bp);
|
||||
vec3 local_unit_normal = get_unit_normal(new_bp);
|
||||
orientation = sign(dot(v_global_unit_normal[0], local_unit_normal));
|
||||
orientation = v_orientation[0];
|
||||
|
||||
if(bezier_degree >= 1){
|
||||
emit_pentagon(new_bp, local_unit_normal);
|
||||
|
|
|
|||
|
|
@ -3,12 +3,12 @@
|
|||
#INSERT camera_uniform_declarations.glsl
|
||||
|
||||
in vec3 point;
|
||||
in vec3 unit_normal;
|
||||
in float orientation;
|
||||
in vec4 color;
|
||||
in float vert_index;
|
||||
|
||||
out vec3 bp; // Bezier control point
|
||||
out vec3 v_global_unit_normal;
|
||||
out float v_orientation;
|
||||
out vec4 v_color;
|
||||
out float v_vert_index;
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ out float v_vert_index;
|
|||
|
||||
void main(){
|
||||
bp = position_point_into_frame(point);
|
||||
v_global_unit_normal = rotate_point_into_frame(unit_normal);
|
||||
v_orientation = orientation;
|
||||
v_color = color;
|
||||
v_vert_index = vert_index;
|
||||
}
|
||||
|
|
@ -22,7 +22,6 @@ uniform float shadow;
|
|||
in vec3 bp[3];
|
||||
in vec3 prev_bp[3];
|
||||
in vec3 next_bp[3];
|
||||
in vec3 v_global_unit_normal[3];
|
||||
|
||||
in vec4 v_color[3];
|
||||
in float v_stroke_width[3];
|
||||
|
|
@ -43,6 +42,8 @@ out float bezier_degree;
|
|||
out vec2 uv_coords;
|
||||
out vec2 uv_b2;
|
||||
|
||||
vec3 unit_normal;
|
||||
|
||||
// Codes for joint types
|
||||
const float AUTO_JOINT = 0;
|
||||
const float ROUND_JOINT = 1;
|
||||
|
|
@ -206,6 +207,7 @@ void main() {
|
|||
vec3 controls[3];
|
||||
vec3 prev[3];
|
||||
vec3 next[3];
|
||||
unit_normal = get_unit_normal(controls);
|
||||
bezier_degree = get_reduced_control_points(vec3[3](bp[0], bp[1], bp[2]), controls);
|
||||
if(bezier_degree == 0.0) return; // Null curve
|
||||
int degree = int(bezier_degree);
|
||||
|
|
@ -219,7 +221,7 @@ void main() {
|
|||
float sf = perspective_scale_factor(controls[i].z, focal_distance);
|
||||
if(bool(flat_stroke)){
|
||||
vec3 to_cam = normalize(vec3(0.0, 0.0, focal_distance) - controls[i]);
|
||||
sf *= abs(dot(v_global_unit_normal[i], to_cam));
|
||||
sf *= abs(dot(unit_normal, to_cam));
|
||||
}
|
||||
scaled_strokes[i] = v_stroke_width[i] * sf;
|
||||
}
|
||||
|
|
@ -259,7 +261,7 @@ void main() {
|
|||
color = finalize_color(
|
||||
v_color[index_map[i]],
|
||||
xyz_coords,
|
||||
v_global_unit_normal[index_map[i]],
|
||||
unit_normal,
|
||||
light_source_position,
|
||||
camera_position,
|
||||
reflectiveness,
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ in vec4 color;
|
|||
out vec3 bp;
|
||||
out vec3 prev_bp;
|
||||
out vec3 next_bp;
|
||||
out vec3 v_global_unit_normal;
|
||||
|
||||
out float v_stroke_width;
|
||||
out vec4 v_color;
|
||||
|
|
@ -27,7 +26,6 @@ void main(){
|
|||
bp = position_point_into_frame(point);
|
||||
prev_bp = position_point_into_frame(prev_point);
|
||||
next_bp = position_point_into_frame(next_point);
|
||||
v_global_unit_normal = rotate_point_into_frame(unit_normal);
|
||||
|
||||
v_stroke_width = STROKE_WIDTH_CONVERSION * stroke_width * frame_shape[1] / 8.0;
|
||||
v_color = color;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue