[Bf-blender-cvs] [43bca12ec43] temp-sculpt-colors: Merge branch 'master' into temp-sculpt-colors
Joseph Eagar
noreply at git.blender.org
Sat Jan 29 21:54:36 CET 2022
Commit: 43bca12ec43fcc042176c4bec8ddb1f5c6383c28
Author: Joseph Eagar
Date: Fri Jan 28 17:57:42 2022 -0800
Branches: temp-sculpt-colors
https://developer.blender.org/rB43bca12ec43fcc042176c4bec8ddb1f5c6383c28
Merge branch 'master' into temp-sculpt-colors
===================================================================
===================================================================
diff --cc release/scripts/startup/bl_ui/properties_data_mesh.py
index de2bacff37f,11e2cd84903..562f522c8e5
--- a/release/scripts/startup/bl_ui/properties_data_mesh.py
+++ b/release/scripts/startup/bl_ui/properties_data_mesh.py
@@@ -695,8 -661,10 +706,9 @@@ class DATA_PT_mesh_attributes(MeshButto
layout.label(text="Name collisions: {}".format(", ".join(colliding_names)), icon='ERROR')
-classes = (
- MESH_MT_vertex_group_context_menu,
+classes = (MESH_MT_vertex_group_context_menu,
MESH_MT_shape_key_context_menu,
+ MESH_MT_attribute_context_menu,
MESH_UL_vgroups,
MESH_UL_fmaps,
MESH_UL_shape_keys,
diff --cc source/blender/draw/intern/draw_cache_extract_mesh_render_data.c
index 5abb69f6955,a47a124bd24..3439d93e362
--- a/source/blender/draw/intern/draw_cache_extract_mesh_render_data.c
+++ b/source/blender/draw/intern/draw_cache_extract_mesh_render_data.c
@@@ -454,17 -455,13 +455,19 @@@ MeshRenderData *mesh_render_data_create
copy_m4_m4(mr->obmat, obmat);
if (is_editmode) {
- BLI_assert(me->edit_mesh->mesh_eval_cage && me->edit_mesh->mesh_eval_final);
+ Mesh *editmesh_eval_final = BKE_object_get_editmesh_eval_final(object);
+ Mesh *editmesh_eval_cage = BKE_object_get_editmesh_eval_cage(object);
+
+ BLI_assert(editmesh_eval_cage && editmesh_eval_final);
mr->bm = me->edit_mesh->bm;
mr->edit_bmesh = me->edit_mesh;
- mr->me = (do_final) ? me->edit_mesh->mesh_eval_final : me->edit_mesh->mesh_eval_cage;
+
- mr->me->attributes_active_index = me->attributes_active_index;
+ mr->me = (do_final) ? editmesh_eval_final : editmesh_eval_cage;
+
+ /* needed so correct vcol layer is shown in edit mode */
+ mr->me->attr_color_active = me->attr_color_active;
+ mr->me->attr_color_render = me->attr_color_render;
+
mr->edit_data = is_mode_active ? mr->me->runtime.edit_data : NULL;
if (mr->edit_data) {
diff --cc source/blender/draw/intern/draw_cache_impl_mesh.c
index a68a6188c2c,f57921d058c..bd5db7719f8
--- a/source/blender/draw/intern/draw_cache_impl_mesh.c
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@@ -463,48 -474,29 +474,52 @@@ static void mesh_cd_calc_active_mask_uv
}
}
- static bool mesh_cd_calc_active_vcol_layer(Mesh *me, DRW_MeshAttributes *attrs_used)
-static void mesh_cd_calc_active_vcol_layer(const Object *object,
++static bool mesh_cd_calc_active_vcol_layer(const Object *object,
+ const Mesh *me,
+ DRW_MeshAttributes *attrs_used)
{
- CustomDataLayer *layer = BKE_id_attributes_active_get((ID *)me);
-
- const Mesh *me_final = editmesh_final_or_this(me);
+ const Mesh *me_final = editmesh_final_or_this(object, me);
const CustomData *cd_vdata = mesh_cd_vdata_get_from_mesh(me_final);
+ const CustomData *cd_ldata = mesh_cd_ldata_get_from_mesh(me_final);
- int layer = CustomData_get_active_layer(cd_vdata, CD_PROP_COLOR);
- if (layer != -1) {
- drw_mesh_attributes_add_request(attrs_used, CD_PROP_COLOR, layer, ATTR_DOMAIN_POINT);
++ CustomDataLayer *layer = BKE_id_attributes_active_color_get((ID *)me);
++
+ int type, layer_i = -1;
+ AttributeDomain domain;
+
+ if (layer && ELEM(layer->type, CD_PROP_COLOR, CD_MLOOPCOL)) {
+ domain = BKE_id_attribute_domain((ID *)me, layer);
+ type = layer->type;
+
+ layer_i = CustomData_get_named_layer(
+ domain == ATTR_DOMAIN_POINT ? cd_vdata : cd_ldata, type, layer->name);
+ }
+ else {
+ layer_i = CustomData_get_active_layer(cd_vdata, CD_PROP_COLOR);
+ type = CD_PROP_COLOR;
+ domain = ATTR_DOMAIN_POINT;
+ }
+
+ if (layer_i != -1) {
+ if (type != CD_MLOOPCOL) {
+ drw_mesh_attributes_add_request(attrs_used, type, layer_i, domain);
+ }
}
+
+ return layer_i != -1;
}
- static void mesh_cd_calc_active_mloopcol_layer(const Mesh *me, DRW_MeshCDMask *cd_used)
+ static void mesh_cd_calc_active_mloopcol_layer(const Object *object,
+ const Mesh *me,
+ DRW_MeshCDMask *cd_used)
{
- const Mesh *me_final = editmesh_final_or_this(me);
+ const Mesh *me_final = editmesh_final_or_this(object, me);
+ const CustomData *cd_vdata = mesh_cd_vdata_get_from_mesh(me_final);
const CustomData *cd_ldata = mesh_cd_ldata_get_from_mesh(me_final);
- int layer = CustomData_get_active_layer(cd_ldata, CD_MLOOPCOL);
+ int layer = mesh_cd_get_active_color_i(me_final, cd_vdata, cd_ldata);
if (layer != -1) {
- cd_used->vcol |= (1 << layer);
+ cd_used->vcol |= (1UL << (uint)layer);
}
}
diff --cc source/blender/editors/geometry/geometry_attributes.cc
index 201a145111b,17229c4898e..ce5a2332f95
--- a/source/blender/editors/geometry/geometry_attributes.cc
+++ b/source/blender/editors/geometry/geometry_attributes.cc
@@@ -21,10 -21,18 +21,20 @@@
* \ingroup edgeometry
*/
+ #include "MEM_guardedalloc.h"
+
+ #include "DNA_mesh_types.h"
+ #include "DNA_meshdata_types.h"
+ #include "DNA_scene_types.h"
+
+#include "BLI_math.h"
+
#include "BKE_attribute.h"
#include "BKE_context.h"
+ #include "BKE_deform.h"
+ #include "BKE_geometry_set.hh"
+ #include "BKE_object_deform.h"
+ #include "BKE_report.h"
#include "RNA_access.h"
#include "RNA_define.h"
@@@ -212,129 -200,188 +231,315 @@@ void GEOMETRY_OT_attribute_remove(wmOpe
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
+static int geometry_color_attribute_add_exec(bContext *C, wmOperator *op)
+{
+ Object *ob = ED_object_context(C);
+ ID *id = static_cast<ID *>(ob->data);
+
+ char name[MAX_NAME];
+ RNA_string_get(op->ptr, "name", name);
+ CustomDataType type = (CustomDataType)RNA_enum_get(op->ptr, "data_type");
+ AttributeDomain domain = (AttributeDomain)RNA_enum_get(op->ptr, "domain");
+ CustomDataLayer *layer = BKE_id_attribute_new(
+ id, name, type, domain, CD_MASK_PROP_ALL, op->reports);
+
+ if (layer == NULL) {
+ return OPERATOR_CANCELLED;
+ }
+
+ BKE_id_attributes_active_color_set(id, layer);
+
+ if (!BKE_id_attributes_render_color_get(id)) {
+ BKE_id_attributes_render_color_set(id, layer);
+ }
+
+ DEG_id_tag_update(id, ID_RECALC_GEOMETRY);
+ WM_main_add_notifier(NC_GEOM | ND_DATA, id);
+
+ return OPERATOR_FINISHED;
+}
+
+ enum class ConvertAttributeMode {
+ Generic,
+ UVMap,
+ VertexGroup,
+ VertexColor,
+ };
+
+ static bool geometry_attribute_convert_poll(bContext *C)
+ {
+ if (!geometry_attributes_poll(C)) {
+ return false;
+ }
+
+ Object *ob = ED_object_context(C);
+ ID *data = static_cast<ID *>(ob->data);
+ if (GS(data->name) != ID_ME) {
+ return false;
+ }
+ CustomDataLayer *layer = BKE_id_attributes_active_get(data);
+ if (layer == nullptr) {
+ return false;
+ }
+ return true;
+ }
+
+ static int geometry_attribute_convert_exec(bContext *C, wmOperator *op)
+ {
+ Object *ob = ED_object_context(C);
+ ID *ob_data = static_cast<ID *>(ob->data);
+ CustomDataLayer *layer = BKE_id_attributes_active_get(ob_data);
+ const std::string name = layer->name;
+
+ const ConvertAttributeMode mode = static_cast<ConvertAttributeMode>(
+ RNA_enum_get(op->ptr, "mode"));
+
+ Mesh *mesh = reinterpret_cast<Mesh *>(ob_data);
+ MeshComponent mesh_component;
+ mesh_component.replace(mesh, GeometryOwnershipType::Editable);
+
+ /* General conversion steps are always the same:
+ * 1. Convert old data to right domain and data type.
+ * 2. Copy the data into a new array so that it does not depend on the old attribute anymore.
+ * 3. Delete the old attribute.
+ * 4. Create a new attribute based on the previously copied data. */
+ switch (mode) {
+ case ConvertAttributeMode::Generic: {
+ const AttributeDomain dst_domain = static_cast<AttributeDomain>(
+ RNA_enum_get(op->ptr, "domain"));
+ const CustomDataType dst_type = static_cast<CustomDataType>(
+ RNA_enum_get(op->ptr, "data_type"));
+
+ if (ELEM(dst_type, CD_PROP_STRING, CD_MLOOPCOL)) {
+ BKE_report(op->reports, RPT_ERROR, "Cannot convert to the selected type");
+ return OPERATOR_CANCELLED;
+ }
+
+ GVArray src_varray = mesh_component.attribute_get_for_read(name, dst_domain, dst_type);
+ const CPPType &cpp_type = src_varray.type();
+ void *new_data = MEM_malloc_arrayN(src_varray.size(), cpp_type.size(), __func__);
+ src_varray.materialize_to_uninitialized(new_data);
+ mesh_component.attribute_try_delete(name);
+ mesh_component.attribute_try_create(name, dst_domain, dst_type, AttributeInitMove(new_data));
+ break;
+ }
+ case ConvertAttributeMode::UVMap: {
+ MLoopUV *dst_uvs = static_cast<MLoopUV *>(
+ MEM_calloc_arrayN(mesh->totloop, sizeof(MLoopUV), __func__));
+ VArray<float2> src_varray = mesh_component.attribute_get_for_read<float2>(
+ name, ATTR_DOMAIN_CORNER, {0.0f, 0.0f});
+ for (const int i : IndexRange(mesh->totloop)) {
+ copy_v2_v2(dst_uvs[i].uv, src_varray[i]);
+ }
+ mesh_component.attribute_try_delete(name);
+ CustomData_add_layer_named(
+ &mesh->ldata, CD_MLOOPUV, CD_ASSIGN, dst_uvs, mesh->totloop, name.c_str());
+ break;
+ }
+ case ConvertAttributeMode::VertexColor: {
+ MLoopCol *dst_colors = static_cast<MLoopCol *>(
+ MEM_calloc_arrayN(mesh->totloop, sizeof(MLoopCol), __func__));
+ VArray<ColorGeometry4f> src_varray = mesh_component.attribute_get_for_read<ColorGeometry4f>(
+ name, ATTR_DOMAIN_CORNER, ColorGeometry4f{0.0f, 0.0f, 0.0f, 1.0f});
+ for (const int i : IndexRange(mesh->totloop)) {
+ ColorGeometry4b encoded_color = src_varray[i].encode();
+ copy_v4_v4_uchar(&dst_colors[i].r, &encoded_color.r);
+ }
+ mesh_component.attribute_try_delete(name);
+ CustomData_add_layer_named(
+ &mesh->ldata, CD_MLOOPCOL, CD_ASSIGN, dst_colors, mesh->totloop, name.c_str());
+ break;
+ }
+ case ConvertAttributeMode::VertexGroup: {
+ Array<float> src_weights(mesh->totvert);
+ VArr
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list