[Bf-blender-cvs] [da4138e1deb] sculpt-dev: Sculpt: sculpt colors fixes
Joseph Eagar
noreply at git.blender.org
Fri Oct 15 05:06:10 CEST 2021
Commit: da4138e1deb6c27e5f91db596d083d8efb0f2d5b
Author: Joseph Eagar
Date: Thu Oct 14 19:57:02 2021 -0700
Branches: sculpt-dev
https://developer.blender.org/rBda4138e1deb6c27e5f91db596d083d8efb0f2d5b
Sculpt: sculpt colors fixes
* Paint brush now uses its own temp attribute
layers instead of hijacking MSculptVert->origcolor.
* The various SCULPT_UNDO_XXX enums are now bit flags.
* Fixed anchored/drag drop mode for the paint brushes.
* Color hardening brush now works with dyntopo.
* Added a CD_FLAG_ELEM_NOINTERP flag to the customdata
API. If set it will either copy the first element
in the sources list if CD_FLAG_ELEM_NOCOPY is unset,
or nothing at all if it is.
This necassary to properly support the design
pattern whereby helper custom attributes
reset themselves in each brush stroke by comparing
a per-vertex stroke id with ss->stroke_id, thus obviating
the need to walk the entire mesh at every stroke start.
===================================================================
M source/blender/blenkernel/intern/customdata.c
M source/blender/blenkernel/intern/pbvh.c
M source/blender/editors/sculpt_paint/sculpt.c
M source/blender/editors/sculpt_paint/sculpt_intern.h
M source/blender/editors/sculpt_paint/sculpt_paint_color.c
M source/blender/makesdna/DNA_brush_enums.h
M source/blender/makesdna/DNA_customdata_types.h
===================================================================
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index d98e81eb157..f199d39e395 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -3471,10 +3471,32 @@ void CustomData_interp(const CustomData *source,
if (dest->layers[dest_i].type == source->layers[src_i].type) {
void *src_data = source->layers[src_i].data;
+ if (dest->layers[dest_i].type == CD_MESH_ID) {
+ continue; // paranoia check that we don't process id layers
+ }
+
for (int j = 0; j < count; j++) {
sources[j] = POINTER_OFFSET(src_data, (size_t)src_indices[j] * typeInfo->size);
}
+ if (dest->layers[dest_i].flag & CD_FLAG_ELEM_NOINTERP) {
+ if (!(dest->layers[dest_i].flag & CD_FLAG_ELEM_NOCOPY)) {
+ if (typeInfo->copy) {
+ typeInfo->copy(
+ sources[0],
+ POINTER_OFFSET(dest->layers[dest_i].data, (size_t)dest_index * typeInfo->size),
+ 1);
+ }
+ else {
+ memcpy(POINTER_OFFSET(dest->layers[dest_i].data, (size_t)dest_index * typeInfo->size),
+ sources[0],
+ typeInfo->size);
+ }
+ }
+
+ continue;
+ }
+
typeInfo->interp(
sources,
weights,
@@ -4621,6 +4643,23 @@ void CustomData_bmesh_interp(CustomData *data,
continue;
}
+ if (layer->flag & CD_FLAG_ELEM_NOINTERP) {
+ if (!(layer->flag & CD_FLAG_ELEM_NOCOPY)) {
+ if (typeInfo->copy) {
+ typeInfo->copy(POINTER_OFFSET(src_blocks[0], layer->offset),
+ POINTER_OFFSET(dst_block, layer->offset),
+ 1);
+ }
+ else {
+ memcpy(POINTER_OFFSET(dst_block, layer->offset),
+ POINTER_OFFSET(src_blocks[0], layer->offset),
+ typeInfo->size);
+ }
+ }
+
+ continue;
+ }
+
if (typeInfo->interp) {
for (int j = 0; j < count; j++) {
sources[j] = POINTER_OFFSET(src_blocks[j], layer->offset);
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 357e07c64ee..079f22cce90 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1542,6 +1542,8 @@ static void pbvh_update_draw_buffers(PBVH *pbvh, PBVHNode **nodes, int totnode,
if (pbvh->type == PBVH_BMESH) {
if (pbvh->bm) {
+ pbvh->cd_vcol_offset = CustomData_get_offset(&pbvh->bm->vdata, CD_PROP_COLOR);
+
vdata = &pbvh->bm->vdata;
ldata = &pbvh->bm->ldata;
}
@@ -3415,7 +3417,7 @@ void pbvh_vertex_iter_init(PBVH *pbvh, PBVHNode *node, PBVHVertexIter *vi, int m
vi->cd_sculpt_vert = CustomData_get_offset(vi->bm_vdata, CD_DYNTOPO_VERT);
// we ensure pbvh->cd_vcol_offset is up to date here too
- vi->cd_vcol_offset = pbvh->cd_vcol_offset = CustomData_get_offset(vi->bm_vdata, CD_PROP_COLOR);
+ vi->cd_vcol_offset = CustomData_get_offset(vi->bm_vdata, CD_PROP_COLOR);
vi->cd_vert_mask_offset = CustomData_get_offset(vi->bm_vdata, CD_PAINT_MASK);
}
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index 37c5a48fb42..2fc977ffd39 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -516,6 +516,8 @@ static bool sculpt_temp_customlayer_get(SculptSession *ss,
{
bool simple_array = params->simple_array;
bool permanent = params->permanent;
+ bool nocopy = params->nocopy;
+ bool nointerp = params->nointerp;
out->params = *params;
out->proptype = proptype;
@@ -668,10 +670,17 @@ static bool sculpt_temp_customlayer_get(SculptSession *ss,
idx = CustomData_get_named_layer_index(cdata, proptype, name);
SCULPT_dyntopo_node_layers_update_offsets(ss);
+
+ if (!permanent) {
+ cdata->layers[idx].flag |= CD_FLAG_TEMPORARY | CD_FLAG_NOCOPY;
+ }
}
- if (!permanent) {
- cdata->layers[idx].flag |= CD_FLAG_TEMPORARY | CD_FLAG_NOCOPY;
+ if (nocopy) {
+ cdata->layers[idx].flag |= CD_FLAG_ELEM_NOCOPY;
+ }
+ if (nointerp) {
+ cdata->layers[idx].flag |= CD_FLAG_ELEM_NOINTERP;
}
out->data = NULL;
@@ -757,6 +766,13 @@ static bool sculpt_temp_customlayer_get(SculptSession *ss,
}
}
+ if (nocopy) {
+ cdata->layers[idx].flag |= CD_FLAG_ELEM_NOCOPY;
+ }
+ if (nointerp) {
+ cdata->layers[idx].flag |= CD_FLAG_ELEM_NOINTERP;
+ }
+
out->data = NULL;
out->is_cdlayer = true;
out->layer = cdata->layers + idx;
@@ -3149,68 +3165,68 @@ bool SCULPT_stroke_is_dynamic_topology(const SculptSession *ss, const Brush *bru
/*** paint mesh ***/
-static void paint_mesh_restore_co_task_cb(void *__restrict userdata,
- const int n,
- const TaskParallelTLS *__restrict UNUSED(tls))
+ATTR_NO_OPT static void paint_mesh_restore_co_task_cb(
+ void *__restrict userdata, const int n, const TaskParallelTLS *__restrict UNUSED(tls))
{
SculptThreadedTaskData *data = userdata;
SculptSession *ss = data->ob->sculpt;
- SculptUndoNode *unode;
- SculptUndoType type = (data->brush->sculpt_tool == SCULPT_TOOL_MASK ? SCULPT_UNDO_MASK :
- SCULPT_UNDO_COORDS);
-
- SculptUndoNode tmp = {0};
- if (ss->bm) {
- unode = &tmp;
- tmp.type = type;
- // unode = SCULPT_undo_push_node(data->ob, data->nodes[n], type);
- }
- else {
- unode = SCULPT_undo_get_node(data->nodes[n], type);
+ SculptUndoType type = 0;
- if (!unode) {
- return;
- }
+ switch (data->brush->sculpt_tool) {
+ case SCULPT_TOOL_MASK:
+ type |= SCULPT_UNDO_MASK;
+ break;
+ case SCULPT_TOOL_PAINT:
+ case SCULPT_TOOL_SMEAR:
+ type |= SCULPT_UNDO_COLOR;
+ break;
+ case SCULPT_TOOL_VCOL_BOUNDARY:
+ type |= SCULPT_UNDO_COLOR | SCULPT_UNDO_COORDS;
+ break;
+ default:
+ type |= SCULPT_UNDO_COORDS;
+ break;
}
PBVHVertexIter vd;
SculptOrigVertData orig_data;
- SCULPT_orig_vert_data_unode_init(&orig_data, data->ob, unode);
-
bool modified = false;
BKE_pbvh_vertex_iter_begin (ss->pbvh, data->nodes[n], vd, PBVH_ITER_UNIQUE) {
- SCULPT_orig_vert_data_update(&orig_data, vd.vertex);
+ SCULPT_vertex_check_origdata(ss, vd.vertex);
+ MSculptVert *mv = SCULPT_vertex_get_mdyntopo(ss, vd.vertex);
- if (orig_data.unode->type == SCULPT_UNDO_COORDS) {
- if (len_squared_v3v3(vd.co, orig_data.co) > FLT_EPSILON) {
+ if (type & SCULPT_UNDO_COORDS) {
+ if (len_squared_v3v3(vd.co, mv->origco) > FLT_EPSILON) {
modified = true;
}
- copy_v3_v3(vd.co, orig_data.co);
+ copy_v3_v3(vd.co, mv->origco);
if (vd.no) {
- copy_v3_v3_short(vd.no, orig_data.no);
+ normal_float_to_short_v3(vd.no, mv->origno);
}
else {
- normal_short_to_float_v3(vd.fno, orig_data.no);
+ copy_v3_v3(vd.fno, mv->origno);
}
}
- else if (orig_data.unode->type == SCULPT_UNDO_MASK) {
- if ((*vd.mask - orig_data.mask) * (*vd.mask - orig_data.mask) > FLT_EPSILON) {
+
+ if (type & SCULPT_UNDO_MASK) {
+ if ((*vd.mask - mv->origmask) * (*vd.mask - mv->origmask) > FLT_EPSILON) {
modified = true;
}
- *vd.mask = orig_data.mask;
+ *vd.mask = mv->origmask;
}
- else if (orig_data.unode->type == SCULPT_UNDO_COLOR && vd.col && orig_data.col) {
- if (len_squared_v4v4(vd.col, orig_data.col) > FLT_EPSILON) {
+
+ if (type & SCULPT_UNDO_COLOR && vd.col) {
+ if (len_squared_v4v4(vd.col, mv->origcolor) > FLT_EPSILON) {
modified = true;
}
- copy_v4_v4(vd.col, orig_data.col);
+ copy_v4_v4(vd.col, mv->origcolor);
}
if (vd.mvert) {
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index a034c9aeca7..43c4ab94bff 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -55,6 +55,8 @@ enum ePaintSymmetryFlags;
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 {
@@ -848,15 +850,15 @@ void SCULPT_do_symmetrize_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int to
/* Undo */
typedef enum {
- SCULPT_UNDO_COORDS,
- SCULPT_UNDO_HIDDEN,
- SCULPT_UNDO_MASK,
- SCULPT_UNDO_DYNTOPO_BEGIN,
- SCULPT_UNDO_DYNTOPO_END,
- SCULPT_UNDO_DYNTOPO_SYMMETRIZE,
- SCULPT_UNDO_GEOMETRY,
- SCULPT_UNDO_FACE_SETS,
- SCULPT_UNDO_COLOR,
+ SCULPT_UNDO_COORDS = 1 << 0,
+ SCULPT_UNDO_HIDDEN = 1 << 1,
+ SCULPT_UNDO_MASK = 1 << 2,
+ SCULPT_UNDO_DYNTOPO_BEGIN = 1 << 3,
+ SCULPT_UNDO_DYNTOPO_END = 1 << 4,
+ SCULPT_UNDO_DYNTOPO_SYMMETRIZE = 1 << 5,
+ SCULPT_UNDO_GEOMETRY = 1 << 6,
+ SCULPT_UNDO_FACE_SETS = 1 << 7,
+ SCULPT_UNDO_COLOR = 1 << 8,
} SculptUndoType;
/* Storage of geometry for the undo node.
diff --git a/source/blender/editors/sculpt_paint/sculpt_paint_color.c b/source/blender/editors/sculpt_paint/sculpt_paint_color.c
index 3cc8ef5a77c..604d3130043 100644
--- a/source/blender/editors/sculpt_paint/sculpt_paint_color.c
+++ b/source/blender/editors/sculpt_paint/sculpt_paint_color.c
@@ -120,14 +120,14 @@ static void do_paint_brush_task_cb_ex(void *__restrict userdata,
const Brush *brush = data->brush;
const float bstrength = fabsf(ss->cache->bstrength);
- PBVHVertexIter vd;
- // PBVHColorBufferNode *color_buffer;
+ const SculptCustomLayer *buffer_scl = data->scl;
+ const SculptCustomLayer *stroke_id_scl = data->scl2;
- SculptOrigVertData orig_data;
- SCULPT_orig_vert_data_init(&orig_data, data->ob, data->nodes[n], SCULPT_UNDO_COLOR);
- orig_data.datatype = SCULPT_UNDO_COLOR;
+ PBVHVertexIter vd;
- // co
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list