Skip to content
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

CubeMove breaks when the cube is rotated #4

Open
vvolhejn opened this issue Oct 5, 2021 · 0 comments · May be fixed by #5
Open

CubeMove breaks when the cube is rotated #4

vvolhejn opened this issue Oct 5, 2021 · 0 comments · May be fixed by #5

Comments

@vvolhejn
Copy link

vvolhejn commented Oct 5, 2021

When the cube is rotated so that it's not axis-aligned, CubeMove throws a KeyError. Example:

from manim import *
from manim_rubikscube import *


class RubiksCubeBug(ThreeDScene):
    def construct(self):
        cube = RubiksCube()
        cube.rotate(axis=[1, 1, 1], angle=PI)
        self.add(cube)
        self.play(CubeMove(cube, "F"))
        self.wait(1)

This gives me:


╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│                                                                                                  │
│ /usr/local/lib/python3.9/site-packages/manim/cli/render/commands.py:139 in render                │
│                                                                                                  │
│   136 │   │   for SceneClass in scene_classes_from_file(file):                                   │
│   137 │   │   │   try:                                                                           │
│   138 │   │   │   │   scene = SceneClass()                                                       │
│ ❱ 139 │   │   │   │   scene.render()                                                             │
│   140 │   │   │   except Exception:                                                              │
│   141 │   │   │   │   error_console.print_exception()                                            │
│   142 │   │   │   │   sys.exit(1)                                                                │
│ /usr/local/lib/python3.9/site-packages/manim/scene/scene.py:213 in render                        │
│                                                                                                  │
│    210 │   │   """                                                                               │
│    211 │   │   self.setup()                                                                      │
│    212 │   │   try:                                                                              │
│ ❱  213 │   │   │   self.construct()                                                              │
│    214 │   │   except EndSceneEarlyException:                                                    │
│    215 │   │   │   pass                                                                          │
│    216 │   │   except RerunSceneException as e:                                                  │
│                                                                                                  │
│ /Users/vaclav/prog/rubiks-cube-video/cube_bug.py:11 in construct                                 │
│                                                                                                  │
│    8 │   │   cube.rotate(axis=[1, 1, 1], angle=PI)                                               │
│    9 │   │   self.add(cube)                                                                      │
│   10 │   │   self.play(CubeMove(cube, "F"))                                                      │
│ ❱ 11 │   │   self.wait(1)                                                                        │
│   12                                                                                             │
│                                                                                                  │
│ /usr/local/lib/python3.9/site-packages/manim/scene/scene.py:888 in play                          │
│                                                                                                  │
│    885 │   │   │   return np.max([animation.run_time for animation in animations])               │
│    886 │                                                                                         │
│    887 │   def play(self, *args, **kwargs):                                                      │
│ ❱  888 │   │   self.renderer.play(self, *args, **kwargs)                                         │
│    889 │                                                                                         │
│    890 │   def wait(self, duration=DEFAULT_WAIT_TIME, stop_condition=None):                      │
│    891 │   │   self.play(Wait(run_time=duration, stop_condition=stop_condition))                 │
│                                                                                                  │
│ /usr/local/lib/python3.9/site-packages/manim/renderer/cairo_renderer.py:134 in play              │
│                                                                                                  │
│   131 │   │   │   # In this case, as there is only a wait, it will be the length of the wait.    │
│   132 │   │   │   self.freeze_current_frame(scene.duration)                                      │
│   133 │   │   else:                                                                              │
│ ❱ 134 │   │   │   scene.play_internal()                                                          │
│   135 │   │   self.file_writer.end_animation(not self.skip_animations)                           │
│   136 │   │                                                                                      │
│   137 │   │   self.num_plays += 1                                                                │
│                                                                                                  │
│ /usr/local/lib/python3.9/site-packages/manim/scene/scene.py:999 in play_internal                 │
│                                                                                                  │
│    996 │   │   │   │   break                                                                     │
│    997 │   │                                                                                     │
│    998 │   │   for animation in self.animations:                                                 │
│ ❱  999 │   │   │   animation.finish()                                                            │
│   1000 │   │   │   animation.clean_up_from_scene(self)                                           │
│   1001 │   │   if not self.renderer.skip_animations:                                             │
│   1002 │   │   │   self.update_mobjects(0)                                                       │
│                                                                                                  │
│ /usr/local/lib/python3.9/site-packages/manim_rubikscube/cube_animations.py:31 in finish          │
│                                                                                                  │
│   28 │                                                                                           │
│   29 │   def finish(self):                                                                       │
│   30 │   │   super().finish()                                                                    │
│ ❱ 31 │   │   self.mobject.adjust_indices(self.mobject.get_face(self.face[0], False))             │
│                                                                                                  │
│ /usr/local/lib/python3.9/site-packages/manim_rubikscube/cube.py:117 in adjust_indices            │
│                                                                                                  │
│   114 │                                                                                          │
│   115 │   def adjust_indices(self, cubies):                                                      │
│   116 │   │   for c in cubies.flatten():                                                         │
│ ❱ 117 │   │   │   loc = self.indices[c.get_rounded_center()]                                     │
│   118 │   │   │   self.cubies[loc[0], loc[1], loc[2]] = c                                        │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
KeyError: (0.0, 1.4, -0.0)

I am using Manim Community v0.11.0, manim-rubikscube v0.1.0.

@vvolhejn vvolhejn linked a pull request Oct 5, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant