From b20ecee5556dc73a920773664ee2800256598ca4 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 16 Jul 2025 18:26:26 +0200 Subject: [PATCH] Mesh: Move freestyle tags to generic attributes This commit moves the freestyle edge and face mark tags to become generic attributes, similar to other changes over the past years. The attributes are called "freestyle_edge" and "freestyle_face", and they're now propagated like regular boolean attributes. Compatibility wise, forward and backward blend file compatibility are maintained (for forward compatibility this is implemented a bit differently than in the past because of the ongoing `AttributeStorage` transition). In the Python API, `use_freestyle_mark` has been removed; the attribute API should be used instead (just like bevel weights). The BMesh (`freestyle`) accessors are removed too. The conversions benefit from the fact that bit-wise, the old structs are the same as `bool`, so we can convert to the old and new formats without reallocating arrays. Pull Request: https://projects.blender.org/blender/blender/pulls/141996 --- scripts/startup/bl_operators/freestyle.py | 4 +- .../blenkernel/BKE_mesh_legacy_convert.hh | 11 ++ .../intern/attribute_legacy_convert.cc | 4 +- .../blender/blenkernel/intern/customdata.cc | 42 ++----- .../blenkernel/intern/data_transfer.cc | 51 ++++++-- .../blenkernel/intern/data_transfer_intern.hh | 2 + source/blender/blenkernel/intern/mesh.cc | 4 + .../blenkernel/intern/mesh_legacy_convert.cc | 112 ++++++++++++++++++ .../blenkernel/intern/object_update.cc | 7 -- .../blenloader/intern/versioning_500.cc | 6 + .../draw_cache_extract_mesh_render_data.cc | 6 +- .../intern/mesh_extractors/extract_mesh.cc | 4 +- .../extract_mesh_vbo_edit_data.cc | 4 +- source/blender/editors/mesh/editmesh_path.cc | 20 +--- .../editors/mesh/editmesh_select_similar.cc | 55 +++++---- source/blender/editors/mesh/editmesh_tools.cc | 30 ++--- .../blender_interface/BlenderFileLoader.cpp | 19 +-- .../geometry/intern/mesh_split_edges.cc | 1 - .../blender/makesdna/DNA_customdata_types.h | 4 +- source/blender/makesdna/DNA_meshdata_types.h | 4 +- source/blender/makesrna/intern/rna_mesh.cc | 70 ----------- .../modifiers/intern/lineart/lineart_cpu.cc | 40 ++----- .../geometry/nodes/node_geo_extrude_mesh.cc | 17 --- .../python/bmesh/bmesh_py_types_customdata.cc | 15 --- 24 files changed, 265 insertions(+), 267 deletions(-) diff --git a/scripts/startup/bl_operators/freestyle.py b/scripts/startup/bl_operators/freestyle.py index 1145c4943c6..bd61ec00fe9 100644 --- a/scripts/startup/bl_operators/freestyle.py +++ b/scripts/startup/bl_operators/freestyle.py @@ -147,7 +147,7 @@ class SCENE_OT_freestyle_add_edge_marks_to_keying_set(Operator): bpy.ops.object.mode_set(mode='OBJECT', toggle=False) for i, edge in enumerate(mesh.edges): if not edge.hide and edge.select: - path = "edges[{:d}].use_freestyle_mark".format(i) + path = "attributes[\"freestyle_edge\"].data[{:d}].value".format(i) ks.paths.add(mesh, path, index=0) bpy.ops.object.mode_set(mode=ob_mode, toggle=False) return {'FINISHED'} @@ -178,7 +178,7 @@ class SCENE_OT_freestyle_add_face_marks_to_keying_set(Operator): bpy.ops.object.mode_set(mode='OBJECT', toggle=False) for i, polygon in enumerate(mesh.polygons): if not polygon.hide and polygon.select: - path = "polygons[{:d}].use_freestyle_mark".format(i) + path = "attributes[\"freestyle_face\"].data[{:d}].value".format(i) ks.paths.add(mesh, path, index=0) bpy.ops.object.mode_set(mode=ob_mode, toggle=False) return {'FINISHED'} diff --git a/source/blender/blenkernel/BKE_mesh_legacy_convert.hh b/source/blender/blenkernel/BKE_mesh_legacy_convert.hh index af46feb0a3b..bd70d06fc61 100644 --- a/source/blender/blenkernel/BKE_mesh_legacy_convert.hh +++ b/source/blender/blenkernel/BKE_mesh_legacy_convert.hh @@ -8,6 +8,10 @@ * \ingroup bke */ +#include "BKE_attribute_storage.hh" + +#include "BLI_vector.hh" + struct CustomData; struct Main; struct Mesh; @@ -20,6 +24,13 @@ void mesh_custom_normals_to_generic(Mesh &mesh); void mesh_sculpt_mask_to_generic(Mesh &mesh); +void mesh_freestyle_marks_to_generic(Mesh &mesh); +void mesh_freestyle_marks_to_legacy(AttributeStorage::BlendWriteData &attr_write_data, + CustomData &edge_data, + CustomData &face_data, + Vector &edge_layers, + Vector &face_layers); + } // namespace blender::bke void BKE_mesh_legacy_convert_uvs_to_generic(Mesh *mesh); diff --git a/source/blender/blenkernel/intern/attribute_legacy_convert.cc b/source/blender/blenkernel/intern/attribute_legacy_convert.cc index 07fb066f650..84af41053b4 100644 --- a/source/blender/blenkernel/intern/attribute_legacy_convert.cc +++ b/source/blender/blenkernel/intern/attribute_legacy_convert.cc @@ -41,6 +41,8 @@ std::optional custom_data_type_to_attr_type(const eCustomDataType data case CD_SCULPT_FACE_SETS: case CD_MTFACE: case CD_TESSLOOPNORMAL: + case CD_FREESTYLE_EDGE: + case CD_FREESTYLE_FACE: /* These types are only used for versioning old files. */ return std::nullopt; case CD_SHAPEKEY: @@ -61,8 +63,6 @@ std::optional custom_data_type_to_attr_type(const eCustomDataType data case CD_ORIGSPACE_MLOOP: case CD_GRID_PAINT_MASK: case CD_MVERT_SKIN: - case CD_FREESTYLE_EDGE: - case CD_FREESTYLE_FACE: case CD_MLOOPTANGENT: /* These types are not generic. They will either be moved to some generic data type or * #AttributeStorage will be extended to be able to support a similar format. */ diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc index 9329e383d61..318e4ee2036 100644 --- a/source/blender/blenkernel/intern/customdata.cc +++ b/source/blender/blenkernel/intern/customdata.cc @@ -1940,28 +1940,10 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = { layerInterp_mvert_skin, nullptr, layerDefault_mvert_skin}, - /* 37: CD_FREESTYLE_EDGE */ - {sizeof(FreestyleEdge), - alignof(FreestyleEdge), - "FreestyleEdge", - 1, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr}, - /* 38: CD_FREESTYLE_FACE */ - {sizeof(FreestyleFace), - alignof(FreestyleFace), - "FreestyleFace", - 1, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr}, + /* 37: CD_FREESTYLE_EDGE */ /* DEPRECATED */ + {sizeof(FreestyleEdge), alignof(FreestyleEdge), "FreestyleEdge", 1}, + /* 38: CD_FREESTYLE_FACE */ /* DEPRECATED */ + {sizeof(FreestyleFace), alignof(FreestyleFace), "FreestyleFace", 1}, /* 39: CD_MLOOPTANGENT */ {sizeof(float[4]), alignof(float[4]), @@ -2208,10 +2190,10 @@ const CustomData_MeshMasks CD_MASK_BAREMESH_ORIGINDEX = { const CustomData_MeshMasks CD_MASK_MESH = { /*vmask*/ (CD_MASK_PROP_FLOAT3 | CD_MASK_MDEFORMVERT | CD_MASK_MVERT_SKIN | CD_MASK_PROP_ALL), /*emask*/ - (CD_MASK_FREESTYLE_EDGE | CD_MASK_PROP_ALL), + CD_MASK_PROP_ALL, /*fmask*/ 0, /*pmask*/ - (CD_MASK_FREESTYLE_FACE | CD_MASK_PROP_ALL), + CD_MASK_PROP_ALL, /*lmask*/ (CD_MASK_MDISPS | CD_MASK_GRID_PAINT_MASK | CD_MASK_PROP_ALL), }; @@ -2219,20 +2201,20 @@ const CustomData_MeshMasks CD_MASK_DERIVEDMESH = { /*vmask*/ (CD_MASK_ORIGINDEX | CD_MASK_MDEFORMVERT | CD_MASK_SHAPEKEY | CD_MASK_MVERT_SKIN | CD_MASK_ORCO | CD_MASK_CLOTH_ORCO | CD_MASK_PROP_ALL), /*emask*/ - (CD_MASK_ORIGINDEX | CD_MASK_FREESTYLE_EDGE | CD_MASK_PROP_ALL), + (CD_MASK_ORIGINDEX | CD_MASK_PROP_ALL), /*fmask*/ (CD_MASK_ORIGINDEX | CD_MASK_ORIGSPACE | CD_MASK_TANGENT), /*pmask*/ - (CD_MASK_ORIGINDEX | CD_MASK_FREESTYLE_FACE | CD_MASK_PROP_ALL), + (CD_MASK_ORIGINDEX | CD_MASK_PROP_ALL), /*lmask*/ (CD_MASK_ORIGSPACE_MLOOP | CD_MASK_PROP_ALL), /* XXX: MISSING #CD_MASK_MLOOPTANGENT ? */ }; const CustomData_MeshMasks CD_MASK_BMESH = { /*vmask*/ (CD_MASK_MDEFORMVERT | CD_MASK_MVERT_SKIN | CD_MASK_SHAPEKEY | CD_MASK_SHAPE_KEYINDEX | CD_MASK_PROP_ALL), - /*emask*/ (CD_MASK_FREESTYLE_EDGE | CD_MASK_PROP_ALL), + /*emask*/ CD_MASK_PROP_ALL, /*fmask*/ 0, /*pmask*/ - (CD_MASK_FREESTYLE_FACE | CD_MASK_PROP_ALL), + CD_MASK_PROP_ALL, /*lmask*/ (CD_MASK_MDISPS | CD_MASK_GRID_PAINT_MASK | CD_MASK_PROP_ALL), }; @@ -2241,12 +2223,12 @@ const CustomData_MeshMasks CD_MASK_EVERYTHING = { CD_MASK_MVERT_SKIN | CD_MASK_ORCO | CD_MASK_CLOTH_ORCO | CD_MASK_SHAPEKEY | CD_MASK_SHAPE_KEYINDEX | CD_MASK_PROP_ALL), /*emask*/ - (CD_MASK_BM_ELEM_PYPTR | CD_MASK_ORIGINDEX | CD_MASK_FREESTYLE_EDGE | CD_MASK_PROP_ALL), + (CD_MASK_BM_ELEM_PYPTR | CD_MASK_ORIGINDEX | CD_MASK_PROP_ALL), /*fmask*/ (CD_MASK_MFACE | CD_MASK_ORIGINDEX | CD_MASK_NORMAL | CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_ORIGSPACE | CD_MASK_TANGENT | CD_MASK_TESSLOOPNORMAL | CD_MASK_PROP_ALL), /*pmask*/ - (CD_MASK_BM_ELEM_PYPTR | CD_MASK_ORIGINDEX | CD_MASK_FREESTYLE_FACE | CD_MASK_PROP_ALL), + (CD_MASK_BM_ELEM_PYPTR | CD_MASK_ORIGINDEX | CD_MASK_PROP_ALL), /*lmask*/ (CD_MASK_BM_ELEM_PYPTR | CD_MASK_MDISPS | CD_MASK_NORMAL | CD_MASK_MLOOPTANGENT | CD_MASK_ORIGSPACE_MLOOP | CD_MASK_GRID_PAINT_MASK | CD_MASK_PROP_ALL), diff --git a/source/blender/blenkernel/intern/data_transfer.cc b/source/blender/blenkernel/intern/data_transfer.cc index 38fbc402114..b3413681fd2 100644 --- a/source/blender/blenkernel/intern/data_transfer.cc +++ b/source/blender/blenkernel/intern/data_transfer.cc @@ -201,14 +201,14 @@ int BKE_object_data_transfer_dttype_to_cdtype(const int dtdata_type) case DT_TYPE_BWEIGHT_EDGE: return CD_FAKE_BWEIGHT; case DT_TYPE_FREESTYLE_EDGE: - return CD_FREESTYLE_EDGE; + return CD_FAKE_FREESTYLE_EDGE; case DT_TYPE_UV: return CD_FAKE_UV; case DT_TYPE_SHARP_FACE: return CD_FAKE_SHARP; case DT_TYPE_FREESTYLE_FACE: - return CD_FREESTYLE_FACE; + return CD_FAKE_FREESTYLE_FACE; case DT_TYPE_LNOR: return CD_FAKE_LNOR; case DT_TYPE_MLOOPCOL_VERT: @@ -503,15 +503,6 @@ static void data_transfer_layersmapping_add_item_cd(ListBase *r_map, cd_datatransfer_interp interp, void *interp_data) { - uint64_t data_flag = 0; - - if (cddata_type == CD_FREESTYLE_EDGE) { - data_flag = FREESTYLE_EDGE_MARK; - } - else if (cddata_type == CD_FREESTYLE_FACE) { - data_flag = FREESTYLE_FACE_MARK; - } - data_transfer_layersmapping_add_item(r_map, cddata_type, mix_mode, @@ -524,7 +515,7 @@ static void data_transfer_layersmapping_add_item_cd(ListBase *r_map, 0, 0, 0, - data_flag, + 0, interp, interp_data); } @@ -1035,6 +1026,24 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map, interp_data); return true; } + if (r_map && cddata_type == CD_FAKE_FREESTYLE_EDGE) { + if (!CustomData_get_layer_named(&me_dst->edge_data, CD_PROP_BOOL, "freestyle_edge")) { + CustomData_add_layer_named( + &me_dst->edge_data, CD_PROP_BOOL, CD_SET_DEFAULT, me_dst->edges_num, "freestyle_edge"); + } + data_transfer_layersmapping_add_item_cd( + r_map, + CD_PROP_BOOL, + mix_mode, + mix_factor, + mix_weights, + CustomData_get_layer_named(&me_src->edge_data, CD_PROP_BOOL, "freestyle_edge"), + CustomData_get_layer_named_for_write( + &me_dst->edge_data, CD_PROP_BOOL, "freestyle_edge", me_dst->edges_num), + interp, + interp_data); + return true; + } return false; } @@ -1137,6 +1146,24 @@ static bool data_transfer_layersmapping_generate(ListBase *r_map, interp_data); return true; } + if (r_map && cddata_type == CD_FAKE_FREESTYLE_FACE) { + if (!CustomData_has_layer_named(&me_dst->face_data, CD_PROP_BOOL, "freestyle_face")) { + CustomData_add_layer_named( + &me_dst->face_data, CD_PROP_BOOL, CD_SET_DEFAULT, me_dst->faces_num, "freestyle_face"); + } + data_transfer_layersmapping_add_item_cd( + r_map, + CD_PROP_BOOL, + mix_mode, + mix_factor, + mix_weights, + CustomData_get_layer_named(&me_src->face_data, CD_PROP_BOOL, "freestyle_face"), + CustomData_get_layer_named_for_write( + &me_dst->face_data, CD_PROP_BOOL, "freestyle_face", me_dst->faces_num), + interp, + interp_data); + return true; + } return false; } diff --git a/source/blender/blenkernel/intern/data_transfer_intern.hh b/source/blender/blenkernel/intern/data_transfer_intern.hh index 39d7804abae..cf0ed95935b 100644 --- a/source/blender/blenkernel/intern/data_transfer_intern.hh +++ b/source/blender/blenkernel/intern/data_transfer_intern.hh @@ -42,6 +42,8 @@ enum { CD_FAKE_BWEIGHT = CD_FAKE | 300, CD_FAKE_CREASE = CD_FAKE | 400, + CD_FAKE_FREESTYLE_EDGE = CD_FAKE | 500, + CD_FAKE_FREESTYLE_FACE = CD_FAKE | 600, }; float data_transfer_interp_float_do(int mix_mode, float val_dst, float val_src, float mix_factor); diff --git a/source/blender/blenkernel/intern/mesh.cc b/source/blender/blenkernel/intern/mesh.cc index 65730547df2..35f0455d262 100644 --- a/source/blender/blenkernel/intern/mesh.cc +++ b/source/blender/blenkernel/intern/mesh.cc @@ -357,6 +357,10 @@ static void mesh_blend_write(BlendWriter *writer, ID *id, const void *id_address mesh->face_data, AttrDomain::Face, mesh->faces_num, face_layers, attribute_data); CustomData_blend_write_prepare( mesh->corner_data, AttrDomain::Corner, mesh->corners_num, loop_layers, attribute_data); + if (!is_undo) { + mesh_freestyle_marks_to_legacy( + attribute_data, mesh->edge_data, mesh->face_data, edge_layers, face_layers); + } if (attribute_data.attributes.is_empty()) { mesh->attribute_storage.dna_attributes = nullptr; mesh->attribute_storage.dna_attributes_num = 0; diff --git a/source/blender/blenkernel/intern/mesh_legacy_convert.cc b/source/blender/blenkernel/intern/mesh_legacy_convert.cc index 3526799a3eb..563a2e938bd 100644 --- a/source/blender/blenkernel/intern/mesh_legacy_convert.cc +++ b/source/blender/blenkernel/intern/mesh_legacy_convert.cc @@ -2489,6 +2489,118 @@ void mesh_sculpt_mask_to_generic(Mesh &mesh) } } +void mesh_freestyle_marks_to_generic(Mesh &mesh) +{ + { + void *data = nullptr; + const ImplicitSharingInfo *sharing_info = nullptr; + for (const int i : IndexRange(mesh.edge_data.totlayer)) { + CustomDataLayer &layer = mesh.edge_data.layers[i]; + if (layer.type == CD_FREESTYLE_EDGE) { + data = layer.data; + sharing_info = layer.sharing_info; + layer.data = nullptr; + layer.sharing_info = nullptr; + CustomData_free_layer(&mesh.edge_data, CD_FREESTYLE_EDGE, i); + break; + } + } + if (data != nullptr) { + static_assert(sizeof(FreestyleEdge) == sizeof(bool)); + static_assert(char(FREESTYLE_EDGE_MARK) == char(true)); + CustomData_add_layer_named_with_data( + &mesh.edge_data, CD_PROP_BOOL, data, mesh.edges_num, "freestyle_edge", sharing_info); + } + if (sharing_info != nullptr) { + sharing_info->remove_user_and_delete_if_last(); + } + } + { + void *data = nullptr; + const ImplicitSharingInfo *sharing_info = nullptr; + for (const int i : IndexRange(mesh.face_data.totlayer)) { + CustomDataLayer &layer = mesh.face_data.layers[i]; + if (layer.type == CD_FREESTYLE_FACE) { + data = layer.data; + sharing_info = layer.sharing_info; + layer.data = nullptr; + layer.sharing_info = nullptr; + CustomData_free_layer(&mesh.face_data, CD_FREESTYLE_FACE, i); + break; + } + } + if (data != nullptr) { + static_assert(sizeof(FreestyleFace) == sizeof(bool)); + static_assert(char(FREESTYLE_FACE_MARK) == char(true)); + CustomData_add_layer_named_with_data( + &mesh.face_data, CD_PROP_BOOL, data, mesh.faces_num, "freestyle_face", sharing_info); + } + if (sharing_info != nullptr) { + sharing_info->remove_user_and_delete_if_last(); + } + } +} + +void mesh_freestyle_marks_to_legacy(AttributeStorage::BlendWriteData &attr_write_data, + CustomData &edge_data, + CustomData &face_data, + Vector &edge_layers, + Vector &face_layers) +{ + Array attrs_to_remove(attr_write_data.attributes.size(), false); + for (const int i : attr_write_data.attributes.index_range()) { + const ::Attribute &dna_attr = attr_write_data.attributes[i]; + if (dna_attr.data_type != int8_t(AttrType::Bool)) { + continue; + } + if (dna_attr.storage_type != int8_t(AttrStorageType::Array)) { + continue; + } + if (dna_attr.domain == int8_t(AttrDomain::Edge)) { + if (STREQ(dna_attr.name, "freestyle_edge")) { + const auto &array_dna = *static_cast(dna_attr.data); + static_assert(sizeof(FreestyleEdge) == sizeof(bool)); + static_assert(char(FREESTYLE_EDGE_MARK) == char(true)); + CustomDataLayer layer{}; + layer.type = CD_FREESTYLE_EDGE; + layer.data = array_dna.data; + layer.sharing_info = array_dna.sharing_info; + edge_layers.append(layer); + std::stable_sort( + edge_layers.begin(), + edge_layers.end(), + [](const CustomDataLayer &a, const CustomDataLayer &b) { return a.type < b.type; }); + edge_data.totlayer = edge_layers.size(); + edge_data.maxlayer = edge_data.totlayer; + attrs_to_remove[i] = true; + } + } + else if (dna_attr.domain == int8_t(AttrDomain::Face)) { + if (STREQ(dna_attr.name, "freestyle_face")) { + const auto &array_dna = *static_cast(dna_attr.data); + static_assert(sizeof(FreestyleFace) == sizeof(bool)); + static_assert(char(FREESTYLE_FACE_MARK) == char(true)); + CustomDataLayer layer{}; + layer.type = CD_FREESTYLE_FACE; + layer.data = array_dna.data; + layer.sharing_info = array_dna.sharing_info; + face_layers.append(layer); + std::stable_sort( + face_layers.begin(), + face_layers.end(), + [](const CustomDataLayer &a, const CustomDataLayer &b) { return a.type < b.type; }); + face_data.totlayer = face_layers.size(); + face_data.maxlayer = face_data.totlayer; + attrs_to_remove[i] = true; + } + } + } + attr_write_data.attributes.remove_if([&](const ::Attribute &attr) { + const int i = &attr - attr_write_data.attributes.begin(); + return attrs_to_remove[i]; + }); +} + void mesh_custom_normals_to_generic(Mesh &mesh) { if (mesh.attributes().contains("custom_normal")) { diff --git a/source/blender/blenkernel/intern/object_update.cc b/source/blender/blenkernel/intern/object_update.cc index 648f6c4599d..42d8cc4745a 100644 --- a/source/blender/blenkernel/intern/object_update.cc +++ b/source/blender/blenkernel/intern/object_update.cc @@ -142,13 +142,6 @@ void BKE_object_handle_data_update(Depsgraph *depsgraph, Scene *scene, Object *o cddata_masks.fmask |= CD_MASK_PROP_ALL; cddata_masks.pmask |= CD_MASK_PROP_ALL; cddata_masks.lmask |= CD_MASK_PROP_ALL; - - /* Make sure Freestyle edge/face marks appear in evaluated mesh (see #40315). - * Due to Line Art implementation, edge marks should also be shown in viewport. */ -#ifdef WITH_FREESTYLE - cddata_masks.emask |= CD_MASK_FREESTYLE_EDGE; - cddata_masks.pmask |= CD_MASK_FREESTYLE_FACE; -#endif if (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER) { /* Always compute orcos for render. */ cddata_masks.vmask |= CD_MASK_ORCO; diff --git a/source/blender/blenloader/intern/versioning_500.cc b/source/blender/blenloader/intern/versioning_500.cc index 53ab360a8c0..1636ee929bc 100644 --- a/source/blender/blenloader/intern/versioning_500.cc +++ b/source/blender/blenloader/intern/versioning_500.cc @@ -1505,4 +1505,10 @@ void blo_do_versions_500(FileData * /*fd*/, Library * /*lib*/, Main *bmain) * * \note Keep this message at the bottom of the function. */ + + /* Keep this versioning always enabled at the bottom of the function; it can only be moved behind + * a subversion bump when the file format is changed. */ + LISTBASE_FOREACH (Mesh *, mesh, &bmain->meshes) { + bke::mesh_freestyle_marks_to_generic(*mesh); + } } diff --git a/source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc b/source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc index 8bb3d6f4202..f9037732bc6 100644 --- a/source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc +++ b/source/blender/draw/intern/draw_cache_extract_mesh_render_data.cc @@ -590,8 +590,10 @@ MeshRenderData mesh_render_data_create(Object &object, mr.bweight_ofs = CustomData_get_offset_named( &mr.bm->edata, CD_PROP_FLOAT, "bevel_weight_edge"); #ifdef WITH_FREESTYLE - mr.freestyle_edge_ofs = CustomData_get_offset(&mr.bm->edata, CD_FREESTYLE_EDGE); - mr.freestyle_face_ofs = CustomData_get_offset(&mr.bm->pdata, CD_FREESTYLE_FACE); + mr.freestyle_edge_ofs = CustomData_get_offset_named( + &mr.bm->edata, CD_PROP_BOOL, "freestyle_edge"); + mr.freestyle_face_ofs = CustomData_get_offset_named( + &mr.bm->pdata, CD_PROP_BOOL, "freestyle_face"); #endif /* Use bmesh directly when the object is unchanged by any modifiers. For non-final UVs, always diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh.cc index 60868d4db4b..a186f5d0090 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh.cc @@ -43,9 +43,7 @@ void mesh_render_data_face_flag(const MeshRenderData &mr, #ifdef WITH_FREESTYLE if (mr.freestyle_face_ofs != -1) { - const FreestyleFace *ffa = (const FreestyleFace *)BM_ELEM_CD_GET_VOID_P(efa, - mr.freestyle_face_ofs); - if (ffa->flag & FREESTYLE_FACE_MARK) { + if (BM_ELEM_CD_GET_BOOL(efa, mr.freestyle_face_ofs)) { eattr.v_flag |= VFLAG_FACE_FREESTYLE; } } diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc index ece084fd0e7..a2b89d5a2c7 100644 --- a/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc +++ b/source/blender/draw/intern/mesh_extractors/extract_mesh_vbo_edit_data.cc @@ -72,9 +72,7 @@ static void mesh_render_data_edge_flag(const MeshRenderData &mr, } #ifdef WITH_FREESTYLE if (mr.freestyle_edge_ofs != -1) { - const FreestyleEdge *fed = (const FreestyleEdge *)BM_ELEM_CD_GET_VOID_P(eed, - mr.freestyle_edge_ofs); - if (fed->flag & FREESTYLE_EDGE_MARK) { + if (BM_ELEM_CD_GET_BOOL(eed, mr.freestyle_edge_ofs)) { eattr.e_flag |= VFLAG_EDGE_FREESTYLE; } } diff --git a/source/blender/editors/mesh/editmesh_path.cc b/source/blender/editors/mesh/editmesh_path.cc index a22b98f0733..8f4c6a53688 100644 --- a/source/blender/editors/mesh/editmesh_path.cc +++ b/source/blender/editors/mesh/editmesh_path.cc @@ -307,10 +307,7 @@ static bool edgetag_test_cb(BMEdge *e, void *user_data_v) return BM_ELEM_CD_GET_FLOAT(e, user_data->cd_offset); #ifdef WITH_FREESTYLE case EDGE_MODE_TAG_FREESTYLE: { - BMesh *bm = user_data->bm; - FreestyleEdge *fed = static_cast( - CustomData_bmesh_get(&bm->edata, e->head.data, CD_FREESTYLE_EDGE)); - return (!fed) ? false : (fed->flag & FREESTYLE_EDGE_MARK) ? true : false; + return BM_ELEM_CD_GET_BOOL(e, user_data->cd_offset); } #endif } @@ -338,15 +335,7 @@ static void edgetag_set_cb(BMEdge *e, bool val, void *user_data_v) break; #ifdef WITH_FREESTYLE case EDGE_MODE_TAG_FREESTYLE: { - FreestyleEdge *fed; - fed = static_cast( - CustomData_bmesh_get(&bm->edata, e->head.data, CD_FREESTYLE_EDGE)); - if (!val) { - fed->flag &= ~FREESTYLE_EDGE_MARK; - } - else { - fed->flag |= FREESTYLE_EDGE_MARK; - } + BM_ELEM_CD_SET_BOOL(e, user_data->cd_offset, val); break; } #endif @@ -370,8 +359,8 @@ static void edgetag_ensure_cd_flag(Mesh *mesh, const char edge_mode) break; #ifdef WITH_FREESTYLE case EDGE_MODE_TAG_FREESTYLE: - if (!CustomData_has_layer(&bm->edata, CD_FREESTYLE_EDGE)) { - BM_data_layer_add(bm, &bm->edata, CD_FREESTYLE_EDGE); + if (!CustomData_has_layer_named(&bm->edata, CD_PROP_BOOL, "freestyle_edge")) { + BM_data_layer_add_named(bm, &bm->edata, CD_PROP_BOOL, "freestyle_edge"); } break; #endif @@ -396,6 +385,7 @@ static void mouse_mesh_shortest_path_edge( case EDGE_MODE_TAG_SHARP: #ifdef WITH_FREESTYLE case EDGE_MODE_TAG_FREESTYLE: + cd_offset = CustomData_get_offset_named(&bm->edata, CD_PROP_BOOL, "freestyle_edge"); #endif break; case EDGE_MODE_TAG_CREASE: diff --git a/source/blender/editors/mesh/editmesh_select_similar.cc b/source/blender/editors/mesh/editmesh_select_similar.cc index 76563e20ff5..61e79f6e34e 100644 --- a/source/blender/editors/mesh/editmesh_select_similar.cc +++ b/source/blender/editors/mesh/editmesh_select_similar.cc @@ -210,6 +210,7 @@ static wmOperatorStatus similar_face_select_exec(bContext *C, wmOperator *op) float ob_m3[3][3]; copy_m3_m4(ob_m3, ob->object_to_world().ptr()); + int custom_data_offset = -1; switch (type) { case SIMFACE_MATERIAL: { if (ob->totcol == 0) { @@ -219,7 +220,9 @@ static wmOperatorStatus similar_face_select_exec(bContext *C, wmOperator *op) break; } case SIMFACE_FREESTYLE: { - if (!CustomData_has_layer(&bm->pdata, CD_FREESTYLE_FACE)) { + custom_data_offset = CustomData_get_offset_named( + &bm->pdata, CD_PROP_BOOL, "freestyle_face"); + if (custom_data_offset == -1) { face_data_value |= SIMFACE_DATA_FALSE; continue; } @@ -274,10 +277,7 @@ static wmOperatorStatus similar_face_select_exec(bContext *C, wmOperator *op) break; } case SIMFACE_FREESTYLE: { - FreestyleFace *fface; - fface = static_cast( - CustomData_bmesh_get(&bm->pdata, face->head.data, CD_FREESTYLE_FACE)); - if ((fface == nullptr) || ((fface->flag & FREESTYLE_FACE_MARK) == 0)) { + if (custom_data_offset == -1 || !BM_ELEM_CD_GET_BOOL(face, custom_data_offset)) { face_data_value |= SIMFACE_DATA_FALSE; } else { @@ -317,7 +317,7 @@ static wmOperatorStatus similar_face_select_exec(bContext *C, wmOperator *op) float ob_m3[3][3]; copy_m3_m4(ob_m3, ob->object_to_world().ptr()); - bool has_custom_data_layer = false; + int custom_data_offset = -1; switch (type) { case SIMFACE_MATERIAL: { if (ob->totcol == 0) { @@ -327,8 +327,9 @@ static wmOperatorStatus similar_face_select_exec(bContext *C, wmOperator *op) break; } case SIMFACE_FREESTYLE: { - has_custom_data_layer = CustomData_has_layer(&bm->pdata, CD_FREESTYLE_FACE); - if ((face_data_value == SIMFACE_DATA_TRUE) && !has_custom_data_layer) { + custom_data_offset = CustomData_get_offset_named( + &bm->pdata, CD_PROP_BOOL, "freestyle_face"); + if ((face_data_value == SIMFACE_DATA_TRUE) && (custom_data_offset == -1)) { continue; } break; @@ -429,19 +430,15 @@ static wmOperatorStatus similar_face_select_exec(bContext *C, wmOperator *op) } break; case SIMFACE_FREESTYLE: { - FreestyleFace *fface; - if (!has_custom_data_layer) { + if (custom_data_offset == -1) { BLI_assert(face_data_value == SIMFACE_DATA_FALSE); select = true; break; } - fface = static_cast( - CustomData_bmesh_get(&bm->pdata, face->head.data, CD_FREESTYLE_FACE)); - if (((fface != nullptr) && (fface->flag & FREESTYLE_FACE_MARK)) == - ((face_data_value & SIMFACE_DATA_TRUE) != 0)) - { + const bool value = BM_ELEM_CD_GET_BOOL(face, custom_data_offset); + if (value == ((face_data_value & SIMFACE_DATA_TRUE) != 0)) { select = true; } break; @@ -611,7 +608,7 @@ static wmOperatorStatus similar_edge_select_exec(bContext *C, wmOperator *op) switch (type) { case SIMEDGE_FREESTYLE: { - if (!CustomData_has_layer(&bm->edata, CD_FREESTYLE_EDGE)) { + if (!CustomData_has_layer_named(&bm->edata, CD_PROP_BOOL, "freestyle_edge")) { edge_data_value |= SIMEDGE_DATA_FALSE; continue; } @@ -637,6 +634,11 @@ static wmOperatorStatus similar_edge_select_exec(bContext *C, wmOperator *op) int custom_data_offset; switch (type) { + case SIMEDGE_FREESTYLE: { + custom_data_offset = CustomData_get_offset_named( + &bm->edata, CD_PROP_BOOL, "freestyle_edge"); + break; + } case SIMEDGE_CREASE: custom_data_offset = CustomData_get_offset_named(&bm->edata, CD_PROP_FLOAT, "crease_edge"); break; @@ -692,10 +694,7 @@ static wmOperatorStatus similar_edge_select_exec(bContext *C, wmOperator *op) } break; case SIMEDGE_FREESTYLE: { - FreestyleEdge *fedge; - fedge = static_cast( - CustomData_bmesh_get(&bm->edata, edge->head.data, CD_FREESTYLE_EDGE)); - if ((fedge == nullptr) || ((fedge->flag & FREESTYLE_EDGE_MARK) == 0)) { + if (custom_data_offset == -1 || !BM_ELEM_CD_GET_BOOL(edge, custom_data_offset)) { edge_data_value |= SIMEDGE_DATA_FALSE; } else { @@ -736,7 +735,8 @@ static wmOperatorStatus similar_edge_select_exec(bContext *C, wmOperator *op) bool has_custom_data_layer = false; switch (type) { case SIMEDGE_FREESTYLE: { - has_custom_data_layer = CustomData_has_layer(&bm->edata, CD_FREESTYLE_EDGE); + has_custom_data_layer = CustomData_has_layer_named( + &bm->edata, CD_PROP_BOOL, "freestyle_edge"); if ((edge_data_value == SIMEDGE_DATA_TRUE) && !has_custom_data_layer) { continue; } @@ -776,6 +776,10 @@ static wmOperatorStatus similar_edge_select_exec(bContext *C, wmOperator *op) int custom_data_offset; switch (type) { + case SIMEDGE_FREESTYLE: + custom_data_offset = CustomData_get_offset_named( + &bm->edata, CD_PROP_BOOL, "freestyle_edge"); + break; case SIMEDGE_CREASE: custom_data_offset = CustomData_get_offset_named(&bm->edata, CD_PROP_FLOAT, "crease_edge"); break; @@ -852,19 +856,14 @@ static wmOperatorStatus similar_edge_select_exec(bContext *C, wmOperator *op) } break; case SIMEDGE_FREESTYLE: { - FreestyleEdge *fedge; - if (!has_custom_data_layer) { BLI_assert(edge_data_value == SIMEDGE_DATA_FALSE); select = true; break; } - fedge = static_cast( - CustomData_bmesh_get(&bm->edata, edge->head.data, CD_FREESTYLE_EDGE)); - if (((fedge != nullptr) && (fedge->flag & FREESTYLE_EDGE_MARK)) == - ((edge_data_value & SIMEDGE_DATA_TRUE) != 0)) - { + const bool value = BM_ELEM_CD_GET_BOOL(edge, custom_data_offset); + if (value == ((edge_data_value & SIMEDGE_DATA_TRUE) != 0)) { select = true; } break; diff --git a/source/blender/editors/mesh/editmesh_tools.cc b/source/blender/editors/mesh/editmesh_tools.cc index bc2f74c7de8..0e3abbdbcec 100644 --- a/source/blender/editors/mesh/editmesh_tools.cc +++ b/source/blender/editors/mesh/editmesh_tools.cc @@ -7990,7 +7990,6 @@ static wmOperatorStatus edbm_mark_freestyle_edge_exec(bContext *C, wmOperator *o { BMEdge *eed; BMIter iter; - FreestyleEdge *fed; const bool clear = RNA_boolean_get(op->ptr, "clear"); const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); @@ -8010,25 +8009,23 @@ static wmOperatorStatus edbm_mark_freestyle_edge_exec(bContext *C, wmOperator *o continue; } - if (!CustomData_has_layer(&em->bm->edata, CD_FREESTYLE_EDGE)) { - BM_data_layer_add(em->bm, &em->bm->edata, CD_FREESTYLE_EDGE); + BM_data_layer_ensure_named(bm, &em->bm->edata, CD_PROP_BOOL, "freestyle_edge"); + const int offset = CustomData_get_offset_named(&em->bm->edata, CD_PROP_BOOL, "freestyle_edge"); + if (offset == -1) { + continue; } if (clear) { BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { if (BM_elem_flag_test(eed, BM_ELEM_SELECT) && !BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) { - fed = static_cast( - CustomData_bmesh_get(&em->bm->edata, eed->head.data, CD_FREESTYLE_EDGE)); - fed->flag &= ~FREESTYLE_EDGE_MARK; + BM_ELEM_CD_SET_BOOL(eed, offset, false); } } } else { BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) { if (BM_elem_flag_test(eed, BM_ELEM_SELECT) && !BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) { - fed = static_cast( - CustomData_bmesh_get(&em->bm->edata, eed->head.data, CD_FREESTYLE_EDGE)); - fed->flag |= FREESTYLE_EDGE_MARK; + BM_ELEM_CD_SET_BOOL(eed, offset, true); } } } @@ -8070,7 +8067,6 @@ static wmOperatorStatus edbm_mark_freestyle_face_exec(bContext *C, wmOperator *o { BMFace *efa; BMIter iter; - FreestyleFace *ffa; const bool clear = RNA_boolean_get(op->ptr, "clear"); const Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); @@ -8088,25 +8084,23 @@ static wmOperatorStatus edbm_mark_freestyle_face_exec(bContext *C, wmOperator *o continue; } - if (!CustomData_has_layer(&em->bm->pdata, CD_FREESTYLE_FACE)) { - BM_data_layer_add(em->bm, &em->bm->pdata, CD_FREESTYLE_FACE); + BM_data_layer_ensure_named(em->bm, &em->bm->edata, CD_PROP_BOOL, "freestyle_edge"); + const int offset = CustomData_get_offset_named(&em->bm->edata, CD_PROP_BOOL, "freestyle_edge"); + if (offset == -1) { + continue; } if (clear) { BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) { - ffa = static_cast( - CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_FREESTYLE_FACE)); - ffa->flag &= ~FREESTYLE_FACE_MARK; + BM_ELEM_CD_SET_BOOL(efa, offset, false); } } } else { BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) { if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) { - ffa = static_cast( - CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_FREESTYLE_FACE)); - ffa->flag |= FREESTYLE_FACE_MARK; + BM_ELEM_CD_SET_BOOL(efa, offset, true); } } } diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp index be9cb123d60..e5a75bbc1fd 100644 --- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp +++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp @@ -394,7 +394,10 @@ int BlenderFileLoader::testDegenerateTriangle(float v1[3], float v2[3], float v3 return 0; } -static bool testEdgeMark(Mesh *mesh, const FreestyleEdge *fed, const blender::int3 &tri, int i) +static bool testEdgeMark(Mesh *mesh, + const blender::VArray &fed, + const blender::int3 &tri, + int i) { const Span edges = mesh->edges(); const Span corner_verts = mesh->corner_verts(); @@ -409,7 +412,7 @@ static bool testEdgeMark(Mesh *mesh, const FreestyleEdge *fed, const blender::in return false; } - return (fed[corner_edges[corner]].flag & FREESTYLE_EDGE_MARK) != 0; + return fed[corner_edges[corner]]; } void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *mesh, int id) @@ -428,12 +431,13 @@ void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *mesh, int id) vert_positions, mesh_polys, corner_verts, {corner_tris, tottri}); const blender::Span tri_faces = mesh->corner_tri_faces(); const blender::Span corner_normals = mesh->corner_normals(); + const bke::AttributeAccessor attributes = mesh->attributes(); // Get other mesh data - const FreestyleEdge *fed = (const FreestyleEdge *)CustomData_get_layer(&mesh->edge_data, - CD_FREESTYLE_EDGE); - const FreestyleFace *ffa = (const FreestyleFace *)CustomData_get_layer(&mesh->face_data, - CD_FREESTYLE_FACE); + const VArray fed = *attributes.lookup_or_default( + "freestyle_edge", bke::AttrDomain::Edge, false); + const VArray ffa = *attributes.lookup_or_default( + "freestyle_face", bke::AttrDomain::Face, false); // Compute view matrix Object *ob_camera_eval = DEG_get_evaluated(_depsgraph, RE_GetCamera(_re)); @@ -519,7 +523,6 @@ void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *mesh, int id) FrsMaterial tmpMat; - const bke::AttributeAccessor attributes = mesh->attributes(); const VArray material_indices = *attributes.lookup_or_default( "material_index", bke::AttrDomain::Face, 0); const VArray sharp_faces = *attributes.lookup_or_default( @@ -570,7 +573,7 @@ void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *mesh, int id) continue; } - bool fm = (ffa) ? (ffa[poly_i].flag & FREESTYLE_FACE_MARK) != 0 : false; + bool fm = ffa[poly_i]; bool em1 = false, em2 = false, em3 = false; if (fed) { diff --git a/source/blender/geometry/intern/mesh_split_edges.cc b/source/blender/geometry/intern/mesh_split_edges.cc index d3e1cb60d8b..65cfc74946e 100644 --- a/source/blender/geometry/intern/mesh_split_edges.cc +++ b/source/blender/geometry/intern/mesh_split_edges.cc @@ -65,7 +65,6 @@ static void propagate_vert_attributes(Mesh &mesh, const Span new_to_old_ver static void propagate_edge_attributes(Mesh &mesh, const Span new_to_old_edge_map) { - CustomData_free_layers(&mesh.edge_data, CD_FREESTYLE_EDGE); CustomData_realloc(&mesh.edge_data, mesh.edges_num, mesh.edges_num + new_to_old_edge_map.size()); mesh.edges_num += new_to_old_edge_map.size(); diff --git a/source/blender/makesdna/DNA_customdata_types.h b/source/blender/makesdna/DNA_customdata_types.h index 1df23ec3227..0187d1769a9 100644 --- a/source/blender/makesdna/DNA_customdata_types.h +++ b/source/blender/makesdna/DNA_customdata_types.h @@ -147,8 +147,10 @@ typedef enum eCustomDataType { #endif CD_GRID_PAINT_MASK = 35, CD_MVERT_SKIN = 36, +#ifdef DNA_DEPRECATED_ALLOW CD_FREESTYLE_EDGE = 37, CD_FREESTYLE_FACE = 38, +#endif CD_MLOOPTANGENT = 39, CD_TESSLOOPNORMAL = 40, #ifdef DNA_DEPRECATED_ALLOW @@ -202,8 +204,6 @@ using eCustomDataMask = uint64_t; #define CD_MASK_GRID_PAINT_MASK (1LL << CD_GRID_PAINT_MASK) #define CD_MASK_MVERT_SKIN (1LL << CD_MVERT_SKIN) -#define CD_MASK_FREESTYLE_EDGE (1LL << CD_FREESTYLE_EDGE) -#define CD_MASK_FREESTYLE_FACE (1LL << CD_FREESTYLE_FACE) #define CD_MASK_MLOOPTANGENT (1LL << CD_MLOOPTANGENT) #define CD_MASK_TESSLOOPNORMAL (1LL << CD_TESSLOOPNORMAL) #define CD_MASK_PROP_COLOR (1ULL << CD_PROP_COLOR) diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h index 147bbf30235..1e5e4d4e6e8 100644 --- a/source/blender/makesdna/DNA_meshdata_types.h +++ b/source/blender/makesdna/DNA_meshdata_types.h @@ -252,6 +252,8 @@ typedef struct OrigSpaceLoop { /** \} */ +#ifdef DNA_DEPRECATED_ALLOW + /* -------------------------------------------------------------------- */ /** \name Custom Data (FreeStyle for Edge, Face) * \{ */ @@ -280,8 +282,6 @@ enum { /** \name Deprecated Structs * \{ */ -#ifdef DNA_DEPRECATED_ALLOW - /** * Mesh Edges. * diff --git a/source/blender/makesrna/intern/rna_mesh.cc b/source/blender/makesrna/intern/rna_mesh.cc index 9e92ecf4b19..7fa2fb4861b 100644 --- a/source/blender/makesrna/intern/rna_mesh.cc +++ b/source/blender/makesrna/intern/rna_mesh.cc @@ -829,64 +829,6 @@ static void rna_CustomDataLayer_clone_set(PointerRNA *ptr, CustomData *data, int CustomData_set_layer_clone_index(data, eCustomDataType(type), n); } -static bool rna_MEdge_freestyle_edge_mark_get(PointerRNA *ptr) -{ - const Mesh *mesh = rna_mesh(ptr); - const int index = rna_MeshEdge_index_get(ptr); - const FreestyleEdge *fed = static_cast( - CustomData_get_layer(&mesh->edge_data, CD_FREESTYLE_EDGE)); - - return fed && (fed[index].flag & FREESTYLE_EDGE_MARK) != 0; -} - -static void rna_MEdge_freestyle_edge_mark_set(PointerRNA *ptr, bool value) -{ - Mesh *mesh = rna_mesh(ptr); - const int index = rna_MeshEdge_index_get(ptr); - FreestyleEdge *fed = static_cast( - CustomData_get_layer_for_write(&mesh->edge_data, CD_FREESTYLE_EDGE, mesh->edges_num)); - - if (!fed) { - fed = static_cast(CustomData_add_layer( - &mesh->edge_data, CD_FREESTYLE_EDGE, CD_SET_DEFAULT, mesh->edges_num)); - } - if (value) { - fed[index].flag |= FREESTYLE_EDGE_MARK; - } - else { - fed[index].flag &= ~FREESTYLE_EDGE_MARK; - } -} - -static bool rna_MPoly_freestyle_face_mark_get(PointerRNA *ptr) -{ - const Mesh *mesh = rna_mesh(ptr); - const int index = rna_MeshPolygon_index_get(ptr); - const FreestyleFace *ffa = static_cast( - CustomData_get_layer(&mesh->face_data, CD_FREESTYLE_FACE)); - - return ffa && (ffa[index].flag & FREESTYLE_FACE_MARK) != 0; -} - -static void rna_MPoly_freestyle_face_mark_set(PointerRNA *ptr, bool value) -{ - Mesh *mesh = rna_mesh(ptr); - const int index = rna_MeshPolygon_index_get(ptr); - FreestyleFace *ffa = static_cast( - CustomData_get_layer_for_write(&mesh->face_data, CD_FREESTYLE_FACE, mesh->faces_num)); - - if (!ffa) { - ffa = static_cast(CustomData_add_layer( - &mesh->face_data, CD_FREESTYLE_FACE, CD_SET_DEFAULT, mesh->faces_num)); - } - if (value) { - ffa[index].flag |= FREESTYLE_FACE_MARK; - } - else { - ffa[index].flag &= ~FREESTYLE_FACE_MARK; - } -} - /* uv_layers */ DEFINE_CUSTOMDATA_LAYER_COLLECTION(uv_layer, ldata, CD_PROP_FLOAT2) @@ -2085,12 +2027,6 @@ static void rna_def_medge(BlenderRNA *brna) RNA_def_property_boolean_funcs(prop, "rna_MeshEdge_is_loose_get", nullptr); RNA_def_property_ui_text(prop, "Loose", "Edge is not connected to any faces"); - prop = RNA_def_property(srna, "use_freestyle_mark", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_funcs( - prop, "rna_MEdge_freestyle_edge_mark_get", "rna_MEdge_freestyle_edge_mark_set"); - RNA_def_property_ui_text(prop, "Freestyle Edge Mark", "Edge mark for Freestyle line rendering"); - RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all"); - prop = RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED); RNA_def_property_clear_flag(prop, PROP_EDITABLE); RNA_def_property_int_funcs(prop, "rna_MeshEdge_index_get", nullptr, nullptr); @@ -2298,12 +2234,6 @@ static void rna_def_mpolygon(BlenderRNA *brna) RNA_def_property_ui_text(prop, "Smooth", ""); RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all"); - prop = RNA_def_property(srna, "use_freestyle_mark", PROP_BOOLEAN, PROP_NONE); - RNA_def_property_boolean_funcs( - prop, "rna_MPoly_freestyle_face_mark_get", "rna_MPoly_freestyle_face_mark_set"); - RNA_def_property_ui_text(prop, "Freestyle Face Mark", "Face mark for Freestyle line rendering"); - RNA_def_property_update(prop, 0, "rna_Mesh_update_data_legacy_deg_tag_all"); - prop = RNA_def_property(srna, "normal", PROP_FLOAT, PROP_DIRECTION); RNA_def_property_array(prop, 3); RNA_def_property_range(prop, -1.0f, 1.0f); diff --git a/source/blender/modifiers/intern/lineart/lineart_cpu.cc b/source/blender/modifiers/intern/lineart/lineart_cpu.cc index 20c8198f0bf..a68d509c08a 100644 --- a/source/blender/modifiers/intern/lineart/lineart_cpu.cc +++ b/source/blender/modifiers/intern/lineart/lineart_cpu.cc @@ -1495,9 +1495,9 @@ struct EdgeFeatData { float crease_threshold; bool use_auto_smooth; bool use_freestyle_face; - const FreestyleFace *freestyle_face; + blender::VArray freestyle_face; bool use_freestyle_edge; - const FreestyleEdge *freestyle_edge; + blender::VArray freestyle_edge; LineartEdgeNeighbor *edge_nabr; }; @@ -1541,14 +1541,13 @@ static void lineart_identify_corner_tri_feature_edges(void *__restrict userdata, if (enable_face_mark) { bool ff1 = false; bool ff2 = false; - if (const FreestyleFace *freestyle_face = e_feat_data->freestyle_face) { - if (freestyle_face[tri_faces[i / 3]].flag & FREESTYLE_FACE_MARK) { + if (const blender::VArray &freestyle_face = e_feat_data->freestyle_face) { + if (freestyle_face[tri_faces[i / 3]]) { ff1 = true; } } if (edge_nabr[i].e > -1 && e_feat_data->freestyle_face) { - ff2 = (e_feat_data->freestyle_face[tri_faces[edge_nabr[i].e / 3]].flag & - FREESTYLE_FACE_MARK) != 0; + ff2 = e_feat_data->freestyle_face[tri_faces[edge_nabr[i].e / 3]]; } else { /* Handle mesh boundary cases: We want mesh boundaries to respect @@ -1709,7 +1708,7 @@ static void lineart_identify_corner_tri_feature_edges(void *__restrict userdata, } if (ld->conf.use_edge_marks && e_feat_data->use_freestyle_edge) { - if (e_feat_data->freestyle_edge[real_edges[i % 3]].flag & FREESTYLE_EDGE_MARK) { + if (e_feat_data->freestyle_edge[real_edges[i % 3]]) { edge_flag_result |= MOD_LINEART_EDGE_FLAG_EDGE_MARK; } } @@ -1978,19 +1977,6 @@ static void lineart_geometry_object_load(LineartObjectInfo *ob_info, const AttributeAccessor attributes = mesh->attributes(); const VArraySpan material_indices = *attributes.lookup("material_index", AttrDomain::Face); - /* Check if we should look for custom data tags like Freestyle edges or faces. */ - bool can_find_freestyle_edge = false; - int layer_index = CustomData_get_active_layer_index(&mesh->edge_data, CD_FREESTYLE_EDGE); - if (layer_index != -1) { - can_find_freestyle_edge = true; - } - - bool can_find_freestyle_face = false; - layer_index = CustomData_get_active_layer_index(&mesh->face_data, CD_FREESTYLE_FACE); - if (layer_index != -1) { - can_find_freestyle_face = true; - } - /* If we allow duplicated edges, one edge should get added multiple times if is has been * classified as more than one edge type. This is so we can create multiple different line type * chains containing the same edge. */ @@ -2127,16 +2113,10 @@ static void lineart_geometry_object_load(LineartObjectInfo *ob_info, edge_feat_data.v_array = la_v_arr; edge_feat_data.crease_threshold = crease_angle; edge_feat_data.use_auto_smooth = use_auto_smooth; - edge_feat_data.use_freestyle_face = can_find_freestyle_face; - edge_feat_data.use_freestyle_edge = can_find_freestyle_edge; - if (edge_feat_data.use_freestyle_face) { - edge_feat_data.freestyle_face = static_cast( - CustomData_get_layer(&mesh->face_data, CD_FREESTYLE_FACE)); - } - if (edge_feat_data.use_freestyle_edge) { - edge_feat_data.freestyle_edge = static_cast( - CustomData_get_layer(&mesh->edge_data, CD_FREESTYLE_EDGE)); - } + edge_feat_data.freestyle_face = *attributes.lookup("freestyle_face", AttrDomain::Face); + edge_feat_data.freestyle_edge = *attributes.lookup("freestyle_edge", AttrDomain::Edge); + edge_feat_data.use_freestyle_face = bool(edge_feat_data.freestyle_face); + edge_feat_data.use_freestyle_edge = bool(edge_feat_data.freestyle_edge); BLI_task_parallel_range(0, total_edges, diff --git a/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc b/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc index 72badb880a2..3acc644ec13 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc @@ -114,16 +114,6 @@ static void remove_unsupported_vert_data(Mesh &mesh) CustomData_free_layers(&mesh.vert_data, CD_MVERT_SKIN); } -static void remove_unsupported_edge_data(Mesh &mesh) -{ - CustomData_free_layers(&mesh.edge_data, CD_FREESTYLE_EDGE); -} - -static void remove_unsupported_face_data(Mesh &mesh) -{ - CustomData_free_layers(&mesh.face_data, CD_FREESTYLE_FACE); -} - static void remove_unsupported_corner_data(Mesh &mesh) { CustomData_free_layers(&mesh.corner_data, CD_MDISPS); @@ -417,7 +407,6 @@ static void extrude_mesh_vertices(Mesh &mesh, } remove_unsupported_vert_data(mesh); - remove_unsupported_edge_data(mesh); expand_mesh(mesh, selection.size(), selection.size(), 0, 0); const IndexRange new_vert_range{orig_vert_size, selection.size()}; @@ -629,8 +618,6 @@ static void extrude_mesh_edges(Mesh &mesh, } remove_unsupported_vert_data(mesh); - remove_unsupported_edge_data(mesh); - remove_unsupported_face_data(mesh); remove_unsupported_corner_data(mesh); expand_mesh(mesh, new_vert_range.size(), @@ -971,8 +958,6 @@ static void extrude_mesh_face_regions(Mesh &mesh, remove_non_propagated_attributes(attributes, attribute_filter); remove_unsupported_vert_data(mesh); - remove_unsupported_edge_data(mesh); - remove_unsupported_face_data(mesh); remove_unsupported_corner_data(mesh); expand_mesh(mesh, new_vert_range.size(), @@ -1266,8 +1251,6 @@ static void extrude_individual_mesh_faces(Mesh &mesh, remove_non_propagated_attributes(attributes, attribute_filter); remove_unsupported_vert_data(mesh); - remove_unsupported_edge_data(mesh); - remove_unsupported_face_data(mesh); remove_unsupported_corner_data(mesh); expand_mesh(mesh, new_vert_range.size(), diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.cc b/source/blender/python/bmesh/bmesh_py_types_customdata.cc index 1385f524319..c528ae34d71 100644 --- a/source/blender/python/bmesh/bmesh_py_types_customdata.cc +++ b/source/blender/python/bmesh/bmesh_py_types_customdata.cc @@ -311,13 +311,6 @@ static PyGetSetDef bpy_bmlayeraccess_edge_getseters[] = { (setter) nullptr, bpy_bmlayeraccess_collection__string_doc, (void *)CD_PROP_STRING}, -#ifdef WITH_FREESTYLE - {"freestyle", - (getter)bpy_bmlayeraccess_collection_get, - (setter) nullptr, - bpy_bmlayeraccess_collection__freestyle_edge_doc, - (void *)CD_FREESTYLE_EDGE}, -#endif {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */ }; @@ -358,14 +351,6 @@ static PyGetSetDef bpy_bmlayeraccess_face_getseters[] = { bpy_bmlayeraccess_collection__string_doc, (void *)CD_PROP_STRING}, -#ifdef WITH_FREESTYLE - {"freestyle", - (getter)bpy_bmlayeraccess_collection_get, - (setter) nullptr, - bpy_bmlayeraccess_collection__freestyle_face_doc, - (void *)CD_FREESTYLE_FACE}, -#endif - {nullptr, nullptr, nullptr, nullptr, nullptr} /* Sentinel */ };