Stateful behavior with ID.evaluated_get(..) and Object.to_mesh(preserve_all_data_layers=True, ..) #79965
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
6 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#79965
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?
Note
This issue has already been reported (https://developer.blender.org/T72581), but the task was closed due to missing information.
My attempt to provide the missing data didn't receive any attention, hence I am opening a new task now.
System Information
Operating system: Linux-5.8.0-sparky-amd64-x86_64-with-glibc2.29 64 Bits
Graphics card: Mesa DRI Intel(R) HD Graphics 3000 (SNB GT2) Intel Open Source Technology Center 3.3 (Core Profile) Mesa 20.1.5
Blender Version
Tested by original reporter: 2.80-2.82a2
Broken: version: 2.83.2, 2.83.3, 2.83.4, 2.90.0 Beta, branch: master, commit date: 2020-08-19 10:14, hash:
83c78529b9
, 2.91.0 Alpha, branch: master, commit date: 2020-08-19 22:55, hash:940b239ad4
Worked: -
Short description of error
We can use the following snippet to retrieve an evaluated mesh from an object while preserving all data layers.
This is useful e.g. in exporter scripts.
The problem arises when executing this code several times in a row. In that case the transformation of the mesh will 'stick' and then be applied multiple times.
It feels as if
to_mesh_clear()
didn't do anything and executingto_mesh(..)
a second time would return the same, already transformed, mesh again.This is contrary to the documentation of
to_mesh
:Exact steps for others to reproduce the error
Open the attached .blend file and follow the instruction on screen (Readme file is included).
The attached file contains a cube that is scaled by factor 2.
A custom Operator uses above code to retrieve the cube's mesh and then transform it by the cubes world matrix.
Next the coordinate of one Vertex is reported to Info.
Expected Result: (2, 2, 2) (modulo sign)
Actual Result: Coordinates double every time the Operator is executed
statefulBehaviour.blend
Added subscriber: @skatbude
Added subscriber: @stjerneidioten
I am currently writing an exporter and running into the exact same problem. I have to transform the meshes into a different coordinate system upon export, but the transform gets applied every time you run the exporter, even though I use
to_mesh_clear()
to clean up as per the documentation.Currently I have to set
preserve_all_data_layers=False
for it to work properly, but the problem is now that materials aren't updated properly, if I access them directly through the mesh they still contain deleted nodes from the node tree etc. so I have to use thematerial.original
to get the proper updated material. Which is temporary fix in my case as I only read from the material.I can provide more documentation/examples if needed. But what is currently uploaded seems sufficient to reproduce the bug.
Added subscriber: @lichtwerk
Changed status from 'Needs Triage' to: 'Confirmed'
Can confirm, will have a quick look.
Added subscriber: @Sergey
@Sergey: this seems to be your playground:
2f7711962a
963917e1b9
72a563cdee
Mind having a look (looks like a bug to me)?
Added subscriber: @brecht
Temporarily refers to the fact that the Mesh will not be preserved if the "source" (object on which
to_mesh
was used) is deleted or re-evaluated. Additionally, this mesh can not be assigned to an object which is in the main database, as its lifetime is shorter than the lifetime of the main database.The result mesh will reference data from the source object to keep memory under control. For example, if there are no modifiers the mesh will reference original vertices array and modifying them will modify the source as well.
@brecht, do you think it will be good idea to add an option to the
to_mesh()
to "de-reference" the result mesh so that it can be modified?If this was a C++ API, I would mark the return value of
to_mesh
asconst
and require the API user to make a copy. So maybemesh.copy()
can be made to work.Either way, what's unclear to me who would own the memory of such a copied or de-referenced mesh.
Am I missing something or we don't currently have
mesh.copy()
?The memory ownership is indeed an interesting topic. With
mesh.copy()
the ownership becomes more tricky.My initial idea was to make it so
Mesh
calculated byto_mesh()
will not useCD_REFERENCE
(optionally, for the cases when user intend to edit the mesh). The owner of the CD layers then the mesh itself, which will be freed byto_mesh_clear()
..copy()
is a available for all datablocks as far as I know.But I did not realize
CD_REFERENCE
was the issue.Referenced data layers are not supposed to ever be edited.
mesh.transform()
should callCustomData_duplicate_referenced_layer
before modifying the data layer.This issue was referenced by
3791dbea1e
Changed status from 'Confirmed' to: 'Resolved'