Regression: Python: World matrix for newly created objects is not identity #119250

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

System Information
Operating system: Windows-10-10.0.19045-SP0 64 Bits
Graphics card: NVIDIA GeForce RTX 3090/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 551.76

Blender Version
Broken: version: 4.2.0 Alpha, branch: main, commit date: 2024-02-23 23:00, hash: 06d3627c4398
Worked: version: 4.2.0 Alpha, branch: main, commit date: 2024-02-09 09:37, hash: e20b2d2fb947

Short description of error
Newly crated objects via python (bpy.data.objects.new() ) have degenerate (all 0) world matrix matrix_world instead of identity.

Exact steps for others to reproduce the error
Run script in the attached file. The script creates new object and compares basis and world matrices to identity.
On 4.2.0alpha script raises and exception when comparing world matrix to identity.
On older stable versions no exceptions are raised.

**System Information** Operating system: Windows-10-10.0.19045-SP0 64 Bits Graphics card: NVIDIA GeForce RTX 3090/PCIe/SSE2 NVIDIA Corporation 4.6.0 NVIDIA 551.76 **Blender Version** Broken: version: 4.2.0 Alpha, branch: main, commit date: 2024-02-23 23:00, hash: `06d3627c4398` Worked: version: 4.2.0 Alpha, branch: main, commit date: 2024-02-09 09:37, hash: `e20b2d2fb947` **Short description of error** Newly crated objects via python (`bpy.data.objects.new()` ) have degenerate (all 0) world matrix `matrix_world` instead of identity. **Exact steps for others to reproduce the error** Run script in the attached file. The script creates new object and compares basis and world matrices to identity. On 4.2.0alpha script raises and exception when comparing world matrix to identity. On older stable versions no exceptions are raised.
Vitalii-2 added the
Status
Needs Triage
Severity
Normal
Type
Report
labels 2024-03-09 14:21:00 +01:00
Iliya Katushenock changed title from Regression, Python: world matrix for newly created objects is not identity to Regression: Python: World matrix for newly created objects is not identity 2024-03-09 14:30:51 +01:00
Iliya Katushenock added the
Interest
Python API
label 2024-03-09 14:30:57 +01:00

import subprocess

def get_python_expr(func, *args, **kwargs):
    """ Does not work with `shell=True`. """

    import inspect
    import textwrap
    import json

    expr = [textwrap.dedent(inspect.getsource(func))]

    args_json = repr(json.dumps(args))
    kwargs_json = repr(json.dumps(kwargs))

    expr.append('import json')
    expr.append(f'args = json.loads({args_json})')
    expr.append(f'kwargs = json.loads({kwargs_json})')
    expr.append(f'{func.__name__}(*args, **kwargs)')

    return '\n'.join(expr)


def import_model(filepath):
    import bpy

    bpy.data.batch_remove(bpy.data.objects)

    with bpy.data.libraries.load(filepath = filepath) as (data_from, data_to):
        data_to.objects = data_from.objects

    for object in bpy.data.objects:
        print(object.matrix_world)


blender_exe = r'C:\blender\blender-4.2.0-alpha+main.196cd48aad53-windows.amd64-release\blender.exe'
filepath = r'D:\Desktop\city_hangar_test.blend'

command = [blender_exe, '-b', '--factory-startup', '-noaudio', '--python-expr', get_python_expr(import_model, filepath)]
subprocess.run(command, check = True, text = True)

command = ['blender', '-b', '--factory-startup', '-noaudio', '--python-expr', get_python_expr(import_model, filepath)]
subprocess.run(command, check = True, text = True)
Blender 4.2.0 Alpha (hash 196cd48aad53 built 2024-03-09 02:04:44)
<Matrix 4x4 (0.0000, 0.0000, 0.0000, 0.0000)
            (0.0000, 0.0000, 0.0000, 0.0000)
            (0.0000, 0.0000, 0.0000, 0.0000)
            (0.0000, 0.0000, 0.0000, 0.0000)>
<Matrix 4x4 (0.0000, 0.0000, 0.0000, 0.0000)
            (0.0000, 0.0000, 0.0000, 0.0000)
            (0.0000, 0.0000, 0.0000, 0.0000)
            (0.0000, 0.0000, 0.0000, 0.0000)>
<Matrix 4x4 (0.0000, 0.0000, 0.0000, 0.0000)
            (0.0000, 0.0000, 0.0000, 0.0000)
            (0.0000, 0.0000, 0.0000, 0.0000)
            (0.0000, 0.0000, 0.0000, 0.0000)>
<Matrix 4x4 (0.0000, 0.0000, 0.0000, 0.0000)
            (0.0000, 0.0000, 0.0000, 0.0000)
            (0.0000, 0.0000, 0.0000, 0.0000)
            (0.0000, 0.0000, 0.0000, 0.0000)>

