Regression: Copy of eval mesh may keep shape keys #109327

Open
opened 2023-06-24 18:25:10 +02:00 by Thomas Barlow · 1 comment
Member

System Information
Operating system: Windows-10-10.0.19045-SP0 64 Bits
Graphics card: NVIDIA GeForce GTX 1070 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 531.41

Blender Version
Broken: version: 4.0.0 Alpha, branch: main, commit date: 2023-06-19 17:26, hash: cedec09d0594
Worked: sort of 2.79 (the API was a bit different). And in 2.90.1, only the first buggy scenario (see below) is present

Short description of error
Calling Object.to_mesh() on an evaluated mesh keeps the shape keys in some circumstances, even though the shape keys and modifiers have been applied to the mesh.

There are two buggy scenarios this can create:

  1. A mesh whereby the mesh vertex positions do not match its reference ('Basis') shape key positions. This is a fairly common unusual state (there are a number other ways to get into this state) which causes issues with creating new shape keys with from_mix=False and exporting with most exporters that support exporting shape keys (#98890).
  2. A mesh whereby the number of mesh vertices does not match the number of shape key 'vertices'/data. This is a particularly buggy state that should never happen. Notably, this does not occur in 2.90.1 and earlier, and from 2.91.0 to 3.3.x it also happens to meshes created by Object.data.copy().

In both cases, simply removing all the shape keys will restore the meshes to their expected states because both the shape keys and modifiers have been applied to the mesh vertices as expected.

It's not clear which of Object.to_mesh() or Mesh.copy() is at fault for not removing the shape keys.

The API in 2.79 is a little different to 2.80+, since there is no depsgraph, you choose with the function arguments whether or not to apply modifiers:
When using apply_modifiers=True, the new mesh has no shape keys as expected.
When using apply_modifiers=False, the new mesh retains its shape keys as expected.
Additionally, in 2.79, Object.to_mesh() creates a new Mesh data-block in bpy.data.meshes rather than creating a temporary Mesh owned by the Object.

Exact steps for others to reproduce the error
Scenario 1 (mesh vertex positions do not match reference shape key positions)

Using the attached .blend:

  1. Open the attached .blend
  2. Run the script in the Text Editor
  3. Select one of the magenta meshes
  4. Set the value of the shape keys to 0.0
  5. Observe that the state of the mesh with all shape keys set to 0.0 appears to be the original mesh with all shape keys set to 0.0
  6. Remove all the shape keys
  7. Observe that the state of the mesh changes to the appearance of the original mesh with its shape keys applied

Step-by-step:

  1. Create a mesh Object
  2. Add a shape key (other than the 'Basis')
  3. Enter Edit Mode
  4. Modify the shape key so that it noticeably moves the mesh
  5. Exit Edit Mode
  6. Change the Value of the shape key to 1.0
  7. Run in the Python Console:
    1. depsgraph = C.evaluated_depsgraph_get()
    2. obj_eval = C.object.evaluated_get(depsgraph)
    3. temp_mesh = obj_eval.to_mesh(preserve_all_data_layers=True, depsgraph=depsgraph)
    4. new_mesh = temp_mesh.copy()
    5. C.object.data = new_mesh
  8. Observe that the new mesh has shape keys
  9. Set the value of the shape keys to 0.0
  10. Observe that the state of the mesh with all shape keys set to 0.0 appears to be the original mesh with all shape keys set to 0.0
  11. Remove all the shape keys
  12. Observe that the state of the mesh changes to the appearance of the original mesh with its shape keys applied

Scenario 2 (number of mesh vertices does not match number of shape key 'vertices'/data)
Using the attached .blend:

  1. Open the attached .blend
  2. Run the script in the Text Editor
  3. Select one of the black meshes
  4. Add a new shape key
  5. Change the Value of the new shape key
  6. Observe the mesh going crazy/exploding as the Value changes
  7. Remove all the shape keys
  8. Observe that the state of the mesh changes to the appearance of the original mesh with its shape keys and modifiers applied

Step-by-step:

  1. Create a mesh Object
  2. Add a shape key (other than the 'Basis')
  3. Enter Edit Mode
  4. Modify the shape key so that it noticeably moves the mesh
  5. Exit Edit Mode
  6. Change the Value of the shape key to 1.0
  7. Add an Array modifier with default settings to the Object
  8. Run in the Python Console:
    1. depsgraph = C.evaluated_depsgraph_get()
    2. obj_eval = C.object.evaluated_get(depsgraph)
    3. temp_mesh = obj_eval.to_mesh(preserve_all_data_layers=False, depsgraph=depsgraph) # Note: False this time
    4. new_mesh = temp_mesh.copy()
    5. C.object.data = new_mesh
  9. Remove the Array modifier from the Object to avoid confusion
  10. Observe that the new mesh has shape keys
  11. Add a new shape key
  12. Change the Value of the new shape key
  13. Observe the mesh going crazy/exploding as the Value changes
  14. Remove all the shape keys
  15. Observe that the state of the mesh changes to the appearance of the original mesh with its shape keys and modifiers applied

Attached is a .blend (authored in 2.80) that has a script and three Objects that go over different cases (has modifiers/no modifiers/has modifiers but they're disabled) or creating meshes from evaluated Objects with Object.to_mesh as well as comparing the behaviour of the similar BlendDataMeshes.new_from_object function and Mesh.copy()

These are the results of running the script in the attached .blend in 4.0.0a:
image

**System Information** Operating system: Windows-10-10.0.19045-SP0 64 Bits Graphics card: NVIDIA GeForce GTX 1070 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 531.41 **Blender Version** Broken: version: 4.0.0 Alpha, branch: main, commit date: 2023-06-19 17:26, hash: `cedec09d0594` Worked: sort of 2.79 (the API was a bit different). And in 2.90.1, only the first buggy scenario (see below) is present **Short description of error** Calling `Object.to_mesh()` on an evaluated mesh keeps the shape keys in some circumstances, even though the shape keys and modifiers have been applied to the mesh. There are two buggy scenarios this can create: 1. A mesh whereby the mesh vertex positions do not match its reference ('Basis') shape key positions. This is a fairly common unusual state (there are a number other ways to get into this state) which causes issues with creating new shape keys with `from_mix=False` and exporting with most exporters that support exporting shape keys (#98890). 2. A mesh whereby the number of mesh vertices does not match the number of shape key 'vertices'/data. This is a particularly buggy state that should never happen. Notably, this does not occur in 2.90.1 and earlier, and from 2.91.0 to 3.3.x it also happens to meshes created by `Object.data.copy()`. In both cases, simply removing all the shape keys will restore the meshes to their expected states because both the shape keys and modifiers have been applied to the mesh vertices as expected. It's not clear which of `Object.to_mesh()` or `Mesh.copy()` is at fault for not removing the shape keys. The API in 2.79 is a little different to 2.80+, since there is no depsgraph, you choose with the function arguments whether or not to apply modifiers: When using apply_modifiers=True, the new mesh has no shape keys as expected. When using apply_modifiers=False, the new mesh retains its shape keys as expected. Additionally, in 2.79, `Object.to_mesh()` creates a new Mesh data-block in bpy.data.meshes rather than creating a temporary Mesh owned by the Object. **Exact steps for others to reproduce the error** Scenario 1 (mesh vertex positions do not match reference shape key positions) Using the attached .blend: 1. Open the attached .blend 1. Run the script in the Text Editor 1. Select one of the magenta meshes 1. Set the value of the shape keys to 0.0 1. Observe that the state of the mesh with all shape keys set to 0.0 appears to be the original mesh with all shape keys set to 0.0 1. Remove all the shape keys 1. Observe that the state of the mesh changes to the appearance of the original mesh with its shape keys applied Step-by-step: 1. Create a mesh Object 1. Add a shape key (other than the 'Basis') 1. Enter Edit Mode 1. Modify the shape key so that it noticeably moves the mesh 1. Exit Edit Mode 1. Change the Value of the shape key to 1.0 1. Run in the Python Console: 1. `depsgraph = C.evaluated_depsgraph_get()` 1. `obj_eval = C.object.evaluated_get(depsgraph)` 1. `temp_mesh = obj_eval.to_mesh(preserve_all_data_layers=True, depsgraph=depsgraph)` 1. `new_mesh = temp_mesh.copy()` 1. `C.object.data = new_mesh` 1. Observe that the new mesh has shape keys 1. Set the value of the shape keys to 0.0 1. Observe that the state of the mesh with all shape keys set to 0.0 appears to be the original mesh with all shape keys set to 0.0 1. Remove all the shape keys 1. Observe that the state of the mesh changes to the appearance of the original mesh with its shape keys applied Scenario 2 (number of mesh vertices does not match number of shape key 'vertices'/data) Using the attached .blend: 1. Open the attached .blend 1. Run the script in the Text Editor 1. Select one of the black meshes 1. Add a new shape key 1. Change the Value of the new shape key 1. Observe the mesh going crazy/exploding as the Value changes 1. Remove all the shape keys 1. Observe that the state of the mesh changes to the appearance of the original mesh with its shape keys and modifiers applied Step-by-step: 1. Create a mesh Object 1. Add a shape key (other than the 'Basis') 1. Enter Edit Mode 1. Modify the shape key so that it noticeably moves the mesh 1. Exit Edit Mode 1. Change the Value of the shape key to 1.0 1. Add an Array modifier with default settings to the Object 1. Run in the Python Console: 1. `depsgraph = C.evaluated_depsgraph_get()` 1. `obj_eval = C.object.evaluated_get(depsgraph)` 1. `temp_mesh = obj_eval.to_mesh(preserve_all_data_layers=False, depsgraph=depsgraph)` # Note: False this time 1. `new_mesh = temp_mesh.copy()` 1. `C.object.data = new_mesh` 1. Remove the Array modifier from the Object to avoid confusion 1. Observe that the new mesh has shape keys 1. Add a new shape key 1. Change the Value of the new shape key 1. Observe the mesh going crazy/exploding as the Value changes 1. Remove all the shape keys 1. Observe that the state of the mesh changes to the appearance of the original mesh with its shape keys and modifiers applied Attached is a .blend (authored in 2.80) that has a script and three Objects that go over different cases (has modifiers/no modifiers/has modifiers but they're disabled) or creating meshes from evaluated Objects with `Object.to_mesh` as well as comparing the behaviour of the similar `BlendDataMeshes.new_from_object` function and `Mesh.copy()` These are the results of running the script in the attached .blend in 4.0.0a: ![image](/attachments/6af21126-1627-4248-bd35-d6e7685d86df)
Thomas Barlow added the
Type
Report
Status
Needs Triage
Priority
Normal
labels 2023-06-24 18:25:11 +02:00
Iliya Katushenock changed title from `Object.to_mesh().copy()` may keep shape keys of meshes created from evaluated Objects to Regression: Copy of eval mesh may keep shape keys 2023-06-25 01:34:05 +02:00
Iliya Katushenock added the
Interest
Modeling
label 2023-06-25 01:34:17 +02:00
Member

Observe the mesh going crazy/exploding as the Value changes

This is definitely gonna be a problem.

I'm not sure but maybe we could combine the discussion in here with #109313.

> Observe the mesh going crazy/exploding as the Value changes This is definitely gonna be a problem. I'm not sure but maybe we could combine the discussion in here with #109313.
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
2 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#109327
No description provided.