Blender  V2.93
MOD_mirror.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  * The Original Code is Copyright (C) 2005 by the Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #include "BLI_math.h"
25 
26 #include "BLT_translation.h"
27 
28 #include "DNA_defaults.h"
29 #include "DNA_mesh_types.h"
30 #include "DNA_meshdata_types.h"
31 #include "DNA_object_types.h"
32 #include "DNA_screen_types.h"
33 
34 #include "BKE_context.h"
35 #include "BKE_deform.h"
36 #include "BKE_lib_id.h"
37 #include "BKE_lib_query.h"
38 #include "BKE_mesh.h"
39 #include "BKE_mesh_mirror.h"
40 #include "BKE_modifier.h"
41 #include "BKE_screen.h"
42 
43 #include "UI_interface.h"
44 #include "UI_resources.h"
45 
46 #include "RNA_access.h"
47 
48 #include "bmesh.h"
49 #include "bmesh_tools.h"
50 
51 #include "MEM_guardedalloc.h"
52 
53 #include "DEG_depsgraph_build.h"
54 #include "DEG_depsgraph_query.h"
55 
56 #include "MOD_modifiertypes.h"
57 #include "MOD_ui_common.h"
58 
59 static void initData(ModifierData *md)
60 {
62 
64 
66 }
67 
68 static void foreachIDLink(ModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
69 {
71 
72  walk(userData, ob, (ID **)&mmd->mirror_ob, IDWALK_CB_NOP);
73 }
74 
76 {
78  if (mmd->mirror_ob != NULL) {
79  DEG_add_object_relation(ctx->node, mmd->mirror_ob, DEG_OB_COMP_TRANSFORM, "Mirror Modifier");
80  DEG_add_modifier_to_transform_relation(ctx->node, "Mirror Modifier");
81  }
82 }
83 
85 {
86  Mesh *result = mesh;
87 
88  /* check which axes have been toggled and mirror accordingly */
89  if (mmd->flag & MOD_MIR_AXIS_X) {
91  }
92  if (mmd->flag & MOD_MIR_AXIS_Y) {
93  Mesh *tmp = result;
95  if (tmp != mesh) {
96  /* free intermediate results */
97  BKE_id_free(NULL, tmp);
98  }
99  }
100  if (mmd->flag & MOD_MIR_AXIS_Z) {
101  Mesh *tmp = result;
103  if (tmp != mesh) {
104  /* free intermediate results */
105  BKE_id_free(NULL, tmp);
106  }
107  }
108 
109  return result;
110 }
111 
113 {
114  Mesh *result;
116 
118 
119  if (result != mesh) {
120  result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
121  }
122  return result;
123 }
124 
125 static void panel_draw(const bContext *UNUSED(C), Panel *panel)
126 {
127  uiLayout *row, *col, *sub;
128  uiLayout *layout = panel->layout;
130 
131  PropertyRNA *prop;
132  PointerRNA ob_ptr;
134 
135  col = uiLayoutColumn(layout, false);
136  uiLayoutSetPropSep(col, true);
137 
138  prop = RNA_struct_find_property(ptr, "use_axis");
139  row = uiLayoutRowWithHeading(col, true, IFACE_("Axis"));
140  uiItemFullR(row, ptr, prop, 0, 0, toggles_flag, IFACE_("X"), ICON_NONE);
141  uiItemFullR(row, ptr, prop, 1, 0, toggles_flag, IFACE_("Y"), ICON_NONE);
142  uiItemFullR(row, ptr, prop, 2, 0, toggles_flag, IFACE_("Z"), ICON_NONE);
143 
144  prop = RNA_struct_find_property(ptr, "use_bisect_axis");
145  row = uiLayoutRowWithHeading(col, true, IFACE_("Bisect"));
146  uiItemFullR(row, ptr, prop, 0, 0, toggles_flag, IFACE_("X"), ICON_NONE);
147  uiItemFullR(row, ptr, prop, 1, 0, toggles_flag, IFACE_("Y"), ICON_NONE);
148  uiItemFullR(row, ptr, prop, 2, 0, toggles_flag, IFACE_("Z"), ICON_NONE);
149 
150  prop = RNA_struct_find_property(ptr, "use_bisect_flip_axis");
151  row = uiLayoutRowWithHeading(col, true, IFACE_("Flip"));
152  uiItemFullR(row, ptr, prop, 0, 0, toggles_flag, IFACE_("X"), ICON_NONE);
153  uiItemFullR(row, ptr, prop, 1, 0, toggles_flag, IFACE_("Y"), ICON_NONE);
154  uiItemFullR(row, ptr, prop, 2, 0, toggles_flag, IFACE_("Z"), ICON_NONE);
155 
156  uiItemS(col);
157 
158  uiItemR(col, ptr, "mirror_object", 0, NULL, ICON_NONE);
159 
160  uiItemR(col, ptr, "use_clip", 0, IFACE_("Clipping"), ICON_NONE);
161 
162  row = uiLayoutRowWithHeading(col, true, IFACE_("Merge"));
163  uiItemR(row, ptr, "use_mirror_merge", 0, "", ICON_NONE);
164  sub = uiLayoutRow(row, true);
165  uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_mirror_merge"));
166  uiItemR(sub, ptr, "merge_threshold", 0, "", ICON_NONE);
167 
168  bool is_bisect_set[3];
169  RNA_boolean_get_array(ptr, "use_bisect_axis", is_bisect_set);
170 
171  sub = uiLayoutRow(col, true);
172  uiLayoutSetActive(sub, is_bisect_set[0] || is_bisect_set[1] || is_bisect_set[2]);
173  uiItemR(sub, ptr, "bisect_threshold", 0, IFACE_("Bisect Distance"), ICON_NONE);
174 
175  modifier_panel_end(layout, ptr);
176 }
177 
178 static void data_panel_draw(const bContext *UNUSED(C), Panel *panel)
179 {
180  uiLayout *col, *row, *sub;
181  uiLayout *layout = panel->layout;
182 
184 
185  uiLayoutSetPropSep(layout, true);
186 
187  col = uiLayoutColumn(layout, true);
188  row = uiLayoutRowWithHeading(col, true, IFACE_("Mirror U"));
189  uiLayoutSetPropDecorate(row, false);
190  sub = uiLayoutRow(row, true);
191  uiItemR(sub, ptr, "use_mirror_u", 0, "", ICON_NONE);
192  sub = uiLayoutRow(sub, true);
193  uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_mirror_u"));
194  uiItemR(sub, ptr, "mirror_offset_u", UI_ITEM_R_SLIDER, "", ICON_NONE);
195  uiItemDecoratorR(row, ptr, "mirror_offset_u", 0);
196 
197  row = uiLayoutRowWithHeading(col, true, IFACE_("V"));
198  uiLayoutSetPropDecorate(row, false);
199  sub = uiLayoutRow(row, true);
200  uiItemR(sub, ptr, "use_mirror_v", 0, "", ICON_NONE);
201  sub = uiLayoutRow(sub, true);
202  uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_mirror_v"));
203  uiItemR(sub, ptr, "mirror_offset_v", UI_ITEM_R_SLIDER, "", ICON_NONE);
204  uiItemDecoratorR(row, ptr, "mirror_offset_v", 0);
205 
206  col = uiLayoutColumn(layout, true);
207  uiItemR(col, ptr, "offset_u", UI_ITEM_R_SLIDER, IFACE_("Offset U"), ICON_NONE);
208  uiItemR(col, ptr, "offset_v", UI_ITEM_R_SLIDER, IFACE_("V"), ICON_NONE);
209 
210  uiItemR(layout, ptr, "use_mirror_vertex_groups", 0, IFACE_("Vertex Groups"), ICON_NONE);
211  uiItemR(layout, ptr, "use_mirror_udim", 0, IFACE_("Flip UDIM"), ICON_NONE);
212 }
213 
214 static void panelRegister(ARegionType *region_type)
215 {
217  modifier_subpanel_register(region_type, "data", "Data", NULL, data_panel_draw, panel_type);
218 }
219 
221  /* name */ "Mirror",
222  /* structName */ "MirrorModifierData",
223  /* structSize */ sizeof(MirrorModifierData),
224  /* srna */ &RNA_MirrorModifier,
229  /* this is only the case when 'MOD_MIR_VGROUP' is used */
231  /* icon */ ICON_MOD_MIRROR,
232 
233  /* copyData */ BKE_modifier_copydata_generic,
234 
235  /* deformVerts */ NULL,
236  /* deformMatrices */ NULL,
237  /* deformVertsEM */ NULL,
238  /* deformMatricesEM */ NULL,
239  /* modifyMesh */ modifyMesh,
240  /* modifyHair */ NULL,
241  /* modifyGeometrySet */ NULL,
242  /* modifyVolume */ NULL,
243 
244  /* initData */ initData,
245  /* requiredDataMask */ NULL,
246  /* freeData */ NULL,
247  /* isDisabled */ NULL,
248  /* updateDepsgraph */ updateDepsgraph,
249  /* dependsOnTime */ NULL,
250  /* dependsOnNormals */ NULL,
251  /* foreachIDLink */ foreachIDLink,
252  /* foreachTexLink */ NULL,
253  /* freeRuntimeData */ NULL,
254  /* panelRegister */ panelRegister,
255  /* blendWrite */ NULL,
256  /* blendRead */ NULL,
257 };
support for deformation groups and hooks.
void BKE_id_free(struct Main *bmain, void *idv)
@ IDWALK_CB_NOP
Definition: BKE_lib_query.h:47
struct Mesh * BKE_mesh_mirror_apply_mirror_on_axis_for_modifier(struct MirrorModifierData *mmd, struct Object *ob, const struct Mesh *mesh, const int axis)
void(* IDWalkFunc)(void *userData, struct Object *ob, struct ID **idpoin, int cb_flag)
Definition: BKE_modifier.h:120
@ eModifierTypeFlag_AcceptsCVs
Definition: BKE_modifier.h:81
@ eModifierTypeFlag_SupportsMapping
Definition: BKE_modifier.h:82
@ eModifierTypeFlag_UsesPreview
Definition: BKE_modifier.h:113
@ eModifierTypeFlag_EnableInEditmode
Definition: BKE_modifier.h:92
@ 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 MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member)
#define IFACE_(msgid)
void DEG_add_object_relation(struct DepsNodeHandle *node_handle, struct Object *object, eDepsObjectComponentType component, const char *description)
void DEG_add_modifier_to_transform_relation(struct DepsNodeHandle *node_handle, const char *description)
@ DEG_OB_COMP_TRANSFORM
#define CD_MASK_NORMAL
#define DNA_struct_default_get(struct_name)
Definition: DNA_defaults.h:44
@ eModifierType_Mirror
struct MirrorModifierData MirrorModifierData
@ MOD_MIR_AXIS_Z
@ MOD_MIR_AXIS_X
@ MOD_MIR_AXIS_Y
Object is a sort of wrapper for general info.
Read Guarded memory(de)allocation.
static Mesh * modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
Definition: MOD_mirror.c:112
ModifierTypeInfo modifierType_Mirror
Definition: MOD_mirror.c:220
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
Definition: MOD_mirror.c:75
static Mesh * mirrorModifier__doMirror(MirrorModifierData *mmd, Object *ob, Mesh *mesh)
Definition: MOD_mirror.c:84
static void data_panel_draw(const bContext *UNUSED(C), Panel *panel)
Definition: MOD_mirror.c:178
static void foreachIDLink(ModifierData *md, Object *ob, IDWalkFunc walk, void *userData)
Definition: MOD_mirror.c:68
static void panel_draw(const bContext *UNUSED(C), Panel *panel)
Definition: MOD_mirror.c:125
static void initData(ModifierData *md)
Definition: MOD_mirror.c:59
static void panelRegister(ARegionType *region_type)
Definition: MOD_mirror.c:214
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)
PanelType * modifier_subpanel_register(ARegionType *region_type, const char *name, const char *label, PanelDrawFn draw_header, PanelDrawFn draw, PanelType *parent)
StructRNA RNA_MirrorModifier
#define C
Definition: RandGen.cpp:39
uiLayout * uiLayoutRowWithHeading(uiLayout *layout, bool align, const char *heading)
void uiLayoutSetActive(uiLayout *layout, bool active)
@ UI_ITEM_R_TOGGLE
@ UI_ITEM_R_FORCE_BLANK_DECORATE
@ UI_ITEM_R_SLIDER
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
void uiItemS(uiLayout *layout)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
void uiLayoutSetPropDecorate(uiLayout *layout, bool is_sep)
void uiItemDecoratorR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int index)
void uiItemFullR(uiLayout *layout, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, int value, int flag, const char *name, int icon)
uint col
void RNA_boolean_get_array(PointerRNA *ptr, const char *name, bool *values)
Definition: rna_access.c:6284
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
Definition: rna_access.c:866
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6261
Definition: DNA_ID.h:273
struct Object * mirror_ob
struct Object * object
Definition: BKE_modifier.h:154
struct DepsNodeHandle * node
Definition: BKE_modifier.h:147
struct uiLayout * layout
PointerRNA * ptr
Definition: wm_files.c:3157