From 906f9962bc8de6a328274876696752931e4ba931 Mon Sep 17 00:00:00 2001 From: Jacob Morris Date: Wed, 16 Jan 2019 08:16:56 -0500 Subject: [PATCH] added roof mirroring --- jv_builder_base.py | 19 +++++++++++++++++++ jv_properties.py | 6 +++++- jv_roofing.py | 15 +++++++++++++-- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/jv_builder_base.py b/jv_builder_base.py index a84de82..c07e82e 100644 --- a/jv_builder_base.py +++ b/jv_builder_base.py @@ -524,3 +524,22 @@ def _mortar_geometry(props, dims: tuple): faces = [(0, 3, 2, 1)] return verts, faces + + @staticmethod + def _mirror(mesh, axis='X'): + """ + Duplicate and mirror existing geometry across the specified axis + :param mesh: the mesh to duplicate and mirror + :param axis: the axis to mirror across, must be in {'X', 'Y', 'Z'} + :return: + """ + # duplicate geometry + new_geom = bmesh.ops.duplicate(mesh, geom=mesh.verts[:] + mesh.edges[:] + mesh.faces[:])["geom"] + + i = {'X': 1, 'Y': 0, 'Z': 2}[axis.upper()] + for item in new_geom: + if isinstance(item, bmesh.types.BMVert): + item.co[i] *= -1 + + mesh.verts.ensure_lookup_table() + mesh.faces.ensure_lookup_table() diff --git a/jv_properties.py b/jv_properties.py index 1bcaafa..7e14151 100644 --- a/jv_properties.py +++ b/jv_properties.py @@ -112,7 +112,7 @@ class Cutout(PropertyGroup): ) local: BoolProperty( - name="Local Coordinates?", default=False, + name="Local Coordinates?", default=True, description="Are offset and rotation values in reference to the object's origin?", update=jv_on_property_update ) @@ -547,6 +547,10 @@ class JVProperties(PropertyGroup): description="The distance between the half-circles on the tiles", update=jv_on_property_update ) + mirror: BoolProperty( + name="Mirror?", default=False, description="Mirror roofing across X-axis?", update=jv_on_property_update + ) + # WINDOW SPECIFIC -------------------------------------------------------------------------- jamb_width: FloatProperty( name="Jamb Width", diff --git a/jv_roofing.py b/jv_roofing.py index b713cde..7a7d515 100644 --- a/jv_roofing.py +++ b/jv_roofing.py @@ -12,7 +12,7 @@ # along with this program. If not, see . from . jv_builder_base import JVBuilderBase -from mathutils import Euler +from mathutils import Euler, Vector from math import atan, cos, radians, sin, asin from . jv_utils import Units @@ -76,6 +76,11 @@ def draw(props, layout): layout.separator() layout.prop(props, "gap_uniform") + # mirror + if props.convert_source_object is None: + layout.separator() + layout.prop(props, "mirror", icon="MOD_MIRROR") + @staticmethod def update(props, context): if props.convert_source_object is not None: @@ -102,7 +107,13 @@ def update(props, context): rotation = Euler((rot, 0, 0)) JVRoofing._rotate_mesh_vertices(mesh, rotation) - # TODO: mirror + # mirror + if props.mirror: + shift = Vector((0, -props.width, 0)) + for v in mesh.verts: + v.co += shift + + JVRoofing._mirror(mesh) # cutouts if props.add_cutouts: