diff --git a/__init__.py b/__init__.py index 01faf59..8546ac8 100644 --- a/__init__.py +++ b/__init__.py @@ -13,16 +13,17 @@ import sys import os + if "bpy" in locals(): import imp - + imp.reload(bLT_main) imp.reload(bLT_utils) print("bLT: Reloaded multifiles") else: from . import bLT_main from . import bLT_utils - + print("bLT: Imported multifiles") import bpy @@ -30,7 +31,7 @@ from bpy.types import AddonPreferences from bpy.props import StringProperty,CollectionProperty,IntProperty,BoolProperty - + class d0obqp1l(AddonPreferences): bl_idname = __name__ @@ -38,13 +39,17 @@ class d0obqp1l(AddonPreferences): description="Path to GDAL", maxlen= 1024, subtype='DIR_PATH', - default='c:\Program Files\GDAL\\') - + default="/usr/bin/" if os.name == "posix" else "c:\\Program Files\\GDAL\\" + ) + # Actually, this option makes little sense on Linux/Mac Systems, as the executables of GDAL are + # usually available in the path environment anyway. + d0p1olqb = StringProperty(name="Output", description="Path to Output folder", maxlen= 1024, subtype='DIR_PATH', - default='{}\\Documents\\'.format(os.environ['USERPROFILE'])) + default="{}".format(os.environ["HOME"]) if os.name == "posix" else os.path.join(os.environ['USERPROFILE'], "Documents") + ) def draw(self, context): layout = self.layout @@ -85,7 +90,7 @@ def register(): bpy.types.Scene.dq0p1bol = IntProperty(default=-1) bpy.context.user_preferences.filepaths.use_relative_paths = False - + def unregister(): for cls in classes: bpy.utils.unregister_class(cls) @@ -94,4 +99,4 @@ def unregister(): del bpy.types.Scene.dq0p1bol if __name__ == "__main__": - register() \ No newline at end of file + register() diff --git a/bLT_main.py b/bLT_main.py index 112c3a0..0ca416d 100644 --- a/bLT_main.py +++ b/bLT_main.py @@ -7,12 +7,11 @@ class dplq01bo(PropertyGroup): d0blo1qp = BoolProperty(name="",default=False) - + class dpq0bl1o(UIList): def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index): layout.prop(item, "name", text="", emboss=False) - icon = 'RESTRICT_VIEW_OFF' if item.d0blo1qp else 'RESTRICT_VIEW_ON' op = layout.operator("scene.dq10polb", text="", emboss=False, icon=icon) op.dol0qpb1 = index @@ -22,7 +21,7 @@ class d1qoplb0(bpy.types.Operator): bl_label = "Remove Location" bl_options = {'REGISTER'} bl_description = 'Removes current location(eye icon) without commiting any changes!!!' - + def execute(self, context): scene = bpy.data.scenes['Default_Location'] d0obpql1 = scene.d0obpql1 @@ -49,14 +48,12 @@ def execute(self, context): context.window.screen.scene = bpy.data.scenes['Default_Location'] context.scene.dbq0po1l = False context.scene.dlqbo01p = True - return {'FINISHED'} - + def invoke(self, context, event): - return context.window_manager.invoke_confirm(self,event) - + class dbq10plo(bpy.types.Operator): bl_idname = "scene.dq10polb" bl_label = "Switch Locations" @@ -81,7 +78,7 @@ def execute(self, context): bpy.ops.view3d.view_selected() return {'FINISHED'} - + class dobqlp01(bpy.types.Operator): bl_idname = "scene.do0lbq1p" bl_label = "Create Project" @@ -102,12 +99,12 @@ def execute(self, context): context.scene.d0blop1q = True return {'FINISHED'} - + class d0qobl1p(bpy.types.Operator): bl_idname = "scene.d1bqpo0l" bl_label = "Import Location" bl_description = 'Imports a new location' - + def execute(self, context): db0lqo1p() return {'FINISHED'} @@ -123,7 +120,7 @@ def execute(self, context): self.report({'WARNING'}, "Location with this name already exists! Try a different name.") bpy.ops.scene.d1bqpo0l() return {'CANCELLED'} - + global d0bp1qol,topLeftColumn,bottomRightRow,bottomRightColumn,d1qbpo0l,dlpo0q1b,dbl1o0qp,d01pqlob dq0b1plo(self.db10qolp,dbl1o0qp,d01pqlob,d0bp1qol,topLeftColumn,bottomRightRow,bottomRightColumn,d1qbpo0l,dlpo0q1b) @@ -143,28 +140,28 @@ def execute(self, context): bpy.ops.wm.save_mainfile() return {'FINISHED'} - + def invoke(self, context, event): self.db10qolp = 'Type location name here...' return context.window_manager.invoke_props_dialog(self) - + def cancel(self, context): context.area.type = 'VIEW_3D' return {'CANCELLED'} - + class d0o1plqb(bpy.types.Operator): bl_idname = "scene.dqpolb01" bl_label = "Commit Location" bl_description = 'Commits all terrain changes to elevation.bLTe\nand elevation.asc(Project\\Output)' - + def execute(self, context): dbpo1ql0() return {'FINISHED'} - + class dp0qbl1o(bpy.types.Operator): bl_idname = "view2d.dp0ql1bo" bl_label = "Pick Location" - + def modal(self, context, event): global d0bp1qol,topLeftColumn,bottomRightRow,bottomRightColumn,d1qbpo0l,dlpo0q1b,dbl1o0qp,d01pqlob context.area.tag_redraw() @@ -187,7 +184,6 @@ def modal(self, context, event): if event.type == 'MOUSEMOVE': self.do1qpbl0, self.dqo0p1lb = event.mouse_region_x,event.mouse_region_y - elif event.type == 'LEFTMOUSE' and event.value == 'PRESS': self.switch = True self.dqbo0pl1 += 1 @@ -200,9 +196,7 @@ def modal(self, context, event): bpy.ops.scene.d1ob0plq('INVOKE_DEFAULT') bpy.types.SpaceImageEditor.draw_handler_remove(self._handle, 'WINDOW') return {'FINISHED'} - self.dlp01qbo = context.region.view2d.region_to_view(event.mouse_region_x, event.mouse_region_y) - elif event.type == 'BACK_SPACE': if bpy.data.images.get('previewSatTex.png') is not None and bpy.data.images.get('previewTerTex.tif') is not None: for space in bpy.context.area.spaces: @@ -217,18 +211,15 @@ def modal(self, context, event): for space in bpy.context.area.spaces: if space.type == 'IMAGE_EDITOR': space.image = bpy.data.images['previewSatTex.png'] - return {'PASS_THROUGH'} - elif event.type in {'RIGHTMOUSE', 'ESC'}: context.area.type = 'VIEW_3D' bpy.types.SpaceImageEditor.draw_handler_remove(self._handle, 'WINDOW') return {'CANCELLED'} - elif event.type in {'WHEELUPMOUSE', 'WHEELDOWNMOUSE','MIDDLEMOUSE','LEFT_SHIFT'}: return {'PASS_THROUGH'} return {'RUNNING_MODAL'} - + def invoke(self, context, event): self.do1qpbl0,self.dqo0p1lb = 0,0 self.dqbo0pl1 = 0 @@ -243,28 +234,28 @@ def invoke(self, context, event): else: self.report({'WARNING'}, "Image Editor not found, cannot run operator") return {'CANCELLED'} - + class dpbo10ql(bpy.types.Operator): bl_idname = "view3d.d1lp0obq" bl_label = "Draw splash screen" - + def modal(self, context, event): context.area.tag_redraw() - + if event.type in {'RIGHTMOUSE', 'LEFTMOUSE', 'ESC'}: self.img.gl_free() bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW') return {'FINISHED'} - + return {'RUNNING_MODAL'} - + def invoke(self, context, event): if context.area.type == 'VIEW_3D': args = (self, context) self._handle = bpy.types.SpaceView3D.draw_handler_add(dql0o1pb, args, 'WINDOW', 'POST_PIXEL') dboplq01 = dqolbp10()[2] if bpy.data.images.get('splash.png') is None: - bpy.data.images.load('{}\\splash.png'.format(dboplq01)) + bpy.data.images.load( os.path.join(dboplq01, 'splash.png') ) bpy.data.images['splash.png'].use_fake_user = True else: bpy.data.images['splash.png'].reload() @@ -279,7 +270,7 @@ def invoke(self, context, event): class dp10bqol(bpy.types.Operator): bl_idname = "object.dlpoq0b1" bl_label = "Textured + Wire overlay" - + def execute(self, context): Areas = context.screen.areas for Area in Areas: @@ -294,7 +285,7 @@ def execute(self, context): class dol1pbq0(bpy.types.Operator): bl_idname = "object.dlb0pq1o" bl_label = "Textured" - + def execute(self, context): Areas = context.screen.areas for Area in Areas: @@ -309,7 +300,7 @@ def execute(self, context): class dp1oqb0l(bpy.types.Operator): bl_idname = "scene.dlobq0p1" bl_label = "MatCap" - + def execute(self, context): Areas = context.screen.areas for Area in Areas: @@ -325,7 +316,7 @@ def execute(self, context): class d0qo1lbp(bpy.types.Operator): bl_idname = "scene.dlob10pq" bl_label = "MatCap + Wire overlay" - + def execute(self, context): Areas = context.screen.areas for Area in Areas: @@ -349,10 +340,10 @@ class dq0po1bl(bpy.types.Operator): def execute(self, context): dlb0o1pq(self.d1oqlpb0,self.db1l0opq,self.dq01lobp) return {'FINISHED'} - + def invoke(self, context, event): return context.window_manager.invoke_props_dialog(self) - + class dblqo0p1(Panel): bl_category = "bLandscape Tools" bl_label = "Project Settings" @@ -376,20 +367,20 @@ class dblqo0p1(Panel): maxlen= 1024, subtype='FILE_PATH', update=d0lbqop1) - + Scene.dlp1qo0b = StringProperty(name="", attr="terrainPath", description="Path to terrain heightmap to create 3D terrain", maxlen= 1024, subtype='FILE_PATH', update=d1qpbo0l) - + Scene.d10bqlop = StringProperty(name="", attr="terrainPath", description="Path to bLT internal elevation file", maxlen= 1024, subtype='FILE_PATH') - + d0p1lqob = [ ("RVEngine", "RVEngine", "", 1), ("Unreal Engine 4", "Unreal Engine 4", "", 2), @@ -397,7 +388,7 @@ class dblqo0p1(Panel): ("Unity", "Unity", "", 4), ("Enfusion", "Enfusion", "", 5) ] - + Scene.db1q0opl = bpy.props.EnumProperty(items=d0p1lqob,name="Engine",default='RVEngine') Scene.dlpb1qo0 = BoolProperty(default=True) @@ -405,18 +396,18 @@ class dblqo0p1(Panel): @classmethod def poll(cls, context): return context.scene.dlpb1qo0 - + def draw(self, context): scene = context.scene layout = self.layout - + box = layout.box() row = box.column() row.label(text="Project Folder") row.prop(scene,'dblo0p1q') row.separator() row.prop(scene, 'db1q0opl') - + row3 = box.column() row3.separator() row3.operator("scene.do0lbq1p",text='Create Project') @@ -425,7 +416,7 @@ def draw(self, context): row3.enabled = False else: row3.enabled = True - + class d0bpqol1(Panel): bl_category = "bLandscape Tools" bl_label = "Data Source" @@ -437,11 +428,10 @@ class d0bpqol1(Panel): @classmethod def poll(cls, context): return context.scene.dlqbo01p - + def draw(self, context): scene = context.scene layout = self.layout - box = layout.box() row1 = box.column() @@ -455,14 +445,12 @@ def draw(self, context): if len(bpy.data.scenes) > 1: row1.enabled = False row2.enabled = False - - + class dbolpq10(Panel): bl_category = "bLandscape Tools" bl_label = "Locations manager" bl_space_type = "VIEW_3D" bl_region_type = "TOOLS" - Scene.d0b1olqp = BoolProperty(name="", description="", @@ -473,7 +461,7 @@ class dbolpq10(Panel): @classmethod def poll(cls, context): return context.scene.d0blop1q - + def draw(self, context): scene = context.scene layout = self.layout @@ -489,7 +477,7 @@ def draw(self, context): elif bpy.context.object is not None: if bpy.context.object.mode == 'EDIT': row1.enabled = False - + row2 = col.row() row2.operator("scene.dqpolb01",icon='APPEND_BLEND',text="") if not scene.d0b1olqp: @@ -507,10 +495,6 @@ def draw(self, context): elif bpy.context.object is not None: if bpy.context.object.mode == 'EDIT': row3.enabled = False - - - - class d0ob1lpq(Panel): bl_category = "bLandscape Tools" @@ -524,7 +508,7 @@ class d0ob1lpq(Panel): @classmethod def poll(cls, context): return context.scene.dbq0po1l - + def draw(self, context): scene = context.scene view = context.space_data @@ -548,7 +532,7 @@ def draw(self, context): row4.template_icon_view(view, "matcap_icon") if not scene.d0b1olqp: row4.enabled = False - + col = layout.column() col.prop(fx_settings, "use_ssao", text="Ambient Occlusion") if fx_settings.use_ssao: @@ -558,14 +542,14 @@ def draw(self, context): subcol.prop(ssao_settings, "distance_max") subcol.prop(ssao_settings, "attenuation") subcol.prop(ssao_settings, "samples") - + if not scene.d0b1olqp: row.enabled = False row1.enabled = False row2.enabled = False col.enabled = False - + class dpqol01b(Panel): bl_category = "bLandscape Tools" bl_label = "Create" @@ -576,7 +560,7 @@ class dpqol01b(Panel): def draw(self, context): scene = context.scene layout = self.layout - + row = layout.row(align=True) row.operator("scene.dl10qbpo",icon='MESH_GRID') - + diff --git a/bLT_utils.py b/bLT_utils.py index b843f41..05777f2 100644 --- a/bLT_utils.py +++ b/bLT_utils.py @@ -10,43 +10,47 @@ def d0lbqop1(self, context): dboqpl01 = bpy.context.user_preferences.addons["bLandscapeTools-master"].preferences.dboqpl01 dblo0p1q = bpy.data.scenes["Default_Location"].dblo0p1q - do1bq0pl = 'Project_{}'.format(dblo0p1q.split('\\')[-2]) + do1bq0pl = 'Project_{}'.format(dblo0p1q.split(os.path.sep)[-2]) dbp1loq0 = dp0l1obq(dboqpl01,dl10pqob) - if os.path.exists('{}ProjectData\\Textures\\previewSatTex.png'.format(dblo0p1q)): - os.remove('{}ProjectData\\Textures\\previewSatTex.png'.format(dblo0p1q)) + if os.path.exists( os.path.join( dblo0p1q, "ProjectData", "Textures", "previewSatTex.png" ) ): + os.remove( os.path.join(dblo0p1q, "ProjectData", "Textures", "previewSatTex.png") ) if dbp1loq0 < 5000: - copy(bpy.context.scene.dp0l1boq,'{}ProjectData\\Textures\\'.format(dblo0p1q)) - dq1olbp0 = bpy.context.scene.dp0l1boq.split('\\')[-1] - os.rename('{}ProjectData\\Textures\\{}'.format(dblo0p1q,dq1olbp0),'{}ProjectData\\Textures\\previewSatTex.png'.format(dblo0p1q)) + copy(bpy.context.scene.dp0l1boq, os.path.join(dblo0p1q, "ProjectData", "Textures") ) + dq1olbp0 = bpy.context.scene.dp0l1boq.split(os.path.sep)[-1] + os.rename( os.path.join(dblo0p1q, "ProjectData", "Textures", dq1olbp0) , os.path.join(dblo0p1q, "ProjectData", "Textures", "previewSatTex.png") ) else: - cmd = '"{}gdal_translate.exe" "{}" -of PNG -outsize 5000 5000 "{}ProjectData\Textures\previewSatTex.png"'.format(dboqpl01,dl10pqob,dblo0p1q) + prev = os.path.join(dblo0p1q, "ProjectData", "Textures", "previewSatTex.png") + if os.name == "posix": + gdal = "gdal_translate" + cmd = "{} {} -of PNG -outsize 5000 5000 '{}'".format(gdal, dl10pqob, prev) + else: + gdal = os.path.join(dboqpl01, "gdal_translate.exe" ) + cmd = '"{}" "{}" -of PNG -outsize 5000 5000 "{}"'.format(gdal,dl10pqob,prev) subprocess.call(cmd) if bpy.data.images.get('previewSatTex.png') is None: - bpy.data.images.load('{}ProjectData\\Textures\\previewSatTex.png'.format(dblo0p1q)) + bpy.data.images.load( os.path.join(dblo0p1q, "ProjectData", "Textures", "previewSatTex.png") ) bpy.data.images['previewSatTex.png'].use_fake_user = True else: bpy.data.images['previewSatTex.png'].reload() - + dpq1lb0o = bpy.data.scenes['Default_Location'] dpq1lb0o["ImageryResolution"] = dbp1loq0 - bpy.ops.wm.save_as_mainfile(filepath='{}{}.blend'.format(dblo0p1q,do1bq0pl)) - + bpy.ops.wm.save_as_mainfile(filepath=os.path.join(dblo0p1q,"{}.blend".format(do1bq0pl))) + def d1qpbo0l(self, context): - - d1bplo0q = bpy.data.scenes["Default_Location"].dlp1qo0b dboqpl01 = bpy.context.user_preferences.addons["bLandscapeTools-master"].preferences.dboqpl01 dblo0p1q = bpy.data.scenes["Default_Location"].dblo0p1q - do1bq0pl = 'Project_{}'.format(dblo0p1q.split('\\')[-2]) + do1bq0pl = 'Project_{}'.format(dblo0p1q.split(os.path.sep)[-2]) dl1p0oqb = dpbqo01l(d1bplo0q) dq1ob0lp = genfromtxt(d1bplo0q, delimiter=' ', skip_header=6) - dq1bl0op = '{}ProjectData\\Textures\\elevation.bLTe'.format(dblo0p1q) + dq1bl0op = os.path.join(dblo0p1q, "ProjectData", "Textures", "elevation.bLTe") dq1ob0lp.astype('float32').tofile(dq1bl0op) - + print('Elevation converted') dqlbo0p1(d1bplo0q) @@ -57,24 +61,28 @@ def d1qpbo0l(self, context): dpq1lb0o["yllcorner"] = dl1p0oqb[2] dpq1lb0o["dboqp1l0"] = dl1p0oqb[3] bpy.data.scenes['Default_Location'].d10bqlop = dq1bl0op - - - bpy.ops.wm.save_as_mainfile(filepath='{}{}.blend'.format(dblo0p1q,do1bq0pl)) + bpy.ops.wm.save_as_mainfile(filepath=os.path.join(dblo0p1q,"{}.blend".format(do1bq0pl))) + def dqlbo0p1(d1bplo0q): dboqpl01 = bpy.context.user_preferences.addons["bLandscapeTools-master"].preferences.dboqpl01 dblo0p1q = bpy.data.scenes["Default_Location"].dblo0p1q - cmd = '"{}gdaldem.exe" hillshade -az 45 -z 1.3 "{}" "{}ProjectData\Textures\previewTerTex.tif"'.format(dboqpl01,d1bplo0q,dblo0p1q) + prev = os.path.join( dblo0p1q, "ProjectData", "Textures", "previewTerTex.tif") + if os.name == "posix": + gdal = "gdaldem" + cmd = '{} hillshade -az 45 -z 1.3 "{}" "{}"'.format(gdal,d1bplo0q,prev) + else: + gdal = os.path.join(dboqpl01, "gdaldem.exe") + cmd = '"{}" hillshade -az 45 -z 1.3 "{}" "{}"'.format(gdal,d1bplo0q,prev) subprocess.call(cmd) if bpy.data.images.get('previewTerTex.tif') is None: - bpy.data.images.load('{}ProjectData\\Textures\\previewTerTex.tif'.format(dblo0p1q)) + bpy.data.images.load( os.path.join(dblo0p1q, "ProjectData", "Textures", "previewTerTex.tif" )) bpy.data.images['previewTerTex.tif'].use_fake_user = True else: bpy.data.images['previewTerTex.tif'].reload() - def dqolbp10(): import addon_utils @@ -84,12 +92,12 @@ def dqolbp10(): if mod.__name__ == "bLandscapeTools-master": dpo0qbl1 = mod.__file__ pass - + dlq1obp0 = dpo0qbl1[:-12] - dboplq01 = '{}\\data'.format(dlq1obp0) + dboplq01 = os.path.join(dlq1obp0, "data") return dpo0qbl1,dlq1obp0,dboplq01 - + def dp0l1obq(dboqpl01,dl10pqob): ext = dl10pqob.split('.')[-1] if ext == 'png': @@ -98,8 +106,12 @@ def dp0l1obq(dboqpl01,dl10pqob): d01qbopl = 'tfw' if ext == 'jpg' or ext == 'jpeg': d01qbopl = 'jgw' - - cmd = '{}gdalinfo.exe "{}"'.format(dboqpl01,dl10pqob) + + if os.name == "posix": + cmd = 'gdalinfo "{}"'.format(dl10pqob) + else: + gdal = os.path.join(dboqpl01, "gdalinfo.exe") + cmd = '"{}" "{}"'.format(gdal,dl10pqob) print(cmd) dbol1p0q = subprocess.Popen(cmd, stdout=subprocess.PIPE) @@ -107,9 +119,9 @@ def dp0l1obq(dboqpl01,dl10pqob): line = str(dbol1p0q.stdout.readline()).rstrip('\\r\\n\'') if line.split(' ')[0][2:] == 'Size': info = int(line.split(' ')[3]) - - return info + return info + def dpbqo01l(path): info = [] f = open(path,"r") @@ -124,15 +136,12 @@ def dpbqo01l(path): y = float(info[3]) return ncols,x,y,d1oqlpb0 - - - def d1qp0lob(db10qolp): bpy.ops.object.lamp_add(type='HEMI') hemi = bpy.context.object hemi.hide = True hemi.name = "Hemi_" + db10qolp - + Areas = bpy.context.screen.areas for Area in Areas: if Area.type == 'VIEW_3D': @@ -148,35 +157,31 @@ def d1qp0lob(db10qolp): Area.spaces.active.fx_settings.ssao.factor = 4.1 Area.spaces.active.fx_settings.ssao.distance_max = 4.0 Area.spaces.active.fx_settings.ssao.samples = 70 - - + def dplq01ob(): dboplq01 = dqolbp10()[2] dblo0p1q = bpy.context.scene.dblo0p1q - do1bq0pl = 'Project_{}'.format(dblo0p1q.split('\\')[-2]) - - - + do1bq0pl = 'Project_{}'.format(dblo0p1q.split(os.path.sep)[-2]) + + bpy.ops.wm.open_mainfile(filepath=os.path.join(dboplq01, "dummy.blend")) - bpy.ops.wm.open_mainfile(filepath='{}\\dummy.blend'.format(dboplq01)) - bpy.context.scene.dqlob01p = True bpy.context.scene.dblo0p1q = dblo0p1q bpy.context.scene['d0b1olqp'] = False bpy.ops.wm.save_as_mainfile(filepath='{}{}.blend'.format(bpy.context.scene.dblo0p1q,do1bq0pl),copy=False) - + if not os.path.exists(bpy.context.scene.dblo0p1q + 'ProjectData'): os.makedirs(bpy.context.scene.dblo0p1q + 'ProjectData') - if not os.path.exists(bpy.context.scene.dblo0p1q + 'ProjectData\\Textures'): - os.makedirs(bpy.context.scene.dblo0p1q + 'ProjectData\\Textures') + if not os.path.exists(os.path.join(bpy.context.scene.dblo0p1q + 'ProjectData', 'Textures')): + os.makedirs(os.path.join(bpy.context.scene.dblo0p1q + 'ProjectData', 'Textures')) else: - rmtree(bpy.context.scene.dblo0p1q + 'ProjectData\\Textures') - os.makedirs(bpy.context.scene.dblo0p1q + 'ProjectData\\Textures') + rmtree(os.path.join( bpy.context.scene.dblo0p1q + 'ProjectData', 'Textures') ) + os.makedirs(os.path.join( bpy.context.scene.dblo0p1q + 'ProjectData', 'Textures') ) if not os.path.exists(bpy.context.scene.dblo0p1q + 'Output'): os.makedirs(bpy.context.scene.dblo0p1q + 'Output') - + def db0lqo1p(): bpy.context.area.type = 'IMAGE_EDITOR' @@ -186,7 +191,6 @@ def db0lqo1p(): if bpy.data.images.get('previewSatTex.png') is not None: space.image = bpy.data.images['previewSatTex.png'] - bpy.ops.image.view_all() screen = bpy.context.window.screen @@ -199,7 +203,7 @@ def db0lqo1p(): def dql0o1pb(self,context): region = context.region - + width,height = region.width,region.height center = [width / 2, height / 2] @@ -208,7 +212,7 @@ def dql0o1pb(self,context): blf.enable(0, blf.SHADOW) blf.shadow_offset(0, 1, -1) blf.shadow(0, 3, 0.0, 0.0, 0.0, 1) - + bgl.glBindTexture(bgl.GL_TEXTURE_2D, self.img.bindcode[0]) bgl.glTexParameteri(bgl.GL_TEXTURE_2D, bgl.GL_TEXTURE_MIN_FILTER, bgl.GL_NEAREST) bgl.glEnable(bgl.GL_TEXTURE_2D) @@ -217,16 +221,16 @@ def dql0o1pb(self,context): bgl.glTexCoord2f(0, 0) bgl.glVertex2f(center[0] - 384, center[1] - 192) - + bgl.glTexCoord2f(0, 1) bgl.glVertex2f(center[0] - 384, center[1] + 192) - + bgl.glTexCoord2f(1, 1) bgl.glVertex2f(center[0] + 384, center[1] + 192) - + bgl.glTexCoord2f(1, 0) bgl.glVertex2f(center[0] + 384, center[1] - 192) - + bgl.glEnd() bgl.glDisable(bgl.GL_TEXTURE_2D) @@ -236,12 +240,12 @@ def dql0o1pb(self,context): bgl.glColor4f(0.0, 0.0, 0.0, 1.0) blf.disable(0, blf.SHADOW) - + def dqob0lp1(self, context): region = context.region - + width,height = region.width,region.height - + font_id = 0 blf.size(font_id, 12, 72) blf.enable(0, blf.SHADOW) @@ -260,7 +264,7 @@ def dqob0lp1(self, context): bgl.glVertex2i(self.do1qpbl0, 0) bgl.glVertex2i(self.do1qpbl0, height) bgl.glEnd() - + else: dlb0o1qp = self.dlp01qbo dob10lpq = list(bpy.context.region.view2d.view_to_region(dlb0o1qp[0],dlb0o1qp[1],clip=False)) @@ -271,7 +275,7 @@ def dqob0lp1(self, context): bgl.glVertex2i(dob10lpq[0], dob10lpq[1]) bgl.glVertex2i(self.do1qpbl0, dob10lpq[1]) bgl.glEnd() - + bgl.glColor4f(0.0, 1.0, 0.0, 0.3) bgl.glBegin(bgl.GL_POLYGON) bgl.glVertex2i(self.do1qpbl0, self.dqo0p1lb) @@ -286,24 +290,24 @@ def dqob0lp1(self, context): blf.draw(font_id, self.dp1qb0lo) blf.position(font_id, self.do1qpbl0 - 210, self.dqo0p1lb - 45, 0) blf.draw(font_id, self.dplo1bq0) - + bgl.glColor4f(0.0, 0.0, 0.0, 1.0) bgl.glDisable(bgl.GL_LINE_STIPPLE) blf.disable(0, blf.SHADOW) - + def dlpoqb10(do0lbqp1,dpbo0ql1): dp10loqb, d1p0lqob, dlbp0oq1, d01olpbq = do0lbqp1[0], do0lbqp1[1], dpbo0ql1[0], dpbo0ql1[1] - + if dlbp0oq1 < 0: dlbp0oq1 = 0.0 elif dlbp0oq1 > 1: dlbp0oq1 = 1.0 - + if d01olpbq < 0: d01olpbq = 0.0 elif d01olpbq > 1: d01olpbq = 1.0 - + if dp10loqb < 0: dp10loqb = 0.0 elif dp10loqb > 1: @@ -313,23 +317,23 @@ def dlpoqb10(do0lbqp1,dpbo0ql1): d1p0lqob = 0.0 elif d1p0lqob > 1: d1p0lqob = 1.0 - + if dlbp0oq1 < dp10loqb: dlbp1o0q = dlbp0oq1 d0qbpol1 = dp10loqb else: dlbp1o0q = dp10loqb d0qbpol1 = dlbp0oq1 - + if d01olpbq > d1p0lqob: db1pqo0l = d01olpbq d1bq0olp = d1p0lqob else: db1pqo0l = d1p0lqob d1bq0olp = d01olpbq - - return db1pqo0l,dlbp1o0q,d1bq0olp,d0qbpol1 + return db1pqo0l,dlbp1o0q,d1bq0olp,d0qbpol1 + def dpbq01ol(d1oqlpb0,d0pqol1b,db1pqo0l,dlbp1o0q,d1bq0olp,d0qbpol1): d1qbpo0l = False dlpo0q1b = False @@ -338,31 +342,31 @@ def dpbq01ol(d1oqlpb0,d0pqol1b,db1pqo0l,dlbp1o0q,d1bq0olp,d0qbpol1): db1pqo0l = 0.0 if isnan(dlbp1o0q): dlbp1o0q = 0.0 - + if db1pqo0l == 1.0: d0bp1qol = 0 d1qbpo0l = True else: d0bp1qol = floor((1 - db1pqo0l) * d0pqol1b) - + topLeftColumn = ceil(dlbp1o0q * d0pqol1b) if d1bq0olp == 0.0: bottomRightRow = d0pqol1b - 1 else: bottomRightRow = floor((1 - d1bq0olp) * d0pqol1b) - 1 - + if d0qbpol1 == 1.0: bottomRightColumn = d0pqol1b - 1 dlpo0q1b = True else: bottomRightColumn = ceil(d0qbpol1 * d0pqol1b) - 1 - + dbl1o0qp = bottomRightColumn - topLeftColumn + 2 if dlpo0q1b else bottomRightColumn - topLeftColumn + 1 d01pqlob = bottomRightRow - d0bp1qol + 2 if d1qbpo0l else bottomRightRow - d0bp1qol + 1 - - return d0bp1qol, topLeftColumn, bottomRightRow, bottomRightColumn, d1qbpo0l, dlpo0q1b, dbl1o0qp, d01pqlob + return d0bp1qol, topLeftColumn, bottomRightRow, bottomRightColumn, d1qbpo0l, dlpo0q1b, dbl1o0qp, d01pqlob + def dq0ol1pb(dopql1b0,d0pqol1b,d0bp1qol,topLeftColumn,bottomRightRow,bottomRightColumn,d1qbpo0l,dlpo0q1b): print(1111,time.ctime()) dqlp01bo = fromfile(dopql1b0, dtype=float32) @@ -404,7 +408,7 @@ def d1qlpob0(do0bq1lp,d0bolqp1,topLeftColumn,d0bp1qolChanged,dpo0b1lq,d1opblq0,d def dbqop1l0(originalHeightField, d1blqop0, dopblq10): originalHeightField[dopblq10[0]:dopblq10[0] + d1blqop0.shape[0], dopblq10[1]:dopblq10[1] + d1blqop0.shape[1]] = d1blqop0 return originalHeightField - + def dbpo1ql0(): dq1bolp0 = bpy.data.scenes['Default_Location'] dobpl1q0 = dq1bolp0.d10bqlop @@ -421,7 +425,7 @@ def dbpo1ql0(): for v in doq01bpl.data.vertices: worldCoord = do01bpql * v.co dqlp01bo1D.append(round(worldCoord[2],2)) - + d1blqop0 = array(dqlp01bo1D).reshape(doq01bpl["d0blqp1o"],doq01bpl["dqo1lpb0"]) if doq01bpl['dlbpo1q0']: d1blqop0 = delete(d1blqop0,0,0) @@ -431,8 +435,8 @@ def dbpo1ql0(): dobl01qp = dbqop1l0(dpol0bq1, d1blqop0, [doq01bpl["dqp1b0lo"],doq01bpl["dqlbp10o"]]) dobl01qp.astype('float32').tofile(dobpl1q0) header = 'ncols {}\nnrows {}\nxllcorner {}\nyllcorner {}\ncellsize {}\nNODATA_value -9999'.format(d0pqol1b,d0pqol1b,xllcorner,yllcorner,d1oqlpb0) - savetxt('{}\\Output\\elevation.asc'.format(dblo0p1q),dobl01qp,fmt='%.2f',delimiter=' ',comments='',header=header) - dqlbo0p1('{}\\Output\\elevation.asc'.format(dblo0p1q)) + savetxt(os.path.join(dblo0p1q, 'Output', 'elevation.asc'),dobl01qp,fmt='%.2f',delimiter=' ',comments='',header=header) + dqlbo0p1(os.path.join(dblo0p1q, 'Output', 'elevation.asc') ) def dq0b1plo(db10qolp,dbl1o0qp,d01pqlob,d0bp1qol,topLeftColumn,bottomRightRow,bottomRightColumn,d1qbpo0l,dlpo0q1b): print(1,time.ctime()) @@ -443,20 +447,19 @@ def dq0b1plo(db10qolp,dbl1o0qp,d01pqlob,d0bp1qol,topLeftColumn,bottomRightRow,bo dl10pqob = bpy.data.scenes["Default_Location"].dp0l1boq dblo0p1q = bpy.data.scenes["Default_Location"].dblo0p1q dboqpl01 = bpy.context.user_preferences.addons["bLandscapeTools-master"].preferences.dboqpl01 - + bpy.context.window.screen.scene = bpy.data.scenes["Default_Location"] bpy.ops.scene.new(type='FULL_COPY') bpy.context.scene.name = db10qolp bpy.context.scene['d0b1olqp'] = True - d1qp0lob(db10qolp) print(2,time.ctime()) if bpy.data.meshes.get('TerrainMesh_{}'.format(db10qolp)) is not None: bpy.data.meshes.get('TerrainMesh_{}'.format(db10qolp)).user_clear() bpy.data.meshes.remove(bpy.data.meshes.get('TerrainMesh_{}'.format(db10qolp))) - + dq1lpo0b = bpy.data.meshes.new('TerrainMesh_{}'.format(db10qolp)) doq01bpl = bpy.data.objects.new('Terrain_{}'.format(db10qolp),dq1lpo0b) bpy.context.scene.objects.link(doq01bpl) @@ -478,13 +481,12 @@ def dq0b1plo(db10qolp,dbl1o0qp,d01pqlob,d0bp1qol,topLeftColumn,bottomRightRow,bo if not d1qbpo0l: d0bp1qolChanged += 1 - + d01olqbp += 1 - dpo0b1lq = floor(topLeftColumn * d0bolqp1 / do0bq1lp) d1opblq0 = floor(round(d0bp1qolChanged * d0bolqp1 / do0bq1lp,6)) - + if dlpo0q1b: d1qobp0l += 1 @@ -499,13 +501,18 @@ def dq0b1plo(db10qolp,dbl1o0qp,d01pqlob,d0bp1qol,topLeftColumn,bottomRightRow,bo print("Terrain texture resolution: ", dblpqo01,dq10bpol) print(4,time.ctime()) - cmd = '"{}gdal_translate.exe" "{}" -of PNG -srcwin "{}" "{}" "{}" "{}" "{}ProjectData\\Textures\\terTexture_{}.png"'.format(dboqpl01,dl10pqob,dpo0b1lq,d1opblq0,dblpqo01,dq10bpol,dblo0p1q,db10qolp) + prev = os.join.path(dblo0p1q, "ProjectData", "Textures", "terTexture_{}.png".format(db10qolp) ) + if os.name == "posix": + cmd = 'gdal_translate "{}" -of PNG -srcwin "{}" "{}" "{}" "{}" "{}"'.format(dl10pqob,dpo0b1lq,d1opblq0,dblpqo01,dq10bpol,prev) + else: + gdal = os.join.path(dboqpl01, "gdal_translate.exe") + cmd = '"{}" "{}" -of PNG -srcwin "{}" "{}" "{}" "{}" "{}"'.format(gdal,dl10pqob,dpo0b1lq,d1opblq0,dblpqo01,dq10bpol,prev) + subprocess.call(cmd) print(5,time.ctime()) dq10lpob= bpy.data.textures.new('terTexture_{}'.format(db10qolp), type = 'IMAGE') - dq10lpob.image = bpy.data.images.load('{}ProjectData\\Textures\\terTexture_{}.png'.format(dblo0p1q,db10qolp)) - - + dq10lpob.image = bpy.data.images.load( os.path.join(dblo0p1q, 'ProjectData', 'Textures', 'terTexture_{}.png'.format(db10qolp))) + #-------------------------- Create new terrain material ---------------------------------------------- d0qpol1b = bpy.data.materials.new('TerrainMaterial_{}'.format(db10qolp)) d0qpol1b.specular_intensity = 0 @@ -525,7 +532,7 @@ def dq0b1plo(db10qolp,dbl1o0qp,d01pqlob,d0bp1qol,topLeftColumn,bottomRightRow,bo if dl10pqob != '': do1p0qbl = bm.faces.layers.tex.verify() d0olp1qb = bm.loops.layers.uv.verify() - + print(7,time.ctime()) d0pblq1o = dq0ol1pb(dpoqlb01,d0pqol1b,d0bp1qol,topLeftColumn,bottomRightRow,bottomRightColumn,d1qbpo0l,dlpo0q1b) print(8,time.ctime()) @@ -563,7 +570,7 @@ def dq0b1plo(db10qolp,dbl1o0qp,d01pqlob,d0bp1qol,topLeftColumn,bottomRightRow,bo d1lpboq0.loops[2][d0olp1qb].uv = [dlboqp01 + d10polqb * db0p1olq + db0p1olq, d1qobl0p - uvShiftY * d1p0qlbo - d1p0qlbo] d1lpboq0.loops[3][d0olp1qb].uv = [dlboqp01 + d10polqb * db0p1olq + db0p1olq, d1qobl0p - uvShiftY * d1p0qlbo] uvShiftY += 1 - + print(11,time.ctime()) bmesh.ops.triangulate(bm, faces=bm.faces, quad_method=2) print(12,time.ctime()) @@ -589,12 +596,12 @@ def dq0b1plo(db10qolp,dbl1o0qp,d01pqlob,d0bp1qol,topLeftColumn,bottomRightRow,bo for region in area.regions: if region.type == 'WINDOW': override = {'window': bpy.context.window, 'screen': screen, 'area': area, 'region': region, 'scene': bpy.context.scene, 'edit_object': bpy.context.edit_object} - + bpy.ops.view3d.view_selected(override) print(14,time.ctime()) - + def dlb0o1pq(d1oqlpb0,db1l0opq,dq01lobp,): d0p1olqb = bpy.context.user_preferences.addons["bLandscapeTools-master"].preferences.d0p1olqb result = ones((db1l0opq,db1l0opq)) * dq01lobp header = 'ncols {}\nnrows {}\nxllcorner 0\nyllcorner 0\ncellsize {}\nNODATA_value -9999'.format(db1l0opq,db1l0opq,d1oqlpb0) - savetxt('{}\\elevation.asc'.format(d0p1olqb),result,fmt='%.2f',delimiter=' ',newline='\r\n',comments='',header=header) \ No newline at end of file + savetxt( os.path.join(d0p1olqb, 'elevation.asc'),result,fmt='%.2f',delimiter=' ',newline='\r\n',comments='',header=header)