2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2013-12-22 07:08:35 +11:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup modifiers
|
2014-03-18 02:40:39 +11:00
|
|
|
*/
|
2013-12-22 07:08:35 +11:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
#include <cstring>
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2019-02-25 11:39:14 +01:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
2024-02-19 15:54:48 +01:00
|
|
|
#include "BLT_translation.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-10-01 09:38:00 -05:00
|
|
|
#include "DNA_defaults.h"
|
2018-05-04 08:45:43 +02:00
|
|
|
#include "DNA_mesh_types.h"
|
2013-12-22 07:08:35 +11:00
|
|
|
#include "DNA_object_types.h"
|
2020-06-05 10:41:03 -04:00
|
|
|
#include "DNA_screen_types.h"
|
2013-12-22 07:08:35 +11:00
|
|
|
|
2024-02-19 15:54:48 +01:00
|
|
|
#include "BKE_context.hh"
|
2024-01-29 18:57:16 -05:00
|
|
|
#include "BKE_deform.hh"
|
2023-08-02 22:14:18 +02:00
|
|
|
#include "BKE_mesh.hh"
|
2024-02-19 15:54:48 +01:00
|
|
|
#include "BKE_screen.hh"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_interface.hh"
|
|
|
|
|
#include "UI_resources.hh"
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
2022-03-14 16:54:46 +01:00
|
|
|
#include "RNA_prototypes.h"
|
2013-12-22 07:08:35 +11:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
#include "MOD_modifiertypes.hh"
|
|
|
|
|
#include "MOD_ui_common.hh"
|
2013-12-22 07:08:35 +11:00
|
|
|
|
2023-12-05 23:01:12 +01:00
|
|
|
#include "bmesh.hh"
|
|
|
|
|
#include "tools/bmesh_wireframe.hh"
|
2013-12-22 07:08:35 +11:00
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void init_data(ModifierData *md)
|
2013-12-22 07:08:35 +11:00
|
|
|
{
|
|
|
|
|
WireframeModifierData *wmd = (WireframeModifierData *)md;
|
2020-10-01 09:38:00 -05:00
|
|
|
|
|
|
|
|
BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(wmd, modifier));
|
|
|
|
|
|
|
|
|
|
MEMCPY_STRUCT_AFTER(wmd, DNA_struct_default_get(WireframeModifierData), modifier);
|
2013-12-22 07:08:35 +11:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void required_data_mask(ModifierData *md, CustomData_MeshMasks *r_cddata_masks)
|
2013-12-22 07:08:35 +11:00
|
|
|
{
|
|
|
|
|
WireframeModifierData *wmd = (WireframeModifierData *)md;
|
|
|
|
|
|
2023-05-05 09:25:45 +10:00
|
|
|
/* Ask for vertex-groups if we need them. */
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
if (wmd->defgrp_name[0] != '\0') {
|
|
|
|
|
r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
|
|
|
|
|
}
|
2013-12-22 07:08:35 +11:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static bool depends_on_normals(ModifierData * /*md*/)
|
2014-10-03 12:12:10 +02:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-04 08:45:43 +02:00
|
|
|
static Mesh *WireframeModifier_do(WireframeModifierData *wmd, Object *ob, Mesh *mesh)
|
2013-12-22 07:08:35 +11:00
|
|
|
{
|
2018-05-04 08:45:43 +02:00
|
|
|
Mesh *result;
|
2013-12-22 07:08:35 +11:00
|
|
|
BMesh *bm;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-07-13 12:10:34 -04:00
|
|
|
const int defgrp_index = BKE_id_defgroup_name_index(&mesh->id, wmd->defgrp_name);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
BMeshCreateParams create_params{};
|
|
|
|
|
BMeshFromMeshParams convert_params{};
|
|
|
|
|
convert_params.calc_face_normal = true;
|
|
|
|
|
convert_params.calc_vert_normal = true;
|
|
|
|
|
convert_params.add_key_index = false;
|
|
|
|
|
convert_params.use_shapekey = false;
|
|
|
|
|
convert_params.active_shapekey = 0;
|
|
|
|
|
convert_params.cd_mask_extra.vmask = CD_MASK_ORIGINDEX;
|
|
|
|
|
convert_params.cd_mask_extra.emask = CD_MASK_ORIGINDEX;
|
|
|
|
|
convert_params.cd_mask_extra.pmask = CD_MASK_ORIGINDEX;
|
|
|
|
|
|
|
|
|
|
bm = BKE_mesh_to_bmesh_ex(mesh, &create_params, &convert_params);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-22 07:08:35 +11:00
|
|
|
BM_mesh_wireframe(bm,
|
|
|
|
|
wmd->offset,
|
|
|
|
|
wmd->offset_fac,
|
|
|
|
|
wmd->offset_fac_vg,
|
|
|
|
|
(wmd->flag & MOD_WIREFRAME_REPLACE) != 0,
|
|
|
|
|
(wmd->flag & MOD_WIREFRAME_BOUNDARY) != 0,
|
2013-12-22 07:16:41 +11:00
|
|
|
(wmd->flag & MOD_WIREFRAME_OFS_EVEN) != 0,
|
|
|
|
|
(wmd->flag & MOD_WIREFRAME_OFS_RELATIVE) != 0,
|
|
|
|
|
(wmd->flag & MOD_WIREFRAME_CREASE) != 0,
|
2013-12-22 07:08:35 +11:00
|
|
|
wmd->crease_weight,
|
|
|
|
|
defgrp_index,
|
|
|
|
|
(wmd->flag & MOD_WIREFRAME_INVERT_VGROUP) != 0,
|
|
|
|
|
wmd->mat_ofs,
|
2023-11-07 16:33:19 +11:00
|
|
|
std::max(ob->totcol - 1, 0),
|
2013-12-22 07:08:35 +11:00
|
|
|
false);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
result = BKE_mesh_from_bmesh_for_eval_nomain(bm, nullptr, mesh);
|
2013-12-22 07:08:35 +11:00
|
|
|
BM_mesh_free(bm);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-12-22 07:08:35 +11:00
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static Mesh *modify_mesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
|
2013-12-22 07:08:35 +11:00
|
|
|
{
|
2018-05-04 08:45:43 +02:00
|
|
|
return WireframeModifier_do((WireframeModifierData *)md, ctx->object, mesh);
|
2013-12-22 07:08:35 +11:00
|
|
|
}
|
|
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
static void panel_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
uiLayout *col, *row, *sub;
|
|
|
|
|
uiLayout *layout = panel->layout;
|
|
|
|
|
|
|
|
|
|
PointerRNA ob_ptr;
|
2020-09-02 14:13:26 -05:00
|
|
|
PointerRNA *ptr = modifier_panel_get_property_pointers(panel, &ob_ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "thickness", UI_ITEM_NONE, IFACE_("Thickness"), ICON_NONE);
|
|
|
|
|
uiItemR(layout, ptr, "offset", UI_ITEM_NONE, nullptr, ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
col = uiLayoutColumn(layout, true);
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(col, ptr, "use_boundary", UI_ITEM_NONE, IFACE_("Boundary"), ICON_NONE);
|
|
|
|
|
uiItemR(col, ptr, "use_replace", UI_ITEM_NONE, IFACE_("Replace Original"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
col = uiLayoutColumnWithHeading(layout, true, IFACE_("Thickness"));
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(col, ptr, "use_even_offset", UI_ITEM_NONE, IFACE_("Even"), ICON_NONE);
|
|
|
|
|
uiItemR(col, ptr, "use_relative_offset", UI_ITEM_NONE, IFACE_("Relative"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
row = uiLayoutRowWithHeading(layout, true, IFACE_("Crease Edges"));
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(row, ptr, "use_crease", UI_ITEM_NONE, "", ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
sub = uiLayoutRow(row, true);
|
2020-09-02 14:13:26 -05:00
|
|
|
uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_crease"));
|
|
|
|
|
uiItemR(sub, ptr, "crease_weight", UI_ITEM_R_SLIDER, "", ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(layout, ptr, "material_offset", UI_ITEM_NONE, IFACE_("Material Offset"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
modifier_panel_end(layout, ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
static void vertex_group_panel_draw(const bContext * /*C*/, Panel *panel)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
uiLayout *row;
|
|
|
|
|
uiLayout *layout = panel->layout;
|
|
|
|
|
|
|
|
|
|
PointerRNA ob_ptr;
|
2020-09-02 14:13:26 -05:00
|
|
|
PointerRNA *ptr = modifier_panel_get_property_pointers(panel, &ob_ptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
2020-09-02 14:13:26 -05:00
|
|
|
bool has_vertex_group = RNA_string_length(ptr, "vertex_group") != 0;
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
uiLayoutSetPropSep(layout, true);
|
|
|
|
|
|
2023-05-04 18:35:37 +02:00
|
|
|
modifier_vgroup_ui(layout, ptr, &ob_ptr, "vertex_group", "invert_vertex_group", nullptr);
|
2020-06-05 10:41:03 -04:00
|
|
|
|
|
|
|
|
row = uiLayoutRow(layout, true);
|
|
|
|
|
uiLayoutSetActive(row, has_vertex_group);
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(row, ptr, "thickness_vertex_group", UI_ITEM_NONE, IFACE_("Factor"), ICON_NONE);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
static void panel_register(ARegionType *region_type)
|
2020-06-05 10:41:03 -04:00
|
|
|
{
|
|
|
|
|
PanelType *panel_type = modifier_panel_register(
|
|
|
|
|
region_type, eModifierType_Wireframe, panel_draw);
|
|
|
|
|
modifier_subpanel_register(
|
2023-05-04 18:35:37 +02:00
|
|
|
region_type, "vertex_group", "Vertex Group", nullptr, vertex_group_panel_draw, panel_type);
|
2020-06-05 10:41:03 -04:00
|
|
|
}
|
|
|
|
|
|
2013-12-22 07:08:35 +11:00
|
|
|
ModifierTypeInfo modifierType_Wireframe = {
|
2023-07-26 17:08:14 +02:00
|
|
|
/*idname*/ "Wireframe",
|
2023-01-16 12:41:11 +11:00
|
|
|
/*name*/ N_("Wireframe"),
|
2023-07-27 12:04:18 +10:00
|
|
|
/*struct_name*/ "WireframeModifierData",
|
|
|
|
|
/*struct_size*/ sizeof(WireframeModifierData),
|
2023-01-16 12:41:11 +11:00
|
|
|
/*srna*/ &RNA_WireframeModifier,
|
2023-11-14 10:03:56 +01:00
|
|
|
/*type*/ ModifierTypeType::Constructive,
|
2023-01-16 12:41:11 +11:00
|
|
|
/*flags*/ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_SupportsEditmode,
|
|
|
|
|
/*icon*/ ICON_MOD_WIREFRAME,
|
|
|
|
|
|
2023-07-27 12:04:18 +10:00
|
|
|
/*copy_data*/ BKE_modifier_copydata_generic,
|
|
|
|
|
|
|
|
|
|
/*deform_verts*/ nullptr,
|
|
|
|
|
/*deform_matrices*/ nullptr,
|
|
|
|
|
/*deform_verts_EM*/ nullptr,
|
|
|
|
|
/*deform_matrices_EM*/ nullptr,
|
|
|
|
|
/*modify_mesh*/ modify_mesh,
|
|
|
|
|
/*modify_geometry_set*/ nullptr,
|
|
|
|
|
|
|
|
|
|
/*init_data*/ init_data,
|
|
|
|
|
/*required_data_mask*/ required_data_mask,
|
|
|
|
|
/*free_data*/ nullptr,
|
|
|
|
|
/*is_disabled*/ nullptr,
|
|
|
|
|
/*update_depsgraph*/ nullptr,
|
|
|
|
|
/*depends_on_time*/ nullptr,
|
|
|
|
|
/*depends_on_normals*/ depends_on_normals,
|
|
|
|
|
/*foreach_ID_link*/ nullptr,
|
|
|
|
|
/*foreach_tex_link*/ nullptr,
|
|
|
|
|
/*free_runtime_data*/ nullptr,
|
|
|
|
|
/*panel_register*/ panel_register,
|
|
|
|
|
/*blend_write*/ nullptr,
|
|
|
|
|
/*blend_read*/ nullptr,
|
2024-01-18 22:51:30 +01:00
|
|
|
/*foreach_cache*/ nullptr,
|
2013-12-22 07:08:35 +11:00
|
|
|
};
|