Fix: Incorrect BMesh to Mesh attribute copying #104421
No reviewers
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
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#104421
Loading…
Reference in New Issue
No description provided.
Delete Branch "HooglyBoogly/blender:bmesh-mesh-conversion-faster-hot-loops"
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?
The existing logic to copy
BMesh
custom data layers toMesh
attributearrays was quite complicated, and incorrect in some cases when the
source and destinations didn't have the same layers. The functions
leave a lot to be desired in general, since they have a lot of redundant
complexity that ends up doing the same thing for every element.
The problem in #104154 was that the "rest_position" attribute overwrote
the mesh positions since it has the same type and the positions weren't
copied. This same problem has shown up in boolean attribute conversion
in the past. Other changes fixed some specific cases but I think a larger
change is the only proper solution.
This patch adds preprocessing before looping over all elements to
find the basic information for copying the relevant layers, taking
layer names into account. The preprocessing makes the hot loops
simpler.
In a simple file with a 1 million vertex grid, I observed a 6% improvement
animation playback framerate in edit mode with a simple geometry nodes
modifier, from 5 to 5.3 FPS.
Fixes #104154, #104348
Mesh: Simplify BMesh Mesh conversion attribute copyingto Fix: Incorrect BMesh to Mesh attribute copyingGenerally this looks fine, noticed an issue (noted inline).
I'd also really prefer not use get/copy as prefixes - see patch:
3d82ba7ad4
... it includes some additional code-comments too.@ -153,0 +177,4 @@
CustomData_get_layer_index_n(&bm_data, type, per_type_index[type]) :
CustomData_get_named_layer_index(&bm_data, type, bm_layer.name);
if (mesh_layer_index == -1) {
infos.append({});
Appending a zeroed MeshToBMeshLayerInfo doesn't seem correct, the BMesh data should still be initialized so even if there is no source layer (where
MeshToBMeshLayerInfo::mesh_data
is NULL), theCustomData_data_set_default_value
needs thebmesh_offset
to be set. From what I can tell the other members should be set (type, elem_size) just not the mesh_data.If I'm misunderstanding the logic, an explanation of why a zeroed
MeshToBMeshLayerInfo
is needed should be included.It would also be good to have doc-strings for the functions that generate
*LayerInfo
vectors noting thatVector<BMeshToMeshLayerInfo>
isn'tmesh_data.totlayer
aligned, wereVector<MeshToBMeshLayerInfo>
isbm_data.totlayer
aligned, it's not obvious why conversion in one direction needs to account for all layers while conversion in the other direction doesn't.Good point, the logic was bad there, thanks.
I added more comments about why some layers are skipped. I kept
BMToMesh
instead ofBMeshToMesh
since it's shorter and keeps statements on a single line which looks so much better.I also added comments to the copy info struct elements.
Oops, this wasn't necessary. I made that change too.