Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eliemichel committed Mar 30, 2019
0 parents commit c0415f7
Show file tree
Hide file tree
Showing 22 changed files with 964 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__/
builds/
34 changes: 34 additions & 0 deletions Licenses.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Licenses
========

Maps Models Importer
---------------------

*Maps Models Importer* is released under the MIT license:

Copyright (c) 2019 Élie Michel

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


RenderDoc
---------

*Maps Models Importer* relies on a dynamic library provided by [RenderDoc](https://github.com/baldurk/renderdoc), which is released under the MIT license:

Copyright (c) 2015-2019 Baldur Karlsson

Copyright (c) 2014 Crytek

Copyright (c) 1998-2018 [Third party code and tools](https://github.com/baldurk/renderdoc/blob/v1.x/docs/credits_acknowledgements.rst)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Maps Models Importer
====================

*Maps Models Importer* is a set of tools for importint 3D models from wide maps in 3D content softwares.
This is a proof of concept containing only a Blender add-on for importing 3D models from Google Maps.

The `blender` directory contains the source code of the Blender add-on importing captures recorded with [RenderDoc](https://renderdoc.org/):

![Screenshot of blender addon in action](doc/screenshot.png)

**NB** This is an add-on for Blender 2.80 and above, which you can download from [here](https://builder.blender.org/download/).

Installation
------------

Download a [release](TODO) and make a zip of `blender/MapsModelsImporter/`. In Blender, go to `Edit > Preferences`, `Add-on`, `Install`, then browse to the zip file.

Usage
-----

1. Start RenderDoc, and `File > Inject into process`;

2. Start chrome using specific flags: `chrome.exe --disable-gpu-sandbox --gpu-startup-dialog --use-angle=gl`. Do NOT press Ok on the dialog box yet;

3. In RenderDoc, search for the chrome process and inject into it;

4. Press OK in the chrom dialog;

5. Go to Google Maps in satellite view, and take a capture using `Print Screen` **while moving** in the viewport;

6. In RenderDoc, save the capture as an rdc file

7. In Blender, go to `File > Import > Google Maps Capture` an choose your capture file.

Disclaimer
----------

This is a proof of concept showcasing how the 3D render process of Google Maps can be inspected. This is intended for educational purpose only. For a more in-depth analysis, see [Importing Actual 3D Models From Google Maps](TODO).

Do not use this for any commercial nor redistribution purpose. Actually, the use of such tool might be allowed for private read-only use, as this is what happens when browsing Google Maps, but not beyond. I do not take responsibility for any use of this tool.


Help Wanted
-----------

This repository does not provide the required RenderDoc binaries for linux nor for OSX. If you have such a system, build RenderDoc against Python 3.7.0 (the minor version matters) to be compatible with the version of Blender's Python distribution.

34 changes: 34 additions & 0 deletions blender/MapsModelsImporter/Licenses.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
Licenses
========

Maps Models Importer
---------------------

*Maps Models Importer* is released under the MIT license:

Copyright (c) 2019 Élie Michel

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


RenderDoc
---------

*Maps Models Importer* relies on a dynamic library provided by [RenderDoc](https://github.com/baldurk/renderdoc), which is released under the MIT license:

Copyright (c) 2015-2019 Baldur Karlsson

Copyright (c) 2014 Crytek

Copyright (c) 1998-2018 [Third party code and tools](https://github.com/baldurk/renderdoc/blob/v1.x/docs/credits_acknowledgements.rst)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

23 changes: 23 additions & 0 deletions blender/MapsModelsImporter/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Maps Models Importer
====================

*Maps Models Importer* is a set of tools for importint 3D models from wide maps in 3D content softwares.
This is a proof of concept containing only a Blender add-on for importing 3D models from Google Maps.

The `blender` directory contains the source code of the Blender add-on importing captures recorded with [RenderDoc](https://renderdoc.org/):

![Screenshot of blender addon in action](doc/screenshot.png)

Disclaimer
----------

This is a proof of concept showcasing how the 3D render process of Google Maps can be inspected. This is intended for educational purpose only. For a more in-depth analysis, see [](TODO)

Do not use this for any commercial nor redistribution purpose. Actually, the use of such tool might be allowed for private read-only use, as this is what happens when browsing Google Maps, but not beyond. I do not take responsibility for any use of this tool.


Help Wanted
-----------

This repository does not provide the required RenderDoc binaries for linux nor for OSX. If you have such a system, build RenderDoc against Python 3.7.0 (the minor version matters) to be compatible with the version of Blender's Python distribution.

54 changes: 54 additions & 0 deletions blender/MapsModelsImporter/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright (c) 2019 Elie Michel
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the “Software”), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# The Software is provided “as is”, without warranty of any kind, express or
# implied, including but not limited to the warranties of merchantability,
# fitness for a particular purpose and noninfringement. In no event shall
# the authors or copyright holders be liable for any claim, damages or other
# liability, whether in an action of contract, tort or otherwise, arising from,
# out of or in connection with the software or the use or other dealings in the
# Software.
#
# This file is part of MapsModelsImporter, a set of addons to import 3D models
# from Maps services

bl_info = {
"name": "Maps Models Importer",
"author": "Elie Michel",
"version": (1, 0),
"blender": (2, 80, 0),
"location": "File > Import > Google Maps Capture",
"description": "Import meshes from a Google Maps capture",
"warning": "",
"wiki_url": "",
"category": "Import-Export",
}

from . import preferences
from . import properties
from . import operators
from . import panels

def register():
preferences.register()
properties.register()
operators.register()
panels.register()

def unregister():
panels.unregister()
operators.unregister()
properties.unregister()
preferences.unregister()

if __name__ == "__main__":
register()
Empty file.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
175 changes: 175 additions & 0 deletions blender/MapsModelsImporter/google_maps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
# Copyright (c) 2019 Elie Michel
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the “Software”), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# The Software is provided “as is”, without warranty of any kind, express or
# implied, including but not limited to the warranties of merchantability,
# fitness for a particular purpose and noninfringement. In no event shall
# the authors or copyright holders be liable for any claim, damages or other
# liability, whether in an action of contract, tort or otherwise, arising from,
# out of or in connection with the software or the use or other dealings in the
# Software.
#
# This file is part of MapsModelsImporter, a set of addons to import 3D models
# from Maps services

import sys
import os
import subprocess

from .utils import getBinaryDir, makeTmpDir

SCRIPT_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), "google_maps_rd.py")

def captureToFiles(filepath, prefix):
"""Extract binary files and textures from a RenderDoc capture file.
This spawns a standalone Python interpreter because renderdoc module cannot be loaded in embedded Python"""
blender_dir = os.path.dirname(sys.executable)
python_home = os.path.join(blender_dir, "2.80", "python")
os.environ["PYTHONHOME"] = python_home
os.environ["PYTHONPATH"] = os.environ.get("PYTHONPATH", "")
os.environ["PYTHONPATH"] += os.pathsep + os.path.abspath(getBinaryDir())
python = os.path.join(python_home, "bin", "python.exe" if sys.platform == "win32" else "python")
subprocess.run([python, SCRIPT_PATH, filepath, prefix])

# -----------------------------------------------------------------------------

import bpy
import bmesh
import pickle
from bpy_extras import object_utils
from math import floor, pi
from mathutils import Matrix
import os

def extractUniforms(constants, refMatrix):
"""Extract from constant buffer the model matrix and uv offset
The reference matrix is used to cancel the view part of teh modelview matrix
"""
uvOffsetScale = constants['$Globals']['webgl_fa7f624db8ab37d1']
mdata = constants['$Globals']['webgl_3c7b7f37a9bd4c1d']
matrix = Matrix([
mdata[0:4],
mdata[4:8],
mdata[8:12],
[0, 0, 0, 1],
])
if refMatrix is None:
# Rotate around Y because Google Maps uses X as up axis
refMatrix = Matrix.Rotation(-pi/2, 4, 'Y') @ matrix.inverted()
matrix = refMatrix @ matrix

matrix[0][3] *= .0039
matrix[1][3] *= .0039
matrix[2][3] *= .0039

return uvOffsetScale, matrix, refMatrix

def addMesh(context, name, verts, tris, uvs):
mesh = bpy.data.meshes.new(name)

mesh.from_pydata(verts, [], tris)
mesh.update()

bm = bmesh.new()
bm.from_mesh(mesh)
uv_layer = bm.loops.layers.uv.verify()
for f in bm.faces:
for l in f.loops:
luv = l[uv_layer]
luv.uv = tuple(uvs[l.vert.index])
bm.to_mesh(mesh)

obj = object_utils.object_data_add(context, mesh, operator=None)
return obj

def addImageMaterial(name, obj, img):
bpy.ops.material.new()
mat = bpy.data.materials.new(name=name)
mat.use_nodes = True
obj.data.materials.append(mat)
nodes = mat.node_tree.nodes
principled = nodes["Principled BSDF"]
texture_node = nodes.new(type="ShaderNodeTexImage")
texture_node.image = img
links = mat.node_tree.links
link = links.new(texture_node.outputs[0], principled.inputs[0])

def loadData(prefix, drawcallId):
with open("{}{:05d}-indices.bin".format(prefix, drawcallId), 'rb') as file:
indices = pickle.load(file)

with open("{}{:05d}-positions.bin".format(prefix, drawcallId), 'rb') as file:
positions = pickle.load(file)

with open("{}{:05d}-uv.bin".format(prefix, drawcallId), 'rb') as file:
uvs = pickle.load(file)

img = bpy.data.images.load("{}{:05d}-texture.png".format(prefix, drawcallId))

with open("{}{:05d}-constants.bin".format(prefix, drawcallId), 'rb') as file:
constants = pickle.load(file)

return indices, positions, uvs, img, constants

# -----------------------------------------------------------------------------

def filesToBlender(context, prefix, max_blocks=200):
"""Import data from the files extracted by captureToFiles"""
# Get reference matrix
refMatrix = None
if context.scene.maps_models_importer_is_ref_matrix_valid:
values = context.scene.maps_models_importer_ref_matrix
refMatrix = Matrix((values[0:4], values[4:8], values[8:12], values[12:16]))

for drawcallId in range(max_blocks):
if not os.path.isfile("{}{:05d}-indices.bin".format(prefix, drawcallId)):
break

try:
indices, positions, uvs, img, constants = loadData(prefix, drawcallId)
except FileNotFoundError as err:
print("Skipping ({})".format(err))
continue

uvOffsetScale, matrix, refMatrix = extractUniforms(constants, refMatrix)

# Make triangles from triangle strip index buffer
n = len(indices)
tris = [ [ indices[i+j] for j in [[0,1,2],[0,2,1]][i%2] ] for i in range(n - 3)]
tris = [ t for t in tris if t[0] != t[1] and t[0] != t[2] and t[1] != t[2] ]
verts = [ [ p[0], p[1], p[2] ] for p in positions ]

[ou, ov, su, sv] = uvOffsetScale
uvs = [ [ (floor(u * 65535.0 + 0.5) + ou) * su, (floor(v * 65535.0 + 0.5) + ov) * sv ] for u, v in uvs ]

if len(indices) == 0:
continue

mesh_name = "BuildingMesh-{:05d}".format(drawcallId)
obj = addMesh(context, mesh_name, verts, tris, uvs)
obj.matrix_world = matrix

mat_name = "BuildingMat-{:05d}".format(drawcallId)
addImageMaterial(mat_name, obj, img)

# Save reference matrix
if refMatrix:
values = sum([list(v) for v in refMatrix], [])
context.scene.maps_models_importer_ref_matrix = values
context.scene.maps_models_importer_is_ref_matrix_valid = True

# -----------------------------------------------------------------------------

def importCapture(context, filepath, max_blocks, pref):
prefix = makeTmpDir(pref, filepath)
captureToFiles(filepath, prefix)
filesToBlender(context, prefix, max_blocks)
Loading

0 comments on commit c0415f7

Please sign in to comment.