Skip to content

ThreeDScene's set_to_default_angled_camera_orientation method raises AttributeError #4472

@kmdouglass

Description

@kmdouglass

Description of bug / unexpected behavior

The set_to_default_angled_camera_orientation method of ThreeDScene raises an AttributeError when called because the class attribute default_camera_orientation_kwargs does not exist.

I believe that the problem comes from these lines:

The classes's __init__ method sets an attribute called self.default_angled_camera_orientation_kwargs, but the method tries to access an attribute called self.default_camera_orientation_kwargs.

Expected behavior

I expect that set_to_default_angled_camera_orientation should not raise an AttributeError.

I also expect that the keyword arguments such as phi and theta can be passed to this method because this is what is described in the documentation: https://docs.manim.community/en/stable/reference/manim.scene.three_d_scene.ThreeDScene.html#manim.scene.three_d_scene.ThreeDScene.set_to_default_angled_camera_orientation

How to reproduce the issue

See the code snippet below.

The line that raises the error is the very first call to set_to_default_angled_camera_orientation in the ThreeDScene's construct method.

The create_3d_crystal_lattice function is not important but included to make the code snippet run.

Code for reproducing the problem
from manim import *


def create_3d_crystal_lattice(
    num_points_per_axis: int = 3,
    point_radius: float = 0.1,
    dx: float = 1.0,
    dy: float = 1.0,
    dz: float = 1.0,
    scale: float = 2.0,
) -> VGroup:
    lattice = VGroup()

    # Axes
    # The axes are centered at zero and at most two units longer than the extent of the atoms
    axis_range = (
        (-((num_points_per_axis + 1) // 2) * dx, ((num_points_per_axis + 1) // 2) * dx, 1),
        (-((num_points_per_axis + 1) // 2) * dy, ((num_points_per_axis + 1) // 2) * dy, 1),
        (-((num_points_per_axis + 1) // 2) * dz, ((num_points_per_axis + 1) // 2) * dz, 1),
    )

    axes = ThreeDAxes(
        x_range=axis_range[0],
        y_range=axis_range[1],
        z_range=axis_range[2],
        x_length=scale * ((num_points_per_axis + 1) // 2 * dx),
        y_length=scale * ((num_points_per_axis + 1) // 2 * dy),
        z_length=scale * ((num_points_per_axis + 1) // 2 * dz),
    )
    lattice.add(axes)

    # Atoms
    for i in range(num_points_per_axis):
        for j in range(num_points_per_axis):
            for k in range(num_points_per_axis):
                atom = Sphere(
                    radius=point_radius,
                    resolution=(8, 8)
                )
                atom.set_color(YELLOW)
                atom.move_to(
                    np.array(
                        [
                            i * dx - (num_points_per_axis / 2 - 0.5),
                            j * dy - (num_points_per_axis / 2 - 0.5),
                            k * dz - (num_points_per_axis / 2 - 0.5)
                        ]
                    )
                )
                lattice.add(atom)
    return lattice


class BraggCondition(ThreeDScene):
    def construct(self) -> None:
        #------------------------------------------------------------------------------------------
        # Crystal Lattice
        self.set_to_default_angled_camera_orientation(phi=0 * DEGREES, theta=0 * DEGREES)

        lattice = create_3d_crystal_lattice()
        lattice.move_to(ORIGIN)
        self.play(Create(lattice))
        self.wait(1)

        self.move_camera(phi=75 * DEGREES, theta=30 * DEGREES)
        self.wait(2)
        self.move_camera(phi=0 * DEGREES, theta=0 * DEGREES)

Additional media files

N/A

Logs

Terminal output
+--------------------- Traceback (most recent call last) ---------------------+
| C:\Users\douglass\src\teaching\animations\xray_diffraction\.venv\Lib\site-p |
| ackages\manim\cli\render\commands.py:125 in render                          |
|                                                                             |
|   122             try:                                                      |
|   123                 with tempconfig({}):                                  |
|   124                     scene = SceneClass()                              |
| > 125                     scene.render()                                    |
|   126             except Exception:                                         |
|   127                 error_console.print_exception()                       |
|   128                 sys.exit(1)                                           |
|                                                                             |
| C:\Users\douglass\src\teaching\animations\xray_diffraction\.venv\Lib\site-p |
| ackages\manim\scene\scene.py:237 in render                                  |
|                                                                             |
|    234         """                                                          |
|    235         self.setup()                                                 |
|    236         try:                                                         |
| >  237             self.construct()                                         |
|    238         except EndSceneEarlyException:                               |
|    239             pass                                                     |
|    240         except RerunSceneException:                                  |
|                                                                             |
| c:\Users\douglass\src\teaching\animations\xray_diffraction\bragg_condition. |
| py:62 in construct                                                          |
|                                                                             |
|   59                                                                        |
|   60         #------------------------------------------------------------- |
|   61         # Crystal Lattice                                              |
| > 62         self.set_to_default_angled_camera_orientation(phi=0 * DEGREES, |
|   63                                                                        |
|   64         lattice = create_3d_crystal_lattice()                          |
|   65         lattice.move_to(ORIGIN)                                        |
|                                                                             |
| C:\Users\douglass\src\teaching\animations\xray_diffraction\.venv\Lib\site-p |
| ackages\manim\scene\three_d_scene.py:431 in                                 |
| set_to_default_angled_camera_orientation                                    |
|                                                                             |
|   428             which have the same meaning as the parameters in set_came |
|   429         """                                                           |
|   430         config = dict(                                                |
| > 431             self.default_camera_orientation_kwargs,                   |
|   432         )  # Where doe this come from?                                |
|   433         config.update(kwargs)                                         |
|   434         self.set_camera_orientation(**config)                         |
+-----------------------------------------------------------------------------+
AttributeError: 'BraggCondition' object has no attribute 
'default_camera_orientation_kwargs'
[17060] Execution returned code=1 in 1.639 seconds returned signal null

System specifications

System Details
  • OS: Windows 11 Pro 24H2 26100.6899
  • RAM: 32 GB
  • Python version (python/py/python3 --version): 3.13.2
  • Installed modules (provide output from pip list):
Package           Version
----------------- -----------
audioop-lts       0.2.2
av                13.1.0
beautifulsoup4    4.14.2
click             8.3.0
cloup             3.0.8
colorama          0.4.6
decorator         5.2.1
glcontext         3.0.0
isosurfaces       0.1.2
manim             0.19.0
manimpango        0.6.1
mapbox-earcut     1.0.3
markdown-it-py    4.0.0
mdurl             0.1.2
moderngl          5.12.0
moderngl-window   3.1.1
networkx          3.5
numpy             2.3.4
pillow            12.0.0
pycairo           1.28.0
pydub             0.25.1
pyglet            2.1.11
pyglm             2.8.2
pygments          2.19.2
rich              14.2.0
scipy             1.16.3
screeninfo        0.8.1
skia-pathops      0.8.0.post2
soupsieve         2.8
srt               3.5.3
svgelements       1.9.6
tqdm              4.67.1
typing-extensions 4.15.0
watchdog          6.0.0
LaTeX details
  • LaTeX distribution: MikTeX 24.1
  • Installed LaTeX packages:

Additional comments

There is a telling comment in the source code that indicates that the programmer was aware that it was not clear where the attribute comes from:

) # Where doe this come from?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions