Change Matrix Representation and Access in Python to Conform with Standard Notation #29534
Labels
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
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#29534
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?
%%%It is often a point of confusion among new users that matrices don't appear to behave correctly within Blender. It is often cited that internally Blender stores matrices in column major format, while typically users are expecting row major format. However this does not fully explain the issues around matrices. For instance, if a user were to enter:
m=Matrix(((1, 2), (3, 4)))
They would receive the following upon inspecting m:
Matrix(((1.0, 2.0),
Which appears as expected and may be accessed as expected with m[row][column] notation. However, should a vector be entered, e.g.,
v=Vector((1, 1))
and then multiplied by the matrix, the incorrect result would be formed,
m*v == Vector((4.0, 6.0))
whereas the user would expect
m*v == Vector(( m- [x]- [x] * v- [x] + m- [x]- [x] * v- [x], m- [x]- [x] * v- [x] + m- [x]- [x] * v- [x] )) = Vector((3.0, 7.0))
This issue arises because the Python Representation -> Internal Data conversion is performed incorrectly for the representation shown in the console.
This patch rectifies the issue by ensuring that the conversion from Python representation to internal storage and back again accounts for the differing notations used by each. This also means that no internal functions for calulating matrix products, additions etc are modified, only the initialisation and representation of matrices in Python.
Thanks,
Andrew%%%
Changed status to: 'Open'
%%%While using the patched matrices, an error in matrix/vector multiplication was uncovered for non-square matrices.
m = Matrix(((1, 1, 1), (2, 2, 2)))
v = Vector((1, 1, 1))
m * v == Vector((3.0, 6.0, -12289734))
This is because resultant vector was not being sized properly but merely taking its size from the input vector which is bad. It should have size == mat1->col_size
This needs fixing.%%%
%%%I don't think this reasoning is correct. Creating and printing matrices uses a list of columns. So the rows are (1, 3) and (2, 4), and a multiplication with vector (1, 1) gives (4, 6).%%%
%%%I've attached a new patch which accounts for recent changes in mathutils. This patch also rectifies the problem with matrix/vector multiplication noted above. In addition, it also wraps the translation component of a matrix into matrix.translation but only for 4x4 matrices. This is especially useful for scripts that originally used matrix- [x] to access the translation component.
Thanks,
Andrew%%%
%%%Small fix for most recent SVN%%%
%%%Final patch which is separated from some fixes already applied by Campbell.%%%
%%%applied, closing.%%%
Changed status from 'Open' to: 'Archived'