Mesh: Replace MPoly struct with offset indices #105938
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
3 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#105938
Loading…
Reference in New Issue
No description provided.
Delete Branch "refactor-mesh-face-generic"
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?
Implements #95967.
Currently the
MPoly
struct is 12 bytes, and stores the index of aface's first corner and the number of corners/verts/edges. Polygons
and corners are always created in order by Blender, meaning each
face's corners will be after the previous face's corners. We can take
advantage of this fact and eliminate the redundancy in mesh face
storage by only storing a single integer corner offset for each face.
The size of the face is then encoded by the offset of the next face.
The size of a single integer is 4 bytes, so this reduces memory
usage by 3 times.
The same method is used for
CurvesGeometry
, so Blender already hasan abstraction to simplify using these offsets called
OffsetIndices
.This class is used to easily retrieve a range of corner indices for
each face. This also gives the opportunity for sharing some logic with
curves.
Another benefit of the change is that the offsets and sizes stored in
MPoly
can no longer disagree with each other. Storing faces in theorder of their corners can simplify some code too.
Face/polygon variables now use the
IndexRange
type, which comes withquite a few utilities that can simplify code.
Implementation notes:
avoid a branch for every face, which means the data is no longer part
of the mesh's
CustomData
.until more reusable CoW from #104478 is committed. That will be added
in a separate commit.
CustomData
, poly offsets often have to becopied manually.
OffsetIndices
in many places, some functions andstructs in headers were moved to only compile in C++.
corners, but just in case, meshes with mismatched order are fixed by
versioning code.
MeshPolygon.totloop
is no longer editable in RNA. Some breakage isnecessary here unfortunately, and it should be worth it in 3.6, since
that's the best way to allow loading meshes from 4.0.
I found one issue related to undo. To reproduce the crash, open Blender, duplicate the default cube and undo. I couldn't figure out the root cause yet. The crash happens because
mesh->poly_offsets_data
is null after the undo. For some reasonBLO_read_int32_array
sets the pointer to null, even though the array seems to be written correctly inmesh_blend_write
.What do you think about renaming
poly_offsets_data
topoly_offset_indices
?I finally found the issue. For some reason the order of operations matters a lot when writing a mesh. I think I understood why last year at some point but now I forget, it's pretty weird.
Good idea, done.
Ah good find, for some reason I thought that we always write the id struct at the beginning of the function, but didn't check here.
I believe the reason is that the old-new-map is created per ID. Everything that comes after an ID block in the file belongs to that ID, until the next one starts.
@blender-bot build
Could not find another issue in my tests.
Noted some issues inline, otherwise LGTM, no need for an extra review cycle.
@ -944,6 +957,23 @@ Mesh *BKE_mesh_add(Main *bmain, const char *name)
return me;
}
void BKE_mesh_poly_offsets_ensure(Mesh *mesh)
Suggestion: "Ensure" functions typically create the data and fill it with valid values.
This function just ensures the memory is allocated. Perhaps this could be called
BKE_mesh_poly_offsets_ensure_alloc
orBKE_mesh_poly_offsets_ensure_uninitialized
.@ -2199,0 +2261,4 @@
});
CustomData old_poly_data = mesh->pdata;
CustomData_reset(&mesh->pdata);
CustomData_copy(&old_poly_data, &mesh->pdata, CD_MASK_MESH.lmask, CD_CONSTRUCT, mesh->totloop);
Shouldn't
pmask
andtotpoly
be used here?