diff options
author | Hans Goudey <h.goudey@me.com> | 2022-08-31 17:09:01 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2022-08-31 17:09:01 +0300 |
commit | f1c0249f34c4171ec311b5b9882e36fed5889259 (patch) | |
tree | 7dd630c9301b8dd468c8279e8c446c62824fb6d6 /source/blender/makesdna | |
parent | 3e73afb5360592fe2bf43419e216035ea3c281f9 (diff) |
Mesh: Move material indices to a generic attribute
This patch moves material indices from the mesh `MPoly` struct to a
generic integer attribute. The builtin material index was already
exposed in geometry nodes, but this makes it a "proper" attribute
accessible with Python and visible in the "Attributes" panel.
The goals of the refactor are code simplification and memory and
performance improvements, mainly because the attribute doesn't have
to be stored and processed if there are no materials. However, until
4.0, material indices will still be read and written in the old
format, meaning there may be a temporary increase in memory usage.
Further notes:
* Completely removing the `MPoly.mat_nr` after 4.0 may require
changes to DNA or introducing a new `MPoly` type.
* Geometry nodes regression tests didn't look at material indices,
so the change reveals a bug in the realize instances node that I fixed.
* Access to material indices from the RNA `MeshPolygon` type is slower
with this patch. The `material_index` attribute can be used instead.
* Cycles is changed to read from the attribute instead.
* BMesh isn't changed in this patch. Theoretically it could be though,
to save 2 bytes per face when less than two materials are used.
* Eventually we could use a 16 bit integer attribute type instead.
Ref T95967
Differential Revision: https://developer.blender.org/D15675
Diffstat (limited to 'source/blender/makesdna')
-rw-r--r-- | source/blender/makesdna/DNA_mesh_types.h | 3 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_meshdata_types.h | 7 |
2 files changed, 6 insertions, 4 deletions
diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h index 97355548b09..9912ec8ec3b 100644 --- a/source/blender/makesdna/DNA_mesh_types.h +++ b/source/blender/makesdna/DNA_mesh_types.h @@ -161,7 +161,8 @@ typedef struct Mesh { /** * An array of materials, with length #totcol. These can be overridden by material slots - * on #Object. Indices in #MPoly.mat_nr control which material is used for every face. + * on #Object. Indices in the "material_index" attribute control which material is used for every + * face. */ struct Material **mat; diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h index c62907e26ed..e0333f3ef03 100644 --- a/source/blender/makesdna/DNA_meshdata_types.h +++ b/source/blender/makesdna/DNA_meshdata_types.h @@ -74,7 +74,8 @@ typedef struct MPoly { int loopstart; /** Keep signed since we need to subtract when getting the previous loop. */ int totloop; - short mat_nr; + /** Deprecated material index. Now stored in the "material_index" attribute, but kept for IO. */ + short mat_nr DNA_DEPRECATED; char flag, _pad; } MPoly; @@ -156,8 +157,8 @@ enum { * * Usage examples: * \code{.c} - * // access original material. - * short mat_nr = mpoly[lt->poly].mat_nr; + * // access polygon attribute value. + * T value = polygon_attribute[lt->poly]; * * // access vertex locations. * float *vtri_co[3] = { |