Skip to content

Conversation

@MrDiver
Copy link
Collaborator

@MrDiver MrDiver commented May 7, 2022

Overview: What does this pull request change?

Fixing the stroke rendering of the opengl mobjects by porting the curve functions over to them and then optimizing the code again with the newly added features

  • opengl_vectorized_object
    • fixed implementation of pointwise_become_partial (ported from vectorized_mobject)

Before vs After

Before After
drawing drawing
drawing drawing
Test Scene Code
class DashedVMobjectExample(Scene):
    def construct(self):
        r = 0.5

        top_row = VGroup()  # Increasing num_dashes
        for dashes in range(1, 12):
            circ = DashedVMobject(Circle(radius=r, color=WHITE), num_dashes=dashes)
            top_row.add(circ)

        middle_row = VGroup()  # Increasing dashed_ratio
        for ratio in np.arange(1 / 11, 1, 1 / 11):
            circ = DashedVMobject(
                Circle(radius=r, color=WHITE), dashed_ratio=ratio
            )
            middle_row.add(circ)

        func1 = FunctionGraph(lambda t: t**5,[-1,1],color=WHITE)
        func_even = DashedVMobject(func1,num_dashes=6,equal_lengths=True)
        func_stretched = DashedVMobject(func1, num_dashes=6, equal_lengths=False)
        bottom_row = VGroup(func_even,func_stretched)


        top_row.arrange(buff=0.3)
        middle_row.arrange()
        bottom_row.arrange(buff=1)
        everything = VGroup(top_row, middle_row, bottom_row).arrange(DOWN, buff=1)
        self.add(everything)
class SimpleGLTestStill(Scene):
    def construct(self):
        square = Square(side_length=2)
        square.set_fill(RED, opacity=0.3)
        square.rotate(PI / 4)
        square.set_stroke(WHITE, width=2)

        dashed = DashedVMobject(square.copy().rotate(PI/4).scale(2), num_dashes=20, equal_lengths=True)
        dashed.set_fill(GREEN)

        self.add(DashedLine((-3.5,-3,0),(-3.5,3,0)))
        self.add(DashedLine((-3,3,0),(-3,-3,0)))
        self.add(DashedLine((-3,3.5,0),(3,3.5,0)))
        self.add(DashedLine((-2,3,0),(2,3,0)))

        self.add(Line((3.5,-3,0),(3.5,3,0)))
        self.add(Line((3,3,0),(3,-3,0)))
        self.add(Line((-3,-3.5,0),(3,-3.5,0)))
        self.add(Line((-2,-3,0),(2,-3,0)))

        self.add(DashedVMobject(Circle().scale(2), num_dashes=20, equal_lengths=False))
        self.add(DashedVMobject(Circle().scale(1.5), num_dashes=20, equal_lengths=True))
        self.add(square, dashed)
        cube_mesh = Cube(side_length=2)
        self.add(cube_mesh.rotate(PI/4, axis=UP).rotate(PI/4, axis=LEFT).scale(0.5).set_stroke(WHITE,width=2))

Motivation and Explanation: Why and how do your changes improve the library?

Futher improves rendering compatibility with OpenGL

Depends on

Archive

Persisting problem

Overlapping points produce gaps in a curve. It would be good if the mobject didn't need all the redundant points! But if we change the implementation to be similar to vectorized_mobject then the interpolation function will not work anymore. There needs to be a way to interpolate between mobjects with different amounts of points!

Reality Expected
grafik grafik

Temporary solution

I switched the order in which the points appear such that they produce no gaps but also do not produce errors in an animation or triangulation step.

Solution

Porting over pointwise_become_partial from Mobject into OpenGLMobject

Reviewer Checklist

  • The PR title is descriptive enough for the changelog, and the PR is labeled correctly
  • If applicable: newly added non-private functions and classes have a docstring including a short summary and a PARAMETERS section
  • If applicable: newly added functions and classes are tested

