Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoseph Eagar <joeedh@gmail.com>2022-04-05 21:42:55 +0300
committerJoseph Eagar <joeedh@gmail.com>2022-04-05 21:42:55 +0300
commiteae36be372a6b16ee3e76eff0485a47da4f3c230 (patch)
treed1ca2dc30951e31f1b91eed6a4edfdfb0824bf1f /source/blender/blenkernel/intern/paint.c
parenta3e122b9aec59fc303c2375a78183cfb8642c14f (diff)
Refactor: Unify vertex and sculpt colors into new
color attribute system. This commit removes sculpt colors from experimental status and unifies it with vertex colors. It introduces the concept of "color attributes", which are any attributes that represents colors. Color attributes can be represented with byte or floating-point numbers and can be stored in either vertices or face corners. Color attributes share a common namespace (so you can no longer have a floating-point sculpt color attribute and a byte vertex color attribute with the same name). Note: this commit does not include vertex paint mode, which is a separate patch, see: https://developer.blender.org/D14179 Differential Revision: https://developer.blender.org/D12587 Ref D12587
Diffstat (limited to 'source/blender/blenkernel/intern/paint.c')
-rw-r--r--source/blender/blenkernel/intern/paint.c54
1 files changed, 50 insertions, 4 deletions
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 1c58173f570..80c3ead3039 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -29,6 +29,7 @@
#include "BLT_translation.h"
+#include "BKE_attribute.h"
#include "BKE_brush.h"
#include "BKE_ccg.h"
#include "BKE_colortools.h"
@@ -1666,7 +1667,28 @@ static void sculpt_update_object(Depsgraph *depsgraph,
ss->multires.modifier = NULL;
ss->multires.level = 0;
ss->vmask = CustomData_get_layer(&me->vdata, CD_PAINT_MASK);
- ss->vcol = CustomData_get_layer(&me->vdata, CD_PROP_COLOR);
+
+ CustomDataLayer *layer;
+ AttributeDomain domain;
+
+ if (BKE_pbvh_get_color_layer(me, &layer, &domain)) {
+ if (layer->type == CD_PROP_COLOR) {
+ ss->vcol = layer->data;
+ }
+ else {
+ ss->mcol = layer->data;
+ }
+
+ ss->vcol_domain = domain;
+ ss->vcol_type = layer->type;
+ }
+ else {
+ ss->vcol = NULL;
+ ss->mcol = NULL;
+
+ ss->vcol_type = -1;
+ ss->vcol_domain = ATTR_DOMAIN_NUM;
+ }
}
/* Sculpt Face Sets. */
@@ -1692,6 +1714,10 @@ static void sculpt_update_object(Depsgraph *depsgraph,
if (need_pmap && ob->type == OB_MESH && !ss->pmap) {
BKE_mesh_vert_poly_map_create(
&ss->pmap, &ss->pmap_mem, me->mpoly, me->mloop, me->totvert, me->totpoly, me->totloop);
+
+ if (ss->pbvh) {
+ BKE_pbvh_pmap_set(ss->pbvh, ss->pmap);
+ }
}
pbvh_show_mask_set(ss->pbvh, ss->show_mask);
@@ -1791,16 +1817,30 @@ void BKE_sculpt_update_object_after_eval(Depsgraph *depsgraph, Object *ob_eval)
void BKE_sculpt_color_layer_create_if_needed(struct Object *object)
{
Mesh *orig_me = BKE_object_get_original_mesh(object);
- if (!U.experimental.use_sculpt_vertex_colors) {
- return;
+
+ int types[] = {CD_PROP_COLOR, CD_MLOOPCOL};
+ bool has_color = false;
+
+ for (int i = 0; i < ARRAY_SIZE(types); i++) {
+ has_color = CustomData_has_layer(&orig_me->vdata, types[i]) ||
+ CustomData_has_layer(&orig_me->ldata, types[i]);
+
+ if (has_color) {
+ break;
+ }
}
- if (CustomData_has_layer(&orig_me->vdata, CD_PROP_COLOR)) {
+ if (has_color) {
return;
}
CustomData_add_layer(&orig_me->vdata, CD_PROP_COLOR, CD_DEFAULT, NULL, orig_me->totvert);
+ CustomDataLayer *layer = orig_me->vdata.layers +
+ CustomData_get_layer_index(&orig_me->vdata, CD_PROP_COLOR);
+
BKE_mesh_update_customdata_pointers(orig_me, true);
+
+ BKE_id_attributes_active_color_set(&orig_me->id, layer);
DEG_id_tag_update(&orig_me->id, ID_RECALC_GEOMETRY_ALL_MODES);
}
@@ -2173,6 +2213,10 @@ PBVH *BKE_sculpt_object_pbvh_ensure(Depsgraph *depsgraph, Object *ob)
BKE_sculpt_bvh_update_from_ccg(pbvh, subdiv_ccg);
}
}
+
+ BKE_pbvh_update_active_vcol(pbvh, BKE_object_get_original_mesh(ob));
+ BKE_pbvh_pmap_set(pbvh, ob->sculpt->pmap);
+
return pbvh;
}
@@ -2192,6 +2236,8 @@ PBVH *BKE_sculpt_object_pbvh_ensure(Depsgraph *depsgraph, Object *ob)
}
}
+ BKE_pbvh_pmap_set(pbvh, ob->sculpt->pmap);
+
ob->sculpt->pbvh = pbvh;
return pbvh;
}