mirror of
https://github.com/3b1b/manim.git
synced 2025-11-15 20:07:45 +00:00
Revert emit_pentagon to work on 3d vectors
This commit is contained in:
parent
6ec3d9f4a5
commit
116d6fe244
1 changed files with 16 additions and 19 deletions
|
|
@ -67,28 +67,25 @@ void emit_simple_triangle(){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void emit_pentagon(vec3[3] points){
|
void emit_pentagon(vec3[3] points, vec3 normal){
|
||||||
vec2 p0 = points[0].xy;
|
vec3 p0 = points[0];
|
||||||
vec2 p1 = points[1].xy;
|
vec3 p1 = points[1];
|
||||||
vec2 p2 = points[2].xy;
|
vec3 p2 = points[2];
|
||||||
|
|
||||||
// Tangent vectors
|
// Tangent vectors
|
||||||
vec2 t01 = normalize(p1 - p0);
|
vec3 t01 = normalize(p1 - p0);
|
||||||
vec2 t12 = normalize(p2 - p1);
|
vec3 t12 = normalize(p2 - p1);
|
||||||
|
|
||||||
// Vectors perpendicular to the curve in the plane
|
// Vectors perpendicular to the curve in the plane of the curve pointing outside the curve
|
||||||
// of the curve pointing outside the curve
|
vec3 p0_perp = cross(t01, normal);
|
||||||
float cross_prod = cross2d(t01, t12);
|
vec3 p2_perp = cross(t12, normal);
|
||||||
float sgn = cross_prod >= 0.0 ? 1.0 : -1.0;
|
|
||||||
vec2 p0_perp = sgn * vec2(t01.y, -t01.x);
|
|
||||||
vec2 p2_perp = sgn * vec2(t12.y, -t12.x);
|
|
||||||
|
|
||||||
float angle = asin(clamp(cross_prod, -1, 1));
|
float angle = acos(clamp(dot(t01, t12), -1, 1));
|
||||||
is_linear = float(abs(angle) < ANGLE_THRESHOLD);
|
is_linear = float(angle < ANGLE_THRESHOLD);
|
||||||
|
|
||||||
bool fill_inside = orientation > 0.0;
|
bool fill_inside = orientation > 0.0;
|
||||||
float aaw = anti_alias_width * frame_shape.y / pixel_shape.y;
|
float aaw = anti_alias_width * frame_shape.y / pixel_shape.y;
|
||||||
vec2 corners[5] = vec2[5](p0, p0, p1, p2, p2);
|
vec3 corners[5] = vec3[5](p0, p0, p1, p2, p2);
|
||||||
|
|
||||||
if(fill_inside || bool(is_linear)){
|
if(fill_inside || bool(is_linear)){
|
||||||
// Add buffer outside the curve
|
// Add buffer outside the curve
|
||||||
|
|
@ -103,13 +100,13 @@ void emit_pentagon(vec3[3] points){
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute xy_to_uv matrix, and potentially re-evaluate bezier degree
|
// Compute xy_to_uv matrix, and potentially re-evaluate bezier degree
|
||||||
mat3 xy_to_uv = get_xy_to_uv(vec2[3](p0, p1, p2), is_linear, is_linear);
|
mat3 xy_to_uv = get_xy_to_uv(vec2[3](p0.xy, p1.xy, p2.xy), is_linear, is_linear);
|
||||||
uv_anti_alias_width = aaw * length(xy_to_uv[0].xy);
|
uv_anti_alias_width = aaw * length(xy_to_uv[0].xy);
|
||||||
|
|
||||||
for(int i = 0; i < 5; i++){
|
for(int i = 0; i < 5; i++){
|
||||||
int j = int(sign(i - 1) + 1); // Maps i = [0, 1, 2, 3, 4] onto j = [0, 0, 1, 2, 2]
|
int j = int(sign(i - 1) + 1); // Maps i = [0, 1, 2, 3, 4] onto j = [0, 0, 1, 2, 2]
|
||||||
vec3 corner = vec3(corners[i], points[j].z);
|
vec3 corner = corners[i];
|
||||||
uv_coords = (xy_to_uv * vec3(corners[i], 1.0)).xy;
|
uv_coords = (xy_to_uv * vec3(corner.xy, 1.0)).xy;
|
||||||
emit_vertex_wrapper(corner, j);
|
emit_vertex_wrapper(corner, j);
|
||||||
}
|
}
|
||||||
EndPrimitive();
|
EndPrimitive();
|
||||||
|
|
@ -132,6 +129,6 @@ void main(){
|
||||||
unit_normal = get_unit_normal(verts);
|
unit_normal = get_unit_normal(verts);
|
||||||
orientation = v_orientation[0];
|
orientation = v_orientation[0];
|
||||||
|
|
||||||
emit_pentagon(verts);
|
emit_pentagon(verts, unit_normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue