Skip to content

[pull] main from ManimCommunity:main #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/cffconvert.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: cffconvert

on:
push:
paths:
- CITATION.cff

jobs:
validate:
name: "validate"
runs-on: ubuntu-latest
steps:
- name: Check out a copy of the repository
uses: actions/checkout@v2

- name: Check whether the citation metadata from CITATION.cff is valid
uses: citation-file-format/[email protected]
with:
args: "--validate"
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
authors:
-
name: "The Manim Community Developers"
cff-version: "1.1.0"
cff-version: "1.2.0"
date-released: 2022-01-07
license: MIT
message: "We acknowledge the importance of good software to support research, and we note that research becomes more valuable when it is communicated effectively. To demonstrate the value of Manim, we ask that you cite Manim in your work."
Expand Down
38 changes: 33 additions & 5 deletions manim/mobject/opengl_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class OpenGLMobject:
rgbas = _Data()

is_fixed_in_frame = _Uniforms()
is_fixed_orientation = _Uniforms()
fixed_orientation_center = _Uniforms() # for fixed orientation reference
gloss = _Uniforms()
shadow = _Uniforms()

Expand All @@ -85,6 +87,7 @@ def __init__(
depth_test=False,
# If true, the mobject will not get rotated according to camera position
is_fixed_in_frame=False,
is_fixed_orientation=False,
# Must match in attributes of vert shader
# Event listener
listen_to_events=False,
Expand All @@ -109,6 +112,8 @@ def __init__(
self.depth_test = depth_test
# If true, the mobject will not get rotated according to camera position
self.is_fixed_in_frame = float(is_fixed_in_frame)
self.is_fixed_orientation = float(is_fixed_orientation)
self.fixed_orientation_center = (0, 0, 0)
# Must match in attributes of vert shader
# Event listener
self.listen_to_events = listen_to_events
Expand Down Expand Up @@ -2349,11 +2354,20 @@ def construct(self):

self.data[key][:] = func(mobject1.data[key], mobject2.data[key], alpha)
for key in self.uniforms:
self.uniforms[key] = interpolate(
mobject1.uniforms[key],
mobject2.uniforms[key],
alpha,
)
if key != "fixed_orientation_center":
self.uniforms[key] = interpolate(
mobject1.uniforms[key],
mobject2.uniforms[key],
alpha,
)
else:
self.uniforms["fixed_orientation_center"] = tuple(
interpolate(
np.array(mobject1.uniforms["fixed_orientation_center"]),
np.array(mobject2.uniforms["fixed_orientation_center"]),
alpha,
)
)
return self

def pointwise_become_partial(self, mobject, a, b):
Expand Down Expand Up @@ -2485,11 +2499,25 @@ def fix_in_frame(self):
self.is_fixed_in_frame = 1.0
return self

@affects_shader_info_id
def fix_orientation(self):
self.is_fixed_orientation = 1.0
self.fixed_orientation_center = tuple(self.get_center())
self.depth_test = True
return self

@affects_shader_info_id
def unfix_from_frame(self):
self.is_fixed_in_frame = 0.0
return self

@affects_shader_info_id
def unfix_orientation(self):
self.is_fixed_orientation = 0.0
self.fixed_orientation_center = (0, 0, 0)
self.depth_test = False
return self

@affects_shader_info_id
def apply_depth_test(self):
self.depth_test = True
Expand Down
2 changes: 2 additions & 0 deletions manim/mobject/types/opengl_vectorized_mobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,8 @@ def get_stroke_uniforms(self):
def get_fill_uniforms(self):
return {
"is_fixed_in_frame": float(self.is_fixed_in_frame),
"is_fixed_orientation": float(self.is_fixed_orientation),
"fixed_orientation_center": self.fixed_orientation_center,
"gloss": self.gloss,
"shadow": self.shadow,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ uniform float anti_alias_width;
uniform vec3 camera_center;
uniform mat3 camera_rotation;
uniform float is_fixed_in_frame;
uniform float is_fixed_orientation;
uniform vec3 fixed_orientation_center;
uniform float focal_distance;
11 changes: 9 additions & 2 deletions manim/renderer/shaders/include/get_gl_Position.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// uniform vec2 frame_shape;
// uniform float focal_distance;
// uniform float is_fixed_in_frame;
// uniform float is_fixed_orientation;
// uniform vec3 fixed_orientation_center;

const vec2 DEFAULT_FRAME_SHAPE = vec2(8.0 * 16.0 / 9.0, 8.0);

Expand All @@ -23,8 +25,13 @@ vec4 get_gl_Position(vec3 point){
result.z *= 0.01;
}
} else{
result.x *= 2.0 / DEFAULT_FRAME_SHAPE.x;
result.y *= 2.0 / DEFAULT_FRAME_SHAPE.y;
if (!bool(is_fixed_orientation)){
result.x *= 2.0 / DEFAULT_FRAME_SHAPE.x;
result.y *= 2.0 / DEFAULT_FRAME_SHAPE.y;
} else{
result.x *= 2.0 / frame_shape.x;
result.y *= 2.0 / frame_shape.y;
}
}
result.z *= -1;
return result;
Expand Down
6 changes: 6 additions & 0 deletions manim/renderer/shaders/include/position_point_into_frame.glsl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Assumes the following uniforms exist in the surrounding context:
// uniform float is_fixed_in_frame;
// uniform float is_fixed_orientation;
// uniform vec3 fixed_orientation_center;
// uniform vec3 camera_center;
// uniform mat3 camera_rotation;

Expand All @@ -15,5 +17,9 @@ vec3 position_point_into_frame(vec3 point){
if(bool(is_fixed_in_frame)){
return point;
}
if(bool(is_fixed_orientation)){
vec3 new_center = rotate_point_into_frame(fixed_orientation_center);
return point + (new_center - fixed_orientation_center);
}
return rotate_point_into_frame(point - camera_center);
}
2 changes: 2 additions & 0 deletions manim/renderer/shaders/quadratic_bezier_fill/geom.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ uniform float anti_alias_width;
uniform vec2 frame_shape;
uniform float focal_distance;
uniform float is_fixed_in_frame;
uniform float is_fixed_orientation;
uniform vec3 fixed_orientation_center;
// Needed for finalize_color
uniform vec3 light_source_position;
uniform float gloss;
Expand Down
2 changes: 2 additions & 0 deletions manim/renderer/shaders/quadratic_bezier_stroke/geom.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ layout (triangle_strip, max_vertices = 5) out;
uniform vec2 frame_shape;
uniform float focal_distance;
uniform float is_fixed_in_frame;
uniform float is_fixed_orientation;
uniform vec3 fixed_orientation_center;

uniform float anti_alias_width;
uniform float flat_stroke;
Expand Down
2 changes: 2 additions & 0 deletions manim/renderer/shaders/true_dot/geom.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ layout (triangle_strip, max_vertices = 4) out;
uniform vec2 frame_shape;
uniform float focal_distance;
uniform float is_fixed_in_frame;
uniform float is_fixed_orientation;
uniform vec3 fixed_orientation_center;
uniform float anti_alias_width;

in vec3 v_point[1];
Expand Down
37 changes: 31 additions & 6 deletions manim/scene/three_d_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,14 @@ def add_fixed_orientation_mobjects(self, *mobjects, **kwargs):
use_static_center_func : bool
center_func : function
"""
self.add(*mobjects)
self.renderer.camera.add_fixed_orientation_mobjects(*mobjects, **kwargs)
if config.renderer != "opengl":
self.add(*mobjects)
self.renderer.camera.add_fixed_orientation_mobjects(*mobjects, **kwargs)
else:
for mob in mobjects:
mob: OpenGLMobject
mob.fix_orientation()
self.add(mob)

def add_fixed_in_frame_mobjects(self, *mobjects):
"""
Expand All @@ -365,8 +371,15 @@ def add_fixed_in_frame_mobjects(self, *mobjects):
*mobjects : Mobjects
The Mobjects whose orientation must be fixed.
"""
self.add(*mobjects)
self.renderer.camera.add_fixed_in_frame_mobjects(*mobjects)
if config.renderer != "opengl":
self.add(*mobjects)
self.camera: ThreeDCamera
self.camera.add_fixed_in_frame_mobjects(*mobjects)
else:
for mob in mobjects:
mob: OpenGLMobject
mob.fix_in_frame()
self.add(mob)

def remove_fixed_orientation_mobjects(self, *mobjects):
"""
Expand All @@ -380,7 +393,13 @@ def remove_fixed_orientation_mobjects(self, *mobjects):
*mobjects : Mobjects
The Mobjects whose orientation must be unfixed.
"""
self.renderer.camera.remove_fixed_orientation_mobjects(*mobjects)
if config.renderer != "opengl":
self.renderer.camera.remove_fixed_orientation_mobjects(*mobjects)
else:
for mob in mobjects:
mob: OpenGLMobject
mob.unfix_orientation()
self.remove(mob)

def remove_fixed_in_frame_mobjects(self, *mobjects):
"""
Expand All @@ -393,7 +412,13 @@ def remove_fixed_in_frame_mobjects(self, *mobjects):
*mobjects : Mobjects
The Mobjects whose position and orientation must be unfixed.
"""
self.renderer.camera.remove_fixed_in_frame_mobjects(*mobjects)
if config.renderer != "opengl":
self.renderer.camera.remove_fixed_in_frame_mobjects(*mobjects)
else:
for mob in mobjects:
mob: OpenGLMobject
mob.unfix_from_frame()
self.remove(mob)

##
def set_to_default_angled_camera_orientation(self, **kwargs):
Expand Down
Binary file not shown.
13 changes: 13 additions & 0 deletions tests/test_graphical_units/test_opengl.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,16 @@ def test_Circle(scene):
circle = Circle().set_color(RED)
scene.add(circle)
scene.wait()


@frames_comparison(
renderer_class=OpenGLRenderer,
renderer="opengl",
)
def test_FixedMobjects3D(scene: Scene):
scene.renderer.camera.set_euler_angles(phi=75 * DEGREES, theta=-45 * DEGREES)
circ = Circle(fill_opacity=1).to_edge(LEFT)
square = Square(fill_opacity=1).to_edge(RIGHT)
triangle = Triangle(fill_opacity=1).to_corner(UR)
[i.fix_orientation() for i in (circ, square)]
triangle.fix_in_frame()
13 changes: 0 additions & 13 deletions tests/test_graphical_units/test_threed.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,6 @@ def test_AmbientCameraMove(scene):
scene.wait()


# TODO: bring test back after introducing testing tolerance
# to account for OS-specific differences in numerics.

# class FixedInFrameMObjectTest(ThreeDScene):
# def construct(scene):
# axes = ThreeDAxes()
# scene.set_camera_orientation(phi=75 * DEGREES, theta=-45 * DEGREES)
# circ = Circle()
# scene.add_fixed_in_frame_mobjects(circ)
# circ.to_corner(UL)
# scene.add(axes)


@frames_comparison(base_scene=ThreeDScene)
def test_MovingVertices(scene):
scene.set_camera_orientation(phi=75 * DEGREES, theta=30 * DEGREES)
Expand Down