Skip to content

Commit

Permalink
generator refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ranjian0 committed Nov 29, 2021
1 parent e5dfe0e commit 23f4d15
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions btools/building/generator.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
import bpy
import bmesh
import btools
import random

from contextlib import contextmanager


@contextmanager
def select_top_faces():
with btools.utils.bmesh_from_active_object(bpy.context) as bm:
max_z = max([f.calc_center_median().z for f in bm.faces])
top_faces = [f for f in bm.faces if f.calc_center_median().z == max_z]
btools.utils.select(top_faces)

yield

top_faces = btools.utils.validate(top_faces)
btools.utils.select(top_faces, False)

class BuildingGenerator:
_props = None

def __init__(self):
self.obj = None

@staticmethod
@contextmanager
def select_top_faces():
with btools.utils.bmesh_from_active_object(bpy.context) as bm:
max_z = max([f.calc_center_median().z for f in bm.faces])
top_faces = [f for f in bm.faces if f.calc_center_median().z == max_z]
btools.utils.select(top_faces)

yield

top_faces = btools.utils.validate(top_faces)
btools.utils.select(top_faces, False)

def build_random(self):
self.obj = FloorplanGenerator().build_random()

Expand All @@ -34,7 +32,7 @@ def build_random(self):
bpy.ops.object.mode_set(mode="EDIT")

FloorGenerator().build_random()
with self.select_top_faces():
with select_top_faces():
RoofGenerator().build_random()

# Reset Context
Expand Down

0 comments on commit 23f4d15

Please sign in to comment.