question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mesh.rotate_*( ) & mesh.translate( ) move camera even though camera.position is specified

See original GitHub issue

Describe the bug, what’s wrong, and what you expected.

When applying rotations or translations to meshes, it seems like the camera moves around even though a camera.position is specified. This seems like undesired behaviour, as when I specify a camera I would like it to be fixed and not be influenced by a mesh being rotated or translated. Seems like even the axis changes sometimes (couldn’t get a screenshot this time).

Steps to reproduce the bug.

from pyvista import examples
filename = examples.planefile
plane = pv.read(filename)

# Alternate between different translations and rotations here
plane_mesh = plane.translate((100, 0, 100), inplace=False)
plane_mesh = plane_mesh.rotate_z(-30, inplace=False)

p = pv.Plotter()
p.show_axes()
p.add_mesh(plane, color=True, show_edges=True, opacity=0.5)
p.add_mesh(plane_mesh, color=True, show_edges=True, opacity=0.5)
p.camera.position = (0, 3000, 2000)
p.show()

System Information

--------------------------------------------------------------------------------
  Date: Tue Aug 16 12:06:34 2022 CEST

                OS : Darwin
            CPU(s) : 8
           Machine : x86_64
      Architecture : 64bit
               RAM : 16.0 GiB
       Environment : Jupyter
       File system : apfs
        GPU Vendor : ATI Technologies Inc.
      GPU Renderer : AMD Radeon Pro 560 OpenGL Engine
       GPU Version : 4.1 ATI-4.8.54

  Python 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 05:57:50)
  [Clang 11.1.0 ]

           pyvista : 0.36.1
               vtk : 9.1.0
             numpy : 1.21.6
           imageio : 2.21.1
           appdirs : 1.4.4
            scooby : 0.5.12
        matplotlib : 3.5.2
           IPython : 7.33.0
          colorcet : 3.0.0
           cmocean : 2.0
        ipyvtklink : 0.2.2
             scipy : 1.7.3
              tqdm : 4.64.0
            meshio : 5.3.4
        jupyterlab : 3.4.4
--------------------------------------------------------------------------------

Screenshots

Screenshot 2022-08-16 at 12 02 00 Screenshot 2022-08-16 at 12 01 36 Screenshot 2022-08-16 at 12 01 01

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
MatthewFlammcommented, Aug 17, 2022

Sorry actually this sets the focal point on the centre of the original plane, but does it have to be dependent on a mesh? Or can it be set to the global origin instead?

In my example, plane.center is a sequence (X, Y, Z). You can use any point in space. Try (0, 0, 0) to use the world origin.

1reaction
MatthewFlammcommented, Aug 16, 2022

You have set the camera position, but have allowed the focal point of the camera to adjust based on the scene. Does the below do what you want? It sets the focal point on the center of the original plane.

from pyvista import examples
filename = examples.planefile
plane = pv.read(filename)

# Alternate between different translations and rotations here
plane_mesh = plane.translate((100, 0, 100), inplace=False)
plane_mesh = plane_mesh.rotate_z(-30, inplace=False)

p = pv.Plotter()
p.show_axes()
p.add_mesh(plane, color='red', show_edges=True, opacity=0.5)
p.add_mesh(plane_mesh, color='blue', show_edges=True, opacity=0.5)
p.camera.position = (0, 3000, 2000)
p.camera.focal_point = plane.center
p.show()
Read more comments on GitHub >

github_iconTop Results From Across the Web

metal - Rotation, Translation and Default Camera Location
1 Answer 1 · There is no default location for the camera, other than the origin (0, 0, 0) if you want to...
Read more >
Transformations, Coordinate Systems, and the Scene Graph
Here, we explore how to move objects around in 3D space using translation, rotation, and scale, and the coordinate systems which makes up...
Read more >
Use Translations and Rotations - Babylon.js Documentation
Unlike position which sets the mesh to the values give translate moves the mesh in the given direction by the distance give and...
Read more >
Camera - LearnOpenGL
First we set the camera position to the previously defined cameraPos . The direction is the current position + the direction vector we...
Read more >
How to move the Camera in Blender (All possible ways)
The first and easiest way of moving a camera in Blender is using the tried ... G (Grab/translate) and R (Rotate) after selecting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found