[Bf-blender-cvs] [cfd6d48aab8] temp_bmesh_multires: * Prototyped a faster smooth algo, currently disabled. * Wrote a new API for wrangling temporary customdata layers across pbvh types: - SCULPT_temp_customlayer_ensure: makes sure a (named) customdata layer exists. Works for multires; since these are temporary layers we can safely allocate them in a temporary CustomData structure (in ss->temp_vdata). - SCULPT_temp_customlayer_get: initializes a special structure, SculptCustomLayer, that is used to get per elem customdata. - SCULPT_temp_cdata_get: Uses a SculptCustomLayer ref along with a SculptVertexRef to look up the data.
Joseph Eagar
noreply at git.blender.org
Sat May 15 03:31:20 CEST 2021
Commit: cfd6d48aab81ed42beec70fe76c191749b5e790d
Author: Joseph Eagar
Date: Fri May 14 18:26:41 2021 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rBcfd6d48aab81ed42beec70fe76c191749b5e790d
* Prototyped a faster smooth algo, currently disabled.
* Wrote a new API for wrangling temporary customdata layers across pbvh types:
- SCULPT_temp_customlayer_ensure: makes sure a (named) customdata
layer exists. Works for multires; since these are temporary
layers we can safely allocate them in a temporary CustomData
structure (in ss->temp_vdata).
- SCULPT_temp_customlayer_get: initializes a special structure,
SculptCustomLayer, that is used to get per elem customdata.
- SCULPT_temp_cdata_get: Uses a SculptCustomLayer ref along with
a SculptVertexRef to look up the data.
===================================================================
M source/blender/blenkernel/BKE_customdata.h
M source/blender/blenkernel/BKE_paint.h
M source/blender/blenkernel/intern/customdata.c
M source/blender/blenkernel/intern/paint.c
M source/blender/bmesh/intern/bmesh_log.c
M source/blender/bmesh/intern/bmesh_polygon.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
M source/blender/editors/sculpt_paint/sculpt_smooth.c
===================================================================
diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h
index 5c73f4e3ca1..7b33a6077d0 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -605,6 +605,8 @@ void CustomData_blend_read(struct BlendDataReader *reader, struct CustomData *da
void CustomData_unmark_temporary_nocopy(struct CustomData *data);
void CustomData_mark_temporary_nocopy(struct CustomData *data);
+int CustomData_get_elem_size(CustomDataLayer *layer);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 301e9ed9422..a6b4f3ab49b 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -27,6 +27,7 @@
#include "BLI_bitmap.h"
#include "BLI_utildefines.h"
#include "DNA_brush_enums.h"
+#include "DNA_customdata_types.h"
#include "DNA_object_enums.h"
#ifdef __cplusplus
@@ -471,6 +472,12 @@ typedef struct SculptSession {
struct MPoly *mpoly;
struct MLoop *mloop;
+ // only assigned in PBVH_FACES and PBVH_GRIDS
+ CustomData *vdata, *edata, *ldata, *pdata;
+
+ // for grids
+ CustomData temp_vdata, temp_pdata;
+
/* These contain the vertex and poly counts of the final mesh. */
int totvert, totpoly;
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 3e3e5ca39af..1c5792461ca 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -2107,6 +2107,11 @@ static const LayerTypeInfo *layerType_getInfo(int type)
return &LAYERTYPEINFO[type];
}
+int CustomData_get_elem_size(CustomDataLayer *layer)
+{
+ return layerType_getInfo(layer->type)->size;
+}
+
static const char *layerType_getName(int type)
{
if (type < 0 || type >= CD_NUMTYPES) {
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 80467bef5f2..2c830e92142 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -1630,7 +1630,7 @@ static void sculpt_update_object(Depsgraph *depsgraph,
Scene *scene = DEG_get_input_scene(depsgraph);
Sculpt *sd = scene->toolsettings->sculpt;
SculptSession *ss = ob->sculpt;
- const Mesh *me = BKE_object_get_original_mesh(ob);
+ Mesh *me = BKE_object_get_original_mesh(ob);
MultiresModifierData *mmd = BKE_sculpt_multires_active(scene, ob);
const bool use_face_sets = (ob->mode & OB_MODE_SCULPT) != 0;
@@ -1683,6 +1683,11 @@ static void sculpt_update_object(Depsgraph *depsgraph,
ss->multires.level = 0;
ss->vmask = CustomData_get_layer(&me->vdata, CD_PAINT_MASK);
ss->vcol = CustomData_get_layer(&me->vdata, CD_PROP_COLOR);
+
+ ss->vdata = &me->vdata;
+ ss->edata = &me->edata;
+ ss->ldata = &me->ldata;
+ ss->pdata = &me->pdata;
}
/* Sculpt Face Sets. */
@@ -2233,7 +2238,7 @@ PBVH *BKE_sculpt_object_pbvh_ensure(Depsgraph *depsgraph, Object *ob)
pbvh = build_pbvh_for_dynamic_topology(ob);
ob->sculpt->pbvh = pbvh;
- //reorder mesh elements to improve memory cache performance
+ // reorder mesh elements to improve memory cache performance
SCULPT_reorder_bmesh(ob->sculpt);
}
else {
diff --git a/source/blender/bmesh/intern/bmesh_log.c b/source/blender/bmesh/intern/bmesh_log.c
index c6c96481e7f..cd5cd05f10a 100644
--- a/source/blender/bmesh/intern/bmesh_log.c
+++ b/source/blender/bmesh/intern/bmesh_log.c
@@ -782,7 +782,8 @@ void BM_log_set_cd_offsets(BMLog *log, int cd_dyn_vert)
log->cd_dyn_vert = cd_dyn_vert;
}
-void BM_log_set_bm(BMesh *bm, BMLog *log) {
+void BM_log_set_bm(BMesh *bm, BMLog *log)
+{
log->bm = bm;
}
diff --git a/source/blender/bmesh/intern/bmesh_polygon.c b/source/blender/bmesh/intern/bmesh_polygon.c
index 9beeb5c900b..780b4a06044 100644
--- a/source/blender/bmesh/intern/bmesh_polygon.c
+++ b/source/blender/bmesh/intern/bmesh_polygon.c
@@ -29,6 +29,7 @@
#include "MEM_guardedalloc.h"
#include "BLI_alloca.h"
+#include "BLI_compiler_attrs.h"
#include "BLI_heap.h"
#include "BLI_linklist.h"
#include "BLI_math.h"
@@ -1105,20 +1106,20 @@ bool BM_face_point_inside_test(const BMFace *f, const float co[3])
* \note use_tag tags new flags and edges.
*/
void BM_face_triangulate(BMesh *bm,
- BMFace *f,
- BMFace **r_faces_new,
- int *r_faces_new_tot,
- BMEdge **r_edges_new,
- int *r_edges_new_tot,
- LinkNode **r_faces_double,
- const int quad_method,
- const int ngon_method,
- const bool use_tag,
- /* use for ngons only! */
- MemArena *pf_arena,
-
- /* use for MOD_TRIANGULATE_NGON_BEAUTY only! */
- struct Heap *pf_heap)
+ BMFace *f,
+ BMFace **r_faces_new,
+ int *r_faces_new_tot,
+ BMEdge **r_edges_new,
+ int *r_edges_new_tot,
+ LinkNode **r_faces_double,
+ const int quad_method,
+ const int ngon_method,
+ const bool use_tag,
+ /* use for ngons only! */
+ MemArena *pf_arena,
+
+ /* use for MOD_TRIANGULATE_NGON_BEAUTY only! */
+ struct Heap *pf_heap)
{
const int cd_loop_mdisp_offset = CustomData_get_offset(&bm->ldata, CD_MDISPS);
const bool use_beauty = (ngon_method == MOD_TRIANGULATE_NGON_BEAUTY);
@@ -1467,7 +1468,6 @@ void BM_face_as_array_vert_quad(BMFace *f, BMVert *r_verts[4])
r_verts[3] = l->v;
}
-
/**
* faster alternative to:
* BM_iter_as_array(bm, BM_LOOPS_OF_FACE, f, (void **)l, 4);
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 4f2bde51971..0694a9d5b42 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -46,6 +46,7 @@
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
+#include "BKE_attribute.h"
#include "BKE_brush.h"
#include "BKE_ccg.h"
#include "BKE_colortools.h"
@@ -120,7 +121,6 @@ void SCULPT_vertex_random_access_ensure(SculptSession *ss)
}
}
-
/* Sculpt PBVH abstraction API
*
* This is read-only, for writing use PBVH vertex iterators. There vd.index matches
@@ -168,7 +168,7 @@ const float *SCULPT_vertex_origco_get(SculptSession *ss, SculptVertRef vertex)
const float *SCULPT_vertex_co_get(SculptSession *ss, SculptVertRef index)
{
if (ss->bm) {
- return ((BMVert*)index.i)->co;
+ return ((BMVert *)index.i)->co;
}
switch (BKE_pbvh_type(ss->pbvh)) {
@@ -335,6 +335,132 @@ void SCULPT_vertex_persistent_normal_get(SculptSession *ss,
SCULPT_vertex_normal_get(ss, index, no);
}
+static bool sculpt_temp_customlayer_get(SculptSession *ss,
+ AttributeDomain domain,
+ int proptype,
+ char *name,
+ SculptCustomLayer *out,
+ bool autocreate)
+{
+ switch (BKE_pbvh_type(ss->pbvh)) {
+ case PBVH_BMESH: {
+ CustomData *cdata = NULL;
+
+ if (!ss->bm) {
+ return false;
+ }
+
+ switch (domain) {
+ case ATTR_DOMAIN_POINT:
+ cdata = &ss->bm->vdata;
+ break;
+ case ATTR_DOMAIN_FACE:
+ cdata = &ss->bm->pdata;
+ break;
+ default:
+ return false;
+ }
+
+ int idx = CustomData_get_named_layer_index(cdata, proptype, name);
+
+ if (idx < 0) {
+ if (!autocreate) {
+ return false;
+ }
+
+ BM_data_layer_add_named(ss->bm, cdata, proptype, name);
+ idx = CustomData_get_named_layer_index(cdata, proptype, name);
+ cdata->layers[idx].flag |= CD_FLAG_TEMPORARY;
+ SCULPT_dyntopo_node_layers_update_offsets(ss);
+ }
+
+ out->data = NULL;
+ out->is_cdlayer = true;
+ out->layer = cdata->layers + idx;
+ out->cd_offset = out->layer->offset;
+ out->elemsize = CustomData_get_elem_size(out->layer);
+
+ break;
+ }
+ case PBVH_FACES: {
+ CustomData *cdata = NULL;
+ int totelem = 0;
+
+ switch (domain) {
+ case ATTR_DOMAIN_POINT:
+ totelem = ss->totvert;
+ cdata = ss->vdata;
+ break;
+ case ATTR_DOMAIN_FACE:
+ totelem = ss->totfaces;
+ cdata = ss->pdata;
+ break;
+ default:
+ return false;
+ }
+
+ int idx = CustomData_get_named_layer_index(cdata, proptype, name);
+
+ if (idx < 0) {
+ if (!autocreate) {
+ return false;
+ }
+
+ CustomData_add_layer_named(cdata, proptype, CD_CALLOC, NULL, totelem, name);
+ idx = CustomData_get_named_layer_index(cdata, proptype, name);
+
+ cdata->layers[idx].flag |= CD_FLAG_TEMPORARY;
+ }
+
+ out->data = NULL;
+ out->is_cdlayer = true;
+ out->layer = cdata->layers + idx;
+ out->cd_offset = -1;
+ out->data = out->layer->data;
+ out->elemsize = CustomData_get_elem_size(out->layer);
+ break;
+ }
+ case PBVH_GRIDS: {
+ CustomData *cdata = NULL;
+ int totelem = 0;
+
+ switch (domain) {
+ case ATTR_DOMAIN_POINT:
+ totelem = BKE_pbvh_get_grid_num_vertices(ss->pbvh);
+ cdata = &ss->temp_vdata;
+ break;
+ case ATTR_DOMAIN_FACE:
+ // not supported
+ return false;
+ default:
+ return false;
+ }
+
+ int idx = CustomData_get_named_layer_index(cdata, proptype, name);
+
+ if (idx < 0) {
+ if (!autocreate) {
+ retur
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list