Refactor building assembly module
This commit is contained in:
@@ -52,12 +52,10 @@ from osmassets.materials import ( # noqa: E402
|
||||
from osmassets.mesh import ( # noqa: E402
|
||||
MeshBatch,
|
||||
add_polyline,
|
||||
add_roof,
|
||||
add_wall_panel,
|
||||
make_prism,
|
||||
new_collection,
|
||||
)
|
||||
from osmassets.osm import Projector, parse_height, parse_osm # noqa: E402
|
||||
from osmassets import building as _building # noqa: E402
|
||||
from osmassets import fountain as _fountain # noqa: E402
|
||||
from osmassets import water as _water # noqa: E402
|
||||
from osmassets import grass as _grass # noqa: E402
|
||||
@@ -65,35 +63,6 @@ from osmassets import scrub as _scrub # noqa: E402
|
||||
from osmassets import tree as _tree # noqa: E402
|
||||
|
||||
|
||||
# Building assembly stays in this file because it needs make_prism, add_roof,
|
||||
# add_wall_panel, and add_building_details — Blender geometry helpers that
|
||||
# live a few lines above. The other feature assembly code lives under
|
||||
# osmassets/ and keeps build() focused on data dispatch, materials, and counts.
|
||||
def _assemble_building(ring, way_id, tag, args, buildings_c, building_mats):
|
||||
industrial = (tag.get("building") == "industrial" and
|
||||
way_id not in args["office_overrides"])
|
||||
source_height = max(3.0, parse_height(tag, 12.0))
|
||||
height = source_height if industrial or source_height >= 30.0 else 11.4
|
||||
material = building_mats["industrial"] if industrial else building_mats["default"]
|
||||
building_name = "Building_" + way_id
|
||||
building_obj = make_prism(building_name, ring, 0.08, height,
|
||||
material, buildings_c)
|
||||
if building_obj:
|
||||
building_obj["osm_height"] = source_height
|
||||
building_obj["render_height"] = height
|
||||
building_obj["building_kind"] = "industrial" if industrial else "office"
|
||||
building_obj["osm_building_tag"] = tag.get("building", "")
|
||||
building_obj["office_override"] = way_id in args["office_overrides"]
|
||||
bevel = building_obj.modifiers.new("Soft facade edges", "BEVEL")
|
||||
bevel.width = 0.16
|
||||
bevel.segments = 2
|
||||
roof_mat = (building_mats["industrial_roof"] if industrial
|
||||
else building_mats["office_roof"])
|
||||
add_roof(building_name, ring, height + 0.095, roof_mat, buildings_c)
|
||||
add_building_details(building_name, ring, height, industrial,
|
||||
building_mats, buildings_c)
|
||||
return 1, int(industrial), ring
|
||||
|
||||
MODEL_ROOT = os.path.abspath(os.path.join(
|
||||
os.path.dirname(__file__), "..", "assets", "models", "polyhaven"
|
||||
))
|
||||
@@ -176,34 +145,6 @@ def cli_args():
|
||||
return values
|
||||
|
||||
|
||||
def add_building_details(name, ring, height, industrial, materials, collection):
|
||||
footprint = ring[:-1] if len(ring) > 1 and ring[0] == ring[-1] else ring
|
||||
if len(footprint) < 3:
|
||||
return
|
||||
glass_mat = materials["factory_glass"] if industrial else materials["glass"]
|
||||
|
||||
glass_batch = MeshBatch(name + "_Windows", collection, glass_mat)
|
||||
edges = list(zip(footprint, footprint[1:] + footprint[:1]))
|
||||
if industrial:
|
||||
band_height = min(1.8, max(0.75, height * 0.16))
|
||||
band_base = max(0.9, height * 0.52)
|
||||
for start, end in edges:
|
||||
add_wall_panel(glass_batch, start, end, band_base, band_height,
|
||||
thickness=0.055, inset=0.12)
|
||||
else:
|
||||
floor_height = 3.25
|
||||
floor_count = max(1, int((height - 0.7) / floor_height))
|
||||
for floor in range(floor_count):
|
||||
band_base = 0.55 + floor * floor_height + 0.95
|
||||
if band_base + 1.25 > height - 0.18:
|
||||
break
|
||||
for start, end in edges:
|
||||
add_wall_panel(glass_batch, start, end, band_base, 1.25,
|
||||
thickness=0.045, inset=0.10)
|
||||
glass_batch.finish()
|
||||
|
||||
|
||||
|
||||
def add_geojson_layer(path, layer, projector, collection, material, z):
|
||||
if not os.path.exists(path):
|
||||
return 0
|
||||
@@ -787,8 +728,9 @@ def build(args):
|
||||
tree_rows.append((ring, tag))
|
||||
focus_points.extend(ring)
|
||||
elif "building" in tag and len(ring) >= 3:
|
||||
added, ind_added, ring_pts = _assemble_building(
|
||||
ring, str(way["id"]), tag, args, buildings_c, building_mats)
|
||||
added, ind_added, ring_pts = _building.assemble(
|
||||
ring, str(way["id"]), tag, args["office_overrides"],
|
||||
buildings_c, building_mats)
|
||||
counts["building_count"] += added
|
||||
counts["industrial_count"] += ind_added
|
||||
if ring_pts:
|
||||
|
||||
Reference in New Issue
Block a user