Skip to main content
added 166 characters in body
Source Link
batFINGER
  • 85.1k
  • 10
  • 114
  • 244

Here are some updates to the script https://github.com/vvoovv/blender-geo/blob/master/io_import_scene_osm.py

Extruded buildings based on building:levels using a level_height setting in import. Also added a scale setting.

https://gist.github.com/batFINGER/87ad90900be589281eeeaa83697d541f

Result So far.

enter image description here

Haven't done much with roofs yet.

Till I add it into code proper this adds some materials / object color to buildings

import bpy
from bpy import context

# CoDEmanX from BA.org
def hex_to_rgb(color_str):
    # supports '123456', '#123456' and '0x123456'
    (r,g,b), a = map(lambda component: component / 255, bytes.fromhex(color_str[-6:])), 1.0
    return (r,g,b,a)

scene = context.scene
# buildings with material

bm = [b for b in scene.objects if "building:colour" in b.keys()]
materials = {}
for b in bm:
    matname = b.get("building:material")
    if matname is None:
        matname = "building:material"
    mat = bpy.data.materials.get(matname)
    if mat is None:
        mat = bpy.data.materials.new(matname)
    mat.use_object_color = True
    if matname not in b.data.materials:
        b.data.materials.append(mat)
    if b.get("building:colour"):
        b.color = hex_to_rgb(b.get("building:colour"))

