Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add custom name support for osm maps and terrain #460

Draft
wants to merge 1 commit into
base: release
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -71,15 +71,18 @@ def download(self, url, filepath, data=None):
f.write(u.read())
print("Saving the file to %s..." % filepath)

def downloadOsmFile(self, osmDir, minLon, minLat, maxLon, maxLat):
def downloadOsmFile(self, osmDir, minLon, minLat, maxLon, maxLat, customName):
# find a file name for the OSM file
osmFileName = BaseApp.osmFileName % ""
counter = 1
while True:
osmFilepath = os.path.realpath( os.path.join(osmDir, osmFileName) )
if os.path.isfile(osmFilepath):
counter += 1
osmFileName = BaseApp.osmFileName % "_%s" % counter
if customName != "":
osmFileName = BaseApp.osmFileName % "_%s" % customName
else:
counter += 1
osmFileName = BaseApp.osmFileName % "_%s" % counter
else:
break
self.osmFilepath = osmFilepath
14 changes: 11 additions & 3 deletions app/blender.py
Original file line number Diff line number Diff line change
@@ -112,6 +112,7 @@ class BlenderApp(BaseApp):

voidValue = -32768
voidSubstitution = 0
customName = ""

def __init__(self):
super().__init__()
@@ -198,7 +199,7 @@ def initOsm(self, op, context):
]

if addon.osmSource == "server":
self.downloadOsmFile(osmDir, self.minLon, self.minLat, self.maxLon, self.maxLat)
self.downloadOsmFile(osmDir, self.minLon, self.minLat, self.maxLon, self.maxLat, self.customName)
else:
self.osmFilepath = os.path.realpath(bpy.path.abspath(self.osmFilepath))

@@ -531,10 +532,17 @@ def importTerrain(self, context):
v[2] -= minHeight

# create a mesh object in Blender
mesh = bpy.data.meshes.new("Terrain")
if context.scene.blosm.terrainName != "Terrain":
mesh = bpy.data.meshes.new(context.scene.blosm.terrainName)
else:
mesh = bpy.data.meshes.new("Terrain")
mesh.from_pydata(verts, [], indices)
mesh.update()
obj = bpy.data.objects.new("Terrain", mesh)
if context.scene.blosm.terrainName != "Terrain":
obj = bpy.data.objects.new(context.scene.blosm.terrainName, mesh)
else:
obj = bpy.data.objects.new("Terrain", mesh)

obj["height_offset"] = minHeight
context.scene.collection.objects.link(obj)
context.scene.blosm.terrainObject = obj.name
3 changes: 2 additions & 1 deletion app/command_line.py
Original file line number Diff line number Diff line change
@@ -42,6 +42,7 @@ def initArgParser(self):
argParser.add_argument("--osmFilepath", help="Path to an OSM file")
argParser.add_argument("--osmDir", help="A directory for the downloaded OSM files")
argParser.add_argument("--setupScript", help="The path to a custom setup script")
argParser.add_argument("--customName", help="A custom name for the downloaded OSM file", default="")

argParser.add_argument("--buildings", action='store_true', help="Import buildings", default=False)
argParser.add_argument("--highways", action='store_true', help="Import roads and paths", default=False)
@@ -76,7 +77,7 @@ def initOsm(self):
if self.osmFilepath:
self.osmFilepath = os.path.realpath(self.osmFilepath)
else:
self.downloadOsmFile(self.osmDir, self.minLon, self.minLat, self.maxLon, self.maxLat)
self.downloadOsmFile(self.osmDir, self.minLon, self.minLat, self.maxLon, self.maxLat, self.customName)

def render(self):
logger = self.logger
12 changes: 12 additions & 0 deletions gui/__init__.py
Original file line number Diff line number Diff line change
@@ -863,6 +863,12 @@ class BlosmProperties(bpy.types.PropertyGroup):
default = 3.
)

customName: bpy.props.StringProperty(
name = "Custom name",
description = "Custom name for the imported objects",
default = ""
)

defaultLevels: bpy.props.CollectionProperty(type = BlosmDefaultLevelsEntry)

defaultLevelsIndex: bpy.props.IntProperty(
@@ -922,6 +928,12 @@ class BlosmProperties(bpy.types.PropertyGroup):
description="Primitive type used for the terrain mesh: quad or triangle",
default="quad"
)

terrainName: bpy.props.StringProperty(
name="Terrain name",
description="Name for the terrain object",
default="Terrain"
)

# Number of vertex reduction
# The Reduction Ratio is a divider of 1200
2 changes: 2 additions & 0 deletions parse/osm/__init__.py
Original file line number Diff line number Diff line change
@@ -77,6 +77,8 @@ def __init__(self, app):
self.minLon = 0.
self.maxLon = 0.

self.customName = ""

def addCondition(self, condition, layerId=None, manager=None, renderer=None):
self.conditions.append(
(condition, manager, renderer, layerId)
13 changes: 11 additions & 2 deletions terrain/__init__.py
Original file line number Diff line number Diff line change
@@ -261,9 +261,18 @@ def createFlatTerrain(minLon, minLat, maxLon, maxLat, projection, context):
vertsCounter += 1

# create a mesh object in Blender
mesh = bpy.data.meshes.new("Terrain")
if context.scene.blosm.terrainName != "Terrain":
mesh = bpy.data.meshes.new(context.scene.blosm.terrainName)
else:
mesh = bpy.data.meshes.new("Terrain")

mesh.from_pydata(verts, [], indices)
mesh.update()
obj = bpy.data.objects.new("Terrain", mesh)

if context.scene.blosm.terrainName != "Terrain":
obj = bpy.data.objects.new(context.scene.blosm.terrainName, mesh)
else:
obj = bpy.data.objects.new("Terrain", mesh)

bpy.context.scene.collection.objects.link(obj)
return obj.name