object rotate python API #67393

Closed
opened 2019-07-21 18:27:59 +02:00 by jensdahlkunoy@gmail.com · 6 comments

System Information
Operating system: Windows 10
Graphics card: RTX 2060

Blender Version
Broken: 2.80 RC 2

Short description of error
Python API does not rotate camera around 3d cursor but around local camera axis. See this screendump: wrongrotate.PNG

Exact steps for others to reproduce the error
Based on the default startup or an attached .blend file (as simple as possible).

Run the following script: rotatebug.py

import bpy
    
loc=[0,0,10]
rot=[0,0,0]
bpy.ops.object.camera_add(location=loc,rotation=rot)

bpy.context.scene.cursor.location=[0,0,0]
bpy.context.scene.tool_settings.transform_pivot_point = 'CURSOR'
bpy.ops.transform.rotate(value=45, orient_axis='X', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(True, False, False))
**System Information** Operating system: Windows 10 Graphics card: RTX 2060 **Blender Version** Broken: 2.80 RC 2 **Short description of error** Python API does not rotate camera around 3d cursor but around local camera axis. See this screendump: ![wrongrotate.PNG](https://archive.blender.org/developer/F7621987/wrongrotate.PNG) **Exact steps for others to reproduce the error** Based on the default startup or an attached .blend file (as simple as possible). Run the following script: [rotatebug.py](https://archive.blender.org/developer/F7621982/rotatebug.py) ``` import bpy loc=[0,0,10] rot=[0,0,0] bpy.ops.object.camera_add(location=loc,rotation=rot) bpy.context.scene.cursor.location=[0,0,0] bpy.context.scene.tool_settings.transform_pivot_point = 'CURSOR' bpy.ops.transform.rotate(value=45, orient_axis='X', orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(True, False, False)) ```

Added subscriber: @jdk

Added subscriber: @jdk

Added subscriber: @dr.sybren

Added subscriber: @dr.sybren

I can confirm that the attached code rotates the camera around its own origin, rather than the 3D cursor.

Generally it's better to not use operators to perform transformations, though. Rotating around an arbitrary point can be done without moving the 3D cursor by multiplying the object's matrix. This is also generally faster than relying on operators, and easier to control (you don't have to change the active object, don't have to change the 3D cursor, etc.).

I can confirm that the attached code rotates the camera around its own origin, rather than the 3D cursor. Generally it's better to not use operators to perform transformations, though. Rotating around an arbitrary point can be done without moving the 3D cursor by multiplying the object's matrix. This is also generally faster than relying on operators, and easier to control (you don't have to change the active object, don't have to change the 3D cursor, etc.).
Campbell Barton was assigned by Sebastian Parborg 2019-07-30 12:53:48 +02:00
Campbell Barton was unassigned by Dalai Felinto 2019-12-23 16:33:37 +01:00

Added subscriber: @ideasman42

Added subscriber: @ideasman42

Changed status from 'Confirmed' to: 'Archived'

Changed status from 'Confirmed' to: 'Archived'
Sybren A. Stüvel self-assigned this 2020-01-27 18:31:46 +01:00

I'm closing this as Known Issue, as the operators are working as designed and are hard to change without influencing many other areas of Blender.

As I said my earlier comment, changing the object's matrix is a better way to rotate; it's more reliable, and it doesn't make users loose their 3D cursor position.

I'm closing this as Known Issue, as the operators are working as designed and are hard to change without influencing many other areas of Blender. As I said my earlier comment, changing the object's matrix is a better way to rotate; it's more reliable, and it doesn't make users loose their 3D cursor position.
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#67393
No description provided.