Might also pay to have a look at osm2x3d to convert to x3d and import from that format. (Haven't tried)

Here are some updates to the script https://github.com/vvoovv/blender-geo/blob/master/io_import_scene_osm.py

Extruded buildings based on building:levels using a level_height setting in import. Also added a scale setting.

https://gist.github.com/batFINGER/87ad90900be589281eeeaa83697d541f

Result So far.

enter image description here

Haven't done much with roofs yet.

Till I add it into code proper this adds some materials / object color to buildings

import bpy
from bpy import context

# CoDEmanX from BA.org
def hex_to_rgb(color_str):
    # supports '123456', '#123456' and '0x123456'
    (r,g,b), a = map(lambda component: component / 255, bytes.fromhex(color_str[-6:])), 1.0
    return (r,g,b,a)

scene = context.scene
# buildings with material

bm = [b for b in scene.objects if "building:colour" in b.keys()]
materials = {}
for b in bm:
    matname = b.get("building:material")
    if matname is None:
        matname = "building:material"
    mat = bpy.data.materials.get(matname)
    if mat is None:
        mat = bpy.data.materials.new(matname)
    mat.use_object_color = True
    if matname not in b.data.materials:
        b.data.materials.append(mat)
    if b.get("building:colour"):
        b.color = hex_to_rgb(b.get("building:colour"))

Here are some updates to the script https://github.com/vvoovv/blender-geo/blob/master/io_import_scene_osm.py

Extruded buildings based on building:levels using a level_height setting in import. Also added a scale setting.

https://gist.github.com/batFINGER/87ad90900be589281eeeaa83697d541f

Result So far.

enter image description here

Haven't done much with roofs yet.

Till I add it into code proper this adds some materials / object color to buildings

import bpy
from bpy import context

# CoDEmanX from BA.org
def hex_to_rgb(color_str):
    # supports '123456', '#123456' and '0x123456'
    (r,g,b), a = map(lambda component: component / 255, bytes.fromhex(color_str[-6:])), 1.0
    return (r,g,b,a)

scene = context.scene
# buildings with material

bm = [b for b in scene.objects if "building:colour" in b.keys()]
materials = {}
for b in bm:
    matname = b.get("building:material")
    if matname is None:
        matname = "building:material"
    mat = bpy.data.materials.get(matname)
    if mat is None:
        mat = bpy.data.materials.new(matname)
    mat.use_object_color = True
    if matname not in b.data.materials:
        b.data.materials.append(mat)
    if b.get("building:colour"):
        b.color = hex_to_rgb(b.get("building:colour"))

Might also pay to have a look at osm2x3d to convert to x3d and import from that format. (Haven't tried)

added 550 characters in body
Source Link
batFINGER
  • 85.1k
  • 10
  • 114
  • 244

EDIT: Just noticed I've only done levels for building parts, will update and get back.

Here is a quick fixare some updates to the script https://github.com/vvoovv/blender-geo/blob/master/io_import_scene_osm.py file at line 394

Extruded buildings based on building:levels using a level_height setting in import. Which basically assignsAlso added a height of 2 for each levelscale setting.

https://gist.github.com/batFINGER/87ad90900be589281eeeaa83697d541f

Result So far.

enter image description here

Haven't done much with roofs yet.

Till I add it into code proper this adds some materials / object color to buildings

   import bpy
from bpy import context

# ifCoDEmanX "height"from inBA.org
def tagshex_to_rgb(color_str):
    # supports '123456', '#123456' and '0x123456'
   # There's(r,g,b), a height tag.= It'smap(lambda parsedcomponent: ascomponent text/ and255, couldbytes.fromhex(color_str[-6:])), look1.0
 like: 25, 25m, 25return ft(r,g,b,a)

scene etc= context.scene
 # buildings with material

bm = [b for b in scene.objects if height"building:colour" =in parse_scalar_and_unitb.keys(tags["height"])[0]]
materials = {}
for b in bm:
    matname = b.get("building:material")
    if "levels"matname inis tagsNone:
 or       matname = "building:levels"material"
 in tags  mat = bpy.data.materials.get(matname)
    if mat is None:
        mat = bpy.data.materials.new(matname)
    mat.use_object_color = True
    if "height"matname not in tagsb.data.materials:
        b.data.materials.append(mat)
    if b.get("building:colour"):
      height = 2b.color *= inthex_to_rgb(tags["buildingb.get("building:levels"]colour"))

Gives this as a result, which based on your 2.5D pic is still quite a few buildings short.

[![enter image description here][1]][1]

Haven't looked into roofs yet. [1]: https://i.sstatic.net/VLqLw.png

EDIT: Just noticed I've only done levels for building parts, will update and get back.

Here is a quick fix to the https://github.com/vvoovv/blender-geo/blob/master/io_import_scene_osm.py file at line 394. Which basically assigns a height of 2 for each level

        if "height" in tags:
            # There's a height tag. It's parsed as text and could look like: 25, 25m, 25 ft, etc.
            height = parse_scalar_and_unit(tags["height"])[0]

        if "levels" in tags or "building:levels" in tags:
            if "height" not in tags:
                height = 2 * int(tags["building:levels"])

Gives this as a result, which based on your 2.5D pic is still quite a few buildings short.

[![enter image description here][1]][1]

Haven't looked into roofs yet. [1]: https://i.sstatic.net/VLqLw.png

Here are some updates to the script https://github.com/vvoovv/blender-geo/blob/master/io_import_scene_osm.py

Extruded buildings based on building:levels using a level_height setting in import. Also added a scale setting.

https://gist.github.com/batFINGER/87ad90900be589281eeeaa83697d541f

Result So far.

enter image description here

Haven't done much with roofs yet.

Till I add it into code proper this adds some materials / object color to buildings

import bpy
from bpy import context

# CoDEmanX from BA.org
def hex_to_rgb(color_str):
    # supports '123456', '#123456' and '0x123456'
    (r,g,b), a = map(lambda component: component / 255, bytes.fromhex(color_str[-6:])), 1.0
    return (r,g,b,a)

scene = context.scene
# buildings with material

bm = [b for b in scene.objects if "building:colour" in b.keys()]
materials = {}
for b in bm:
    matname = b.get("building:material")
    if matname is None:
        matname = "building:material"
    mat = bpy.data.materials.get(matname)
    if mat is None:
        mat = bpy.data.materials.new(matname)
    mat.use_object_color = True
    if matname not in b.data.materials:
        b.data.materials.append(mat)
    if b.get("building:colour"):
        b.color = hex_to_rgb(b.get("building:colour"))
added 90 characters in body
Source Link
batFINGER
  • 85.1k
  • 10
  • 114
  • 244

EDIT: Just noticed I've only done levels for building parts, will update and get back.

Here is a quick fix to the https://github.com/vvoovv/blender-geo/blob/master/io_import_scene_osm.py file at line 394. Which basically assigns a height of 2 for each level

        if "height" in tags:
            # There's a height tag. It's parsed as text and could look like: 25, 25m, 25 ft, etc.
            height = parse_scalar_and_unit(tags["height"])[0]

        if "levels" in tags or "building:levels" in tags:
            if "height" not in tags:
                height = 2 * int(tags["building:levels"])

Gives this as a result, which based on your 2.5D pic is still quite a few buildings short.

[![enter image description here][1]][1]

Haven't looked into roofs yet. [1]: https://i.sstatic.net/VLqLw.png

Here is a quick fix to the https://github.com/vvoovv/blender-geo/blob/master/io_import_scene_osm.py file at line 394. Which basically assigns a height of 2 for each level

        if "height" in tags:
            # There's a height tag. It's parsed as text and could look like: 25, 25m, 25 ft, etc.
            height = parse_scalar_and_unit(tags["height"])[0]

        if "levels" in tags or "building:levels" in tags:
            if "height" not in tags:
                height = 2 * int(tags["building:levels"])

Gives this as a result, which based on your 2.5D pic is still quite a few buildings short.

[![enter image description here][1]][1]

Haven't looked into roofs yet. [1]: https://i.sstatic.net/VLqLw.png

EDIT: Just noticed I've only done levels for building parts, will update and get back.

Here is a quick fix to the https://github.com/vvoovv/blender-geo/blob/master/io_import_scene_osm.py file at line 394. Which basically assigns a height of 2 for each level

        if "height" in tags:
            # There's a height tag. It's parsed as text and could look like: 25, 25m, 25 ft, etc.
            height = parse_scalar_and_unit(tags["height"])[0]

        if "levels" in tags or "building:levels" in tags:
            if "height" not in tags:
                height = 2 * int(tags["building:levels"])

Gives this as a result, which based on your 2.5D pic is still quite a few buildings short.

[![enter image description here][1]][1]

Haven't looked into roofs yet. [1]: https://i.sstatic.net/VLqLw.png

added 30 characters in body
Source Link
batFINGER
  • 85.1k
  • 10
  • 114
  • 244
Loading
Source Link
batFINGER
  • 85.1k
  • 10
  • 114
  • 244
Loading