diff --git a/scripts/blender-svg b/scripts/blender-svg deleted file mode 100644 index 4a0dc3e4..00000000 --- a/scripts/blender-svg +++ /dev/null @@ -1,157 +0,0 @@ -import bpy -from mathutils import Vector, Euler -from math import pi -import json -import os -import bpy_extras -import bmesh -import time - -class ModalTimerOperator(bpy.types.Operator): - """Operator which runs its self from a timer""" - bl_idname = "wm.modal_timer_operator" - bl_label = "Modal Timer Operator" - - _timer = None - index = 0 - - def menu_func(self, context): - self.layout.operator(ModalTimerOperator.bl_idname) - - def modal(self, context, event): - scene = context.scene - if self.index >= len(self.sides): - self.cancel(context) - return {'CANCELLED'} - - if event.type == 'TIMER': - print("HOLY COW!!!") - self.capture(self.sides[self.index]) - self.index += 1 - if self.index < len(self.sides): - self.position_camera(self.sides[self.index]) - else: - self.export_data() - - return {'PASS_THROUGH'} - - def execute(self, context): - print("execute!") - self.c = bpy.data.objects["cam"] - self.scene = bpy.context.scene - selected = bpy.context.selected_objects[0] - - bpy.ops.object.mode_set(mode="OBJECT") - bpy.ops.object.transform_apply( rotation = True ) - - self.data = {} - - self.b = selected - - FRONT = [0, 1, 2, "Front"] - SIDE = [1, 1, 2, "Side"] - TOP = [0, 0, 1, "Top"] - ANGLED = [0.5, 1, 2, "Angled"] - - self.sides = [FRONT, SIDE, TOP, ANGLED] - - path = "/tmp/macrovision/" - - media_path = "/home/crux/furry/macrovision/media/" - media_folder = "buildings/Houses/" - - os.makedirs(path, exist_ok=True) - os.makedirs(os.path.join(media_path, media_folder), exist_ok=True) - wm = context.window_manager - self._timer = wm.event_timer_add(0.25, window=context.window) - wm.modal_handler_add(self) - self.position_camera(self.sides[self.index]) - return {'RUNNING_MODAL'} - - def cancel(self, context): - wm = context.window_manager - wm.event_timer_remove(self._timer) - - - def getView3dAreaAndRegion(self, context): - for area in context.screen.areas: - if area.type == "VIEW_3D": - for region in area.regions: - if region.type == "WINDOW": - print("Found WINDOW") - return area, region - - def select_border(self, context, view3dAreaAndRegion=None, extend=True): - if not view3dAreaAndRegion: - view3dAreaAndRegion = self.getView3dAreaAndRegion(context) - print(view3dAreaAndRegion) - view3dArea, view3dRegion = view3dAreaAndRegion - override = context.copy() - override['area'] = view3dArea - override['region'] = view3dRegion - bpy.ops.view3d.select_box(override,xmin=0,xmax=view3dArea.width,ymin=0,ymax=view3dArea.height,mode='SET') - - def position_camera(self, angles): - bpy.ops.object.mode_set(mode="OBJECT") - local_bbox_center = 0.125 * sum((Vector(box) for box in self.b.bound_box), Vector()) - global_bbox_center = self.b.matrix_world @ local_bbox_center - self.c.data.ortho_scale = max(self.b.dimensions) * 1.3 - self.c.location = global_bbox_center - self.c.rotation_euler = Euler([angles[1] * pi / 2, 0, angles[0] * pi / 2]) - rot = self.c.rotation_euler.to_matrix() - rot.invert() - self.c.location = self.c.location + Vector([0, 0, 100]) @ rot - self.data[angles[3]] = self.b.dimensions[angles[2]] - - def capture(self, angles): - bpy.ops.object.mode_set(mode="EDIT") - bpy.ops.mesh.select_all(action="SELECT") - bpy.ops.mesh.sort_elements(type='VIEW_ZAXIS', elements={'FACE'}, reverse=False) - bm = bmesh.from_edit_mesh(bpy.context.active_object.data) - polygons = [] - edges = [] - - self.select_border(bpy.context) - bm.faces.ensure_lookup_table() - bm.verts.ensure_lookup_table() - bm.edges.ensure_lookup_table() - for face in bm.faces: - if not face.select: - continue - verts = [] - for vert in face.verts: - co = bpy_extras.object_utils.world_to_camera_view(self.scene, self.c, vert.co) - verts.append([co[0], co[1]]) - verts.append(verts[0]) - polygons.append({"verts": verts, "type": "bright" if face.material_index == 1 else "dark"}) - for edge in face.edges: - if not edge.select: - continue - co1 = bpy_extras.object_utils.world_to_camera_view(self.scene, self.c, edge.verts[0].co) - co2 = bpy_extras.object_utils.world_to_camera_view(self.scene, self.c, edge.verts[1].co) - polygons.append({"type": "edge", "verts": [ - [co1[0], co1[1]], - [co2[0], co2[1]] - ]}) - bm.free() - bpy.ops.object.mode_set(mode="OBJECT") - - - with open(f"/tmp/polygons-{angles[3]}.json", "w", encoding="utf-8") as file: - json.dump({"polygons": polygons}, file) - - - def export_data(self): - with open(f"/tmp/data-{self.b.name}.json", "w", encoding="utf-8") as file: - json.dump({"name": self.b.name, "views": self.data}, file) - - -def register(): - bpy.utils.register_class(ModalTimerOperator) - bpy.types.VIEW3D_MT_object.append(ModalTimerOperator.menu_func) - -def unregister(): - bpy.utils.unregister_class(ModalTimerOperator) - - -register() \ No newline at end of file diff --git a/scripts/osm-bounds/.gitignore b/scripts/osm-bounds/.gitignore deleted file mode 100644 index 919463b9..00000000 --- a/scripts/osm-bounds/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.svg -*.json \ No newline at end of file diff --git a/scripts/osm-bounds/cities.txt b/scripts/osm-bounds/cities.txt deleted file mode 100644 index 358e04d5..00000000 --- a/scripts/osm-bounds/cities.txt +++ /dev/null @@ -1,10 +0,0 @@ -London -Paris -Melbourne -Sydney -Berlin -Moscow -Seoul -Madrid -Hong Kong -Beijing \ No newline at end of file diff --git a/scripts/osm-bounds/get-polygon.py b/scripts/osm-bounds/get-polygon.py deleted file mode 100644 index b07a7ca7..00000000 --- a/scripts/osm-bounds/get-polygon.py +++ /dev/null @@ -1,88 +0,0 @@ -import requests -import sys -import urllib.parse -import json -import subprocess -import os - -def get_polygon(name): - if not os.path.isfile(name + ".json"): - url = "https://nominatim.openstreetmap.org/search.php?q={0}&polygon_geojson=1&format=jsonv2".format( - urllib.parse.quote(name) - ) - r = requests.get(url) - data = json.loads(r.text) - - if data is None: - raise ValueError("Bogus results") - - osm_id = None - for entry in data: - if "boundary" in entry["category"] and entry["osm_type"] == "relation": - osm_id = entry["osm_id"] - break - - if not osm_id: - raise ValueError("No id") - - url = "http://polygons.openstreetmap.fr/get_geojson.py?id={0}¶ms=0".format(osm_id) - - with open(name + ".json", "w") as file: - file.write(requests.get(url).text) - else: - data = json.load(open(name + ".json")) - - info = subprocess.check_output( - [ - "mapshaper", - "-i", - "{0}.json".format(name), - "-each", - "console.log(this.centroidX, this.centroidY, this.area)"], - shell=True, - stderr=subprocess.STDOUT, - ).decode("utf-8") - - lon, lat, area = list(map(float, info.split(" "))) - if area is not None: - info = subprocess.check_output( - [ - "mapshaper", - "-i", - "{0}.json".format(name), - "-proj", - "+proj=nsper", - "+h=100000", - "+lat_0={0}".format(lat), - "+lon_0={0}".format(lon), - "-simplify", - "resolution=500x500", - "-each", - "console.log(\"HEIGHT:\" + this.height)", - "-o", - "{0}.svg".format(name), - ], - shell=True, - stderr=subprocess.STDOUT, - ).decode("utf-8") - height = None - for line in info.split("\n"): - if "HEIGHT:" in line: - height = float(line.split(":")[1].strip()) - print("[\"{0}\", {1}, {2}],".format(name, area, height)) - -if __name__ == "__main__": - if len(sys.argv) < 2: - print("Usage: {0} list-of-cities".format(sys.argv[0])) - else: - city = None - try: - for city in open(sys.argv[1]).readlines(): - try: - get_polygon(city.strip()) - except ValueError as e: - print(city + " failed") - print(e) - except Exception as e: - print(city + " failed") - print(e) \ No newline at end of file diff --git a/scripts/osm-bounds/process-shapefile.py b/scripts/osm-bounds/process-shapefile.py deleted file mode 100644 index 3473bf3c..00000000 --- a/scripts/osm-bounds/process-shapefile.py +++ /dev/null @@ -1,41 +0,0 @@ -import subprocess -import sys -import json - -def get_centroids(file, field_name): - results = {} - for entry in subprocess.check_output( - [ - "mapshaper", - "-i", - file, - "-each", - "\"console.log(JSON.stringify({{name: {0}, lon: this.centroidX, lat: this.centroidY}}))\"".format(field_name) - ], - shell = True, - stderr = subprocess.STDOUT - ).decode("utf-8").split("\n"): - print(entry) - parts = json.loads(entry) - results[parts["name"]] = { - "lon": float(parts["lon"]), - "lat": float(parts["lat"]) - } - - return results - -def extract_shape(file, field_name, field_value): - lat, lon = subprocess.check_output( - [ - "mapshaper", - "-i", - file, - "-filter", - "\"{0} == {1}\"".format(field_name, field_value), - "-each", - "\"console.log(this.centroidX, this.centroidY)" - ] - ) - -if __name__ == "__main__": - print(get_centroids(sys.argv[1], sys.argv[2])) \ No newline at end of file diff --git a/scripts/process-potrace-model-forms.py b/scripts/process-model.py similarity index 100% rename from scripts/process-potrace-model-forms.py rename to scripts/process-model.py