[Bf-blender-cvs] [342793ef756] soc-2017-normal-tools: Fixed bugs in copy and made UI changes
Rohan Rathi
noreply at git.blender.org
Tue Aug 15 19:11:39 CEST 2017
Commit: 342793ef756e0294940e304e251c99f2113b16d9
Author: Rohan Rathi
Date: Tue Aug 15 22:39:39 2017 +0530
Branches: soc-2017-normal-tools
https://developer.blender.org/rB342793ef756e0294940e304e251c99f2113b16d9
Fixed bugs in copy and made UI changes
===================================================================
M release/scripts/startup/bl_ui/properties_data_modifier.py
M release/scripts/startup/bl_ui/space_view3d_toolbar.py
M source/blender/bmesh/intern/bmesh_mesh.c
M source/blender/editors/mesh/editmesh_tools.c
M source/blender/makesdna/DNA_modifier_types.h
M source/blender/makesrna/intern/rna_modifier.c
M source/blender/modifiers/intern/MOD_weighted_normal.c
===================================================================
diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index a2af2b5e43e..d631e583c6b 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1543,7 +1543,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
row.active = has_vgroup
row.prop(md, "invert_vertex_group", text="", icon='ARROW_LEFTRIGHT')
layout.prop(md, "keep_sharp")
- layout.prop(md, "boolean_weights")
+ layout.prop(md, "binary_weights")
classes = (
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index 5b02407db6b..82766ac7ad0 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -459,7 +459,7 @@ class VIEW3D_PT_tools_normal(View3DPanel, Panel):
col.operator_menu_enum("mesh.average_loop_normals", "average_type")
col = layout.column(align=True)
- col.label(text="Copy/Paste Loop")
+ col.label(text="Copy/Paste Normal")
row = col.row(align=True)
row.operator("mesh.copy_normal", text="Copy").copy = True
row.operator("mesh.copy_normal", text="Paste").copy = False
diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c
index 91c0a9c49db..b3d1c6b3348 100644
--- a/source/blender/bmesh/intern/bmesh_mesh.c
+++ b/source/blender/bmesh/intern/bmesh_mesh.c
@@ -1093,7 +1093,9 @@ void BM_lnorspace_rebuild(BMesh *bm, bool preserve_clnor)
}
}
- BKE_lnor_spacearr_clear(bm->lnor_spacearr);
+ if (bm->spacearr_dirty & BM_SPACEARR_DIRTY_ALL) {
+ BKE_lnor_spacearr_clear(bm->lnor_spacearr);
+ }
BM_loops_calc_normal_vcos(bm, NULL, NULL, NULL, true, M_PI, r_lnors, bm->lnor_spacearr, NULL, cd_loop_clnors_offset, true);
MEM_freeN(r_lnors);
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index b91abfa0d11..9868674815c 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -6558,11 +6558,17 @@ static int edbm_average_loop_normals_exec(bContext *C, wmOperator *op)
const int average_type = RNA_enum_get(op->ptr, "average_type");
int cd_clnors_offset = CustomData_get_offset(&bm->ldata, CD_CUSTOMLOOPNORMAL);
- float weight = (float) RNA_int_get(op->ptr, "weight"), threshold = RNA_float_get(op->ptr, "threshold");
- const bool boolean_weights = RNA_boolean_get(op->ptr, "boolean_weights");
- weight = weight / 10.0f;
+ float absweight = (float) RNA_int_get(op->ptr, "weight"), threshold = RNA_float_get(op->ptr, "threshold");
+ const bool boolean_weights = RNA_boolean_get(op->ptr, "binary_weights");
+ float weight = absweight / 10.0f;
- if (weight > 1) {
+ if (absweight == 20) {
+ weight = (float)SHRT_MAX;
+ }
+ else if (absweight == 1) {
+ weight = 1 / (float)SHRT_MAX;
+ }
+ else if (weight > 1) {
weight = (weight - 1) * 10;
}
@@ -6706,13 +6712,14 @@ void MESH_OT_average_loop_normals(struct wmOperatorType *ot)
ot->prop = RNA_def_float(ot->srna, "threshold", 0.01f, 0, 5, "Threshold", "Threshold value for different weights to be considered equal", 0, 5);
- ot->prop = RNA_def_boolean(ot->srna, "boolean_weights", 0, "Boolean Weights", "Sets weight of smooth faces to 0. Weight of flat faces remains unchanged");
+ ot->prop = RNA_def_boolean(ot->srna, "binary_weights", 0, "Binary Weights", "Sets weight of smooth faces to 0. Weight of flat faces remains unchanged");
}
/********************** Copy/Paste Loop Normals **********************/
static int edbm_copy_paste_normal_exec(bContext *C, wmOperator *op)
{
+
Object *obedit = CTX_data_edit_object(C);
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
@@ -6726,6 +6733,12 @@ static int edbm_copy_paste_normal_exec(bContext *C, wmOperator *op)
int i = 0;
if (copy && (op->flag & OP_IS_INVOKE)) {
+ if (bm->totfacesel != 1 && ld->totloop != 1 && bm->totvertsel != 1) {
+ BKE_report(op->reports, RPT_ERROR, "Can only copy Split normal, Averaged vertex normal or Face normal");
+ MEM_freeN(ld->normal);
+ MEM_freeN(ld);
+ return OPERATOR_CANCELLED;
+ }
bool join = ld->totloop > 0 ? true : false;
for (; i < ld->totloop; i++, tld++) {
if (!compare_v3v3(ld->normal->nloc, tld->nloc, 1e-4f))
@@ -6743,13 +6756,15 @@ static int edbm_copy_paste_normal_exec(bContext *C, wmOperator *op)
}
}
}
- else {
- BKE_report(op->reports, RPT_ERROR, "Invalid Selection");
+ else if (!join) {
+ BKE_report(op->reports, RPT_ERROR, "Can only copy Split normal, Averaged vertex normal or Face normal");
+ MEM_freeN(ld->normal);
+ MEM_freeN(ld);
return OPERATOR_CANCELLED;
}
op->flag &= ~OP_IS_INVOKE; //required to make target editable from ui
}
- else if (!copy){
+ else if (!copy) {
float normal_val[3];
RNA_float_get_array(op->ptr, "normal_vector", normal_val);
@@ -6764,6 +6779,7 @@ static int edbm_copy_paste_normal_exec(bContext *C, wmOperator *op)
BKE_lnor_space_custom_normal_to_data(bm->lnor_spacearr->lspacearr[tld->loop_index], abs_normal, tld->clnors_data);
}
else {
+ normalize_v3(normal_val);
BKE_lnor_space_custom_normal_to_data(bm->lnor_spacearr->lspacearr[tld->loop_index], normal_val, tld->clnors_data);
}
}
@@ -6798,11 +6814,11 @@ void MESH_OT_copy_normal(struct wmOperatorType *ot)
ot->prop = RNA_def_boolean(ot->srna, "copy", 1, "Copy Normal", "Copy normal of mesh");
RNA_def_property_flag(ot->prop, PROP_HIDDEN);
- PropertyRNA *prop = RNA_def_boolean(ot->srna, "absolute", 0, "Absolute", "Absolute value to copy");
+ PropertyRNA *prop = RNA_def_boolean(ot->srna, "absolute", 0, "Absolute Coordinates", "Copy Absolute coordinates or Normal direction");
prop = RNA_def_property(ot->srna, "normal_vector", PROP_FLOAT, PROP_XYZ);
RNA_def_property_array(prop, 3);
- RNA_def_property_ui_text(prop, "Copied Normal", "Normal vector of copied face or loop");
+ RNA_def_property_ui_text(prop, "Copied Normal", "Normal vector of copied face or vertex");
}
static int edbm_set_normals_from_faces_exec(bContext *C, wmOperator *op)
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 23b73a2e78d..181ef91b109 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1633,7 +1633,7 @@ enum {
enum {
MOD_WEIGHTEDNORMAL_KEEP_SHARP = (1 << 0),
MOD_WEIGHTEDNORMAL_INVERT_VGROUP = (1 << 1),
- MOD_WEIGHTEDNORMAL_BOOL_WEIGHTS = (1 << 2),
+ MOD_WEIGHTEDNORMAL_BIN_WEIGHTS = (1 << 2),
};
#define MOD_MESHSEQ_READ_ALL \
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index ec8e9347be8..52595084159 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -4807,9 +4807,9 @@ static void rna_def_modifier_weightednormal(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Invert", "Invert vertex group influence");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
- prop = RNA_def_property(srna, "boolean_weights", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_WEIGHTEDNORMAL_BOOL_WEIGHTS);
- RNA_def_property_ui_text(prop, "Boolean Weights", "Sets weight of smooth faces to 0. Weight of flat faces remains unchanged.");
+ prop = RNA_def_property(srna, "binary_weights", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", MOD_WEIGHTEDNORMAL_BIN_WEIGHTS);
+ RNA_def_property_ui_text(prop, "Binary Weights", "Sets weight of smooth faces to 0. Weight of flat faces remains unchanged.");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
}
diff --git a/source/blender/modifiers/intern/MOD_weighted_normal.c b/source/blender/modifiers/intern/MOD_weighted_normal.c
index 8a286737ef3..8735a737bf3 100644
--- a/source/blender/modifiers/intern/MOD_weighted_normal.c
+++ b/source/blender/modifiers/intern/MOD_weighted_normal.c
@@ -389,11 +389,11 @@ static void WeightedNormal_FaceArea(
int defgrp_index, const bool use_invert_vgroup, const float weight)
{
pair *face_area = MEM_mallocN(sizeof(*face_area) * numPoly, "__func__");
- const bool bool_weights = (wnmd->flag & MOD_WEIGHTEDNORMAL_BOOL_WEIGHTS) != 0;
+ const bool bin_weights = (wnmd->flag & MOD_WEIGHTEDNORMAL_BIN_WEIGHTS) != 0;
for (int mp_index = 0; mp_index < numPoly; mp_index++) {
face_area[mp_index].val = BKE_mesh_calc_poly_area(&mpoly[mp_index], &mloop[mpoly[mp_index].loopstart], mvert);
- if (bool_weights && (mpoly[mp_index].flag & ME_SMOOTH)) {
+ if (bin_weights && (mpoly[mp_index].flag & ME_SMOOTH)) {
face_area[mp_index].val = 0;
}
face_area[mp_index].index = mp_index;
@@ -414,7 +414,7 @@ static void WeightedNormal_CornerAngle(WeightedNormalModifierData *wnmd, Object
{
pair *corner_angle = MEM_mallocN(sizeof(*corner_angle) * numLoops, "__func__");
float *index_angle = MEM_mallocN(sizeof(*index_angle) * numLoops, "__func__");
- const bool bool_weights = (wnmd->flag & MOD_WEIGHTEDNORMAL_BOOL_WEIGHTS) != 0;
+ const bool bin_weights = (wnmd->flag & MOD_WEIGHTEDNORMAL_BIN_WEIGHTS) != 0;
/* index_angle is first used to calculate corner angle and is then used to store poly index for each loop */
for (int mp_index = 0; mp_index < numPoly; mp_index++) {
@@ -423,7 +423,7 @@ static void WeightedNormal_CornerAngle(WeightedNormalModifierData *wnmd, Object
for (int i = l_start; i < l_start + mpoly[mp_index].totloop; i++) {
corner_angle[i].val = (float)M_PI - index_angle[i];
- if (bool_weights && (mpoly[mp_index].flag & ME_SMOOTH)) {
+ if (bin_weights && (mpoly[mp_index].flag & ME_SMOOTH)) {
corner_angle[i].val = 0;
}
corner_angle[i].index = i;
@@ -447,7 +447,7 @@ static void WeightedNormal_FacewithAngle(WeightedNormalModifierData *wnmd, Objec
{
pair *combined = MEM_mallocN(sizeof(*combined) * numLoops, "__func__");
float *index_angle = MEM_mallocN(sizeof(*index_angle) * numLoops, "__func__");
- const bool bool_weights = (wnmd->flag & MOD_WEIGHTEDNOR
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list