Python: Add support for @ infix operator matrix multiplication #56276
Labels
No Label
Interest
Animation & Rigging
Interest
Blender Cloud
Interest
Collada
Interest
Core
Interest
Documentation
Interest
Eevee & Viewport
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
Import and Export
Interest
Modeling
Interest
Modifiers
Interest
Nodes & Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds, Tests & Devices
Interest
Python API
Interest
Rendering & Cycles
Interest
Sculpt, Paint & Texture
Interest
Translations
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Meta
Good First Issue
Meta
Papercut
Module
Add-ons (BF-Blender)
Module
Add-ons (Community)
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
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender-addons#56276
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This subtask is to add support for the @ infix operator in python for matrix multiplication. The following combinations are permitted:
The subtask also covers element-wise multiplication but will be disabled. This will allow current usage of * for matrix multiplication in scripts to be identified and transitioned before the change to element-wise multiplication is introduced. A notable exception to this is that constant * matrix/vector/quaternion (and vice versa) is still permitted. The combinations to be supported are:
Added subscribers: @truman, @brita, @NumesSanguis-3, @JacquesLucke, @intrah, @gfxcoder, @vitorbalbio-3, @nathanvollmer, @monique, @Jeroen-Bakker, @lvxejay, @jta, @bliblubli, @Januz, @satishgoda1, @KerimBorchaev, @RayMairlot, @Ko, @Sergey, @VukGardasevic, @mano-wii, @JamesCrowther, @StephenSwaney, @jasperge-2, @dfelinto, @BrianSavery, @dr.sybren, @tetha.z, @MikeErwin, @BrendonMurphy, @mont29, @ideasman42
Not sure why that’s assigned to me… Guess @ideasman42 will want to check on that?
I suggest to leave this one out, since Blender uses column vector convention. Having it, could confuse people as to the order of multiplication of the matrices.
Vector @ Matrix (vector interpreted as row vector)
This one usually goes component-wise in shading languages.
Vector @ Vector (dot product)
I think it can be potentially confusing which operation it does ( I would write dot or cross explicitly always and for component-wise I wouldn't even know what to write, since that's usually the default.) You wouln't use vector-vector multiplication inline with matrix multiplications of transform code.
@brita / @truman, what about following numpy conventions for cases which are disputable?
@brita / @ideasman42
As per review comments on D3587, I've also implemented:
matrix @= matrix
matrix *= matrix/float
quat @= quat
quat *= quat/float
This seems like a reasonable approach. See below code, both numpy and mathutils produce the dot product for
vector @ vector
. Eventually element-wise multiplication will be exposed usingvector * vector
which matches numpy.The current API allows for
matrix * vector
andvector * matrix
, so it shouldn't introduce any additional confusion. Both are valid in numpy and produce the same results as mathutils (see below). Are we happy to maintain the status quo and allow both?If at least vector * vector doesn't do a dot product, I'm happy ^^
I wasn't aware of the @ possibility and I am also not familiar with numpy, but it definitely sounds like a good idea to follow a similar convention :)
Changed status from 'Open' to: 'Resolved'
Implemented in blender/blender@aa5a96430e
Note that this is now enabled in master (for 2.90 release).