|
| 1 | +# Migrating from v0.19.0 to v0.20.0 |
| 2 | + |
| 3 | +This constitutes a list of all the changes needed to migrate your code |
| 4 | +to work with the latest version of Manim |
| 5 | + |
| 6 | +## Manager |
| 7 | +If you ever used `Scene.render`, you must replace it with {class}`.Manager`. |
| 8 | + |
| 9 | +Original code: |
| 10 | +```py |
| 11 | +scene = SceneClass() |
| 12 | +scene.render() |
| 13 | +``` |
| 14 | +should be changed to: |
| 15 | +```py |
| 16 | +manager = Manager(SceneClass) |
| 17 | +manager.render() |
| 18 | +``` |
| 19 | + |
| 20 | +If you are a plugin author that subclasses `Scene` and changed `Scene.render`, you should migrate |
| 21 | +your code to use the specific public methods on {class}`.Manager` instead. |
| 22 | + |
| 23 | +## ThreeDScene and Camera |
| 24 | +`ThreeDScene` has been completely removed, and all of its functionality has been replaced |
| 25 | +with methods on {class}`.Camera`, which can be accessed via {attr}`.Scene.camera`. |
| 26 | + |
| 27 | +For example, the following code |
| 28 | +```py |
| 29 | +class MyScene(ThreeDScene): |
| 30 | + def construct(self): |
| 31 | + t = Text("Hello") |
| 32 | + self.add_fixed_in_frame_mobjects(t) |
| 33 | + self.begin_ambient_camera_rotation() |
| 34 | + self.wait(3) |
| 35 | +``` |
| 36 | +should be changed to |
| 37 | +```py |
| 38 | +# change ThreeDScene -> Scene |
| 39 | +class MyScene(Scene): |
| 40 | + def construct(self): |
| 41 | + t = Text("Hello") |
| 42 | + # add_fixed_in_frame_mobjects() no longer exists. |
| 43 | + # Now you must use Mobject.fix_in_frame() manually for each Mobject. |
| 44 | + t.fix_in_frame() |
| 45 | + self.add(t) |
| 46 | + |
| 47 | + # access the method on the camera |
| 48 | + self.camera.begin_ambient_rotation() |
| 49 | + self.add(self.camera) |
| 50 | + self.wait(3) |
| 51 | +``` |
| 52 | + |
| 53 | +## Animation |
| 54 | +`Animation.interpolate_mobject` has been combined into `Animation.interpolate`. |
| 55 | + |
| 56 | +Methods `Animation._setup_scene` and `Animation.clean_up_from_scene` have been removed |
| 57 | +in favor of `Animation.begin` and `Animation.finish`. If you need to access the scene, |
| 58 | +you can use a simple buffer to communicate. Note that this buffer cannot access |
| 59 | +methods on the {class}`.Scene`, but can only do basic actions like {meth}`.Scene.add`, |
| 60 | +{meth}`.Scene.remove`, and {meth}`.Scene.replace`. |
| 61 | + |
| 62 | +For example, the following code: |
| 63 | +```py |
| 64 | +class MyAnimation(Animation): |
| 65 | + def begin(self) -> None: |
| 66 | + self._sqrs = VGroup(Square()) |
| 67 | + |
| 68 | + def _setup_scene(self, scene: Scene) -> None: |
| 69 | + scene.add(self._sqr) |
| 70 | + self.scene = scene |
| 71 | + |
| 72 | + def interpolate_mobject(self, alpha: float) -> None: |
| 73 | + sqr = Square().move_to((alpha, 0, 0)) |
| 74 | + self._sqrs.add(sqr) |
| 75 | + self.scene.add(sqr) |
| 76 | + |
| 77 | + def clean_up_from_scene(self, scene: Scene) -> None: |
| 78 | + scene.remove(self._sqrs) |
| 79 | +``` |
| 80 | + |
| 81 | +should be changed to |
| 82 | +```py |
| 83 | +class MyAnimation(Animation): |
| 84 | + def begin(self) -> None: |
| 85 | + self._sqrs = VGroup(Square()) |
| 86 | + self.buffer.add(self._sqrs) |
| 87 | + |
| 88 | + def interpolate(self, alpha: float) -> None: |
| 89 | + sqr = Square().move_to((alpha, 0, 0)) |
| 90 | + self._sqrs.add(sqr) |
| 91 | + self.buffer.add(sqr) |
| 92 | + # tell the scene to empty the buffer |
| 93 | + self.apply_buffer = True |
| 94 | + |
| 95 | + def finish(self) -> None: |
| 96 | + self.buffer.remove(self._sqrs) |
| 97 | +``` |
0 commit comments