@MrDiver MrDiver marked this pull request as draft May 7, 2022 14:16
@MrDiver MrDiver added opengl Concerning the OpenGL renderer. issue:bug Something isn't working... For use in issues enhancement Additions and improvements in general labels May 7, 2022
@MrDiver MrDiver force-pushed the stroke_rendering branch 4 times, most recently from 4d9be92 to 0468edd Compare May 7, 2022 15:41
@MrDiver MrDiver marked this pull request as ready for review May 7, 2022 15:43
@MrDiver MrDiver marked this pull request as draft May 7, 2022 15:59
@MrDiver MrDiver force-pushed the stroke_rendering branch 3 times, most recently from 3d4f836 to b994b2c Compare May 7, 2022 22:21
@MrDiver MrDiver marked this pull request as ready for review May 7, 2022 22:22
@MrDiver MrDiver requested review from Darylgolden and removed request for Darylgolden May 7, 2022 22:22
@MrDiver MrDiver force-pushed the stroke_rendering branch 5 times, most recently from 025ddb3 to 58e1564 Compare May 7, 2022 23:03
Copy link
Collaborator

@k4pran k4pran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great thank you very much. I don't know the code well so hopefully someone else can also review, but I tested it locally and the examples you provided work well. I was also playing around with some other existing examples and they also look good.

@MrDiver MrDiver marked this pull request as draft May 9, 2022 20:13
@MrDiver
Copy link
Collaborator Author

MrDiver commented May 9, 2022

Still breaks a lot. The Animation system needs a deeper rewrite than this to be comparable to the cairo rendering.

@MrDiver MrDiver marked this pull request as ready for review May 20, 2022 09:08
@MrDiver MrDiver force-pushed the stroke_rendering branch 2 times, most recently from 80f8593 to 6f96943 Compare May 25, 2022 14:06
@MrDiver MrDiver changed the title Fix Stroke Rendering OpenGLVMobject fix pointwise_become_partial to fix stroke rendering May 25, 2022
@MrDiver
Copy link
Collaborator Author

MrDiver commented May 25, 2022

Now ready to be reviewed and potentially merged!

@MrDiver MrDiver requested a review from behackl May 28, 2022 09:04
@MrDiver MrDiver self-assigned this Jun 12, 2022
@MrDiver MrDiver added the pr:dependent This PR or issue requires that another PR is merged first label Jun 16, 2022
@MrDiver
Copy link
Collaborator Author

MrDiver commented Jun 19, 2022

get_bezier_tuples_from_points might be implemented with np.reshape instead of creating a new list. This assures no conversion between numpy and normal python is taking place when remapping which makes it a lot faster!

@MrDiver MrDiver force-pushed the stroke_rendering branch from 4357981 to 68e8d72 Compare July 9, 2022 10:51
@MrDiver MrDiver force-pushed the stroke_rendering branch from 68e8d72 to b63ecca Compare July 9, 2022 10:53
@MrDiver MrDiver force-pushed the stroke_rendering branch from 26eb51c to 3aff661 Compare July 9, 2022 10:57
@MrDiver MrDiver marked this pull request as ready for review July 9, 2022 12:13
@behackl behackl enabled auto-merge (squash) July 10, 2022 15:44
@behackl behackl added this to the v0.16.0 milestone Jul 10, 2022
@behackl behackl merged commit 9a0cac7 into ManimCommunity:main Jul 10, 2022
@behackl behackl changed the title OpenGLVMobject fix pointwise_become_partial to fix stroke rendering Fixed :meth:.OpenGLVMobject.pointwise_become_partial to improve stroke rendering Jul 10, 2022
@MrDiver MrDiver deleted the stroke_rendering branch December 26, 2022 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Additions and improvements in general issue:bug Something isn't working... For use in issues opengl Concerning the OpenGL renderer. pr:dependent This PR or issue requires that another PR is merged first

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants