Regression: Python: Objects loaded from blend files have default matrices before depsgraph update #119348

Closed
opened 2024-03-11 22:14:01 +01:00 by Vitalii-2 · 11 comments

Seems like that should be a separate report. Indeed, when appending objects, the transforms won't be calculated until there's a depsgraph update.

Originally posted by @HooglyBoogly in #119250 (comment)

Blender Version
Broken: version: 4.2.0 Alpha, branch: main, commit date: 2024-03-10 18:36, hash: 703353b5dafc
Worked: (newest version of Blender that worked as expected)

Caused by 1c0f374ec3

Short description of error
When loading objects from blend files with python (bpy.data.libraries.load), loaded objects would have default value for world and local matrices instead of values stored in blend file.

Exact steps for others to reproduce the error
Place asset.blend and script.blend into same folder. Open script.blend and run the script. The script loads an object from asset.blend file and compares world matrix of an object before and after depsgraph update.
On 4.2.0 alpha this raises an exception as matrices don't match
On previous versions no exception is raised.

There is also a forward compatibility issue, as object loaded from blend files of 4.2 by older version of blender would also have default matrices before depsgraph update.

Seems like that should be a separate report. Indeed, when appending objects, the transforms won't be calculated until there's a depsgraph update. _Originally posted by @HooglyBoogly in https://projects.blender.org/blender/blender/issues/119250#issuecomment-1143815_ **Blender Version** Broken: version: 4.2.0 Alpha, branch: main, commit date: 2024-03-10 18:36, hash: `703353b5dafc` Worked: (newest version of Blender that worked as expected) Caused by 1c0f374ec3 **Short description of error** When loading objects from blend files with python (`bpy.data.libraries.load`), loaded objects would have default value for world and local matrices instead of values stored in blend file. **Exact steps for others to reproduce the error** Place asset.blend and script.blend into same folder. Open script.blend and run the script. The script loads an object from asset.blend file and compares world matrix of an object before and after depsgraph update. On 4.2.0 alpha this raises an exception as matrices don't match On previous versions no exception is raised. There is also a forward compatibility issue, as object loaded from blend files of 4.2 by older version of blender would also have default matrices before depsgraph update.
Vitalii-2 added the
Priority
Normal
Type
Report
Status
Needs Triage
labels 2024-03-11 22:14:02 +01:00
Member

Can confirm

Can confirm
Philipp Oeser added
Status
Confirmed
and removed
Status
Needs Triage
labels 2024-03-12 11:40:58 +01:00
Philipp Oeser added this to the 4.2 LTS milestone 2024-03-12 11:41:48 +01:00
Philipp Oeser added
Priority
High
Module
Modeling
and removed
Priority
Normal
labels 2024-03-12 11:42:25 +01:00
Member

CC @HooglyBoogly (just noting it is only an issue in 4.2 -- so not relevant for next weeks release)

CC @HooglyBoogly (just noting it is only an issue in 4.2 -- so not relevant for next weeks release)
Philipp Oeser changed title from Regrssion: Python: Objects loaded from blend files have default matrices before depsgraph update to Regression: Python: Objects loaded from blend files have default matrices before depsgraph update 2024-03-12 12:27:19 +01:00

What depends on these matrices being set immediately after appending?

In general, due to parenting, animation and constraints these matrices could already be mismatched with the actual object transform in the new blend file. Previously they just happened to be initialized to the value of the last evaluated frame in other blend file.

Depending on why and if this is important, possible options are:

  • Initialize based on location/rotation/scale without any parenting, animation or constraints
  • Restore old code to save them in the .blend file
  • Do nothing
What depends on these matrices being set immediately after appending? In general, due to parenting, animation and constraints these matrices could already be mismatched with the actual object transform in the new blend file. Previously they just happened to be initialized to the value of the last evaluated frame in other blend file. Depending on why and if this is important, possible options are: * Initialize based on location/rotation/scale without any parenting, animation or constraints * Restore old code to save them in the .blend file * Do nothing
Brecht Van Lommel removed the
Interest
Compositing
label 2024-03-21 15:09:10 +01:00
Author

Outside of python scripts that process object transforms before depsgraph update, the part of blender that relies on those matrices not being degenerate is bpy.ops.object.add_named() used to place objects from outliner into scene. Because appended object has world matrix with all 0, the the operator creates an object with no rotation and 0 for scale.

With animation transform of appended object not likely being valid, I'm voting on initialization to base transform. Maybe with parent if parent relationship got preserved on append?

Outside of python scripts that process object transforms before depsgraph update, the part of blender that relies on those matrices not being degenerate is `bpy.ops.object.add_named()` used to place objects from outliner into scene. Because appended object has world matrix with all 0, the the operator creates an object with no rotation and 0 for scale. With animation transform of appended object not likely being valid, I'm voting on initialization to base transform. Maybe with parent if parent relationship got preserved on append?

