forked from bartvdbraak/blender
fix [#35453] "copy mirrored uv coords" doesn't work
- made precision configurable. - report a warning when doubles are found since they cause problems. added Polygon.center attribute to avoid calculating in python.
This commit is contained in:
parent
6d9fcdf983
commit
e03bbcec65
@ -21,7 +21,7 @@
|
|||||||
import bpy
|
import bpy
|
||||||
from bpy.types import Operator
|
from bpy.types import Operator
|
||||||
|
|
||||||
from bpy.props import EnumProperty
|
from bpy.props import EnumProperty, IntProperty
|
||||||
|
|
||||||
|
|
||||||
class MeshMirrorUV(Operator):
|
class MeshMirrorUV(Operator):
|
||||||
@ -36,6 +36,14 @@ class MeshMirrorUV(Operator):
|
|||||||
('NEGATIVE', "Negative", "")),
|
('NEGATIVE', "Negative", "")),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
precision = IntProperty(
|
||||||
|
name="Precision",
|
||||||
|
description=("Tolerance for finding vertex duplicates"),
|
||||||
|
min=1, max=16,
|
||||||
|
soft_min=1, soft_max=16,
|
||||||
|
default=3,
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def poll(cls, context):
|
def poll(cls, context):
|
||||||
obj = context.active_object
|
obj = context.active_object
|
||||||
@ -43,6 +51,8 @@ class MeshMirrorUV(Operator):
|
|||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
DIR = (self.direction == 'NEGATIVE')
|
DIR = (self.direction == 'NEGATIVE')
|
||||||
|
precision = self.precision
|
||||||
|
double_warn = 0
|
||||||
|
|
||||||
ob = context.active_object
|
ob = context.active_object
|
||||||
is_editmode = (ob.mode == 'EDIT')
|
is_editmode = (ob.mode == 'EDIT')
|
||||||
@ -55,12 +65,14 @@ class MeshMirrorUV(Operator):
|
|||||||
mirror_gt = {}
|
mirror_gt = {}
|
||||||
mirror_lt = {}
|
mirror_lt = {}
|
||||||
|
|
||||||
vcos = (v.co.to_tuple(5) for v in mesh.vertices)
|
vcos = (v.co.to_tuple(precision) for v in mesh.vertices)
|
||||||
|
|
||||||
for i, co in enumerate(vcos):
|
for i, co in enumerate(vcos):
|
||||||
if co[0] >= 0.0:
|
if co[0] >= 0.0:
|
||||||
|
double_warn += co in mirror_gt
|
||||||
mirror_gt[co] = i
|
mirror_gt[co] = i
|
||||||
if co[0] <= 0.0:
|
if co[0] <= 0.0:
|
||||||
|
double_warn += co in mirror_lt
|
||||||
mirror_lt[co] = i
|
mirror_lt[co] = i
|
||||||
|
|
||||||
#for i, v in enumerate(mesh.vertices):
|
#for i, v in enumerate(mesh.vertices):
|
||||||
@ -95,10 +107,7 @@ class MeshMirrorUV(Operator):
|
|||||||
(uv.select for uv in uv_loops[lstart:lend]))
|
(uv.select for uv in uv_loops[lstart:lend]))
|
||||||
# Vert idx of the poly.
|
# Vert idx of the poly.
|
||||||
vidxs[i] = tuple(l.vertex_index for l in loops[lstart:lend])
|
vidxs[i] = tuple(l.vertex_index for l in loops[lstart:lend])
|
||||||
# As we have no poly.center yet...
|
pcents[i] = p.center
|
||||||
pcents[i] = tuple(map(lambda x: x / p.loop_total,
|
|
||||||
map(sum, zip(*(verts[idx].co
|
|
||||||
for idx in vidxs[i])))))
|
|
||||||
# Preparing next step finding matching polys.
|
# Preparing next step finding matching polys.
|
||||||
mirror_pm[tuple(sorted(vidxs[i]))] = i
|
mirror_pm[tuple(sorted(vidxs[i]))] = i
|
||||||
|
|
||||||
@ -135,4 +144,9 @@ class MeshMirrorUV(Operator):
|
|||||||
if is_editmode:
|
if is_editmode:
|
||||||
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
|
bpy.ops.object.mode_set(mode='EDIT', toggle=False)
|
||||||
|
|
||||||
|
if double_warn:
|
||||||
|
self.report({'WARNING'},
|
||||||
|
"%d duplicates found, mirror may be incomplete" %
|
||||||
|
double_warn)
|
||||||
|
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
@ -326,10 +326,17 @@ static void rna_MeshPolygon_normal_get(PointerRNA *ptr, float *values)
|
|||||||
Mesh *me = rna_mesh(ptr);
|
Mesh *me = rna_mesh(ptr);
|
||||||
MPoly *mp = (MPoly *)ptr->data;
|
MPoly *mp = (MPoly *)ptr->data;
|
||||||
|
|
||||||
/* BMESH_TODO: might be faster to look for a CD_NORMALS layer and use that */
|
|
||||||
BKE_mesh_calc_poly_normal(mp, me->mloop + mp->loopstart, me->mvert, values);
|
BKE_mesh_calc_poly_normal(mp, me->mloop + mp->loopstart, me->mvert, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void rna_MeshPolygon_center_get(PointerRNA *ptr, float *values)
|
||||||
|
{
|
||||||
|
Mesh *me = rna_mesh(ptr);
|
||||||
|
MPoly *mp = (MPoly *)ptr->data;
|
||||||
|
|
||||||
|
BKE_mesh_calc_poly_center(mp, me->mloop + mp->loopstart, me->mvert, values);
|
||||||
|
}
|
||||||
|
|
||||||
static float rna_MeshPolygon_area_get(PointerRNA *ptr)
|
static float rna_MeshPolygon_area_get(PointerRNA *ptr)
|
||||||
{
|
{
|
||||||
Mesh *me = (Mesh *)ptr->id.data;
|
Mesh *me = (Mesh *)ptr->id.data;
|
||||||
@ -1880,6 +1887,12 @@ static void rna_def_mpolygon(BlenderRNA *brna)
|
|||||||
RNA_def_property_float_funcs(prop, "rna_MeshPolygon_normal_get", NULL, NULL);
|
RNA_def_property_float_funcs(prop, "rna_MeshPolygon_normal_get", NULL, NULL);
|
||||||
RNA_def_property_ui_text(prop, "Face normal", "Local space unit length normal vector for this polygon");
|
RNA_def_property_ui_text(prop, "Face normal", "Local space unit length normal vector for this polygon");
|
||||||
|
|
||||||
|
prop = RNA_def_property(srna, "center", PROP_FLOAT, PROP_NONE);
|
||||||
|
RNA_def_property_array(prop, 3);
|
||||||
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||||
|
RNA_def_property_float_funcs(prop, "rna_MeshPolygon_center_get", NULL, NULL);
|
||||||
|
RNA_def_property_ui_text(prop, "Face center", "Center of the polygon");
|
||||||
|
|
||||||
prop = RNA_def_property(srna, "area", PROP_FLOAT, PROP_UNSIGNED);
|
prop = RNA_def_property(srna, "area", PROP_FLOAT, PROP_UNSIGNED);
|
||||||
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||||
RNA_def_property_float_funcs(prop, "rna_MeshPolygon_area_get", NULL, NULL);
|
RNA_def_property_float_funcs(prop, "rna_MeshPolygon_area_get", NULL, NULL);
|
||||||
|
@ -105,7 +105,10 @@ static void matrix_from_obj_pchan(float mat[4][4], Object *ob, const char *bonen
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define OMP_LIMIT 1000
|
#ifdef _OPENMP
|
||||||
|
# define OMP_LIMIT 1000
|
||||||
|
#endif
|
||||||
|
|
||||||
static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
|
static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
|
||||||
DerivedMesh *dm,
|
DerivedMesh *dm,
|
||||||
ModifierApplyFlag UNUSED(flag))
|
ModifierApplyFlag UNUSED(flag))
|
||||||
|
Loading…
Reference in New Issue
Block a user