def handler(way, parser, kwargs): # Never add building parts when importing as single mesh. if kwargs["bm"]: return wayNodes = way["nodes"] numNodes = len( wayNodes ) - 1 # we need to skip the last node which is the same as the first ones # a polygon must have at least 3 vertices if numNodes < 3: return tags = way["tags"] osmId = way["id"] # compose object name name = osmId if "addr:housenumber" in tags and "addr:street" in tags: name = tags["addr:street"] + ", " + tags["addr:housenumber"] elif "name" in tags: name = tags["name"] min_height = 0 height = 0 if "building:min_height" in tags: # There's a height tag. It's parsed as text and could look like: 25, 25m, 25 ft, etc. min_height, unit = osm_utils.parse_scalar_and_unit( tags["building:min_height"]) if "height" in tags: # There's a height tag. It's parsed as text and could look like: 25, 25m, 25 ft, etc. height, unit = osm_utils.parse_scalar_and_unit(tags["height"]) bm = kwargs["bm"] if kwargs["bm"] else bmesh.new() verts = [] for node in range(numNodes): node = parser.nodes[wayNodes[node]] v = kwargs["projection"].fromGeographic(node["lat"], node["lon"]) verts.append(bm.verts.new((v[0], v[1], min_height))) bm.faces.new(verts) tags = way["tags"] # extrude if (height - min_height) > 0: utils.extrudeMesh(bm, (height - min_height)) bm.normal_update() mesh = bpy.data.meshes.new(osmId) bm.to_mesh(mesh) obj = bpy.data.objects.new(name, mesh) bpy.context.scene.objects.link(obj) bpy.context.scene.update() # final adjustments obj.select = True # assign OSM tags to the blender object osm_utils.assignTags(obj, tags)
def handler(way, parser, kwargs): # Never add building parts when importing as single mesh. if kwargs["bm"]: return wayNodes = way["nodes"] numNodes = len(wayNodes)-1 # we need to skip the last node which is the same as the first ones # a polygon must have at least 3 vertices if numNodes<3: return tags = way["tags"] osmId = way["id"] # compose object name name = osmId if "addr:housenumber" in tags and "addr:street" in tags: name = tags["addr:street"] + ", " + tags["addr:housenumber"] elif "name" in tags: name = tags["name"] min_height = 0 height = 0 if "building:min_height" in tags: # There's a height tag. It's parsed as text and could look like: 25, 25m, 25 ft, etc. min_height,unit = osm_utils.parse_scalar_and_unit(tags["building:min_height"]) if "height" in tags: # There's a height tag. It's parsed as text and could look like: 25, 25m, 25 ft, etc. height,unit = osm_utils.parse_scalar_and_unit(tags["height"]) bm = kwargs["bm"] if kwargs["bm"] else bmesh.new() verts = [] for node in range(numNodes): node = parser.nodes[wayNodes[node]] v = kwargs["projection"].fromGeographic(node["lat"], node["lon"]) verts.append( bm.verts.new((v[0], v[1], min_height)) ) bm.faces.new(verts) tags = way["tags"] # extrude if (height-min_height)>0: utils.extrudeMesh(bm, (height-min_height)) bm.normal_update() mesh = bpy.data.meshes.new(osmId) bm.to_mesh(mesh) obj = bpy.data.objects.new(name, mesh) bpy.context.scene.objects.link(obj) bpy.context.scene.update() # final adjustments obj.select = True # assign OSM tags to the blender object osm_utils.assignTags(obj, tags)
def handler(way, parser, kwargs): wayNodes = way["nodes"] numNodes = len( wayNodes ) - 1 # we need to skip the last node which is the same as the first ones # a polygon must have at least 3 vertices if numNodes < 3: return if not kwargs["bm"]: # not a single mesh tags = way["tags"] osmId = way["id"] # compose object name name = osmId if "addr:housenumber" in tags and "addr:street" in tags: name = tags["addr:street"] + ", " + tags["addr:housenumber"] elif "name" in tags: name = tags["name"] bm = kwargs["bm"] if kwargs["bm"] else bmesh.new() verts = [] for node in range(numNodes): node = parser.nodes[wayNodes[node]] v = kwargs["projection"].fromGeographic(node["lat"], node["lon"]) verts.append(bm.verts.new((v[0], v[1], 0))) bm.faces.new(verts) if not kwargs["bm"]: tags = way["tags"] thickness = 0 if "height" in tags: # There's a height tag. It's parsed as text and could look like: 25, 25m, 25 ft, etc. thickness, unit = osm_utils.parse_scalar_and_unit( tags["height"]) else: thickness = kwargs["thickness"] if ("thickness" in kwargs) else 0 # extrude if thickness > 0: utils.extrudeMesh(bm, thickness) bm.normal_update() mesh = bpy.data.meshes.new(osmId) bm.to_mesh(mesh) obj = bpy.data.objects.new(name, mesh) bpy.context.scene.objects.link(obj) bpy.context.scene.update() # final adjustments obj.select = True # assign OSM tags to the blender object osm_utils.assignTags(obj, tags) utils.assignMaterials(obj, "roof", (1.0, 0.0, 0.0), [mesh.polygons[0]]) utils.assignMaterials(obj, "wall", (1, 0.7, 0.0), mesh.polygons[1:])
def handler(way, parser, kwargs): heightPerLevel = 2.70 # default height per level if building height is not specified wayNodes = way["nodes"] numNodes = len(wayNodes)-1 # we need to skip the last node which is the same as the first ones # a polygon must have at least 3 vertices if numNodes<3: return if not kwargs["bm"]: # not a single mesh tags = way["tags"] osmId = way["id"] # compose object name name = osmId if "addr:housenumber" in tags and "addr:street" in tags: name = tags["addr:street"] + ", " + tags["addr:housenumber"] elif "name" in tags: name = tags["name"] bm = kwargs["bm"] if kwargs["bm"] else bmesh.new() verts = [] for node in range(numNodes): node = parser.nodes[wayNodes[node]] v = kwargs["projection"].fromGeographic(node["lat"], node["lon"]) verts.append( bm.verts.new((v[0], v[1], 0)) ) bm.faces.new(verts) if not kwargs["bm"]: tags = way["tags"] thickness = 0 if "height" in tags: # There's a height tag. It's parsed as text and could look like: 25, 25m, 25 ft, etc. thickness,unit = osm_utils.parse_scalar_and_unit(tags["height"]) elif "building:levels" in tags: # If no height is given, calculate height of Building from Levels thickness = int(tags["building:levels"])*heightPerLevel else: thickness = kwargs["thickness"] if ("thickness" in kwargs) else 0 # extrude if thickness>0: utils.extrudeMesh(bm, thickness) bm.normal_update() mesh = bpy.data.meshes.new(osmId) bm.to_mesh(mesh) obj = bpy.data.objects.new(name, mesh) bpy.context.scene.objects.link(obj) bpy.context.scene.update() # final adjustments obj.select = True # assign OSM tags to the blender object osm_utils.assignTags(obj, tags) utils.assignMaterials( obj, "roof", (1.0,0.0,0.0), [mesh.polygons[0]] ) utils.assignMaterials( obj, "wall", (1,0.7,0.0), mesh.polygons[1:] )
def handler(way, parser, kwargs): singleMesh = kwargs["bm"] wayNodes = way["nodes"] numNodes = len( wayNodes ) - 1 # we need to skip the last node which is the same as the first ones # a polygon must have at least 3 vertices if numNodes < 3: return tags = way["tags"] if not singleMesh: osmId = way["id"] # compose object name name = osmId if "addr:housenumber" in tags and "addr:street" in tags: name = tags["addr:street"] + ", " + tags["addr:housenumber"] elif "name" in tags: name = tags["name"] min_height = 0. if "min_height" in tags: # There's a height tag. It's parsed as text and could look like: 25, 25m, 25 ft, etc. min_height = osm_utils.parse_scalar_and_unit(tags["min_height"])[0] elif "building:min_level" in tags: min_level = getNumber(tags["building:min_level"]) if not min_level is None: min_height = min_level * kwargs["levelHeight"] height = kwargs["defaultHeight"] if "height" in tags: # There's a height tag. It's parsed as text and could look like: 25, 25m, 25 ft, etc. height = osm_utils.parse_scalar_and_unit(tags["height"])[0] elif "building:levels" in tags: numLevels = getNumber(tags["building:levels"]) if not numLevels is None: height = numLevels * kwargs["levelHeight"] bm = kwargs["bm"] if singleMesh else bmesh.new() verts = [] for node in range(numNodes): node = parser.nodes.get(wayNodes[node]) if node is None: # skip that OSM way return v = kwargs["projection"].fromGeographic(node["lat"], node["lon"]) verts.append(bm.verts.new((v[0], v[1], min_height))) face = bm.faces.new(verts) # extrude if (height - min_height) > 0.: utils.extrudeMesh(bm, (height - min_height), face if singleMesh else None) if not singleMesh: bmesh.ops.recalc_face_normals(bm, faces=bm.faces) mesh = bpy.data.meshes.new(osmId) bm.to_mesh(mesh) obj = bpy.data.objects.new(name, mesh) bpy.context.scene.objects.link(obj) bpy.context.scene.update() # final adjustments obj.select = True # assign OSM tags to the blender object osm_utils.assignTags(obj, tags)