Matrix world from driver expression is different from object's matrix world? #112816

Open
opened 2023-09-24 21:51:05 +02:00 by Andrej · 6 comments
Contributor

Blender 3.6.3

Noticed that object.matrix_world we get from the driver's expression is different from the same matrix we get from just getting the same matrix using Python API. Since this is basically exactly the same object's property I thought it should be consistent.

Steps to reproduce the issue.

  1. Default Blender scene.

  2. Go to scene->gravity and add 3 drivers similar to this one (issue is unrelated to gravity, just to visualise) with paths listed below:
    image

Paths (Z basis is 2nd column therefore we use [i][2]):

  • matrix_world[0][2]
  • matrix_world[1][2]
  • matrix_world[2][2]
  1. Rotate cube by 90 degrees X axis.

  2. Since I was trying to get Z basis vector then expected values in drivers expected to be (0, -1, 0).
    We can confirm it by running code in python console: C.object.matrix_world[0][2], C.object.matrix_world[1][2], C.object.matrix_world[2][2] and get (0,-1,0).

But the issue is that it's returning (0,1,0) which looks like Z-component of the X,Y,Z basises - so it's kind of like matrix_world we get from the driver expression is transposed I guess.

Blender 3.6.3 Noticed that object.matrix_world we get from the driver's expression is different from the same matrix we get from just getting the same matrix using Python API. Since this is basically exactly the same object's property I thought it should be consistent. Steps to reproduce the issue. 1. Default Blender scene. 2. Go to scene->gravity and add 3 drivers similar to this one (issue is unrelated to gravity, just to visualise) with paths listed below: ![image](/attachments/cc345ae2-2806-4804-a7df-0ba128c90e9c) Paths (Z basis is 2nd column therefore we use [i][2]): - matrix_world[0][2] - matrix_world[1][2] - matrix_world[2][2] 3. Rotate cube by 90 degrees X axis. 4. Since I was trying to get Z basis vector then expected values in drivers expected to be (0, -1, 0). We can confirm it by running code in python console: `C.object.matrix_world[0][2], C.object.matrix_world[1][2], C.object.matrix_world[2][2]` and get (0,-1,0). But the issue is that it's returning (0,1,0) which looks like Z-component of the X,Y,Z basises - so it's kind of like matrix_world we get from the driver expression is transposed I guess.
Andrej added the
Type
Report
Priority
Normal
Status
Needs Triage
labels 2023-09-24 21:51:06 +02:00
Member

Can confirm that accessing ob.matrix_world seems to be the transpose of the result accessed from driver variable expression.

This is the result of ob.matrix_world, it seems that the python api here uses row-priority (The last column being the translation component), however when evaluated in driver expression, it seems to have became column priority.

图片

Can confirm that accessing `ob.matrix_world` seems to be the transpose of the result accessed from driver variable expression. This is the result of `ob.matrix_world`, it seems that the python api here uses row-priority (The last column being the translation component), however when evaluated in driver expression, it seems to have became column priority. ![图片](/attachments/01a0ad53-387d-4e7a-a75d-9e4a25c69ec0)
YimingWu added
Module
Python API
Status
Confirmed
and removed
Status
Needs Triage
labels 2023-09-25 06:59:19 +02:00
Member

Hi, due to the design of the property, for the moment, you could try following method:

  • Set var as matrix_world (the expression will show red at the moment)
  • Set expression as var[1][2], you will get the correct result a result that's consistent with what you get in script terminal.
Hi, due to the design of the property, for the moment, you could try following method: - Set `var` as `matrix_world` (the expression will show red at the moment) - Set expression as `var[1][2]`, you will get ~~the correct result~~ a result that's consistent with what you get in script terminal.
Author
Contributor

Hi, due to the design of the property, for the moment, you could try following method:

  • Set var as matrix_world (the expression will show red at the moment)
  • Set expression as var[1][2], you will get the correct result.

it works! I can even do var.col[2].y which could be a bit more readable in some cases.
Didn't know that I can set variables to more complex objects like matrices and not just scalar values.

> Hi, due to the design of the property, for the moment, you could try following method: > > - Set `var` as `matrix_world` (the expression will show red at the moment) > - Set expression as `var[1][2]`, you will get the correct result. it works! I can even do `var.col[2].y` which could be a bit more readable in some cases. Didn't know that I can set variables to more complex objects like matrices and not just scalar values.
Member

That's kind of a quirk of current design, which it will return a python object when it's not evaluated to a simple value, then it can be used in the expression above.

I'll mark this as a known issue, since people rarely drive stuff directly from matrix entries (like in your case, it can be done with dot products between object axis and global, which is a little bit more complicated), and due to the fact that the wrapping of the matrix is different so they will change row/column priority.

That's kind of a quirk of current design, which it will return a python object when it's not evaluated to a simple value, then it can be used in the expression above. I'll mark this as a known issue, since people rarely drive stuff directly from matrix entries (like in your case, it can be done with dot products between object axis and global, which is a little bit more complicated), and due to the fact that the wrapping of the matrix is different so they will change row/column priority.
YimingWu added
Status
Needs Info from Developers
Type
Known Issue
and removed
Status
Confirmed
Type
Report
labels 2023-09-27 04:46:01 +02:00
Author
Contributor

That's kind of a quirk of current design, which it will return a python object when it's not evaluated to a simple value, then it can be used in the expression above.

But why matrix is transposed though?

> That's kind of a quirk of current design, which it will return a python object when it's not evaluated to a simple value, then it can be used in the expression above. But why matrix is transposed though?
Member

But why matrix is transposed though?

Internally, Blender's matrices are column-major, but accessed through the Python API they are row-major. I think drivers run entirely in C code if possible for performance, but I guess those drivers running entirely in C forgot to account for the differences in matrix access.

> But why matrix is transposed though? Internally, Blender's matrices are column-major, but accessed through the Python API they are row-major. I think drivers run entirely in C code if possible for performance, but I guess those drivers running entirely in C forgot to account for the differences in matrix access.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
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#112816
No description provided.