From 7a252a83d06fe0a93634ddc4806316ae4355c7e3 Mon Sep 17 00:00:00 2001 From: Minho Shim <6764739+minostauros@users.noreply.github.com> Date: Fri, 2 Oct 2020 02:21:20 +0900 Subject: [PATCH] add: seoul map import capability https://smap.seoul.go.kr/ --- blender/MapsModelsImporter/google_maps.py | 20 +++++++++++--- blender/MapsModelsImporter/google_maps_rd.py | 29 +++++++++++++------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/blender/MapsModelsImporter/google_maps.py b/blender/MapsModelsImporter/google_maps.py index 136cfa9..1e66b3f 100644 --- a/blender/MapsModelsImporter/google_maps.py +++ b/blender/MapsModelsImporter/google_maps.py @@ -70,7 +70,7 @@ def captureToFiles(context, filepath, prefix, max_blocks): import pickle from bpy_extras import object_utils from math import floor, pi -from mathutils import Matrix +from mathutils import Matrix, Vector import os def makeMatrix(mdata): @@ -120,6 +120,11 @@ def extractUniforms(constants, refMatrix): (-0.7269363403320312, 0.28318125009536743, 0.6255972981452942, -1.349690556526184), (0.0, 0.0, 0.0, 1.0)) ) @ Matrix.Scale(500, 4) + elif '_f' in globUniforms or '_i' in globUniforms: + # Google Chrome 85.0.4183.121 (64bit), RendorDoc 1.9, RTX 3090, https://smap.seoul.go.kr/ + uvOffsetScale = [0, 0, 1/65535., 1/65535.] + matrix = makeMatrix(globUniforms['_f']) + postMatrix = Matrix.Scale(3, 4, Vector((1.0, 0., 0.))) else: if refMatrix is None: print("globUniforms:") @@ -130,8 +135,12 @@ def extractUniforms(constants, refMatrix): return None, None, None if refMatrix is None: - # Rotate around Y because Google Maps uses X as up axis - refMatrix = Matrix.Rotation(-pi/2, 4, 'Y') @ matrix.inverted() + if '_f' in globUniforms or '_i' in globUniforms: + # Rotate around Z, upside down for SMAP + refMatrix = Matrix.Rotation(-pi, 4, 'Z') @ matrix.inverted() + else: + # Rotate around Y because Google Maps uses X as up axis + refMatrix = Matrix.Rotation(-pi/2, 4, 'Y') @ matrix.inverted() matrix = refMatrix @ matrix if postMatrix is not None: @@ -190,7 +199,7 @@ def loadData(prefix, drawcall_id): # ----------------------------------------------------------------------------- -def filesToBlender(context, prefix, max_blocks=200, globalScale=1.0/256.0): +def filesToBlender(context, prefix, max_blocks=200): """Import data from the files extracted by captureToFiles""" # Get reference matrix refMatrix = None @@ -245,6 +254,9 @@ def filesToBlender(context, prefix, max_blocks=200, globalScale=1.0/256.0): mesh_name = "BuildingMesh-{:05d}".format(drawcall_id) obj = addMesh(context, mesh_name, verts, tris, uvs) + globalScale=1.0/256.0 + if constants["DrawCall"]["type"] == 'SeoulMap': + globalScale=1.0 obj.matrix_world = matrix * globalScale mat_name = "BuildingMat-{:05d}".format(drawcall_id) diff --git a/blender/MapsModelsImporter/google_maps_rd.py b/blender/MapsModelsImporter/google_maps_rd.py index fdd638b..5e1c388 100644 --- a/blender/MapsModelsImporter/google_maps_rd.py +++ b/blender/MapsModelsImporter/google_maps_rd.py @@ -200,15 +200,20 @@ def run(self): meshes = [makeMeshData(attr, ib, vbs, draw) for attr in attrs] try: + if len(meshes) < 2: + continue # Position m = meshes[0] m.fetchTriangle(controller) - indices = m.fetchIndices(controller) - with open("{}{:05d}-indices.bin".format(FILEPREFIX, drawcallId), 'wb') as file: - pickle.dump(indices, file) unpacked = m.fetchData(controller) + if len(unpacked) < 1 or len(unpacked[0]) < 3: + continue with open("{}{:05d}-positions.bin".format(FILEPREFIX, drawcallId), 'wb') as file: pickle.dump(unpacked, file) + indices = m.fetchIndices(controller) + with open("{}{:05d}-indices.bin".format(FILEPREFIX, drawcallId), 'wb') as file: + pickle.dump(indices, file) + # UV m = meshes[2 if capture_type == "Google Earth" else 1] @@ -220,6 +225,17 @@ def run(self): print("(Skipping: {})".format(err)) continue + # Texture + # dirty + bindpoints = state.GetBindpointMapping(rd.ShaderStage.Fragment) + if len(bindpoints.samplers) > 1: + capture_type = 'SeoulMap' + texture_bind = bindpoints.samplers[0].bind + else: + texture_bind = bindpoints.samplers[-1].bind + resources = state.GetReadOnlyResources(rd.ShaderStage.Fragment) + rid = resources[texture_bind].resources[0].resourceId + # Vertex Shader Constants shader = state.GetShader(rd.ShaderStage.Vertex) ep = state.GetShaderEntryPoint(rd.ShaderStage.Vertex) @@ -231,13 +247,6 @@ def run(self): } with open("{}{:05d}-constants.bin".format(FILEPREFIX, drawcallId), 'wb') as file: pickle.dump(constants, file) - - # Texture - # dirty - bindpoints = state.GetBindpointMapping(rd.ShaderStage.Fragment) - texture_bind = bindpoints.samplers[-1].bind - resources = state.GetReadOnlyResources(rd.ShaderStage.Fragment) - rid = resources[texture_bind].resources[0].resourceId texsave = rd.TextureSave() texsave.resourceId = rid