[Bf-blender-cvs] [c4781c72435] sculpt-dev: Sculpt-dev: cross-module ref cleanup
Joseph Eagar
noreply at git.blender.org
Wed Nov 17 13:09:23 CET 2021
Commit: c4781c72435b73250f38dfc56ffc7804fe876d2f
Author: Joseph Eagar
Date: Wed Nov 17 04:08:41 2021 -0800
Branches: sculpt-dev
https://developer.blender.org/rBc4781c72435b73250f38dfc56ffc7804fe876d2f
Sculpt-dev: cross-module ref cleanup
* Removed a bunch of nasty editors->blenkernel
dependencies (2 still remain).
* Fixed a few bugs in last commit.
===================================================================
M source/blender/blenkernel/BKE_paint.h
M source/blender/blenkernel/intern/attribute.c
M source/blender/blenkernel/intern/paint.c
M source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_vcol.cc
M source/blender/editors/geometry/geometry_attributes.c
M source/blender/editors/sculpt_paint/sculpt.c
M source/blender/editors/sculpt_paint/sculpt_dyntopo.c
M source/blender/editors/sculpt_paint/sculpt_intern.h
===================================================================
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 48425c5e6c4..6c06ebfb8fd 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -25,6 +25,7 @@
#include "BKE_brush_engine.h"
#include "BKE_pbvh.h"
+#include "BKE_attribute.h"
#include "BLI_bitmap.h"
#include "BLI_utildefines.h"
@@ -604,6 +605,32 @@ typedef struct SculptFakeNeighbors {
/* Session data (mode-specific) */
+/* Custom Temporary Attributes */
+
+typedef struct SculptLayerParams {
+ int simple_array : 1; // cannot be combined with permanent
+ int permanent : 1; // cannot be combined with simple_array
+ int nocopy : 1;
+ int nointerp : 1;
+} SculptLayerParams;
+
+typedef struct SculptCustomLayer {
+ AttributeDomain domain;
+ int proptype;
+ SculptLayerParams params;
+
+ char name[512];
+
+ bool is_cdlayer; // false for multires data
+ void *data; // only valid for multires and face
+ int elemsize;
+ int cd_offset; // for bmesh
+ struct CustomDataLayer *layer; // not for multires
+ bool from_bmesh; // note that layers can be fixed arrays but still from a bmesh, e.g. filter
+ // laplacian smooth
+ bool released;
+} SculptCustomLayer;
+
/* These custom attributes have references
(SculptCustomLayer pointers) inside of ss->custom_layers
that are kept up to date with SCULPT_update_customdata_refs.
@@ -851,8 +878,20 @@ void BKE_sculptsession_free_vwpaint_data(struct SculptSession *ss);
void BKE_sculptsession_bm_to_me(struct Object *ob, bool reorder);
void BKE_sculptsession_bm_to_me_for_render(struct Object *object);
bool BKE_sculptsession_check_mdyntopo(SculptSession *ss, struct PBVH *pbvh, int totvert);
-
-/* Create new color layer on object if it doesn't have one and if experimental feature set has
+void BKE_sculptsession_sync_attributes(struct Object *ob, struct Mesh *me);
+struct BMesh *BKE_sculptsession_empty_bmesh_create();
+void BKE_sculptsession_bmesh_add_layers(struct Object *ob);
+bool BKE_sculptsession_customlayer_get(struct Object *ob,
+ AttributeDomain domain,
+ int proptype,
+ const char *name,
+ SculptCustomLayer *scl,
+ SculptLayerParams *params);
+void BKE_sculptsession_bmesh_attr_update_internal(struct Object *ob);
+void BKE_sculptsession_update_attr_refs(struct Object *ob);
+int BKE_sculptsession_get_totvert(const SculptSession *ss);
+
+ /* Create new color layer on object if it doesn't have one and if experimental feature set has
* sculpt vertex color enabled. Returns truth if new layer has been added, false otherwise. */
void BKE_sculpt_color_layer_create_if_needed(struct Object *object);
diff --git a/source/blender/blenkernel/intern/attribute.c b/source/blender/blenkernel/intern/attribute.c
index 9f0373288ca..6c0bc58bc66 100644
--- a/source/blender/blenkernel/intern/attribute.c
+++ b/source/blender/blenkernel/intern/attribute.c
@@ -608,8 +608,7 @@ int BKE_id_attribute_index_from_ref(ID *id,
for (int i = 0; i < data->totlayer; i++) {
CustomDataLayer *layer = data->layers + i;
- if (layer->type == ref->type &&
- STREQ(layer->name, ref->name)) {
+ if (layer->type == ref->type && STREQ(layer->name, ref->name)) {
return index;
}
@@ -643,15 +642,15 @@ bool BKE_id_attribute_ref_from_index(ID *id,
for (int i = 0; i < data->totlayer; i++) {
CustomDataLayer *layer = data->layers + i;
- if (index == attr_index) {
- r_ref->domain = domain;
- r_ref->type = layer->type;
- BLI_strncpy_utf8(r_ref->name, layer->name, MAX_CUSTOMDATA_LAYER_NAME);
+ if (CD_TYPE_AS_MASK(layer->type) & type_filter) {
+ if (index == attr_index) {
+ r_ref->domain = domain;
+ r_ref->type = layer->type;
+ BLI_strncpy_utf8(r_ref->name, layer->name, MAX_CUSTOMDATA_LAYER_NAME);
- return true;
- }
+ return true;
+ }
- if (CD_TYPE_AS_MASK(layer->type) & type_filter) {
index++;
}
}
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 262e8139e34..011dd71efa3 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -38,10 +38,13 @@
#include "DNA_view3d_types.h"
#include "DNA_workspace_types.h"
+#include "BLI_array.h"
#include "BLI_bitmap.h"
#include "BLI_hash.h"
#include "BLI_listbase.h"
#include "BLI_math_vector.h"
+#include "BLI_string_utf8.h"
+#include "BLI_string_utils.h"
#include "BLI_utildefines.h"
#include "BLT_translation.h"
@@ -82,12 +85,8 @@
#include "bmesh.h"
// TODO: figure out bad cross module refs
-void SCULPT_dynamic_topology_sync_layers(Object *ob, Mesh *me);
void SCULPT_on_sculptsession_bmesh_free(SculptSession *ss);
-void SCULPT_dyntopo_node_layers_add(SculptSession *ss, Object *ob);
-BMesh *SCULPT_dyntopo_empty_bmesh();
void SCULPT_undo_ensure_bmlog(Object *ob);
-void SCULPT_update_customdata_refs(SculptSession *ss, Object *ob);
static void init_mdyntopo_layer(SculptSession *ss, PBVH *pbvh, int totvert);
@@ -1899,7 +1898,7 @@ static void sculpt_update_object(Depsgraph *depsgraph,
if (idx == -1) {
BM_data_layer_add_named(ss->bm, &ss->bm->vdata, CD_SHAPEKEY, key->name);
- SCULPT_update_customdata_refs(ss, ob);
+ BKE_sculptsession_update_attr_refs(ob);
idx = CustomData_get_named_layer_index(&ss->bm->vdata, CD_SHAPEKEY, key->name);
ss->bm->vdata.layers[idx].uid = key->uid;
@@ -1945,7 +1944,7 @@ static void sculpt_update_object(Depsgraph *depsgraph,
int cd_co = ss->bm->vdata.layers[idx].offset;
ss->bm->vdata.layers[idx].uid = newkey->uid;
- SCULPT_update_customdata_refs(ss, ob);
+ BKE_sculptsession_update_attr_refs(ob);
BM_ITER_MESH (v, &iter, ss->bm, BM_VERTS_OF_MESH) {
float *keyco = BM_ELEM_CD_GET_VOID_P(v, cd_co);
@@ -2026,7 +2025,7 @@ void BKE_sculpt_update_object_after_eval(Depsgraph *depsgraph, Object *ob_eval)
BLI_assert(me_eval != NULL);
sculpt_update_object(depsgraph, ob_orig, me_eval, false, false, false);
- SCULPT_dynamic_topology_sync_layers(ob_orig, me_orig);
+ BKE_sculptsession_sync_attributes(ob_orig, me_orig);
}
void BKE_sculpt_color_layer_create_if_needed(struct Object *object)
@@ -2603,7 +2602,7 @@ PBVH *BKE_sculpt_object_pbvh_ensure(Depsgraph *depsgraph, Object *ob)
else if (BKE_pbvh_type(pbvh) == PBVH_BMESH) {
// Object *object_eval = DEG_get_evaluated_object(depsgraph, ob);
- SCULPT_dynamic_topology_sync_layers(ob, BKE_object_get_original_mesh(ob));
+ BKE_sculptsession_sync_attributes(ob, BKE_object_get_original_mesh(ob));
}
return pbvh;
}
@@ -2621,7 +2620,7 @@ PBVH *BKE_sculpt_object_pbvh_ensure(Depsgraph *depsgraph, Object *ob)
bool is_dyntopo = (mesh_orig->flag & ME_SCULPT_DYNAMIC_TOPOLOGY);
if (is_dyntopo) {
- BMesh *bm = SCULPT_dyntopo_empty_bmesh();
+ BMesh *bm = BKE_sculptsession_empty_bmesh_create();
ob->sculpt->bm = bm;
@@ -2636,12 +2635,12 @@ PBVH *BKE_sculpt_object_pbvh_ensure(Depsgraph *depsgraph, Object *ob)
.copy_temp_cdlayers = true,
.cd_mask_extra = CD_MASK_DYNTOPO_VERT}));
- SCULPT_dyntopo_node_layers_add(ob->sculpt, ob);
+ BKE_sculptsession_bmesh_add_layers(ob);
SCULPT_undo_ensure_bmlog(ob);
pbvh = build_pbvh_for_dynamic_topology(ob, true);
- SCULPT_update_customdata_refs(ob->sculpt, ob);
+ BKE_sculptsession_update_attr_refs(ob);
}
else {
Object *object_eval = DEG_get_evaluated_object(depsgraph, ob);
@@ -2730,3 +2729,575 @@ void BKE_paint_face_set_overlay_color_get(const int face_set, const int seed, uc
&rgba[2]);
rgba_float_to_uchar(r_color, rgba);
}
+
+int BKE_sculptsession_get_totvert(const SculptSession *ss)
+{
+ switch (BKE_pbvh_type(ss->pbvh)) {
+ case PBVH_FACES:
+ return ss->totvert;
+ case PBVH_BMESH:
+ return BM_mesh_elem_count(BKE_pbvh_get_bmesh(ss->pbvh), BM_VERT);
+ case PBVH_GRIDS:
+ return BKE_pbvh_get_grid_num_vertices(ss->pbvh);
+ }
+
+ return 0;
+}
+
+/**
+ Syncs customdata layers with internal bmesh, but ignores deleted layers.
+*/
+void BKE_sculptsession_sync_attributes(struct Object *ob, struct Mesh *me)
+{
+ SculptSession *ss = ob->sculpt;
+
+ if (!ss || !ss->bm) {
+ return;
+ }
+
+ bool modified = false;
+ BMesh *bm = ss->bm;
+
+ CustomData *cd1[4] = {&me->vdata, &me->edata, &me->ldata, &me->pdata};
+ CustomData *cd2[4] = {&bm->vdata, &bm->edata, &bm->ldata, &bm->pdata};
+ int badmask = CD_MASK_MLOOP | CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MPOLY | CD_MASK_ORIGINDEX |
+ CD_MASK_ORIGSPACE | CD_MASK_MFACE;
+
+ for (int i = 0; i < 4; i++) {
+ CustomDataLayer **newlayers = NULL;
+ BLI_array_declare(newlayers);
+
+ CustomData *data1 = cd1[i];
+ CustomData *data2 = cd2[i];
+
+ if (!data1->layers) {
+ modified |= data2->layers != NULL;
+ continue;
+ }
+
+ for (int j = 0; j < data1->totlayer; j++) {
+ CustomDataLayer *cl1 = data1->layers + j;
+
+ if ((1 << cl1->type) & badmask) {
+ continue;
+ }
+
+ int idx = CustomData_get_named_layer_index(data2, cl1->type, cl1->name);
+ if (idx < 0) {
+ BLI_array_append(newlayers, cl1);
+ }
+ }
+
+ for (int j = 0; j < BLI_array_len(newlayers); j++) {
+ BM_data_layer_add_named(bm, data2, newlayers[j]->type, newlayers[j]->name);
+ modified = true;
+ }
+
+ /* sync various ids */
+ for (int j = 0; j < data1->totlayer; j++) {
+ CustomDataLayer *cl1 = data1->layers + j;
+
+ if ((1 << cl1->type) & badmask) {
+ continue;
+ }
+
+ int idx = CustomData_get_named_layer_index(data2, cl1->type, cl1->name);
+
+ if (idx == -1) {
+ continue;
+ }
+
+ CustomDataLayer
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list