The code that becomes broken for me is setting an object's matrix_parent_inverse from the parent object's matrix_world.inverted() as it is now all zeros and it gives ValueError: Matrix.invert(ed): matrix does not have an inverse or the default matrix that is incorrect.

Blender 4
image

Blender 4.2
image

The code that becomes broken for me is setting an object's `matrix_parent_inverse` from the parent object's `matrix_world.inverted()` as it is now all zeros and it gives `ValueError: Matrix.invert(ed): matrix does not have an inverse` or the default matrix that is incorrect. Blender 4 ![image](/attachments/1ef0d983-ddaf-479a-a273-713b6931bdc8) Blender 4.2 ![image](/attachments/71825183-38a8-435a-8849-9c0b129b107c)
286 KiB
256 KiB

place objects from outliner into scene [...] object has world matrix with all 0

With the 4.2.0 Alpha, branch: main, commit date: 2024-03-21 22:18, hash: c61ecf1f4094 it is now the default one. So if the original scale of the object was 3 you will get 1.

> place objects from outliner into scene [...] object has world matrix with all 0 With the `4.2.0 Alpha, branch: main, commit date: 2024-03-21 22:18, hash: c61ecf1f4094` it is now the default one. So if the original scale of the object was 3 you will get 1.
Member

Given the options outlined by Brecht above, I'd argue for "Do nothing". The matrices when appending the object before depsgraph evaluation should be identity matrices. Some reasoning:

  • Arguably the previous behavior was never purposeful, it just happened because all runtime data was written to files.
  • It would be good to avoid adding object-specific code to data-block append/link
  • Initializing the matrices based on loc/rot/scale may have some performance cost that we wouldn't be able to fix
  • The new behavior clarifies the use and implementation of the structs, and is more self-consistent.
Given the options outlined by Brecht above, I'd argue for "Do nothing". The matrices when appending the object before depsgraph evaluation should be identity matrices. Some reasoning: - Arguably the previous behavior was never purposeful, it just happened because all runtime data was written to files. - It would be good to avoid adding object-specific code to data-block append/link - Initializing the matrices based on loc/rot/scale may have some performance cost that we wouldn't be able to fix - The new behavior clarifies the use and implementation of the structs, and is more self-consistent.

Agree with @HooglyBoogly for current situation. If scripts depend on runtime evaluated data, then they should ensure that the data is evaluated.

We do have a forward compatibility issue here though, in that when opening a 4.2 blendfile in Blender 4.1 or older, these matrices will be initialized to null (and not identity) by the DNA reading code.

The only way to fix this issue I can think of currently is to keep writing dummy identity matrices in Object data for the time being (until we reach 5.0), to avoid getting invalid transform matrices in older versions... Not sure how critical this fix is though.

Agree with @HooglyBoogly for current situation. If scripts depend on runtime evaluated data, then they should ensure that the data is evaluated. We do have a forward compatibility issue here though, in that when opening a 4.2 blendfile in Blender 4.1 or older, these matrices will be initialized to null (and _not_ identity) by the DNA reading code. The only way to fix this issue I can think of currently is to keep writing dummy identity matrices in Object data for the time being (until we reach 5.0), to avoid getting invalid transform matrices in older versions... Not sure how critical this fix is though.
Member

We do have a forward compatibility issue here though, in that when opening a 4.2 blendfile in Blender 4.1 or older, these matrices will be initialized to null (and not identity) by the DNA reading code.

I think we can handle that with versioning code that checks if the file is from the future and initializes identity matrices in that case. We can patch 4.1 and 3.6 anyway. Given the non-critical aspect of the problem (data is properly filled in as soon as the object is evaluated), I'd think that should be enough.

>We do have a forward compatibility issue here though, in that when opening a 4.2 blendfile in Blender 4.1 or older, these matrices will be initialized to null (and not identity) by the DNA reading code. I think we can handle that with versioning code that checks if the file is from the future and initializes identity matrices in that case. We can patch 4.1 and 3.6 anyway. Given the non-critical aspect of the problem (data is properly filled in as soon as the object is evaluated), I'd think that should be enough.
Bastien Montagne modified the milestone from 4.2 LTS to 4.1 2024-04-15 11:31:54 +02:00

@HooglyBoogly if this is to be fixed that way, then we need a PR for 4.1.1 within the coming hours. ;)

@HooglyBoogly if this is to be fixed that way, then we need a PR for 4.1.1 within the coming hours. ;)
Member

4.1 has been changed to set the identity matrix on file load. There's nothing more to do here, so I'll close this task.

4.1 has been changed to set the identity matrix on file load. There's nothing more to do here, so I'll close this task.
Blender Bot added
Status
Archived
and removed
Status
Confirmed
labels 2024-04-15 16:37:24 +02:00
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
6 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#119348
No description provided.