Blender  V2.93
MOD_wireframe.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #include <string.h>
22 
23 #include "BLI_utildefines.h"
24 
25 #include "BLT_translation.h"
26 
27 #include "DNA_defaults.h"
28 #include "DNA_mesh_types.h"
29 #include "DNA_object_types.h"
30 #include "DNA_screen_types.h"
31 
32 #include "BKE_context.h"
33 #include "BKE_deform.h"
34 #include "BKE_mesh.h"
35 #include "BKE_screen.h"
36 
37 #include "UI_interface.h"
38 #include "UI_resources.h"
39 
40 #include "RNA_access.h"
41 
42 #include "MOD_modifiertypes.h"
43 #include "MOD_ui_common.h"
44 
45 #include "bmesh.h"
46 #include "tools/bmesh_wireframe.h"
47 
48 static void initData(ModifierData *md)
49 {
51 
53 
55 }
56 
57 static void requiredDataMask(Object *UNUSED(ob),
58  ModifierData *md,
59  CustomData_MeshMasks *r_cddata_masks)
60 {
62 
63  /* ask for vertexgroups if we need them */
64  if (wmd->defgrp_name[0] != '\0') {
65  r_cddata_masks->vmask |= CD_MASK_MDEFORMVERT;
66  }
67 }
68 
70 {
71  return true;
72 }
73 
75 {
76  Mesh *result;
77  BMesh *bm;
78 
79  const int defgrp_index = BKE_object_defgroup_name_index(ob, wmd->defgrp_name);
80 
82  &(struct BMeshCreateParams){0},
83  &(struct BMeshFromMeshParams){
84  .calc_face_normal = true,
85  .add_key_index = false,
86  .use_shapekey = false,
87  .active_shapekey = 0,
88  .cd_mask_extra = {.vmask = CD_MASK_ORIGINDEX,
89  .emask = CD_MASK_ORIGINDEX,
90  .pmask = CD_MASK_ORIGINDEX},
91  });
92 
94  wmd->offset,
95  wmd->offset_fac,
96  wmd->offset_fac_vg,
97  (wmd->flag & MOD_WIREFRAME_REPLACE) != 0,
98  (wmd->flag & MOD_WIREFRAME_BOUNDARY) != 0,
99  (wmd->flag & MOD_WIREFRAME_OFS_EVEN) != 0,
100  (wmd->flag & MOD_WIREFRAME_OFS_RELATIVE) != 0,
101  (wmd->flag & MOD_WIREFRAME_CREASE) != 0,
102  wmd->crease_weight,
103  defgrp_index,
104  (wmd->flag & MOD_WIREFRAME_INVERT_VGROUP) != 0,
105  wmd->mat_ofs,
106  MAX2(ob->totcol - 1, 0),
107  false);
108 
110  BM_mesh_free(bm);
111 
112  result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
113 
114  return result;
115 }
116 
117 static Mesh *modifyMesh(ModifierData *md, const struct ModifierEvalContext *ctx, struct Mesh *mesh)
118 {
120 }
121 
122 static void panel_draw(const bContext *UNUSED(C), Panel *panel)
123 {
124  uiLayout *col, *row, *sub;
125  uiLayout *layout = panel->layout;
126 
127  PointerRNA ob_ptr;
129 
130  uiLayoutSetPropSep(layout, true);
131 
132  uiItemR(layout, ptr, "thickness", 0, IFACE_("Thickness"), ICON_NONE);
133  uiItemR(layout, ptr, "offset", 0, NULL, ICON_NONE);
134 
135  col = uiLayoutColumn(layout, true);
136  uiItemR(col, ptr, "use_boundary", 0, IFACE_("Boundary"), ICON_NONE);
137  uiItemR(col, ptr, "use_replace", 0, IFACE_("Replace Original"), ICON_NONE);
138 
139  col = uiLayoutColumnWithHeading(layout, true, IFACE_("Thickness"));
140  uiItemR(col, ptr, "use_even_offset", 0, IFACE_("Even"), ICON_NONE);
141  uiItemR(col, ptr, "use_relative_offset", 0, IFACE_("Relative"), ICON_NONE);
142 
143  row = uiLayoutRowWithHeading(layout, true, IFACE_("Crease Edges"));
144  uiItemR(row, ptr, "use_crease", 0, "", ICON_NONE);
145  sub = uiLayoutRow(row, true);
146  uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_crease"));
147  uiItemR(sub, ptr, "crease_weight", UI_ITEM_R_SLIDER, "", ICON_NONE);
148 
149  uiItemR(layout, ptr, "material_offset", 0, IFACE_("Material Offset"), ICON_NONE);
150 
151  modifier_panel_end(layout, ptr);
152 }
153 
154 static void vertex_group_panel_draw(const bContext *UNUSED(C), Panel *panel)
155 {
156  uiLayout *row;
157  uiLayout *layout = panel->layout;
158 
159  PointerRNA ob_ptr;
161 
162  bool has_vertex_group = RNA_string_length(ptr, "vertex_group") != 0;
163 
164  uiLayoutSetPropSep(layout, true);
165 
166  modifier_vgroup_ui(layout, ptr, &ob_ptr, "vertex_group", "invert_vertex_group", NULL);
167 
168  row = uiLayoutRow(layout, true);
169  uiLayoutSetActive(row, has_vertex_group);
170  uiItemR(row, ptr, "thickness_vertex_group", 0, IFACE_("Factor"), ICON_NONE);
171 }
172 
173 static void panelRegister(ARegionType *region_type)
174 {
175  PanelType *panel_type = modifier_panel_register(
176  region_type, eModifierType_Wireframe, panel_draw);
178  region_type, "vertex_group", "Vertex Group", NULL, vertex_group_panel_draw, panel_type);
179 }
180 
182  /* name */ "Wireframe",
183  /* structName */ "WireframeModifierData",
184  /* structSize */ sizeof(WireframeModifierData),
185  /* srna */ &RNA_WireframeModifier,
188  /* icon */ ICON_MOD_WIREFRAME,
189 
190  /* copyData */ BKE_modifier_copydata_generic,
191 
192  /* deformVerts */ NULL,
193  /* deformMatrices */ NULL,
194  /* deformVertsEM */ NULL,
195  /* deformMatricesEM */ NULL,
196  /* modifyMesh */ modifyMesh,
197  /* modifyHair */ NULL,
198  /* modifyGeometrySet */ NULL,
199  /* modifyVolume */ NULL,
200 
201  /* initData */ initData,
202  /* requiredDataMask */ requiredDataMask,
203  /* freeData */ NULL,
204  /* isDisabled */ NULL,
205  /* updateDepgraph */ NULL,
206  /* dependsOnTime */ NULL,
207  /* dependsOnNormals */ dependsOnNormals,
208  /* foreachIDLink */ NULL,
209  /* foreachTexLink */ NULL,
210  /* freeRuntimeData */ NULL,
211  /* panelRegister */ panelRegister,
212  /* blendWrite */ NULL,
213  /* blendRead */ NULL,
214 };
support for deformation groups and hooks.
int BKE_object_defgroup_name_index(const struct Object *ob, const char *name)
struct BMesh * BKE_mesh_to_bmesh_ex(const struct Mesh *me, const struct BMeshCreateParams *create_params, const struct BMeshFromMeshParams *convert_params)
struct Mesh * BKE_mesh_from_bmesh_for_eval_nomain(struct BMesh *bm, const struct CustomData_MeshMasks *cd_mask_extra, const struct Mesh *me_settings)
@ eModifierTypeFlag_SupportsEditmode
Definition: BKE_modifier.h:83
@ eModifierTypeFlag_AcceptsMesh
Definition: BKE_modifier.h:80
void BKE_modifier_copydata_generic(const struct ModifierData *md, struct ModifierData *md_dst, const int flag)
@ eModifierTypeType_Constructive
Definition: BKE_modifier.h:61
#define BLI_assert(a)
Definition: BLI_assert.h:58
#define UNUSED(x)
#define MAX2(a, b)
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member)
#define IFACE_(msgid)
#define CD_MASK_NORMAL
#define CD_MASK_ORIGINDEX
#define CD_MASK_MDEFORMVERT
#define DNA_struct_default_get(struct_name)
Definition: DNA_defaults.h:44
@ MOD_WIREFRAME_OFS_EVEN
@ MOD_WIREFRAME_OFS_RELATIVE
@ MOD_WIREFRAME_INVERT_VGROUP
@ MOD_WIREFRAME_CREASE
@ MOD_WIREFRAME_BOUNDARY
@ MOD_WIREFRAME_REPLACE
@ eModifierType_Wireframe
struct WireframeModifierData WireframeModifierData
Object is a sort of wrapper for general info.
PointerRNA * modifier_panel_get_property_pointers(Panel *panel, PointerRNA *r_ob_ptr)
void modifier_panel_end(uiLayout *layout, PointerRNA *ptr)
PanelType * modifier_panel_register(ARegionType *region_type, ModifierType type, PanelDrawFn draw)
void modifier_vgroup_ui(uiLayout *layout, PointerRNA *ptr, PointerRNA *ob_ptr, const char *vgroup_prop, const char *invert_vgroup_prop, const char *text)
PanelType * modifier_subpanel_register(ARegionType *region_type, const char *name, const char *label, PanelDrawFn draw_header, PanelDrawFn draw, PanelType *parent)
ModifierTypeInfo modifierType_Wireframe
static void vertex_group_panel_draw(const bContext *UNUSED(C), Panel *panel)
static bool dependsOnNormals(ModifierData *UNUSED(md))
Definition: MOD_wireframe.c:69
static void panel_draw(const bContext *UNUSED(C), Panel *panel)
static void initData(ModifierData *md)
Definition: MOD_wireframe.c:48
static void panelRegister(ARegionType *region_type)
static Mesh * modifyMesh(ModifierData *md, const struct ModifierEvalContext *ctx, struct Mesh *mesh)
static void requiredDataMask(Object *UNUSED(ob), ModifierData *md, CustomData_MeshMasks *r_cddata_masks)
Definition: MOD_wireframe.c:57
static Mesh * WireframeModifier_do(WireframeModifierData *wmd, Object *ob, Mesh *mesh)
Definition: MOD_wireframe.c:74
StructRNA RNA_WireframeModifier
#define C
Definition: RandGen.cpp:39
uiLayout * uiLayoutRowWithHeading(uiLayout *layout, bool align, const char *heading)
void uiLayoutSetActive(uiLayout *layout, bool active)
@ UI_ITEM_R_SLIDER
uiLayout * uiLayoutColumnWithHeading(uiLayout *layout, bool align, const char *heading)
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
ATTR_WARN_UNUSED_RESULT BMesh * bm
void BM_mesh_free(BMesh *bm)
BMesh Free Mesh.
Definition: bmesh_mesh.c:307
void BM_mesh_wireframe(BMesh *bm, const float offset, const float offset_fac, const float offset_fac_vg, const bool use_replace, const bool use_boundary, const bool use_even_offset, const bool use_relative_offset, const bool use_crease, const float crease_weight, const int defgrp_index, const bool defgrp_invert, const short mat_offset, const short mat_max, const bool use_tag)
uint col
int RNA_string_length(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6539
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6261
struct Object * object
Definition: BKE_modifier.h:154
struct uiLayout * layout
PointerRNA * ptr
Definition: wm_files.c:3157