Don't pre-normalize joint_products

This commit is contained in:
Grant Sanderson 2023-01-24 21:10:26 -08:00
parent 98eccab977
commit 307487e087
2 changed files with 15 additions and 10 deletions

View file

@ -875,6 +875,7 @@ class VMobject(Mobject):
new_points = np.vstack(paths)
mob.resize_points(len(new_points), resize_func=resize_preserving_order)
mob.set_points(new_points)
mob.get_joint_products()
return self
def insert_n_curves(self, n: int, recurse: bool = True):
@ -1069,8 +1070,8 @@ class VMobject(Mobject):
# Find all the unit tangent vectors at each joint
a0, h, a1 = points[0:-1:2], points[1::2], points[2::2]
a0_to_h = normalize_along_axis(h - a0, 1)
h_to_a1 = normalize_along_axis(a1 - h, 1)
a0_to_h = h - a0
h_to_a1 = a1 - h
vect_to_vert = np.zeros(points.shape)
vect_from_vert = np.zeros(points.shape)

View file

@ -99,13 +99,17 @@ void get_corners(
float buff0 = 0.5 * v_stroke_width[0] + aaw;
float buff2 = 0.5 * v_stroke_width[2] + aaw;
vec4 jp0 = normalize(v_joint_product[0]);
vec4 jp1 = normalize(v_joint_product[1]);
vec4 jp2 = normalize(v_joint_product[2]);
// Add correction for sharp angles to prevent weird bevel effects
if(v_joint_product[0].w < -0.9) buff0 *= 10 * (v_joint_product[0].w + 1.0);
if(v_joint_product[2].w < -0.9) buff2 *= 10 * (v_joint_product[2].w + 1.0);
if(jp0.w < -0.9) buff0 *= 10 * (jp0.w + 1.0);
if(jp2.w < -0.9) buff2 *= 10 * (jp2.w + 1.0);
// Unit normal and joint angles
vec3 normal0 = get_joint_unit_normal(v_joint_product[0]);
vec3 normal2 = get_joint_unit_normal(v_joint_product[2]);
vec3 normal0 = get_joint_unit_normal(jp0);
vec3 normal2 = get_joint_unit_normal(jp2);
// Set global unit normal
unit_normal = normal0;
@ -136,14 +140,14 @@ void get_corners(
vec3 c5 = p2 - p2_perp;
// Move the inner middle control point to make
// room for the curve
float orientation = dot(normal0, v_joint_product[1].xyz);
float orientation = dot(normal0, jp1.xyz);
if(orientation >= 0.0) c2 = 0.5 * (c0 + c4);
else if(orientation < 0.0) c3 = 0.5 * (c1 + c5);
// Account for previous and next control points
if(bool(flat_stroke)){
create_joint(v_joint_product[0], v01, buff0, c1, c1, c0, c0);
create_joint(v_joint_product[2], -v12, buff2, c5, c5, c4, c4);
create_joint(jp0, v01, buff0, c1, c1, c0, c0);
create_joint(jp2, -v12, buff2, c5, c5, c4, c4);
}
corners = vec3[6](c0, c1, c2, c3, c4, c5);
@ -164,7 +168,7 @@ void main() {
vec3 v01 = normalize(p1 - p0);
vec3 v12 = normalize(p2 - p1);
float cos_angle = v_joint_product[1].w;
float cos_angle = normalize(v_joint_product[1]).w;
is_linear = float(cos_angle > COS_THRESHOLD);
// We want to change the coordinates to a space where the curve