Blender quit
Blender 3.1.2 (hash cc66d1020c3b built 2022-03-31 23:39:57)
<Matrix 4x4 (1.2342, 0.0000, 0.0000,  0.0325)
            (0.0000, 1.2342, 0.0000, -0.2509)
            (0.0000, 0.0000, 1.2342, -0.0213)
            (0.0000, 0.0000, 0.0000,  1.0000)>
<Matrix 4x4 (1.2342, 0.0000, 0.0000,  0.0325)
            (0.0000, 1.2342, 0.0000, -0.2509)
            (0.0000, 0.0000, 1.2342, -0.0213)
            (0.0000, 0.0000, 0.0000,  1.0000)>
<Matrix 4x4 (0.1274, 0.0000, 0.0000, -1.2274)
            (0.0000, 0.1274, 0.0000,  0.2705)
            (0.0000, 0.0000, 0.1274,  1.1341)
            (0.0000, 0.0000, 0.0000,  1.0000)>
<Matrix 4x4 (3.5520, 0.0000, 0.0000, -0.0264)
            (0.0000, 3.5520, 0.0000, -0.0000)
            (0.0000, 0.0000, 3.5520,  0.0132)
            (0.0000, 0.0000, 0.0000,  1.0000)>

Blender quit
```python import subprocess def get_python_expr(func, *args, **kwargs): """ Does not work with `shell=True`. """ import inspect import textwrap import json expr = [textwrap.dedent(inspect.getsource(func))] args_json = repr(json.dumps(args)) kwargs_json = repr(json.dumps(kwargs)) expr.append('import json') expr.append(f'args = json.loads({args_json})') expr.append(f'kwargs = json.loads({kwargs_json})') expr.append(f'{func.__name__}(*args, **kwargs)') return '\n'.join(expr) def import_model(filepath): import bpy bpy.data.batch_remove(bpy.data.objects) with bpy.data.libraries.load(filepath = filepath) as (data_from, data_to): data_to.objects = data_from.objects for object in bpy.data.objects: print(object.matrix_world) blender_exe = r'C:\blender\blender-4.2.0-alpha+main.196cd48aad53-windows.amd64-release\blender.exe' filepath = r'D:\Desktop\city_hangar_test.blend' command = [blender_exe, '-b', '--factory-startup', '-noaudio', '--python-expr', get_python_expr(import_model, filepath)] subprocess.run(command, check = True, text = True) command = ['blender', '-b', '--factory-startup', '-noaudio', '--python-expr', get_python_expr(import_model, filepath)] subprocess.run(command, check = True, text = True) ``` ```cmd Blender 4.2.0 Alpha (hash 196cd48aad53 built 2024-03-09 02:04:44) <Matrix 4x4 (0.0000, 0.0000, 0.0000, 0.0000) (0.0000, 0.0000, 0.0000, 0.0000) (0.0000, 0.0000, 0.0000, 0.0000) (0.0000, 0.0000, 0.0000, 0.0000)> <Matrix 4x4 (0.0000, 0.0000, 0.0000, 0.0000) (0.0000, 0.0000, 0.0000, 0.0000) (0.0000, 0.0000, 0.0000, 0.0000) (0.0000, 0.0000, 0.0000, 0.0000)> <Matrix 4x4 (0.0000, 0.0000, 0.0000, 0.0000) (0.0000, 0.0000, 0.0000, 0.0000) (0.0000, 0.0000, 0.0000, 0.0000) (0.0000, 0.0000, 0.0000, 0.0000)> <Matrix 4x4 (0.0000, 0.0000, 0.0000, 0.0000) (0.0000, 0.0000, 0.0000, 0.0000) (0.0000, 0.0000, 0.0000, 0.0000) (0.0000, 0.0000, 0.0000, 0.0000)> Blender quit Blender 3.1.2 (hash cc66d1020c3b built 2022-03-31 23:39:57) <Matrix 4x4 (1.2342, 0.0000, 0.0000, 0.0325) (0.0000, 1.2342, 0.0000, -0.2509) (0.0000, 0.0000, 1.2342, -0.0213) (0.0000, 0.0000, 0.0000, 1.0000)> <Matrix 4x4 (1.2342, 0.0000, 0.0000, 0.0325) (0.0000, 1.2342, 0.0000, -0.2509) (0.0000, 0.0000, 1.2342, -0.0213) (0.0000, 0.0000, 0.0000, 1.0000)> <Matrix 4x4 (0.1274, 0.0000, 0.0000, -1.2274) (0.0000, 0.1274, 0.0000, 0.2705) (0.0000, 0.0000, 0.1274, 1.1341) (0.0000, 0.0000, 0.0000, 1.0000)> <Matrix 4x4 (3.5520, 0.0000, 0.0000, -0.0264) (0.0000, 3.5520, 0.0000, -0.0000) (0.0000, 0.0000, 3.5520, 0.0132) (0.0000, 0.0000, 0.0000, 1.0000)> Blender quit ```
Contributor

