mirror of
https://github.com/3b1b/manim.git
synced 2025-11-13 17:50:23 +00:00
Push clip plane functionality up to all Mobjects
This commit is contained in:
parent
8eac976c8d
commit
95fca885c9
4 changed files with 21 additions and 25 deletions
|
|
@ -142,6 +142,7 @@ class Mobject(object):
|
||||||
self.uniforms: UniformDict = {
|
self.uniforms: UniformDict = {
|
||||||
"is_fixed_in_frame": 0.0,
|
"is_fixed_in_frame": 0.0,
|
||||||
"shading": np.array(self.shading, dtype=float),
|
"shading": np.array(self.shading, dtype=float),
|
||||||
|
"clip_plane": np.zeros(4),
|
||||||
}
|
}
|
||||||
|
|
||||||
def init_colors(self):
|
def init_colors(self):
|
||||||
|
|
@ -1946,6 +1947,21 @@ class Mobject(object):
|
||||||
mob.depth_test = False
|
mob.depth_test = False
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def set_clip_plane(
|
||||||
|
self,
|
||||||
|
vect: Vect3 | None = None,
|
||||||
|
threshold: float | None = None
|
||||||
|
) -> Self:
|
||||||
|
if vect is not None:
|
||||||
|
self.uniforms["clip_plane"][:3] = vect
|
||||||
|
if threshold is not None:
|
||||||
|
self.uniforms["clip_plane"][3] = threshold
|
||||||
|
return self
|
||||||
|
|
||||||
|
def deactivate_clip_plane(self) -> Self:
|
||||||
|
self.uniforms["clip_plane"][:] = 0
|
||||||
|
return self
|
||||||
|
|
||||||
# Shader code manipulation
|
# Shader code manipulation
|
||||||
|
|
||||||
@affects_data
|
@affects_data
|
||||||
|
|
|
||||||
|
|
@ -65,10 +65,6 @@ class Surface(Mobject):
|
||||||
)
|
)
|
||||||
self.compute_triangle_indices()
|
self.compute_triangle_indices()
|
||||||
|
|
||||||
def init_uniforms(self):
|
|
||||||
super().init_uniforms()
|
|
||||||
self.uniforms["clip_plane"] = np.zeros(4)
|
|
||||||
|
|
||||||
def uv_func(self, u: float, v: float) -> tuple[float, float, float]:
|
def uv_func(self, u: float, v: float) -> tuple[float, float, float]:
|
||||||
# To be implemented in subclasses
|
# To be implemented in subclasses
|
||||||
return (u, v, 0.0)
|
return (u, v, 0.0)
|
||||||
|
|
@ -216,21 +212,6 @@ class Surface(Mobject):
|
||||||
self.add_updater(updater)
|
self.add_updater(updater)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def set_clip_plane(
|
|
||||||
self,
|
|
||||||
vect: Vect3 | None = None,
|
|
||||||
threshold: float | None = None
|
|
||||||
) -> Self:
|
|
||||||
if vect is not None:
|
|
||||||
self.uniforms["clip_plane"][:3] = vect
|
|
||||||
if threshold is not None:
|
|
||||||
self.uniforms["clip_plane"][3] = threshold
|
|
||||||
return self
|
|
||||||
|
|
||||||
def deactivate_clip_plane(self) -> Self:
|
|
||||||
self.uniforms["clip_plane"][:] = 0
|
|
||||||
return self
|
|
||||||
|
|
||||||
def get_shader_vert_indices(self) -> np.ndarray:
|
def get_shader_vert_indices(self) -> np.ndarray:
|
||||||
return self.get_triangle_indices()
|
return self.get_triangle_indices()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ uniform float is_fixed_in_frame;
|
||||||
uniform mat4 view;
|
uniform mat4 view;
|
||||||
uniform float focal_distance;
|
uniform float focal_distance;
|
||||||
uniform vec3 frame_rescale_factors;
|
uniform vec3 frame_rescale_factors;
|
||||||
|
uniform vec4 clip_plane;
|
||||||
|
|
||||||
void emit_gl_Position(vec3 point){
|
void emit_gl_Position(vec3 point){
|
||||||
vec4 result = vec4(point, 1.0);
|
vec4 result = vec4(point, 1.0);
|
||||||
|
|
@ -13,4 +14,8 @@ void emit_gl_Position(vec3 point){
|
||||||
// Flip and scale to prevent premature clipping
|
// Flip and scale to prevent premature clipping
|
||||||
result.z *= -0.1;
|
result.z *= -0.1;
|
||||||
gl_Position = result;
|
gl_Position = result;
|
||||||
|
|
||||||
|
if(clip_plane.xyz != vec3(0.0, 0.0, 0.0)){
|
||||||
|
gl_ClipDistance[0] = dot(vec4(point, 1.0), clip_plane);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
#version 330
|
#version 330
|
||||||
|
|
||||||
uniform vec4 clip_plane;
|
|
||||||
|
|
||||||
in vec3 point;
|
in vec3 point;
|
||||||
in vec3 du_point;
|
in vec3 du_point;
|
||||||
in vec3 dv_point;
|
in vec3 dv_point;
|
||||||
|
|
@ -17,8 +15,4 @@ void main(){
|
||||||
emit_gl_Position(point);
|
emit_gl_Position(point);
|
||||||
vec3 normal = cross(normalize(du_point - point), normalize(dv_point - point));
|
vec3 normal = cross(normalize(du_point - point), normalize(dv_point - point));
|
||||||
v_color = finalize_color(rgba, point, normalize(normal));
|
v_color = finalize_color(rgba, point, normalize(normal));
|
||||||
|
|
||||||
if(clip_plane.xyz != vec3(0.0, 0.0, 0.0)){
|
|
||||||
gl_ClipDistance[0] = dot(vec4(point, 1.0), clip_plane);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Loading…
Add table
Reference in a new issue