-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path__init__.py
764 lines (618 loc) · 26.4 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
"""
This file is a part of Blosm addon for Blender.
Copyright (C) 2014-2023 Vladimir Elistratov
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
bl_info = {
"name": "Blosm",
"author": "Vladimir Elistratov <[email protected]>",
"version": (2, 7, 11),
"blender": (4, 2, 0),
"location": "Right side panel > \"Blosm\" tab",
"description": "A few clicks import of OpenStreetMap, Google 3D cities, terrain, satellite imagery, web maps",
"warning": "",
"wiki_url": "https://github.com/vvoovv/blosm/wiki/Premium-Version",
"tracker_url": "https://github.com/vvoovv/blosm/issues",
"support": "COMMUNITY",
"category": "Import-Export",
"blosmAssets": "2021.05.07"
}
import os, sys, json, textwrap
# force cleanup of sys.modules to avoid conflicts with the other addons for Blender
for m in [
"action", "ape", "app", "building", "building2", "defs", "gpx", "grammar", "gui",
"item", "item_renderer", "lib", "manager", "material", "mpl", "overlay", "parse",
"pml", "realistic", "renderer", "script", "setup", "style", "terrain",
"threed_tiles", "util", "way"
]:
sys.modules.pop(m, 0)
def _checkPath():
path = os.path.dirname(os.path.realpath(__file__))
if path in sys.path:
sys.path.remove(path)
# make <path> the first one to search for a module
sys.path.insert(0, path)
sys.path.insert(1, os.path.join(path, "pml"))
sys.path.insert(2, os.path.join(path, "threed_tiles"))
_checkPath()
import bpy, bmesh, bgl, blf
from util.transverse_mercator import TransverseMercator
from renderer import Renderer
from parse.osm import Osm
import gui, ape
import app.blender as blenderApp
from defs import Keys
# set the minimum version for BLOSM assets
blenderApp.app.setMinAssetsVersion(bl_info["blosmAssets"])
# set addon version
blenderApp.app.version = bl_info["version"]
blenderApp.app.isPremium = os.path.isdir(os.path.join(os.path.dirname(os.path.realpath(__file__)), "realistic"))
class BlosmPreferences(bpy.types.AddonPreferences, ape.AssetPackageEditor):
bl_idname = __name__
screenType: bpy.props.EnumProperty(
name = "Screen type for addon preferences",
items = (
("preferences", "preferences", "preferences"),
("ape", "asset package editor", "asset package editor")
),
description = "Preferences of Asset Package Editor",
default = "preferences"
)
dataDir: bpy.props.StringProperty(
name = '',
subtype = 'DIR_PATH',
description = "Directory to store downloaded OpenStreetMap and terrain files"
)
assetsDir: bpy.props.StringProperty(
name = '',
subtype = 'DIR_PATH',
description = "Directory with assets (building_materials.blend, vegetation.blend). "+
"It can be also set in the addon GUI"
)
mapboxAccessToken: bpy.props.StringProperty(
name = "Mapbox access token",
description = "A string token to access overlays from Mapbox company"
)
arcgisAccessToken: bpy.props.StringProperty(
name = "ArcGIS access token",
description = "A string token (API Key) to access satellite imagery from ArcGIS location service"
)
googleMapsApiKey: bpy.props.StringProperty(
name = "Google 3D Tiles Key",
description = "A string token (API Key) to access 3D Tiles by Google"
)
osmServer: bpy.props.EnumProperty(
name = "OSM data server",
items = (
("overpass-api.de", "overpass-api.de: 8 cores, 128 GB RAM", "overpass-api.de: 8 cores, 128 GB RAM"),
("vk maps", "VK Maps: 56 cores, 384 GB RAM", "VK Maps: 56 cores, 384 GB RAM"),
("kumi.systems", "kumi.systems: 20 cores, 256 GB RAM", "kumi.systems: 20 cores, 256 GB RAM")
),
description = "OSM data server if the default one is inaccessible",
default = "overpass-api.de"
)
enableExperimentalFeatures: bpy.props.BoolProperty(
name = "Enable export (experimental)",
description = "Enable export to the popular 3D formats. Experimental feature! Use it with caution!",
default = False
)
def draw(self, context):
layout = self.layout
if blenderApp.app.isPremium:
layout.box().label(text="Thank you for purchasing the premium version!")
if self.enableExperimentalFeatures:
layout.row().prop(self, "screenType", expand=True)
if self.screenType == "ape":
self.drawApe(context)
else:
layout.label(text="Directory to store downloaded OpenStreetMap and terrain files:")
layout.prop(self, "dataDir")
if blenderApp.app.isPremium:
layout.label(text="Directory with assets (building_materials.blend, vegetation.blend):")
layout.prop(self, "assetsDir")
layout.separator()
layout.label(text="Paste one or more access tokens to get satellite imagery:")
split = layout.split(factor=0.9)
split.prop(self, "arcgisAccessToken")
split.operator("blosm.get_arcgis_token", text="Get it!")
split = layout.split(factor=0.9)
split.prop(self, "mapboxAccessToken")
split.operator("blosm.get_mapbox_token", text="Get it!")
split = layout.split(factor=0.9)
split.prop(self, "googleMapsApiKey")
split.operator("blosm.get_google_maps_api_key", text="Get it!")
layout.separator()
layout.box().label(text="Advanced settings:")
# Extensions might come later
#layout.operator("blosm.load_extensions", text="Load extensions")
layout.prop(self, "osmServer")
if blenderApp.app.isPremium:
layout.prop(self, "enableExperimentalFeatures", text="Enable experimental features")
blenderApp.app.addonName = BlosmPreferences.bl_idname
class BLOSM_OT_GetArcgisToken(bpy.types.Operator):
bl_idname = "blosm.get_arcgis_token"
bl_label = ""
bl_description = "Get ArcGIS API key"
bl_options = {'INTERNAL'}
url = "https://location.arcgis.com/sign-up/"
def execute(self, context):
import webbrowser
webbrowser.open_new_tab(self.url)
return {'FINISHED'}
class BLOSM_OT_GetMapboxToken(bpy.types.Operator):
bl_idname = "blosm.get_mapbox_token"
bl_label = ""
bl_description = "Get Mapbox access token"
bl_options = {'INTERNAL'}
url = "https://www.mapbox.com/account/access-tokens"
def execute(self, context):
import webbrowser
webbrowser.open_new_tab(self.url)
return {'FINISHED'}
class BLOSM_OT_GetGoogleMapsApiKey(bpy.types.Operator):
bl_idname = "blosm.get_google_maps_api_key"
bl_label = ""
bl_description = "Get Google 3D Tiles Key"
bl_options = {'INTERNAL'}
url = "https://developers.google.com/maps/documentation/tile/get-api-key"
def execute(self, context):
import webbrowser
webbrowser.open_new_tab(self.url)
return {'FINISHED'}
"""
class BLOSM_OT_LoadExtensions(bpy.types.Operator):
bl_idname = "blosm.load_extensions"
bl_label = ""
bl_description = "Scan Blender addons, find extensions for Blosm and load them"
bl_options = {'INTERNAL'}
def execute(self, context):
numExtensions = blednerApp.app.loadExtensions(context)
self.report({'INFO'},
"No extension found" if not numExtensions else\
("Loaded 1 extension" if numExtensions==1 else "Loaded %s extensions" % numExtensions)
)
return {'FINISHED'}
"""
class BLOSM_OT_ImportData(bpy.types.Operator):
"""Import data: OpenStreetMap or terrain"""
bl_idname = "blosm.import_data" # important since its how bpy.ops.blosm.import_data is constructed
bl_label = "Blosm"
bl_description = "Import data of the selected type (OpenStreetMap, Google 3D Tiles, terrain, etc)"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
a = blenderApp.app
dataType = context.scene.blosm.dataType
self.setup(context, a.addonName)
a.projection = None
a.setAttributes(context)
if dataType == "osm":
return self.importOsm(context)
elif dataType == "terrain":
return self.importTerrain(context)
elif dataType == "overlay":
return self.importOverlay(context)
elif dataType == "gpx":
return self.importGpx(context)
elif dataType == "3d-tiles":
return self.import3dTiles(context)
elif dataType == "geojson":
return self.importGeoJson(context)
return {'FINISHED'}
def setup(self, context, addonName):
# check if the file <setup_execute.py> is available
setup_function = self.loadSetupScript(
os.path.join(os.path.dirname(os.path.realpath(__file__)), "setup_execute.py"),
reportError=False
)
if setup_function:
setup_function(context, addonName)
def importOsm(self, context):
a = blenderApp.app
addon = context.scene.blosm
try:
a.initOsm(self, context)
except Exception as e:
self.report({'ERROR'}, str(e))
return {'CANCELLED'}
createFlatTerrain = a.mode is a.realistic and a.forests
forceExtentCalculation = createFlatTerrain and a.osmSource == "file"
setupScript = addon.setupScript
if setupScript:
setup_function = self.loadSetupScript(setupScript, reportError=True)
if not setup_function:
return {'CANCELLED'}
else:
if a.mode is a.realistic:
if a.enableExperimentalFeatures:
from setup.realistic_dev import setup as setup_function
else:
from setup.premium_default import setup as setup_function
else:
from setup.base import setup as setup_function
scene = context.scene
self.setObjectMode(context)
bpy.ops.object.select_all(action='DESELECT')
osm = Osm(a)
setup_function(a, osm)
a.createLayers(osm)
setLatLon = False
if "lat" in scene and "lon" in scene and a.relativeToInitialImport:
osm.setProjection(scene["lat"], scene["lon"])
elif a.osmSource == "server":
osm.setProjection( (a.minLat+a.maxLat)/2., (a.minLon+a.maxLon)/2. )
setLatLon = True
else:
# This is the case if <a.osmSource == "file"> and if the first condition is not true
setLatLon = True
osm.parse(a.osmFilepath, forceExtentCalculation=forceExtentCalculation)
if a.loadMissingMembers and a.incompleteRelations:
try:
a.loadMissingWays(osm)
except Exception as e:
self.report({'ERROR'}, str(e))
a.loadMissingMembers = False
a.processIncompleteRelations(osm)
if not osm.projection:
# <osm.projection> wasn't set so far if there were only incomplete relations that
# satisfy <osm.conditions>.
# See also the comments in <parse.osm.__init__.py>
# at the end of the method <osm.parse(..)>
osm.setProjection( (osm.minLat+osm.maxLat)/2., (osm.minLon+osm.maxLon)/2. )
if forceExtentCalculation:
a.minLat = osm.minLat
a.maxLat = osm.maxLat
a.minLon = osm.minLon
a.maxLon = osm.maxLon
# Check if have a terrain Blender object set
# At this point <a.projection> is set, so we can set the terrain
a.setTerrain(
context,
createFlatTerrain = createFlatTerrain,
createBvhTree = True
)
a.initLayers()
a.process()
a.render()
# Set <lon> and <lat> attributes for <scene> if necessary.
# <osm.projection> is set in <osm.setProjection(..)> along with <osm.lat> and <osm.lon>
# So we test if <osm.projection> is set, that also means that <osm.lat> and <osm.lon> are also set.
if setLatLon and osm.projection:
# <osm.lat> and <osm.lon> have been set in osm.parse(..)
self.setCenterLatLon(context, osm.lat, osm.lon)
a.clean()
return {'FINISHED'}
def getCenterLatLon(self, context):
a = blenderApp.app
scene = context.scene
if "lat" in scene and "lon" in scene and a.relativeToInitialImport:
lat = scene["lat"]
lon = scene["lon"]
setLatLon = False
else:
lat = (a.minLat+a.maxLat)/2.
lon = (a.minLon+a.maxLon)/2.
setLatLon = True
return lat, lon, setLatLon
def setCenterLatLon(self, context, lat, lon):
context.scene["lat"] = lat
context.scene["lon"] = lon
def loadSetupScript(self, setupScript, reportError):
setupScript = os.path.realpath(bpy.path.abspath(setupScript))
if not os.path.isfile(setupScript):
if reportError:
self.report({'ERROR'},
"The script file doesn't exist"
)
return None
import imp
# remove extension from the path
setupScript = os.path.splitext(setupScript)[0]
moduleName = os.path.basename(setupScript)
try:
_file, _pathname, _description = imp.find_module(moduleName, [os.path.dirname(setupScript)])
module = imp.load_module(moduleName, _file, _pathname, _description)
_file.close()
return module.setup
except Exception:
self.report({'ERROR'},
"Unable to execute the setup script! See the error message in the Blender console!"
)
return None
def importTerrain(self, context):
a = blenderApp.app
try:
a.initTerrain(context)
except Exception as e:
self.report({'ERROR'}, str(e))
return {'CANCELLED'}
lat, lon, setLatLon = self.getCenterLatLon(context)
a.setProjection(lat, lon)
a.importTerrain(context)
# set the custom parameters <lat> and <lon> to the active scene
if setLatLon:
self.setCenterLatLon(context, lat, lon)
return {'FINISHED'}
def importOverlay(self, context):
a = blenderApp.app
blosm = context.scene.blosm
# find the Blender area holding 3D View
for area in context.screen.areas:
if area.type == "VIEW_3D":
a.area = area
break
else:
a.area = None
lat, lon, setLatLon = self.getCenterLatLon(context)
a.setProjection(lat, lon)
try:
a.initOverlay(context)
except Exception as e:
self.report({'ERROR'}, str(e))
return {'CANCELLED'}
terrainObject = context.scene.objects.get(blosm.terrainObject)
minLon, minLat, maxLon, maxLat = a.getExtentFromObject(terrainObject, context)\
if terrainObject else\
(a.minLon, a.minLat, a.maxLon, a.maxLat)
a.overlay.prepareImport(minLon, minLat, maxLon, maxLat)
if blosm.commandLineMode:
hasTiles = True
while hasTiles:
hasTiles = blenderApp.app.overlay.importNextTile()
if blenderApp.app.overlay.finalizeImport():
self.report({'INFO'}, "Overlay import is finished!")
else:
self.report({'ERROR'}, "Probably something is wrong with the tile server!")
else:
bpy.ops.blosm.control_overlay()
# set the custom parameters <lat> and <lon> to the active scene
if setLatLon:
self.setCenterLatLon(context, lat, lon)
return {'FINISHED'}
def import3dTiles(self, context):
from threed_tiles.manager import BaseManager
from threed_tiles.blender import BlenderRenderer
addon = context.scene.blosm
google3dTiles = addon.threedTilesSource == "google"
renderer = BlenderRenderer(
"Google 3D Tiles" if google3dTiles else "3D Tiles",
addon.join3dTilesObjects,
addon.instanceName
)
manager = BaseManager(
"https://tile.googleapis.com/v1/3dtiles/root.json" if google3dTiles else addon.threedTilesUrl,
renderer
)
manager.cacheJsonFiles = addon.cacheJsonFiles
manager.cache3dFiles = addon.cache3dFiles
a = blenderApp.app
try:
a.init3dTiles(context, manager, "google")
except Exception as e:
self.report({'ERROR'}, str(e))
return {'CANCELLED'}
manager.centerLat, manager.centerLon, setLatLonHeight = self.getCenterLatLon(context)
if not setLatLonHeight and "height_offset" in context.scene:
renderer.heightOffset = context.scene["height_offset"]
else:
renderer.calculateHeightOffset = True
result = manager.render(a.minLon, a.minLat, a.maxLon, a.maxLat)
if len(result) == 1:
# a critical error happend
self.report({'ERROR'}, result[0])
return {'CANCELLED'}
numImportedTiles, errors = result
if numImportedTiles:
if setLatLonHeight:
context.scene["lat"] = manager.centerLat
context.scene["lon"] = manager.centerLon
if renderer.calculateHeightOffset:
context.scene["height_offset"] = renderer.heightOffset
self.report(
{'INFO'},
"Imported %s 3D Tiles. %s errors occured during the import. " % (numImportedTiles, len(errors)) +\
"See the System Console."\
if errors else\
"Successfully Imported %s 3D Tiles." % numImportedTiles
)
else:
self.report(
{'ERROR'},
"No 3D tiles were imported. %s errors occured during the import. " % len(errors) +\
"See the System Console."
)
if errors:
for error in errors:
print(error)
return {'FINISHED'} if numImportedTiles else {'CANCELLED'}
def importGpx(self, context):
from parse.gpx import Gpx
from gpx import GpxRenderer
a = blenderApp.app
try:
a.initGpx(context, BlosmPreferences.bl_idname)
except Exception as e:
self.report({'ERROR'}, str(e))
return {'CANCELLED'}
scene = context.scene
self.setObjectMode(context)
bpy.ops.object.select_all(action='DESELECT')
gpx = Gpx(a)
if "lat" in scene and "lon" in scene and a.relativeToInitialImport:
gpx.setProjection(scene["lat"], scene["lon"])
setLatLon = False
else:
setLatLon = True
gpx.parse(a.gpxFilepath)
# check if have a terrain Blender object set
a.setTerrain(
context,
createFlatTerrain = False,
createBvhTree = False
)
GpxRenderer(a).render(gpx)
# setting <lon> and <lat> attributes for <scene> if necessary
if setLatLon:
# <gpx.lat> and <gpx.lon> have been set in gpx.parse(..)
self.setCenterLatLon(context, gpx.lat, gpx.lon)
return {'FINISHED'}
def importGeoJson(self, context):
from parse.geojson import GeoJson
a = blenderApp.app
addon = context.scene.blosm
try:
a.initGeoJson(self, context)
except Exception as e:
self.report({'ERROR'}, str(e))
return {'CANCELLED'}
createFlatTerrain = a.mode is a.realistic and a.forests
forceExtentCalculation = createFlatTerrain
# check if have a terrain Blender object set
a.setTerrain(
context,
createFlatTerrain = createFlatTerrain,
createBvhTree = True
)
setupScript = addon.setupScript
if setupScript:
setup_function = self.loadSetupScript(setupScript, reportError=True)
if not setup_function:
return {'CANCELLED'}
else:
if a.mode is a.realistic:
from setup.premium_default import setup as setup_function
else:
from setup.geojson_base import setup as setup_function
scene = context.scene
self.setObjectMode(context)
bpy.ops.object.select_all(action='DESELECT')
data = GeoJson(a)
setup_function(a, data)
a.createLayers(data)
setLatLon = False
if "lat" in scene and "lon" in scene and a.relativeToInitialImport:
a.setProjection(scene["lat"], scene["lon"])
elif a.coordinatesAsFilter:
a.setProjection( (a.minLat+a.maxLat)/2., (a.minLon+a.maxLon)/2. )
else:
setLatLon = True
data.parse(a.osmFilepath, forceExtentCalculation=forceExtentCalculation)
if forceExtentCalculation:
a.minLat = data.minLat
a.maxLat = data.maxLat
a.minLon = data.minLon
a.maxLon = data.maxLon
a.initLayers()
a.process()
a.render()
# setting <lon> and <lat> attributes for <scene> if necessary
if setLatLon:
# <osm.lat> and <osm.lon> have been set in osm.parse(..)
self.setCenterLatLon(context, data.lat, data.lon)
a.clean()
return {'FINISHED'}
def setObjectMode(self, context):
scene = context.scene
# 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 available
if not context.view_layer.objects.active:
context.view_layer.objects.active = scene.objects[0]
bpy.ops.object.mode_set(mode="OBJECT")
# Also deselect the active object since the operator
# <bpy.ops.object.select_all(action='DESELECT')> does not affect hidden objects and
# the hidden active object
if context.view_layer.objects.active:
context.view_layer.objects.active.select_set(False)
class BLOSM_OT_ControlOverlay(bpy.types.Operator):
bl_idname = "blosm.control_overlay"
bl_label = ""
bl_description = "Control overlay import and display progress in the 3D View"
bl_options = {'INTERNAL'}
lineWidth = 70 # in characters
def modal(self, context, event):
if event.type == 'TIMER':
hasTiles = blenderApp.app.overlay.importNextTile()
if not hasTiles:
self.stop(context)
if blenderApp.app.overlay.finalizeImport():
self.report({'INFO'}, "Overlay import is finished!")
else:
self.report({'ERROR'}, "Probably something is wrong with the tile server!")
# cleanup
blenderApp.app.area = None
return {'FINISHED'}
return {'RUNNING_MODAL'}
def execute(self, context):
wm = context.window_manager
self._drawHandle = bpy.types.SpaceView3D.draw_handler_add(
self.drawMessage,
tuple(),
'WINDOW',
'POST_PIXEL'
)
self._timer = wm.event_timer_add(0.1, window=context.window)
wm.modal_handler_add(self)
return {'RUNNING_MODAL'}
def stop(self, context):
context.window_manager.event_timer_remove(self._timer)
bpy.types.SpaceView3D.draw_handler_remove(self._drawHandle, 'WINDOW')
blenderApp.app.stateMessage = None
self._timer = None
self._drawHandle = None
def drawMessage(self):
message = blenderApp.app.stateMessage
if message:
# draw message
fontId = 0
blf.color(fontId, 0., 1., 0., 1.)
if len(message)<=self.lineWidth:
self.drawLine(message, 60)
else:
for i,line in enumerate(reversed(textwrap.wrap(message, self.lineWidth))):
self.drawLine(line, 60+35*i)
def drawLine(self, content, yPosition):
fontId = 0
blf.position(fontId, 15, yPosition, 0)
blf.size(fontId, 20)
blf.draw(fontId, content)
def setHeaderText(self, context):
for area in context.screen.areas:
if area.type == "VIEW_3D":
area.header_text_set(blenderApp.app.stateMessage)
blenderApp.app.stateMessage = ''
return
_classes = (
BlosmPreferences,
BLOSM_OT_GetArcgisToken,
BLOSM_OT_GetMapboxToken,
BLOSM_OT_GetGoogleMapsApiKey,
#BLOSM_OT_LoadExtensions,
BLOSM_OT_ImportData,
BLOSM_OT_ControlOverlay
)
def register():
for c in _classes:
bpy.utils.register_class(c)
gui.register()
ape.register()
if blenderApp.app.has(Keys.mode3dRealistic):
import realistic
realistic.register()
def unregister():
for c in _classes:
bpy.utils.unregister_class(c)
gui.unregister()
ape.unregister()
if blenderApp.app.has(Keys.mode3dRealistic):
import realistic
realistic.unregister()