importing GIS data into unity

Per Stu’s workflow, I wanted to load a DEM of the local area into Unity.

1. Stu’s workflow: http://www.dead-mens-eyes.org/embodied-gis-howto-part-1-loading-archaeological-landscapes-into-unity3d-via-blender/

I obtained a DEM from the university library. QGIS would not open the damned thing; folks on Twitter suggested that the header file might be corrupt.

However, I was able to view the DEM using MicroDEM. I exported a grayscale geotiff from MicroDEM. The next step is to import into Unity. Stu’s workflow is pretty complicated, but in the comment thread, he notes this:

2. Alastair’s workflow: https://alastaira.wordpress.com/2013/11/12/importing-dem-terrain-heightmaps-for-unity-using-gdal/

Alrighty then, gdal. I’d already installed gdal when I updated QGIS. But, I couldn’t seem to get it to work from the command line. Hmmm. Turns out, you’ve got to put things into the path (lord how I loathe environment variables, paths, etc.)

export PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH

Now I can use the command line. Hooray! However, his suggested command for converting from geotiff to raw heightmap expected by unity:

gdal_translate –ot UInt16 –scale –of ENVI –outsize 1025 1025 srtm_36_02_warped_cropped.tif heightmap.raw

(using my own file names, of course) kept giving me ‘too many options’ errors. I examined the help file on that gdal_translate, and by rearranging the sequence of flags in my command to how they’re listed in the help,

gdal_translate -ot UInt16 -of ENVI -outsize 1025 1025 -scale localdem.tif heightmap.raw

the issue went away. Poof!

Into Unity3d I went, creating a new project, with a new terrain object, importing the raw heightmap. Nothing. Nada. Rien.

Knowing that with computers sometimes, when you just keep doing things over and over expecting a different result you actually get a different result:

https://twitter.com/electricarchaeo/status/608073149670944768

So from above, something like my original dem, though flipped a bit. I’m not too sure how to tie scripts into things, so we’ll let that pass for now. But as I examined the object closely, there were all sorts of jitters and jags and … well, it only looks like terrain from directly above.

A bit more googling, and I found this video:

which seems to imply that interleaving in the Raw format might be to blame (? I donno). Anyway, I don’t have Photoshop or anything handy on this machine for dealing with raster images. I might just go back to Qgis with the geotiff I made with Microdem.

(I went to install Gimp, saw that you could do it with Macports, and I’ve been waiting for the better part of an hour. I should not have done that, I suppose).

Anyway, the reason for all this – I’m trying to replicate Stu’s embodied gis concept. The first part of that is to get the target landscape into the unity engine. Then it gets pushed through vuforia… (I think. Need to go back and read his book, if I could remember who I let borrow it).

update june 9 – Success!

  1. I opened the grayscale image exported from MicroDem in Gimp.
  2. I resized the image as power of 2 + 1 (*shrug* everything indicates this is what you do, with unity); in this case, 1025.
  3. Saved as RAW.
  4. Changed the file extension from .data to .raw.
  5. Created a new 3d terrain object in Unity.
  6. Imported my .raw image.
  7. On the import dialogue, changed it to 8-bit image rather than 16-bit.
  8. Changed the width, height, x and z to all be 1025. Changed the y to be 75 (as the original image height is somewhere around 60 m above sea level, the highest point 135 m above sea level. Otherwise, I was getting these monstrous mountains when going with the default ‘600’).
  9. This post provided the solution: http://newton64.github.io/blog/2013-07-24-gimp-unity-terrain.html

I still need to rotate things, add water, add controls, etc. But now I could add my 3d models of the cemetery (which is on the banks of this river), perhaps also Oculus support etc. Talking with Stu a bit more, I see that his embodied GIS is still a bit beyond what I can do (lots of custom scripting), but imagine publishing an excavation this way, especially if ‘Excavation is destruction digitization‘…

Screen Shot 2015-06-09 at 12.14.30 PM

Success! That’s the mighty Rideau you’re looking at there.

working with vuforia unity plugin for augmented reality

Notes to self:

– working on Mac.
-install vuforia plugin for unity
-followed this: http://developer.vuforia.com/library/articles/Solution/Compiling-a-Simple-Unity-Project
-this post is handy too. http://www.marcofolio.net/other/introduction_into_augmented_reality_with_vuforia.html
-however: you have to register a key for your app that you build https://developer.vuforia.com/targetmanager/licenseManager/licenseListing
-you also have to create an image tracking database. (under the ‘develop’ page of the Vuforia website). You upload your images, it creates a database xml in return. You download it, and while unity is open, double click on the download – it adds itself automatically.
-you have to have the ios or android sdk installed on your machine. I’m working with android. I had to find the location of the sdk; needed to ‘unhide’ the ‘Library’ folder in the Finder in order to do so (Unity will ask you for the location of the sdk when it builds your app. If you don’t unhide it, you can’t find or select it).

-some screenshots from within Unity, for reference:

Screen Shot 2015-05-30 at 4.18.11 PM

delete the default camera. add arcamera from ‘prefabs’ in the project. add imagetargets from ‘prefabs’. assets go underneath an imagetarget.

Screen Shot 2015-05-30 at 4.18.21 PM

prefabs are where the magic lies. the 3dmodels folder was one I added via the finder, and then I dropped my obj and texture pngs in there. Unity updated automatically, creating also the materials folder.

Screen Shot 2015-05-30 at 4.18.48 PM

you add the app license key that you made with the online licence manager here. If you have more than one tracking image, *I think* you put that info here in ‘max simultaneous tracked images’. If you’ve got more than 1 tracked object at a time, update accordingly.

Screen Shot 2015-05-30 at 4.19.12 PM

for your image target, you select ‘data set’ to grab images from the database you created, and then image target. You also have to set ‘width’; I do not understand, yet, what units these are in.