Пример #1
0
    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)
Пример #2
0
    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:] )
Пример #4
0
    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 execute(self, context):
        # setting active object if there is no active object
        if context.mode != "OBJECT":
            # if there is no object in the scene, only "OBJECT" mode is provided
            if not context.scene.objects.active:
                context.scene.objects.active = context.scene.objects[0]
            bpy.ops.object.mode_set(mode="OBJECT")

        bpy.ops.object.select_all(action="DESELECT")

        name = os.path.basename(self.filepath)

        if self.singleMesh:
            self.bm = bmesh.new()
        else:
            self.bm = None
            # create an empty object to parent all imported OSM objects
            bpy.ops.object.empty_add(type="PLAIN_AXES", location=(0, 0, 0))
            parentObject = context.active_object
            self.parentObject = parentObject
            parentObject.name = name

        self.read_osm_file(context)

        if self.singleMesh:
            bm = self.bm
            # extrude
            if self.thickness > 0:
                utils.extrudeMesh(bm, self.thickness)

            bm.normal_update()

            mesh = bpy.data.meshes.new(name)
            bm.to_mesh(mesh)

            obj = bpy.data.objects.new(name, mesh)
            bpy.context.scene.objects.link(obj)

            # remove double vertices
            context.scene.objects.active = obj
            bpy.ops.object.mode_set(mode="EDIT")
            bpy.ops.mesh.select_all(action="SELECT")
            bpy.ops.mesh.remove_doubles()
            bpy.ops.mesh.select_all(action="DESELECT")
            bpy.ops.object.mode_set(mode="OBJECT")

            bpy.context.scene.update()
        else:
            # perform parenting
            context.scene.objects.active = parentObject
            bpy.ops.object.parent_set()

        bpy.ops.object.select_all(action="DESELECT")
        return {"FINISHED"}
    def execute(self, context):
        # setting active object if there is no active object
        if context.mode != "OBJECT":
            # if there is no object in the scene, only "OBJECT" mode is provided
            if not context.scene.objects.active:
                context.scene.objects.active = context.scene.objects[0]
            bpy.ops.object.mode_set(mode="OBJECT")

        bpy.ops.object.select_all(action="DESELECT")

        name = os.path.basename(self.filepath)

        if self.singleMesh:
            self.bm = bmesh.new()
        else:
            self.bm = None
            # create an empty object to parent all imported OSM objects
            bpy.ops.object.empty_add(type="PLAIN_AXES", location=(0, 0, 0))
            parentObject = context.active_object
            self.parentObject = parentObject
            parentObject.name = name

        self.read_osm_file(context)

        if self.singleMesh:
            bm = self.bm
            # extrude
            if self.thickness > 0:
                utils.extrudeMesh(bm, self.thickness)

            bm.normal_update()

            mesh = bpy.data.meshes.new(name)
            bm.to_mesh(mesh)

            obj = bpy.data.objects.new(name, mesh)
            bpy.context.scene.objects.link(obj)

            # remove double vertices
            context.scene.objects.active = obj
            bpy.ops.object.mode_set(mode="EDIT")
            bpy.ops.mesh.select_all(action="SELECT")
            bpy.ops.mesh.remove_doubles()
            bpy.ops.mesh.select_all(action="DESELECT")
            bpy.ops.object.mode_set(mode="OBJECT")

            bpy.context.scene.update()
        else:
            # perform parenting
            context.scene.objects.active = parentObject
            bpy.ops.object.parent_set()

        bpy.ops.object.select_all(action="DESELECT")
        return {"FINISHED"}
Пример #7
0
    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"]
            thickness = kwargs["thickness"] if ("thickness" in kwargs) else 0
            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"]:
            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)
Пример #8
0
	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"]
			thickness = kwargs["thickness"] if ("thickness" in kwargs) else 0
			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"]:
			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)
Пример #9
0
    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)