I can confirm that git bisect shows that 1c0f374ec3 is the first bad commit.

I can confirm that git bisect shows that 1c0f374ec3e3 is the first bad commit.
Iliya Katushenock added
Module
Modeling
Interest
Python API
and removed
Module
Python API
labels 2024-03-10 17:15:23 +01:00
Author

I can confirm that git bisect shows that 1c0f374ec3 is the first bad commit.

so what I understood from commit's description is that blender no longer updates object matrices outside of depsgraph updates, requiring script writers linking object into any scene and forcing an update (which is rather heavy handed) or calculating valid matrix manually, which can very complicated if it's a linked object with constraints

> I can confirm that git bisect shows that 1c0f374ec3e3 is the first bad commit. so what I understood from commit's description is that blender no longer updates object matrices outside of depsgraph updates, requiring script writers linking object into any scene and forcing an update (which is rather heavy handed) or calculating valid matrix manually, which can very complicated if it's a linked object with constraints

CC @HooglyBoogly, this looks like a release blocker.

@lichtwerk @mod_moder I don't know if it's a formal policy, but for a high priority bug I think it's important to always CC the relevant developer, especially this close to the release.

CC @HooglyBoogly, this looks like a release blocker. @lichtwerk @mod_moder I don't know if it's a formal policy, but for a high priority bug I think it's important to always CC the relevant developer, especially this close to the release.
Hans Goudey self-assigned this 2024-03-11 14:11:38 +01:00
Member

@brecht @mod_moder : we do have it in the https://developer.blender.org/docs/handbook/bug_reports/triaging_playbook/ (under "Advanced Actions")

Contact the commit author and/or subscribe the author in the issue to raise awareness.

If the issue was nailed down to a recent faulty commit, contact the commit author and/or subscribe the author in the issue to raise awareness

@brecht @mod_moder : we do have it in the https://developer.blender.org/docs/handbook/bug_reports/triaging_playbook/ (under "Advanced Actions") >Contact the commit author and/or subscribe the author in the issue to raise awareness. >If the issue was nailed down to a recent faulty commit, contact the commit author and/or subscribe the author in the issue to raise awareness
Member

CC @HooglyBoogly, this looks like a release blocker.

To be clear, this is only a problem in main, not the 4.1 release branch.

>CC @HooglyBoogly, this looks like a release blocker. To be clear, this is only a problem in main, not the 4.1 release branch.
Hans Goudey added
Type
Bug
and removed
Type
Report
labels 2024-03-11 20:34:26 +01:00
Blender Bot added
Status
Resolved
and removed
Status
Confirmed
labels 2024-03-11 20:35:14 +01:00
Author

while that does address issue for new objects. it doesn't address issue of objects loaded from blend files via python to have default matrices prior update (reported by first comment), which shares the root cause. or would that require separate issue?

while that does address issue for new objects. it doesn't address issue of objects loaded from blend files via python to have default matrices prior update (reported by first comment), which shares the root cause. or would that require separate issue?
Member

Seems like that should be a separate report. Indeed, when appending objects, the transforms won't be calculated until there's a 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.

@HooglyBoogly This may have caused this error (pic below), I fixed it in 39f3ea4ab0

@HooglyBoogly This may have caused this error (pic below), I fixed it in https://projects.blender.org/blender/blender-addons/commit/39f3ea4ab0c18c85b8643d3be32161a2654e1fbd
Author

@HooglyBoogly This may have caused this error (pic below), I fixed it in 39f3ea4ab0

c0f374ec3e3 made blender not to calculate world and local matrices before depsgraph update (which was all 0, before commit that resolved this issue), so I'm fairly certain that it's the case.

but I can't help but wonder as to why import script doesn't read whole world space matrix from fbx and doesn't update matrix_world which would force blender to recalculate matrix_local?

> @HooglyBoogly This may have caused this error (pic below), I fixed it in https://projects.blender.org/blender/blender-addons/commit/39f3ea4ab0c18c85b8643d3be32161a2654e1fbd [c0f374ec3e3](https://projects.blender.org/blender/blender/commit/1c0f374ec3e3) made blender not to calculate world and local matrices before depsgraph update (which was all 0, before commit that resolved this issue), so I'm fairly certain that it's the case. but I can't help but wonder as to why import script doesn't read whole world space matrix from fbx and doesn't update `matrix_world` which would force blender to recalculate `matrix_local`?
Member

In Blender these matrices are calculated dynamically based on the original location, rotation, and scale, and various procedural effects like constraints, drivers, and the animation system. They aren't directly write-able.

In Blender these matrices are calculated dynamically based on the original location, rotation, and scale, and various procedural effects like constraints, drivers, and the animation system. They aren't directly write-able.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
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
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
7 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#119250
No description provided.