Add 'no_joint' to joint types

This commit is contained in:
Grant Sanderson 2023-01-10 11:06:41 -08:00
parent ab1227a908
commit 6ec3d9f4a5
5 changed files with 14 additions and 11 deletions

View file

@ -65,8 +65,8 @@ RADIANS: float = 1
FFMPEG_BIN: str = "ffmpeg" FFMPEG_BIN: str = "ffmpeg"
JOINT_TYPE_MAP: dict = { JOINT_TYPE_MAP: dict = {
"auto": 0, "no_joint": 0,
"round": 1, "auto": 1,
"bevel": 2, "bevel": 2,
"miter": 3, "miter": 3,
} }

View file

@ -93,9 +93,10 @@ class ImplicitFunction(VMobject):
min_depth: int = 5, min_depth: int = 5,
max_quads: int = 1500, max_quads: int = 1500,
use_smoothing: bool = True, use_smoothing: bool = True,
joint_type: str = 'no_joint',
**kwargs **kwargs
): ):
super().__init__(**kwargs) super().__init__(joint_type=joint_type, **kwargs)
p_min, p_max = ( p_min, p_max = (
np.array([x_range[0], y_range[0]]), np.array([x_range[0], y_range[0]]),

View file

@ -38,6 +38,7 @@ class SurfaceMesh(VGroup):
normal_nudge: float = 1e-2, normal_nudge: float = 1e-2,
flat_stroke: bool = False, flat_stroke: bool = False,
depth_test: bool = True, depth_test: bool = True,
joint_type: str = 'no_joint',
**kwargs **kwargs
): ):
self.uv_surface = uv_surface self.uv_surface = uv_surface
@ -49,6 +50,7 @@ class SurfaceMesh(VGroup):
stroke_color=stroke_color, stroke_color=stroke_color,
stroke_width=stroke_width, stroke_width=stroke_width,
depth_test=depth_test, depth_test=depth_test,
joint_type=joint_type,
**kwargs **kwargs
) )
@ -291,7 +293,7 @@ class VGroup3D(VGroup):
gloss: float = 0.2, gloss: float = 0.2,
shadow: float = 0.2, shadow: float = 0.2,
reflectiveness: float = 0.2, reflectiveness: float = 0.2,
joint_type: str = "round", joint_type: str = "no_joint",
**kwargs **kwargs
): ):
super().__init__(*vmobjects, **kwargs) super().__init__(*vmobjects, **kwargs)

View file

@ -84,7 +84,7 @@ class VMobject(Mobject):
draw_stroke_behind_fill: bool = False, draw_stroke_behind_fill: bool = False,
background_image_file: str | None = None, background_image_file: str | None = None,
long_lines: bool = False, long_lines: bool = False,
# Could also be "bevel", "miter", "round" # Could also be "no_joint", "bevel", "miter"
joint_type: str = "auto", joint_type: str = "auto",
flat_stroke: bool = False, flat_stroke: bool = False,
# Measured in pixel widths # Measured in pixel widths

View file

@ -36,10 +36,10 @@ out float is_linear;
out vec2 uv_coords; out vec2 uv_coords;
// Codes for joint types // Codes for joint types
const float AUTO_JOINT = 0; const int NO_JOINT = 0;
const float ROUND_JOINT = 1; const int AUTO_JOINT = 1;
const float BEVEL_JOINT = 2; const int BEVEL_JOINT = 2;
const float MITER_JOINT = 3; const int MITER_JOINT = 3;
const float PI = 3.141592653; const float PI = 3.141592653;
const float DISJOINT_CONST = 404.0; const float DISJOINT_CONST = 404.0;
@ -56,10 +56,10 @@ void create_joint(float angle, vec2 unit_tan, float buff,
vec2 static_c0, out vec2 changing_c0, vec2 static_c0, out vec2 changing_c0,
vec2 static_c1, out vec2 changing_c1){ vec2 static_c1, out vec2 changing_c1){
float shift; float shift;
if(abs(angle) < ANGLE_THRESHOLD){ if(abs(angle) < ANGLE_THRESHOLD || int(joint_type) == NO_JOINT){
// No joint // No joint
shift = 0; shift = 0;
}else if(joint_type == MITER_JOINT || (joint_type == AUTO_JOINT && angle > 0.9 * PI)){ }else if(int(joint_type) == MITER_JOINT || (int(joint_type) == AUTO_JOINT && angle > 0.9 * PI)){
shift = buff * (-1.0 - cos(angle)) / sin(angle); shift = buff * (-1.0 - cos(angle)) / sin(angle);
}else{ }else{
// For a Bevel joint // For a Bevel joint