Skip to content

Commit

Permalink
added roof mirroring
Browse files Browse the repository at this point in the history
  • Loading branch information
BlendingJake committed Jan 16, 2019
1 parent 62c1ace commit 906f996
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
19 changes: 19 additions & 0 deletions jv_builder_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 5 additions & 1 deletion jv_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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",
Expand Down
15 changes: 13 additions & 2 deletions jv_roofing.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

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

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 906f996

Please sign in to comment.