diff options
author | Joseph Eagar <joeedh@gmail.com> | 2022-09-16 22:20:28 +0300 |
---|---|---|
committer | Joseph Eagar <joeedh@gmail.com> | 2022-09-16 22:20:28 +0300 |
commit | 02575bcbd0a91f499f13d15860adc3896920b9ff (patch) | |
tree | ca29d97875a996cffd5b7d196ffe3648b299fc1c /source/blender/blenkernel/intern/pbvh_bmesh.c | |
parent | 4cea4f4c5f845a85dd5bc95967b5ce63296015d1 (diff) |
Sculpt: New attribute API
New unified attribute API for sculpt code.
= Basic Design =
The sculpt attribute API can create temporary or permanent attributes (only supported in `PBVH_FACES` mode). Attributes are created via `BKE_sculpt_attribute_ensure.`
Attributes can be explicit CustomData attributes or simple array-based pseudo-attributes (this is useful for PBVH_GRIDS and PBVH_BMESH).
== `SculptAttributePointers` ==
There is a structure in `SculptSession` for convenience attribute pointers, `ss->attrs`. Standard attributes should assign these; the attribute API will automatically clear them when the associated attributes are released. For example, the automasking code stores its factor attribute layer in `ss->attrs.automasking_factor`.
== Naming ==
Temporary attributes should use the SCULPT_ATTRIBUTE_NAME macro for naming, it takes an entry in `SculptAttributePointers` and builds a layer name.
== `SculptAttribute` ==
Attributes are referenced by a special `SculptAttribute` structure, which holds
all the info needed to look up elements of an attribute at run time.
All of these structures live in a preallocated flat array in `SculptSession`, `ss->temp_attributes`. This is extremely important. Since any change to the `CustomData` layout can in principle invalidate every extant `SculptAttribute`, having them all in one block of memory whose location doesn't change allows us to update them transparently.
This makes for much simpler code and eliminates bugs. To see why this is tricky to get right, imagine we want to create three attributes in PBVH_BMESH mode and we provide our own `SculptAttribute` structs for the API to fill in. Each new layer will invalidate the `CustomData` block offsets in the prior one, leading to memory corruption.
Reviewed by: Brecht Van Lommel
Differential Revision: https://developer.blender.org/D15496
Ref D15496
Diffstat (limited to 'source/blender/blenkernel/intern/pbvh_bmesh.c')
-rw-r--r-- | source/blender/blenkernel/intern/pbvh_bmesh.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c index c4993684100..e065180b600 100644 --- a/source/blender/blenkernel/intern/pbvh_bmesh.c +++ b/source/blender/blenkernel/intern/pbvh_bmesh.c @@ -1863,6 +1863,12 @@ static void pbvh_bmesh_create_nodes_fast_recursive( /***************************** Public API *****************************/ +void BKE_pbvh_update_bmesh_offsets(PBVH *pbvh, int cd_vert_node_offset, int cd_face_node_offset) +{ + pbvh->cd_vert_node_offset = cd_vert_node_offset; + pbvh->cd_face_node_offset = cd_face_node_offset; +} + void BKE_pbvh_build_bmesh(PBVH *pbvh, BMesh *bm, bool smooth_shading, @@ -1870,8 +1876,6 @@ void BKE_pbvh_build_bmesh(PBVH *pbvh, const int cd_vert_node_offset, const int cd_face_node_offset) { - pbvh->cd_vert_node_offset = cd_vert_node_offset; - pbvh->cd_face_node_offset = cd_face_node_offset; pbvh->header.bm = bm; BKE_pbvh_bmesh_detail_size_set(pbvh, 0.75); @@ -1882,6 +1886,8 @@ void BKE_pbvh_build_bmesh(PBVH *pbvh, /* TODO: choose leaf limit better */ pbvh->leaf_limit = 100; + BKE_pbvh_update_bmesh_offsets(pbvh, cd_vert_node_offset, cd_face_node_offset); + if (smooth_shading) { pbvh->flags |= PBVH_DYNTOPO_SMOOTH_SHADING; } |