This should work.
Say there’s a historical map that you want to digitize. It may or may not have contour lines on it, but there is some indication of the topography (hatching or shading or what not). Say you wanted to digitize it such that a person could explore its conception of geography from a first person perspective.
Here’s a workflow for making that happen.
Some time ago, the folks at the NYPL put together a tutorial explaining how to turn such a map into a minecraft world. So let’s do the first part of their tutorial. In essence, what we do is take the georectified map (which you could georectify using something like the Harvard Map Warper), load that into QGIS, add elevation points, generate a surface from that elevation, turn it into grayscale, export that image, convert to raw format, import into Unity3d.
Easy peasy.
For the first part, we follow the NYPL:
Requirements
QGIS 2.2.0 ( http://qgis.org )
- Activate Contour plugin
- Activate GRASS plugin if not already activated
A map image to work from
- We used a geo-rectified TIFF exported from this map but any high rez scan of a map with elevation data and features will suffice.
Process:
Layer > Add Raster Layer > [select rectified tiff]
- Repeat for each tiff to be analyzed
Layer > New > New Shapefile Layer
- Type: Point
- New Attribute: add ‘elevation’ type whole number
- remove id
Contour (plugin)
- Vector Layer: choose points layer just created
- Data field: elevation
- Number: at least 20 (maybe.. number of distinct elevations + 2)
- Layer name: default is fine
Export and import contours as vector layer:
- right click save (e.g. port-washington-contours.shp)
- May report error like “Only 19 of 20 features written.” Doesn’t seem to matter much
Layer > Add Vector Layer > [add .shp layer just exported]
Edit Current Grass Region (to reduce rendering time)
- clip to minimal lat longs
Open Grass Tools
- Modules List: Select “v.in.ogr.qgis”
- Select recently added contours layer
- Run, View output, and close
Open Grass Tools
- Modules List: Select “v.to.rast.attr”
- Name of input vector map: (layer just generated)
- Attribute field: elevation
- Run, View output, and close
Open Grass Tools
- Modules List: Select “r.surf.contour”
- Name of existing raster map containing colors: (layer just generated)
- Run (will take a while), View output, and close
Hide points and contours (and anything else above bw elevation image) Project > Save as Image
You may want to create a cropped version of the result to remove un-analyzed/messy edges
As I noted a while ago, there are some “hidden, tacit bits [concerning] installing the Contour plugin, and working with GRASS tools (especially the bit about ‘editing the current grass region’, which always is fiddly, I find).” Unhelpfully, I didn’t write down what these were.
Anyway, now that you have a grayscale image, open it in Gimp (or Photoshop; if you do have photoshop go watch this video and you’re done.).
For those of us without photoshop, this next bit comes from the addendum to a previous post of mine:L
- open the grayscale image in Gimp.
- resized the image as power of 2 + 1 (*shrug* everything indicates this is what you do, with unity); in this case I chose 1025.
- save as file type RAW. IMPORTANT: in the dialogue that opens, set ‘RGB save type to ‘planar’.
- Change the file extension from .data to .raw in mac Finder or windows Explorer.
Now you can import this historical elevation map in Unity. In Unity, add a gameobject -> 3d object -> terrain to the project. In the inspector window, there’s a cogwheel. Click this; it opens the settings. One of the options will be ‘import raw’. Click this.
Select your .raw grayscale image.
- On the import dialogue, change it to 8-bit image rather than 16-bit.
- Change the width, height, x and z to all be 1025. Changed the y to be 75 (yours will be different; look at the range in your original map of highest and lowest point, and input that. For reference, please also see this post which saved me: http://newton64.github.io/blog/2013-07-24-gimp-unity-terrain.html
Ta da – a white glacial landscape with your elevation data.
Now the fun stuff can happen. But – before someone can ‘walk’ around your landscape, you have to add controls to your project. So, in Unity 3d, go to:
Assets – Import package – characters.
Once that’s all done, you’ll drag-and-drop a ‘FPSController’ into your project. You’ll find it as below:
Click and grab that blue box and move it up into your project (just drop it in the main window). Make sure that the control is above (and also, not intersecting any part of) your landscape, or when you go to play, you’ll either be stuck or indeed falling to the centre of the earth. We don’t want that. Also, delete the ‘camera’ from the hierarchy; the fpscontroller has its own camera. My interface looks like this:
You do the grass and trees etc from the terrain inspector, as in the window there on the right. I’ll play some more with that aspect, report back soonish. Notice the column drum in the right foreground, and the tombstone in the back? Those were made with 3d photogrammetry; both are hosted on Sketchfab, as it happens. Anyway, in Meshlab I converted from .obj to .dae, after having reduced the polygons with quadratic edge decimation, to make them a bit simpler. You can add such models to your landscape by dropping the folder into the ‘assets’ folder of your Unity project (via the mac Finder or windows explorer). Then, as you did with the fpscontroller block, you drag them into your scene and reposition them as you want.
Here’s my version, pushed to webGL
Enjoy!
(by the way, it occurs to me that you could use that workflow to visualize damned near anything that can be mapped, not just geography. Convert the output of a topic model into a grayscale elevation map; take a network and add elevation points to match betweeness metrics…)
One thought on “historical maps into Unity3d”
Comments are closed.